Skip to content

Commit fdfb49e

Browse files
leitaomehmetb0
authored andcommitted
spi: tegra210-quad: Avoid shift-out-of-bounds
BugLink: https://bugs.launchpad.net/bugs/2095283 [ Upstream commit f399051 ] A shift-out-of-bounds issue was identified by UBSAN in the tegra_qspi_fill_tx_fifo_from_client_txbuf() function. UBSAN: shift-out-of-bounds in drivers/spi/spi-tegra210-quad.c:345:27 shift exponent 32 is too large for 32-bit type 'u32' (aka 'unsigned int') Call trace: tegra_qspi_start_cpu_based_transfer The problem arises when shifting the contents of tx_buf left by 8 times the value of i, which can exceed 4 and result in an exponent larger than 32 bits. Resolve this by restrict the value of i to be less than 4, preventing the shift operation from overflowing. Signed-off-by: Breno Leitao <[email protected]> Fixes: 921fc18 ("spi: tegra210-quad: Add support for Tegra210 QSPI controller") Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Koichiro Den <[email protected]>
1 parent 13a5451 commit fdfb49e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/spi/spi-tegra210-quad.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ tegra_qspi_fill_tx_fifo_from_client_txbuf(struct tegra_qspi *tqspi, struct spi_t
298298
for (count = 0; count < max_n_32bit; count++) {
299299
u32 x = 0;
300300

301-
for (i = 0; len && (i < bytes_per_word); i++, len--)
301+
for (i = 0; len && (i < min(4, bytes_per_word)); i++, len--)
302302
x |= (u32)(*tx_buf++) << (i * 8);
303303
tegra_qspi_writel(tqspi, x, QSPI_TX_FIFO);
304304
}

0 commit comments

Comments
 (0)