Linux USB
 help / color / mirror / Atom feed
From: liuc63 <liuc63@xiaopeng.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Weibin Liu <liuwb@xiaopeng.com>,
	linux-usb@vger.kernel.org, Liu Chao <liuc63@xiaopeng.com>,
	stable@vger.kernel.org
Subject: [PATCH] usb: gadget: net2280: fix out-of-bounds read of short packet in write_fifo
Date: Mon, 19 Oct 2026 15:56:49 +0800	[thread overview]
Message-ID: <20261019075651.2093625-1-liuc63@xiaopeng.com> (raw)

From: Liu Chao <liuc63@xiaopeng.com>

write_fifo() handles the trailing short word of an IN transfer by
reading a full 32-bit word from req->buf even when only 1..3 bytes
remain. get_unaligned((u32 *)buf) therefore reads up to three bytes
past the end of the request buffer, which KASAN reports as a
slab-out-of-bounds read.

The over-read bytes are not sent to the host: set_fifo_bytecount()
limits the FIFO to count & 0x03 bytes, so this is an out-of-bounds read
rather than an information leak.

Copy the remaining 1..3 bytes into a zero-padded word and feed that to
the existing get_unaligned()/cpu_to_le32s() sequence, so the trailing
word is built only from data that belongs to the request. The full-word
path above is unchanged, and reusing get_unaligned()/cpu_to_le32s()
keeps the byte order identical on both little- and big-endian hosts.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Reviewed-by: Weibin Liu <liuwb@xiaopeng.com>
Signed-off-by: Liu Chao <liuc63@xiaopeng.com>
---
 drivers/usb/gadget/udc/net2280.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c
index 7c5f30cfd24d..a1f5d11f82d2 100644
--- a/drivers/usb/gadget/udc/net2280.c
+++ b/drivers/usb/gadget/udc/net2280.c
@@ -649,7 +649,18 @@ static void write_fifo(struct net2280_ep *ep, struct usb_request *req)
 	 * when maxpacket is not a multiple of 4 bytes.
 	 */
 	if (count || total < ep->ep.maxpacket) {
-		tmp = count ? get_unaligned((u32 *)buf) : count;
+		/*
+		 * Don't read past the end of the request buffer: a short
+		 * trailing packet has only count & 0x03 valid bytes. Copy
+		 * them into a zero-padded word and reuse the same
+		 * get_unaligned()/cpu_to_le32s() sequence as the full-word
+		 * path above, so the byte order on the wire is unchanged.
+		 */
+		u8 tail[4] = {};
+
+		if (count)
+			memcpy(tail, buf, count & 0x03);
+		tmp = get_unaligned((u32 *)tail);
 		cpu_to_le32s(&tmp);
 		set_fifo_bytecount(ep, count & 0x03);
 		writel(tmp, &regs->ep_data);
-- 
2.50.1


             reply	other threads:[~2026-10-19  7:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19  7:56 liuc63 [this message]
2026-10-19  7:59 ` [PATCH] usb: gadget: net2280: fix out-of-bounds read of short packet in write_fifo sashiko-bot
2026-10-19 14:11 ` Alan Stern

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=20261019075651.2093625-1-liuc63@xiaopeng.com \
    --to=liuc63@xiaopeng.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=liuwb@xiaopeng.com \
    --cc=stable@vger.kernel.org \
    /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