From: Cheng Yongkang <teel4res@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] usb: usbfs: clamp the copied length to transfer_buffer_length
Date: Thu, 29 Oct 2026 07:12:20 -0700 [thread overview]
Message-ID: <179328314074.648427.8187049654053191605@gmail.com> (raw)
In-Reply-To: <179328314073.648427.8311262845412746237@gmail.com>
copy_urb_data_to_user() uses urb->actual_length as the number of bytes to
copy to userspace for non-isochronous URBs. The usbfs contract is that a
driver must not report more data than the transfer buffer holds, but
usbfs cannot rely on every HCD or device implementation to honor it; a
malicious usbip peer can already set actual_length beyond
transfer_buffer_length and trigger an out-of-bounds read:
BUG: KASAN: slab-out-of-bounds in _copy_to_user+0x79/0xb0
Read of size 88 at addr ...
copy_urb_data_to_user+0x36f/0x480
Clamp the non-isochronous length to transfer_buffer_length before the
copy. Normal URBs are unaffected; the isochronous path already uses
transfer_buffer_length.
Fixes: 3d97ff63f899 ("usbdevfs: Use scatter-gather lists for large bulk transfers")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
---
drivers/usb/core/devio.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 101cb94..9554b6a 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -557,10 +557,13 @@ static int copy_urb_data_to_user(u8 __user *userbuffer, struct urb *urb)
{
unsigned i, len, size;
- if (urb->number_of_packets > 0) /* Isochronous */
+ if (urb->number_of_packets > 0) { /* Isochronous */
len = urb->transfer_buffer_length;
- else /* Non-Isoc */
+ } else { /* Non-Isoc */
len = urb->actual_length;
+ if (len > urb->transfer_buffer_length)
+ len = urb->transfer_buffer_length;
+ }
if (urb->num_sgs == 0) {
if (copy_to_user(userbuffer, urb->transfer_buffer, len))
--
2.34.1
prev parent reply other threads:[~2026-10-29 14:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 14:12 [PATCH 0/2] usb: fix over-reported actual_length in usbip/usbfs Cheng Yongkang
2026-10-29 14:12 ` [PATCH 1/2] usbip: clear actual_length after a failed receive Cheng Yongkang
2026-10-29 18:42 ` Shuah Khan
2026-10-29 14:12 ` Cheng Yongkang [this message]
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=179328314074.648427.8187049654053191605@gmail.com \
--to=teel4res@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@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
all inboxes | Powered by JetHome®