linux/include/net/bluetooth
Chengfeng Ye 81a2345f19 Bluetooth: Serialize SMP remote OOB data access
build_pairing_cmd() looks up remote OOB data and copies its contents
without holding hdev->lock, which serializes the list's writers. After
SMP finds an entry, a concurrent management Remove Remote OOB Data
command can unlink and free it before SMP reads its present flag or
copies its random and confirmation values. Removal can also invalidate
an entry while the lookup is still traversing the list.

KASAN reported:

  BUG: KASAN: slab-use-after-free in build_pairing_cmd+0x948/0x9b0
  Call Trace:
   build_pairing_cmd+0x948/0x9b0
   smp_recv_cb+0x459f/0x8110
   l2cap_recv_frame+0xf14/0x9190
   l2cap_recv_acldata+0xa64/0xd40
   hci_rx_work+0x4ca/0x730

  Allocated by task 87:
   hci_add_remote_oob_data+0x11d/0x530
   add_remote_oob_data+0x282/0x400
   hci_sock_sendmsg+0x1033/0x1ea0

  Freed by task 93:
   hci_remote_oob_data_clear+0x108/0x1c0
   remove_remote_oob_data+0x198/0x220
   hci_sock_sendmsg+0x1033/0x1ea0

Taking hdev->lock in build_pairing_cmd() would recurse for callers that
already hold it and invert the device-to-L2CAP lock order on the receive
path. Add a per-device remote_oob_lock instead, held across the SMP
lookup and copies and by the add, remove and clear helpers. Cover
initialization and in-place updates as well, so SMP cannot read partially
initialized or updated OOB values. Release the mutex on allocation
failure, preserving the existing error return.

The new critical sections acquire no device, connection or channel locks.
Writers retain their existing hdev->lock protection, which continues to
serialize the other readers without changing their locking or behavior.

Link: https://lore.kernel.org/r/00660cd3-7d71-13a4-f617-229e6defb701@gmail.com
Fixes: 02b05bd8b0 ("Bluetooth: Set SMP OOB flag if OOB data is available")
Cc: stable@vger.kernel.org
Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2026-09-28 11:00:20 -04:00
..
bluetooth.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
coredump.h Bluetooth: coredump: Quiesce dump work on unregister 2026-09-15 14:49:41 -04:00
hci_core.h Bluetooth: Serialize SMP remote OOB data access 2026-09-28 11:00:20 -04:00
hci_drv.h Bluetooth: Annotate struct hci_drv_rp_read_info with __counted_by_le() 2025-09-27 11:37:00 -04:00
hci_mon.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
hci_sock.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
hci_sync.h Bluetooth: Add MGMT Load Connection Subrate command 2026-08-07 15:38:32 -04:00
hci.h Bluetooth: hci_event: Use 255 as max event payload length in hci_ev_table[] 2026-08-07 15:40:27 -04:00
iso.h Bluetooth: ISO: Add broadcast support 2022-07-22 17:14:13 -07:00
l2cap.h Bluetooth: L2CAP: fix race l2cap_sock_cleanup_listen() vs. put_chan 2026-08-24 13:06:49 -04:00
mgmt.h Bluetooth: Add MGMT Load Connection Subrate command 2026-08-07 15:38:32 -04:00
rfcomm.h Bluetooth: RFCOMM: Fix session UAF in set_termios 2026-07-20 17:41:07 -04:00
sco.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00