syzbot


KASAN: use-after-free Read in kernfs_get (2)

Status: premoderation: reported on 2024/07/15 05:15
Reported-by: syzbot+796f6b9dffdc6fa01dfc@syzkaller.appspotmail.com
First crash: 129d, last: 11d
Similar bugs (8)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Read in kernfs_get kernfs 8 861d 983d 0/28 auto-obsoleted due to no activity on 2022/11/11 09:18
upstream KASAN: use-after-free Read in kernfs_get (2) kernfs 2 643d 730d 0/28 auto-obsoleted due to no activity on 2023/06/16 19:32
android-5-15 KASAN: use-after-free Read in kernfs_get 3 640d 764d 0/2 auto-obsoleted due to no activity on 2023/05/20 22:47
android-6-1 KASAN: use-after-free Read in kernfs_get 2 100d 145d 0/2 auto-obsoleted due to no activity on 2024/11/11 11:50
linux-5.15 KASAN: use-after-free Read in kernfs_get 1 98d 98d 0/3 upstream: reported on 2024/08/15 10:42
android-6-1 KASAN: use-after-free Write in kernfs_get 1 2d00h 2d00h 0/2 premoderation: reported on 2024/11/19 13:51
upstream KASAN: slab-use-after-free Read in kernfs_get kernfs 1 279d 279d 0/28 auto-obsoleted due to no activity on 2024/05/26 00:41
android-5-15 KASAN: use-after-free Write in kernfs_get 3 395d 482d 0/2 auto-obsoleted due to no activity on 2024/01/21 14:31

Sample crash report:
==================================================================
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+0x21/0x90 fs/kernfs/dir.c:504
Read of size 4 at addr ffff8881150090c8 by task kworker/0:59/11796

CPU: 0 PID: 11796 Comm: kworker/0:59 Not tainted 5.15.167-syzkaller-android13-5.15.167_r00 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
Workqueue: events flush_stashed_error_work
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x151/0x1c0 lib/dump_stack.c:106
 print_address_description+0x87/0x3b0 mm/kasan/report.c:248
 __kasan_report mm/kasan/report.c:427 [inline]
 kasan_report+0x179/0x1c0 mm/kasan/report.c:444
 kasan_check_range+0x293/0x2a0 mm/kasan/generic.c:189
 __kasan_check_read+0x11/0x20 mm/kasan/shadow.c:31
 instrument_atomic_read include/linux/instrumented.h:71 [inline]
 atomic_read include/linux/atomic/atomic-instrumented.h:27 [inline]
 kernfs_get+0x21/0x90 fs/kernfs/dir.c:504
 sysfs_notify+0x9a/0xd0 fs/sysfs/file.c:190
 ext4_notify_error_sysfs+0x25/0x30 fs/ext4/sysfs.c:516
 flush_stashed_error_work+0x302/0x320
 process_one_work+0x6bb/0xc10 kernel/workqueue.c:2325
 worker_thread+0xad5/0x12a0 kernel/workqueue.c:2472
 kthread+0x421/0x510 kernel/kthread.c:337
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:287
 </TASK>

Allocated by task 15135:
 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:433 [inline]
 __kasan_slab_alloc+0xb1/0xe0 mm/kasan/common.c:466
 kasan_slab_alloc include/linux/kasan.h:217 [inline]
 slab_post_alloc_hook+0x53/0x2c0 mm/slab.h:550
 slab_alloc_node mm/slub.c:3240 [inline]
 slab_alloc mm/slub.c:3248 [inline]
 kmem_cache_alloc+0xf5/0x200 mm/slub.c:3253
 kmem_cache_zalloc include/linux/slab.h:723 [inline]
 __kernfs_new_node+0xdb/0x700 fs/kernfs/dir.c:593
 kernfs_new_node+0x130/0x230 fs/kernfs/dir.c:669
 kernfs_create_dir_ns+0x44/0x130 fs/kernfs/dir.c:1017
 sysfs_create_dir_ns+0x185/0x390 fs/sysfs/dir.c:59
 create_dir lib/kobject.c:89 [inline]
 kobject_add_internal+0x763/0xd90 lib/kobject.c:263
 kobject_add_varg lib/kobject.c:398 [inline]
 kobject_init_and_add+0x120/0x190 lib/kobject.c:481
 ext4_register_sysfs+0xbf/0x2c0 fs/ext4/sysfs.c:529
 ext4_fill_super+0x8a31/0x96e0 fs/ext4/super.c:4940
 mount_bdev+0x282/0x3b0 fs/super.c:1398
 ext4_mount+0x34/0x40 fs/ext4/super.c:6593
 legacy_get_tree+0xf1/0x190 fs/fs_context.c:611
 vfs_get_tree+0x88/0x290 fs/super.c:1528
 do_new_mount+0x2ba/0xb30 fs/namespace.c:3005
 path_mount+0x671/0x1070 fs/namespace.c:3335
 do_mount fs/namespace.c:3348 [inline]
 __do_sys_mount fs/namespace.c:3556 [inline]
 __se_sys_mount+0x2c4/0x3b0 fs/namespace.c:3533
 __x64_sys_mount+0xbf/0xd0 fs/namespace.c:3533
 x64_sys_call+0x49d/0x9a0 arch/x86/include/generated/asm/syscalls_64.h:166
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x66/0xd0

Freed by task 15115:
 kasan_save_stack mm/kasan/common.c:38 [inline]
 kasan_set_track+0x4b/0x70 mm/kasan/common.c:45
 kasan_set_free_info+0x23/0x40 mm/kasan/generic.c:370
 ____kasan_slab_free+0x126/0x160 mm/kasan/common.c:365
 __kasan_slab_free+0x11/0x20 mm/kasan/common.c:373
 kasan_slab_free include/linux/kasan.h:193 [inline]
 slab_free_hook mm/slub.c:1723 [inline]
 slab_free_freelist_hook+0xbd/0x190 mm/slub.c:1749
 slab_free mm/slub.c:3519 [inline]
 kmem_cache_free+0x116/0x2e0 mm/slub.c:3535
 kernfs_put+0x392/0x520 fs/kernfs/dir.c:547
 sysfs_put include/linux/sysfs.h:641 [inline]
 __kobject_del+0x10f/0x300 lib/kobject.c:629
 kobject_del+0x45/0x60 lib/kobject.c:651
 ext4_unregister_sysfs+0x91/0xa0 fs/ext4/sysfs.c:563
 ext4_put_super+0x80/0xd20 fs/ext4/super.c:1182
 generic_shutdown_super+0x157/0x2e0 fs/super.c:475
 kill_block_super+0x7e/0xe0 fs/super.c:1425
 deactivate_locked_super+0xad/0x110 fs/super.c:335
 deactivate_super+0xbe/0xf0 fs/super.c:366
 cleanup_mnt+0x45c/0x510 fs/namespace.c:1143
 __cleanup_mnt+0x19/0x20 fs/namespace.c:1150
 task_work_run+0x129/0x190 kernel/task_work.c:188
 tracehook_notify_resume include/linux/tracehook.h:189 [inline]
 exit_to_user_mode_loop+0xc4/0xe0 kernel/entry/common.c:181
 exit_to_user_mode_prepare+0x5a/0xa0 kernel/entry/common.c:214
 __syscall_exit_to_user_mode_work kernel/entry/common.c:296 [inline]
 syscall_exit_to_user_mode+0x26/0x160 kernel/entry/common.c:307
 do_syscall_64+0x47/0xb0 arch/x86/entry/common.c:86
 entry_SYSCALL_64_after_hwframe+0x66/0xd0

The buggy address belongs to the object at ffff8881150090c8
 which belongs to the cache kernfs_node_cache of size 136
The buggy address is located 0 bytes inside of
 136-byte region [ffff8881150090c8, ffff888115009150)
The buggy address belongs to the page:
page:ffffea0004540240 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x115009
flags: 0x4000000000000200(slab|zone=1)
raw: 4000000000000200 ffffea0004540300 0000000400000004 ffff8881001cc480
raw: 0000000000000000 0000000000140014 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 4813, ts 270963734219, free_ts 250112459664
 set_page_owner include/linux/page_owner.h:33 [inline]
 post_alloc_hook+0x1a3/0x1b0 mm/page_alloc.c:2605
 prep_new_page+0x1b/0x110 mm/page_alloc.c:2611
 get_page_from_freelist+0x3550/0x35d0 mm/page_alloc.c:4485
 __alloc_pages+0x27e/0x8f0 mm/page_alloc.c:5779
 allocate_slab mm/slub.c:1932 [inline]
 new_slab+0x9a/0x4e0 mm/slub.c:1995
 ___slab_alloc+0x39e/0x830 mm/slub.c:3028
 __slab_alloc+0x4a/0x90 mm/slub.c:3115
 slab_alloc_node mm/slub.c:3206 [inline]
 slab_alloc mm/slub.c:3248 [inline]
 kmem_cache_alloc+0x134/0x200 mm/slub.c:3253
 kmem_cache_zalloc include/linux/slab.h:723 [inline]
 __kernfs_new_node+0xdb/0x700 fs/kernfs/dir.c:593
 kernfs_new_node+0x130/0x230 fs/kernfs/dir.c:669
 kernfs_create_dir_ns+0x44/0x130 fs/kernfs/dir.c:1017
 sysfs_create_dir_ns+0x185/0x390 fs/sysfs/dir.c:59
 create_dir lib/kobject.c:89 [inline]
 kobject_add_internal+0x763/0xd90 lib/kobject.c:263
 kobject_add_varg lib/kobject.c:398 [inline]
 kobject_init_and_add+0x120/0x190 lib/kobject.c:481
 netdev_queue_add_kobject net/core/net-sysfs.c:1666 [inline]
 netdev_queue_update_kobjects+0x185/0x400 net/core/net-sysfs.c:1711
 register_queue_kobjects net/core/net-sysfs.c:1772 [inline]
 netdev_register_kobject+0x270/0x320 net/core/net-sysfs.c:2018
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:26 [inline]
 free_pages_prepare mm/page_alloc.c:1472 [inline]
 free_pcp_prepare mm/page_alloc.c:1544 [inline]
 free_unref_page_prepare+0x7c8/0x7d0 mm/page_alloc.c:3534
 free_unref_page+0xe8/0x750 mm/page_alloc.c:3616
 free_the_page mm/page_alloc.c:805 [inline]
 __free_pages+0x61/0xf0 mm/page_alloc.c:5855
 __free_slab+0xec/0x1d0 mm/slub.c:2020
 free_slab mm/slub.c:2035 [inline]
 discard_slab+0x29/0x40 mm/slub.c:2041
 __slab_free+0x205/0x290 mm/slub.c:3424
 do_slab_free mm/slub.c:3507 [inline]
 ___cache_free+0x109/0x120 mm/slub.c:3526
 qlink_free+0x4d/0x90 mm/kasan/quarantine.c:157
 qlist_free_all+0x44/0xb0 mm/kasan/quarantine.c:176
 kasan_quarantine_reduce+0x15a/0x180 mm/kasan/quarantine.c:283
 ____kasan_kmalloc+0x2f/0x110 mm/kasan/common.c:478
 __kasan_kmalloc+0x9/0x10 mm/kasan/common.c:521
 kasan_kmalloc include/linux/kasan.h:227 [inline]
 kmem_cache_alloc_trace+0x115/0x210 mm/slub.c:3267
 kmem_cache_alloc_node_trace include/linux/slab.h:491 [inline]
 kmalloc_node include/linux/slab.h:621 [inline]
 kzalloc_node include/linux/slab.h:744 [inline]
 __get_vm_area_node+0x117/0x360 mm/vmalloc.c:2432
 __vmalloc_node_range+0xe2/0x8d0 mm/vmalloc.c:3051
 alloc_thread_stack_node kernel/fork.c:254 [inline]
 dup_task_struct+0x416/0xc60 kernel/fork.c:944

Memory state around the buggy address:
 ffff888115008f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff888115009000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888115009080: fb fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb
                                              ^
 ffff888115009100: fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc fc
 ffff888115009180: fc fc fa fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
general protection fault, probably for non-canonical address 0xf29ffc274000076b: 0000 [#1] PREEMPT SMP KASAN
KASAN: maybe wild-memory-access in range [0x9500013a00003b58-0x9500013a00003b5f]
CPU: 0 PID: 11796 Comm: kworker/0:59 Tainted: G    B             5.15.167-syzkaller-android13-5.15.167_r00 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
Workqueue: events flush_stashed_error_work
RIP: 0010:kernfs_root fs/kernfs/kernfs-internal.h:50 [inline]
RIP: 0010:kernfs_find_and_get_ns+0x52/0x110 fs/kernfs/dir.c:884
Code: 08 48 89 f8 48 c1 e8 03 42 80 3c 30 00 74 05 e8 74 29 d5 ff 49 8b 5d 08 48 85 db 49 0f 44 dd 48 83 c3 50 48 89 d8 48 c1 e8 03 <42> 80 3c 30 00 74 08 48 89 df e8 4f 29 d5 ff 4c 8b 33 49 83 c6 68
RSP: 0018:ffffc90002907c58 EFLAGS: 00010a02
RAX: 12a000274000076b RBX: 9500013a00003b5b RCX: ffffffff81dd7fec
RDX: 0000000000000000 RSI: 0000000000000292 RDI: ffff8881150090d0
RBP: ffffc90002907c80 R08: dffffc0000000000 R09: 0000000000000003
R10: ffffed1022a01219 R11: dffffc0000000001 R12: ffffffff858f1220
R13: ffff8881150090c8 R14: dffffc0000000000 R15: 0000000000000000
FS:  0000000000000000(0000) GS:ffff8881f7000000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007efc29f23000 CR3: 0000000110286000 CR4: 00000000003506b0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 kernfs_find_and_get include/linux/kernfs.h:574 [inline]
 sysfs_notify+0x73/0xd0 fs/sysfs/file.c:193
 ext4_notify_error_sysfs+0x25/0x30 fs/ext4/sysfs.c:516
 flush_stashed_error_work+0x302/0x320
 process_one_work+0x6bb/0xc10 kernel/workqueue.c:2325
 worker_thread+0xad5/0x12a0 kernel/workqueue.c:2472
 kthread+0x421/0x510 kernel/kthread.c:337
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:287
 </TASK>
Modules linked in:
---[ end trace ab82004770004369 ]---
RIP: 0010:kernfs_root fs/kernfs/kernfs-internal.h:50 [inline]
RIP: 0010:kernfs_find_and_get_ns+0x52/0x110 fs/kernfs/dir.c:884
Code: 08 48 89 f8 48 c1 e8 03 42 80 3c 30 00 74 05 e8 74 29 d5 ff 49 8b 5d 08 48 85 db 49 0f 44 dd 48 83 c3 50 48 89 d8 48 c1 e8 03 <42> 80 3c 30 00 74 08 48 89 df e8 4f 29 d5 ff 4c 8b 33 49 83 c6 68
RSP: 0018:ffffc90002907c58 EFLAGS: 00010a02
RAX: 12a000274000076b RBX: 9500013a00003b5b RCX: ffffffff81dd7fec
RDX: 0000000000000000 RSI: 0000000000000292 RDI: ffff8881150090d0
RBP: ffffc90002907c80 R08: dffffc0000000000 R09: 0000000000000003
R10: ffffed1022a01219 R11: dffffc0000000001 R12: ffffffff858f1220
R13: ffff8881150090c8 R14: dffffc0000000000 R15: 0000000000000000
FS:  0000000000000000(0000) GS:ffff8881f7000000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007efc29f23000 CR3: 0000000110286000 CR4: 00000000003506b0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
   0:	08 48 89             	or     %cl,-0x77(%rax)
   3:	f8                   	clc
   4:	48 c1 e8 03          	shr    $0x3,%rax
   8:	42 80 3c 30 00       	cmpb   $0x0,(%rax,%r14,1)
   d:	74 05                	je     0x14
   f:	e8 74 29 d5 ff       	call   0xffd52988
  14:	49 8b 5d 08          	mov    0x8(%r13),%rbx
  18:	48 85 db             	test   %rbx,%rbx
  1b:	49 0f 44 dd          	cmove  %r13,%rbx
  1f:	48 83 c3 50          	add    $0x50,%rbx
  23:	48 89 d8             	mov    %rbx,%rax
  26:	48 c1 e8 03          	shr    $0x3,%rax
* 2a:	42 80 3c 30 00       	cmpb   $0x0,(%rax,%r14,1) <-- trapping instruction
  2f:	74 08                	je     0x39
  31:	48 89 df             	mov    %rbx,%rdi
  34:	e8 4f 29 d5 ff       	call   0xffd52988
  39:	4c 8b 33             	mov    (%rbx),%r14
  3c:	49 83 c6 68          	add    $0x68,%r14

Crashes (7):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/11/10 08:08 android13-5.15-lts 5e4635681cf1 6b856513 .config console log report info [disk image] [vmlinux] [kernel image] ci2-android-5-15 KASAN: use-after-free Read in kernfs_get
2024/09/12 06:58 android13-5.15-lts e6fb3b0fa87f d94c83d8 .config console log report info [disk image] [vmlinux] [kernel image] ci2-android-5-15 KASAN: use-after-free Read in kernfs_get
2024/09/10 04:33 android13-5.15-lts c53388f01037 784df80e .config console log report info [disk image] [vmlinux] [kernel image] ci2-android-5-15 KASAN: use-after-free Read in kernfs_get
2024/08/30 22:23 android13-5.15-lts 29d153aabd54 1eda0d14 .config console log report info [disk image] [vmlinux] [kernel image] ci2-android-5-15 KASAN: use-after-free Read in kernfs_get
2024/07/15 05:14 android13-5.15-lts db06c48ab67e eaeb5c15 .config console log report info [disk image] [vmlinux] [kernel image] ci2-android-5-15 KASAN: use-after-free Read in kernfs_get
2024/10/15 17:27 android13-5.15-lts 5e4635681cf1 7eb57b4a .config console log report info [disk image] [vmlinux] [kernel image] ci2-android-5-15 KASAN: use-after-free Write in kernfs_get
2024/08/31 05:26 android13-5.15-lts 29d153aabd54 1eda0d14 .config console log report info [disk image] [vmlinux] [kernel image] ci2-android-5-15 KASAN: use-after-free Write in kernfs_get
* Struck through repros no longer work on HEAD.