spi: Ensure that sg_table won't be used after being freed
authorMarek Szyprowski <m.szyprowski@samsung.com>
Fri, 30 Sep 2022 11:34:08 +0000 (13:34 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 10:34:48 +0000 (12:34 +0200)
commitc91b922b4170caef934c7e79c4a0f4faad184baf
tree66ef1d2a6537ad5c2516ccfaf4e9cfa9059dafb5
parent49d429760df7fd662dd24d54c7325d5b2fd78697
spi: Ensure that sg_table won't be used after being freed

[ Upstream commit 8e9204cddcc3fea9affcfa411715ba4f66e97587 ]

SPI code checks for non-zero sgt->orig_nents to determine if the buffer
has been DMA-mapped. Ensure that sg_table is really zeroed after free to
avoid potential NULL pointer dereference if the given SPI xfer object is
reused again without being DMA-mapped.

Fixes: 0c17ba73c08f ("spi: Fix cache corruption due to DMA/PIO overlap")
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/20220930113408.19720-1-m.szyprowski@samsung.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/spi/spi.c