mirror of
https://github.com/linux-sunxi/u-boot-sunxi.git
synced 2024-02-12 11:16:03 +08:00
STMicro TPM: Fix potential buffer overruns
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>
This commit is contained in:
@ -303,7 +303,8 @@ static int st33zp24_i2c_recv_data(struct udevice *dev, u8 *buf, size_t count)
|
|||||||
static int st33zp24_i2c_recv(struct udevice *dev, u8 *buf, size_t count)
|
static int st33zp24_i2c_recv(struct udevice *dev, u8 *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct tpm_chip *chip = dev_get_priv(dev);
|
struct tpm_chip *chip = dev_get_priv(dev);
|
||||||
int size, expected;
|
int size;
|
||||||
|
unsigned int expected;
|
||||||
|
|
||||||
if (!chip)
|
if (!chip)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@ -320,7 +321,7 @@ static int st33zp24_i2c_recv(struct udevice *dev, u8 *buf, size_t count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
expected = get_unaligned_be32(buf + 2);
|
expected = get_unaligned_be32(buf + 2);
|
||||||
if (expected > count) {
|
if (expected > count || expected < TPM_HEADER_SIZE) {
|
||||||
size = -EIO;
|
size = -EIO;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -431,7 +431,8 @@ static int st33zp24_spi_recv_data(struct udevice *dev, u8 *buf, size_t count)
|
|||||||
static int st33zp24_spi_recv(struct udevice *dev, u8 *buf, size_t count)
|
static int st33zp24_spi_recv(struct udevice *dev, u8 *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct tpm_chip *chip = dev_get_priv(dev);
|
struct tpm_chip *chip = dev_get_priv(dev);
|
||||||
int size, expected;
|
int size;
|
||||||
|
unsigned int expected;
|
||||||
|
|
||||||
if (!chip)
|
if (!chip)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@ -448,7 +449,7 @@ static int st33zp24_spi_recv(struct udevice *dev, u8 *buf, size_t count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
expected = get_unaligned_be32(buf + 2);
|
expected = get_unaligned_be32(buf + 2);
|
||||||
if (expected > count) {
|
if (expected > count || expected < TPM_HEADER_SIZE) {
|
||||||
size = -EIO;
|
size = -EIO;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user