syzbot


KASAN: use-after-free Read in kernfs_activate
Status: upstream: reported on 2022/03/05 17:08
Reported-by: syzbot+82240fa5f8dffe45d4f1@syzkaller.appspotmail.com
First crash: 87d, last: 75d

Sample crash report:
usb 2-1: Direct firmware load for ueagle-atm/eagleI.fw failed with error -2
usb 2-1: Falling back to sysfs fallback for: ueagle-atm/eagleI.fw
==================================================================
BUG: KASAN: use-after-free in kernfs_root fs/kernfs/kernfs-internal.h:48 [inline]
BUG: KASAN: use-after-free in kernfs_next_descendant_post fs/kernfs/dir.c:1272 [inline]
BUG: KASAN: use-after-free in kernfs_activate+0xef/0x520 fs/kernfs/dir.c:1312
Read of size 8 at addr ffff88807da7d770 by task kworker/0:15/7817

CPU: 0 PID: 7817 Comm: kworker/0:15 Not tainted 5.17.0-rc7-syzkaller-00235-gaad611a868d1 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: events request_firmware_work_func
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1dc/0x2d8 lib/dump_stack.c:106
 print_address_description+0x65/0x3a0 mm/kasan/report.c:255
 __kasan_report mm/kasan/report.c:442 [inline]
 kasan_report+0x19a/0x1f0 mm/kasan/report.c:459
 kernfs_root fs/kernfs/kernfs-internal.h:48 [inline]
 kernfs_next_descendant_post fs/kernfs/dir.c:1272 [inline]
 kernfs_activate+0xef/0x520 fs/kernfs/dir.c:1312
 kernfs_add_one+0x56c/0x6d0 fs/kernfs/dir.c:767
 kernfs_create_dir_ns+0x1bf/0x220 fs/kernfs/dir.c:1004
 sysfs_create_dir_ns+0x181/0x390 fs/sysfs/dir.c:59
 create_dir lib/kobject.c:89 [inline]
 kobject_add_internal+0x418/0xb50 lib/kobject.c:255
 kobject_add_varg lib/kobject.c:390 [inline]
 kobject_add+0x14c/0x210 lib/kobject.c:442
 class_dir_create_and_add drivers/base/core.c:2942 [inline]
 get_device_parent+0x3d5/0x430 drivers/base/core.c:2997
 device_add+0x3b7/0x16d0 drivers/base/core.c:3326
 fw_load_sysfs_fallback+0xd2/0x7d0 drivers/base/firmware_loader/fallback.c:512
 fw_load_from_user_helper+0x242/0x320 drivers/base/firmware_loader/fallback.c:588
 _request_firmware+0x3b9/0x670 drivers/base/firmware_loader/main.c:774
 request_firmware_work_func+0x128/0x270 drivers/base/firmware_loader/main.c:1020
 process_one_work+0x86c/0x1190 kernel/workqueue.c:2307
 worker_thread+0xab1/0x1300 kernel/workqueue.c:2454
 kthread+0x2a3/0x2d0 kernel/kthread.c:377
 ret_from_fork+0x1f/0x30
 </TASK>

Allocated by task 7817:
 kasan_save_stack mm/kasan/common.c:38 [inline]
 kasan_set_track mm/kasan/common.c:45 [inline]
 set_alloc_info mm/kasan/common.c:436 [inline]
 __kasan_slab_alloc+0xb2/0xe0 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_node mm/slub.c:3230 [inline]
 slab_alloc mm/slub.c:3238 [inline]
 kmem_cache_alloc+0x1c9/0x310 mm/slub.c:3243
 kmem_cache_zalloc include/linux/slab.h:704 [inline]
 __kernfs_new_node+0xdb/0x720 fs/kernfs/dir.c:585
 kernfs_new_node fs/kernfs/dir.c:647 [inline]
 kernfs_create_dir_ns+0x90/0x220 fs/kernfs/dir.c:994
 sysfs_create_dir_ns+0x181/0x390 fs/sysfs/dir.c:59
 create_dir lib/kobject.c:89 [inline]
 kobject_add_internal+0x418/0xb50 lib/kobject.c:255
 kobject_add_varg lib/kobject.c:390 [inline]
 kobject_add+0x14c/0x210 lib/kobject.c:442
 class_dir_create_and_add drivers/base/core.c:2942 [inline]
 get_device_parent+0x3d5/0x430 drivers/base/core.c:2997
 device_add+0x3b7/0x16d0 drivers/base/core.c:3326
 fw_load_sysfs_fallback+0xd2/0x7d0 drivers/base/firmware_loader/fallback.c:512
 fw_load_from_user_helper+0x242/0x320 drivers/base/firmware_loader/fallback.c:588
 _request_firmware+0x3b9/0x670 drivers/base/firmware_loader/main.c:774
 request_firmware_work_func+0x128/0x270 drivers/base/firmware_loader/main.c:1020
 process_one_work+0x86c/0x1190 kernel/workqueue.c:2307
 worker_thread+0xab1/0x1300 kernel/workqueue.c:2454
 kthread+0x2a3/0x2d0 kernel/kthread.c:377
 ret_from_fork+0x1f/0x30

Freed by task 4978:
 kasan_save_stack mm/kasan/common.c:38 [inline]
 kasan_set_track+0x4c/0x70 mm/kasan/common.c:45
 kasan_set_free_info+0x1f/0x40 mm/kasan/generic.c:370
 ____kasan_slab_free+0x126/0x180 mm/kasan/common.c:366
 kasan_slab_free include/linux/kasan.h:236 [inline]
 slab_free_hook mm/slub.c:1728 [inline]
 slab_free_freelist_hook+0x12e/0x1a0 mm/slub.c:1754
 slab_free mm/slub.c:3509 [inline]
 kmem_cache_free+0xb6/0x1c0 mm/slub.c:3526
 kernfs_put+0x340/0x490 fs/kernfs/dir.c:539
 __kernfs_remove+0xe80/0x1150 fs/kernfs/dir.c:1388
 kernfs_remove+0x6c/0x80 fs/kernfs/dir.c:1403
 __kobject_del+0xcc/0x310 lib/kobject.c:620
 kobject_del+0x41/0x60 lib/kobject.c:643
 device_del+0xa1e/0xbf0 drivers/base/core.c:3603
 usb_disconnect+0x56f/0x8a0 drivers/usb/core/hub.c:2254
 hub_port_connect+0x29c/0x2910 drivers/usb/core/hub.c:5202
 hub_port_connect_change+0x5f9/0xc20 drivers/usb/core/hub.c:5502
 port_event+0xca0/0x13e0 drivers/usb/core/hub.c:5660
 hub_event+0x4ed/0xe40 drivers/usb/core/hub.c:5742
 process_one_work+0x86c/0x1190 kernel/workqueue.c:2307
 process_scheduled_works kernel/workqueue.c:2370 [inline]
 worker_thread+0xe18/0x1300 kernel/workqueue.c:2456
 kthread+0x2a3/0x2d0 kernel/kthread.c:377
 ret_from_fork+0x1f/0x30

The buggy address belongs to the object at ffff88807da7d740
 which belongs to the cache kernfs_node_cache of size 168
The buggy address is located 48 bytes inside of
 168-byte region [ffff88807da7d740, ffff88807da7d7e8)
The buggy address belongs to the page:
page:ffffea0001f69f40 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7da7d
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffffea0001f22b00 dead000000000005 ffff888140007b40
raw: 0000000000000000 0000000080110011 00000001ffffffff 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 0x112cc0(GFP_USER|__GFP_NOWARN|__GFP_NORETRY), pid 15718, ts 547562933232, free_ts 491946928858
 prep_new_page mm/page_alloc.c:2434 [inline]
 get_page_from_freelist+0x729/0x9e0 mm/page_alloc.c:4165
 __alloc_pages+0x255/0x580 mm/page_alloc.c:5389
 alloc_slab_page mm/slub.c:1799 [inline]
 allocate_slab+0xce/0x3f0 mm/slub.c:1944
 new_slab mm/slub.c:2004 [inline]
 ___slab_alloc+0x3fe/0xc30 mm/slub.c:3018
 __slab_alloc mm/slub.c:3105 [inline]
 slab_alloc_node mm/slub.c:3196 [inline]
 slab_alloc mm/slub.c:3238 [inline]
 kmem_cache_alloc+0x276/0x310 mm/slub.c:3243
 kmem_cache_zalloc include/linux/slab.h:704 [inline]
 __kernfs_new_node+0xdb/0x720 fs/kernfs/dir.c:585
 kernfs_new_node+0x95/0x160 fs/kernfs/dir.c:647
 kernfs_create_link+0x9f/0x1f0 fs/kernfs/symlink.c:39
 sysfs_do_create_link_sd+0x85/0x100 fs/sysfs/symlink.c:44
 device_add_class_symlinks drivers/base/core.c:3147 [inline]
 device_add+0x9ea/0x16d0 drivers/base/core.c:3353
 netdev_register_kobject+0x178/0x310 net/core/net-sysfs.c:2008
 register_netdevice+0x127a/0x1c00 net/core/dev.c:9667
 register_netdev+0x37/0x50 net/core/dev.c:9791
 sit_init_net+0x1f6/0x510 net/ipv6/sit.c:1923
 ops_init+0x313/0x430 net/core/net_namespace.c:140
 setup_net+0x45b/0xb70 net/core/net_namespace.c:330
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+0xd1c/0xe00 mm/page_alloc.c:1404
 free_unref_page_prepare mm/page_alloc.c:3325 [inline]
 free_unref_page+0x7d/0x580 mm/page_alloc.c:3404
 __vunmap+0x936/0xa80 mm/vmalloc.c:2635
 __vfree mm/vmalloc.c:2683 [inline]
 __vmalloc_area_node mm/vmalloc.c:3016 [inline]
 __vmalloc_node_range+0xbe2/0xd90 mm/vmalloc.c:3107
 __bpf_map_area_alloc+0x11e/0x130 kernel/bpf/syscall.c:329
 queue_stack_map_alloc+0xba/0x1d0 kernel/bpf/queue_stack_maps.c:76
 find_and_alloc_map kernel/bpf/syscall.c:128 [inline]
 map_create kernel/bpf/syscall.c:865 [inline]
 __sys_bpf+0x63c4/0x12db0 kernel/bpf/syscall.c:4619
 __do_sys_bpf kernel/bpf/syscall.c:4741 [inline]
 __se_sys_bpf kernel/bpf/syscall.c:4739 [inline]
 __x64_sys_bpf+0x78/0x90 kernel/bpf/syscall.c:4739
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae

Memory state around the buggy address:
 ffff88807da7d600: fb fb fb fc fc fc fc fc fc fc fc fb fb fb fb fb
 ffff88807da7d680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88807da7d700: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
                                                             ^
 ffff88807da7d780: fb fb fb fb fb fb fb fb fb fb fb fb fb fc fc fc
 ffff88807da7d800: fc fc fc fc fc fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (2):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-kasan-gce-smack-root 2022/03/13 06:54 upstream aad611a868d1 9e8eaa75 .config log report info KASAN: use-after-free Read in kernfs_activate
ci-upstream-kasan-gce-smack-root 2022/03/01 15:15 upstream 719fce7539cd 45a13a73 .config log report info KASAN: use-after-free Read in kernfs_activate