kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tpm: Check for integer overflow in tpm2_map_response_body()
@ 2021-09-08  5:33 Dan Carpenter
  2021-09-09 14:04 ` Jarkko Sakkinen
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2021-09-08  5:33 UTC (permalink / raw)
  To: Peter Huewe, Jarkko Sakkinen
  Cc: Jason Gunthorpe, James Bottomley, linux-integrity, kernel-janitors

The "4 * be32_to_cpu(data->count)" multiplication can potentially
overflow which would lead to memory corruption.  Add a check for that.

Fixes: 745b361e989a ("tpm: infrastructure for TPM spaces")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/char/tpm/tpm2-space.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c
index 784b8b3cb903..97e916856cf3 100644
--- a/drivers/char/tpm/tpm2-space.c
+++ b/drivers/char/tpm/tpm2-space.c
@@ -455,6 +455,9 @@ static int tpm2_map_response_body(struct tpm_chip *chip, u32 cc, u8 *rsp,
 	if (be32_to_cpu(data->capability) != TPM2_CAP_HANDLES)
 		return 0;
 
+	if (be32_to_cpu(data->count) > (UINT_MAX - TPM_HEADER_SIZE - 9) / 4)
+		return -EFAULT;
+
 	if (len != TPM_HEADER_SIZE + 9 + 4 * be32_to_cpu(data->count))
 		return -EFAULT;
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tpm: Check for integer overflow in tpm2_map_response_body()
  2021-09-08  5:33 [PATCH] tpm: Check for integer overflow in tpm2_map_response_body() Dan Carpenter
@ 2021-09-09 14:04 ` Jarkko Sakkinen
  0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2021-09-09 14:04 UTC (permalink / raw)
  To: Dan Carpenter, Peter Huewe
  Cc: Jason Gunthorpe, James Bottomley, linux-integrity, kernel-janitors

On Wed, 2021-09-08 at 08:33 +0300, Dan Carpenter wrote:
> The "4 * be32_to_cpu(data->count)" multiplication can potentially
> overflow which would lead to memory corruption.  Add a check for that.
> 
> Fixes: 745b361e989a ("tpm: infrastructure for TPM spaces")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/char/tpm/tpm2-space.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c
> index 784b8b3cb903..97e916856cf3 100644
> --- a/drivers/char/tpm/tpm2-space.c
> +++ b/drivers/char/tpm/tpm2-space.c
> @@ -455,6 +455,9 @@ static int tpm2_map_response_body(struct tpm_chip *chip, u32 cc, u8 *rsp,
>  	if (be32_to_cpu(data->capability) != TPM2_CAP_HANDLES)
>  		return 0;
>  
> +	if (be32_to_cpu(data->count) > (UINT_MAX - TPM_HEADER_SIZE - 9) / 4)
> +		return -EFAULT;
> +
>  	if (len != TPM_HEADER_SIZE + 9 + 4 * be32_to_cpu(data->count))
>  		return -EFAULT;
>  

Thanks!

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

/Jarkko


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-09 14:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-08  5:33 [PATCH] tpm: Check for integer overflow in tpm2_map_response_body() Dan Carpenter
2021-09-09 14:04 ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).