Skip to content

Commit fa1ed74

Browse files
Dan Carpentergregkh
authored andcommitted
USB: devio: Don't corrupt user memory
The user buffer has "uurb->buffer_length" bytes. If the kernel has more information than that, we should truncate it instead of writing past the end of the user's buffer. I added a WARN_ONCE() to help the user debug the issue. Reported-by: Alan Stern <[email protected]> Cc: stable <[email protected]> Signed-off-by: Dan Carpenter <[email protected]> Acked-by: Alan Stern <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 57999d1 commit fa1ed74

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/usb/core/devio.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,11 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
15761576
totlen += isopkt[u].length;
15771577
}
15781578
u *= sizeof(struct usb_iso_packet_descriptor);
1579-
uurb->buffer_length = totlen;
1579+
if (totlen <= uurb->buffer_length)
1580+
uurb->buffer_length = totlen;
1581+
else
1582+
WARN_ONCE(1, "uurb->buffer_length is too short %d vs %d",
1583+
totlen, uurb->buffer_length);
15801584
break;
15811585

15821586
default:

0 commit comments

Comments
 (0)