All of lore.kernel.org
 help / color / mirror / Atom feed
* usb/gadget: warning in dev_config/memdup_user
@ 2016-12-02 15:07 Andrey Konovalov
  2016-12-02 15:56 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Andrey Konovalov @ 2016-12-02 15:07 UTC (permalink / raw)
  To: Felipe Balbi, Greg Kroah-Hartman, Marek Szyprowski, Al Viro,
	David Eccher, Arnd Bergmann, Binyamin Sharet, Bin Liu,
	Kirill A. Shutemov, linux-usb, LKML
  Cc: Dmitry Vyukov, Kostya Serebryany, syzkaller

Hi!

I've got the following error report while running the syzkaller fuzzer.

The length passed to memdup_user() directly without limitations.

On commit 2caceb3294a78c389b462e7e236a4e744a53a474 (Dec 1).

WARNING: CPU: 3 PID: 14477 at mm/page_alloc.c:3511
__alloc_pages_nodemask+0x159c/0x1e20
Kernel panic - not syncing: panic_on_warn set ...

CPU: 3 PID: 14477 Comm: syz-executor0 Not tainted 4.9.0-rc7+ #61
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
 ffff880039b67298 ffffffff81f96bba ffffffff00000200 1ffff1000736cde6
 ffffed000736cdde 0000000000000a06 0000000041b58ab3 ffffffff8598af00
 ffffffff81f96928 0000000041b58ab3 ffffffff859423c8 ffffffff81432790
Call Trace:
 [<     inline     >] __dump_stack lib/dump_stack.c:15
 [<ffffffff81f96bba>] dump_stack+0x292/0x398 lib/dump_stack.c:51
 [<ffffffff8168c7ae>] panic+0x1cb/0x3a9 kernel/panic.c:179
 [<ffffffff812b80b4>] __warn+0x1c4/0x1e0 kernel/panic.c:542
 [<ffffffff812b831c>] warn_slowpath_null+0x2c/0x40 kernel/panic.c:585
 [<     inline     >] __alloc_pages_slowpath mm/page_alloc.c:3511
 [<ffffffff816c07cc>] __alloc_pages_nodemask+0x159c/0x1e20 mm/page_alloc.c:3781
 [<ffffffff817cdd27>] alloc_pages_current+0x1c7/0x6b0 mm/mempolicy.c:2072
 [<     inline     >] alloc_pages include/linux/gfp.h:469
 [<ffffffff8172fcdf>] kmalloc_order+0x1f/0x70 mm/slab_common.c:1015
 [<ffffffff8172fd4f>] kmalloc_order_trace+0x1f/0x160 mm/slab_common.c:1026
 [<     inline     >] kmalloc_large include/linux/slab.h:422
 [<ffffffff817e348f>] __kmalloc_track_caller+0x1df/0x290 mm/slub.c:4233
 [<ffffffff8171bb3c>] memdup_user+0x2c/0xa0 mm/util.c:137
 [<ffffffff83228ca2>] dev_config+0x2e2/0x1180
drivers/usb/gadget/legacy/inode.c:1776
 [<ffffffff817fde55>] __vfs_write+0x5d5/0x760 fs/read_write.c:510
 [<ffffffff817ff750>] vfs_write+0x170/0x4e0 fs/read_write.c:560
 [<     inline     >] SYSC_write fs/read_write.c:607
 [<ffffffff81803b5b>] SyS_write+0xfb/0x230 fs/read_write.c:599
 [<ffffffff84f44cc1>] entry_SYSCALL_64_fastpath+0x1f/0xc2
Dumping ftrace buffer:
   (ftrace buffer empty)
Kernel Offset: disabled

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: usb/gadget: warning in dev_config/memdup_user
  2016-12-02 15:07 usb/gadget: warning in dev_config/memdup_user Andrey Konovalov
@ 2016-12-02 15:56 ` Greg Kroah-Hartman
  2016-12-02 16:04   ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2016-12-02 15:56 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Felipe Balbi, Marek Szyprowski, Al Viro, David Eccher,
	Arnd Bergmann, Binyamin Sharet, Bin Liu, Kirill A. Shutemov,
	linux-usb, LKML, Dmitry Vyukov, Kostya Serebryany, syzkaller

On Fri, Dec 02, 2016 at 04:07:38PM +0100, Andrey Konovalov wrote:
> Hi!
> 
> I've got the following error report while running the syzkaller fuzzer.
> 
> The length passed to memdup_user() directly without limitations.
> 
> On commit 2caceb3294a78c389b462e7e236a4e744a53a474 (Dec 1).
> 
> WARNING: CPU: 3 PID: 14477 at mm/page_alloc.c:3511
> __alloc_pages_nodemask+0x159c/0x1e20
> Kernel panic - not syncing: panic_on_warn set ...
> 
> CPU: 3 PID: 14477 Comm: syz-executor0 Not tainted 4.9.0-rc7+ #61
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
>  ffff880039b67298 ffffffff81f96bba ffffffff00000200 1ffff1000736cde6
>  ffffed000736cdde 0000000000000a06 0000000041b58ab3 ffffffff8598af00
>  ffffffff81f96928 0000000041b58ab3 ffffffff859423c8 ffffffff81432790
> Call Trace:
>  [<     inline     >] __dump_stack lib/dump_stack.c:15
>  [<ffffffff81f96bba>] dump_stack+0x292/0x398 lib/dump_stack.c:51
>  [<ffffffff8168c7ae>] panic+0x1cb/0x3a9 kernel/panic.c:179
>  [<ffffffff812b80b4>] __warn+0x1c4/0x1e0 kernel/panic.c:542
>  [<ffffffff812b831c>] warn_slowpath_null+0x2c/0x40 kernel/panic.c:585
>  [<     inline     >] __alloc_pages_slowpath mm/page_alloc.c:3511
>  [<ffffffff816c07cc>] __alloc_pages_nodemask+0x159c/0x1e20 mm/page_alloc.c:3781
>  [<ffffffff817cdd27>] alloc_pages_current+0x1c7/0x6b0 mm/mempolicy.c:2072
>  [<     inline     >] alloc_pages include/linux/gfp.h:469
>  [<ffffffff8172fcdf>] kmalloc_order+0x1f/0x70 mm/slab_common.c:1015
>  [<ffffffff8172fd4f>] kmalloc_order_trace+0x1f/0x160 mm/slab_common.c:1026
>  [<     inline     >] kmalloc_large include/linux/slab.h:422
>  [<ffffffff817e348f>] __kmalloc_track_caller+0x1df/0x290 mm/slub.c:4233
>  [<ffffffff8171bb3c>] memdup_user+0x2c/0xa0 mm/util.c:137
>  [<ffffffff83228ca2>] dev_config+0x2e2/0x1180
> drivers/usb/gadget/legacy/inode.c:1776
>  [<ffffffff817fde55>] __vfs_write+0x5d5/0x760 fs/read_write.c:510
>  [<ffffffff817ff750>] vfs_write+0x170/0x4e0 fs/read_write.c:560
>  [<     inline     >] SYSC_write fs/read_write.c:607
>  [<ffffffff81803b5b>] SyS_write+0xfb/0x230 fs/read_write.c:599
>  [<ffffffff84f44cc1>] entry_SYSCALL_64_fastpath+0x1f/0xc2
> Dumping ftrace buffer:
>    (ftrace buffer empty)
> Kernel Offset: disabled

Oh how nice, we check to ensure that the buffer is not too small, but no
one checks if it is too big :(

Felipe, would a patch like the one below solve this?  If so, I'll resend
it in a "proper" format...

thanks,

greg k-h

---------------------

diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index bd82dd12deff..42f9003b1621 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -1765,6 +1765,10 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 	if (len < (USB_DT_CONFIG_SIZE + USB_DT_DEVICE_SIZE + 4))
 		return -EINVAL;
 
+	/* No one needs more than 64k... */
+	if (len > PAGE_SIZE * 8)
+		return -EINVAL;
+
 	/* we might need to change message format someday */
 	if (copy_from_user (&tag, buf, 4))
 		return -EFAULT;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: usb/gadget: warning in dev_config/memdup_user
  2016-12-02 15:56 ` Greg Kroah-Hartman
@ 2016-12-02 16:04   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2016-12-02 16:04 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Felipe Balbi, Marek Szyprowski, Al Viro, David Eccher,
	Arnd Bergmann, Binyamin Sharet, Bin Liu, Kirill A. Shutemov,
	linux-usb, LKML, Dmitry Vyukov, Kostya Serebryany, syzkaller

On Fri, Dec 02, 2016 at 04:56:15PM +0100, Greg Kroah-Hartman wrote:
> On Fri, Dec 02, 2016 at 04:07:38PM +0100, Andrey Konovalov wrote:
> > Hi!
> > 
> > I've got the following error report while running the syzkaller fuzzer.
> > 
> > The length passed to memdup_user() directly without limitations.
> > 
> > On commit 2caceb3294a78c389b462e7e236a4e744a53a474 (Dec 1).
> > 
> > WARNING: CPU: 3 PID: 14477 at mm/page_alloc.c:3511
> > __alloc_pages_nodemask+0x159c/0x1e20
> > Kernel panic - not syncing: panic_on_warn set ...
> > 
> > CPU: 3 PID: 14477 Comm: syz-executor0 Not tainted 4.9.0-rc7+ #61
> > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
> >  ffff880039b67298 ffffffff81f96bba ffffffff00000200 1ffff1000736cde6
> >  ffffed000736cdde 0000000000000a06 0000000041b58ab3 ffffffff8598af00
> >  ffffffff81f96928 0000000041b58ab3 ffffffff859423c8 ffffffff81432790
> > Call Trace:
> >  [<     inline     >] __dump_stack lib/dump_stack.c:15
> >  [<ffffffff81f96bba>] dump_stack+0x292/0x398 lib/dump_stack.c:51
> >  [<ffffffff8168c7ae>] panic+0x1cb/0x3a9 kernel/panic.c:179
> >  [<ffffffff812b80b4>] __warn+0x1c4/0x1e0 kernel/panic.c:542
> >  [<ffffffff812b831c>] warn_slowpath_null+0x2c/0x40 kernel/panic.c:585
> >  [<     inline     >] __alloc_pages_slowpath mm/page_alloc.c:3511
> >  [<ffffffff816c07cc>] __alloc_pages_nodemask+0x159c/0x1e20 mm/page_alloc.c:3781
> >  [<ffffffff817cdd27>] alloc_pages_current+0x1c7/0x6b0 mm/mempolicy.c:2072
> >  [<     inline     >] alloc_pages include/linux/gfp.h:469
> >  [<ffffffff8172fcdf>] kmalloc_order+0x1f/0x70 mm/slab_common.c:1015
> >  [<ffffffff8172fd4f>] kmalloc_order_trace+0x1f/0x160 mm/slab_common.c:1026
> >  [<     inline     >] kmalloc_large include/linux/slab.h:422
> >  [<ffffffff817e348f>] __kmalloc_track_caller+0x1df/0x290 mm/slub.c:4233
> >  [<ffffffff8171bb3c>] memdup_user+0x2c/0xa0 mm/util.c:137
> >  [<ffffffff83228ca2>] dev_config+0x2e2/0x1180
> > drivers/usb/gadget/legacy/inode.c:1776
> >  [<ffffffff817fde55>] __vfs_write+0x5d5/0x760 fs/read_write.c:510
> >  [<ffffffff817ff750>] vfs_write+0x170/0x4e0 fs/read_write.c:560
> >  [<     inline     >] SYSC_write fs/read_write.c:607
> >  [<ffffffff81803b5b>] SyS_write+0xfb/0x230 fs/read_write.c:599
> >  [<ffffffff84f44cc1>] entry_SYSCALL_64_fastpath+0x1f/0xc2
> > Dumping ftrace buffer:
> >    (ftrace buffer empty)
> > Kernel Offset: disabled
> 
> Oh how nice, we check to ensure that the buffer is not too small, but no
> one checks if it is too big :(
> 
> Felipe, would a patch like the one below solve this?  If so, I'll resend
> it in a "proper" format...
> 
> thanks,
> 
> greg k-h
> 
> ---------------------
> 
> diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
> index bd82dd12deff..42f9003b1621 100644
> --- a/drivers/usb/gadget/legacy/inode.c
> +++ b/drivers/usb/gadget/legacy/inode.c
> @@ -1765,6 +1765,10 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
>  	if (len < (USB_DT_CONFIG_SIZE + USB_DT_DEVICE_SIZE + 4))
>  		return -EINVAL;
>  
> +	/* No one needs more than 64k... */
> +	if (len > PAGE_SIZE * 8)
> +		return -EINVAL;

That's what I get for trying to be cute with comments right after a long
lunch, the math is wrong...  But the main concept should be sane.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-12-02 16:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-02 15:07 usb/gadget: warning in dev_config/memdup_user Andrey Konovalov
2016-12-02 15:56 ` Greg Kroah-Hartman
2016-12-02 16:04   ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.