Skip to content

Commit a0bcce2

Browse files
Dan Carpenterjarkkojs
authored andcommitted
tpm: Check for integer overflow in tpm2_map_response_body()
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]>
1 parent 4091c00 commit a0bcce2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/char/tpm/tpm2-space.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ static int tpm2_map_response_body(struct tpm_chip *chip, u32 cc, u8 *rsp,
455455
if (be32_to_cpu(data->capability) != TPM2_CAP_HANDLES)
456456
return 0;
457457

458+
if (be32_to_cpu(data->count) > (UINT_MAX - TPM_HEADER_SIZE - 9) / 4)
459+
return -EFAULT;
460+
458461
if (len != TPM_HEADER_SIZE + 9 + 4 * be32_to_cpu(data->count))
459462
return -EFAULT;
460463

0 commit comments

Comments
 (0)