syzbot


KASAN: use-after-free Read in kernfs_add_one (3)

Status: upstream: reported on 2024/08/05 12:08
Reported-by: syzbot+15857877fe6531118a98@syzkaller.appspotmail.com
First crash: 64d, last: 64d
Similar bugs (5)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Read in kernfs_add_one kernfs C error inconclusive 39 181d 1112d 0/28 auto-obsoleted due to no activity on 2024/08/14 07:44
linux-6.1 KASAN: use-after-free Read in kernfs_add_one (2) 1 171d 171d 0/3 auto-obsoleted due to no activity on 2024/07/29 04:04
linux-6.1 KASAN: use-after-free Read in kernfs_add_one 1 478d 478d 0/3 auto-obsoleted due to no activity on 2023/09/26 01:13
linux-5.15 KASAN: use-after-free Read in kernfs_add_one 1 374d 374d 0/3 auto-obsoleted due to no activity on 2024/01/09 18:18
upstream KASAN: slab-use-after-free Read in kernfs_add_one kernfs 1 30d 11d 0/28 upstream: reported on 2024/09/27 15:10

Sample crash report:
usb 3-1: Direct firmware load for ueagle-atm/eagleII.fw failed with error -2
usb 3-1: Falling back to sysfs fallback for: ueagle-atm/eagleII.fw
==================================================================
BUG: KASAN: use-after-free in kernfs_root fs/kernfs/kernfs-internal.h:66 [inline]
BUG: KASAN: use-after-free in kernfs_next_descendant_post fs/kernfs/dir.c:1326 [inline]
BUG: KASAN: use-after-free in kernfs_activate fs/kernfs/dir.c:1381 [inline]
BUG: KASAN: use-after-free in kernfs_add_one+0x4ae/0x850 fs/kernfs/dir.c:806
Read of size 8 at addr ffff8880283604b8 by task kworker/0:8/3686

CPU: 0 PID: 3686 Comm: kworker/0:8 Not tainted 6.1.103-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 06/27/2024
Workqueue: events request_firmware_work_func
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1e3/0x2cb lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:284 [inline]
 print_report+0x15f/0x4f0 mm/kasan/report.c:395
 kasan_report+0x136/0x160 mm/kasan/report.c:495
 kernfs_root fs/kernfs/kernfs-internal.h:66 [inline]
 kernfs_next_descendant_post fs/kernfs/dir.c:1326 [inline]
 kernfs_activate fs/kernfs/dir.c:1381 [inline]
 kernfs_add_one+0x4ae/0x850 fs/kernfs/dir.c:806
 kernfs_create_dir_ns+0xd5/0x120 fs/kernfs/dir.c:1056
 sysfs_create_dir_ns+0x185/0x390 fs/sysfs/dir.c:59
 create_dir lib/kobject.c:63 [inline]
 kobject_add_internal+0x6df/0xd10 lib/kobject.c:231
 kobject_add_varg lib/kobject.c:366 [inline]
 kobject_add+0x14e/0x210 lib/kobject.c:418
 class_dir_create_and_add drivers/base/core.c:3226 [inline]
 get_device_parent+0x391/0x400 drivers/base/core.c:3281
 device_add+0x336/0xfd0 drivers/base/core.c:3610
 fw_load_sysfs_fallback drivers/base/firmware_loader/fallback.c:82 [inline]
 fw_load_from_user_helper drivers/base/firmware_loader/fallback.c:158 [inline]
 firmware_fallback_sysfs+0x2fd/0x940 drivers/base/firmware_loader/fallback.c:234
 _request_firmware+0xc13/0x1200 drivers/base/firmware_loader/main.c:856
 request_firmware_work_func+0x126/0x270 drivers/base/firmware_loader/main.c:1105
 process_one_work+0x8a9/0x11d0 kernel/workqueue.c:2292
 worker_thread+0xa47/0x1200 kernel/workqueue.c:2439
 kthread+0x28d/0x320 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295
 </TASK>

Allocated by task 3686:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x4b/0x70 mm/kasan/common.c:52
 __kasan_slab_alloc+0x65/0x70 mm/kasan/common.c:328
 kasan_slab_alloc include/linux/kasan.h:201 [inline]
 slab_post_alloc_hook+0x52/0x3a0 mm/slab.h:737
 slab_alloc_node mm/slub.c:3398 [inline]
 slab_alloc mm/slub.c:3406 [inline]
 __kmem_cache_alloc_lru mm/slub.c:3413 [inline]
 kmem_cache_alloc+0x10c/0x2d0 mm/slub.c:3422
 kmem_cache_zalloc include/linux/slab.h:682 [inline]
 __kernfs_new_node+0xd4/0x870 fs/kernfs/dir.c:614
 kernfs_new_node+0x136/0x230 fs/kernfs/dir.c:690
 kernfs_create_dir_ns+0x3f/0x120 fs/kernfs/dir.c:1046
 sysfs_create_dir_ns+0x185/0x390 fs/sysfs/dir.c:59
 create_dir lib/kobject.c:63 [inline]
 kobject_add_internal+0x6df/0xd10 lib/kobject.c:231
 kobject_add_varg lib/kobject.c:366 [inline]
 kobject_add+0x14e/0x210 lib/kobject.c:418
 class_dir_create_and_add drivers/base/core.c:3226 [inline]
 get_device_parent+0x391/0x400 drivers/base/core.c:3281
 device_add+0x336/0xfd0 drivers/base/core.c:3610
 fw_load_sysfs_fallback drivers/base/firmware_loader/fallback.c:82 [inline]
 fw_load_from_user_helper drivers/base/firmware_loader/fallback.c:158 [inline]
 firmware_fallback_sysfs+0x2fd/0x940 drivers/base/firmware_loader/fallback.c:234
 _request_firmware+0xc13/0x1200 drivers/base/firmware_loader/main.c:856
 request_firmware_work_func+0x126/0x270 drivers/base/firmware_loader/main.c:1105
 process_one_work+0x8a9/0x11d0 kernel/workqueue.c:2292
 worker_thread+0xa47/0x1200 kernel/workqueue.c:2439
 kthread+0x28d/0x320 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Freed by task 4218:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x4b/0x70 mm/kasan/common.c:52
 kasan_save_free_info+0x27/0x40 mm/kasan/generic.c:516
 ____kasan_slab_free+0xd6/0x120 mm/kasan/common.c:236
 kasan_slab_free include/linux/kasan.h:177 [inline]
 slab_free_hook mm/slub.c:1724 [inline]
 slab_free_freelist_hook mm/slub.c:1750 [inline]
 slab_free mm/slub.c:3661 [inline]
 kmem_cache_free+0x292/0x510 mm/slub.c:3683
 kernfs_put+0x325/0x4a0 fs/kernfs/dir.c:568
 __kernfs_remove+0x5fc/0x710 fs/kernfs/dir.c:1480
 kernfs_remove+0x76/0x90 fs/kernfs/dir.c:1500
 __kobject_del+0xe2/0x310 lib/kobject.c:596
 kobject_del+0x41/0x60 lib/kobject.c:619
 device_del+0x9fe/0xbd0 drivers/base/core.c:3899
 usb_disconnect+0x58f/0x8c0 drivers/usb/core/hub.c:2301
 hub_port_connect drivers/usb/core/hub.c:5321 [inline]
 hub_port_connect_change drivers/usb/core/hub.c:5617 [inline]
 port_event drivers/usb/core/hub.c:5773 [inline]
 hub_event+0x1f78/0x5730 drivers/usb/core/hub.c:5855
 process_one_work+0x8a9/0x11d0 kernel/workqueue.c:2292
 process_scheduled_works kernel/workqueue.c:2355 [inline]
 worker_thread+0xd04/0x1200 kernel/workqueue.c:2441
 kthread+0x28d/0x320 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

The buggy address belongs to the object at ffff888028360488
 which belongs to the cache kernfs_node_cache of size 168
The buggy address is located 48 bytes inside of
 168-byte region [ffff888028360488, ffff888028360530)

The buggy address belongs to the physical page:
page:ffffea0000a0d800 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x28360
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffffea0001639780 dead000000000002 ffff888012a40c80
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 3868, tgid 3868 (syz-executor), ts 78422686506, free_ts 78310465521
 set_page_owner include/linux/page_owner.h:31 [inline]
 post_alloc_hook+0x18d/0x1b0 mm/page_alloc.c:2517
 prep_new_page mm/page_alloc.c:2524 [inline]
 get_page_from_freelist+0x322e/0x33b0 mm/page_alloc.c:4283
 __alloc_pages+0x28d/0x770 mm/page_alloc.c:5551
 alloc_slab_page+0x6a/0x150 mm/slub.c:1794
 allocate_slab mm/slub.c:1939 [inline]
 new_slab+0x84/0x2d0 mm/slub.c:1992
 ___slab_alloc+0xc20/0x1270 mm/slub.c:3180
 __slab_alloc mm/slub.c:3279 [inline]
 slab_alloc_node mm/slub.c:3364 [inline]
 slab_alloc mm/slub.c:3406 [inline]
 __kmem_cache_alloc_lru mm/slub.c:3413 [inline]
 kmem_cache_alloc+0x1a5/0x2d0 mm/slub.c:3422
 kmem_cache_zalloc include/linux/slab.h:682 [inline]
 __kernfs_new_node+0xd4/0x870 fs/kernfs/dir.c:614
 kernfs_new_node+0x136/0x230 fs/kernfs/dir.c:690
 __kernfs_create_file+0x45/0x2e0 fs/kernfs/file.c:1047
 sysfs_add_file_mode_ns+0x246/0x300 fs/sysfs/file.c:294
 create_files fs/sysfs/group.c:64 [inline]
 internal_create_group+0x545/0xed0 fs/sysfs/group.c:148
 internal_create_groups fs/sysfs/group.c:188 [inline]
 sysfs_create_groups+0x52/0x110 fs/sysfs/group.c:214
 create_dir lib/kobject.c:68 [inline]
 kobject_add_internal+0x725/0xd10 lib/kobject.c:231
 kobject_add_varg lib/kobject.c:366 [inline]
 kobject_init_and_add+0x120/0x190 lib/kobject.c:449
 netdev_queue_add_kobject net/core/net-sysfs.c:1664 [inline]
 netdev_queue_update_kobjects+0x1f2/0x480 net/core/net-sysfs.c:1716
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1444 [inline]
 free_pcp_prepare mm/page_alloc.c:1494 [inline]
 free_unref_page_prepare+0xf63/0x1120 mm/page_alloc.c:3362
 free_unref_page_list+0x663/0x900 mm/page_alloc.c:3503
 release_pages+0x2836/0x2b40 mm/swap.c:1055
 tlb_batch_pages_flush mm/mmu_gather.c:59 [inline]
 tlb_flush_mmu_free mm/mmu_gather.c:254 [inline]
 tlb_flush_mmu+0xfc/0x210 mm/mmu_gather.c:261
 tlb_finish_mmu+0xce/0x1f0 mm/mmu_gather.c:361
 exit_mmap+0x3c3/0x9f0 mm/mmap.c:3239
 __mmput+0x115/0x3c0 kernel/fork.c:1199
 exit_mm+0x226/0x300 kernel/exit.c:565
 do_exit+0x9f6/0x26a0 kernel/exit.c:858
 do_group_exit+0x202/0x2b0 kernel/exit.c:1021
 __do_sys_exit_group kernel/exit.c:1032 [inline]
 __se_sys_exit_group kernel/exit.c:1030 [inline]
 __x64_sys_exit_group+0x3b/0x40 kernel/exit.c:1030
 do_syscall_x64 arch/x86/entry/common.c:51 [inline]
 do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:81
 entry_SYSCALL_64_after_hwframe+0x68/0xd2

Memory state around the buggy address:
 ffff888028360380: fc fc fc fc fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888028360400: fb fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc
>ffff888028360480: fc fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                        ^
 ffff888028360500: fb fb fb fb fb fb fc fc fc fc fc fc fc fc fa fb
 ffff888028360580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/08/05 12:07 linux-6.1.y 48d525b0e463 e35c337f .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-6-1-kasan KASAN: use-after-free Read in kernfs_add_one
* Struck through repros no longer work on HEAD.