* [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2)
@ 2024-06-24 20:23 syzbot
2024-09-07 14:42 ` syzbot
2024-09-10 18:43 ` syzbot
0 siblings, 2 replies; 15+ messages in thread
From: syzbot @ 2024-06-24 20:23 UTC (permalink / raw)
To: johan.hedberg, linux-bluetooth, linux-kernel, luiz.dentz, marcel,
syzkaller-bugs
Hello,
syzbot found the following issue on:
HEAD commit: 5f583a3162ff Merge tag 'rust-fixes-6.10' of https://github..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=11170741980000
kernel config: https://syzkaller.appspot.com/x/.config?x=f413acf5b1eb4093
dashboard link: https://syzkaller.appspot.com/bug?extid=c12e2f941af1feb5632c
compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
Unfortunately, I don't have any reproducer for this issue yet.
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/f530c7950839/disk-5f583a31.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/b4f810bbc13e/vmlinux-5f583a31.xz
kernel image: https://storage.googleapis.com/syzbot-assets/a49ec6dadbad/bzImage-5f583a31.xz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+c12e2f941af1feb5632c@syzkaller.appspotmail.com
==================================================================
BUG: KASAN: slab-use-after-free in l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949
Read of size 8 at addr ffff88802af53000 by task kworker/u9:4/5114
CPU: 1 PID: 5114 Comm: kworker/u9:4 Not tainted 6.10.0-rc4-syzkaller-00301-g5f583a3162ff #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 06/07/2024
Workqueue: hci1 hci_rx_work
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:114
print_address_description mm/kasan/report.c:377 [inline]
print_report+0xc3/0x620 mm/kasan/report.c:488
kasan_report+0xd9/0x110 mm/kasan/report.c:601
l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949
l2cap_connect_req net/bluetooth/l2cap_core.c:4080 [inline]
l2cap_bredr_sig_cmd net/bluetooth/l2cap_core.c:4772 [inline]
l2cap_sig_channel net/bluetooth/l2cap_core.c:5543 [inline]
l2cap_recv_frame+0xf07/0x8e50 net/bluetooth/l2cap_core.c:6821
l2cap_recv_acldata+0x9ac/0xb60 net/bluetooth/l2cap_core.c:7510
hci_acldata_packet net/bluetooth/hci_core.c:3842 [inline]
hci_rx_work+0xaa7/0x1610 net/bluetooth/hci_core.c:4079
process_one_work+0x9fb/0x1b60 kernel/workqueue.c:3231
process_scheduled_works kernel/workqueue.c:3312 [inline]
worker_thread+0x6c8/0xf70 kernel/workqueue.c:3393
kthread+0x2c1/0x3a0 kernel/kthread.c:389
ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
</TASK>
Allocated by task 4480:
kasan_save_stack+0x33/0x60 mm/kasan/common.c:47
kasan_save_track+0x14/0x30 mm/kasan/common.c:68
poison_kmalloc_redzone mm/kasan/common.c:370 [inline]
__kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:387
kmalloc_noprof include/linux/slab.h:660 [inline]
kzalloc_noprof include/linux/slab.h:778 [inline]
l2cap_conn_add.part.0+0x60/0xa60 net/bluetooth/l2cap_core.c:6864
l2cap_conn_add net/bluetooth/l2cap_core.c:69 [inline]
l2cap_connect_cfm+0x428/0xf80 net/bluetooth/l2cap_core.c:7241
hci_connect_cfm include/net/bluetooth/hci_core.h:1970 [inline]
hci_remote_features_evt+0x548/0x9e0 net/bluetooth/hci_event.c:3721
hci_event_func net/bluetooth/hci_event.c:7417 [inline]
hci_event_packet+0x9e3/0x1170 net/bluetooth/hci_event.c:7469
hci_rx_work+0x2c4/0x1610 net/bluetooth/hci_core.c:4074
process_one_work+0x9fb/0x1b60 kernel/workqueue.c:3231
process_scheduled_works kernel/workqueue.c:3312 [inline]
worker_thread+0x6c8/0xf70 kernel/workqueue.c:3393
kthread+0x2c1/0x3a0 kernel/kthread.c:389
ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
Freed by task 5112:
kasan_save_stack+0x33/0x60 mm/kasan/common.c:47
kasan_save_track+0x14/0x30 mm/kasan/common.c:68
kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:579
poison_slab_object+0xf7/0x160 mm/kasan/common.c:240
__kasan_slab_free+0x32/0x50 mm/kasan/common.c:256
kasan_slab_free include/linux/kasan.h:184 [inline]
slab_free_hook mm/slub.c:2196 [inline]
slab_free mm/slub.c:4437 [inline]
kfree+0x12a/0x3b0 mm/slub.c:4558
l2cap_conn_free net/bluetooth/l2cap_core.c:1810 [inline]
kref_put include/linux/kref.h:65 [inline]
l2cap_conn_put net/bluetooth/l2cap_core.c:1822 [inline]
l2cap_conn_del+0x59d/0x740 net/bluetooth/l2cap_core.c:1802
l2cap_connect_cfm+0x9e6/0xf80 net/bluetooth/l2cap_core.c:7237
hci_connect_cfm include/net/bluetooth/hci_core.h:1970 [inline]
hci_conn_failed+0x1c3/0x370 net/bluetooth/hci_conn.c:1257
hci_abort_conn_sync+0x75a/0xb50 net/bluetooth/hci_sync.c:5450
abort_conn_sync+0x197/0x360 net/bluetooth/hci_conn.c:2909
hci_cmd_sync_work+0x1a4/0x410 net/bluetooth/hci_sync.c:310
process_one_work+0x9fb/0x1b60 kernel/workqueue.c:3231
process_scheduled_works kernel/workqueue.c:3312 [inline]
worker_thread+0x6c8/0xf70 kernel/workqueue.c:3393
kthread+0x2c1/0x3a0 kernel/kthread.c:389
ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
Last potentially related work creation:
kasan_save_stack+0x33/0x60 mm/kasan/common.c:47
__kasan_record_aux_stack+0xba/0xd0 mm/kasan/generic.c:541
insert_work+0x36/0x230 kernel/workqueue.c:2207
__queue_work+0x944/0x1020 kernel/workqueue.c:2359
call_timer_fn+0x1a0/0x610 kernel/time/timer.c:1792
expire_timers kernel/time/timer.c:1838 [inline]
__run_timers+0x567/0xaf0 kernel/time/timer.c:2417
__run_timer_base kernel/time/timer.c:2428 [inline]
__run_timer_base kernel/time/timer.c:2421 [inline]
run_timer_base+0x111/0x190 kernel/time/timer.c:2437
run_timer_softirq+0x1a/0x40 kernel/time/timer.c:2447
handle_softirqs+0x216/0x8f0 kernel/softirq.c:554
__do_softirq kernel/softirq.c:588 [inline]
invoke_softirq kernel/softirq.c:428 [inline]
__irq_exit_rcu kernel/softirq.c:637 [inline]
irq_exit_rcu+0xbb/0x120 kernel/softirq.c:649
instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1043 [inline]
sysvec_apic_timer_interrupt+0x95/0xb0 arch/x86/kernel/apic/apic.c:1043
asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:702
Second to last potentially related work creation:
kasan_save_stack+0x33/0x60 mm/kasan/common.c:47
__kasan_record_aux_stack+0xba/0xd0 mm/kasan/generic.c:541
insert_work+0x36/0x230 kernel/workqueue.c:2207
__queue_work+0x525/0x1020 kernel/workqueue.c:2363
queue_work_on+0x11a/0x140 kernel/workqueue.c:2410
queue_work include/linux/workqueue.h:621 [inline]
l2cap_conn_ready net/bluetooth/l2cap_core.c:1640 [inline]
l2cap_connect_cfm+0x9c9/0xf80 net/bluetooth/l2cap_core.c:7282
hci_connect_cfm include/net/bluetooth/hci_core.h:1970 [inline]
hci_remote_features_evt+0x548/0x9e0 net/bluetooth/hci_event.c:3721
hci_event_func net/bluetooth/hci_event.c:7417 [inline]
hci_event_packet+0x9e3/0x1170 net/bluetooth/hci_event.c:7469
hci_rx_work+0x2c4/0x1610 net/bluetooth/hci_core.c:4074
process_one_work+0x9fb/0x1b60 kernel/workqueue.c:3231
process_scheduled_works kernel/workqueue.c:3312 [inline]
worker_thread+0x6c8/0xf70 kernel/workqueue.c:3393
kthread+0x2c1/0x3a0 kernel/kthread.c:389
ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
The buggy address belongs to the object at ffff88802af53000
which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 0 bytes inside of
freed 1024-byte region [ffff88802af53000, ffff88802af53400)
The buggy address belongs to the physical page:
page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x2af50
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
anon flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffefff(slab)
raw: 00fff00000000040 ffff888015441dc0 0000000000000000 dead000000000001
raw: 0000000000000000 0000000000100010 00000001ffffefff 0000000000000000
head: 00fff00000000040 ffff888015441dc0 0000000000000000 dead000000000001
head: 0000000000000000 0000000000100010 00000001ffffefff 0000000000000000
head: 00fff00000000003 ffffea0000abd401 ffffffffffffffff 0000000000000000
head: 0000000000000008 0000000000000000 00000000ffffffff 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 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 4752, tgid 4752 (dhcpcd), ts 66098690934, free_ts 66038999175
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x2d1/0x350 mm/page_alloc.c:1468
prep_new_page mm/page_alloc.c:1476 [inline]
get_page_from_freelist+0x136a/0x2e50 mm/page_alloc.c:3420
__alloc_pages_noprof+0x22b/0x2460 mm/page_alloc.c:4678
__alloc_pages_node_noprof include/linux/gfp.h:269 [inline]
alloc_pages_node_noprof include/linux/gfp.h:296 [inline]
alloc_slab_page+0x56/0x110 mm/slub.c:2265
allocate_slab mm/slub.c:2428 [inline]
new_slab+0x84/0x260 mm/slub.c:2481
___slab_alloc+0xdac/0x1870 mm/slub.c:3667
__slab_alloc.constprop.0+0x56/0xb0 mm/slub.c:3757
__slab_alloc_node mm/slub.c:3810 [inline]
slab_alloc_node mm/slub.c:3989 [inline]
__do_kmalloc_node mm/slub.c:4121 [inline]
kmalloc_node_track_caller_noprof+0x355/0x430 mm/slub.c:4142
kmemdup_noprof+0x29/0x60 mm/util.c:131
kmemdup_noprof include/linux/fortify-string.h:757 [inline]
bpf_migrate_filter+0xc6/0x390 net/core/filter.c:1268
bpf_prepare_filter+0x183/0x380 net/core/filter.c:1354
bpf_prog_create_from_user+0x1e4/0x2d0 net/core/filter.c:1448
seccomp_prepare_filter kernel/seccomp.c:680 [inline]
seccomp_prepare_user_filter kernel/seccomp.c:717 [inline]
seccomp_set_mode_filter kernel/seccomp.c:1935 [inline]
do_seccomp+0x7b6/0x2580 kernel/seccomp.c:2055
prctl_set_seccomp+0x4b/0x70 kernel/seccomp.c:2108
__do_sys_prctl+0xc83/0x1e40 kernel/sys.c:2539
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
page last free pid 4747 tgid 4747 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1088 [inline]
free_unref_page+0x64a/0xe40 mm/page_alloc.c:2583
__put_partials+0x14c/0x170 mm/slub.c:2995
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x4e/0x140 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x192/0x1e0 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x69/0x90 mm/kasan/common.c:322
kasan_slab_alloc include/linux/kasan.h:201 [inline]
slab_post_alloc_hook mm/slub.c:3941 [inline]
slab_alloc_node mm/slub.c:4001 [inline]
kmem_cache_alloc_lru_noprof+0x121/0x2f0 mm/slub.c:4020
shmem_alloc_inode+0x25/0x50 mm/shmem.c:4468
alloc_inode+0x5d/0x230 fs/inode.c:261
new_inode_pseudo fs/inode.c:1007 [inline]
new_inode+0x22/0x270 fs/inode.c:1033
__shmem_get_inode mm/shmem.c:2503 [inline]
shmem_get_inode+0x194/0xe80 mm/shmem.c:2574
shmem_mknod+0x66/0x240 mm/shmem.c:3268
shmem_mkdir+0x31/0x60 mm/shmem.c:3329
vfs_mkdir+0x57d/0x860 fs/namei.c:4131
do_mkdirat+0x301/0x3a0 fs/namei.c:4154
__do_sys_mkdir fs/namei.c:4174 [inline]
__se_sys_mkdir fs/namei.c:4172 [inline]
__x64_sys_mkdir+0xf1/0x140 fs/namei.c:4172
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
Memory state around the buggy address:
ffff88802af52f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88802af52f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88802af53000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88802af53080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88802af53100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2) 2024-06-24 20:23 [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2) syzbot @ 2024-09-07 14:42 ` syzbot 2024-09-08 7:22 ` [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect Edward Adam Davis 2024-09-10 18:43 ` syzbot 1 sibling, 1 reply; 15+ messages in thread From: syzbot @ 2024-09-07 14:42 UTC (permalink / raw) To: johan.hedberg, linux-bluetooth, linux-kernel, luiz.dentz, marcel, syzkaller-bugs syzbot has found a reproducer for the following issue on: HEAD commit: 788220eee30d Merge tag 'pm-6.11-rc7' of git://git.kernel.o.. git tree: upstream console+strace: https://syzkaller.appspot.com/x/log.txt?x=10502bc7980000 kernel config: https://syzkaller.appspot.com/x/.config?x=57042fe37c7ee7c2 dashboard link: https://syzkaller.appspot.com/bug?extid=c12e2f941af1feb5632c compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=11da6f29980000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1304189f980000 Downloadable assets: disk image: https://storage.googleapis.com/syzbot-assets/e618b7c8e5a2/disk-788220ee.raw.xz vmlinux: https://storage.googleapis.com/syzbot-assets/333bb524a2ba/vmlinux-788220ee.xz kernel image: https://storage.googleapis.com/syzbot-assets/ad1779f24bb2/bzImage-788220ee.xz IMPORTANT: if you fix the issue, please add the following tag to the commit: Reported-by: syzbot+c12e2f941af1feb5632c@syzkaller.appspotmail.com ================================================================== BUG: KASAN: slab-use-after-free in l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949 Read of size 8 at addr ffff8880241e9800 by task kworker/u9:0/54 CPU: 0 UID: 0 PID: 54 Comm: kworker/u9:0 Not tainted 6.11.0-rc6-syzkaller-00268-g788220eee30d #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024 Workqueue: hci2 hci_rx_work Call Trace: <TASK> __dump_stack lib/dump_stack.c:93 [inline] dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:119 print_address_description mm/kasan/report.c:377 [inline] print_report+0xc3/0x620 mm/kasan/report.c:488 kasan_report+0xd9/0x110 mm/kasan/report.c:601 l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949 l2cap_connect_req net/bluetooth/l2cap_core.c:4080 [inline] l2cap_bredr_sig_cmd net/bluetooth/l2cap_core.c:4772 [inline] l2cap_sig_channel net/bluetooth/l2cap_core.c:5543 [inline] l2cap_recv_frame+0xf0b/0x8eb0 net/bluetooth/l2cap_core.c:6825 l2cap_recv_acldata+0x9b4/0xb70 net/bluetooth/l2cap_core.c:7514 hci_acldata_packet net/bluetooth/hci_core.c:3791 [inline] hci_rx_work+0xaab/0x1610 net/bluetooth/hci_core.c:4028 process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231 process_scheduled_works kernel/workqueue.c:3312 [inline] worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389 kthread+0x2c1/0x3a0 kernel/kthread.c:389 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 </TASK> Allocated by task 5253: kasan_save_stack+0x33/0x60 mm/kasan/common.c:47 kasan_save_track+0x14/0x30 mm/kasan/common.c:68 poison_kmalloc_redzone mm/kasan/common.c:370 [inline] __kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:387 kmalloc_noprof include/linux/slab.h:681 [inline] kzalloc_noprof include/linux/slab.h:807 [inline] l2cap_conn_add.part.0+0x60/0xa60 net/bluetooth/l2cap_core.c:6868 l2cap_conn_add net/bluetooth/l2cap_core.c:69 [inline] l2cap_connect_cfm+0x428/0xf80 net/bluetooth/l2cap_core.c:7245 hci_connect_cfm include/net/bluetooth/hci_core.h:1960 [inline] hci_remote_features_evt+0x548/0x9e0 net/bluetooth/hci_event.c:3721 hci_event_func net/bluetooth/hci_event.c:7446 [inline] hci_event_packet+0x9eb/0x1180 net/bluetooth/hci_event.c:7498 hci_rx_work+0x2c6/0x1610 net/bluetooth/hci_core.c:4023 process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231 process_scheduled_works kernel/workqueue.c:3312 [inline] worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389 kthread+0x2c1/0x3a0 kernel/kthread.c:389 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 Freed by task 5245: kasan_save_stack+0x33/0x60 mm/kasan/common.c:47 kasan_save_track+0x14/0x30 mm/kasan/common.c:68 kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:579 poison_slab_object+0xf7/0x160 mm/kasan/common.c:240 __kasan_slab_free+0x32/0x50 mm/kasan/common.c:256 kasan_slab_free include/linux/kasan.h:184 [inline] slab_free_hook mm/slub.c:2256 [inline] slab_free mm/slub.c:4477 [inline] kfree+0x12a/0x3b0 mm/slub.c:4598 l2cap_conn_free net/bluetooth/l2cap_core.c:1810 [inline] kref_put include/linux/kref.h:65 [inline] l2cap_conn_put net/bluetooth/l2cap_core.c:1822 [inline] l2cap_conn_del+0x59d/0x730 net/bluetooth/l2cap_core.c:1802 l2cap_connect_cfm+0x9e6/0xf80 net/bluetooth/l2cap_core.c:7241 hci_connect_cfm include/net/bluetooth/hci_core.h:1960 [inline] hci_conn_failed+0x1c3/0x370 net/bluetooth/hci_conn.c:1265 hci_abort_conn_sync+0x75a/0xb50 net/bluetooth/hci_sync.c:5583 abort_conn_sync+0x197/0x360 net/bluetooth/hci_conn.c:2917 hci_cmd_sync_work+0x1a4/0x410 net/bluetooth/hci_sync.c:328 process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231 process_scheduled_works kernel/workqueue.c:3312 [inline] worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389 kthread+0x2c1/0x3a0 kernel/kthread.c:389 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 Last potentially related work creation: kasan_save_stack+0x33/0x60 mm/kasan/common.c:47 __kasan_record_aux_stack+0xba/0xd0 mm/kasan/generic.c:541 insert_work+0x36/0x230 kernel/workqueue.c:2185 __queue_work+0x97e/0x1070 kernel/workqueue.c:2341 call_timer_fn+0x1a0/0x610 kernel/time/timer.c:1792 expire_timers kernel/time/timer.c:1838 [inline] __run_timers+0x567/0xaf0 kernel/time/timer.c:2417 __run_timer_base kernel/time/timer.c:2428 [inline] __run_timer_base kernel/time/timer.c:2421 [inline] run_timer_base+0x111/0x190 kernel/time/timer.c:2437 run_timer_softirq+0x1a/0x40 kernel/time/timer.c:2447 handle_softirqs+0x216/0x8f0 kernel/softirq.c:554 __do_softirq kernel/softirq.c:588 [inline] invoke_softirq kernel/softirq.c:428 [inline] __irq_exit_rcu kernel/softirq.c:637 [inline] irq_exit_rcu+0xbb/0x120 kernel/softirq.c:649 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1043 [inline] sysvec_apic_timer_interrupt+0x95/0xb0 arch/x86/kernel/apic/apic.c:1043 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:702 Second to last potentially related work creation: kasan_save_stack+0x33/0x60 mm/kasan/common.c:47 __kasan_record_aux_stack+0xba/0xd0 mm/kasan/generic.c:541 insert_work+0x36/0x230 kernel/workqueue.c:2185 __queue_work+0x3f8/0x1070 kernel/workqueue.c:2345 queue_work_on+0x11a/0x140 kernel/workqueue.c:2392 queue_work include/linux/workqueue.h:621 [inline] l2cap_conn_ready net/bluetooth/l2cap_core.c:1640 [inline] l2cap_connect_cfm+0x9c9/0xf80 net/bluetooth/l2cap_core.c:7286 hci_connect_cfm include/net/bluetooth/hci_core.h:1960 [inline] hci_remote_features_evt+0x548/0x9e0 net/bluetooth/hci_event.c:3721 hci_event_func net/bluetooth/hci_event.c:7446 [inline] hci_event_packet+0x9eb/0x1180 net/bluetooth/hci_event.c:7498 hci_rx_work+0x2c6/0x1610 net/bluetooth/hci_core.c:4023 process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231 process_scheduled_works kernel/workqueue.c:3312 [inline] worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389 kthread+0x2c1/0x3a0 kernel/kthread.c:389 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 The buggy address belongs to the object at ffff8880241e9800 which belongs to the cache kmalloc-1k of size 1024 The buggy address is located 0 bytes inside of freed 1024-byte region [ffff8880241e9800, ffff8880241e9c00) The buggy address belongs to the physical page: page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x241e8 head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff) page_type: 0xfdffffff(slab) raw: 00fff00000000040 ffff88801ac41dc0 ffffea00007cac00 dead000000000002 raw: 0000000000000000 0000000000100010 00000001fdffffff 0000000000000000 head: 00fff00000000040 ffff88801ac41dc0 ffffea00007cac00 dead000000000002 head: 0000000000000000 0000000000100010 00000001fdffffff 0000000000000000 head: 00fff00000000003 ffffea0000907a01 ffffffffffffffff 0000000000000000 head: 0000000000000008 0000000000000000 00000000ffffffff 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 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 4642, tgid 4642 (init), ts 27796307015, free_ts 0 set_page_owner include/linux/page_owner.h:32 [inline] post_alloc_hook+0x2d1/0x350 mm/page_alloc.c:1500 prep_new_page mm/page_alloc.c:1508 [inline] get_page_from_freelist+0x1351/0x2e50 mm/page_alloc.c:3446 __alloc_pages_noprof+0x22b/0x2460 mm/page_alloc.c:4702 __alloc_pages_node_noprof include/linux/gfp.h:269 [inline] alloc_pages_node_noprof include/linux/gfp.h:296 [inline] alloc_slab_page+0x4e/0xf0 mm/slub.c:2325 allocate_slab mm/slub.c:2488 [inline] new_slab+0x84/0x260 mm/slub.c:2541 ___slab_alloc+0xdac/0x1870 mm/slub.c:3727 __slab_alloc.constprop.0+0x56/0xb0 mm/slub.c:3817 __slab_alloc_node mm/slub.c:3870 [inline] slab_alloc_node mm/slub.c:4029 [inline] __do_kmalloc_node mm/slub.c:4161 [inline] __kmalloc_noprof+0x367/0x400 mm/slub.c:4174 kmalloc_noprof include/linux/slab.h:685 [inline] kzalloc_noprof include/linux/slab.h:807 [inline] tomoyo_init_log+0x13ca/0x2180 security/tomoyo/audit.c:275 tomoyo_supervisor+0x30c/0xea0 security/tomoyo/common.c:2089 tomoyo_audit_env_log security/tomoyo/environ.c:36 [inline] tomoyo_env_perm+0x193/0x210 security/tomoyo/environ.c:63 tomoyo_environ security/tomoyo/domain.c:672 [inline] tomoyo_find_next_domain+0xef9/0x2020 security/tomoyo/domain.c:878 tomoyo_bprm_check_security security/tomoyo/tomoyo.c:102 [inline] tomoyo_bprm_check_security+0x12e/0x1d0 security/tomoyo/tomoyo.c:92 security_bprm_check+0x65/0xb0 security/security.c:1191 search_binary_handler fs/exec.c:1815 [inline] exec_binprm fs/exec.c:1869 [inline] bprm_execve fs/exec.c:1920 [inline] bprm_execve+0x642/0x1960 fs/exec.c:1896 do_execveat_common.isra.0+0x4f1/0x630 fs/exec.c:2027 page_owner free stack trace missing Memory state around the buggy address: ffff8880241e9700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff8880241e9780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc >ffff8880241e9800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff8880241e9880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff8880241e9900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== --- If you want syzbot to run the reproducer, reply with: #syz test: git://repo/address.git branch-or-commit-hash If you attach or paste a git patch, syzbot will apply it before testing. ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect 2024-09-07 14:42 ` syzbot @ 2024-09-08 7:22 ` Edward Adam Davis 2024-09-10 20:56 ` Luiz Augusto von Dentz 0 siblings, 1 reply; 15+ messages in thread From: Edward Adam Davis @ 2024-09-08 7:22 UTC (permalink / raw) To: syzbot+c12e2f941af1feb5632c Cc: johan.hedberg, linux-bluetooth, linux-kernel, luiz.dentz, marcel, syzkaller-bugs [Syzbot reported] BUG: KASAN: slab-use-after-free in l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949 Read of size 8 at addr ffff8880241e9800 by task kworker/u9:0/54 CPU: 0 UID: 0 PID: 54 Comm: kworker/u9:0 Not tainted 6.11.0-rc6-syzkaller-00268-g788220eee30d #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024 Workqueue: hci2 hci_rx_work Call Trace: <TASK> __dump_stack lib/dump_stack.c:93 [inline] dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:119 print_address_description mm/kasan/report.c:377 [inline] print_report+0xc3/0x620 mm/kasan/report.c:488 kasan_report+0xd9/0x110 mm/kasan/report.c:601 l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949 l2cap_connect_req net/bluetooth/l2cap_core.c:4080 [inline] l2cap_bredr_sig_cmd net/bluetooth/l2cap_core.c:4772 [inline] l2cap_sig_channel net/bluetooth/l2cap_core.c:5543 [inline] l2cap_recv_frame+0xf0b/0x8eb0 net/bluetooth/l2cap_core.c:6825 l2cap_recv_acldata+0x9b4/0xb70 net/bluetooth/l2cap_core.c:7514 hci_acldata_packet net/bluetooth/hci_core.c:3791 [inline] hci_rx_work+0xaab/0x1610 net/bluetooth/hci_core.c:4028 process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231 process_scheduled_works kernel/workqueue.c:3312 [inline] worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389 kthread+0x2c1/0x3a0 kernel/kthread.c:389 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 ... Freed by task 5245: kasan_save_stack+0x33/0x60 mm/kasan/common.c:47 kasan_save_track+0x14/0x30 mm/kasan/common.c:68 kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:579 poison_slab_object+0xf7/0x160 mm/kasan/common.c:240 __kasan_slab_free+0x32/0x50 mm/kasan/common.c:256 kasan_slab_free include/linux/kasan.h:184 [inline] slab_free_hook mm/slub.c:2256 [inline] slab_free mm/slub.c:4477 [inline] kfree+0x12a/0x3b0 mm/slub.c:4598 l2cap_conn_free net/bluetooth/l2cap_core.c:1810 [inline] kref_put include/linux/kref.h:65 [inline] l2cap_conn_put net/bluetooth/l2cap_core.c:1822 [inline] l2cap_conn_del+0x59d/0x730 net/bluetooth/l2cap_core.c:1802 l2cap_connect_cfm+0x9e6/0xf80 net/bluetooth/l2cap_core.c:7241 hci_connect_cfm include/net/bluetooth/hci_core.h:1960 [inline] hci_conn_failed+0x1c3/0x370 net/bluetooth/hci_conn.c:1265 hci_abort_conn_sync+0x75a/0xb50 net/bluetooth/hci_sync.c:5583 abort_conn_sync+0x197/0x360 net/bluetooth/hci_conn.c:2917 hci_cmd_sync_work+0x1a4/0x410 net/bluetooth/hci_sync.c:328 process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231 process_scheduled_works kernel/workqueue.c:3312 [inline] worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389 kthread+0x2c1/0x3a0 kernel/kthread.c:389 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 [Analysis] There was a data race when accessing conn in hci_rx_work and hci_cmd_sync_work. This is because the hci dev lock was prematurely exited when executing hci_acldata_macket() in hci_rx_work, which resulted in it being released by hci_cmd_sync_work when accessing conn outside the lock. Reported-and-tested-by: syzbot+c12e2f941af1feb5632c@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=c12e2f941af1feb5632c Signed-off-by: Edward Adam Davis <eadavis@qq.com> --- net/bluetooth/hci_core.c | 3 ++- net/bluetooth/l2cap_core.c | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index f25a21f532aa..4f7b45bb863f 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3776,18 +3776,19 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) hci_dev_lock(hdev); conn = hci_conn_hash_lookup_handle(hdev, handle); - hci_dev_unlock(hdev); if (conn) { hci_conn_enter_active_mode(conn, BT_POWER_FORCE_ACTIVE_OFF); /* Send to upper protocol */ l2cap_recv_acldata(conn, skb, flags); + hci_dev_unlock(hdev); return; } else { bt_dev_err(hdev, "ACL packet for unknown connection handle %d", handle); } + hci_dev_unlock(hdev); kfree_skb(skb); } diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 9988ba382b68..b948b0a3b2f2 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4072,10 +4072,8 @@ static int l2cap_connect_req(struct l2cap_conn *conn, if (cmd_len < sizeof(struct l2cap_conn_req)) return -EPROTO; - hci_dev_lock(hdev); if (hci_dev_test_flag(hdev, HCI_MGMT)) mgmt_device_connected(hdev, hcon, NULL, 0); - hci_dev_unlock(hdev); l2cap_connect(conn, cmd, data, L2CAP_CONN_RSP); return 0; -- 2.43.0 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect 2024-09-08 7:22 ` [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect Edward Adam Davis @ 2024-09-10 20:56 ` Luiz Augusto von Dentz 2024-09-20 15:07 ` Luiz Augusto von Dentz 2024-09-21 10:56 ` Hillf Danton 0 siblings, 2 replies; 15+ messages in thread From: Luiz Augusto von Dentz @ 2024-09-10 20:56 UTC (permalink / raw) To: Edward Adam Davis Cc: syzbot+c12e2f941af1feb5632c, johan.hedberg, linux-bluetooth, linux-kernel, marcel, syzkaller-bugs Hi Edward, On Sun, Sep 8, 2024 at 3:22 AM Edward Adam Davis <eadavis@qq.com> wrote: > > [Syzbot reported] > BUG: KASAN: slab-use-after-free in l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949 > Read of size 8 at addr ffff8880241e9800 by task kworker/u9:0/54 > > CPU: 0 UID: 0 PID: 54 Comm: kworker/u9:0 Not tainted 6.11.0-rc6-syzkaller-00268-g788220eee30d #0 > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024 > Workqueue: hci2 hci_rx_work > Call Trace: > <TASK> > __dump_stack lib/dump_stack.c:93 [inline] > dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:119 > print_address_description mm/kasan/report.c:377 [inline] > print_report+0xc3/0x620 mm/kasan/report.c:488 > kasan_report+0xd9/0x110 mm/kasan/report.c:601 > l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949 > l2cap_connect_req net/bluetooth/l2cap_core.c:4080 [inline] > l2cap_bredr_sig_cmd net/bluetooth/l2cap_core.c:4772 [inline] > l2cap_sig_channel net/bluetooth/l2cap_core.c:5543 [inline] > l2cap_recv_frame+0xf0b/0x8eb0 net/bluetooth/l2cap_core.c:6825 > l2cap_recv_acldata+0x9b4/0xb70 net/bluetooth/l2cap_core.c:7514 > hci_acldata_packet net/bluetooth/hci_core.c:3791 [inline] > hci_rx_work+0xaab/0x1610 net/bluetooth/hci_core.c:4028 > process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231 > process_scheduled_works kernel/workqueue.c:3312 [inline] > worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389 > kthread+0x2c1/0x3a0 kernel/kthread.c:389 > ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 > ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 > ... > > Freed by task 5245: > kasan_save_stack+0x33/0x60 mm/kasan/common.c:47 > kasan_save_track+0x14/0x30 mm/kasan/common.c:68 > kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:579 > poison_slab_object+0xf7/0x160 mm/kasan/common.c:240 > __kasan_slab_free+0x32/0x50 mm/kasan/common.c:256 > kasan_slab_free include/linux/kasan.h:184 [inline] > slab_free_hook mm/slub.c:2256 [inline] > slab_free mm/slub.c:4477 [inline] > kfree+0x12a/0x3b0 mm/slub.c:4598 > l2cap_conn_free net/bluetooth/l2cap_core.c:1810 [inline] > kref_put include/linux/kref.h:65 [inline] > l2cap_conn_put net/bluetooth/l2cap_core.c:1822 [inline] > l2cap_conn_del+0x59d/0x730 net/bluetooth/l2cap_core.c:1802 > l2cap_connect_cfm+0x9e6/0xf80 net/bluetooth/l2cap_core.c:7241 > hci_connect_cfm include/net/bluetooth/hci_core.h:1960 [inline] > hci_conn_failed+0x1c3/0x370 net/bluetooth/hci_conn.c:1265 > hci_abort_conn_sync+0x75a/0xb50 net/bluetooth/hci_sync.c:5583 > abort_conn_sync+0x197/0x360 net/bluetooth/hci_conn.c:2917 > hci_cmd_sync_work+0x1a4/0x410 net/bluetooth/hci_sync.c:328 > process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231 > process_scheduled_works kernel/workqueue.c:3312 [inline] > worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389 > kthread+0x2c1/0x3a0 kernel/kthread.c:389 > ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 > ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 > > [Analysis] > There was a data race when accessing conn in hci_rx_work and hci_cmd_sync_work. > This is because the hci dev lock was prematurely exited when executing > hci_acldata_macket() in hci_rx_work, which resulted in it being released > by hci_cmd_sync_work when accessing conn outside the lock. > > Reported-and-tested-by: syzbot+c12e2f941af1feb5632c@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=c12e2f941af1feb5632c > Signed-off-by: Edward Adam Davis <eadavis@qq.com> > --- > net/bluetooth/hci_core.c | 3 ++- > net/bluetooth/l2cap_core.c | 2 -- > 2 files changed, 2 insertions(+), 3 deletions(-) > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > index f25a21f532aa..4f7b45bb863f 100644 > --- a/net/bluetooth/hci_core.c > +++ b/net/bluetooth/hci_core.c > @@ -3776,18 +3776,19 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) > > hci_dev_lock(hdev); > conn = hci_conn_hash_lookup_handle(hdev, handle); > - hci_dev_unlock(hdev); > > if (conn) { > hci_conn_enter_active_mode(conn, BT_POWER_FORCE_ACTIVE_OFF); > > /* Send to upper protocol */ > l2cap_recv_acldata(conn, skb, flags); > + hci_dev_unlock(hdev); > return; > } else { > bt_dev_err(hdev, "ACL packet for unknown connection handle %d", > handle); > } > + hci_dev_unlock(hdev); This is sort of risky, we shouldn't be calling this deep into the stack with hci_dev_lock held. > > kfree_skb(skb); > } > diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c > index 9988ba382b68..b948b0a3b2f2 100644 > --- a/net/bluetooth/l2cap_core.c > +++ b/net/bluetooth/l2cap_core.c > @@ -4072,10 +4072,8 @@ static int l2cap_connect_req(struct l2cap_conn *conn, > if (cmd_len < sizeof(struct l2cap_conn_req)) > return -EPROTO; > > - hci_dev_lock(hdev); > if (hci_dev_test_flag(hdev, HCI_MGMT)) > mgmt_device_connected(hdev, hcon, NULL, 0); > - hci_dev_unlock(hdev); So this might explain why things gets freed while processing the request, we are locking to call mgmt_device_connected which I suspect is no longer needed ever since: commit db11223571d489d1aab575a4ac4b7352d2d54e2f Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Date: Tue Oct 25 14:12:58 2022 -0700 Bluetooth: btusb: Default CONFIG_BT_HCIBTUSB_POLL_SYNC=y poll_sync has been proven to fix races of USB data and event endpoints so this enables it by default. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Tested-by: Tedd Ho-Jeong An <tedd.an@intel.com> Anyway syzbot don't use btusb so I think this might be due some command pending that the emulator is not responding and instead sending data, and then there is the issue that 7b064edae38d ("Bluetooth: Fix authentication if acl data comes before remote feature evt") attempted to fix which I think it actually made it worse by moving the call to mgmt_device_connected into l2cap_core.c it sort move the problem but didn't fix the actual problem. Maybe something like the following would be a better approach: https://gist.github.com/Vudentz/121a15fa4391b2b1f6c7e8d420a6846e > > l2cap_connect(conn, cmd, data, L2CAP_CONN_RSP); > return 0; > -- > 2.43.0 > -- Luiz Augusto von Dentz ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect 2024-09-10 20:56 ` Luiz Augusto von Dentz @ 2024-09-20 15:07 ` Luiz Augusto von Dentz 2024-09-21 1:40 ` Edward Adam Davis 2024-09-21 10:56 ` Hillf Danton 1 sibling, 1 reply; 15+ messages in thread From: Luiz Augusto von Dentz @ 2024-09-20 15:07 UTC (permalink / raw) To: Edward Adam Davis Cc: syzbot+c12e2f941af1feb5632c, johan.hedberg, linux-bluetooth, linux-kernel, marcel, syzkaller-bugs Hi Edward, On Tue, Sep 10, 2024 at 4:56 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > > Hi Edward, > > On Sun, Sep 8, 2024 at 3:22 AM Edward Adam Davis <eadavis@qq.com> wrote: > > > > [Syzbot reported] > > BUG: KASAN: slab-use-after-free in l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949 > > Read of size 8 at addr ffff8880241e9800 by task kworker/u9:0/54 > > > > CPU: 0 UID: 0 PID: 54 Comm: kworker/u9:0 Not tainted 6.11.0-rc6-syzkaller-00268-g788220eee30d #0 > > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024 > > Workqueue: hci2 hci_rx_work > > Call Trace: > > <TASK> > > __dump_stack lib/dump_stack.c:93 [inline] > > dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:119 > > print_address_description mm/kasan/report.c:377 [inline] > > print_report+0xc3/0x620 mm/kasan/report.c:488 > > kasan_report+0xd9/0x110 mm/kasan/report.c:601 > > l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949 > > l2cap_connect_req net/bluetooth/l2cap_core.c:4080 [inline] > > l2cap_bredr_sig_cmd net/bluetooth/l2cap_core.c:4772 [inline] > > l2cap_sig_channel net/bluetooth/l2cap_core.c:5543 [inline] > > l2cap_recv_frame+0xf0b/0x8eb0 net/bluetooth/l2cap_core.c:6825 > > l2cap_recv_acldata+0x9b4/0xb70 net/bluetooth/l2cap_core.c:7514 > > hci_acldata_packet net/bluetooth/hci_core.c:3791 [inline] > > hci_rx_work+0xaab/0x1610 net/bluetooth/hci_core.c:4028 > > process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231 > > process_scheduled_works kernel/workqueue.c:3312 [inline] > > worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389 > > kthread+0x2c1/0x3a0 kernel/kthread.c:389 > > ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 > > ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 > > ... > > > > Freed by task 5245: > > kasan_save_stack+0x33/0x60 mm/kasan/common.c:47 > > kasan_save_track+0x14/0x30 mm/kasan/common.c:68 > > kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:579 > > poison_slab_object+0xf7/0x160 mm/kasan/common.c:240 > > __kasan_slab_free+0x32/0x50 mm/kasan/common.c:256 > > kasan_slab_free include/linux/kasan.h:184 [inline] > > slab_free_hook mm/slub.c:2256 [inline] > > slab_free mm/slub.c:4477 [inline] > > kfree+0x12a/0x3b0 mm/slub.c:4598 > > l2cap_conn_free net/bluetooth/l2cap_core.c:1810 [inline] > > kref_put include/linux/kref.h:65 [inline] > > l2cap_conn_put net/bluetooth/l2cap_core.c:1822 [inline] > > l2cap_conn_del+0x59d/0x730 net/bluetooth/l2cap_core.c:1802 > > l2cap_connect_cfm+0x9e6/0xf80 net/bluetooth/l2cap_core.c:7241 > > hci_connect_cfm include/net/bluetooth/hci_core.h:1960 [inline] > > hci_conn_failed+0x1c3/0x370 net/bluetooth/hci_conn.c:1265 > > hci_abort_conn_sync+0x75a/0xb50 net/bluetooth/hci_sync.c:5583 > > abort_conn_sync+0x197/0x360 net/bluetooth/hci_conn.c:2917 > > hci_cmd_sync_work+0x1a4/0x410 net/bluetooth/hci_sync.c:328 > > process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231 > > process_scheduled_works kernel/workqueue.c:3312 [inline] > > worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389 > > kthread+0x2c1/0x3a0 kernel/kthread.c:389 > > ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 > > ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 > > > > [Analysis] > > There was a data race when accessing conn in hci_rx_work and hci_cmd_sync_work. > > This is because the hci dev lock was prematurely exited when executing > > hci_acldata_macket() in hci_rx_work, which resulted in it being released > > by hci_cmd_sync_work when accessing conn outside the lock. > > > > Reported-and-tested-by: syzbot+c12e2f941af1feb5632c@syzkaller.appspotmail.com > > Closes: https://syzkaller.appspot.com/bug?extid=c12e2f941af1feb5632c > > Signed-off-by: Edward Adam Davis <eadavis@qq.com> > > --- > > net/bluetooth/hci_core.c | 3 ++- > > net/bluetooth/l2cap_core.c | 2 -- > > 2 files changed, 2 insertions(+), 3 deletions(-) > > > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > > index f25a21f532aa..4f7b45bb863f 100644 > > --- a/net/bluetooth/hci_core.c > > +++ b/net/bluetooth/hci_core.c > > @@ -3776,18 +3776,19 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) > > > > hci_dev_lock(hdev); > > conn = hci_conn_hash_lookup_handle(hdev, handle); > > - hci_dev_unlock(hdev); > > > > if (conn) { > > hci_conn_enter_active_mode(conn, BT_POWER_FORCE_ACTIVE_OFF); > > > > /* Send to upper protocol */ > > l2cap_recv_acldata(conn, skb, flags); > > + hci_dev_unlock(hdev); > > return; > > } else { > > bt_dev_err(hdev, "ACL packet for unknown connection handle %d", > > handle); > > } > > + hci_dev_unlock(hdev); > > This is sort of risky, we shouldn't be calling this deep into the > stack with hci_dev_lock held. > > > > > kfree_skb(skb); > > } > > diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c > > index 9988ba382b68..b948b0a3b2f2 100644 > > --- a/net/bluetooth/l2cap_core.c > > +++ b/net/bluetooth/l2cap_core.c > > @@ -4072,10 +4072,8 @@ static int l2cap_connect_req(struct l2cap_conn *conn, > > if (cmd_len < sizeof(struct l2cap_conn_req)) > > return -EPROTO; > > > > - hci_dev_lock(hdev); > > if (hci_dev_test_flag(hdev, HCI_MGMT)) > > mgmt_device_connected(hdev, hcon, NULL, 0); > > - hci_dev_unlock(hdev); > > So this might explain why things gets freed while processing the > request, we are locking to call mgmt_device_connected which I suspect > is no longer needed ever since: > > commit db11223571d489d1aab575a4ac4b7352d2d54e2f > Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> > Date: Tue Oct 25 14:12:58 2022 -0700 > > Bluetooth: btusb: Default CONFIG_BT_HCIBTUSB_POLL_SYNC=y > > poll_sync has been proven to fix races of USB data and event endpoints > so this enables it by default. > > Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> > Tested-by: Tedd Ho-Jeong An <tedd.an@intel.com> > > Anyway syzbot don't use btusb so I think this might be due some > command pending that the emulator is not responding and instead > sending data, and then there is the issue that 7b064edae38d > ("Bluetooth: Fix authentication if acl data comes before remote > feature evt") attempted to fix which I think it actually made it worse > by moving the call to mgmt_device_connected into l2cap_core.c it sort > move the problem but didn't fix the actual problem. > > Maybe something like the following would be a better approach: > > https://gist.github.com/Vudentz/121a15fa4391b2b1f6c7e8d420a6846e Any comments? Are you still planning to work on this? > > > > l2cap_connect(conn, cmd, data, L2CAP_CONN_RSP); > > return 0; > > -- > > 2.43.0 > > > > > -- > Luiz Augusto von Dentz -- Luiz Augusto von Dentz ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect 2024-09-20 15:07 ` Luiz Augusto von Dentz @ 2024-09-21 1:40 ` Edward Adam Davis 0 siblings, 0 replies; 15+ messages in thread From: Edward Adam Davis @ 2024-09-21 1:40 UTC (permalink / raw) To: luiz.dentz Cc: eadavis, johan.hedberg, linux-bluetooth, linux-kernel, marcel, syzbot+c12e2f941af1feb5632c, syzkaller-bugs On Fri, 20 Sep 2024 11:07:05 -0400, Luiz Augusto von Dentz wrote: > On Tue, Sep 10, 2024 at 4:56 PM Luiz Augusto von Dentz > <luiz.dentz@gmail.com> wrote: > > > > Hi Edward, > > > > On Sun, Sep 8, 2024 at 3:22 AM Edward Adam Davis <eadavis@qq.com> wrote: > > > > > > [Syzbot reported] > > > BUG: KASAN: slab-use-after-free in l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949 > > > Read of size 8 at addr ffff8880241e9800 by task kworker/u9:0/54 > > > > > > CPU: 0 UID: 0 PID: 54 Comm: kworker/u9:0 Not tainted 6.11.0-rc6-syzkaller-00268-g788220eee30d #0 > > > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024 > > > Workqueue: hci2 hci_rx_work > > > Call Trace: > > > <TASK> > > > __dump_stack lib/dump_stack.c:93 [inline] > > > dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:119 > > > print_address_description mm/kasan/report.c:377 [inline] > > > print_report+0xc3/0x620 mm/kasan/report.c:488 > > > kasan_report+0xd9/0x110 mm/kasan/report.c:601 > > > l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949 > > > l2cap_connect_req net/bluetooth/l2cap_core.c:4080 [inline] > > > l2cap_bredr_sig_cmd net/bluetooth/l2cap_core.c:4772 [inline] > > > l2cap_sig_channel net/bluetooth/l2cap_core.c:5543 [inline] > > > l2cap_recv_frame+0xf0b/0x8eb0 net/bluetooth/l2cap_core.c:6825 > > > l2cap_recv_acldata+0x9b4/0xb70 net/bluetooth/l2cap_core.c:7514 > > > hci_acldata_packet net/bluetooth/hci_core.c:3791 [inline] > > > hci_rx_work+0xaab/0x1610 net/bluetooth/hci_core.c:4028 > > > process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231 > > > process_scheduled_works kernel/workqueue.c:3312 [inline] > > > worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389 > > > kthread+0x2c1/0x3a0 kernel/kthread.c:389 > > > ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 > > > ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 > > > ... > > > > > > Freed by task 5245: > > > kasan_save_stack+0x33/0x60 mm/kasan/common.c:47 > > > kasan_save_track+0x14/0x30 mm/kasan/common.c:68 > > > kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:579 > > > poison_slab_object+0xf7/0x160 mm/kasan/common.c:240 > > > __kasan_slab_free+0x32/0x50 mm/kasan/common.c:256 > > > kasan_slab_free include/linux/kasan.h:184 [inline] > > > slab_free_hook mm/slub.c:2256 [inline] > > > slab_free mm/slub.c:4477 [inline] > > > kfree+0x12a/0x3b0 mm/slub.c:4598 > > > l2cap_conn_free net/bluetooth/l2cap_core.c:1810 [inline] > > > kref_put include/linux/kref.h:65 [inline] > > > l2cap_conn_put net/bluetooth/l2cap_core.c:1822 [inline] > > > l2cap_conn_del+0x59d/0x730 net/bluetooth/l2cap_core.c:1802 > > > l2cap_connect_cfm+0x9e6/0xf80 net/bluetooth/l2cap_core.c:7241 > > > hci_connect_cfm include/net/bluetooth/hci_core.h:1960 [inline] > > > hci_conn_failed+0x1c3/0x370 net/bluetooth/hci_conn.c:1265 > > > hci_abort_conn_sync+0x75a/0xb50 net/bluetooth/hci_sync.c:5583 > > > abort_conn_sync+0x197/0x360 net/bluetooth/hci_conn.c:2917 > > > hci_cmd_sync_work+0x1a4/0x410 net/bluetooth/hci_sync.c:328 > > > process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231 > > > process_scheduled_works kernel/workqueue.c:3312 [inline] > > > worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389 > > > kthread+0x2c1/0x3a0 kernel/kthread.c:389 > > > ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 > > > ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 > > > > > > [Analysis] > > > There was a data race when accessing conn in hci_rx_work and hci_cmd_sync_work. > > > This is because the hci dev lock was prematurely exited when executing > > > hci_acldata_macket() in hci_rx_work, which resulted in it being released > > > by hci_cmd_sync_work when accessing conn outside the lock. > > > > > > Reported-and-tested-by: syzbot+c12e2f941af1feb5632c@syzkaller.appspotmail.com > > > Closes: https://syzkaller.appspot.com/bug?extid=c12e2f941af1feb5632c > > > Signed-off-by: Edward Adam Davis <eadavis@qq.com> > > > --- > > > net/bluetooth/hci_core.c | 3 ++- > > > net/bluetooth/l2cap_core.c | 2 -- > > > 2 files changed, 2 insertions(+), 3 deletions(-) > > > > > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > > > index f25a21f532aa..4f7b45bb863f 100644 > > > --- a/net/bluetooth/hci_core.c > > > +++ b/net/bluetooth/hci_core.c > > > @@ -3776,18 +3776,19 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) > > > > > > hci_dev_lock(hdev); > > > conn = hci_conn_hash_lookup_handle(hdev, handle); > > > - hci_dev_unlock(hdev); > > > > > > if (conn) { > > > hci_conn_enter_active_mode(conn, BT_POWER_FORCE_ACTIVE_OFF); > > > > > > /* Send to upper protocol */ > > > l2cap_recv_acldata(conn, skb, flags); > > > + hci_dev_unlock(hdev); > > > return; > > > } else { > > > bt_dev_err(hdev, "ACL packet for unknown connection handle %d", > > > handle); > > > } > > > + hci_dev_unlock(hdev); > > > > This is sort of risky, we shouldn't be calling this deep into the > > stack with hci_dev_lock held. I haven't thought of any better way yet. I understand what you mean, holding hci_dev_lock for a long time. At present, it is not impossible to try some strong drugs. > > > > > > > > kfree_skb(skb); > > > } > > > diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c > > > index 9988ba382b68..b948b0a3b2f2 100644 > > > --- a/net/bluetooth/l2cap_core.c > > > +++ b/net/bluetooth/l2cap_core.c > > > @@ -4072,10 +4072,8 @@ static int l2cap_connect_req(struct l2cap_conn *conn, > > > if (cmd_len < sizeof(struct l2cap_conn_req)) > > > return -EPROTO; > > > > > > - hci_dev_lock(hdev); > > > if (hci_dev_test_flag(hdev, HCI_MGMT)) > > > mgmt_device_connected(hdev, hcon, NULL, 0); > > > - hci_dev_unlock(hdev); > > > > So this might explain why things gets freed while processing the > > request, we are locking to call mgmt_device_connected which I suspect > > is no longer needed ever since: > > > > commit db11223571d489d1aab575a4ac4b7352d2d54e2f > > Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> > > Date: Tue Oct 25 14:12:58 2022 -0700 > > > > Bluetooth: btusb: Default CONFIG_BT_HCIBTUSB_POLL_SYNC=y > > > > poll_sync has been proven to fix races of USB data and event endpoints > > so this enables it by default. > > > > Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> > > Tested-by: Tedd Ho-Jeong An <tedd.an@intel.com> > > > > Anyway syzbot don't use btusb so I think this might be due some > > command pending that the emulator is not responding and instead > > sending data, and then there is the issue that 7b064edae38d > > ("Bluetooth: Fix authentication if acl data comes before remote > > feature evt") attempted to fix which I think it actually made it worse > > by moving the call to mgmt_device_connected into l2cap_core.c it sort > > move the problem but didn't fix the actual problem. I think 7B064edae38d is used to solve another issue. > > > > Maybe something like the following would be a better approach: > > > > https://gist.github.com/Vudentz/121a15fa4391b2b1f6c7e8d420a6846e > > Any comments? Are you still planning to work on this? Sorry for late. > > > > > > > l2cap_connect(conn, cmd, data, L2CAP_CONN_RSP); > > > return 0; > > > -- > > > 2.43.0 > > > > > > > > > -- > > Luiz Augusto von Dentz BR, Edward ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect 2024-09-10 20:56 ` Luiz Augusto von Dentz 2024-09-20 15:07 ` Luiz Augusto von Dentz @ 2024-09-21 10:56 ` Hillf Danton 2024-09-23 14:32 ` Luiz Augusto von Dentz 1 sibling, 1 reply; 15+ messages in thread From: Hillf Danton @ 2024-09-21 10:56 UTC (permalink / raw) To: Luiz Augusto von Dentz Cc: Edward Adam Davis, syzbot+c12e2f941af1feb5632c, linux-bluetooth, linux-kernel, syzkaller-bugs On Tue, Sep 10, 2024 at 4:56 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > > Maybe something like the following would be a better approach: > > https://gist.github.com/Vudentz/121a15fa4391b2b1f6c7e8d420a6846e If your idea is not bad, boy, feel free to win Tested-by from syzbot with it. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect 2024-09-21 10:56 ` Hillf Danton @ 2024-09-23 14:32 ` Luiz Augusto von Dentz 2024-09-23 14:37 ` Aleksandr Nogikh 0 siblings, 1 reply; 15+ messages in thread From: Luiz Augusto von Dentz @ 2024-09-23 14:32 UTC (permalink / raw) To: Hillf Danton Cc: Edward Adam Davis, syzbot+c12e2f941af1feb5632c, linux-bluetooth, linux-kernel, syzkaller-bugs Hi Hillf, On Sat, Sep 21, 2024 at 6:56 AM Hillf Danton <hdanton@sina.com> wrote: > > On Tue, Sep 10, 2024 at 4:56 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > > > > Maybe something like the following would be a better approach: > > > > https://gist.github.com/Vudentz/121a15fa4391b2b1f6c7e8d420a6846e > > If your idea is not bad, boy, feel free to win Tested-by from syzbot with it. Is there a way to quickly check a patch with syzbot? -- Luiz Augusto von Dentz ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect 2024-09-23 14:32 ` Luiz Augusto von Dentz @ 2024-09-23 14:37 ` Aleksandr Nogikh 2024-09-23 15:20 ` Luiz Augusto von Dentz 0 siblings, 1 reply; 15+ messages in thread From: Aleksandr Nogikh @ 2024-09-23 14:37 UTC (permalink / raw) To: Luiz Augusto von Dentz Cc: Hillf Danton, Edward Adam Davis, syzbot+c12e2f941af1feb5632c, linux-bluetooth, linux-kernel, syzkaller-bugs On Mon, Sep 23, 2024 at 4:33 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > > Hi Hillf, > > On Sat, Sep 21, 2024 at 6:56 AM Hillf Danton <hdanton@sina.com> wrote: > > > > On Tue, Sep 10, 2024 at 4:56 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > > > > > > Maybe something like the following would be a better approach: > > > > > > https://gist.github.com/Vudentz/121a15fa4391b2b1f6c7e8d420a6846e > > > > If your idea is not bad, boy, feel free to win Tested-by from syzbot with it. > > Is there a way to quickly check a patch with syzbot? You can send a `#syz test` command in a reply to syzbot and attach the patch-to-test to the email message. See https://github.com/google/syzkaller/blob/master/docs/syzbot.md#testing-patches -- Aleksandr > > -- > Luiz Augusto von Dentz > ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect 2024-09-23 14:37 ` Aleksandr Nogikh @ 2024-09-23 15:20 ` Luiz Augusto von Dentz 2024-09-23 15:28 ` [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2) syzbot ` (2 more replies) 0 siblings, 3 replies; 15+ messages in thread From: Luiz Augusto von Dentz @ 2024-09-23 15:20 UTC (permalink / raw) To: Aleksandr Nogikh Cc: Hillf Danton, Edward Adam Davis, syzbot+c12e2f941af1feb5632c, linux-bluetooth, linux-kernel, syzkaller-bugs Hi Aleksandr, On Mon, Sep 23, 2024 at 10:37 AM Aleksandr Nogikh <nogikh@google.com> wrote: > > On Mon, Sep 23, 2024 at 4:33 PM Luiz Augusto von Dentz > <luiz.dentz@gmail.com> wrote: > > > > Hi Hillf, > > > > On Sat, Sep 21, 2024 at 6:56 AM Hillf Danton <hdanton@sina.com> wrote: > > > > > > On Tue, Sep 10, 2024 at 4:56 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > > > > > > > > Maybe something like the following would be a better approach: > > > > > > > > https://gist.github.com/Vudentz/121a15fa4391b2b1f6c7e8d420a6846e > > > > > > If your idea is not bad, boy, feel free to win Tested-by from syzbot with it. > > > > Is there a way to quickly check a patch with syzbot? > > You can send a `#syz test` command in a reply to syzbot and attach the > patch-to-test to the email message. > > See https://github.com/google/syzkaller/blob/master/docs/syzbot.md#testing-patches Thanks, lets see if this works: #syz test diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index d6976db02c06..b2f8f9c5b610 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3782,6 +3782,8 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) hci_dev_lock(hdev); conn = hci_conn_hash_lookup_handle(hdev, handle); + if (conn && hci_dev_test_flag(hdev, HCI_MGMT)) + mgmt_device_connected(hdev, conn, NULL, 0); hci_dev_unlock(hdev); if (conn) { diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 1c82dcdf6e8f..b87c0f1dab9e 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3706,7 +3706,7 @@ static void hci_remote_features_evt(struct hci_dev *hdev, void *data, goto unlock; } - if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { + if (!ev->status) { struct hci_cp_remote_name_req cp; memset(&cp, 0, sizeof(cp)); bacpy(&cp.bdaddr, &conn->dst); diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 9988ba382b68..6544c1ed7143 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4066,17 +4066,9 @@ static void l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, static int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) { - struct hci_dev *hdev = conn->hcon->hdev; - struct hci_conn *hcon = conn->hcon; - if (cmd_len < sizeof(struct l2cap_conn_req)) return -EPROTO; - hci_dev_lock(hdev); - if (hci_dev_test_flag(hdev, HCI_MGMT)) - mgmt_device_connected(hdev, hcon, NULL, 0); - hci_dev_unlock(hdev); - l2cap_connect(conn, cmd, data, L2CAP_CONN_RSP); return 0; } ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2) 2024-09-23 15:20 ` Luiz Augusto von Dentz @ 2024-09-23 15:28 ` syzbot 2024-09-23 15:38 ` [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect Aleksandr Nogikh 2024-09-23 15:48 ` Luiz Augusto von Dentz 2 siblings, 0 replies; 15+ messages in thread From: syzbot @ 2024-09-23 15:28 UTC (permalink / raw) To: eadavis, hdanton, linux-bluetooth, linux-kernel, luiz.dentz, nogikh, syzkaller-bugs Hello, syzbot tried to test the proposed patch but the build/boot failed: failed to apply patch: checking file net/bluetooth/hci_core.c patch: **** malformed patch at line 6: diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c Tested on: commit: de5cb0dc Merge branch 'address-masking' git tree: upstream kernel config: https://syzkaller.appspot.com/x/.config?x=57042fe37c7ee7c2 dashboard link: https://syzkaller.appspot.com/bug?extid=c12e2f941af1feb5632c compiler: patch: https://syzkaller.appspot.com/x/patch.diff?x=127c12a9980000 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect 2024-09-23 15:20 ` Luiz Augusto von Dentz 2024-09-23 15:28 ` [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2) syzbot @ 2024-09-23 15:38 ` Aleksandr Nogikh 2024-09-23 15:48 ` Luiz Augusto von Dentz 2 siblings, 0 replies; 15+ messages in thread From: Aleksandr Nogikh @ 2024-09-23 15:38 UTC (permalink / raw) To: Luiz Augusto von Dentz Cc: Hillf Danton, Edward Adam Davis, syzbot+c12e2f941af1feb5632c, linux-bluetooth, linux-kernel, syzkaller-bugs Hi Luiz, On Mon, Sep 23, 2024 at 5:20 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > > Hi Aleksandr, > > On Mon, Sep 23, 2024 at 10:37 AM Aleksandr Nogikh <nogikh@google.com> wrote: > > > > On Mon, Sep 23, 2024 at 4:33 PM Luiz Augusto von Dentz > > <luiz.dentz@gmail.com> wrote: > > > > > > Hi Hillf, > > > > > > On Sat, Sep 21, 2024 at 6:56 AM Hillf Danton <hdanton@sina.com> wrote: > > > > > > > > On Tue, Sep 10, 2024 at 4:56 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > > > > > > > > > > Maybe something like the following would be a better approach: > > > > > > > > > > https://gist.github.com/Vudentz/121a15fa4391b2b1f6c7e8d420a6846e > > > > > > > > If your idea is not bad, boy, feel free to win Tested-by from syzbot with it. > > > > > > Is there a way to quickly check a patch with syzbot? > > > > You can send a `#syz test` command in a reply to syzbot and attach the > > patch-to-test to the email message. > > > > See https://github.com/google/syzkaller/blob/master/docs/syzbot.md#testing-patches > > Thanks, lets see if this works: > > #syz test > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > index d6976db02c06..b2f8f9c5b610 100644 > --- a/net/bluetooth/hci_core.c > +++ b/net/bluetooth/hci_core.c > @@ -3782,6 +3782,8 @@ static void hci_acldata_packet(struct hci_dev > *hdev, struct sk_buff *skb) > > hci_dev_lock(hdev); > conn = hci_conn_hash_lookup_handle(hdev, handle); > + if (conn && hci_dev_test_flag(hdev, HCI_MGMT)) > + mgmt_device_connected(hdev, conn, NULL, 0); > hci_dev_unlock(hdev); > ^^ Patch parsing will fail here because it expects to see the git diff output as is -- i.e. if some line only consisted of a single whitespace (= it was an empty line and it did not change), it must remain so. Sometimes these whitespaces get lost during copy-pasting and it confuses syzbot. > if (conn) { > diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > index 1c82dcdf6e8f..b87c0f1dab9e 100644 > --- a/net/bluetooth/hci_event.c > +++ b/net/bluetooth/hci_event.c > @@ -3706,7 +3706,7 @@ static void hci_remote_features_evt(struct > hci_dev *hdev, void *data, > goto unlock; > } > > - if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { > + if (!ev->status) { > struct hci_cp_remote_name_req cp; > memset(&cp, 0, sizeof(cp)); > bacpy(&cp.bdaddr, &conn->dst); > diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c > index 9988ba382b68..6544c1ed7143 100644 > --- a/net/bluetooth/l2cap_core.c > +++ b/net/bluetooth/l2cap_core.c > @@ -4066,17 +4066,9 @@ static void l2cap_connect(struct l2cap_conn > *conn, struct l2cap_cmd_hdr *cmd, > static int l2cap_connect_req(struct l2cap_conn *conn, > struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) > { > - struct hci_dev *hdev = conn->hcon->hdev; > - struct hci_conn *hcon = conn->hcon; > - > if (cmd_len < sizeof(struct l2cap_conn_req)) > return -EPROTO; > > - hci_dev_lock(hdev); > - if (hci_dev_test_flag(hdev, HCI_MGMT)) > - mgmt_device_connected(hdev, hcon, NULL, 0); > - hci_dev_unlock(hdev); > - > l2cap_connect(conn, cmd, data, L2CAP_CONN_RSP); > return 0; > } -- Aleksandr ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect 2024-09-23 15:20 ` Luiz Augusto von Dentz 2024-09-23 15:28 ` [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2) syzbot 2024-09-23 15:38 ` [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect Aleksandr Nogikh @ 2024-09-23 15:48 ` Luiz Augusto von Dentz 2024-09-23 16:21 ` [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2) syzbot 2 siblings, 1 reply; 15+ messages in thread From: Luiz Augusto von Dentz @ 2024-09-23 15:48 UTC (permalink / raw) To: Aleksandr Nogikh Cc: Hillf Danton, Edward Adam Davis, syzbot+c12e2f941af1feb5632c, linux-bluetooth, linux-kernel, syzkaller-bugs Hi, On Mon, Sep 23, 2024 at 11:20 AM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > > Hi Aleksandr, > > On Mon, Sep 23, 2024 at 10:37 AM Aleksandr Nogikh <nogikh@google.com> wrote: > > > > On Mon, Sep 23, 2024 at 4:33 PM Luiz Augusto von Dentz > > <luiz.dentz@gmail.com> wrote: > > > > > > Hi Hillf, > > > > > > On Sat, Sep 21, 2024 at 6:56 AM Hillf Danton <hdanton@sina.com> wrote: > > > > > > > > On Tue, Sep 10, 2024 at 4:56 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > > > > > > > > > > Maybe something like the following would be a better approach: > > > > > > > > > > https://gist.github.com/Vudentz/121a15fa4391b2b1f6c7e8d420a6846e > > > > > > > > If your idea is not bad, boy, feel free to win Tested-by from syzbot with it. > > > > > > Is there a way to quickly check a patch with syzbot? > > > > You can send a `#syz test` command in a reply to syzbot and attach the > > patch-to-test to the email message. > > > > See https://github.com/google/syzkaller/blob/master/docs/syzbot.md#testing-patches > Lets try again with git diff output: #syz test diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index d6976db02c06..b2f8f9c5b610 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3782,6 +3782,8 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) hci_dev_lock(hdev); conn = hci_conn_hash_lookup_handle(hdev, handle); + if (conn && hci_dev_test_flag(hdev, HCI_MGMT)) + mgmt_device_connected(hdev, conn, NULL, 0); hci_dev_unlock(hdev); if (conn) { diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 1c82dcdf6e8f..b87c0f1dab9e 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3706,7 +3706,7 @@ static void hci_remote_features_evt(struct hci_dev *hdev, void *data, goto unlock; } - if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { + if (!ev->status) { struct hci_cp_remote_name_req cp; memset(&cp, 0, sizeof(cp)); bacpy(&cp.bdaddr, &conn->dst); diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 9988ba382b68..6544c1ed7143 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4066,17 +4066,9 @@ static void l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, static int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) { - struct hci_dev *hdev = conn->hcon->hdev; - struct hci_conn *hcon = conn->hcon; - if (cmd_len < sizeof(struct l2cap_conn_req)) return -EPROTO; - hci_dev_lock(hdev); - if (hci_dev_test_flag(hdev, HCI_MGMT)) - mgmt_device_connected(hdev, hcon, NULL, 0); - hci_dev_unlock(hdev); - l2cap_connect(conn, cmd, data, L2CAP_CONN_RSP); return 0; } ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2) 2024-09-23 15:48 ` Luiz Augusto von Dentz @ 2024-09-23 16:21 ` syzbot 0 siblings, 0 replies; 15+ messages in thread From: syzbot @ 2024-09-23 16:21 UTC (permalink / raw) To: eadavis, hdanton, linux-bluetooth, linux-kernel, luiz.dentz, nogikh, syzkaller-bugs Hello, syzbot tried to test the proposed patch but the build/boot failed: failed to apply patch: checking file net/bluetooth/hci_core.c patch: **** malformed patch at line 6: diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c Tested on: commit: de5cb0dc Merge branch 'address-masking' git tree: upstream kernel config: https://syzkaller.appspot.com/x/.config?x=57042fe37c7ee7c2 dashboard link: https://syzkaller.appspot.com/bug?extid=c12e2f941af1feb5632c compiler: patch: https://syzkaller.appspot.com/x/patch.diff?x=11f72107980000 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2) 2024-06-24 20:23 [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2) syzbot 2024-09-07 14:42 ` syzbot @ 2024-09-10 18:43 ` syzbot 1 sibling, 0 replies; 15+ messages in thread From: syzbot @ 2024-09-10 18:43 UTC (permalink / raw) To: eadavis, hdanton, johan.hedberg, linux-bluetooth, linux-kernel, luiz.dentz, luiz.von.dentz, marcel, syzkaller-bugs syzbot has bisected this issue to: commit 5af1f84ed13a416297ab9ced7537f4d5ae7f329a Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Date: Thu Aug 3 18:04:51 2023 +0000 Bluetooth: hci_sync: Fix UAF on hci_abort_conn_sync bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=12477bc7980000 start commit: 788220eee30d Merge tag 'pm-6.11-rc7' of git://git.kernel.o.. git tree: upstream final oops: https://syzkaller.appspot.com/x/report.txt?x=11477bc7980000 console output: https://syzkaller.appspot.com/x/log.txt?x=16477bc7980000 kernel config: https://syzkaller.appspot.com/x/.config?x=57042fe37c7ee7c2 dashboard link: https://syzkaller.appspot.com/bug?extid=c12e2f941af1feb5632c syz repro: https://syzkaller.appspot.com/x/repro.syz?x=11da6f29980000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1304189f980000 Reported-by: syzbot+c12e2f941af1feb5632c@syzkaller.appspotmail.com Fixes: 5af1f84ed13a ("Bluetooth: hci_sync: Fix UAF on hci_abort_conn_sync") For information about bisection process see: https://goo.gl/tpsmEJ#bisection ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2024-09-23 16:21 UTC | newest] Thread overview: 15+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-06-24 20:23 [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2) syzbot 2024-09-07 14:42 ` syzbot 2024-09-08 7:22 ` [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect Edward Adam Davis 2024-09-10 20:56 ` Luiz Augusto von Dentz 2024-09-20 15:07 ` Luiz Augusto von Dentz 2024-09-21 1:40 ` Edward Adam Davis 2024-09-21 10:56 ` Hillf Danton 2024-09-23 14:32 ` Luiz Augusto von Dentz 2024-09-23 14:37 ` Aleksandr Nogikh 2024-09-23 15:20 ` Luiz Augusto von Dentz 2024-09-23 15:28 ` [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2) syzbot 2024-09-23 15:38 ` [PATCH] Bluetooth/l2cap: Fix uaf in l2cap_connect Aleksandr Nogikh 2024-09-23 15:48 ` Luiz Augusto von Dentz 2024-09-23 16:21 ` [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2) syzbot 2024-09-10 18:43 ` syzbot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox