[<prev] [next>] [day] [month] [year] [list]
Message-ID: <CAFRLqsVkqLHo9tNNEhFiJWEn506nVOM-Bnz_=b36A-kXgzb+mw@mail.gmail.com>
Date: Sun, 21 Sep 2025 16:49:57 +0800
From: Cen Zhang <zzzccc427@...il.com>
To: Luiz Augusto von Dentz <luiz.dentz@...il.com>, johan.hedberg@...il.com, marcel@...tmann.org
Cc: linux-kernel@...r.kernel.org, linux-bluetooth@...r.kernel.org
Subject: [BUG] Bluetooth: Use-after-free in hci_acl_create_conn_sync due to
TOCTOU race condition
Hi maintainers,
I've applied the full v6 series (1/3..3/3)
(https://lore.kernel.org/linux-bluetooth/20250915161504.814410-2-luiz.dentz@gmail.com/T/#u)
but discovered a use-after-free vulnerability may caused by another
reason during testing.
After my analysis ,I think the UAF is caused by a TOCTOU
(Time-of-Check-Time-of-Use) race condition in
hci_acl_create_conn_sync(). Two concurrent flows race on the same
hci_conn object:
1. Flow 1 (Task 74): hci_acl_create_conn_sync() validates the
connection with hci_conn_valid() and proceeds to use it
2. Flow 2 (Task 76): Connection failure handling path calls
hci_conn_del() and frees the connection object
The race window exists between the validity check and actual usage in
hci_acl_create_conn_sync(), where the connection can be freed by the
event handling side due to errors, leading to use-after-free when the
original flow continues execution.
The detail KASAN report as follows:
==================================================================
BUG: KASAN: slab-use-after-free in
hci_acl_create_conn_sync+0x134a/0x16e0 net/bluetooth/hci_sync.c:6861
Write of size 2 at addr ffff8881199b0038 by task kworker/u17:0/74
CPU: 2 UID: 0 PID: 74 Comm: kworker/u17:0 Not tainted
6.17.0-rc5-ge5bbb70171d1-dirty #20 PREEMPT(voluntary)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
Workqueue: hci0 hci_cmd_sync_work
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0xca/0x130 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x171/0x7f0 mm/kasan/report.c:482
kasan_report+0x139/0x170 mm/kasan/report.c:595
hci_acl_create_conn_sync+0x134a/0x16e0 net/bluetooth/hci_sync.c:6861
hci_cmd_sync_work+0x798/0xaf0 net/bluetooth/hci_sync.c:332
process_one_work kernel/workqueue.c:3236 [inline]
process_scheduled_works+0x7a8/0x1030 kernel/workqueue.c:3319
worker_thread+0xb97/0x11d0 kernel/workqueue.c:3400
kthread+0x3d4/0x800 kernel/kthread.c:463
ret_from_fork+0x13b/0x1e0 arch/x86/kernel/process.c:148
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
Allocated by task 60621:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
poison_kmalloc_redzone mm/kasan/common.c:388 [inline]
__kasan_kmalloc+0x72/0x90 mm/kasan/common.c:405
kmalloc_noprof include/linux/slab.h:905 [inline]
kzalloc_noprof include/linux/slab.h:1039 [inline]
__hci_conn_add+0x647/0x51d0 net/bluetooth/hci_conn.c:949
hci_conn_add_unset net/bluetooth/hci_conn.c:1061 [inline]
hci_connect_acl+0x650/0xe60 net/bluetooth/hci_conn.c:1672
hci_connect_sco+0x61/0x1c90 net/bluetooth/hci_conn.c:1734
sco_connect net/bluetooth/sco.c:339 [inline]
sco_sock_connect+0x638/0x1ed0 net/bluetooth/sco.c:658
__sys_connect_file net/socket.c:2086 [inline]
__sys_connect+0x277/0x350 net/socket.c:2105
__do_sys_connect net/socket.c:2111 [inline]
__se_sys_connect net/socket.c:2108 [inline]
__x64_sys_connect+0x7a/0x90 net/socket.c:2108
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xd2/0x200 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 76:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:576
poison_slab_object mm/kasan/common.c:243 [inline]
__kasan_slab_free+0x41/0x50 mm/kasan/common.c:275
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2428 [inline]
slab_free mm/slub.c:4701 [inline]
kfree+0x189/0x390 mm/slub.c:4900
bt_link_release+0x49/0x60 net/bluetooth/hci_sysfs.c:16
device_release+0x9c/0x1c0
kobject_cleanup lib/kobject.c:689 [inline]
kobject_release lib/kobject.c:720 [inline]
kref_put include/linux/kref.h:65 [inline]
kobject_put+0x16f/0x270 lib/kobject.c:737
hci_conn_del_sysfs+0x1e2/0x380 net/bluetooth/hci_sysfs.c:62
hci_conn_cleanup net/bluetooth/hci_conn.c:173 [inline]
hci_conn_del+0x1f91/0x37a0 net/bluetooth/hci_conn.c:1211
hci_conn_failed+0x662/0x820 net/bluetooth/hci_conn.c:1314
hci_conn_complete_evt+0xf2b/0x3330 net/bluetooth/hci_event.c:3215
hci_event_func net/bluetooth/hci_event.c:7569 [inline]
hci_event_packet+0x17cd/0x2da0 net/bluetooth/hci_event.c:7623
hci_rx_work+0x982/0x2210 net/bluetooth/hci_core.c:4071
process_one_work kernel/workqueue.c:3236 [inline]
process_scheduled_works+0x7a8/0x1030 kernel/workqueue.c:3319
worker_thread+0xb97/0x11d0 kernel/workqueue.c:3400
kthread+0x3d4/0x800 kernel/kthread.c:463
ret_from_fork+0x13b/0x1e0 arch/x86/kernel/process.c:148
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
The buggy address belongs to the object at ffff8881199b0000
which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 56 bytes inside of
freed 4096-byte region [ffff8881199b0000, ffff8881199b1000)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1199b0
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
anon flags: 0x200000000000040(head|node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000040 ffff888100043040 0000000000000000 dead000000000001
raw: 0000000000000000 0000000000040004 00000000f5000000 0000000000000000
head: 0200000000000040 ffff888100043040 0000000000000000 dead000000000001
head: 0000000000000000 0000000000040004 00000000f5000000 0000000000000000
head: 0200000000000003 ffffea0004666c01 00000000ffffffff 00000000ffffffff
head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff8881199aff00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff8881199aff80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8881199b0000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8881199b0080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8881199b0100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Thanks for taking a look.
Best regards,
CenZhang
Powered by blists - more mailing lists