* [syzbot] KASAN: use-after-free Read in r871xu_dev_remove
@ 2021-07-13 3:14 syzbot
2021-07-13 8:55 ` Pavel Skripkin
2021-07-21 10:01 ` Pavel Skripkin
0 siblings, 2 replies; 8+ messages in thread
From: syzbot @ 2021-07-13 3:14 UTC (permalink / raw)
To: Larry.Finger, florian.c.schilhabel, gregkh, hridayhegde1999,
linux-kernel, linux-staging, paskripkin, rkovhaev, straube.linux,
syzkaller-bugs
Hello,
syzbot found the following issue on:
HEAD commit: 92510a7f Add linux-next specific files for 20210709
git tree: linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=16c50180300000
kernel config: https://syzkaller.appspot.com/x/.config?x=505de2716f052686
dashboard link: https://syzkaller.appspot.com/bug?extid=5872a520e0ce0a7c7230
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1639a73c300000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=15fcd5e4300000
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+5872a520e0ce0a7c7230@syzkaller.appspotmail.com
usb 1-1: USB disconnect, device number 14
==================================================================
BUG: KASAN: use-after-free in __lock_acquire+0x3d86/0x54a0 kernel/locking/lockdep.c:4885
Read of size 8 at addr ffff888038bbce28 by task kworker/1:2/4393
CPU: 1 PID: 4393 Comm: kworker/1:2 Not tainted 5.13.0-next-20210709-syzkaller #0
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:88 [inline]
dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:105
print_address_description.constprop.0.cold+0x6c/0x309 mm/kasan/report.c:233
__kasan_report mm/kasan/report.c:419 [inline]
kasan_report.cold+0x83/0xdf mm/kasan/report.c:436
__lock_acquire+0x3d86/0x54a0 kernel/locking/lockdep.c:4885
lock_acquire kernel/locking/lockdep.c:5625 [inline]
lock_acquire+0x1ab/0x510 kernel/locking/lockdep.c:5590
__raw_spin_lock_irq include/linux/spinlock_api_smp.h:128 [inline]
_raw_spin_lock_irq+0x32/0x50 kernel/locking/spinlock.c:167
do_wait_for_common kernel/sched/completion.c:86 [inline]
__wait_for_common kernel/sched/completion.c:106 [inline]
wait_for_common kernel/sched/completion.c:117 [inline]
wait_for_completion+0x181/0x280 kernel/sched/completion.c:138
r871xu_dev_remove+0x80/0x320 drivers/staging/rtl8712/usb_intf.c:599
usb_unbind_interface+0x1d8/0x8d0 drivers/usb/core/driver.c:458
__device_release_driver+0x3bd/0x6f0 drivers/base/dd.c:1201
device_release_driver_internal drivers/base/dd.c:1232 [inline]
device_release_driver+0x26/0x40 drivers/base/dd.c:1255
bus_remove_device+0x2eb/0x5a0 drivers/base/bus.c:529
device_del+0x502/0xd40 drivers/base/core.c:3544
usb_disable_device+0x35b/0x7b0 drivers/usb/core/message.c:1419
usb_disconnect.cold+0x27a/0x78e drivers/usb/core/hub.c:2221
hub_port_connect drivers/usb/core/hub.c:5151 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5440 [inline]
port_event drivers/usb/core/hub.c:5586 [inline]
hub_event+0x1c9c/0x4330 drivers/usb/core/hub.c:5668
process_one_work+0x98d/0x1630 kernel/workqueue.c:2276
worker_thread+0x658/0x11f0 kernel/workqueue.c:2422
kthread+0x3e5/0x4d0 kernel/kthread.c:319
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295
Allocated by task 4860:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
kasan_set_track mm/kasan/common.c:46 [inline]
set_alloc_info mm/kasan/common.c:434 [inline]
__kasan_slab_alloc+0x84/0xa0 mm/kasan/common.c:467
kasan_slab_alloc include/linux/kasan.h:253 [inline]
slab_post_alloc_hook mm/slab.h:512 [inline]
slab_alloc_node mm/slub.c:2981 [inline]
slab_alloc mm/slub.c:2989 [inline]
kmem_cache_alloc+0x216/0x3a0 mm/slub.c:2994
getname_flags.part.0+0x50/0x4f0 fs/namei.c:138
getname_flags fs/namei.c:2747 [inline]
user_path_at_empty+0xa1/0x100 fs/namei.c:2747
user_path_at include/linux/namei.h:57 [inline]
vfs_statx+0x142/0x390 fs/stat.c:203
vfs_fstatat fs/stat.c:225 [inline]
vfs_lstat include/linux/fs.h:3426 [inline]
__do_sys_newlstat+0x91/0x110 fs/stat.c:380
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
Freed by task 4860:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
kasan_set_track+0x1c/0x30 mm/kasan/common.c:46
kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:360
____kasan_slab_free mm/kasan/common.c:366 [inline]
____kasan_slab_free mm/kasan/common.c:328 [inline]
__kasan_slab_free+0xfb/0x130 mm/kasan/common.c:374
kasan_slab_free include/linux/kasan.h:229 [inline]
slab_free_hook mm/slub.c:1650 [inline]
slab_free_freelist_hook+0xdf/0x240 mm/slub.c:1675
slab_free mm/slub.c:3235 [inline]
kmem_cache_free+0x8e/0x5a0 mm/slub.c:3251
putname+0xe1/0x120 fs/namei.c:259
filename_lookup+0x3df/0x5b0 fs/namei.c:2477
user_path_at include/linux/namei.h:57 [inline]
vfs_statx+0x142/0x390 fs/stat.c:203
vfs_fstatat fs/stat.c:225 [inline]
vfs_lstat include/linux/fs.h:3426 [inline]
__do_sys_newlstat+0x91/0x110 fs/stat.c:380
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
The buggy address belongs to the object at ffff888038bbc400
which belongs to the cache names_cache of size 4096
The buggy address is located 2600 bytes inside of
4096-byte region [ffff888038bbc400, ffff888038bbd400)
The buggy address belongs to the page:
page:ffffea0000e2ee00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x38bb8
head:ffffea0000e2ee00 order:3 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 0000000000000000 dead000000000122 ffff8880109c43c0
raw: 0000000000000000 0000000000070007 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 4860, ts 1160993662069, free_ts 1160991389825
prep_new_page mm/page_alloc.c:2444 [inline]
get_page_from_freelist+0xa72/0x2f80 mm/page_alloc.c:4177
__alloc_pages+0x1b2/0x500 mm/page_alloc.c:5385
alloc_pages+0x18c/0x2a0 mm/mempolicy.c:2244
alloc_slab_page mm/slub.c:1713 [inline]
allocate_slab+0x32b/0x4c0 mm/slub.c:1853
new_slab mm/slub.c:1916 [inline]
new_slab_objects mm/slub.c:2662 [inline]
___slab_alloc+0x4ba/0x820 mm/slub.c:2825
__slab_alloc.constprop.0+0xa7/0xf0 mm/slub.c:2865
slab_alloc_node mm/slub.c:2947 [inline]
slab_alloc mm/slub.c:2989 [inline]
kmem_cache_alloc+0x372/0x3a0 mm/slub.c:2994
getname_flags.part.0+0x50/0x4f0 fs/namei.c:138
getname_flags fs/namei.c:2747 [inline]
user_path_at_empty+0xa1/0x100 fs/namei.c:2747
user_path_at include/linux/namei.h:57 [inline]
vfs_statx+0x142/0x390 fs/stat.c:203
vfs_fstatat fs/stat.c:225 [inline]
vfs_lstat include/linux/fs.h:3426 [inline]
__do_sys_newlstat+0x91/0x110 fs/stat.c:380
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1354 [inline]
free_pcp_prepare+0x312/0x7d0 mm/page_alloc.c:1405
free_unref_page_prepare mm/page_alloc.c:3340 [inline]
free_unref_page+0x19/0x690 mm/page_alloc.c:3419
kvfree+0x42/0x50 mm/util.c:616
netdev_freemem net/core/dev.c:10778 [inline]
free_netdev+0x495/0x5b0 net/core/dev.c:10956
rtl871x_load_fw_cb drivers/staging/rtl8712/hal_init.c:46 [inline]
rtl871x_load_fw_cb.cold+0xf7/0x117 drivers/staging/rtl8712/hal_init.c:32
request_firmware_work_func+0x12c/0x230 drivers/base/firmware_loader/main.c:1081
process_one_work+0x98d/0x1630 kernel/workqueue.c:2276
worker_thread+0x658/0x11f0 kernel/workqueue.c:2422
kthread+0x3e5/0x4d0 kernel/kthread.c:319
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295
Memory state around the buggy address:
ffff888038bbcd00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888038bbcd80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888038bbce00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888038bbce80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888038bbcf00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
---
This report 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 syzkaller@googlegroups.com.
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this issue, for details see:
https://goo.gl/tpsmEJ#testing-patches
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [syzbot] KASAN: use-after-free Read in r871xu_dev_remove 2021-07-13 3:14 [syzbot] KASAN: use-after-free Read in r871xu_dev_remove syzbot @ 2021-07-13 8:55 ` Pavel Skripkin 2021-07-13 9:04 ` Dongliang Mu 2021-07-13 11:07 ` syzbot 2021-07-21 10:01 ` Pavel Skripkin 1 sibling, 2 replies; 8+ messages in thread From: Pavel Skripkin @ 2021-07-13 8:55 UTC (permalink / raw) To: syzbot Cc: Larry.Finger, florian.c.schilhabel, gregkh, hridayhegde1999, linux-kernel, linux-staging, rkovhaev, straube.linux, syzkaller-bugs [-- Attachment #1: Type: text/plain, Size: 1065 bytes --] On Mon, 12 Jul 2021 20:14:24 -0700 syzbot <syzbot+5872a520e0ce0a7c7230@syzkaller.appspotmail.com> wrote: > Hello, > > syzbot found the following issue on: > > HEAD commit: 92510a7f Add linux-next specific files for 20210709 > git tree: linux-next > console output: > https://syzkaller.appspot.com/x/log.txt?x=16c50180300000 kernel > config: https://syzkaller.appspot.com/x/.config?x=505de2716f052686 > dashboard link: > https://syzkaller.appspot.com/bug?extid=5872a520e0ce0a7c7230 syz > repro: > https://syzkaller.appspot.com/x/repro.syz?x=1639a73c300000 C > reproducer: https://syzkaller.appspot.com/x/repro.c?x=15fcd5e4300000 > > IMPORTANT: if you fix the issue, please add the following tag to the > commit: Reported-by: > syzbot+5872a520e0ce0a7c7230@syzkaller.appspotmail.com > Hmm, bisection is wrong this time. It should be e02a3b945816 ("staging: rtl8712: fix memory leak in rtl871x_load_fw_cb") #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master I guess, this should work With regards, Pavel Skripkin [-- Attachment #2: 0001-staging-rtl8712-fix-UAF-in-r871xu_dev_remove.patch --] [-- Type: text/x-patch, Size: 901 bytes --] From 954ffa9067907a5f6d4d6d2b72a98b8773cac11e Mon Sep 17 00:00:00 2001 From: Pavel Skripkin <paskripkin@gmail.com> Date: Tue, 13 Jul 2021 11:52:17 +0300 Subject: [PATCH] staging: rtl8712: fix UAF in r871xu_dev_remove /* .... */ Signed-off-by: Pavel Skripkin <paskripkin@gmail.com> --- drivers/staging/rtl8712/hal_init.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/staging/rtl8712/hal_init.c b/drivers/staging/rtl8712/hal_init.c index 22974277afa0..c06d31784cd4 100644 --- a/drivers/staging/rtl8712/hal_init.c +++ b/drivers/staging/rtl8712/hal_init.c @@ -43,6 +43,7 @@ static void rtl871x_load_fw_cb(const struct firmware *firmware, void *context) r8712_free_drv_sw(adapter); adapter->dvobj_deinit(adapter); complete(&adapter->rtl8712_fw_ready); + shedule(); /* to not trigger UAF in wait_for_completion() */ free_netdev(adapter->pnetdev); return; } -- 2.32.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [syzbot] KASAN: use-after-free Read in r871xu_dev_remove 2021-07-13 8:55 ` Pavel Skripkin @ 2021-07-13 9:04 ` Dongliang Mu 2021-07-13 9:19 ` Pavel Skripkin 2021-07-13 11:07 ` syzbot 1 sibling, 1 reply; 8+ messages in thread From: Dongliang Mu @ 2021-07-13 9:04 UTC (permalink / raw) To: Pavel Skripkin Cc: syzbot, Larry.Finger, florian.c.schilhabel, Greg KH, hridayhegde1999, linux-kernel, linux-staging, rkovhaev, straube.linux, syzkaller-bugs On Tue, Jul 13, 2021 at 4:55 PM Pavel Skripkin <paskripkin@gmail.com> wrote: > > On Mon, 12 Jul 2021 20:14:24 -0700 > syzbot <syzbot+5872a520e0ce0a7c7230@syzkaller.appspotmail.com> wrote: > > > Hello, > > > > syzbot found the following issue on: > > > > HEAD commit: 92510a7f Add linux-next specific files for 20210709 > > git tree: linux-next > > console output: > > https://syzkaller.appspot.com/x/log.txt?x=16c50180300000 kernel > > config: https://syzkaller.appspot.com/x/.config?x=505de2716f052686 > > dashboard link: > > https://syzkaller.appspot.com/bug?extid=5872a520e0ce0a7c7230 syz > > repro: > > https://syzkaller.appspot.com/x/repro.syz?x=1639a73c300000 C > > reproducer: https://syzkaller.appspot.com/x/repro.c?x=15fcd5e4300000 > > > > IMPORTANT: if you fix the issue, please add the following tag to the > > commit: Reported-by: > > syzbot+5872a520e0ce0a7c7230@syzkaller.appspotmail.com > > > > Hmm, bisection is wrong this time. It should be > e02a3b945816 ("staging: rtl8712: fix memory leak in rtl871x_load_fw_cb") Hi Paval, can you share more details about why the patch e02a3b945816 causes this UAF problem? > > #syz test: > git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master > > > I guess, this should work > > > With regards, > Pavel Skripkin > > -- > You received this message because you are subscribed to the Google Groups "syzkaller-bugs" group. > To unsubscribe from this group and stop receiving emails from it, send an email to syzkaller-bugs+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/syzkaller-bugs/20210713115546.34c99ea8%40gmail.com. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [syzbot] KASAN: use-after-free Read in r871xu_dev_remove 2021-07-13 9:04 ` Dongliang Mu @ 2021-07-13 9:19 ` Pavel Skripkin 2021-07-13 11:18 ` syzbot 0 siblings, 1 reply; 8+ messages in thread From: Pavel Skripkin @ 2021-07-13 9:19 UTC (permalink / raw) To: Dongliang Mu Cc: syzbot, Larry.Finger, florian.c.schilhabel, Greg KH, hridayhegde1999, linux-kernel, linux-staging, rkovhaev, straube.linux, syzkaller-bugs [-- Attachment #1: Type: text/plain, Size: 2337 bytes --] On Tue, 13 Jul 2021 17:04:28 +0800 Dongliang Mu <mudongliangabcd@gmail.com> wrote: > On Tue, Jul 13, 2021 at 4:55 PM Pavel Skripkin <paskripkin@gmail.com> > wrote: > > > > On Mon, 12 Jul 2021 20:14:24 -0700 > > syzbot <syzbot+5872a520e0ce0a7c7230@syzkaller.appspotmail.com> > > wrote: > > > > > Hello, > > > > > > syzbot found the following issue on: > > > > > > HEAD commit: 92510a7f Add linux-next specific files for > > > 20210709 git tree: linux-next > > > console output: > > > https://syzkaller.appspot.com/x/log.txt?x=16c50180300000 kernel > > > config: > > > https://syzkaller.appspot.com/x/.config?x=505de2716f052686 > > > dashboard link: > > > https://syzkaller.appspot.com/bug?extid=5872a520e0ce0a7c7230 syz > > > repro: https://syzkaller.appspot.com/x/repro.syz?x=1639a73c300000 > > > C reproducer: > > > https://syzkaller.appspot.com/x/repro.c?x=15fcd5e4300000 > > > > > > IMPORTANT: if you fix the issue, please add the following tag to > > > the commit: Reported-by: > > > syzbot+5872a520e0ce0a7c7230@syzkaller.appspotmail.com > > > > > > > Hmm, bisection is wrong this time. It should be > > e02a3b945816 ("staging: rtl8712: fix memory leak in > > rtl871x_load_fw_cb") > > Hi Paval, > ^^^^^ Pavel :) > can you share more details about why the patch e02a3b945816 causes > this UAF problem? > I am not sure, but I think, that free_netdev() call rigth after complete() can cause use-after-free bug in wait_for_completion() since rtl8712_fw_ready is allocated as netdev private data. I guess, schedule() call after complete() can help here. BTW, I send wrong patch in previous email: typo in schedule() :) #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master > > > > #syz test: > > git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git > > master > > > > > > I guess, this should work > > > > > > With regards, > > Pavel Skripkin > > > > -- > > You received this message because you are subscribed to the Google > > Groups "syzkaller-bugs" group. To unsubscribe from this group and > > stop receiving emails from it, send an email to > > syzkaller-bugs+unsubscribe@googlegroups.com. To view this > > discussion on the web visit > > https://groups.google.com/d/msgid/syzkaller-bugs/20210713115546.34c99ea8%40gmail.com. With regards, Pavel Skripkin [-- Attachment #2: 0001-staging-rtl8712-fix-UAF-in-r871xu_dev_remove.patch --] [-- Type: text/x-patch, Size: 902 bytes --] From 4c25accd0fc806687142aadeaa5b19805289ac74 Mon Sep 17 00:00:00 2001 From: Pavel Skripkin <paskripkin@gmail.com> Date: Tue, 13 Jul 2021 11:52:17 +0300 Subject: [PATCH] staging: rtl8712: fix UAF in r871xu_dev_remove /* .... */ Signed-off-by: Pavel Skripkin <paskripkin@gmail.com> --- drivers/staging/rtl8712/hal_init.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/staging/rtl8712/hal_init.c b/drivers/staging/rtl8712/hal_init.c index 22974277afa0..e81c66cc8580 100644 --- a/drivers/staging/rtl8712/hal_init.c +++ b/drivers/staging/rtl8712/hal_init.c @@ -43,6 +43,7 @@ static void rtl871x_load_fw_cb(const struct firmware *firmware, void *context) r8712_free_drv_sw(adapter); adapter->dvobj_deinit(adapter); complete(&adapter->rtl8712_fw_ready); + schedule(); /* to not trigger UAF in wait_for_completion() */ free_netdev(adapter->pnetdev); return; } -- 2.32.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [syzbot] KASAN: use-after-free Read in r871xu_dev_remove 2021-07-13 9:19 ` Pavel Skripkin @ 2021-07-13 11:18 ` syzbot 0 siblings, 0 replies; 8+ messages in thread From: syzbot @ 2021-07-13 11:18 UTC (permalink / raw) To: Larry.Finger, florian.c.schilhabel, gregkh, hridayhegde1999, linux-kernel, linux-staging, mudongliangabcd, paskripkin, rkovhaev, straube.linux, syzkaller-bugs Hello, syzbot has tested the proposed patch but the reproducer is still triggering an issue: KASAN: slab-out-of-bounds Read in r871xu_dev_remove ================================================================== BUG: KASAN: slab-out-of-bounds in debug_spin_lock_before kernel/locking/spinlock_debug.c:83 [inline] BUG: KASAN: slab-out-of-bounds in do_raw_spin_lock+0x262/0x2b0 kernel/locking/spinlock_debug.c:112 Read of size 4 at addr ffff88802f7ace14 by task kworker/0:0/5 CPU: 0 PID: 5 Comm: kworker/0:0 Tainted: G W 5.14.0-rc1-next-20210713-syzkaller #0 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:88 [inline] dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:105 print_address_description.constprop.0.cold+0x6c/0x309 mm/kasan/report.c:233 __kasan_report mm/kasan/report.c:419 [inline] kasan_report.cold+0x83/0xdf mm/kasan/report.c:436 debug_spin_lock_before kernel/locking/spinlock_debug.c:83 [inline] do_raw_spin_lock+0x262/0x2b0 kernel/locking/spinlock_debug.c:112 do_wait_for_common kernel/sched/completion.c:86 [inline] __wait_for_common kernel/sched/completion.c:106 [inline] wait_for_common kernel/sched/completion.c:117 [inline] wait_for_completion+0x181/0x280 kernel/sched/completion.c:138 r871xu_dev_remove+0x80/0x320 drivers/staging/rtl8712/usb_intf.c:599 usb_unbind_interface+0x1d8/0x8d0 drivers/usb/core/driver.c:458 __device_release_driver+0x3bd/0x6f0 drivers/base/dd.c:1201 device_release_driver_internal drivers/base/dd.c:1232 [inline] device_release_driver+0x26/0x40 drivers/base/dd.c:1255 bus_remove_device+0x2eb/0x5a0 drivers/base/bus.c:529 device_del+0x502/0xd40 drivers/base/core.c:3544 usb_disable_device+0x35b/0x7b0 drivers/usb/core/message.c:1419 usb_disconnect.cold+0x27a/0x78e drivers/usb/core/hub.c:2221 hub_port_connect drivers/usb/core/hub.c:5151 [inline] hub_port_connect_change drivers/usb/core/hub.c:5440 [inline] port_event drivers/usb/core/hub.c:5586 [inline] hub_event+0x1c9c/0x4330 drivers/usb/core/hub.c:5668 process_one_work+0x98d/0x1630 kernel/workqueue.c:2276 worker_thread+0x658/0x11f0 kernel/workqueue.c:2422 kthread+0x3e5/0x4d0 kernel/kthread.c:319 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295 Allocated by task 10657: kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38 kasan_set_track mm/kasan/common.c:46 [inline] set_alloc_info mm/kasan/common.c:434 [inline] ____kasan_kmalloc mm/kasan/common.c:513 [inline] ____kasan_kmalloc mm/kasan/common.c:472 [inline] __kasan_kmalloc+0x9b/0xd0 mm/kasan/common.c:522 kmalloc include/linux/slab.h:596 [inline] tomoyo_realpath_from_path+0xc3/0x620 security/tomoyo/realpath.c:254 tomoyo_get_realpath security/tomoyo/file.c:151 [inline] tomoyo_path_number_perm+0x1d5/0x590 security/tomoyo/file.c:723 security_file_ioctl+0x50/0xb0 security/security.c:1539 __do_sys_ioctl fs/ioctl.c:1063 [inline] __se_sys_ioctl fs/ioctl.c:1055 [inline] __x64_sys_ioctl+0xb3/0x200 fs/ioctl.c:1055 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae Freed by task 10657: kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38 kasan_set_track+0x1c/0x30 mm/kasan/common.c:46 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:360 ____kasan_slab_free mm/kasan/common.c:366 [inline] ____kasan_slab_free mm/kasan/common.c:328 [inline] __kasan_slab_free+0xfb/0x130 mm/kasan/common.c:374 kasan_slab_free include/linux/kasan.h:229 [inline] slab_free_hook mm/slub.c:1650 [inline] slab_free_freelist_hook+0xdf/0x240 mm/slub.c:1675 slab_free mm/slub.c:3235 [inline] kfree+0xeb/0x650 mm/slub.c:4295 tomoyo_realpath_from_path+0x191/0x620 security/tomoyo/realpath.c:291 tomoyo_get_realpath security/tomoyo/file.c:151 [inline] tomoyo_path_number_perm+0x1d5/0x590 security/tomoyo/file.c:723 security_file_ioctl+0x50/0xb0 security/security.c:1539 __do_sys_ioctl fs/ioctl.c:1063 [inline] __se_sys_ioctl fs/ioctl.c:1055 [inline] __x64_sys_ioctl+0xb3/0x200 fs/ioctl.c:1055 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae The buggy address belongs to the object at ffff88802f7ac000 which belongs to the cache kmalloc-4k of size 4096 The buggy address is located 3604 bytes inside of 4096-byte region [ffff88802f7ac000, ffff88802f7ad000) The buggy address belongs to the page: page:ffffea0000bdea00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x2f7a8 head:ffffea0000bdea00 order:3 compound_mapcount:0 compound_pincount:0 flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff) raw: 00fff00000010200 0000000000000000 dead000000000122 ffff888010842140 raw: 0000000000000000 0000000000040004 00000001ffffffff 0000000000000000 page dumped because: kasan: bad access detected page_owner tracks the page as allocated page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 59, ts 93061328154, free_ts 93052725619 prep_new_page mm/page_alloc.c:2433 [inline] get_page_from_freelist+0xa72/0x2f80 mm/page_alloc.c:4166 __alloc_pages+0x1b2/0x500 mm/page_alloc.c:5374 alloc_pages+0x18c/0x2a0 mm/mempolicy.c:2244 alloc_slab_page mm/slub.c:1713 [inline] allocate_slab+0x32b/0x4c0 mm/slub.c:1853 new_slab mm/slub.c:1916 [inline] new_slab_objects mm/slub.c:2662 [inline] ___slab_alloc+0x4ba/0x820 mm/slub.c:2825 __slab_alloc.constprop.0+0xa7/0xf0 mm/slub.c:2865 slab_alloc_node mm/slub.c:2947 [inline] slab_alloc mm/slub.c:2989 [inline] kmem_cache_alloc_trace+0x30f/0x3c0 mm/slub.c:3006 kmalloc include/linux/slab.h:591 [inline] kzalloc include/linux/slab.h:721 [inline] kobject_uevent_env+0x240/0x1650 lib/kobject_uevent.c:524 driver_bound+0x1a8/0x300 drivers/base/dd.c:401 really_probe+0x3d8/0xcd0 drivers/base/dd.c:643 __driver_probe_device+0x338/0x4d0 drivers/base/dd.c:747 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:777 __device_attach_driver+0x20b/0x2f0 drivers/base/dd.c:894 bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:427 __device_attach+0x228/0x4a0 drivers/base/dd.c:965 bus_probe_device+0x1e4/0x290 drivers/base/bus.c:487 page last free stack trace: reset_page_owner include/linux/page_owner.h:24 [inline] free_pages_prepare mm/page_alloc.c:1343 [inline] free_pcp_prepare+0x312/0x7d0 mm/page_alloc.c:1394 free_unref_page_prepare mm/page_alloc.c:3329 [inline] free_unref_page+0x19/0x690 mm/page_alloc.c:3408 kvfree+0x42/0x50 mm/util.c:616 netdev_freemem net/core/dev.c:10780 [inline] free_netdev+0x495/0x5b0 net/core/dev.c:10958 rtl871x_load_fw_cb drivers/staging/rtl8712/hal_init.c:47 [inline] rtl871x_load_fw_cb.cold+0x100/0x120 drivers/staging/rtl8712/hal_init.c:32 request_firmware_work_func+0x12c/0x230 drivers/base/firmware_loader/main.c:1081 process_one_work+0x98d/0x1630 kernel/workqueue.c:2276 worker_thread+0x658/0x11f0 kernel/workqueue.c:2422 kthread+0x3e5/0x4d0 kernel/kthread.c:319 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295 Memory state around the buggy address: ffff88802f7acd00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88802f7acd80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff88802f7ace00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff88802f7ace80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88802f7acf00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== Tested on: commit: 8f0df15b Add linux-next specific files for 20210713 git tree: linux-next console output: https://syzkaller.appspot.com/x/log.txt?x=12ef886c300000 kernel config: https://syzkaller.appspot.com/x/.config?x=5ef73f190e4b0b9a dashboard link: https://syzkaller.appspot.com/bug?extid=5872a520e0ce0a7c7230 compiler: patch: https://syzkaller.appspot.com/x/patch.diff?x=164561d2300000 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [syzbot] KASAN: use-after-free Read in r871xu_dev_remove 2021-07-13 8:55 ` Pavel Skripkin 2021-07-13 9:04 ` Dongliang Mu @ 2021-07-13 11:07 ` syzbot 1 sibling, 0 replies; 8+ messages in thread From: syzbot @ 2021-07-13 11:07 UTC (permalink / raw) To: Larry.Finger, florian.c.schilhabel, gregkh, hridayhegde1999, linux-kernel, linux-staging, paskripkin, rkovhaev, straube.linux, syzkaller-bugs Hello, syzbot tried to test the proposed patch but the build/boot failed: drivers/staging/rtl8712/hal_init.c:46:3: error: implicit declaration of function 'shedule'; did you mean 'schedule'? [-Werror=implicit-function-declaration] Tested on: commit: 8f0df15b Add linux-next specific files for 20210713 git tree: linux-next dashboard link: https://syzkaller.appspot.com/bug?extid=5872a520e0ce0a7c7230 compiler: patch: https://syzkaller.appspot.com/x/patch.diff?x=13a2c06c300000 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [syzbot] KASAN: use-after-free Read in r871xu_dev_remove 2021-07-13 3:14 [syzbot] KASAN: use-after-free Read in r871xu_dev_remove syzbot 2021-07-13 8:55 ` Pavel Skripkin @ 2021-07-21 10:01 ` Pavel Skripkin 2021-07-21 17:12 ` syzbot 1 sibling, 1 reply; 8+ messages in thread From: Pavel Skripkin @ 2021-07-21 10:01 UTC (permalink / raw) To: syzbot Cc: Larry.Finger, florian.c.schilhabel, gregkh, hridayhegde1999, linux-kernel, linux-staging, rkovhaev, straube.linux, syzkaller-bugs [-- Attachment #1: Type: text/plain, Size: 1234 bytes --] On Mon, 12 Jul 2021 20:14:24 -0700 syzbot <syzbot+5872a520e0ce0a7c7230@syzkaller.appspotmail.com> wrote: > Hello, > > syzbot found the following issue on: > > HEAD commit: 92510a7f Add linux-next specific files for 20210709 > git tree: linux-next > console output: > https://syzkaller.appspot.com/x/log.txt?x=16c50180300000 kernel > config: https://syzkaller.appspot.com/x/.config?x=505de2716f052686 > dashboard link: > https://syzkaller.appspot.com/bug?extid=5872a520e0ce0a7c7230 syz > repro: > https://syzkaller.appspot.com/x/repro.syz?x=1639a73c300000 C > reproducer: https://syzkaller.appspot.com/x/repro.c?x=15fcd5e4300000 > > IMPORTANT: if you fix the issue, please add the following tag to the > commit: Reported-by: > syzbot+5872a520e0ce0a7c7230@syzkaller.appspotmail.com > > usb 1-1: USB disconnect, device number 14 > ================================================================== > BUG: KASAN: use-after-free in __lock_acquire+0x3d86/0x54a0 > kernel/locking/lockdep.c:4885 Read of size 8 at addr ffff888038bbce28 > by task kworker/1:2/4393 > And let's test it with this repro as well. #syz test git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master With regards, Pavel Skripkin [-- Attachment #2: 2patches.patch --] [-- Type: text/x-patch, Size: 7388 bytes --] diff --git a/drivers/staging/rtl8712/hal_init.c b/drivers/staging/rtl8712/hal_init.c index 22974277afa0..4eff3fdecdb8 100644 --- a/drivers/staging/rtl8712/hal_init.c +++ b/drivers/staging/rtl8712/hal_init.c @@ -29,21 +29,31 @@ #define FWBUFF_ALIGN_SZ 512 #define MAX_DUMP_FWSZ (48 * 1024) +static void rtl871x_load_fw_fail(struct _adapter *adapter) +{ + struct usb_device *udev = adapter->dvobjpriv.pusbdev; + struct device *dev = &udev->dev; + struct device *parent = dev->parent; + + complete(&adapter->rtl8712_fw_ready); + + dev_err(&udev->dev, "r8712u: Firmware request failed\n"); + + if (parent) + device_lock(parent); + + device_release_driver(dev); + + if (parent) + device_unlock(parent); +} + static void rtl871x_load_fw_cb(const struct firmware *firmware, void *context) { struct _adapter *adapter = context; if (!firmware) { - struct usb_device *udev = adapter->dvobjpriv.pusbdev; - struct usb_interface *usb_intf = adapter->pusb_intf; - - dev_err(&udev->dev, "r8712u: Firmware request failed\n"); - usb_put_dev(udev); - usb_set_intfdata(usb_intf, NULL); - r8712_free_drv_sw(adapter); - adapter->dvobj_deinit(adapter); - complete(&adapter->rtl8712_fw_ready); - free_netdev(adapter->pnetdev); + rtl871x_load_fw_fail(adapter); return; } adapter->fw = firmware; diff --git a/drivers/staging/rtl8712/rtl8712_led.c b/drivers/staging/rtl8712/rtl8712_led.c index 5901026949f2..d5fc9026b036 100644 --- a/drivers/staging/rtl8712/rtl8712_led.c +++ b/drivers/staging/rtl8712/rtl8712_led.c @@ -1820,3 +1820,11 @@ void LedControl871x(struct _adapter *padapter, enum LED_CTL_MODE LedAction) break; } } + +void r8712_flush_led_works(struct _adapter *padapter) +{ + struct led_priv *pledpriv = &padapter->ledpriv; + + flush_work(&pledpriv->SwLed0.BlinkWorkItem); + flush_work(&pledpriv->SwLed1.BlinkWorkItem); +} diff --git a/drivers/staging/rtl8712/rtl871x_led.h b/drivers/staging/rtl8712/rtl871x_led.h index ee19c873cf01..2f0768132ad8 100644 --- a/drivers/staging/rtl8712/rtl871x_led.h +++ b/drivers/staging/rtl8712/rtl871x_led.h @@ -112,6 +112,7 @@ struct led_priv { void r8712_InitSwLeds(struct _adapter *padapter); void r8712_DeInitSwLeds(struct _adapter *padapter); void LedControl871x(struct _adapter *padapter, enum LED_CTL_MODE LedAction); +void r8712_flush_led_works(struct _adapter *padapter); #endif diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.c b/drivers/staging/rtl8712/rtl871x_pwrctrl.c index 23cff43437e2..cd6d9ff0bebc 100644 --- a/drivers/staging/rtl8712/rtl871x_pwrctrl.c +++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.c @@ -224,3 +224,11 @@ void r8712_unregister_cmd_alive(struct _adapter *padapter) } mutex_unlock(&pwrctrl->mutex_lock); } + +void r8712_flush_rwctrl_works(struct _adapter *padapter) +{ + struct pwrctrl_priv *pwrctrl = &padapter->pwrctrlpriv; + + flush_work(&pwrctrl->SetPSModeWorkItem); + flush_work(&pwrctrl->rpwm_workitem); +} diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.h b/drivers/staging/rtl8712/rtl871x_pwrctrl.h index bf6623cfaf27..b35b9c7920eb 100644 --- a/drivers/staging/rtl8712/rtl871x_pwrctrl.h +++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.h @@ -108,5 +108,6 @@ void r8712_cpwm_int_hdl(struct _adapter *padapter, void r8712_set_ps_mode(struct _adapter *padapter, uint ps_mode, uint smart_ps); void r8712_set_rpwm(struct _adapter *padapter, u8 val8); +void r8712_flush_rwctrl_works(struct _adapter *padapter); #endif /* __RTL871X_PWRCTRL_H_ */ diff --git a/drivers/staging/rtl8712/usb_intf.c b/drivers/staging/rtl8712/usb_intf.c index 2434b13c8b12..505ebeb643dc 100644 --- a/drivers/staging/rtl8712/usb_intf.c +++ b/drivers/staging/rtl8712/usb_intf.c @@ -591,35 +591,30 @@ static void r871xu_dev_remove(struct usb_interface *pusb_intf) { struct net_device *pnetdev = usb_get_intfdata(pusb_intf); struct usb_device *udev = interface_to_usbdev(pusb_intf); + struct _adapter *padapter = netdev_priv(pnetdev); + + /* never exit with a firmware callback pending */ + wait_for_completion(&padapter->rtl8712_fw_ready); + usb_set_intfdata(pusb_intf, NULL); + release_firmware(padapter->fw); + if (drvpriv.drv_registered) + padapter->surprise_removed = true; + if (pnetdev->reg_state != NETREG_UNINITIALIZED) + unregister_netdev(pnetdev); /* will call netdev_close() */ + r8712_flush_rwctrl_works(padapter); + r8712_flush_led_works(padapter); + udelay(1); + /* Stop driver mlme relation timer */ + r8712_stop_drv_timers(padapter); + r871x_dev_unload(padapter); + r8712_free_drv_sw(padapter); + free_netdev(pnetdev); + + /* decrease the reference count of the usb device structure + * when disconnect + */ + usb_put_dev(udev); - if (pnetdev) { - struct _adapter *padapter = netdev_priv(pnetdev); - - /* never exit with a firmware callback pending */ - wait_for_completion(&padapter->rtl8712_fw_ready); - pnetdev = usb_get_intfdata(pusb_intf); - usb_set_intfdata(pusb_intf, NULL); - if (!pnetdev) - goto firmware_load_fail; - release_firmware(padapter->fw); - if (drvpriv.drv_registered) - padapter->surprise_removed = true; - if (pnetdev->reg_state != NETREG_UNINITIALIZED) - unregister_netdev(pnetdev); /* will call netdev_close() */ - flush_scheduled_work(); - udelay(1); - /* Stop driver mlme relation timer */ - r8712_stop_drv_timers(padapter); - r871x_dev_unload(padapter); - r8712_free_drv_sw(padapter); - free_netdev(pnetdev); - - /* decrease the reference count of the usb device structure - * when disconnect - */ - usb_put_dev(udev); - } -firmware_load_fail: /* If we didn't unplug usb dongle and remove/insert module, driver * fails on sitesurvey for the first time when device is up. * Reset usb port for sitesurvey fail issue. diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index b04a5a02ecf3..786a06a232fd 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -760,10 +760,18 @@ void hci_sock_dev_event(struct hci_dev *hdev, int event) struct sock *sk; /* Detach sockets from device */ +restart: read_lock(&hci_sk_list.lock); sk_for_each(sk, &hci_sk_list.head) { + /* This sock_hold(sk) is safe, for bt_sock_unlink(sk) + * is not called yet. + */ + sock_hold(sk); + read_unlock(&hci_sk_list.lock); lock_sock(sk); - if (hci_pi(sk)->hdev == hdev) { + write_lock(&hci_sk_list.lock); + /* Check that bt_sock_unlink(sk) is not called yet. */ + if (sk_hashed(sk) && hci_pi(sk)->hdev == hdev) { hci_pi(sk)->hdev = NULL; sk->sk_err = EPIPE; sk->sk_state = BT_OPEN; @@ -771,7 +779,27 @@ void hci_sock_dev_event(struct hci_dev *hdev, int event) hci_dev_put(hdev); } + write_unlock(&hci_sk_list.lock); release_sock(sk); + read_lock(&hci_sk_list.lock); + /* If bt_sock_unlink(sk) is not called yet, we can + * continue iteration. We can use __sock_put(sk) here + * because hci_sock_release() will call sock_put(sk) + * after bt_sock_unlink(sk). + */ + if (sk_hashed(sk)) { + __sock_put(sk); + continue; + } + /* Otherwise, we need to restart iteration, for the + * next socket pointed by sk->next might be already + * gone. We can't use __sock_put(sk) here because + * hci_sock_release() might have already called + * sock_put(sk) after bt_sock_unlink(sk). + */ + read_unlock(&hci_sk_list.lock); + sock_put(sk); + goto restart; } read_unlock(&hci_sk_list.lock); } ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [syzbot] KASAN: use-after-free Read in r871xu_dev_remove 2021-07-21 10:01 ` Pavel Skripkin @ 2021-07-21 17:12 ` syzbot 0 siblings, 0 replies; 8+ messages in thread From: syzbot @ 2021-07-21 17:12 UTC (permalink / raw) To: Larry.Finger, florian.c.schilhabel, gregkh, hridayhegde1999, linux-kernel, linux-staging, paskripkin, rkovhaev, straube.linux, syzkaller-bugs Hello, syzbot has tested the proposed patch and the reproducer did not trigger any issue: Reported-and-tested-by: syzbot+5872a520e0ce0a7c7230@syzkaller.appspotmail.com Tested on: commit: 8cae8cd8 seq_file: disallow extremely large seq buffer.. git tree: upstream kernel config: https://syzkaller.appspot.com/x/.config?x=f7dfeb6dfc05ea19 dashboard link: https://syzkaller.appspot.com/bug?extid=5872a520e0ce0a7c7230 compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.1 patch: https://syzkaller.appspot.com/x/patch.diff?x=11291aa2300000 Note: testing is done by a robot and is best-effort only. ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-07-21 17:12 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-07-13 3:14 [syzbot] KASAN: use-after-free Read in r871xu_dev_remove syzbot 2021-07-13 8:55 ` Pavel Skripkin 2021-07-13 9:04 ` Dongliang Mu 2021-07-13 9:19 ` Pavel Skripkin 2021-07-13 11:18 ` syzbot 2021-07-13 11:07 ` syzbot 2021-07-21 10:01 ` Pavel Skripkin 2021-07-21 17:12 ` syzbot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).