Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794065277; b=nXxv01LjQslqSRhbCIN2qUNmoX9qMX20syu59cG1xU1hjUvpsA5ypqgtcCufNyT3kBRG 7LUG8VuJaO8e+PePtjAszuos0Ah4JtLAXpxuE3tbz+BUO6DAMXZ9yrm7sTUk8H+KNxh8q /Of0wJpsEzihUV908ZFVs+b73q8ZFeZ11JPzNmlgZCoAwRjNjVLGeTMIzs9Hcb3V4mNHg zSkRJYeaciiggOIMWhMoHAYJtM7cX6QtEgbtCit1KX7hFJOGVSVW+7PQ5BprQkyQk5Bwg Hs7CSi8ro63GZPLLsH9OyPOwFEkhGUHO1eNOPfkr9cjTPr2gO48YGWFjA/bmAgeWNEw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794065277; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=gyom9aaX+UY+dWt9TXKuGUwalaIBv4Z+En98nfuY2ss=; b=LyN+i1sUMll74dAss22LzDrdPybuwY8cld5p29uinW1u6f/niKow4aFG0Z2F65MwALj4 dHcXKo/im+wiVtlYFgW6LlzLwXigoKqqDTs7oR0m21oTIm4LOc63S9i5vJcjmF1PcBVaw sDFb9RteLb1ieLjA87ajTiKQeY6zlxFSOSYsxN03aMxFaQ10K6N4ka7XwX2Dj/2XNyS6x RkG+o9TY/8Pmvw/i6Vo+FfZsCTcclnkvF64BjGROk/jHW37XftJqGb89GxzBZHmGedwH/ 6GAqG57+/874GJHB0ovmScmAt463t8JQXbDSrmXRZfob3XUrTvzqZO5qyPyrar3Ei0Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=kx8J35cw; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5143B606A331; Sat, 7 Nov 2026 15:27:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=kx8J35cw Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD0AC1F008A1; Sat, 7 Nov 2026 15:27:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794065276; bh=gyom9aaX+UY+dWt9TXKuGUwalaIBv4Z+En98nfuY2ss=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kx8J35cwVmpCaX1AwOAqgoMH8pDUfcRzBJWRNSumi8ehYzBbnm8N21RogQ82c+4Vh S55Z3nSvE+MNjROY9ID/vcLmolR62z83Ye3yM1Ja0VbVNmtQ27hbVHHE9ftDg7Zb20 BuaEN6tU2At6Lbfk2EJiGW3bwB6tVoWQEh2atFhY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pufan Jin , Mark Brown , Sasha Levin Subject: [PATCH 7.3 1039/1257] spi: zynq-qspi: fix address buffer corruption and support 4-byte address Date: Sat, 7 Nov 2026 08:55:35 -0500 Message-ID: <20261107135008.013534759@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107134939.434104957@linuxfoundation.org> References: <20261107134939.434104957@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pufan Jin [ 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(). Fixes: 67dca5e580f1 ("spi: spi-mem: Add support for Zynq QSPI controller") Cc: stable@vger.kernel.org Signed-off-by: Pufan Jin Link: https://patch.msgid.link/20261016130812.282624-1-cyan2254650260@gmail.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-zynq-qspi.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-zynq-qspi.c b/drivers/spi/spi-zynq-qspi.c index d762aaf452afd..bfcbcfe85b918 100644 --- a/drivers/spi/spi-zynq-qspi.c +++ b/drivers/spi/spi-zynq-qspi.c @@ -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; -- 2.53.0