Skip to content

Commit b74a454

Browse files
Dan Carpentergregkh
authored andcommitted
USB: devio: Don't corrupt user memory
commit fa1ed74eb1c233be6131ec92df21ab46499a15b6 upstream. 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 <stern@rowland.harvard.edu> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e84b4a0 commit b74a454

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

drivers/usb/core/devio.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,11 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
14171417
totlen += isopkt[u].length;
14181418
}
14191419
u *= sizeof(struct usb_iso_packet_descriptor);
1420-
uurb->buffer_length = totlen;
1420+
if (totlen <= uurb->buffer_length)
1421+
uurb->buffer_length = totlen;
1422+
else
1423+
WARN_ONCE(1, "uurb->buffer_length is too short %d vs %d",
1424+
totlen, uurb->buffer_length);
14211425
break;
14221426

14231427
default:

0 commit comments

Comments
 (0)