[bluetooth?] KASAN: slab-use-after-free Read in __lock_sock

22 views
Skip to first unread message

Edward Adam Davis

unread,
Nov 22, 2023, 8:14:39 PM11/22/23
to syzbot+60bfed...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test uaf in __lock_sock

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git 8de1e7afcc1c

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index c736186aba26..692727831dde 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -443,6 +443,7 @@ static void __sco_sock_close(struct sock *sk)
sco_conn_lock(sco_pi(sk)->conn);
hci_conn_drop(sco_pi(sk)->conn->hcon);
sco_pi(sk)->conn->hcon = NULL;
+ sco_pi(sk)->conn->sk = NULL;
sco_conn_unlock(sco_pi(sk)->conn);
} else
sco_chan_del(sk, ECONNRESET);

syzbot

unread,
Nov 22, 2023, 8:35:08 PM11/22/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Write in hci_conn_drop

==================================================================
BUG: KASAN: slab-use-after-free in instrument_atomic_read_write include/linux/instrumented.h:96 [inline]
BUG: KASAN: slab-use-after-free in atomic_dec_and_test include/linux/atomic/atomic-instrumented.h:1375 [inline]
BUG: KASAN: slab-use-after-free in hci_conn_drop+0x34/0x2bc include/net/bluetooth/hci_core.h:1523
Write of size 4 at addr ffff0000d750a010 by task syz-executor.0/6829

CPU: 0 PID: 6829 Comm: syz-executor.0 Not tainted 6.6.0-rc7-syzkaller-00089-g8de1e7afcc1c-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
Call trace:
dump_backtrace+0x1b8/0x1e4 arch/arm64/kernel/stacktrace.c:233
show_stack+0x2c/0x44 arch/arm64/kernel/stacktrace.c:240
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xd0/0x124 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:364 [inline]
print_report+0x174/0x514 mm/kasan/report.c:475
kasan_report+0xd8/0x138 mm/kasan/report.c:588
kasan_check_range+0x254/0x294 mm/kasan/generic.c:187
__kasan_check_write+0x20/0x30 mm/kasan/shadow.c:37
instrument_atomic_read_write include/linux/instrumented.h:96 [inline]
atomic_dec_and_test include/linux/atomic/atomic-instrumented.h:1375 [inline]
hci_conn_drop+0x34/0x2bc include/net/bluetooth/hci_core.h:1523
__sco_sock_close+0x3a8/0x7d0 net/bluetooth/sco.c:444
sco_sock_close net/bluetooth/sco.c:470 [inline]
sco_sock_release+0xb4/0x2c0 net/bluetooth/sco.c:1247
__sock_release net/socket.c:659 [inline]
sock_close+0xa4/0x1e8 net/socket.c:1419
__fput+0x324/0x7f8 fs/file_table.c:384
__fput_sync+0x60/0x9c fs/file_table.c:465
__do_sys_close fs/open.c:1572 [inline]
__se_sys_close fs/open.c:1557 [inline]
__arm64_sys_close+0x150/0x1e0 fs/open.c:1557
__invoke_syscall arch/arm64/kernel/syscall.c:37 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155
el0_svc+0x54/0x158 arch/arm64/kernel/entry-common.c:678
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595

Allocated by task 6830:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4c/0x7c mm/kasan/common.c:52
kasan_save_alloc_info+0x24/0x30 mm/kasan/generic.c:511
____kasan_kmalloc mm/kasan/common.c:374 [inline]
__kasan_kmalloc+0xac/0xc4 mm/kasan/common.c:383
kasan_kmalloc include/linux/kasan.h:198 [inline]
kmalloc_trace+0x70/0x88 mm/slab_common.c:1122
kmalloc include/linux/slab.h:599 [inline]
kzalloc include/linux/slab.h:720 [inline]
hci_conn_add+0xcc/0x1210 net/bluetooth/hci_conn.c:957
hci_connect_sco+0x94/0x2bc net/bluetooth/hci_conn.c:1701
sco_connect net/bluetooth/sco.c:266 [inline]
sco_sock_connect+0x278/0x840 net/bluetooth/sco.c:592
__sys_connect_file net/socket.c:2050 [inline]
__sys_connect+0x268/0x290 net/socket.c:2067
__do_sys_connect net/socket.c:2077 [inline]
__se_sys_connect net/socket.c:2074 [inline]
__arm64_sys_connect+0x7c/0x94 net/socket.c:2074
__invoke_syscall arch/arm64/kernel/syscall.c:37 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155
el0_svc+0x54/0x158 arch/arm64/kernel/entry-common.c:678
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595

Freed by task 5661:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4c/0x7c mm/kasan/common.c:52
kasan_save_free_info+0x38/0x5c mm/kasan/generic.c:522
____kasan_slab_free+0x144/0x1c0 mm/kasan/common.c:236
__kasan_slab_free+0x18/0x28 mm/kasan/common.c:244
kasan_slab_free include/linux/kasan.h:164 [inline]
slab_free_hook mm/slub.c:1800 [inline]
slab_free_freelist_hook mm/slub.c:1826 [inline]
slab_free mm/slub.c:3809 [inline]
__kmem_cache_free+0x2ac/0x480 mm/slub.c:3822
kfree+0xb8/0x19c mm/slab_common.c:1075
bt_link_release+0x20/0x30 net/bluetooth/hci_sysfs.c:16
device_release+0x8c/0x1ac
kobject_cleanup lib/kobject.c:682 [inline]
kobject_release lib/kobject.c:716 [inline]
kref_put include/linux/kref.h:65 [inline]
kobject_put+0x1c4/0x3c4 lib/kobject.c:733
put_device+0x28/0x40 drivers/base/core.c:3732
hci_conn_put include/net/bluetooth/hci_core.h:1506 [inline]
hci_conn_cleanup net/bluetooth/hci_conn.c:178 [inline]
hci_conn_del+0x78c/0xabc net/bluetooth/hci_conn.c:1156
hci_conn_failed+0x204/0x2c0 net/bluetooth/hci_conn.c:1252
hci_abort_conn_sync+0x688/0xe38 net/bluetooth/hci_sync.c:5428
abort_conn_sync+0x5c/0x8c net/bluetooth/hci_conn.c:2910
hci_cmd_sync_work+0x1cc/0x34c net/bluetooth/hci_sync.c:306
process_one_work+0x694/0x1204 kernel/workqueue.c:2630
process_scheduled_works kernel/workqueue.c:2703 [inline]
worker_thread+0x938/0xef4 kernel/workqueue.c:2784
kthread+0x288/0x310 kernel/kthread.c:388
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:857

The buggy address belongs to the object at ffff0000d750a000
which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 16 bytes inside of
freed 4096-byte region [ffff0000d750a000, ffff0000d750b000)

The buggy address belongs to the physical page:
page:00000000d7ff5a94 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x117508
head:00000000d7ff5a94 order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x5ffc00000000840(slab|head|node=0|zone=2|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 05ffc00000000840 ffff0000c0002140 dead000000000122 0000000000000000
raw: 0000000000000000 0000000080040004 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff0000d7509f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff0000d7509f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff0000d750a000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff0000d750a080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff0000d750a100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
------------[ cut here ]------------
ODEBUG: assert_init not available (active state 0) object: 000000003c9b8964 object type: timer_list hint: hci_conn_timeout+0x0/0x1e8 net/bluetooth/hci_conn.c:928
WARNING: CPU: 0 PID: 6829 at lib/debugobjects.c:517 debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
Modules linked in:
CPU: 0 PID: 6829 Comm: syz-executor.0 Tainted: G B 6.6.0-rc7-syzkaller-00089-g8de1e7afcc1c-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
pstate: 604000c5 (nZCv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
lr : debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
sp : ffff800096e67790
x29: ffff800096e67790 x28: dfff800000000000 x27: ffff700012dccf00
x26: dfff800000000000 x25: dfff800000000000 x24: ffff0000d750a390
x23: ffff80008ad651a0 x22: ffff800089881d98 x21: ffff80008a89c360
x20: 0000000000000000 x19: ffff80008ad64cc0 x18: 0000000000000000
x17: 0000000000000000 x16: ffff80008a71b23c x15: 0000000000000001
x14: 1ffff00012dcce44 x13: 0000000000000000 x12: 0000000000000000
x11: 0000000000000001 x10: 0000000000000000 x9 : 49493c6eef4d4300
x8 : 49493c6eef4d4300 x7 : 0000000000000001 x6 : 0000000000000001
x5 : ffff800096e67078 x4 : ffff80008e4210a0 x3 : ffff800082b180c4
x2 : 0000000000000001 x1 : 0000000100000001 x0 : 0000000000000000
Call trace:
debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
debug_object_assert_init+0x318/0x3c8 lib/debugobjects.c:941
debug_timer_assert_init kernel/time/timer.c:792 [inline]
debug_assert_init kernel/time/timer.c:837 [inline]
__timer_delete+0xac/0x2f8 kernel/time/timer.c:1321
timer_delete+0x24/0x34 kernel/time/timer.c:1361
del_timer include/linux/timer.h:213 [inline]
try_to_grab_pending+0x8c/0x618 kernel/workqueue.c:1564
__cancel_work+0xb0/0x2a8 kernel/workqueue.c:3582
cancel_delayed_work+0x24/0x38 kernel/workqueue.c:3620
hci_conn_drop+0x150/0x2bc include/net/bluetooth/hci_core.h:1548
__sco_sock_close+0x3a8/0x7d0 net/bluetooth/sco.c:444
sco_sock_close net/bluetooth/sco.c:470 [inline]
sco_sock_release+0xb4/0x2c0 net/bluetooth/sco.c:1247
__sock_release net/socket.c:659 [inline]
sock_close+0xa4/0x1e8 net/socket.c:1419
__fput+0x324/0x7f8 fs/file_table.c:384
__fput_sync+0x60/0x9c fs/file_table.c:465
__do_sys_close fs/open.c:1572 [inline]
__se_sys_close fs/open.c:1557 [inline]
__arm64_sys_close+0x150/0x1e0 fs/open.c:1557
__invoke_syscall arch/arm64/kernel/syscall.c:37 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155
el0_svc+0x54/0x158 arch/arm64/kernel/entry-common.c:678
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595
irq event stamp: 14487
hardirqs last enabled at (14487): [<ffff80008a719090>] __exit_to_kernel_mode arch/arm64/kernel/entry-common.c:84 [inline]
hardirqs last enabled at (14487): [<ffff80008a719090>] exit_to_kernel_mode+0xdc/0x10c arch/arm64/kernel/entry-common.c:94
hardirqs last disabled at (14486): [<ffff800080021724>] __do_softirq+0x950/0xd54 kernel/softirq.c:569
softirqs last enabled at (14306): [<ffff8000888c272c>] spin_unlock_bh include/linux/spinlock.h:396 [inline]
softirqs last enabled at (14306): [<ffff8000888c272c>] lock_sock_nested+0xcc/0x11c net/core/sock.c:3512
softirqs last disabled at (14304): [<ffff8000888c26d4>] spin_lock_bh include/linux/spinlock.h:356 [inline]
softirqs last disabled at (14304): [<ffff8000888c26d4>] lock_sock_nested+0x74/0x11c net/core/sock.c:3508
---[ end trace 0000000000000000 ]---
------------[ cut here ]------------
WARNING: CPU: 0 PID: 6829 at kernel/workqueue.c:1939 __queue_delayed_work kernel/workqueue.c:1939 [inline]
WARNING: CPU: 0 PID: 6829 at kernel/workqueue.c:1939 queue_delayed_work_on+0x214/0x2e4 kernel/workqueue.c:1986
Modules linked in:
CPU: 0 PID: 6829 Comm: syz-executor.0 Tainted: G B W 6.6.0-rc7-syzkaller-00089-g8de1e7afcc1c-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
pstate: 804000c5 (Nzcv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : __queue_delayed_work kernel/workqueue.c:1939 [inline]
pc : queue_delayed_work_on+0x214/0x2e4 kernel/workqueue.c:1986
lr : __queue_delayed_work kernel/workqueue.c:1939 [inline]
lr : queue_delayed_work_on+0x214/0x2e4 kernel/workqueue.c:1986
sp : ffff800096e67af0
x29: ffff800096e67af0 x28: 1fffe000193ba0c0 x27: dfff800000000000
x26: 0000000000000000 x25: ffff0000d750a3a8 x24: ffff0000c864c000
x23: 0000000000000000 x22: ffff0000d750a348 x21: 0000000000000008
x20: 0000000000000000 x19: 0000000000000000 x18: 0000000000000000
x17: 0000000000000000 x16: ffff80008a71b23c x15: ffff60001aea1469
x14: 1fffe0001aea1469 x13: 00000000000000fb x12: ffffffffffffffff
x11: 0000000000000001 x10: 0000000000000000 x9 : 0000000000000000
x8 : ffff0000d1d29bc0 x7 : 0000000000000000 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff800080221e68
x2 : 0000000000000000 x1 : 0000000000000008 x0 : 0000000000000000
Call trace:
__queue_delayed_work kernel/workqueue.c:1939 [inline]
queue_delayed_work_on+0x214/0x2e4 kernel/workqueue.c:1986
queue_delayed_work include/linux/workqueue.h:569 [inline]
hci_conn_drop+0x198/0x2bc include/net/bluetooth/hci_core.h:1549
__sco_sock_close+0x3a8/0x7d0 net/bluetooth/sco.c:444
sco_sock_close net/bluetooth/sco.c:470 [inline]
sco_sock_release+0xb4/0x2c0 net/bluetooth/sco.c:1247
__sock_release net/socket.c:659 [inline]
sock_close+0xa4/0x1e8 net/socket.c:1419
__fput+0x324/0x7f8 fs/file_table.c:384
__fput_sync+0x60/0x9c fs/file_table.c:465
__do_sys_close fs/open.c:1572 [inline]
__se_sys_close fs/open.c:1557 [inline]
__arm64_sys_close+0x150/0x1e0 fs/open.c:1557
__invoke_syscall arch/arm64/kernel/syscall.c:37 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155
el0_svc+0x54/0x158 arch/arm64/kernel/entry-common.c:678
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595
irq event stamp: 14487
hardirqs last enabled at (14487): [<ffff80008a719090>] __exit_to_kernel_mode arch/arm64/kernel/entry-common.c:84 [inline]
hardirqs last enabled at (14487): [<ffff80008a719090>] exit_to_kernel_mode+0xdc/0x10c arch/arm64/kernel/entry-common.c:94
hardirqs last disabled at (14486): [<ffff800080021724>] __do_softirq+0x950/0xd54 kernel/softirq.c:569
softirqs last enabled at (14306): [<ffff8000888c272c>] spin_unlock_bh include/linux/spinlock.h:396 [inline]
softirqs last enabled at (14306): [<ffff8000888c272c>] lock_sock_nested+0xcc/0x11c net/core/sock.c:3512
softirqs last disabled at (14304): [<ffff8000888c26d4>] spin_lock_bh include/linux/spinlock.h:356 [inline]
softirqs last disabled at (14304): [<ffff8000888c26d4>] lock_sock_nested+0x74/0x11c net/core/sock.c:3508
---[ end trace 0000000000000000 ]---
------------[ cut here ]------------
ODEBUG: activate not available (active state 0) object: 00000000009b9630 object type: work_struct hint: hci_conn_timeout+0x0/0x1e8 net/bluetooth/hci_conn.c:928
WARNING: CPU: 0 PID: 6829 at lib/debugobjects.c:517 debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
Modules linked in:
CPU: 0 PID: 6829 Comm: syz-executor.0 Tainted: G B W 6.6.0-rc7-syzkaller-00089-g8de1e7afcc1c-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
pstate: 604000c5 (nZCv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
lr : debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
sp : ffff800096e67870
x29: ffff800096e67870 x28: dfff800000000000 x27: ffff700012dccf1c
x26: ffff0000c9d81168 x25: dfff800000000000 x24: ffff0000d750a348
x23: ffff80008ad651a0 x22: ffff800089881d98 x21: ffff80008a8710a0
x20: 0000000000000000 x19: ffff80008ad64c40 x18: 0000000000000000
x17: 0000000000000000 x16: ffff80008a71b23c x15: 0000000000000001
x14: 1fffe0003682f032 x13: 0000000000000000 x12: 0000000000000000
x11: 0000000000000002 x10: 0000000000000000 x9 : 49493c6eef4d4300
x8 : 49493c6eef4d4300 x7 : 0000000000000001 x6 : 0000000000000001
x5 : ffff800096e67158 x4 : ffff80008e4210a0 x3 : ffff8000805a359c
x2 : 0000000000000001 x1 : 0000000000000002 x0 : 0000000000000000
Call trace:
debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
debug_object_activate+0x600/0x7e0 lib/debugobjects.c:760
debug_work_activate kernel/workqueue.c:572 [inline]
insert_work+0x4c/0x2d4 kernel/workqueue.c:1644
__queue_work+0xcf4/0x1338 kernel/workqueue.c:1799
__queue_delayed_work kernel/workqueue.c:1950 [inline]
queue_delayed_work_on+0x1f4/0x2e4 kernel/workqueue.c:1986
queue_delayed_work include/linux/workqueue.h:569 [inline]
hci_conn_drop+0x198/0x2bc include/net/bluetooth/hci_core.h:1549
__sco_sock_close+0x3a8/0x7d0 net/bluetooth/sco.c:444
sco_sock_close net/bluetooth/sco.c:470 [inline]
sco_sock_release+0xb4/0x2c0 net/bluetooth/sco.c:1247
__sock_release net/socket.c:659 [inline]
sock_close+0xa4/0x1e8 net/socket.c:1419
__fput+0x324/0x7f8 fs/file_table.c:384
__fput_sync+0x60/0x9c fs/file_table.c:465
__do_sys_close fs/open.c:1572 [inline]
__se_sys_close fs/open.c:1557 [inline]
__arm64_sys_close+0x150/0x1e0 fs/open.c:1557
__invoke_syscall arch/arm64/kernel/syscall.c:37 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155
el0_svc+0x54/0x158 arch/arm64/kernel/entry-common.c:678
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595
irq event stamp: 14487
hardirqs last enabled at (14487): [<ffff80008a719090>] __exit_to_kernel_mode arch/arm64/kernel/entry-common.c:84 [inline]
hardirqs last enabled at (14487): [<ffff80008a719090>] exit_to_kernel_mode+0xdc/0x10c arch/arm64/kernel/entry-common.c:94
hardirqs last disabled at (14486): [<ffff800080021724>] __do_softirq+0x950/0xd54 kernel/softirq.c:569
softirqs last enabled at (14306): [<ffff8000888c272c>] spin_unlock_bh include/linux/spinlock.h:396 [inline]
softirqs last enabled at (14306): [<ffff8000888c272c>] lock_sock_nested+0xcc/0x11c net/core/sock.c:3512
softirqs last disabled at (14304): [<ffff8000888c26d4>] spin_lock_bh include/linux/spinlock.h:356 [inline]
softirqs last disabled at (14304): [<ffff8000888c26d4>] lock_sock_nested+0x74/0x11c net/core/sock.c:3508
---[ end trace 0000000000000000 ]---


Tested on:

commit: 8de1e7af Merge branch 'for-next/core' into for-kernelci
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=145cde9f680000
kernel config: https://syzkaller.appspot.com/x/.config?x=3e6feaeda5dcbc27
dashboard link: https://syzkaller.appspot.com/bug?extid=60bfed6b415fbd1fbb87
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
userspace arch: arm64
patch: https://syzkaller.appspot.com/x/patch.diff?x=14e9d8d8e80000

Edward Adam Davis

unread,
Nov 22, 2023, 9:06:32 PM11/22/23
to syzbot+60bfed...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test uaf in __lock_sock

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git 8de1e7afcc1c

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index c736186aba26..82e50c215386 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -270,6 +270,7 @@ static int sco_connect(struct sock *sk)
goto unlock;
}

+ hci_conn_get(hcon);
conn = sco_conn_add(hcon);
if (!conn) {
hci_conn_drop(hcon);
@@ -438,12 +439,13 @@ static void __sco_sock_close(struct sock *sk)
case BT_CONNECTED:
case BT_CONFIG:
if (sco_pi(sk)->conn->hcon) {
+ struct hci_conn *hcon = sco_pi(sk)->conn->hcon;
sk->sk_state = BT_DISCONN;
sco_sock_set_timer(sk, SCO_DISCONN_TIMEOUT);
sco_conn_lock(sco_pi(sk)->conn);
- hci_conn_drop(sco_pi(sk)->conn->hcon);
sco_pi(sk)->conn->hcon = NULL;
sco_conn_unlock(sco_pi(sk)->conn);
+ hci_conn_put(hcon);
} else
sco_chan_del(sk, ECONNRESET);
break;

syzbot

unread,
Nov 22, 2023, 10:06:07 PM11/22/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in __sco_sock_close

==================================================================
BUG: KASAN: slab-use-after-free in sco_chan_del net/bluetooth/sco.c:170 [inline]
BUG: KASAN: slab-use-after-free in __sco_sock_close+0x274/0x788 net/bluetooth/sco.c:456
Read of size 8 at addr ffff0000c7299400 by task syz-executor661/9434

CPU: 1 PID: 9434 Comm: syz-executor661 Not tainted 6.6.0-rc7-syzkaller-00089-g8de1e7afcc1c-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
Call trace:
dump_backtrace+0x1b8/0x1e4 arch/arm64/kernel/stacktrace.c:233
show_stack+0x2c/0x44 arch/arm64/kernel/stacktrace.c:240
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xd0/0x124 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:364 [inline]
print_report+0x174/0x514 mm/kasan/report.c:475
kasan_report+0xd8/0x138 mm/kasan/report.c:588
__asan_report_load8_noabort+0x20/0x2c mm/kasan/report_generic.c:381
sco_chan_del net/bluetooth/sco.c:170 [inline]
__sco_sock_close+0x274/0x788 net/bluetooth/sco.c:456
sco_sock_close net/bluetooth/sco.c:471 [inline]
sco_sock_release+0xb4/0x2c0 net/bluetooth/sco.c:1248
__sock_release net/socket.c:659 [inline]
sock_close+0xa4/0x1e8 net/socket.c:1419
__fput+0x324/0x7f8 fs/file_table.c:384
____fput+0x20/0x30 fs/file_table.c:412
task_work_run+0x230/0x2e0 kernel/task_work.c:180
get_signal+0x13f4/0x15ec kernel/signal.c:2668
do_signal arch/arm64/kernel/signal.c:1249 [inline]
do_notify_resume+0x3bc/0x393c arch/arm64/kernel/signal.c:1302
exit_to_user_mode_prepare arch/arm64/kernel/entry-common.c:137 [inline]
exit_to_user_mode arch/arm64/kernel/entry-common.c:144 [inline]
el0_svc+0x9c/0x158 arch/arm64/kernel/entry-common.c:679
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595

Allocated by task 9431:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4c/0x7c mm/kasan/common.c:52
kasan_save_alloc_info+0x24/0x30 mm/kasan/generic.c:511
____kasan_kmalloc mm/kasan/common.c:374 [inline]
__kasan_kmalloc+0xac/0xc4 mm/kasan/common.c:383
kasan_kmalloc include/linux/kasan.h:198 [inline]
kmalloc_trace+0x70/0x88 mm/slab_common.c:1122
kmalloc include/linux/slab.h:599 [inline]
kzalloc include/linux/slab.h:720 [inline]
sco_conn_add+0xc4/0x2cc net/bluetooth/sco.c:134
sco_connect net/bluetooth/sco.c:274 [inline]
sco_sock_connect+0x2a0/0x848 net/bluetooth/sco.c:593
__sys_connect_file net/socket.c:2050 [inline]
__sys_connect+0x268/0x290 net/socket.c:2067
__do_sys_connect net/socket.c:2077 [inline]
__se_sys_connect net/socket.c:2074 [inline]
__arm64_sys_connect+0x7c/0x94 net/socket.c:2074
__invoke_syscall arch/arm64/kernel/syscall.c:37 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155
el0_svc+0x54/0x158 arch/arm64/kernel/entry-common.c:678
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595

Freed by task 6094:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4c/0x7c mm/kasan/common.c:52
kasan_save_free_info+0x38/0x5c mm/kasan/generic.c:522
____kasan_slab_free+0x144/0x1c0 mm/kasan/common.c:236
__kasan_slab_free+0x18/0x28 mm/kasan/common.c:244
kasan_slab_free include/linux/kasan.h:164 [inline]
slab_free_hook mm/slub.c:1800 [inline]
slab_free_freelist_hook mm/slub.c:1826 [inline]
slab_free mm/slub.c:3809 [inline]
__kmem_cache_free+0x2ac/0x480 mm/slub.c:3822
kfree+0xb8/0x19c mm/slab_common.c:1075
sco_conn_del+0x3b4/0x498 net/bluetooth/sco.c:210
sco_connect_cfm+0xf0/0x948 net/bluetooth/sco.c:1363
hci_connect_cfm include/net/bluetooth/hci_core.h:1935 [inline]
hci_conn_failed+0x17c/0x2c0 net/bluetooth/hci_conn.c:1251
hci_abort_conn_sync+0x688/0xe38 net/bluetooth/hci_sync.c:5428
abort_conn_sync+0x5c/0x8c net/bluetooth/hci_conn.c:2910
hci_cmd_sync_work+0x1cc/0x34c net/bluetooth/hci_sync.c:306
process_one_work+0x694/0x1204 kernel/workqueue.c:2630
process_scheduled_works kernel/workqueue.c:2703 [inline]
worker_thread+0x938/0xef4 kernel/workqueue.c:2784
kthread+0x288/0x310 kernel/kthread.c:388
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:857

Last potentially related work creation:
kasan_save_stack+0x40/0x6c mm/kasan/common.c:45
__kasan_record_aux_stack+0xcc/0xe8 mm/kasan/generic.c:492
kasan_record_aux_stack_noalloc+0x14/0x20 mm/kasan/generic.c:502
kvfree_call_rcu+0xac/0x674 kernel/rcu/tree.c:3372
drop_sysctl_table+0x2c8/0x410 fs/proc/proc_sysctl.c:1508
drop_sysctl_table+0x2d8/0x410 fs/proc/proc_sysctl.c:1511
unregister_sysctl_table+0x48/0x68 fs/proc/proc_sysctl.c:1529
unregister_net_sysctl_table+0x20/0x30 net/sysctl_net.c:185
mpls_dev_sysctl_unregister+0x88/0xc0 net/mpls/af_mpls.c:1447
mpls_dev_notify+0x448/0x654 net/mpls/af_mpls.c:1659
notifier_call_chain+0x1a4/0x510 kernel/notifier.c:93
raw_notifier_call_chain+0x3c/0x50 kernel/notifier.c:461
call_netdevice_notifiers_info net/core/dev.c:1995 [inline]
call_netdevice_notifiers_extack net/core/dev.c:2033 [inline]
call_netdevice_notifiers net/core/dev.c:2047 [inline]
unregister_netdevice_many_notify+0xd44/0x17a8 net/core/dev.c:10967
unregister_netdevice_many net/core/dev.c:11023 [inline]
default_device_exit_batch+0x6c8/0x744 net/core/dev.c:11492
ops_exit_list net/core/net_namespace.c:175 [inline]
cleanup_net+0x5dc/0x8d0 net/core/net_namespace.c:614
process_one_work+0x694/0x1204 kernel/workqueue.c:2630
process_scheduled_works kernel/workqueue.c:2703 [inline]
worker_thread+0x938/0xef4 kernel/workqueue.c:2784
kthread+0x288/0x310 kernel/kthread.c:388
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:857

The buggy address belongs to the object at ffff0000c7299400
which belongs to the cache kmalloc-256 of size 256
The buggy address is located 0 bytes inside of
freed 256-byte region [ffff0000c7299400, ffff0000c7299500)

The buggy address belongs to the physical page:
page:0000000073a3d90c refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x107298
head:0000000073a3d90c order:1 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x5ffc00000000840(slab|head|node=0|zone=2|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 05ffc00000000840 ffff0000c0001b40 dead000000000100 dead000000000122
raw: 0000000000000000 0000000080100010 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff0000c7299300: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff0000c7299380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff0000c7299400: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff0000c7299480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff0000c7299500: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================


Tested on:

commit: 8de1e7af Merge branch 'for-next/core' into for-kernelci
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=10e32aa4e80000
kernel config: https://syzkaller.appspot.com/x/.config?x=3e6feaeda5dcbc27
dashboard link: https://syzkaller.appspot.com/bug?extid=60bfed6b415fbd1fbb87
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
userspace arch: arm64
patch: https://syzkaller.appspot.com/x/patch.diff?x=12d17aa4e80000

Edward Adam Davis

unread,
Nov 22, 2023, 10:18:01 PM11/22/23
to syzbot+60bfed...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test uaf in __lock_sock

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git 8de1e7afcc1c

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index c736186aba26..3d76352d3e79 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -270,6 +270,7 @@ static int sco_connect(struct sock *sk)
goto unlock;
}

+ hci_conn_get(hcon);
conn = sco_conn_add(hcon);
if (!conn) {
hci_conn_drop(hcon);
@@ -300,7 +301,6 @@ static int sco_connect(struct sock *sk)

unlock:
hci_dev_unlock(hdev);
- hci_dev_put(hdev);
return err;
}

@@ -438,12 +438,13 @@ static void __sco_sock_close(struct sock *sk)

syzbot

unread,
Nov 23, 2023, 7:20:56 AM11/23/23
to johan....@gmail.com, linux-b...@vger.kernel.org, linux-...@vger.kernel.org, luiz....@gmail.com, mar...@holtmann.org, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 8de1e7afcc1c Merge branch 'for-next/core' into for-kernelci
git tree: git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci
console output: https://syzkaller.appspot.com/x/log.txt?x=1774144f680000
kernel config: https://syzkaller.appspot.com/x/.config?x=3e6feaeda5dcbc27
dashboard link: https://syzkaller.appspot.com/bug?extid=60bfed6b415fbd1fbb87
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
userspace arch: arm64
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=143ee4a0e80000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14c28ca0e80000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/0f00907f9764/disk-8de1e7af.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/0502fe78c60d/vmlinux-8de1e7af.xz
kernel image: https://storage.googleapis.com/syzbot-assets/192135168cc0/Image-8de1e7af.gz.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+60bfed...@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: slab-use-after-free in __lock_acquire+0x114/0x75e8 kernel/locking/lockdep.c:5004
Read of size 8 at addr ffff0000d553e0b0 by task kworker/u5:3/6271

CPU: 1 PID: 6271 Comm: kworker/u5:3 Not tainted 6.6.0-rc7-syzkaller-g8de1e7afcc1c #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
Workqueue: hci0 hci_cmd_sync_work
Call trace:
dump_backtrace+0x1b8/0x1e4 arch/arm64/kernel/stacktrace.c:233
show_stack+0x2c/0x44 arch/arm64/kernel/stacktrace.c:240
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xd0/0x124 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:364 [inline]
print_report+0x174/0x514 mm/kasan/report.c:475
kasan_report+0xd8/0x138 mm/kasan/report.c:588
__asan_report_load8_noabort+0x20/0x2c mm/kasan/report_generic.c:381
__lock_acquire+0x114/0x75e8 kernel/locking/lockdep.c:5004
lock_acquire+0x23c/0x71c kernel/locking/lockdep.c:5753
__raw_spin_lock_bh include/linux/spinlock_api_smp.h:126 [inline]
_raw_spin_lock_bh+0x48/0x60 kernel/locking/spinlock.c:178
spin_lock_bh include/linux/spinlock.h:356 [inline]
__lock_sock+0x170/0x2d4 net/core/sock.c:2960
lock_sock_nested+0xa4/0x11c net/core/sock.c:3510
lock_sock include/net/sock.h:1720 [inline]
sco_conn_ready net/bluetooth/sco.c:1268 [inline]
sco_connect_cfm+0x140/0x948 net/bluetooth/sco.c:1359
hci_connect_cfm include/net/bluetooth/hci_core.h:1935 [inline]
hci_conn_failed+0x17c/0x2c0 net/bluetooth/hci_conn.c:1251
hci_abort_conn_sync+0x688/0xe38 net/bluetooth/hci_sync.c:5428
abort_conn_sync+0x5c/0x8c net/bluetooth/hci_conn.c:2910
hci_cmd_sync_work+0x1cc/0x34c net/bluetooth/hci_sync.c:306
process_one_work+0x694/0x1204 kernel/workqueue.c:2630
process_scheduled_works kernel/workqueue.c:2703 [inline]
worker_thread+0x938/0xef4 kernel/workqueue.c:2784
kthread+0x288/0x310 kernel/kthread.c:388
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:857

Allocated by task 8151:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4c/0x7c mm/kasan/common.c:52
kasan_save_alloc_info+0x24/0x30 mm/kasan/generic.c:511
____kasan_kmalloc mm/kasan/common.c:374 [inline]
__kasan_kmalloc+0xac/0xc4 mm/kasan/common.c:383
kasan_kmalloc include/linux/kasan.h:198 [inline]
__do_kmalloc_node mm/slab_common.c:1026 [inline]
__kmalloc+0xcc/0x1b8 mm/slab_common.c:1039
kmalloc include/linux/slab.h:603 [inline]
sk_prot_alloc+0xc4/0x1f0 net/core/sock.c:2090
sk_alloc+0x44/0x3f4 net/core/sock.c:2143
bt_sock_alloc+0x4c/0x32c net/bluetooth/af_bluetooth.c:148
sco_sock_alloc net/bluetooth/sco.c:495 [inline]
sco_sock_create+0xbc/0x31c net/bluetooth/sco.c:526
bt_sock_create+0x14c/0x248 net/bluetooth/af_bluetooth.c:132
__sock_create+0x43c/0x884 net/socket.c:1569
sock_create net/socket.c:1620 [inline]
__sys_socket_create net/socket.c:1657 [inline]
__sys_socket+0x134/0x340 net/socket.c:1708
__do_sys_socket net/socket.c:1722 [inline]
__se_sys_socket net/socket.c:1720 [inline]
__arm64_sys_socket+0x7c/0x94 net/socket.c:1720
__invoke_syscall arch/arm64/kernel/syscall.c:37 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155
el0_svc+0x54/0x158 arch/arm64/kernel/entry-common.c:678
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595

Freed by task 8151:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4c/0x7c mm/kasan/common.c:52
kasan_save_free_info+0x38/0x5c mm/kasan/generic.c:522
____kasan_slab_free+0x144/0x1c0 mm/kasan/common.c:236
__kasan_slab_free+0x18/0x28 mm/kasan/common.c:244
kasan_slab_free include/linux/kasan.h:164 [inline]
slab_free_hook mm/slub.c:1800 [inline]
slab_free_freelist_hook mm/slub.c:1826 [inline]
slab_free mm/slub.c:3809 [inline]
__kmem_cache_free+0x2ac/0x480 mm/slub.c:3822
kfree+0xb8/0x19c mm/slab_common.c:1075
sk_prot_free net/core/sock.c:2126 [inline]
__sk_destruct+0x4c0/0x770 net/core/sock.c:2218
sk_destruct net/core/sock.c:2233 [inline]
__sk_free+0x37c/0x4e8 net/core/sock.c:2244
sk_free+0x60/0xc8 net/core/sock.c:2255
sock_put include/net/sock.h:1989 [inline]
sco_sock_kill+0xfc/0x1b4 net/bluetooth/sco.c:426
sco_sock_release+0x1fc/0x2c0 net/bluetooth/sco.c:1256
__sock_release net/socket.c:659 [inline]
sock_close+0xa4/0x1e8 net/socket.c:1419
__fput+0x324/0x7f8 fs/file_table.c:384
____fput+0x20/0x30 fs/file_table.c:412
task_work_run+0x230/0x2e0 kernel/task_work.c:180
get_signal+0x13f4/0x15ec kernel/signal.c:2668
do_signal arch/arm64/kernel/signal.c:1249 [inline]
do_notify_resume+0x3bc/0x393c arch/arm64/kernel/signal.c:1302
exit_to_user_mode_prepare arch/arm64/kernel/entry-common.c:137 [inline]
exit_to_user_mode arch/arm64/kernel/entry-common.c:144 [inline]
el0_svc+0x9c/0x158 arch/arm64/kernel/entry-common.c:679
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595

The buggy address belongs to the object at ffff0000d553e000
which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 176 bytes inside of
freed 2048-byte region [ffff0000d553e000, ffff0000d553e800)

The buggy address belongs to the physical page:
page:0000000014f21d98 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x115538
head:0000000014f21d98 order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x5ffc00000000840(slab|head|node=0|zone=2|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 05ffc00000000840 ffff0000c0002000 dead000000000122 0000000000000000
raw: 0000000000000000 0000000080080008 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff0000d553df80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff0000d553e000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff0000d553e080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff0000d553e100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff0000d553e180: 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 syzk...@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 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.

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

syzbot

unread,
Nov 23, 2023, 9:27:05 AM11/23/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+60bfed...@syzkaller.appspotmail.com

Tested on:

commit: 8de1e7af Merge branch 'for-next/core' into for-kernelci
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=128127f0e80000
kernel config: https://syzkaller.appspot.com/x/.config?x=3e6feaeda5dcbc27
dashboard link: https://syzkaller.appspot.com/bug?extid=60bfed6b415fbd1fbb87
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
userspace arch: arm64
patch: https://syzkaller.appspot.com/x/patch.diff?x=106f8c4f680000

Note: testing is done by a robot and is best-effort only.

Edward Adam Davis

unread,
Nov 24, 2023, 6:24:19 AM11/24/23
to syzbot+60bfed...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test uaf in __lock_sock

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git 8de1e7afcc1c

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index c736186aba26..062ab9926146 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -270,6 +270,7 @@ static int sco_connect(struct sock *sk)
goto unlock;
}

+ hci_conn_get(hcon);
conn = sco_conn_add(hcon);
if (!conn) {
hci_conn_drop(hcon);
@@ -300,7 +301,8 @@ static int sco_connect(struct sock *sk)

unlock:
hci_dev_unlock(hdev);
- hci_dev_put(hdev);
+ if (err)
+ hci_dev_put(hdev);
return err;
}

@@ -438,12 +440,13 @@ static void __sco_sock_close(struct sock *sk)

Edward Adam Davis

unread,
Nov 24, 2023, 6:41:51 AM11/24/23
to syzbot+60bfed...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test uaf in __lock_sock

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git 8de1e7afcc1c

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index c736186aba26..d7054e3d7146 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -285,6 +285,7 @@ static int sco_connect(struct sock *sk)
goto unlock;
}

+ hci_conn_get(hcon);
/* Update source addr of the socket */
bacpy(&sco_pi(sk)->src, &hcon->src);

syzbot

unread,
Nov 24, 2023, 6:56:06 AM11/24/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+60bfed...@syzkaller.appspotmail.com

Tested on:

commit: 8de1e7af Merge branch 'for-next/core' into for-kernelci
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=170a9544e80000
kernel config: https://syzkaller.appspot.com/x/.config?x=3e6feaeda5dcbc27
dashboard link: https://syzkaller.appspot.com/bug?extid=60bfed6b415fbd1fbb87
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
userspace arch: arm64
patch: https://syzkaller.appspot.com/x/patch.diff?x=1476a4d8e80000

syzbot

unread,
Nov 24, 2023, 7:22:08 AM11/24/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+60bfed...@syzkaller.appspotmail.com

Tested on:

commit: 8de1e7af Merge branch 'for-next/core' into for-kernelci
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=17a2cff0e80000
kernel config: https://syzkaller.appspot.com/x/.config?x=3e6feaeda5dcbc27
dashboard link: https://syzkaller.appspot.com/bug?extid=60bfed6b415fbd1fbb87
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
userspace arch: arm64
patch: https://syzkaller.appspot.com/x/patch.diff?x=15b4f40ce80000

Edward Adam Davis

unread,
Nov 24, 2023, 8:54:48 AM11/24/23
to syzbot+60bfed...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test uaf in __lock_sock

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git 8de1e7afcc1c

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index c736186aba26..1d603d20970f 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -300,7 +300,8 @@ static int sco_connect(struct sock *sk)

unlock:
hci_dev_unlock(hdev);
- hci_dev_put(hdev);
+ if (err)
+ hci_dev_put(hdev);
return err;
}

@@ -438,12 +439,13 @@ static void __sco_sock_close(struct sock *sk)

syzbot

unread,
Nov 24, 2023, 9:36:07 AM11/24/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in hci_conn_unlink

Bluetooth: hci0: command 0x0409 tx timeout
==================================================================
BUG: KASAN: slab-use-after-free in hci_conn_unlink+0x3b0/0x490 net/bluetooth/hci_conn.c:1104
Read of size 8 at addr ffff0000c7cf4aa8 by task kworker/u5:1/5666

CPU: 1 PID: 5666 Comm: kworker/u5:1 Not tainted 6.6.0-rc7-syzkaller-00089-g8de1e7afcc1c-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
Workqueue: hci0 hci_cmd_sync_work
Call trace:
dump_backtrace+0x1b8/0x1e4 arch/arm64/kernel/stacktrace.c:233
show_stack+0x2c/0x44 arch/arm64/kernel/stacktrace.c:240
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xd0/0x124 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:364 [inline]
print_report+0x174/0x514 mm/kasan/report.c:475
kasan_report+0xd8/0x138 mm/kasan/report.c:588
__asan_report_load8_noabort+0x20/0x2c mm/kasan/report_generic.c:381
hci_conn_unlink+0x3b0/0x490 net/bluetooth/hci_conn.c:1104
hci_conn_del+0x5c/0xabc net/bluetooth/hci_conn.c:1118
hci_conn_failed+0x204/0x2c0 net/bluetooth/hci_conn.c:1252
hci_abort_conn_sync+0x688/0xe38 net/bluetooth/hci_sync.c:5428
abort_conn_sync+0x5c/0x8c net/bluetooth/hci_conn.c:2910
hci_cmd_sync_work+0x1cc/0x34c net/bluetooth/hci_sync.c:306
process_one_work+0x694/0x1204 kernel/workqueue.c:2630
process_scheduled_works kernel/workqueue.c:2703 [inline]
worker_thread+0x938/0xef4 kernel/workqueue.c:2784
kthread+0x288/0x310 kernel/kthread.c:388
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:857

Allocated by task 6565:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4c/0x7c mm/kasan/common.c:52
kasan_save_alloc_info+0x24/0x30 mm/kasan/generic.c:511
____kasan_kmalloc mm/kasan/common.c:374 [inline]
__kasan_kmalloc+0xac/0xc4 mm/kasan/common.c:383
kasan_kmalloc include/linux/kasan.h:198 [inline]
kmalloc_trace+0x70/0x88 mm/slab_common.c:1122
kmalloc include/linux/slab.h:599 [inline]
kzalloc include/linux/slab.h:720 [inline]
hci_conn_add+0xcc/0x1210 net/bluetooth/hci_conn.c:957
hci_connect_sco+0x94/0x2bc net/bluetooth/hci_conn.c:1701
sco_connect net/bluetooth/sco.c:266 [inline]
sco_sock_connect+0x264/0x808 net/bluetooth/sco.c:593
__sys_connect_file net/socket.c:2050 [inline]
__sys_connect+0x268/0x290 net/socket.c:2067
__do_sys_connect net/socket.c:2077 [inline]
__se_sys_connect net/socket.c:2074 [inline]
__arm64_sys_connect+0x7c/0x94 net/socket.c:2074
__invoke_syscall arch/arm64/kernel/syscall.c:37 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155
el0_svc+0x54/0x158 arch/arm64/kernel/entry-common.c:678
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595

Freed by task 6565:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4c/0x7c mm/kasan/common.c:52
kasan_save_free_info+0x38/0x5c mm/kasan/generic.c:522
____kasan_slab_free+0x144/0x1c0 mm/kasan/common.c:236
__kasan_slab_free+0x18/0x28 mm/kasan/common.c:244
kasan_slab_free include/linux/kasan.h:164 [inline]
slab_free_hook mm/slub.c:1800 [inline]
slab_free_freelist_hook mm/slub.c:1826 [inline]
slab_free mm/slub.c:3809 [inline]
__kmem_cache_free+0x2ac/0x480 mm/slub.c:3822
kfree+0xb8/0x19c mm/slab_common.c:1075
bt_link_release+0x20/0x30 net/bluetooth/hci_sysfs.c:16
device_release+0x8c/0x1ac
kobject_cleanup lib/kobject.c:682 [inline]
kobject_release lib/kobject.c:716 [inline]
kref_put include/linux/kref.h:65 [inline]
kobject_put+0x1c4/0x3c4 lib/kobject.c:733
put_device+0x28/0x40 drivers/base/core.c:3732
hci_conn_put include/net/bluetooth/hci_core.h:1506 [inline]
__sco_sock_close+0x3b8/0x788 net/bluetooth/sco.c:448
sco_sock_close net/bluetooth/sco.c:471 [inline]
sco_sock_release+0xb4/0x2c0 net/bluetooth/sco.c:1248
__sock_release net/socket.c:659 [inline]
sock_close+0xa4/0x1e8 net/socket.c:1419
__fput+0x324/0x7f8 fs/file_table.c:384
____fput+0x20/0x30 fs/file_table.c:412
task_work_run+0x230/0x2e0 kernel/task_work.c:180
get_signal+0x13f4/0x15ec kernel/signal.c:2668
do_signal arch/arm64/kernel/signal.c:1249 [inline]
do_notify_resume+0x3bc/0x393c arch/arm64/kernel/signal.c:1302
exit_to_user_mode_prepare arch/arm64/kernel/entry-common.c:137 [inline]
exit_to_user_mode arch/arm64/kernel/entry-common.c:144 [inline]
el0_svc+0x9c/0x158 arch/arm64/kernel/entry-common.c:679
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595

The buggy address belongs to the object at ffff0000c7cf4000
which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 2728 bytes inside of
freed 4096-byte region [ffff0000c7cf4000, ffff0000c7cf5000)

The buggy address belongs to the physical page:
page:0000000058906251 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x107cf0
head:0000000058906251 order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x5ffc00000000840(slab|head|node=0|zone=2|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 05ffc00000000840 ffff0000c0002140 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000040004 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff0000c7cf4980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff0000c7cf4a00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff0000c7cf4a80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff0000c7cf4b00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff0000c7cf4b80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
------------[ cut here ]------------
ODEBUG: assert_init not available (active state 0) object: 00000000bba7ac7f object type: timer_list hint: hci_conn_timeout+0x0/0x1e8 net/bluetooth/hci_conn.c:928
WARNING: CPU: 1 PID: 5666 at lib/debugobjects.c:517 debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
Modules linked in:
CPU: 1 PID: 5666 Comm: kworker/u5:1 Tainted: G B 6.6.0-rc7-syzkaller-00089-g8de1e7afcc1c-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
Workqueue: hci0 hci_cmd_sync_work
pstate: 604000c5 (nZCv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
lr : debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
sp : ffff80009e217430
x29: ffff80009e217430 x28: dfff800000000000 x27: ffff700013c42e94
x26: dfff800000000000 x25: dfff800000000000 x24: ffff0000c7cf4390
x23: ffff80008ad651a0 x22: ffff800089881d98 x21: ffff80008a89c360
x20: 0000000000000000 x19: ffff80008ad64cc0 x18: 1fffe000368333ce
x17: 0000000000000000 x16: ffff80008a668880 x15: 0000000000000001
x14: 1ffff00013c42da0 x13: 0000000000000000 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000000 x9 : 14bd4a4222856a00
x8 : 14bd4a4222856a00 x7 : 0000000000000001 x6 : 0000000000000001
x5 : ffff80009e216d18 x4 : ffff80008e4210a0 x3 : ffff8000803639bc
x2 : 0000000000000001 x1 : 0000000100000000 x0 : 0000000000000000
Call trace:
debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
debug_object_assert_init+0x318/0x3c8 lib/debugobjects.c:941
debug_timer_assert_init kernel/time/timer.c:792 [inline]
debug_assert_init kernel/time/timer.c:837 [inline]
__timer_delete+0xac/0x2f8 kernel/time/timer.c:1321
timer_delete+0x24/0x34 kernel/time/timer.c:1361
del_timer include/linux/timer.h:213 [inline]
try_to_grab_pending+0x8c/0x618 kernel/workqueue.c:1564
__cancel_work_timer+0x118/0x540 kernel/workqueue.c:3453
cancel_delayed_work_sync+0x24/0x38 kernel/workqueue.c:3635
hci_conn_del+0x64/0xabc net/bluetooth/hci_conn.c:1120
hci_conn_failed+0x204/0x2c0 net/bluetooth/hci_conn.c:1252
hci_abort_conn_sync+0x688/0xe38 net/bluetooth/hci_sync.c:5428
abort_conn_sync+0x5c/0x8c net/bluetooth/hci_conn.c:2910
hci_cmd_sync_work+0x1cc/0x34c net/bluetooth/hci_sync.c:306
process_one_work+0x694/0x1204 kernel/workqueue.c:2630
process_scheduled_works kernel/workqueue.c:2703 [inline]
worker_thread+0x938/0xef4 kernel/workqueue.c:2784
kthread+0x288/0x310 kernel/kthread.c:388
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:857
irq event stamp: 3419
hardirqs last enabled at (3419): [<ffff80008028e6c8>] raw_spin_rq_unlock_irq kernel/sched/sched.h:1384 [inline]
hardirqs last enabled at (3419): [<ffff80008028e6c8>] finish_lock_switch+0xbc/0x1e4 kernel/sched/core.c:5134
hardirqs last disabled at (3418): [<ffff80008a7f1250>] __schedule+0x2b4/0x23b4 kernel/sched/core.c:6594
softirqs last enabled at (3156): [<ffff8000888ace70>] spin_unlock_bh include/linux/spinlock.h:396 [inline]
softirqs last enabled at (3156): [<ffff8000888ace70>] release_sock+0x15c/0x1b0 net/core/sock.c:3531
softirqs last disabled at (3154): [<ffff8000888acd50>] spin_lock_bh include/linux/spinlock.h:356 [inline]
softirqs last disabled at (3154): [<ffff8000888acd50>] release_sock+0x3c/0x1b0 net/core/sock.c:3518
---[ end trace 0000000000000000 ]---
------------[ cut here ]------------
ODEBUG: assert_init not available (active state 0) object: 00000000fd1f42ce object type: timer_list hint: hci_conn_auto_accept+0x0/0x58
WARNING: CPU: 1 PID: 5666 at lib/debugobjects.c:517 debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
Modules linked in:
CPU: 1 PID: 5666 Comm: kworker/u5:1 Tainted: G B W 6.6.0-rc7-syzkaller-00089-g8de1e7afcc1c-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
Workqueue: hci0 hci_cmd_sync_work
pstate: 604000c5 (nZCv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
lr : debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
sp : ffff80009e217430
x29: ffff80009e217430 x28: dfff800000000000 x27: ffff700013c42e94
x26: ffff0000d6a8ae50 x25: dfff800000000000 x24: ffff0000c7cf4438
x23: ffff80008ad651a0 x22: ffff800089881f80 x21: ffff80008a89c360
x20: 0000000000000000 x19: ffff80008ad64cc0 x18: 1fffe000368333ce
x17: 0000000000000000 x16: ffff80008a71b1bc x15: 0000000000000001
x14: 1fffe00036833432 x13: 0000000000000000 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000000 x9 : 14bd4a4222856a00
x8 : 14bd4a4222856a00 x7 : 0000000000000001 x6 : 0000000000000001
x5 : ffff80009e216d18 x4 : ffff80008e4210a0 x3 : ffff8000805a359c
x2 : 0000000000000001 x1 : 0000000100000000 x0 : 0000000000000000
Call trace:
debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
debug_object_assert_init+0x318/0x3c8 lib/debugobjects.c:941
debug_timer_assert_init kernel/time/timer.c:792 [inline]
debug_assert_init kernel/time/timer.c:837 [inline]
__timer_delete+0xac/0x2f8 kernel/time/timer.c:1321
timer_delete+0x24/0x34 kernel/time/timer.c:1361
del_timer include/linux/timer.h:213 [inline]
try_to_grab_pending+0x8c/0x618 kernel/workqueue.c:1564
__cancel_work_timer+0x118/0x540 kernel/workqueue.c:3453
cancel_delayed_work_sync+0x24/0x38 kernel/workqueue.c:3635
hci_conn_del+0x6c/0xabc net/bluetooth/hci_conn.c:1121
hci_conn_failed+0x204/0x2c0 net/bluetooth/hci_conn.c:1252
hci_abort_conn_sync+0x688/0xe38 net/bluetooth/hci_sync.c:5428
abort_conn_sync+0x5c/0x8c net/bluetooth/hci_conn.c:2910
hci_cmd_sync_work+0x1cc/0x34c net/bluetooth/hci_sync.c:306
process_one_work+0x694/0x1204 kernel/workqueue.c:2630
process_scheduled_works kernel/workqueue.c:2703 [inline]
worker_thread+0x938/0xef4 kernel/workqueue.c:2784
kthread+0x288/0x310 kernel/kthread.c:388
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:857
irq event stamp: 3419
hardirqs last enabled at (3419): [<ffff80008028e6c8>] raw_spin_rq_unlock_irq kernel/sched/sched.h:1384 [inline]
hardirqs last enabled at (3419): [<ffff80008028e6c8>] finish_lock_switch+0xbc/0x1e4 kernel/sched/core.c:5134
hardirqs last disabled at (3418): [<ffff80008a7f1250>] __schedule+0x2b4/0x23b4 kernel/sched/core.c:6594
softirqs last enabled at (3156): [<ffff8000888ace70>] spin_unlock_bh include/linux/spinlock.h:396 [inline]
softirqs last enabled at (3156): [<ffff8000888ace70>] release_sock+0x15c/0x1b0 net/core/sock.c:3531
softirqs last disabled at (3154): [<ffff8000888acd50>] spin_lock_bh include/linux/spinlock.h:356 [inline]
softirqs last disabled at (3154): [<ffff8000888acd50>] release_sock+0x3c/0x1b0 net/core/sock.c:3518
---[ end trace 0000000000000000 ]---
------------[ cut here ]------------
ODEBUG: assert_init not available (active state 0) object: 000000000db4e74f object type: timer_list hint: hci_conn_idle+0x0/0x554 net/bluetooth/hci_conn.c:676
WARNING: CPU: 1 PID: 5666 at lib/debugobjects.c:517 debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
Modules linked in:
CPU: 1 PID: 5666 Comm: kworker/u5:1 Tainted: G B W 6.6.0-rc7-syzkaller-00089-g8de1e7afcc1c-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
Workqueue: hci0 hci_cmd_sync_work
pstate: 604000c5 (nZCv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
lr : debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
sp : ffff80009e217430
x29: ffff80009e217430 x28: dfff800000000000 x27: ffff700013c42e94
x26: ffff0000d6a8ae50 x25: dfff800000000000 x24: ffff0000c7cf44e0
x23: ffff80008ad651a0 x22: ffff800089881fd8 x21: ffff80008a89c360
x20: 0000000000000000 x19: ffff80008ad64cc0 x18: 1fffe000368333ce
x17: 0000000000000000 x16: ffff80008a668880 x15: 0000000000000001
x14: 1ffff00013c42da0 x13: 0000000000000000 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000000 x9 : 14bd4a4222856a00
x8 : 14bd4a4222856a00 x7 : 0000000000000001 x6 : 0000000000000001
x5 : ffff80009e216d18 x4 : ffff80008e4210a0 x3 : ffff8000803639bc
x2 : 0000000000000001 x1 : 0000000100000000 x0 : 0000000000000000
Call trace:
debug_print_object+0x168/0x1e0 lib/debugobjects.c:514
debug_object_assert_init+0x318/0x3c8 lib/debugobjects.c:941
debug_timer_assert_init kernel/time/timer.c:792 [inline]
debug_assert_init kernel/time/timer.c:837 [inline]
__timer_delete+0xac/0x2f8 kernel/time/timer.c:1321
timer_delete+0x24/0x34 kernel/time/timer.c:1361
del_timer include/linux/timer.h:213 [inline]
try_to_grab_pending+0x8c/0x618 kernel/workqueue.c:1564
__cancel_work_timer+0x118/0x540 kernel/workqueue.c:3453
cancel_delayed_work_sync+0x24/0x38 kernel/workqueue.c:3635
hci_conn_del+0x74/0xabc net/bluetooth/hci_conn.c:1122
hci_conn_failed+0x204/0x2c0 net/bluetooth/hci_conn.c:1252
hci_abort_conn_sync+0x688/0xe38 net/bluetooth/hci_sync.c:5428
abort_conn_sync+0x5c/0x8c net/bluetooth/hci_conn.c:2910
hci_cmd_sync_work+0x1cc/0x34c net/bluetooth/hci_sync.c:306
process_one_work+0x694/0x1204 kernel/workqueue.c:2630
process_scheduled_works kernel/workqueue.c:2703 [inline]
worker_thread+0x938/0xef4 kernel/workqueue.c:2784
kthread+0x288/0x310 kernel/kthread.c:388
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:857
irq event stamp: 3419
hardirqs last enabled at (3419): [<ffff80008028e6c8>] raw_spin_rq_unlock_irq kernel/sched/sched.h:1384 [inline]
hardirqs last enabled at (3419): [<ffff80008028e6c8>] finish_lock_switch+0xbc/0x1e4 kernel/sched/core.c:5134
hardirqs last disabled at (3418): [<ffff80008a7f1250>] __schedule+0x2b4/0x23b4 kernel/sched/core.c:6594
softirqs last enabled at (3156): [<ffff8000888ace70>] spin_unlock_bh include/linux/spinlock.h:396 [inline]
softirqs last enabled at (3156): [<ffff8000888ace70>] release_sock+0x15c/0x1b0 net/core/sock.c:3531
softirqs last disabled at (3154): [<ffff8000888acd50>] spin_lock_bh include/linux/spinlock.h:356 [inline]
softirqs last disabled at (3154): [<ffff8000888acd50>] release_sock+0x3c/0x1b0 net/core/sock.c:3518
---[ end trace 0000000000000000 ]---
Unable to handle kernel paging request at virtual address e0ec406f80000334
KASAN: maybe wild-memory-access in range [0x0766037c000019a0-0x0766037c000019a7]
Mem abort info:
ESR = 0x0000000096000004
EC = 0x25: DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
FSC = 0x04: level 0 translation fault
Data abort info:
ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000
CM = 0, WnR = 0, TnD = 0, TagAccess = 0
GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
[e0ec406f80000334] address between user and kernel address ranges
Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP
Modules linked in:
CPU: 1 PID: 5666 Comm: kworker/u5:1 Tainted: G B W 6.6.0-rc7-syzkaller-00089-g8de1e7afcc1c-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
Workqueue: hci0 hci_cmd_sync_work
pstate: 00400005 (nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : __list_del_entry_valid_or_report+0x78/0x158 lib/list_debug.c:62
lr : __list_del_entry_valid_or_report+0x4c/0x158 lib/list_debug.c:50
sp : ffff80009e2178a0
x29: ffff80009e2178a0 x28: 0000000000000f00 x27: ffff0000d4e94000
x26: 1fffe00018f9e94e x25: 1fffe00018f9e807 x24: dfff800000000000
x23: ffff0000c7cf4338 x22: dfff800000000000 x21: 0766037c000019a5
x20: ffff0000dc7a22f0 x19: ffff0000c7cf4000 x18: 1fffe000368333ce
x17: 0000000000000000 x16: ffff800080515ce8 x15: ffff600018f9e857
x14: 1fffe00018f9e857 x13: 00000000000000fb x12: ffffffffffffffff
x11: 0000000000000000 x10: 0000000000000000 x9 : ffff80009285f2d0
x8 : 00ecc06f80000334 x7 : 0000000000000000 x6 : ffff8000888de614
x5 : 0000000000000000 x4 : 0000000000000001 x3 : ffff800082b8ce90
x2 : dead000000000122 x1 : 0000000000000008 x0 : 0000000000000000
Call trace:
__list_del_entry_valid_or_report+0x78/0x158 lib/list_debug.c:62
__list_del_entry_valid include/linux/list.h:124 [inline]
__list_del_entry include/linux/list.h:215 [inline]
list_del_rcu include/linux/rculist.h:157 [inline]
hci_conn_hash_del include/net/bluetooth/hci_core.h:1029 [inline]
hci_conn_cleanup net/bluetooth/hci_conn.c:154 [inline]
hci_conn_del+0x3e0/0xabc net/bluetooth/hci_conn.c:1156
hci_conn_failed+0x204/0x2c0 net/bluetooth/hci_conn.c:1252
hci_abort_conn_sync+0x688/0xe38 net/bluetooth/hci_sync.c:5428
abort_conn_sync+0x5c/0x8c net/bluetooth/hci_conn.c:2910
hci_cmd_sync_work+0x1cc/0x34c net/bluetooth/hci_sync.c:306
process_one_work+0x694/0x1204 kernel/workqueue.c:2630
process_scheduled_works kernel/workqueue.c:2703 [inline]
worker_thread+0x938/0xef4 kernel/workqueue.c:2784
kthread+0x288/0x310 kernel/kthread.c:388
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:857
Code: 91008902 eb0202bf 54000520 d343fea8 (38766908)
---[ end trace 0000000000000000 ]---
----------------
Code disassembly (best guess):
0: 91008902 add x2, x8, #0x22
4: eb0202bf cmp x21, x2
8: 54000520 b.eq 0xac // b.none
c: d343fea8 lsr x8, x21, #3
* 10: 38766908 ldrb w8, [x8, x22] <-- trapping instruction


Tested on:

commit: 8de1e7af Merge branch 'for-next/core' into for-kernelci
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=16147daf680000
kernel config: https://syzkaller.appspot.com/x/.config?x=3e6feaeda5dcbc27
dashboard link: https://syzkaller.appspot.com/bug?extid=60bfed6b415fbd1fbb87
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
userspace arch: arm64
patch: https://syzkaller.appspot.com/x/patch.diff?x=11bfb1c8e80000

Edward Adam Davis

unread,
Nov 24, 2023, 8:31:14 PM11/24/23
to syzbot+60bfed...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test uaf in __lock_sock

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git 8de1e7afcc1c

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index c736186aba26..0bf3d90c1442 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -285,6 +285,7 @@ static int sco_connect(struct sock *sk)
goto unlock;
}

+ hci_conn_get(hcon);
/* Update source addr of the socket */
bacpy(&sco_pi(sk)->src, &hcon->src);

@@ -297,10 +298,12 @@ static int sco_connect(struct sock *sk)
}

release_sock(sk);
+ printk("hd: %p, hcd: %p\n", &hdev->dev, &hcon->dev);

unlock:
hci_dev_unlock(hdev);
- hci_dev_put(hdev);
+ if (err)
+ hci_dev_put(hdev);
return err;
}

@@ -438,12 +441,13 @@ static void __sco_sock_close(struct sock *sk)

syzbot

unread,
Nov 24, 2023, 8:58:05 PM11/24/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in __lock_sock

==================================================================
BUG: KASAN: slab-use-after-free in __lock_acquire+0x114/0x75e8 kernel/locking/lockdep.c:5004
Read of size 8 at addr ffff0000ce5ce0b0 by task kworker/u5:0/51

CPU: 1 PID: 51 Comm: kworker/u5:0 Not tainted 6.6.0-rc7-syzkaller-00089-g8de1e7afcc1c-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
Workqueue: hci1 hci_cmd_sync_work
Call trace:
dump_backtrace+0x1b8/0x1e4 arch/arm64/kernel/stacktrace.c:233
show_stack+0x2c/0x44 arch/arm64/kernel/stacktrace.c:240
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xd0/0x124 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:364 [inline]
print_report+0x174/0x514 mm/kasan/report.c:475
kasan_report+0xd8/0x138 mm/kasan/report.c:588
__asan_report_load8_noabort+0x20/0x2c mm/kasan/report_generic.c:381
__lock_acquire+0x114/0x75e8 kernel/locking/lockdep.c:5004
lock_acquire+0x23c/0x71c kernel/locking/lockdep.c:5753
__raw_spin_lock_bh include/linux/spinlock_api_smp.h:126 [inline]
_raw_spin_lock_bh+0x48/0x60 kernel/locking/spinlock.c:178
spin_lock_bh include/linux/spinlock.h:356 [inline]
__lock_sock+0x170/0x2d4 net/core/sock.c:2960
lock_sock_nested+0xa4/0x11c net/core/sock.c:3510
lock_sock include/net/sock.h:1720 [inline]
sco_conn_ready net/bluetooth/sco.c:1272 [inline]
sco_connect_cfm+0x140/0x948 net/bluetooth/sco.c:1363
hci_connect_cfm include/net/bluetooth/hci_core.h:1935 [inline]
hci_conn_failed+0x17c/0x2c0 net/bluetooth/hci_conn.c:1251
hci_abort_conn_sync+0x688/0xe38 net/bluetooth/hci_sync.c:5428
abort_conn_sync+0x5c/0x8c net/bluetooth/hci_conn.c:2910
hci_cmd_sync_work+0x1cc/0x34c net/bluetooth/hci_sync.c:306
process_one_work+0x694/0x1204 kernel/workqueue.c:2630
process_scheduled_works kernel/workqueue.c:2703 [inline]
worker_thread+0x938/0xef4 kernel/workqueue.c:2784
kthread+0x288/0x310 kernel/kthread.c:388
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:857

Allocated by task 8236:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4c/0x7c mm/kasan/common.c:52
kasan_save_alloc_info+0x24/0x30 mm/kasan/generic.c:511
____kasan_kmalloc mm/kasan/common.c:374 [inline]
__kasan_kmalloc+0xac/0xc4 mm/kasan/common.c:383
kasan_kmalloc include/linux/kasan.h:198 [inline]
__do_kmalloc_node mm/slab_common.c:1026 [inline]
__kmalloc+0xcc/0x1b8 mm/slab_common.c:1039
kmalloc include/linux/slab.h:603 [inline]
sk_prot_alloc+0xc4/0x1f0 net/core/sock.c:2090
sk_alloc+0x44/0x3f4 net/core/sock.c:2143
bt_sock_alloc+0x4c/0x32c net/bluetooth/af_bluetooth.c:148
sco_sock_alloc net/bluetooth/sco.c:499 [inline]
sco_sock_create+0xbc/0x31c net/bluetooth/sco.c:530
bt_sock_create+0x14c/0x248 net/bluetooth/af_bluetooth.c:132
__sock_create+0x43c/0x884 net/socket.c:1569
sock_create net/socket.c:1620 [inline]
__sys_socket_create net/socket.c:1657 [inline]
__sys_socket+0x134/0x340 net/socket.c:1708
__do_sys_socket net/socket.c:1722 [inline]
__se_sys_socket net/socket.c:1720 [inline]
__arm64_sys_socket+0x7c/0x94 net/socket.c:1720
__invoke_syscall arch/arm64/kernel/syscall.c:37 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155
el0_svc+0x54/0x158 arch/arm64/kernel/entry-common.c:678
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595

Freed by task 8236:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4c/0x7c mm/kasan/common.c:52
kasan_save_free_info+0x38/0x5c mm/kasan/generic.c:522
____kasan_slab_free+0x144/0x1c0 mm/kasan/common.c:236
__kasan_slab_free+0x18/0x28 mm/kasan/common.c:244
kasan_slab_free include/linux/kasan.h:164 [inline]
slab_free_hook mm/slub.c:1800 [inline]
slab_free_freelist_hook mm/slub.c:1826 [inline]
slab_free mm/slub.c:3809 [inline]
__kmem_cache_free+0x2ac/0x480 mm/slub.c:3822
kfree+0xb8/0x19c mm/slab_common.c:1075
sk_prot_free net/core/sock.c:2126 [inline]
__sk_destruct+0x4c0/0x770 net/core/sock.c:2218
sk_destruct net/core/sock.c:2233 [inline]
__sk_free+0x37c/0x4e8 net/core/sock.c:2244
sk_free+0x60/0xc8 net/core/sock.c:2255
sock_put include/net/sock.h:1989 [inline]
sco_sock_kill+0xfc/0x1b4 net/bluetooth/sco.c:429
sco_sock_release+0x1fc/0x2c0 net/bluetooth/sco.c:1260
__sock_release net/socket.c:659 [inline]
sock_close+0xa4/0x1e8 net/socket.c:1419
__fput+0x324/0x7f8 fs/file_table.c:384
____fput+0x20/0x30 fs/file_table.c:412
task_work_run+0x230/0x2e0 kernel/task_work.c:180
get_signal+0x13f4/0x15ec kernel/signal.c:2668
do_signal arch/arm64/kernel/signal.c:1249 [inline]
do_notify_resume+0x3bc/0x393c arch/arm64/kernel/signal.c:1302
exit_to_user_mode_prepare arch/arm64/kernel/entry-common.c:137 [inline]
exit_to_user_mode arch/arm64/kernel/entry-common.c:144 [inline]
el0_svc+0x9c/0x158 arch/arm64/kernel/entry-common.c:679
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595

The buggy address belongs to the object at ffff0000ce5ce000
which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 176 bytes inside of
freed 2048-byte region [ffff0000ce5ce000, ffff0000ce5ce800)

The buggy address belongs to the physical page:
page:00000000b6dddcc6 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10e5c8
head:00000000b6dddcc6 order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x5ffc00000000840(slab|head|node=0|zone=2|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 05ffc00000000840 ffff0000c0002000 dead000000000122 0000000000000000
raw: 0000000000000000 0000000000080008 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff0000ce5cdf80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff0000ce5ce000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff0000ce5ce080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff0000ce5ce100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff0000ce5ce180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Bluetooth: hci1: command 0x0409 tx timeout
Bluetooth: hci1: command 0x040f tx timeout


Tested on:

commit: 8de1e7af Merge branch 'for-next/core' into for-kernelci
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=113dcbcce80000
kernel config: https://syzkaller.appspot.com/x/.config?x=3e6feaeda5dcbc27
dashboard link: https://syzkaller.appspot.com/bug?extid=60bfed6b415fbd1fbb87
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
userspace arch: arm64
patch: https://syzkaller.appspot.com/x/patch.diff?x=1451e294e80000

Edward Adam Davis

unread,
Nov 24, 2023, 10:20:36 PM11/24/23
to syzbot+60bfed...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test uaf in __lock_sock

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git 8de1e7afcc1c

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index c736186aba26..236da4241620 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -285,6 +285,7 @@ static int sco_connect(struct sock *sk)
goto unlock;
}

+ hci_conn_get(hcon);
/* Update source addr of the socket */
bacpy(&sco_pi(sk)->src, &hcon->src);

@@ -297,10 +298,13 @@ static int sco_connect(struct sock *sk)
}

release_sock(sk);
+ printk("hd: %s, hcd: %s, hko: %p, hcko: %p\n", hdev->dev.kobj.name,
+ hcon->dev.kobj.name, &hdev->dev.kobj, &hcon->dev.kobj);

unlock:
hci_dev_unlock(hdev);
- hci_dev_put(hdev);
+ if (err)
+ hci_dev_put(hdev);
return err;
}

@@ -438,12 +442,13 @@ static void __sco_sock_close(struct sock *sk)

syzbot

unread,
Nov 24, 2023, 10:47:06 PM11/24/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+60bfed...@syzkaller.appspotmail.com

Tested on:

commit: 8de1e7af Merge branch 'for-next/core' into for-kernelci
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=138d5d9f680000
kernel config: https://syzkaller.appspot.com/x/.config?x=3e6feaeda5dcbc27
dashboard link: https://syzkaller.appspot.com/bug?extid=60bfed6b415fbd1fbb87
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
userspace arch: arm64
patch: https://syzkaller.appspot.com/x/patch.diff?x=144fb6d0e80000

syzbot

unread,
Mar 1, 2024, 9:18:17 AMMar 1
to syzkall...@googlegroups.com
Auto-closing this bug as obsolete.
No recent activity, existing reproducers are no longer triggering the issue.
Reply all
Reply to author
Forward
0 new messages