BTRFS error (device loop4): re-allocated a block that still has references to it!
BTRFS error (device loop4): dumping block entry [5251072 4096], num_refs 3, metadata 1, from disk 0
==================================================================
BUG: KASAN: use-after-free in rb_first+0x61/0x70 lib/rbtree.c:473
Read of size 8 at addr ffff88801acafd38 by task kworker/u4:10/4477
CPU: 1 PID: 4477 Comm: kworker/u4:10 Not tainted 5.15.135-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/06/2023
Workqueue: btrfs-endio-write btrfs_work_helper
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1e3/0x2cb lib/dump_stack.c:106
print_address_description+0x63/0x3b0 mm/kasan/report.c:248
__kasan_report mm/kasan/report.c:434 [inline]
kasan_report+0x16b/0x1c0 mm/kasan/report.c:451
rb_first+0x61/0x70 lib/rbtree.c:473
dump_block_entry+0xd5/0x480 fs/btrfs/ref-verify.c:633
btrfs_ref_tree_mod+0x1179/0x1500 fs/btrfs/ref-verify.c:746
btrfs_alloc_tree_block+0xebe/0x1780 fs/btrfs/extent-tree.c:4940
__btrfs_cow_block+0x464/0x18f0 fs/btrfs/ctree.c:415
btrfs_cow_block+0x3ff/0x770 fs/btrfs/ctree.c:575
btrfs_search_slot+0xb98/0x28b0 fs/btrfs/ctree.c:1819
btrfs_lookup_file_extent+0x148/0x200 fs/btrfs/file-item.c:245
btrfs_drop_extents+0x4bc/0x3520 fs/btrfs/file.c:740
insert_reserved_file_extent+0x32d/0xce0 fs/btrfs/inode.c:2929
insert_ordered_extent_file_extent fs/btrfs/inode.c:3032 [inline]
btrfs_finish_ordered_io+0xd28/0x1db0 fs/btrfs/inode.c:3134
btrfs_work_helper+0x368/0xba0 fs/btrfs/async-thread.c:325
process_one_work+0x8a1/0x10c0 kernel/workqueue.c:2310
worker_thread+0xaca/0x1280 kernel/workqueue.c:2457
kthread+0x3f6/0x4f0 kernel/kthread.c:319
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298
</TASK>
Allocated by task 3943:
kasan_save_stack mm/kasan/common.c:38 [inline]
kasan_set_track mm/kasan/common.c:46 [inline]
set_alloc_info mm/kasan/common.c:434 [inline]
____kasan_kmalloc+0xba/0xf0 mm/kasan/common.c:513
kasan_kmalloc include/linux/kasan.h:264 [inline]
kmem_cache_alloc_trace+0x143/0x290 mm/slub.c:3247
kmalloc include/linux/slab.h:591 [inline]
kzalloc include/linux/slab.h:721 [inline]
btrfs_ref_tree_mod+0x23c/0x1500 fs/btrfs/ref-verify.c:690
btrfs_free_tree_block+0x2ba/0xbf0 fs/btrfs/extent-tree.c:3292
__btrfs_cow_block+0xe78/0x18f0 fs/btrfs/ctree.c:470
btrfs_cow_block+0x3ff/0x770 fs/btrfs/ctree.c:575
btrfs_search_slot+0xb98/0x28b0 fs/btrfs/ctree.c:1819
btrfs_lookup_file_extent+0x148/0x200 fs/btrfs/file-item.c:245
btrfs_drop_extents+0x4bc/0x3520 fs/btrfs/file.c:740
insert_reserved_file_extent+0x32d/0xce0 fs/btrfs/inode.c:2929
insert_ordered_extent_file_extent fs/btrfs/inode.c:3032 [inline]
btrfs_finish_ordered_io+0xd28/0x1db0 fs/btrfs/inode.c:3134
btrfs_work_helper+0x368/0xba0 fs/btrfs/async-thread.c:325
process_one_work+0x8a1/0x10c0 kernel/workqueue.c:2310
worker_thread+0xaca/0x1280 kernel/workqueue.c:2457
kthread+0x3f6/0x4f0 kernel/kthread.c:319
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298
Freed by task 3943:
kasan_save_stack mm/kasan/common.c:38 [inline]
kasan_set_track+0x4b/0x80 mm/kasan/common.c:46
kasan_set_free_info+0x1f/0x40 mm/kasan/generic.c:360
____kasan_slab_free+0xd8/0x120 mm/kasan/common.c:366
kasan_slab_free include/linux/kasan.h:230 [inline]
slab_free_hook mm/slub.c:1705 [inline]
slab_free_freelist_hook+0xdd/0x160 mm/slub.c:1731
slab_free mm/slub.c:3499 [inline]
kfree+0xf1/0x270 mm/slub.c:4559
btrfs_ref_tree_mod+0x113c/0x1500
btrfs_free_tree_block+0x2ba/0xbf0 fs/btrfs/extent-tree.c:3292
__btrfs_cow_block+0xe78/0x18f0 fs/btrfs/ctree.c:470
btrfs_cow_block+0x3ff/0x770 fs/btrfs/ctree.c:575
btrfs_search_slot+0xb98/0x28b0 fs/btrfs/ctree.c:1819
btrfs_lookup_file_extent+0x148/0x200 fs/btrfs/file-item.c:245
btrfs_drop_extents+0x4bc/0x3520 fs/btrfs/file.c:740
insert_reserved_file_extent+0x32d/0xce0 fs/btrfs/inode.c:2929
insert_ordered_extent_file_extent fs/btrfs/inode.c:3032 [inline]
btrfs_finish_ordered_io+0xd28/0x1db0 fs/btrfs/inode.c:3134
btrfs_work_helper+0x368/0xba0 fs/btrfs/async-thread.c:325
process_one_work+0x8a1/0x10c0 kernel/workqueue.c:2310
worker_thread+0xaca/0x1280 kernel/workqueue.c:2457
kthread+0x3f6/0x4f0 kernel/kthread.c:319
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298
Last potentially related work creation:
kasan_save_stack+0x36/0x60 mm/kasan/common.c:38
kasan_record_aux_stack+0xba/0x100 mm/kasan/generic.c:348
__call_rcu kernel/rcu/tree.c:2994 [inline]
call_rcu+0x1c4/0xa70 kernel/rcu/tree.c:3074
nf_hook_entries_free net/netfilter/core.c:88 [inline]
__nf_register_net_hook+0x743/0x8e0 net/netfilter/core.c:419
nf_register_net_hook+0xac/0x180 net/netfilter/core.c:536
nf_register_net_hooks+0x3d/0x1a0 net/netfilter/core.c:552
nf_ct_netns_do_get+0x344/0x470 net/netfilter/nf_conntrack_proto.c:466
nf_ct_netns_inet_get+0x1f/0x150 net/netfilter/nf_conntrack_proto.c:571
nf_conncount_init+0x12a/0x390 net/netfilter/nf_conncount.c:533
ovs_ct_limit_init net/openvswitch/conntrack.c:1894 [inline]
ovs_ct_init+0x346/0x4c0 net/openvswitch/conntrack.c:2299
ovs_init_net+0x1e2/0x240 net/openvswitch/datapath.c:2584
ops_init+0x356/0x600 net/core/net_namespace.c:135
setup_net+0x358/0x9e0 net/core/net_namespace.c:329
copy_net_ns+0x395/0x5d0 net/core/net_namespace.c:473
create_new_namespaces+0x425/0x7a0 kernel/nsproxy.c:110
unshare_nsproxy_namespaces+0x11e/0x170 kernel/nsproxy.c:226
ksys_unshare+0x580/0xb20 kernel/fork.c:3101
__do_sys_unshare kernel/fork.c:3175 [inline]
__se_sys_unshare kernel/fork.c:3173 [inline]
__x64_sys_unshare+0x34/0x40 kernel/fork.c:3173
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+0x61/0xcb
The buggy address belongs to the object at ffff88801acafd00
which belongs to the cache kmalloc-64 of size 64
The buggy address is located 56 bytes inside of
64-byte region [ffff88801acafd00, ffff88801acafd40)
The buggy address belongs to the page:
page:ffffea00006b2bc0 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1acaf
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 0000000000000000 0000000600000001 ffff888011c41640
raw: 0000000000000000 0000000000200020 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 3549, ts 205504309485, free_ts 205504230604
prep_new_page mm/page_alloc.c:2426 [inline]
get_page_from_freelist+0x322a/0x33c0 mm/page_alloc.c:4159
__alloc_pages+0x272/0x700 mm/page_alloc.c:5421
alloc_slab_page mm/slub.c:1775 [inline]
allocate_slab mm/slub.c:1912 [inline]
new_slab+0xbb/0x4b0 mm/slub.c:1975
___slab_alloc+0x6f6/0xe10 mm/slub.c:3008
__slab_alloc mm/slub.c:3095 [inline]
slab_alloc_node mm/slub.c:3186 [inline]
kmem_cache_alloc_node_trace+0x1ce/0x2e0 mm/slub.c:3270
kmalloc_node include/linux/slab.h:609 [inline]
kzalloc_node include/linux/slab.h:732 [inline]
__get_vm_area_node+0x11f/0x2f0 mm/vmalloc.c:2416
__vmalloc_node_range+0xe3/0x8c0 mm/vmalloc.c:3019
__vmalloc_node mm/vmalloc.c:3079 [inline]
vzalloc+0x75/0x80 mm/vmalloc.c:3149
alloc_counters+0xcf/0x7c0 net/ipv4/netfilter/ip_tables.c:800
copy_entries_to_user net/ipv4/netfilter/ip_tables.c:822 [inline]
get_entries net/ipv4/netfilter/ip_tables.c:1023 [inline]
do_ipt_get_ctl+0xead/0x1880 net/ipv4/netfilter/ip_tables.c:1661
nf_getsockopt+0x28e/0x2b0 net/netfilter/nf_sockopt.c:116
ip_getsockopt+0x136c/0x1ec0 net/ipv4/ip_sockglue.c:1787
tcp_getsockopt+0x26d/0x6c20 net/ipv4/tcp.c:4300
__sys_getsockopt+0x2a6/0x550 net/socket.c:2240
__do_sys_getsockopt net/socket.c:2255 [inline]
__se_sys_getsockopt net/socket.c:2252 [inline]
__x64_sys_getsockopt+0xb1/0xc0 net/socket.c:2252
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1340 [inline]
free_pcp_prepare mm/page_alloc.c:1391 [inline]
free_unref_page_prepare+0xc34/0xcf0 mm/page_alloc.c:3317
free_unref_page+0x95/0x2d0 mm/page_alloc.c:3396
__vunmap+0x8d4/0xa20 mm/vmalloc.c:2621
copy_entries_to_user net/ipv4/netfilter/ip_tables.c:867 [inline]
get_entries net/ipv4/netfilter/ip_tables.c:1023 [inline]
do_ipt_get_ctl+0x11d4/0x1880 net/ipv4/netfilter/ip_tables.c:1661
nf_getsockopt+0x28e/0x2b0 net/netfilter/nf_sockopt.c:116
ip_getsockopt+0x136c/0x1ec0 net/ipv4/ip_sockglue.c:1787
tcp_getsockopt+0x26d/0x6c20 net/ipv4/tcp.c:4300
__sys_getsockopt+0x2a6/0x550 net/socket.c:2240
__do_sys_getsockopt net/socket.c:2255 [inline]
__se_sys_getsockopt net/socket.c:2252 [inline]
__x64_sys_getsockopt+0xb1/0xc0 net/socket.c:2252
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+0x61/0xcb
Memory state around the buggy address:
ffff88801acafc00: 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc
ffff88801acafc80: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
>ffff88801acafd00: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
^
ffff88801acafd80: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
ffff88801acafe00: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
==================================================================