FAILED: patch "[PATCH] spi: zynq-qspi: fix address buffer corruption and support 4-byte address" failed to apply to 5.10-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x dc5ca34f5e8dc10c566ef39aa3b1a201a17ca734
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From dc5ca34f5e8dc10c566ef39aa3b1a201a17ca734 Mon Sep 17 00:00:00 2001
From: Pufan Jin <[email protected]>
Date: Fri, 16 Oct 2026 21:08:12 +0800
Subject: [PATCH] spi: zynq-qspi: fix address buffer corruption and support
4-byte address
In zynq_qspi_exec_mem_op(), when transmitting address bytes, the driver iterates over op->addr.nbytes and populates xqspi->txbuf[i]. However, xqspi->txbuf is never re-assigned before populating the address, meaning it still points to (u8 *)&op->cmd.opcode from the command phase.
This causes two severe issues:
1. Memory corruption: Writing into xqspi->txbuf writes past the opcode buffer on the stack (which was passed as const struct spi_mem_op *). If opcode is zero, xqspi->txbuf is uninitialized.
2. In zynq_qspi_supports_op(), operations with op->addr.nbytes > 3 are rejected. When paired with SPI NOR flashes larger than 16MB (such as Winbond W25Q256), spi_nor_spimem_check_read_pp_op() tests 4-byte address support, which fails and causes spi_nor_select_read() to drop all read capabilities, failing probe with -EINVAL (-22).
The Zynq-7000 QSPI controller hardware in manual I/O mode natively supports transmitting 1 to 4 address bytes via its TXD FIFO registers (ZYNQ_QSPI_TXD_00_00_OFFSET).
Fix this by introducing a local opaddr[4] buffer in zynq_qspi_exec_mem_op() and explicitly setting xqspi->txbuf = opaddr before populating address bytes. Also allow up to 4 address bytes in zynq_qspi_supports_op().
--- drivers/spi/spi-zynq-qspi.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/spi/spi-zynq-qspi.c +7 -6
@@ -229,11 +229,10 @@ static bool zynq_qspi_supports_op(struct spi_mem *mem,return false;/* -* The number of address bytes should be equal to or less than 3 bytes. +* The number of address bytes should be equal to or less than 4 bytes. */ -if (op->addr.nbytes >3 ) +if (op->addr.nbytes >4 )return false; -return true; }
@@ -526,6 +525,7 @@ static int zynq_qspi_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op) {struct zynq_qspi *xqspi =spi_controller_get_devdata (mem->spi->controller); +u8 opaddr[4 ]__aligned(4) ;int err =0 , i;u8 *tmpbuf;
@@ -547,12 +547,13 @@ static int zynq_qspi_exec_mem_op(struct spi_mem *mem, }if (op->addr.nbytes) { -for (i =0 ; i < op->addr.nbytes; i++) { - xqspi->txbuf[i] = op->addr.val >> +for (i =0 ; i < op->addr.nbytes; i++) + opaddr[i] = op->addr.val >> (8 * (op->addr.nbytes - i -1 )); - }reinit_completion (&xqspi->data_completion); + xqspi->txbuf = opaddr; + xqspi->rxbuf =NULL ; xqspi->tx_bytes = op->addr.nbytes; xqspi->rx_bytes = op->addr.nbytes;
Signature · 1 line
2.53.0
PATCH 1/1 spi: zynq-qspi: fix address buffer corruption and support 4-byte address
[ Upstream commit dc5ca34f5e8dc10c566ef39aa3b1a201a17ca734 ]
In zynq_qspi_exec_mem_op(), when transmitting address bytes, the driver iterates over op->addr.nbytes and populates xqspi->txbuf[i]. However, xqspi->txbuf is never re-assigned before populating the address, meaning it still points to (u8 *)&op->cmd.opcode from the command phase.
This causes two severe issues:
1. Memory corruption: Writing into xqspi->txbuf writes past the opcode buffer on the stack (which was passed as const struct spi_mem_op *). If opcode is zero, xqspi->txbuf is uninitialized.
2. In zynq_qspi_supports_op(), operations with op->addr.nbytes > 3 are rejected. When paired with SPI NOR flashes larger than 16MB (such as Winbond W25Q256), spi_nor_spimem_check_read_pp_op() tests 4-byte address support, which fails and causes spi_nor_select_read() to drop all read capabilities, failing probe with -EINVAL (-22).
The Zynq-7000 QSPI controller hardware in manual I/O mode natively supports transmitting 1 to 4 address bytes via its TXD FIFO registers (ZYNQ_QSPI_TXD_00_00_OFFSET).
Fix this by introducing a local opaddr[4] buffer in zynq_qspi_exec_mem_op() and explicitly setting xqspi->txbuf = opaddr before populating address bytes. Also allow up to 4 address bytes in zynq_qspi_supports_op().
--- drivers/spi/spi-zynq-qspi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/spi/spi-zynq-qspi.c +4 -2
@@ -231,7 +231,7 @@ static bool zynq_qspi_supports_op(struct spi_mem *mem,/* * The number of address bytes should be equal to or less than 3 bytes. */ -if (op->addr.nbytes >3 ) +if (op->addr.nbytes >4 )return false;return true;
@@ -535,6 +535,7 @@ static int zynq_qspi_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op) {struct zynq_qspi *xqspi =spi_controller_get_devdata (mem->spi->master); +u8 opaddr[4 ]__aligned(4) ;int err =0 , i;u8 *tmpbuf;
@@ -561,11 +562,12 @@ static int zynq_qspi_exec_mem_op(struct spi_mem *mem,if (op->addr.nbytes) {for (i =0 ; i < op->addr.nbytes; i++) { - xqspi->txbuf[i] = op->addr.val >> + opaddr[i] = op->addr.val >> (8 * (op->addr.nbytes - i -1 )); }reinit_completion (&xqspi->data_completion); + xqspi->txbuf = opaddr; xqspi->rxbuf =NULL ; xqspi->tx_bytes = op->addr.nbytes; xqspi->rx_bytes = op->addr.nbytes;
Signature · 1 line
2.56.0
Re: [PATCH 5.10.y] spi: zynq-qspi: fix address buffer corruption and support 4-byte address
Quoted 1 line
spi: zynq-qspi: fix address buffer corruption and support 4-byte address
Queued for 5.10, thanks.
Signature · 2 lines
Thanks, Sasha