From: Weibin Liu <liuwb@xiaopeng.com>
To: broonie@kernel.org
Cc: wentong.wu@intel.com, lixu.zhang@intel.com,
sakari.ailus@linux.intel.com, linux-spi@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH v2] spi: ljca: validate the response length before copying the data
Date: Tue, 13 Oct 2026 11:17:17 +0800 [thread overview]
Message-ID: <20261013031717.3933277-1-liuwb@xiaopeng.com> (raw)
In-Reply-To: <20260929080126.4168981-1-liuwb@xiaopeng.com>
ljca_spi_read_write() only checks that the response from the adapter
carries the packet header and a non-zero payload length before copying
r_packet->len bytes from the response into the transfer buffer.
The payload length is taken from the packet the device sent back and is
neither bounded by the number of bytes actually received nor by the
size of the requested transfer: a misbehaving adapter can announce a
payload larger than what it actually sent, and the memcpy then reads
past the end of the 60-byte input buffer and writes past the end of the
caller's transfer buffer.
Check that the response carries the full header before reading
r_packet->len, then reject responses whose payload is not contained in
the data received or is longer than the requested transfer.
Fixes: caee8e38da67 ("spi: Add support for Intel LJCA USB SPI driver")
Cc: stable@vger.kernel.org # 6.8+
Signed-off-by: Weibin Liu <liuwb@xiaopeng.com>
---
Changes in v2:
- Check for the full header before reading r_packet->len (Mark Brown).
- Regenerate on a clean tree; v1 carried prerequisite-patch-id entries
for unrelated patches.
---
drivers/spi/spi-ljca.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-ljca.c b/drivers/spi/spi-ljca.c
index 0c6e6248d..8fd001610 100644
--- a/drivers/spi/spi-ljca.c
+++ b/drivers/spi/spi-ljca.c
@@ -105,7 +105,12 @@ static int ljca_spi_read_write(struct ljca_spi_dev *ljca_spi, const u8 *w_data,
(u8 *)r_packet, LJCA_SPI_BUF_SIZE);
if (ret < 0)
return ret;
- else if (ret < sizeof(*r_packet) || r_packet->len <= 0)
+
+ if (ret < sizeof(*r_packet))
+ return -EIO;
+
+ if (!r_packet->len || ret < sizeof(*r_packet) + r_packet->len ||
+ r_packet->len > len)
return -EIO;
if (r_data)
base-commit: 72d3fcf802c45d00b300f25b848a93c3a2bd7c7e
--
2.50.1
next prev parent reply other threads:[~2026-10-13 3:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 8:01 [PATCH] " Weibin Liu
2026-09-29 11:00 ` Sakari Ailus
2026-09-29 11:02 ` Mark Brown
2026-10-13 3:17 ` Weibin Liu [this message]
2026-10-13 19:46 ` [PATCH v2] " Mark Brown
2026-11-03 13:36 ` Arpith Alexander
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261013031717.3933277-1-liuwb@xiaopeng.com \
--to=liuwb@xiaopeng.com \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=lixu.zhang@intel.com \
--cc=sakari.ailus@linux.intel.com \
--cc=stable@vger.kernel.org \
--cc=wentong.wu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®