Re: [PATCH] tpm: Check for integer overflow in tpm2_map_response_body()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
>  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@xxxxxxxxxx>

/Jarkko





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux Kernel]     [Linux Kernel Hardening]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux