Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 23269ac

Browse files
wqyounggregkh
authored andcommitted
spi: spi-zynqmp-gqspi: fix use-after-free in zynqmp_qspi_exec_op
[ Upstream commit a2c5bed ] When handling op->addr, it is using the buffer "tmpbuf" which has been freed. This will trigger a use-after-free KASAN warning. Let's use temporary variables to store op->addr.val and op->cmd.opcode to fix this issue. Fixes: 1c26372 ("spi: spi-zynqmp-gqspi: Update driver to use spi-mem framework") Signed-off-by: Quanyang Wang <quanyang.wang@windriver.com> Link: https://lore.kernel.org/r/20210416004652.2975446-5-quanyang.wang@windriver.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 28b09dc commit 23269ac

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

drivers/spi/spi-zynqmp-gqspi.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -926,8 +926,9 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
926926
struct zynqmp_qspi *xqspi = spi_controller_get_devdata
927927
(mem->spi->master);
928928
int err = 0, i;
929-
u8 *tmpbuf;
930929
u32 genfifoentry = 0;
930+
u16 opcode = op->cmd.opcode;
931+
u64 opaddr;
931932

932933
dev_dbg(xqspi->dev, "cmd:%#x mode:%d.%d.%d.%d\n",
933934
op->cmd.opcode, op->cmd.buswidth, op->addr.buswidth,
@@ -940,14 +941,8 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
940941
genfifoentry |= xqspi->genfifobus;
941942

942943
if (op->cmd.opcode) {
943-
tmpbuf = kzalloc(op->cmd.nbytes, GFP_KERNEL | GFP_DMA);
944-
if (!tmpbuf) {
945-
mutex_unlock(&xqspi->op_lock);
946-
return -ENOMEM;
947-
}
948-
tmpbuf[0] = op->cmd.opcode;
949944
reinit_completion(&xqspi->data_completion);
950-
xqspi->txbuf = tmpbuf;
945+
xqspi->txbuf = &opcode;
951946
xqspi->rxbuf = NULL;
952947
xqspi->bytes_to_transfer = op->cmd.nbytes;
953948
xqspi->bytes_to_receive = 0;
@@ -961,13 +956,12 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
961956
if (!wait_for_completion_timeout
962957
(&xqspi->data_completion, msecs_to_jiffies(1000))) {
963958
err = -ETIMEDOUT;
964-
kfree(tmpbuf);
965959
goto return_err;
966960
}
967-
kfree(tmpbuf);
968961
}
969962

970963
if (op->addr.nbytes) {
964+
xqspi->txbuf = &opaddr;
971965
for (i = 0; i < op->addr.nbytes; i++) {
972966
*(((u8 *)xqspi->txbuf) + i) = op->addr.val >>
973967
(8 * (op->addr.nbytes - i - 1));

0 commit comments

Comments
 (0)