KASAN: invalid-free in hub_event

10 views
Skip to first unread message

syzbot

unread,
Nov 26, 2018, 9:55:04 AM11/26/18
to drin...@chromium.org, felipe...@linux.intel.com, gre...@linuxfoundation.org, jf...@chromium.org, j...@perches.com, kai.he...@canonical.com, linux-...@vger.kernel.org, linu...@vger.kernel.org, mathia...@linux.intel.com, st...@rowland.harvard.edu, syzkall...@googlegroups.com
Hello,

syzbot found the following crash on:

HEAD commit: d6d460b89378 Merge tag 'dma-mapping-4.20-3' of git://git.i..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17bd99eb400000
kernel config: https://syzkaller.appspot.com/x/.config?x=73e2bc0cb6463446
dashboard link: https://syzkaller.appspot.com/bug?extid=98881958e1410ec7e53c
compiler: gcc (GCC) 8.0.1 20180413 (experimental)

Unfortunately, I don't have any reproducer for this crash yet.

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+988819...@syzkaller.appspotmail.com

erofs: read_super, device -> /dev/loop5
erofs: options ->
nouser_xattr,fault_injection=0x00000000000007ff,fowner>00000000000000000000,uid<00000000000000000000,subj_type=ntfs
erofs: cannot find valid erofs superblock
vhci_hcd: default hub control req: 0080 v0400 i0000 l0
==================================================================
BUG: KASAN: double-free or invalid-free in port_over_current_notify
drivers/usb/core/hub.c:5192 [inline]
BUG: KASAN: double-free or invalid-free in port_event
drivers/usb/core/hub.c:5241 [inline]
BUG: KASAN: double-free or invalid-free in hub_event+0xd97/0x4140
drivers/usb/core/hub.c:5384

CPU: 1 PID: 32710 Comm: kworker/1:3 Not tainted 4.20.0-rc3+ #129
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Workqueue: usb_hub_wq hub_event
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x244/0x39d lib/dump_stack.c:113
print_address_description.cold.7+0x9/0x1ff mm/kasan/report.c:256
kasan_report_invalid_free+0x64/0xa0 mm/kasan/report.c:336
__kasan_slab_free+0x13a/0x150 mm/kasan/kasan.c:501
kasan_slab_free+0xe/0x10 mm/kasan/kasan.c:528
__cache_free mm/slab.c:3498 [inline]
kfree+0xcf/0x230 mm/slab.c:3817
port_over_current_notify drivers/usb/core/hub.c:5192 [inline]
port_event drivers/usb/core/hub.c:5241 [inline]
hub_event+0xd97/0x4140 drivers/usb/core/hub.c:5384
process_one_work+0xc90/0x1c40 kernel/workqueue.c:2153
worker_thread+0x17f/0x1390 kernel/workqueue.c:2296
kthread+0x35a/0x440 kernel/kthread.c:246
ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352

Allocated by task 32710:
save_stack+0x43/0xd0 mm/kasan/kasan.c:448
set_track mm/kasan/kasan.c:460 [inline]
kasan_kmalloc+0xc7/0xe0 mm/kasan/kasan.c:553
__do_kmalloc mm/slab.c:3722 [inline]
__kmalloc_track_caller+0x157/0x760 mm/slab.c:3737
kvasprintf+0xb5/0x150 lib/kasprintf.c:25
kasprintf+0xab/0xe0 lib/kasprintf.c:59
port_over_current_notify drivers/usb/core/hub.c:5185 [inline]
port_event drivers/usb/core/hub.c:5241 [inline]
hub_event+0xd5e/0x4140 drivers/usb/core/hub.c:5384
process_one_work+0xc90/0x1c40 kernel/workqueue.c:2153
worker_thread+0x17f/0x1390 kernel/workqueue.c:2296
kthread+0x35a/0x440 kernel/kthread.c:246
ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352

Freed by task 32580:
save_stack+0x43/0xd0 mm/kasan/kasan.c:448
set_track mm/kasan/kasan.c:460 [inline]
__kasan_slab_free+0x102/0x150 mm/kasan/kasan.c:521
kasan_slab_free+0xe/0x10 mm/kasan/kasan.c:528
__cache_free mm/slab.c:3498 [inline]
kfree+0xcf/0x230 mm/slab.c:3817
port_over_current_notify drivers/usb/core/hub.c:5192 [inline]
port_event drivers/usb/core/hub.c:5241 [inline]
hub_event+0xd97/0x4140 drivers/usb/core/hub.c:5384
process_one_work+0xc90/0x1c40 kernel/workqueue.c:2153
worker_thread+0x17f/0x1390 kernel/workqueue.c:2296
kthread+0x35a/0x440 kernel/kthread.c:246
ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352

The buggy address belongs to the object at ffff8881bf0d01c0
which belongs to the cache kmalloc-32 of size 32
The buggy address is located 0 bytes inside of
32-byte region [ffff8881bf0d01c0, ffff8881bf0d01e0)
The buggy address belongs to the page:
page:ffffea0006fc3400 count:1 mapcount:0 mapping:ffff8881da8001c0
index:0xffff8881bf0d0fc1
flags: 0x2fffc0000000200(slab)
raw: 02fffc0000000200 ffffea00074d4b88 ffffea0007528bc8 ffff8881da8001c0
raw: ffff8881bf0d0fc1 ffff8881bf0d0000 000000010000003d 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff8881bf0d0080: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
ffff8881bf0d0100: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
> ffff8881bf0d0180: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
^
ffff8881bf0d0200: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
ffff8881bf0d0280: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
==================================================================


---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#bug-status-tracking for how to communicate with
syzbot.

Alan Stern

unread,
Nov 28, 2018, 11:25:59 AM11/28/18
to Greg KH, syzbot, drin...@chromium.org, jf...@chromium.org, j...@perches.com, Kernel development list, USB list, syzkall...@googlegroups.com
Syzbot and KASAN found the following invalid-free bug in
port_over_current_notify():

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

The problem is caused by use of a static array to store
environment-string pointers. When the routine is called by multiple
threads concurrently, the pointers from one thread can overwrite those
from another.

The solution is to use an ordinary automatic array instead of a static
array.

Signed-off-by: Alan Stern <st...@rowland.harvard.edu>
Reported-by: syzbot+988819...@syzkaller.appspotmail.com

---


[as1881]


drivers/usb/core/hub.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

Index: usb-4.x/drivers/usb/core/hub.c
===================================================================
--- usb-4.x.orig/drivers/usb/core/hub.c
+++ usb-4.x/drivers/usb/core/hub.c
@@ -5163,7 +5163,7 @@ static void hub_port_connect_change(stru
/* Handle notifying userspace about hub over-current events */
static void port_over_current_notify(struct usb_port *port_dev)
{
- static char *envp[] = { NULL, NULL, NULL };
+ char *envp[3];
struct device *hub_dev;
char *port_dev_path;

@@ -5187,6 +5187,7 @@ static void port_over_current_notify(str
if (!envp[1])
goto exit;

+ envp[2] = NULL;
kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp);

kfree(envp[1]);

Reply all
Reply to author
Forward
0 new messages