Skip to content

Commit 8d83f10

Browse files
AlanSterngregkh
authored andcommitted
USB: usbfs: Don't WARN about excessively large memory allocations
commit 4f2629e upstream. Syzbot found that the kernel generates a WARNing if the user tries to submit a bulk transfer through usbfs with a buffer that is way too large. This isn't a bug in the kernel; it's merely an invalid request from the user and the usbfs code does handle it correctly. In theory the same thing can happen with async transfers, or with the packet descriptor table for isochronous transfers. To prevent the MM subsystem from complaining about these bad allocation requests, add the __GFP_NOWARN flag to the kmalloc calls for these buffers. CC: Andrew Morton <akpm@linux-foundation.org> CC: <stable@vger.kernel.org> Reported-and-tested-by: syzbot+882a85c0c8ec4a3e2281@syzkaller.appspotmail.com Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Link: https://lore.kernel.org/r/20210518201835.GA1140918@rowland.harvard.edu Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent bc439b4 commit 8d83f10

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎drivers/usb/core/devio.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,12 @@ static int do_proc_bulk(struct usb_dev_state *ps,
12181218
ret = usbfs_increase_memory_usage(len1 + sizeof(struct urb));
12191219
if (ret)
12201220
return ret;
1221-
tbuf = kmalloc(len1, GFP_KERNEL);
1221+
1222+
/*
1223+
* len1 can be almost arbitrarily large. Don't WARN if it's
1224+
* too big, just fail the request.
1225+
*/
1226+
tbuf = kmalloc(len1, GFP_KERNEL | __GFP_NOWARN);
12221227
if (!tbuf) {
12231228
ret = -ENOMEM;
12241229
goto done;
@@ -1696,7 +1701,7 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
16961701
if (num_sgs) {
16971702
as->urb->sg = kmalloc_array(num_sgs,
16981703
sizeof(struct scatterlist),
1699-
GFP_KERNEL);
1704+
GFP_KERNEL | __GFP_NOWARN);
17001705
if (!as->urb->sg) {
17011706
ret = -ENOMEM;
17021707
goto error;
@@ -1731,7 +1736,7 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
17311736
(uurb_start - as->usbm->vm_start);
17321737
} else {
17331738
as->urb->transfer_buffer = kmalloc(uurb->buffer_length,
1734-
GFP_KERNEL);
1739+
GFP_KERNEL | __GFP_NOWARN);
17351740
if (!as->urb->transfer_buffer) {
17361741
ret = -ENOMEM;
17371742
goto error;

0 commit comments

Comments
 (0)