Commit 6fe26f6
committed
Bluetooth: MGMT: Protect mgmt_pending list with its own lock
This uses a mutex to protect from concurrent access of mgmt_pending
list which can cause crashes like:
==================================================================
BUG: KASAN: slab-use-after-free in hci_sock_get_channel+0x60/0x68 net/bluetooth/hci_sock.c:91
Read of size 2 at addr ffff0000c48885b2 by task syz.4.334/7318
CPU: 0 UID: 0 PID: 7318 Comm: syz.4.334 Not tainted 6.15.0-rc7-syzkaller-g187899f4124a #0 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 02/12/2025
Call trace:
show_stack+0x2c/0x3c arch/arm64/kernel/stacktrace.c:466 (C)
__dump_stack+0x30/0x40 lib/dump_stack.c:94
dump_stack_lvl+0xd8/0x12c lib/dump_stack.c:120
print_address_description+0xa8/0x254 mm/kasan/report.c:408
print_report+0x68/0x84 mm/kasan/report.c:521
kasan_report+0xb0/0x110 mm/kasan/report.c:634
__asan_report_load2_noabort+0x20/0x2c mm/kasan/report_generic.c:379
hci_sock_get_channel+0x60/0x68 net/bluetooth/hci_sock.c:91
mgmt_pending_find+0x7c/0x140 net/bluetooth/mgmt_util.c:223
pending_find net/bluetooth/mgmt.c:947 [inline]
remove_adv_monitor+0x44/0x1a4 net/bluetooth/mgmt.c:5445
hci_mgmt_cmd+0x780/0xc00 net/bluetooth/hci_sock.c:1712
hci_sock_sendmsg+0x544/0xbb0 net/bluetooth/hci_sock.c:1832
sock_sendmsg_nosec net/socket.c:712 [inline]
__sock_sendmsg net/socket.c:727 [inline]
sock_write_iter+0x25c/0x378 net/socket.c:1131
new_sync_write fs/read_write.c:591 [inline]
vfs_write+0x62c/0x97c fs/read_write.c:684
ksys_write+0x120/0x210 fs/read_write.c:736
__do_sys_write fs/read_write.c:747 [inline]
__se_sys_write fs/read_write.c:744 [inline]
__arm64_sys_write+0x7c/0x90 fs/read_write.c:744
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151
el0_svc+0x58/0x17c arch/arm64/kernel/entry-common.c:767
el0t_64_sync_handler+0x78/0x108 arch/arm64/kernel/entry-common.c:786
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:600
Allocated by task 7037:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x40/0x78 mm/kasan/common.c:68
kasan_save_alloc_info+0x44/0x54 mm/kasan/generic.c:562
poison_kmalloc_redzone mm/kasan/common.c:377 [inline]
__kasan_kmalloc+0x9c/0xb4 mm/kasan/common.c:394
kasan_kmalloc include/linux/kasan.h:260 [inline]
__do_kmalloc_node mm/slub.c:4327 [inline]
__kmalloc_noprof+0x2fc/0x4c8 mm/slub.c:4339
kmalloc_noprof include/linux/slab.h:909 [inline]
sk_prot_alloc+0xc4/0x1f0 net/core/sock.c:2198
sk_alloc+0x44/0x3ac net/core/sock.c:2254
bt_sock_alloc+0x4c/0x300 net/bluetooth/af_bluetooth.c:148
hci_sock_create+0xa8/0x194 net/bluetooth/hci_sock.c:2202
bt_sock_create+0x14c/0x24c net/bluetooth/af_bluetooth.c:132
__sock_create+0x43c/0x91c net/socket.c:1541
sock_create net/socket.c:1599 [inline]
__sys_socket_create net/socket.c:1636 [inline]
__sys_socket+0xd4/0x1c0 net/socket.c:1683
__do_sys_socket net/socket.c:1697 [inline]
__se_sys_socket net/socket.c:1695 [inline]
__arm64_sys_socket+0x7c/0x94 net/socket.c:1695
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151
el0_svc+0x58/0x17c arch/arm64/kernel/entry-common.c:767
el0t_64_sync_handler+0x78/0x108 arch/arm64/kernel/entry-common.c:786
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:600
Freed by task 6607:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x40/0x78 mm/kasan/common.c:68
kasan_save_free_info+0x58/0x70 mm/kasan/generic.c:576
poison_slab_object mm/kasan/common.c:247 [inline]
__kasan_slab_free+0x68/0x88 mm/kasan/common.c:264
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2380 [inline]
slab_free mm/slub.c:4642 [inline]
kfree+0x17c/0x474 mm/slub.c:4841
sk_prot_free net/core/sock.c:2237 [inline]
__sk_destruct+0x4f4/0x760 net/core/sock.c:2332
sk_destruct net/core/sock.c:2360 [inline]
__sk_free+0x320/0x430 net/core/sock.c:2371
sk_free+0x60/0xc8 net/core/sock.c:2382
sock_put include/net/sock.h:1944 [inline]
mgmt_pending_free+0x88/0x118 net/bluetooth/mgmt_util.c:290
mgmt_pending_remove+0xec/0x104 net/bluetooth/mgmt_util.c:298
mgmt_set_powered_complete+0x418/0x5cc net/bluetooth/mgmt.c:1355
hci_cmd_sync_work+0x204/0x33c net/bluetooth/hci_sync.c:334
process_one_work+0x7e8/0x156c kernel/workqueue.c:3238
process_scheduled_works kernel/workqueue.c:3319 [inline]
worker_thread+0x958/0xed8 kernel/workqueue.c:3400
kthread+0x5fc/0x75c kernel/kthread.c:464
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:847
Fixes: a380b6c ("Bluetooth: Add generic mgmt helper API")
Closes: https://syzkaller.appspot.com/bug?extid=0a7039d5d9986ff4ecec
Closes: https://syzkaller.appspot.com/bug?extid=cc0cc52e7f43dc9e6df1
Reported-by: syzbot+0a7039d5d9986ff4ecec@syzkaller.appspotmail.com
Tested-by: syzbot+0a7039d5d9986ff4ecec@syzkaller.appspotmail.com
Tested-by: syzbot+cc0cc52e7f43dc9e6df1@syzkaller.appspotmail.com
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>1 parent e6ed54e commit 6fe26f6
File tree
5 files changed
+80
-59
lines changed- include/net/bluetooth
- net/bluetooth
5 files changed
+80
-59
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
546 | 546 | | |
547 | 547 | | |
548 | 548 | | |
| 549 | + | |
549 | 550 | | |
550 | 551 | | |
551 | 552 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2485 | 2485 | | |
2486 | 2486 | | |
2487 | 2487 | | |
| 2488 | + | |
2488 | 2489 | | |
2489 | 2490 | | |
2490 | 2491 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1447 | 1447 | | |
1448 | 1448 | | |
1449 | 1449 | | |
1450 | | - | |
1451 | | - | |
1452 | 1450 | | |
1453 | 1451 | | |
1454 | 1452 | | |
1455 | 1453 | | |
1456 | | - | |
1457 | | - | |
1458 | 1454 | | |
1459 | 1455 | | |
1460 | 1456 | | |
1461 | 1457 | | |
1462 | 1458 | | |
1463 | 1459 | | |
1464 | | - | |
1465 | | - | |
| 1460 | + | |
1466 | 1461 | | |
1467 | 1462 | | |
1468 | 1463 | | |
| |||
1476 | 1471 | | |
1477 | 1472 | | |
1478 | 1473 | | |
1479 | | - | |
1480 | | - | |
1481 | 1474 | | |
1482 | 1475 | | |
1483 | 1476 | | |
| |||
1486 | 1479 | | |
1487 | 1480 | | |
1488 | 1481 | | |
1489 | | - | |
| 1482 | + | |
1490 | 1483 | | |
1491 | 1484 | | |
1492 | 1485 | | |
1493 | 1486 | | |
1494 | 1487 | | |
1495 | | - | |
| 1488 | + | |
1496 | 1489 | | |
1497 | 1490 | | |
1498 | 1491 | | |
| |||
1532 | 1525 | | |
1533 | 1526 | | |
1534 | 1527 | | |
1535 | | - | |
| 1528 | + | |
1536 | 1529 | | |
1537 | 1530 | | |
1538 | 1531 | | |
| |||
1707 | 1700 | | |
1708 | 1701 | | |
1709 | 1702 | | |
1710 | | - | |
| 1703 | + | |
1711 | 1704 | | |
1712 | 1705 | | |
1713 | 1706 | | |
| |||
1943 | 1936 | | |
1944 | 1937 | | |
1945 | 1938 | | |
1946 | | - | |
1947 | | - | |
| 1939 | + | |
| 1940 | + | |
1948 | 1941 | | |
1949 | 1942 | | |
1950 | 1943 | | |
| |||
1954 | 1947 | | |
1955 | 1948 | | |
1956 | 1949 | | |
1957 | | - | |
| 1950 | + | |
1958 | 1951 | | |
1959 | 1952 | | |
1960 | 1953 | | |
| |||
2074 | 2067 | | |
2075 | 2068 | | |
2076 | 2069 | | |
2077 | | - | |
2078 | | - | |
| 2070 | + | |
| 2071 | + | |
2079 | 2072 | | |
2080 | 2073 | | |
2081 | 2074 | | |
2082 | | - | |
| 2075 | + | |
2083 | 2076 | | |
2084 | 2077 | | |
2085 | 2078 | | |
| |||
2138 | 2131 | | |
2139 | 2132 | | |
2140 | 2133 | | |
2141 | | - | |
| 2134 | + | |
2142 | 2135 | | |
2143 | 2136 | | |
2144 | 2137 | | |
| |||
2638 | 2631 | | |
2639 | 2632 | | |
2640 | 2633 | | |
2641 | | - | |
| 2634 | + | |
2642 | 2635 | | |
2643 | 2636 | | |
2644 | 2637 | | |
| |||
3427 | 3420 | | |
3428 | 3421 | | |
3429 | 3422 | | |
3430 | | - | |
| 3423 | + | |
3431 | 3424 | | |
3432 | 3425 | | |
3433 | 3426 | | |
| |||
5186 | 5179 | | |
5187 | 5180 | | |
5188 | 5181 | | |
5189 | | - | |
| 5182 | + | |
5190 | 5183 | | |
5191 | 5184 | | |
5192 | 5185 | | |
| |||
5401 | 5394 | | |
5402 | 5395 | | |
5403 | 5396 | | |
5404 | | - | |
| 5397 | + | |
5405 | 5398 | | |
5406 | 5399 | | |
5407 | 5400 | | |
| |||
5777 | 5770 | | |
5778 | 5771 | | |
5779 | 5772 | | |
5780 | | - | |
| 5773 | + | |
5781 | 5774 | | |
5782 | 5775 | | |
5783 | 5776 | | |
| |||
5998 | 5991 | | |
5999 | 5992 | | |
6000 | 5993 | | |
6001 | | - | |
| 5994 | + | |
6002 | 5995 | | |
6003 | 5996 | | |
6004 | 5997 | | |
| |||
6223 | 6216 | | |
6224 | 6217 | | |
6225 | 6218 | | |
6226 | | - | |
| 6219 | + | |
6227 | 6220 | | |
6228 | 6221 | | |
6229 | 6222 | | |
| |||
6233 | 6226 | | |
6234 | 6227 | | |
6235 | 6228 | | |
6236 | | - | |
| 6229 | + | |
6237 | 6230 | | |
6238 | 6231 | | |
6239 | 6232 | | |
| |||
6577 | 6570 | | |
6578 | 6571 | | |
6579 | 6572 | | |
6580 | | - | |
| 6573 | + | |
6581 | 6574 | | |
6582 | 6575 | | |
6583 | 6576 | | |
| |||
6714 | 6707 | | |
6715 | 6708 | | |
6716 | 6709 | | |
6717 | | - | |
| 6710 | + | |
6718 | 6711 | | |
6719 | 6712 | | |
6720 | 6713 | | |
| |||
7161 | 7154 | | |
7162 | 7155 | | |
7163 | 7156 | | |
7164 | | - | |
| 7157 | + | |
7165 | 7158 | | |
7166 | 7159 | | |
7167 | 7160 | | |
| |||
7321 | 7314 | | |
7322 | 7315 | | |
7323 | 7316 | | |
7324 | | - | |
| 7317 | + | |
7325 | 7318 | | |
7326 | 7319 | | |
7327 | 7320 | | |
| |||
8571 | 8564 | | |
8572 | 8565 | | |
8573 | 8566 | | |
8574 | | - | |
| 8567 | + | |
8575 | 8568 | | |
8576 | 8569 | | |
8577 | | - | |
| 8570 | + | |
8578 | 8571 | | |
8579 | 8572 | | |
8580 | 8573 | | |
| |||
8762 | 8755 | | |
8763 | 8756 | | |
8764 | 8757 | | |
8765 | | - | |
| 8758 | + | |
8766 | 8759 | | |
8767 | 8760 | | |
8768 | | - | |
| 8761 | + | |
8769 | 8762 | | |
8770 | 8763 | | |
8771 | 8764 | | |
| |||
8912 | 8905 | | |
8913 | 8906 | | |
8914 | 8907 | | |
8915 | | - | |
| 8908 | + | |
8916 | 8909 | | |
8917 | 8910 | | |
8918 | | - | |
| 8911 | + | |
8919 | 8912 | | |
8920 | 8913 | | |
8921 | 8914 | | |
| |||
9074 | 9067 | | |
9075 | 9068 | | |
9076 | 9069 | | |
9077 | | - | |
| 9070 | + | |
9078 | 9071 | | |
9079 | 9072 | | |
9080 | | - | |
| 9073 | + | |
9081 | 9074 | | |
9082 | 9075 | | |
9083 | 9076 | | |
| |||
9349 | 9342 | | |
9350 | 9343 | | |
9351 | 9344 | | |
9352 | | - | |
| 9345 | + | |
9353 | 9346 | | |
9354 | 9347 | | |
9355 | 9348 | | |
| |||
9387 | 9380 | | |
9388 | 9381 | | |
9389 | 9382 | | |
9390 | | - | |
| 9383 | + | |
| 9384 | + | |
9391 | 9385 | | |
9392 | 9386 | | |
9393 | 9387 | | |
| |||
9402 | 9396 | | |
9403 | 9397 | | |
9404 | 9398 | | |
9405 | | - | |
| 9399 | + | |
| 9400 | + | |
9406 | 9401 | | |
9407 | 9402 | | |
9408 | 9403 | | |
| |||
9416 | 9411 | | |
9417 | 9412 | | |
9418 | 9413 | | |
9419 | | - | |
| 9414 | + | |
9420 | 9415 | | |
9421 | 9416 | | |
9422 | 9417 | | |
| |||
9657 | 9652 | | |
9658 | 9653 | | |
9659 | 9654 | | |
9660 | | - | |
9661 | 9655 | | |
9662 | 9656 | | |
9663 | 9657 | | |
| |||
9713 | 9707 | | |
9714 | 9708 | | |
9715 | 9709 | | |
9716 | | - | |
9717 | | - | |
| 9710 | + | |
| 9711 | + | |
9718 | 9712 | | |
9719 | 9713 | | |
9720 | 9714 | | |
| |||
9907 | 9901 | | |
9908 | 9902 | | |
9909 | 9903 | | |
9910 | | - | |
| 9904 | + | |
9911 | 9905 | | |
9912 | 9906 | | |
9913 | 9907 | | |
| |||
9917 | 9911 | | |
9918 | 9912 | | |
9919 | 9913 | | |
9920 | | - | |
9921 | | - | |
| 9914 | + | |
| 9915 | + | |
9922 | 9916 | | |
9923 | 9917 | | |
9924 | 9918 | | |
| |||
9942 | 9936 | | |
9943 | 9937 | | |
9944 | 9938 | | |
9945 | | - | |
9946 | | - | |
9947 | | - | |
| 9939 | + | |
| 9940 | + | |
| 9941 | + | |
| 9942 | + | |
| 9943 | + | |
| 9944 | + | |
9948 | 9945 | | |
9949 | 9946 | | |
9950 | 9947 | | |
| |||
0 commit comments