syzbot


KASAN: use-after-free Read in wait_subpage_spinlock

Status: auto-obsoleted due to no activity on 2023/05/15 18:56
Subsystems: btrfs
[Documentation on labels]
Reported-by: syzbot+042fc0183073dc434e78@syzkaller.appspotmail.com
First crash: 449d, last: 428d
Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [btrfs?] KASAN: use-after-free Read in wait_subpage_spinlock 0 (1) 2023/01/02 10:01

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in btrfs_sb fs/btrfs/super.h:14 [inline]
BUG: KASAN: use-after-free in wait_subpage_spinlock+0x87/0x1c0 fs/btrfs/inode.c:8232
Read of size 8 at addr ffff88804263a678 by task syz-executor.4/15689

CPU: 1 PID: 15689 Comm: syz-executor.4 Not tainted 6.2.0-rc4-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1e3/0x2d0 lib/dump_stack.c:106
 print_address_description+0x74/0x340 mm/kasan/report.c:306
 print_report+0x107/0x220 mm/kasan/report.c:417
 kasan_report+0x139/0x170 mm/kasan/report.c:517
 btrfs_sb fs/btrfs/super.h:14 [inline]
 wait_subpage_spinlock+0x87/0x1c0 fs/btrfs/inode.c:8232
 __btrfs_release_folio fs/btrfs/inode.c:8261 [inline]
 btrfs_release_folio+0x146/0x340 fs/btrfs/inode.c:8271
 shrink_folio_list+0x2345/0x6a40 mm/vmscan.c:2000
 shrink_inactive_list+0x5f2/0xca0 mm/vmscan.c:2526
 shrink_list mm/vmscan.c:2767 [inline]
 shrink_lruvec+0x449/0xc50 mm/vmscan.c:5951
 shrink_node_memcgs+0x35c/0x780 mm/vmscan.c:6138
 shrink_node+0x299/0x1050 mm/vmscan.c:6169
 shrink_zones+0x4fb/0xc40 mm/vmscan.c:6407
 do_try_to_free_pages+0x215/0xcd0 mm/vmscan.c:6469
 try_to_free_mem_cgroup_pages+0x3d7/0x6e0 mm/vmscan.c:6786
 memory_max_write+0x273/0x490 mm/memcontrol.c:6481
 cgroup_file_write+0x2ab/0x780 kernel/cgroup/cgroup.c:4061
 kernfs_fop_write_iter+0x3ac/0x500 fs/kernfs/file.c:334
 call_write_iter include/linux/fs.h:2189 [inline]
 new_sync_write fs/read_write.c:491 [inline]
 vfs_write+0x7b5/0xbb0 fs/read_write.c:584
 ksys_write+0x19b/0x2c0 fs/read_write.c:637
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x2b/0x70 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7ff8d208c0c9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 19 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ff8d2d00168 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007ff8d21abf80 RCX: 00007ff8d208c0c9
RDX: 0000000000000012 RSI: 0000000020000080 RDI: 000000000000000a
RBP: 00007ff8d20e7ae9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffd526db26f R14: 00007ff8d2d00300 R15: 0000000000022000
 </TASK>

Allocated by task 15588:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x4c/0x70 mm/kasan/common.c:52
 ____kasan_kmalloc mm/kasan/common.c:371 [inline]
 __kasan_kmalloc+0x97/0xb0 mm/kasan/common.c:380
 kasan_kmalloc include/linux/kasan.h:211 [inline]
 __do_kmalloc_node mm/slab_common.c:968 [inline]
 __kmalloc+0xaf/0x190 mm/slab_common.c:981
 kmalloc include/linux/slab.h:584 [inline]
 tomoyo_realpath_from_path+0xcd/0x5f0 security/tomoyo/realpath.c:251
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_path_number_perm+0x1fe/0x7d0 security/tomoyo/file.c:723
 security_file_ioctl+0x55/0xb0 security/security.c:1624
 __do_sys_ioctl fs/ioctl.c:864 [inline]
 __se_sys_ioctl+0x48/0x170 fs/ioctl.c:856
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x2b/0x70 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 15588:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x4c/0x70 mm/kasan/common.c:52
 kasan_save_free_info+0x27/0x40 mm/kasan/generic.c:518
 ____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:1781 [inline]
 slab_free_freelist_hook+0x12e/0x1a0 mm/slub.c:1807
 slab_free mm/slub.c:3787 [inline]
 __kmem_cache_free+0x71/0x110 mm/slub.c:3800
 tomoyo_realpath_from_path+0x5b9/0x5f0 security/tomoyo/realpath.c:286
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_path_number_perm+0x1fe/0x7d0 security/tomoyo/file.c:723
 security_file_ioctl+0x55/0xb0 security/security.c:1624
 __do_sys_ioctl fs/ioctl.c:864 [inline]
 __se_sys_ioctl+0x48/0x170 fs/ioctl.c:856
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x2b/0x70 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Last potentially related work creation:
 kasan_save_stack+0x3b/0x60 mm/kasan/common.c:45
 __kasan_record_aux_stack+0xb0/0xc0 mm/kasan/generic.c:488
 insert_work+0x54/0x3e0 kernel/workqueue.c:1358
 __queue_work+0xaaa/0xd60 kernel/workqueue.c:1517
 queue_work_on+0x137/0x240 kernel/workqueue.c:1545
 rcu_do_batch kernel/rcu/tree.c:2246 [inline]
 rcu_core+0xa91/0x1790 kernel/rcu/tree.c:2506
 __do_softirq+0x277/0x75b kernel/softirq.c:571

Second to last potentially related work creation:
 kasan_save_stack+0x3b/0x60 mm/kasan/common.c:45
 __kasan_record_aux_stack+0xb0/0xc0 mm/kasan/generic.c:488
 __call_rcu_common kernel/rcu/tree.c:2755 [inline]
 call_rcu+0x163/0xab0 kernel/rcu/tree.c:2868
 put_super fs/super.c:311 [inline]
 deactivate_locked_super+0xdb/0xf0 fs/super.c:343
 cleanup_mnt+0x494/0x520 fs/namespace.c:1291
 task_work_run+0x243/0x300 kernel/task_work.c:179
 resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
 exit_to_user_mode_loop+0x134/0x160 kernel/entry/common.c:171
 exit_to_user_mode_prepare+0xad/0x110 kernel/entry/common.c:203
 __syscall_exit_to_user_mode_work kernel/entry/common.c:285 [inline]
 syscall_exit_to_user_mode+0x2e/0x60 kernel/entry/common.c:296
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

The buggy address belongs to the object at ffff88804263a000
 which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 1656 bytes inside of
 4096-byte region [ffff88804263a000, ffff88804263b000)

The buggy address belongs to the physical page:
page:ffffea0001098e00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x42638
head:ffffea0001098e00 order:3 compound_mapcount:0 subpages_mapcount:0 compound_pincount:0
anon flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 ffff888012842140 0000000000000000 dead000000000001
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 0x1d2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC|__GFP_HARDWALL), pid 4422, tgid 4422 (udevd), ts 160884412203, free_ts 14217499967
 prep_new_page mm/page_alloc.c:2531 [inline]
 get_page_from_freelist+0x72b/0x7a0 mm/page_alloc.c:4283
 __alloc_pages+0x259/0x560 mm/page_alloc.c:5549
 alloc_slab_page+0xbd/0x190 mm/slub.c:1851
 allocate_slab+0x5e/0x3c0 mm/slub.c:1998
 new_slab mm/slub.c:2051 [inline]
 ___slab_alloc+0x7f4/0xeb0 mm/slub.c:3193
 __slab_alloc mm/slub.c:3292 [inline]
 __slab_alloc_node mm/slub.c:3345 [inline]
 slab_alloc_node mm/slub.c:3442 [inline]
 __kmem_cache_alloc_node+0x25b/0x340 mm/slub.c:3491
 __do_kmalloc_node mm/slab_common.c:967 [inline]
 __kmalloc+0x9e/0x190 mm/slab_common.c:981
 kmalloc include/linux/slab.h:584 [inline]
 tomoyo_realpath_from_path+0xcd/0x5f0 security/tomoyo/realpath.c:251
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_path_perm+0x280/0x680 security/tomoyo/file.c:822
 security_inode_getattr+0xc0/0x140 security/security.c:1375
 vfs_getattr fs/stat.c:161 [inline]
 vfs_statx+0x198/0x4b0 fs/stat.c:236
 vfs_fstatat fs/stat.c:270 [inline]
 __do_sys_newfstatat fs/stat.c:440 [inline]
 __se_sys_newfstatat+0x104/0x7b0 fs/stat.c:434
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x2b/0x70 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1446 [inline]
 free_pcp_prepare+0x751/0x780 mm/page_alloc.c:1496
 free_unref_page_prepare mm/page_alloc.c:3369 [inline]
 free_unref_page+0x19/0x4c0 mm/page_alloc.c:3464
 free_contig_range+0xa3/0x160 mm/page_alloc.c:9485
 destroy_args+0xfe/0x990 mm/debug_vm_pgtable.c:998
 debug_vm_pgtable+0x453/0x4b0 mm/debug_vm_pgtable.c:1318
 do_one_initcall+0xbd/0x2c0 init/main.c:1306
 do_initcall_level+0x168/0x220 init/main.c:1379
 do_initcalls+0x43/0x90 init/main.c:1395
 kernel_init_freeable+0x471/0x620 init/main.c:1634
 kernel_init+0x19/0x2b0 init/main.c:1522
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308

Memory state around the buggy address:
 ffff88804263a500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88804263a580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88804263a600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                                ^
 ffff88804263a680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88804263a700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (7):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/01/15 18:55 upstream 5dc4c995db9e a63719e7 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root KASAN: use-after-free Read in wait_subpage_spinlock
2023/01/15 16:57 upstream 7c6984405241 a63719e7 .config console log report info ci-upstream-kasan-gce-selinux-root KASAN: use-after-free Read in wait_subpage_spinlock
2023/01/10 09:19 upstream 5a41237ad1d4 48bc529a .config console log report info ci-qemu-upstream KASAN: use-after-free Read in wait_subpage_spinlock
2023/01/04 15:42 upstream 69b41ac87e4a 1dac8c7a .config console log report info ci-qemu-upstream KASAN: use-after-free Read in wait_subpage_spinlock
2023/01/11 14:07 upstream 7dd4b804e080 96166539 .config console log report info ci-qemu-upstream-386 KASAN: use-after-free Read in wait_subpage_spinlock
2023/01/09 08:24 upstream 1fe4fd6f5cad 1dac8c7a .config console log report info ci-qemu-upstream-386 KASAN: use-after-free Read in wait_subpage_spinlock
2022/12/26 05:59 upstream 1b929c02afd3 9da18ae8 .config console log report info ci-qemu-upstream-386 KASAN: use-after-free Read in wait_subpage_spinlock
* Struck through repros no longer work on HEAD.