Skip to content

Commit 195aba9

Browse files
nvmochsjarkkojs
authored andcommitted
tpm_tis_spi: Account for SPI header when allocating TPM SPI xfer buffer
The TPM SPI transfer mechanism uses MAX_SPI_FRAMESIZE for computing the maximum transfer length and the size of the transfer buffer. As such, it does not account for the 4 bytes of header that prepends the SPI data frame. This can result in out-of-bounds accesses and was confirmed with KASAN. Introduce SPI_HDRSIZE to account for the header and use to allocate the transfer buffer. Fixes: a86a42a ("tpm_tis_spi: Add hardware wait polling") Signed-off-by: Matthew R. Ochs <mochs@nvidia.com> Tested-by: Carol Soto <csoto@nvidia.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 2bfcfd5 commit 195aba9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/char/tpm/tpm_tis_spi_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "tpm_tis_spi.h"
3838

3939
#define MAX_SPI_FRAMESIZE 64
40+
#define SPI_HDRSIZE 4
4041

4142
/*
4243
* TCG SPI flow control is documented in section 6.4 of the spec[1]. In short,
@@ -247,7 +248,7 @@ static int tpm_tis_spi_write_bytes(struct tpm_tis_data *data, u32 addr,
247248
int tpm_tis_spi_init(struct spi_device *spi, struct tpm_tis_spi_phy *phy,
248249
int irq, const struct tpm_tis_phy_ops *phy_ops)
249250
{
250-
phy->iobuf = devm_kmalloc(&spi->dev, MAX_SPI_FRAMESIZE, GFP_KERNEL);
251+
phy->iobuf = devm_kmalloc(&spi->dev, SPI_HDRSIZE + MAX_SPI_FRAMESIZE, GFP_KERNEL);
251252
if (!phy->iobuf)
252253
return -ENOMEM;
253254

0 commit comments

Comments
 (0)