======================================================
WARNING: possible circular locking dependency detected
6.13.0-rc5-syzkaller-00772-g3e5908172c05 #0 Not tainted
------------------------------------------------------
syz.1.1016/9713 is trying to acquire lock:
ffff888011af4078 (&hdev->lock){+.+.}-{4:4}, at: mgmt_remove_adv_monitor_complete+0xaf/0x550 net/bluetooth/mgmt.c:5524
but task is already holding lock:
ffff888011af4690 (&hdev->cmd_sync_work_lock){+.+.}-{4:4}, at: hci_cmd_sync_dequeue+0x44/0x3d0 net/bluetooth/hci_sync.c:887
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (&hdev->cmd_sync_work_lock){+.+.}-{4:4}:
lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
__mutex_lock_common kernel/locking/mutex.c:585 [inline]
__mutex_lock+0x1ac/0xee0 kernel/locking/mutex.c:735
hci_cmd_sync_lookup_entry net/bluetooth/hci_sync.c:838 [inline]
hci_cmd_sync_queue_once+0x43/0x240 net/bluetooth/hci_sync.c:782
le_conn_complete_evt+0xae1/0x12e0 net/bluetooth/hci_event.c:5778
hci_le_conn_complete_evt+0x18c/0x420 net/bluetooth/hci_event.c:5789
hci_event_func net/bluetooth/hci_event.c:7470 [inline]
hci_event_packet+0xa55/0x1540 net/bluetooth/hci_event.c:7525
hci_rx_work+0x3f3/0xdb0 net/bluetooth/hci_core.c:4035
process_one_work kernel/workqueue.c:3229 [inline]
process_scheduled_works+0xa66/0x1840 kernel/workqueue.c:3310
worker_thread+0x870/0xd30 kernel/workqueue.c:3391
kthread+0x2f0/0x390 kernel/kthread.c:389
ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
-> #0 (&hdev->lock){+.+.}-{4:4}:
check_prev_add kernel/locking/lockdep.c:3161 [inline]
check_prevs_add kernel/locking/lockdep.c:3280 [inline]
validate_chain+0x18ef/0x5920 kernel/locking/lockdep.c:3904
__lock_acquire+0x1397/0x2100 kernel/locking/lockdep.c:5226
lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
__mutex_lock_common kernel/locking/mutex.c:585 [inline]
__mutex_lock+0x1ac/0xee0 kernel/locking/mutex.c:735
mgmt_remove_adv_monitor_complete+0xaf/0x550 net/bluetooth/mgmt.c:5524
_hci_cmd_sync_cancel_entry net/bluetooth/hci_sync.c:645 [inline]
hci_cmd_sync_dequeue+0x22b/0x3d0 net/bluetooth/hci_sync.c:890
cmd_complete_rsp+0x4c/0x180 net/bluetooth/mgmt.c:1469
mgmt_pending_foreach+0xd1/0x130 net/bluetooth/mgmt_util.c:259
mgmt_index_removed+0x133/0x390 net/bluetooth/mgmt.c:9483
hci_sock_bind+0xcce/0x1150 net/bluetooth/hci_sock.c:1307
__sys_bind_socket net/socket.c:1838 [inline]
__sys_bind+0x1e4/0x290 net/socket.c:1869
__do_sys_bind net/socket.c:1874 [inline]
__se_sys_bind net/socket.c:1872 [inline]
__x64_sys_bind+0x7a/0x90 net/socket.c:1872
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&hdev->cmd_sync_work_lock);
lock(&hdev->lock);
lock(&hdev->cmd_sync_work_lock);
lock(&hdev->lock);
*** DEADLOCK ***
2 locks held by syz.1.1016/9713:
#0: ffff8880574e0258 (sk_lock-AF_BLUETOOTH-BTPROTO_HCI){+.+.}-{0:0}, at: lock_sock include/net/sock.h:1624 [inline]
#0: ffff8880574e0258 (sk_lock-AF_BLUETOOTH-BTPROTO_HCI){+.+.}-{0:0}, at: hci_sock_bind+0x149/0x1150 net/bluetooth/hci_sock.c:1202
#1: ffff888011af4690 (&hdev->cmd_sync_work_lock){+.+.}-{4:4}, at: hci_cmd_sync_dequeue+0x44/0x3d0 net/bluetooth/hci_sync.c:887
stack backtrace:
CPU: 0 UID: 0 PID: 9713 Comm: syz.1.1016 Not tainted 6.13.0-rc5-syzkaller-00772-g3e5908172c05 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
Call Trace:
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
print_circular_bug+0x13a/0x1b0 kernel/locking/lockdep.c:2074
check_noncircular+0x36a/0x4a0 kernel/locking/lockdep.c:2206
check_prev_add kernel/locking/lockdep.c:3161 [inline]
check_prevs_add kernel/locking/lockdep.c:3280 [inline]
validate_chain+0x18ef/0x5920 kernel/locking/lockdep.c:3904
__lock_acquire+0x1397/0x2100 kernel/locking/lockdep.c:5226
lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
__mutex_lock_common kernel/locking/mutex.c:585 [inline]
__mutex_lock+0x1ac/0xee0 kernel/locking/mutex.c:735
mgmt_remove_adv_monitor_complete+0xaf/0x550 net/bluetooth/mgmt.c:5524
_hci_cmd_sync_cancel_entry net/bluetooth/hci_sync.c:645 [inline]
hci_cmd_sync_dequeue+0x22b/0x3d0 net/bluetooth/hci_sync.c:890
cmd_complete_rsp+0x4c/0x180 net/bluetooth/mgmt.c:1469
mgmt_pending_foreach+0xd1/0x130 net/bluetooth/mgmt_util.c:259
mgmt_index_removed+0x133/0x390 net/bluetooth/mgmt.c:9483
hci_sock_bind+0xcce/0x1150 net/bluetooth/hci_sock.c:1307
__sys_bind_socket net/socket.c:1838 [inline]
__sys_bind+0x1e4/0x290 net/socket.c:1869
__do_sys_bind net/socket.c:1874 [inline]
__se_sys_bind net/socket.c:1872 [inline]
__x64_sys_bind+0x7a/0x90 net/socket.c:1872
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fa3d5785d29
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fa3d64e3038 EFLAGS: 00000246 ORIG_RAX: 0000000000000031
RAX: ffffffffffffffda RBX: 00007fa3d5975fa0 RCX: 00007fa3d5785d29
RDX: 0000000000000006 RSI: 0000000020000040 RDI: 0000000000000005
RBP: 00007fa3d5801b08 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 00007fa3d5975fa0 R15: 00007ffd6e47b428
==================================================================
BUG: KASAN: slab-use-after-free in cmd_complete_rsp+0x67/0x180 net/bluetooth/mgmt.c:1471
Read of size 8 at addr ffff888029f22ec0 by task syz.1.1016/9713
CPU: 1 UID: 0 PID: 9713 Comm: syz.1.1016 Not tainted 6.13.0-rc5-syzkaller-00772-g3e5908172c05 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
Call Trace:
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x169/0x550 mm/kasan/report.c:489
kasan_report+0x143/0x180 mm/kasan/report.c:602
cmd_complete_rsp+0x67/0x180 net/bluetooth/mgmt.c:1471
mgmt_pending_foreach+0xd1/0x130 net/bluetooth/mgmt_util.c:259
mgmt_index_removed+0x133/0x390 net/bluetooth/mgmt.c:9483
hci_sock_bind+0xcce/0x1150 net/bluetooth/hci_sock.c:1307
__sys_bind_socket net/socket.c:1838 [inline]
__sys_bind+0x1e4/0x290 net/socket.c:1869
__do_sys_bind net/socket.c:1874 [inline]
__se_sys_bind net/socket.c:1872 [inline]
__x64_sys_bind+0x7a/0x90 net/socket.c:1872
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fa3d5785d29
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fa3d64e3038 EFLAGS: 00000246 ORIG_RAX: 0000000000000031
RAX: ffffffffffffffda RBX: 00007fa3d5975fa0 RCX: 00007fa3d5785d29
RDX: 0000000000000006 RSI: 0000000020000040 RDI: 0000000000000005
RBP: 00007fa3d5801b08 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 00007fa3d5975fa0 R15: 00007ffd6e47b428
Allocated by task 9714:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
poison_kmalloc_redzone mm/kasan/common.c:377 [inline]
__kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:394
kasan_kmalloc include/linux/kasan.h:260 [inline]
__kmalloc_cache_noprof+0x243/0x390 mm/slub.c:4329
kmalloc_noprof include/linux/slab.h:901 [inline]
kzalloc_noprof include/linux/slab.h:1037 [inline]
mgmt_pending_new+0x65/0x250 net/bluetooth/mgmt_util.c:269
mgmt_pending_add+0x36/0x120 net/bluetooth/mgmt_util.c:296
remove_adv_monitor+0x102/0x1b0 net/bluetooth/mgmt.c:5568
hci_mgmt_cmd+0xc47/0x11d0 net/bluetooth/hci_sock.c:1712
hci_sock_sendmsg+0x7b8/0x11c0 net/bluetooth/hci_sock.c:1832
sock_sendmsg_nosec net/socket.c:711 [inline]
__sock_sendmsg+0x221/0x270 net/socket.c:726
sock_write_iter+0x2d7/0x3f0 net/socket.c:1158
new_sync_write fs/read_write.c:586 [inline]
vfs_write+0xaeb/0xd30 fs/read_write.c:679
ksys_write+0x18f/0x2b0 fs/read_write.c:731
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 9713:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:582
poison_slab_object mm/kasan/common.c:247 [inline]
__kasan_slab_free+0x59/0x70 mm/kasan/common.c:264
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2353 [inline]
slab_free mm/slub.c:4613 [inline]
kfree+0x196/0x430 mm/slub.c:4761
mgmt_remove_adv_monitor_complete+0x2bf/0x550 net/bluetooth/mgmt.c:5533
_hci_cmd_sync_cancel_entry net/bluetooth/hci_sync.c:645 [inline]
hci_cmd_sync_dequeue+0x22b/0x3d0 net/bluetooth/hci_sync.c:890
cmd_complete_rsp+0x4c/0x180 net/bluetooth/mgmt.c:1469
mgmt_pending_foreach+0xd1/0x130 net/bluetooth/mgmt_util.c:259
mgmt_index_removed+0x133/0x390 net/bluetooth/mgmt.c:9483
hci_sock_bind+0xcce/0x1150 net/bluetooth/hci_sock.c:1307
__sys_bind_socket net/socket.c:1838 [inline]
__sys_bind+0x1e4/0x290 net/socket.c:1869
__do_sys_bind net/socket.c:1874 [inline]
__se_sys_bind net/socket.c:1872 [inline]
__x64_sys_bind+0x7a/0x90 net/socket.c:1872
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff888029f22e80
which belongs to the cache kmalloc-96 of size 96
The buggy address is located 64 bytes inside of
freed 96-byte region [ffff888029f22e80, ffff888029f22ee0)
The buggy address belongs to the physical page:
page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x29f22
ksm flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000000 ffff88801ac41280 ffffea0001fda840 dead000000000003
raw: 0000000000000000 0000000000200020 00000001f5000000 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 0x52820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 5937, tgid 5936 (syz.3.9), ts 67730204636, free_ts 67655301509
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x1f3/0x230 mm/page_alloc.c:1558
prep_new_page mm/page_alloc.c:1566 [inline]
get_page_from_freelist+0x365c/0x37a0 mm/page_alloc.c:3476
__alloc_pages_noprof+0x292/0x710 mm/page_alloc.c:4753
alloc_pages_mpol_noprof+0x3e8/0x680 mm/mempolicy.c:2269
alloc_slab_page+0x6a/0x110 mm/slub.c:2423
allocate_slab+0x5a/0x2b0 mm/slub.c:2589
new_slab mm/slub.c:2642 [inline]
___slab_alloc+0xc27/0x14a0 mm/slub.c:3830
__slab_alloc+0x58/0xa0 mm/slub.c:3920
__slab_alloc_node mm/slub.c:3995 [inline]
slab_alloc_node mm/slub.c:4156 [inline]
__do_kmalloc_node mm/slub.c:4297 [inline]
__kmalloc_noprof+0x2e6/0x4c0 mm/slub.c:4310
kmalloc_noprof include/linux/slab.h:905 [inline]
kzalloc_noprof include/linux/slab.h:1037 [inline]
hash_ipmark4_add+0x1137/0x2320 net/netfilter/ipset/ip_set_hash_gen.h:950
hash_ipmark4_uadt+0x7b5/0xb50 net/netfilter/ipset/ip_set_hash_ipmark.c:159
call_ad+0x279/0xa70 net/netfilter/ipset/ip_set_core.c:1751
ip_set_ad+0x7e0/0x990 net/netfilter/ipset/ip_set_core.c:1841
nfnetlink_rcv_msg+0xbec/0x1180 net/netfilter/nfnetlink.c:302
netlink_rcv_skb+0x1e3/0x430 net/netlink/af_netlink.c:2543
nfnetlink_rcv+0x297/0x2ab0 net/netfilter/nfnetlink.c:667
page last free pid 5986 tgid 5983 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1127 [inline]
free_unref_folios+0xe39/0x18b0 mm/page_alloc.c:2706
folios_put_refs+0x76c/0x860 mm/swap.c:962
free_pages_and_swap_cache+0x5c8/0x690 mm/swap_state.c:335
__tlb_batch_free_encoded_pages mm/mmu_gather.c:136 [inline]
tlb_batch_pages_flush mm/mmu_gather.c:149 [inline]
tlb_flush_mmu_free mm/mmu_gather.c:366 [inline]
tlb_flush_mmu+0x3a3/0x680 mm/mmu_gather.c:373
tlb_finish_mmu+0xd4/0x200 mm/mmu_gather.c:465
exit_mmap+0x496/0xc20 mm/mmap.c:1681
__mmput+0x115/0x3c0 kernel/fork.c:1348
exit_mm+0x220/0x310 kernel/exit.c:570
do_exit+0x9ad/0x28e0 kernel/exit.c:925
do_group_exit+0x207/0x2c0 kernel/exit.c:1087
get_signal+0x16b2/0x1750 kernel/signal.c:3017
arch_do_signal_or_restart+0x96/0x860 arch/x86/kernel/signal.c:337
exit_to_user_mode_loop kernel/entry/common.c:111 [inline]
exit_to_user_mode_prepare include/linux/entry-common.h:329 [inline]
__syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
syscall_exit_to_user_mode+0xce/0x340 kernel/entry/common.c:218
do_syscall_64+0x100/0x230 arch/x86/entry/common.c:89
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff888029f22d80: 00 00 00 00 00 00 00 00 00 00 fc fc fc fc fc fc
ffff888029f22e00: 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc
>ffff888029f22e80: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
^
ffff888029f22f00: 00 00 00 00 00 00 00 00 00 00 fc fc fc fc fc fc
ffff888029f22f80: 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc
==================================================================