Skip to content

Commit

Permalink
tpm: Check for integer overflow in tpm2_map_response_body()
Browse files Browse the repository at this point in the history
The "4 * be32_to_cpu(data->count)" multiplication can potentially
overflow which would lead to memory corruption.  Add a check for that.

Cc: [email protected]
Fixes: 745b361 ("tpm: infrastructure for TPM spaces")
Signed-off-by: Dan Carpenter <[email protected]>
Reviewed-by: Jarkko Sakkinen <[email protected]>
Signed-off-by: Jarkko Sakkinen <[email protected]>
  • Loading branch information
Dan Carpenter authored and jarkkojs committed Oct 26, 2021
1 parent 4091c00 commit a0bcce2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/char/tpm/tpm2-space.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit a0bcce2

Please sign in to comment.