Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: a86a42ac2bd6 ("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>

authored by

Matthew R. Ochs and committed by
Jarkko Sakkinen
195aba96 2bfcfd58

+2 -1
+2 -1
drivers/char/tpm/tpm_tis_spi_main.c
··· 37 37 #include "tpm_tis_spi.h" 38 38 39 39 #define MAX_SPI_FRAMESIZE 64 40 + #define SPI_HDRSIZE 4 40 41 41 42 /* 42 43 * TCG SPI flow control is documented in section 6.4 of the spec[1]. In short, ··· 248 247 int tpm_tis_spi_init(struct spi_device *spi, struct tpm_tis_spi_phy *phy, 249 248 int irq, const struct tpm_tis_phy_ops *phy_ops) 250 249 { 251 - phy->iobuf = devm_kmalloc(&spi->dev, MAX_SPI_FRAMESIZE, GFP_KERNEL); 250 + phy->iobuf = devm_kmalloc(&spi->dev, SPI_HDRSIZE + MAX_SPI_FRAMESIZE, GFP_KERNEL); 252 251 if (!phy->iobuf) 253 252 return -ENOMEM; 254 253