syzbot


KASAN: use-after-free Read in kernfs_get
Status: upstream: reported on 2022/03/14 13:49
Reported-by: syzbot+97a16334dbd58916f7fb@syzkaller.appspotmail.com
First crash: 115d, last: 67d

Sample crash report:
usb 7-1: Direct firmware load for ueagle-atm/adi930.fw failed with error -2
usb 7-1: Falling back to sysfs fallback for: ueagle-atm/adi930.fw
==================================================================
BUG: KASAN: use-after-free in instrument_atomic_read include/linux/instrumented.h:71 [inline]
BUG: KASAN: use-after-free in atomic_read include/linux/atomic/atomic-instrumented.h:27 [inline]
BUG: KASAN: use-after-free in kernfs_get.part.0+0x17/0x80 fs/kernfs/dir.c:496
Read of size 4 at addr ffff88806198e040 by task kworker/0:5/3782

CPU: 0 PID: 3782 Comm: kworker/0:5 Not tainted 5.17.0-rc8-syzkaller #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014
Workqueue: events request_firmware_work_func
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
 print_address_description.constprop.0.cold+0x8d/0x303 mm/kasan/report.c:255
 __kasan_report mm/kasan/report.c:442 [inline]
 kasan_report.cold+0x83/0xdf mm/kasan/report.c:459
 check_region_inline mm/kasan/generic.c:183 [inline]
 kasan_check_range+0x13d/0x180 mm/kasan/generic.c:189
 instrument_atomic_read include/linux/instrumented.h:71 [inline]
 atomic_read include/linux/atomic/atomic-instrumented.h:27 [inline]
 kernfs_get.part.0+0x17/0x80 fs/kernfs/dir.c:496
 kernfs_get+0x1b/0x30 fs/kernfs/dir.c:495
 sysfs_get include/linux/sysfs.h:635 [inline]
 create_dir lib/kobject.c:111 [inline]
 kobject_add_internal+0x5c3/0xa60 lib/kobject.c:255
 kobject_add_varg lib/kobject.c:390 [inline]
 kobject_add+0x150/0x1c0 lib/kobject.c:442
 class_dir_create_and_add drivers/base/core.c:2942 [inline]
 get_device_parent+0x3d7/0x590 drivers/base/core.c:2997
 device_add+0x2a8/0x1e20 drivers/base/core.c:3326
 fw_load_sysfs_fallback drivers/base/firmware_loader/fallback.c:512 [inline]
 fw_load_from_user_helper drivers/base/firmware_loader/fallback.c:588 [inline]
 firmware_fallback_sysfs+0x402/0xe70 drivers/base/firmware_loader/fallback.c:664
 _request_firmware+0xb97/0xfe0 drivers/base/firmware_loader/main.c:774
 request_firmware_work_func+0xdd/0x230 drivers/base/firmware_loader/main.c:1020
 process_one_work+0x9ac/0x1650 kernel/workqueue.c:2307
 worker_thread+0x657/0x1110 kernel/workqueue.c:2454
 kthread+0x2e9/0x3a0 kernel/kthread.c:377
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295
 </TASK>

Allocated by task 3782:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track mm/kasan/common.c:45 [inline]
 set_alloc_info mm/kasan/common.c:436 [inline]
 __kasan_slab_alloc+0x85/0xb0 mm/kasan/common.c:469
 kasan_slab_alloc include/linux/kasan.h:260 [inline]
 slab_post_alloc_hook mm/slab.h:732 [inline]
 slab_alloc mm/slab.c:3315 [inline]
 kmem_cache_alloc+0x265/0x560 mm/slab.c:3499
 kmem_cache_zalloc include/linux/slab.h:704 [inline]
 __kernfs_new_node+0xd4/0x8b0 fs/kernfs/dir.c:585
 kernfs_new_node fs/kernfs/dir.c:647 [inline]
 kernfs_create_dir_ns+0x9c/0x220 fs/kernfs/dir.c:994
 sysfs_create_dir_ns+0x127/0x290 fs/sysfs/dir.c:59
 create_dir lib/kobject.c:89 [inline]
 kobject_add_internal+0x2d2/0xa60 lib/kobject.c:255
 kobject_add_varg lib/kobject.c:390 [inline]
 kobject_add+0x150/0x1c0 lib/kobject.c:442
 class_dir_create_and_add drivers/base/core.c:2942 [inline]
 get_device_parent+0x3d7/0x590 drivers/base/core.c:2997
 device_add+0x2a8/0x1e20 drivers/base/core.c:3326
 fw_load_sysfs_fallback drivers/base/firmware_loader/fallback.c:512 [inline]
 fw_load_from_user_helper drivers/base/firmware_loader/fallback.c:588 [inline]
 firmware_fallback_sysfs+0x402/0xe70 drivers/base/firmware_loader/fallback.c:664
 _request_firmware+0xb97/0xfe0 drivers/base/firmware_loader/main.c:774
 request_firmware_work_func+0xdd/0x230 drivers/base/firmware_loader/main.c:1020
 process_one_work+0x9ac/0x1650 kernel/workqueue.c:2307
 worker_thread+0x657/0x1110 kernel/workqueue.c:2454
 kthread+0x2e9/0x3a0 kernel/kthread.c:377
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Freed by task 22597:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track+0x21/0x30 mm/kasan/common.c:45
 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370
 ____kasan_slab_free mm/kasan/common.c:366 [inline]
 ____kasan_slab_free+0xff/0x140 mm/kasan/common.c:328
 kasan_slab_free include/linux/kasan.h:236 [inline]
 __cache_free mm/slab.c:3437 [inline]
 kmem_cache_free.part.0+0x91/0x200 mm/slab.c:3733
 kernfs_put.part.0+0x2c4/0x540 fs/kernfs/dir.c:539
 kernfs_put+0x42/0x50 fs/kernfs/dir.c:513
 __kernfs_remove+0x7a3/0xb20 fs/kernfs/dir.c:1388
 kernfs_remove+0x6d/0x90 fs/kernfs/dir.c:1403
 sysfs_remove_dir+0xc1/0x100 fs/sysfs/dir.c:101
 __kobject_del+0xe2/0x200 lib/kobject.c:620
 kobject_del lib/kobject.c:643 [inline]
 kobject_del+0x3c/0x60 lib/kobject.c:635
 device_del+0x81c/0xc80 drivers/base/core.c:3603
 usb_disconnect.cold+0x4ba/0x78e drivers/usb/core/hub.c:2254
 hub_port_connect drivers/usb/core/hub.c:5202 [inline]
 hub_port_connect_change drivers/usb/core/hub.c:5502 [inline]
 port_event drivers/usb/core/hub.c:5660 [inline]
 hub_event+0x1e39/0x44d0 drivers/usb/core/hub.c:5742
 process_one_work+0x9ac/0x1650 kernel/workqueue.c:2307
 process_scheduled_works kernel/workqueue.c:2370 [inline]
 worker_thread+0x833/0x1110 kernel/workqueue.c:2456
 kthread+0x2e9/0x3a0 kernel/kthread.c:377
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

The buggy address belongs to the object at ffff88806198e040
 which belongs to the cache kernfs_node_cache of size 168
The buggy address is located 0 bytes inside of
 168-byte region [ffff88806198e040, ffff88806198e0e8)
The buggy address belongs to the page:
page:ffffea0001866380 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff88806198e210 pfn:0x6198e
flags: 0x4fff00000000200(slab|node=1|zone=1|lastcpupid=0x7ff)
raw: 04fff00000000200 ffffea0001bcedc8 ffff888040211740 ffff8880402a4100
raw: ffff88806198e210 ffff88806198e040 0000000100000003 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x140cc0(GFP_USER|__GFP_COMP), pid 31866, ts 1125894621781, free_ts 1116947407047
 prep_new_page mm/page_alloc.c:2434 [inline]
 get_page_from_freelist+0xa72/0x2f50 mm/page_alloc.c:4165
 __alloc_pages+0x1b2/0x500 mm/page_alloc.c:5389
 __alloc_pages_node include/linux/gfp.h:572 [inline]
 kmem_getpages mm/slab.c:1378 [inline]
 cache_grow_begin+0x75/0x390 mm/slab.c:2584
 fallback_alloc+0x1e4/0x2e0 mm/slab.c:3132
 __do_cache_alloc mm/slab.c:3274 [inline]
 slab_alloc mm/slab.c:3308 [inline]
 kmem_cache_alloc+0x367/0x560 mm/slab.c:3499
 kmem_cache_zalloc include/linux/slab.h:704 [inline]
 __kernfs_new_node+0xd4/0x8b0 fs/kernfs/dir.c:585
 kernfs_new_node+0x93/0x120 fs/kernfs/dir.c:647
 __kernfs_create_file+0x51/0x350 fs/kernfs/file.c:987
 sysfs_add_file_mode_ns+0x20f/0x3f0 fs/sysfs/file.c:294
 create_files fs/sysfs/group.c:64 [inline]
 internal_create_group+0x322/0xb10 fs/sysfs/group.c:148
 internal_create_groups.part.0+0x90/0x140 fs/sysfs/group.c:188
 internal_create_groups fs/sysfs/group.c:184 [inline]
 sysfs_create_groups+0x25/0x50 fs/sysfs/group.c:214
 create_dir lib/kobject.c:100 [inline]
 kobject_add_internal+0x583/0xa60 lib/kobject.c:255
 kobject_add_varg lib/kobject.c:390 [inline]
 kobject_init_and_add+0x101/0x160 lib/kobject.c:473
 rx_queue_add_kobject net/core/net-sysfs.c:1050 [inline]
 net_rx_queue_update_kobjects+0x25b/0x510 net/core/net-sysfs.c:1101
 register_queue_kobjects net/core/net-sysfs.c:1761 [inline]
 netdev_register_kobject+0x275/0x430 net/core/net-sysfs.c:2012
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1352 [inline]
 free_pcp_prepare+0x374/0x870 mm/page_alloc.c:1404
 free_unref_page_prepare mm/page_alloc.c:3325 [inline]
 free_unref_page+0x19/0x690 mm/page_alloc.c:3404
 slab_destroy mm/slab.c:1630 [inline]
 slabs_destroy+0x89/0xc0 mm/slab.c:1650
 __cache_free_alien mm/slab.c:789 [inline]
 cache_free_alien mm/slab.c:805 [inline]
 ___cache_free+0x1cf/0x600 mm/slab.c:3465
 qlink_free mm/kasan/quarantine.c:157 [inline]
 qlist_free_all+0x50/0x1a0 mm/kasan/quarantine.c:176
 kasan_quarantine_reduce+0x180/0x200 mm/kasan/quarantine.c:283
 __kasan_slab_alloc+0x97/0xb0 mm/kasan/common.c:446
 kasan_slab_alloc include/linux/kasan.h:260 [inline]
 slab_post_alloc_hook mm/slab.h:732 [inline]
 slab_alloc mm/slab.c:3315 [inline]
 kmem_cache_alloc+0x265/0x560 mm/slab.c:3499
 getname_flags.part.0+0x50/0x4f0 fs/namei.c:138
 getname_flags+0x9a/0xe0 include/linux/audit.h:323
 user_path_at_empty+0x2b/0x60 fs/namei.c:2850
 user_path_at include/linux/namei.h:57 [inline]
 ksys_umount fs/namespace.c:1809 [inline]
 __do_sys_umount fs/namespace.c:1817 [inline]
 __se_sys_umount fs/namespace.c:1815 [inline]
 __x64_sys_umount+0xf8/0x180 fs/namespace.c:1815
 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

Memory state around the buggy address:
 ffff88806198df00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff88806198df80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff88806198e000: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
                                           ^
 ffff88806198e080: fb fb fb fb fb fb fb fb fb fb fb fb fb fc fc fc
 ffff88806198e100: fc fc fc fc fc fa fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (6):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-qemu-upstream 2022/03/14 14:46 upstream 09688c0166e7 9e8eaa75 .config log report info KASAN: use-after-free Read in kernfs_get
ci-upstream-kasan-gce-smack-root 2022/03/14 13:49 upstream 09688c0166e7 9e8eaa75 .config log report info KASAN: use-after-free Read in kernfs_get
ci-upstream-kasan-gce 2022/02/20 02:01 upstream 4f12b742eb2b 3cd800e4 .config log report info KASAN: use-after-free Read in kernfs_get
ci-upstream-kasan-gce-root 2022/01/29 22:07 upstream 169387e2aa29 495e00c5 .config log report info KASAN: use-after-free Read in kernfs_get
ci-upstream-kasan-gce 2022/01/29 13:54 upstream 169387e2aa29 495e00c5 .config log report info KASAN: use-after-free Read in kernfs_get
ci-upstream-kasan-gce 2022/01/25 15:45 upstream a08b41ab9e2e 2cbffd88 .config log report info KASAN: use-after-free Read in kernfs_get