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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Mar 2021 10:38:29 +0000 (11:38 +0100)
commit9d83cc1a1e7f494aedee2aa108e801d11525fccf
treef0d7506e91cf275693f6eadff5ceeff20f3f5073
parentd65aef25464f7615d5d5229c2c5b69d1cae68b7a
KEYS: trusted: Fix incorrect handling of tpm_get_random()

commit 5df16caada3fba3b21cb09b85cdedf99507f4ec1 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
security/keys/trusted-keys/trusted_tpm1.c