public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Yuhao Jiang <danisjiang@gmail.com>
To: danisjiang@gmail.com
Cc: stable@vger.kernel.org
Subject: [PATCH] net/9p: Fix buffer overflow in USB transport layer
Date: Mon, 16 Jun 2025 21:21:39 +0800	[thread overview]
Message-ID: <20250616132139.63276-1-danisjiang@gmail.com> (raw)

A buffer overflow vulnerability exists in the USB 9pfs transport layer
where inconsistent size validation between packet header parsing and
actual data copying allows a malicious USB host to overflow heap buffers.

The issue occurs because:
- usb9pfs_rx_header() validates only the declared size in packet header
- usb9pfs_rx_complete() uses req->actual (actual received bytes) for memcpy

This allows an attacker to craft packets with small declared size (bypassing
validation) but large actual payload (triggering overflow in memcpy).

Add validation in usb9pfs_rx_complete() to ensure req->actual does not
exceed the buffer capacity before copying data.

Reported-by: Yuhao Jiang <danisjiang@gmail.com>
Fixes: a3be076dc174 ("net/9p/usbg: Add new usb gadget function transport")
Cc: stable@vger.kernel.org
Signed-off-by: Yuhao Jiang <danisjiang@gmail.com>
---
 net/9p/trans_usbg.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/net/9p/trans_usbg.c b/net/9p/trans_usbg.c
index 6b694f117aef..047a2862fc84 100644
--- a/net/9p/trans_usbg.c
+++ b/net/9p/trans_usbg.c
@@ -242,6 +242,15 @@ static void usb9pfs_rx_complete(struct usb_ep *ep, struct usb_request *req)
 	if (!p9_rx_req)
 		return;
 
+	/* Validate actual received size against buffer capacity */
+	if (req->actual > p9_rx_req->rc.capacity) {
+		dev_err(&cdev->gadget->dev,
+			"received data size %u exceeds buffer capacity %zu\n",
+			req->actual, p9_rx_req->rc.capacity);
+		p9_req_put(usb9pfs->client, p9_rx_req);
+		return;
+	}
+
 	memcpy(p9_rx_req->rc.sdata, req->buf, req->actual);
 
 	p9_rx_req->rc.size = req->actual;
-- 
2.43.0


             reply	other threads:[~2025-06-16 13:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-16 13:21 Yuhao Jiang [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-06-16 13:25 [PATCH] net/9p: Fix buffer overflow in USB transport layer Yuhao Jiang
2025-06-16 23:00 ` asmadeus
2025-06-17  3:01   ` Danis Jiang
2025-06-17  4:11     ` asmadeus
2025-06-17  4:29       ` Danis Jiang

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=20250616132139.63276-1-danisjiang@gmail.com \
    --to=danisjiang@gmail.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