KEYS: trusted: Fix incorrect handling of tpm_get_random()
authorJarkko Sakkinen <jarkko@kernel.org>
Thu, 28 Jan 2021 23:56:19 +0000 (01:56 +0200)
committerJarkko Sakkinen <jarkko@kernel.org>
Tue, 16 Feb 2021 08:40:28 +0000 (10:40 +0200)
commit5df16caada3fba3b21cb09b85cdedf99507f4ec1
tree1c1afeec65b5a134bf62843d480bb85b6219f69a
parent90cba8d20f8b09d62a25f9864cb8e67722d76c3a
KEYS: trusted: Fix incorrect handling of tpm_get_random()

When tpm_get_random() was introduced, it defined the following API for the
return value:

1. A positive value tells how many bytes of random data was generated.
2. A negative value on error.

However, in the call sites the API was used incorrectly, i.e. as it would
only return negative values and otherwise zero. Returning he positive read
counts to the user space does not make any possible sense.

Fix this by returning -EIO when tpm_get_random() returns a positive value.

Fixes: 41ab999c80f1 ("tpm: Move tpm_get_random api into the TPM device driver")
Cc: stable@vger.kernel.org
Cc: Mimi Zohar <zohar@linux.ibm.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Kent Yoder <key@linux.vnet.ibm.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
security/keys/trusted-keys/trusted_tpm1.c