public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Josue Alba Vives <sebasjosue84@gmail.com>
To: security@kernel.org
Cc: gregkh@linuxfoundation.org, shuah@kernel.org,
	stable@vger.kernel.org,
	"Sebastián Alba Vives" <sebasjosue84@gmail.com>
Subject: [PATCH] usbip: validate iso_frame_desc offset and length in usbip_recv_iso()
Date: Sun, 29 Mar 2026 07:17:37 -0600	[thread overview]
Message-ID: <20260329131810.522006-2-sebasjosue84@gmail.com> (raw)
In-Reply-To: <20260329131810.522006-1-sebasjosue84@gmail.com>

From: Sebastián Alba Vives <sebasjosue84@gmail.com>

usbip_recv_iso() receives isochronous packet descriptors from the
network and unpacks them into urb->iso_frame_desc[] via
usbip_pack_iso(). The offset and actual_length fields in each
descriptor come directly from the remote peer without validation.

These fields are subsequently used by usbip_pad_iso() in memmove
operations:

  memmove(urb->transfer_buffer + iso_frame_desc[i].offset,
          urb->transfer_buffer + actualoffset,
          iso_frame_desc[i].actual_length);

A malicious USB/IP server can craft iso frame descriptors with
offset and/or actual_length values exceeding the transfer buffer
bounds, causing an out-of-bounds memmove that corrupts kernel heap
memory. This is exploitable over the network without authentication.

This is a separate vulnerability from the number_of_packets
validation issue. Even with a valid number_of_packets, the
individual descriptor fields can still cause OOB access.

Add validation that each iso_frame_desc entry's offset +
actual_length falls within the transfer buffer bounds. Return
-EPROTO and trigger a connection reset if any entry is invalid.

Cc: stable@vger.kernel.org
Signed-off-by: Sebastián Alba Vives <sebasjosue84@gmail.com>
---
 drivers/usb/usbip/usbip_common.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/usb/usbip/usbip_common.c b/drivers/usb/usbip/usbip_common.c
index f1eeab3a5..8b6ca8f83 100644
--- a/drivers/usb/usbip/usbip_common.c
+++ b/drivers/usb/usbip/usbip_common.c
@@ -711,6 +711,34 @@ int usbip_recv_iso(struct usbip_device *ud, struct urb *urb)
 
 	kfree(buff);
 
+	/*
+	 * Validate each iso_frame_desc entry. The offset and actual_length
+	 * come from the network and must not exceed the transfer buffer.
+	 * Without this check, a malicious server could craft iso descriptors
+	 * with out-of-bounds offset/length values, causing usbip_pad_iso()
+	 * to perform memmove operations beyond the transfer buffer, leading
+	 * to heap buffer overflow.
+	 */
+	for (i = 0; i < np; i++) {
+		unsigned int offset = urb->iso_frame_desc[i].offset;
+		unsigned int length = urb->iso_frame_desc[i].actual_length;
+
+		if (offset > urb->transfer_buffer_length ||
+		    length > urb->transfer_buffer_length - offset) {
+			dev_err(&urb->dev->dev,
+				"iso frame %d: offset %u + length %u > buffer %u\n",
+				i, offset, length,
+				urb->transfer_buffer_length);
+
+			if (ud->side == USBIP_STUB || ud->side == USBIP_VUDC)
+				usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
+			else
+				usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
+
+			return -EPROTO;
+		}
+	}
+
 	if (total_length != urb->actual_length) {
 		dev_err(&urb->dev->dev,
 			"total length of iso packets %d not equal to actual length of buffer %d\n",
-- 
2.43.0


  reply	other threads:[~2026-03-29 13:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-29 12:53 [SECURITY] usbip: vhci: heap buffer overflow via crafted number_of_packets in RET_SUBMIT Sebastian Josue Alba Vives
2026-03-29 12:53 ` [PATCH] usbip: vhci: validate number_of_packets in RET_SUBMIT response Sebastian Josue Alba Vives
2026-03-29 13:25   ` Greg KH
2026-03-29 13:17 ` [SECURITY] usbip: iso_frame_desc OOB memmove via crafted offset/length Sebastian Josue Alba Vives
2026-03-29 13:17   ` Sebastian Josue Alba Vives [this message]
2026-03-29 13:24 ` [SECURITY] usbip: vhci: heap buffer overflow via crafted number_of_packets in RET_SUBMIT Greg KH
2026-03-29 13:34   ` Sebastián Alba
2026-03-29 13:50     ` Greg KH
2026-03-29 13:53       ` Sebastián Alba

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=20260329131810.522006-2-sebasjosue84@gmail.com \
    --to=sebasjosue84@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=security@kernel.org \
    --cc=shuah@kernel.org \
    --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