syzbot


KASAN: use-after-free Read in btrfs_clear_delalloc_extent

Status: upstream: reported on 2022/12/07 06:42
Reported-by: syzbot+7f9db4fc871a025068b5@syzkaller.appspotmail.com
First crash: 60d, last: 55d

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in btrfs_sb fs/btrfs/ctree.h:1091 [inline]
BUG: KASAN: use-after-free in btrfs_clear_delalloc_extent+0x5f/0x830 fs/btrfs/inode.c:2445
Read of size 8 at addr ffff888023496678 by task syz-executor.0/2636

CPU: 1 PID: 2636 Comm: syz-executor.0 Not tainted 6.1.0-rc8-syzkaller-00164-g4cee37b3a4e6 #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+0x1b1/0x28e lib/dump_stack.c:106
 print_address_description+0x74/0x340 mm/kasan/report.c:284
 print_report+0x107/0x1f0 mm/kasan/report.c:395
 kasan_report+0xcd/0x100 mm/kasan/report.c:495
 btrfs_sb fs/btrfs/ctree.h:1091 [inline]
 btrfs_clear_delalloc_extent+0x5f/0x830 fs/btrfs/inode.c:2445
 clear_state_bit+0x62/0x330 fs/btrfs/extent-io-tree.c:514
 __clear_extent_bit+0x669/0xc60 fs/btrfs/extent-io-tree.c:674
 try_release_extent_state fs/btrfs/extent_io.c:3391 [inline]
 try_release_extent_mapping+0x4e5/0x560 fs/btrfs/extent_io.c:3487
 __btrfs_release_folio fs/btrfs/inode.c:8175 [inline]
 btrfs_release_folio+0x126/0x340 fs/btrfs/inode.c:8188
 shrink_folio_list+0x20f7/0x6220 mm/vmscan.c:1982
 shrink_inactive_list+0x57d/0xc00 mm/vmscan.c:2489
 shrink_list mm/vmscan.c:2728 [inline]
 shrink_lruvec+0x429/0xc20 mm/vmscan.c:5923
 shrink_node_memcgs+0x360/0x770 mm/vmscan.c:6110
 shrink_node+0x299/0x1050 mm/vmscan.c:6141
 shrink_zones+0x4b8/0xbd0 mm/vmscan.c:6379
 do_try_to_free_pages+0x215/0xcd0 mm/vmscan.c:6441
 try_to_free_mem_cgroup_pages+0x3b7/0x6b0 mm/vmscan.c:6756
 reclaim_high+0x1c4/0x250 mm/memcontrol.c:2389
 mem_cgroup_handle_over_high+0x11f/0x280 mm/memcontrol.c:2574
 try_charge_memcg+0xf06/0x1100 mm/memcontrol.c:2812
 try_charge mm/memcontrol.c:2823 [inline]
 charge_memcg+0x132/0x5f0 mm/memcontrol.c:6890
 __mem_cgroup_charge+0x23/0x80 mm/memcontrol.c:6911
 mem_cgroup_charge include/linux/memcontrol.h:667 [inline]
 __filemap_add_folio+0x3cd/0x1a30 mm/filemap.c:852
 filemap_add_folio+0x12c/0x5c0 mm/filemap.c:934
 do_read_cache_folio+0x2a9/0x790 mm/filemap.c:3501
 do_read_cache_page mm/filemap.c:3576 [inline]
 read_cache_page+0x56/0x270 mm/filemap.c:3585
 read_mapping_page include/linux/pagemap.h:756 [inline]
 ntfs_attr_extend_initialized fs/ntfs/file.c:217 [inline]
 ntfs_prepare_file_for_write fs/ntfs/file.c:459 [inline]
 ntfs_file_write_iter+0xd7f/0x2d40 fs/ntfs/file.c:1915
 call_write_iter include/linux/fs.h:2199 [inline]
 new_sync_write fs/read_write.c:491 [inline]
 vfs_write+0x7dc/0xc50 fs/read_write.c:584
 ksys_write+0x177/0x2a0 fs/read_write.c:637
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f599608c0d9
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:00007f5996e86168 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007f59961ac120 RCX: 00007f599608c0d9
RDX: 0000000000000030 RSI: 00000000200023c0 RDI: 0000000000000004
RBP: 00007f59960e7ae9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffe134f539f R14: 00007f5996e86300 R15: 0000000000022000
 </TASK>

Allocated by task 2997:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x3d/0x60 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:955 [inline]
 __kmalloc+0xaf/0x1a0 mm/slab_common.c:968
 kmalloc include/linux/slab.h:558 [inline]
 tomoyo_realpath_from_path+0xcd/0x5f0 security/tomoyo/realpath.c:251
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_path_perm+0x227/0x670 security/tomoyo/file.c:822
 tomoyo_path_unlink+0xcc/0x100 security/tomoyo/tomoyo.c:149
 security_path_unlink+0xc3/0x140 security/security.c:1175
 do_unlinkat+0x3be/0x940 fs/namei.c:4316
 __do_sys_unlink fs/namei.c:4368 [inline]
 __se_sys_unlink fs/namei.c:4366 [inline]
 __x64_sys_unlink+0x45/0x50 fs/namei.c:4366
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 2997:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x3d/0x60 mm/kasan/common.c:52
 kasan_save_free_info+0x27/0x40 mm/kasan/generic.c:511
 ____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+0x12e/0x1a0 mm/slub.c:1750
 slab_free mm/slub.c:3661 [inline]
 __kmem_cache_free+0x71/0x110 mm/slub.c:3674
 tomoyo_realpath_from_path+0x5b9/0x5f0 security/tomoyo/realpath.c:286
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_path_perm+0x227/0x670 security/tomoyo/file.c:822
 tomoyo_path_unlink+0xcc/0x100 security/tomoyo/tomoyo.c:149
 security_path_unlink+0xc3/0x140 security/security.c:1175
 do_unlinkat+0x3be/0x940 fs/namei.c:4316
 __do_sys_unlink fs/namei.c:4368 [inline]
 __se_sys_unlink fs/namei.c:4366 [inline]
 __x64_sys_unlink+0x45/0x50 fs/namei.c:4366
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Last potentially related work creation:
 kasan_save_stack+0x2b/0x50 mm/kasan/common.c:45
 __kasan_record_aux_stack+0xb0/0xc0 mm/kasan/generic.c:481
 insert_work+0x54/0x3e0 kernel/workqueue.c:1358
 __queue_work+0xaaa/0xd60 kernel/workqueue.c:1517
 queue_work_on+0x11b/0x200 kernel/workqueue.c:1545
 rcu_do_batch kernel/rcu/tree.c:2250 [inline]
 rcu_core+0x9c1/0x1690 kernel/rcu/tree.c:2510
 __do_softirq+0x277/0x738 kernel/softirq.c:571

Second to last potentially related work creation:
 kasan_save_stack+0x2b/0x50 mm/kasan/common.c:45
 __kasan_record_aux_stack+0xb0/0xc0 mm/kasan/generic.c:481
 call_rcu+0x163/0x9c0 kernel/rcu/tree.c:2798
 put_super fs/super.c:311 [inline]
 deactivate_locked_super+0xdb/0xf0 fs/super.c:343
 cleanup_mnt+0x494/0x520 fs/namespace.c:1186
 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+0x124/0x150 kernel/entry/common.c:171
 exit_to_user_mode_prepare+0xb2/0x140 kernel/entry/common.c:203
 __syscall_exit_to_user_mode_work kernel/entry/common.c:285 [inline]
 syscall_exit_to_user_mode+0x26/0x60 kernel/entry/common.c:296
 do_syscall_64+0x49/0xb0 arch/x86/entry/common.c:86
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

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

The buggy address belongs to the physical page:
page:ffffea00008d2400 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x23490
head:ffffea00008d2400 order:3 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 dead000000000100 dead000000000122 ffff888012842140
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 0x1d2a20(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC|__GFP_HARDWALL), pid 3756, tgid 3756 (kworker/1:9), ts 186763738219, free_ts 177975109644
 prep_new_page mm/page_alloc.c:2539 [inline]
 get_page_from_freelist+0x742/0x7c0 mm/page_alloc.c:4291
 __alloc_pages+0x259/0x560 mm/page_alloc.c:5558
 alloc_slab_page+0xbd/0x190 mm/slub.c:1794
 allocate_slab+0x5e/0x4b0 mm/slub.c:1939
 new_slab mm/slub.c:1992 [inline]
 ___slab_alloc+0x782/0xe20 mm/slub.c:3180
 __slab_alloc mm/slub.c:3279 [inline]
 slab_alloc_node mm/slub.c:3364 [inline]
 __kmem_cache_alloc_node+0x252/0x310 mm/slub.c:3437
 __do_kmalloc_node mm/slab_common.c:954 [inline]
 __kmalloc_node_track_caller+0x9c/0x190 mm/slab_common.c:975
 kmalloc_reserve net/core/skbuff.c:437 [inline]
 __alloc_skb+0x112/0x2b0 net/core/skbuff.c:509
 alloc_skb include/linux/skbuff.h:1267 [inline]
 nsim_dev_trap_skb_build drivers/net/netdevsim/dev.c:751 [inline]
 nsim_dev_trap_report drivers/net/netdevsim/dev.c:808 [inline]
 nsim_dev_trap_report_work+0x268/0xaa0 drivers/net/netdevsim/dev.c:853
 process_one_work+0x877/0xdb0 kernel/workqueue.c:2289
 worker_thread+0xb14/0x1330 kernel/workqueue.c:2436
 kthread+0x266/0x300 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1459 [inline]
 free_pcp_prepare+0x80c/0x8f0 mm/page_alloc.c:1509
 free_unref_page_prepare mm/page_alloc.c:3387 [inline]
 free_unref_page+0x7d/0x5f0 mm/page_alloc.c:3483
 free_slab mm/slub.c:2031 [inline]
 discard_slab mm/slub.c:2037 [inline]
 __unfreeze_partials+0x1ab/0x200 mm/slub.c:2586
 put_cpu_partial+0x106/0x170 mm/slub.c:2662
 qlist_free_all+0x2b/0x70 mm/kasan/quarantine.c:187
 kasan_quarantine_reduce+0x169/0x180 mm/kasan/quarantine.c:294
 __kasan_slab_alloc+0x1f/0x70 mm/kasan/common.c:302
 kasan_slab_alloc include/linux/kasan.h:201 [inline]
 slab_post_alloc_hook mm/slab.h:737 [inline]
 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+0x1cc/0x300 mm/slub.c:3422
 vm_area_alloc+0x20/0xe0 kernel/fork.c:458
 mmap_region+0xd38/0x1e20 mm/mmap.c:2601
 do_mmap+0x8d9/0xf30 mm/mmap.c:1411
 vm_mmap_pgoff+0x19e/0x2b0 mm/util.c:520
 elf_map+0x1a7/0x300 fs/binfmt_elf.c:394
 load_elf_binary+0x100f/0x2850 fs/binfmt_elf.c:1166
 search_binary_handler fs/exec.c:1727 [inline]
 exec_binprm fs/exec.c:1768 [inline]
 bprm_execve+0x8dc/0x1590 fs/exec.c:1837
 kernel_execve+0x8eb/0xa00 fs/exec.c:2002

Memory state around the buggy address:
 ffff888023496500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888023496580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888023496600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                                ^
 ffff888023496680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888023496700: fb fb fb fb fb 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 Assets Title
ci2-upstream-fs 2022/12/12 00:43 upstream 4cee37b3a4e6 67be1ae7 .config console log report info [disk image] [vmlinux] [kernel image] KASAN: use-after-free Read in btrfs_clear_delalloc_extent
ci-qemu-upstream-386 2022/12/07 03:05 upstream 8ed710da2873 d88f3abb .config console log report info KASAN: use-after-free Read in btrfs_clear_delalloc_extent
* Struck through repros no longer work on HEAD.