Ensure that the Infineon I2C and SPI TPM driver performs adequate
validation of the length extracted from the TPM response header.
This patch prevents integer underflow when the length was too small,
which could lead to memory corruption.
Signed-off-by: Jeremy Boone <jeremy.boone@nccgroup.trust>
{
struct tpm_chip *chip = dev_get_priv(dev);
int size = 0;
- int expected, status;
+ int status;
+ unsigned int expected;
int rc;
status = tpm_tis_i2c_status(dev);
}
expected = get_unaligned_be32(buf + TPM_RSP_SIZE_BYTE);
- if ((size_t)expected > count) {
+ if ((size_t)expected > count || (size_t)expected < TPM_HEADER_SIZE) {
debug("Error size=%x, expected=%x, count=%x\n", size, expected,
count);
return -ENOSPC;