linux/net/bluetooth
Chengfeng Ye ebe6674292 Bluetooth: RFCOMM: serialize session teardown
rfcomm_kill_listener() walks session_list and deletes every session
without holding rfcomm_mutex, unlike the normal session processing and
connect error paths.

Under normal operation, an open RFCOMM socket pins rfcomm.ko, so
rfcomm_kill_listener() does not run concurrently with rfcomm_dlc_open().
However, forced module unload via delete_module(O_TRUNC) can stop
krfcommd while a failed connect is still unwinding.

  connect task                    forced unload / krfcommd
  ------------                    ------------------------
  rfcomm_lock()
  rfcomm_session_add()
                                  delete_module("rfcomm", O_TRUNC)
                                  rfcomm_kill_listener()
                                    fetch session from session_list
  kernel_connect() fails
  rfcomm_session_del()
    remove and free session
                                  rfcomm_session_del(session)

The final call then reads the freed session and may corrupt the list.

KASAN reported with mdelay() to enlarge critical window:

  BUG: KASAN: slab-use-after-free in rfcomm_run+0x3802/0x3f00 [rfcomm]
  Read of size 8 at addr ffff888111058d40 by task krfcommd/79
  Tainted: [R]=FORCED_RMMOD
  Allocated by task 86:
   rfcomm_session_add+0xa1/0x300 [rfcomm]
   rfcomm_dlc_open+0x8b2/0xf30 [rfcomm]
   rfcomm_sock_connect+0x34c/0x530 [rfcomm]
  Freed by task 86:
   kfree+0x121/0x3c0
   rfcomm_dlc_open+0xab7/0xf30 [rfcomm]
   rfcomm_sock_connect+0x34c/0x530 [rfcomm]

Hold rfcomm_mutex across the teardown traversal so every reachable
session_list walk uses the same serialization.

Reviewed-by: Ali Ahmet Memis <ali@iusegentoo.com>
Tested-by: Ali Ahmet Memis <ali@iusegentoo.com>
Reviewed-by: Pauli Virtanen <pav@iki.fi>
Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2026-08-24 13:14:43 -04:00
..
bnep Bluetooth: fix BT dependency for submodules 2026-08-07 15:38:30 -04:00
hidp Bluetooth: fix BT dependency for submodules 2026-08-07 15:38:30 -04:00
rfcomm Bluetooth: RFCOMM: serialize session teardown 2026-08-24 13:14:43 -04:00
6lowpan.c Bluetooth: add annotations for l2cap_data locking context 2026-08-07 15:38:32 -04:00
af_bluetooth.c Bluetooth: af_bluetooth: Add minimal context analysis annotations 2026-08-07 12:26:02 -04:00
aosp.c Bluetooth: aosp: Fix typo in comment 2025-07-23 10:30:18 -04:00
aosp.h Bluetooth: aosp: Support AOSP Bluetooth Quality Report 2021-11-02 19:37:52 +01:00
coredump.c Bluetooth: coredump: Expose header size and end marker to drivers 2026-08-07 15:40:26 -04:00
ecdh_helper.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
ecdh_helper.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
eir.c Bluetooth: eir: Fix OOB read in eir_get_service_data() 2026-08-24 13:10:27 -04:00
eir.h Bluetooth: eir: Fix possible crashes on eir_create_adv_data 2025-06-11 16:29:22 -04:00
hci_codec.c Bluetooth: hci: validate codec capability element length 2026-06-11 14:24:41 -04:00
hci_codec.h Bluetooth: Add support for Read Local Supported Codecs V2 2021-09-07 14:09:18 -07:00
hci_conn.c Bluetooth: hci_conn: re-enable advertising only for peripheral role 2026-08-24 13:11:33 -04:00
hci_core.c Bluetooth: hci_core: use skb_get() instead of skb_clone() for req_skb 2026-08-24 13:11:55 -04:00
hci_debugfs.c Bluetooth: simplify force_no_mitm_write() with kstrtobool_from_user() 2026-08-07 12:27:39 -04:00
hci_debugfs.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
hci_drv.c Bluetooth: Introduce HCI Driver protocol 2025-05-21 10:28:07 -04:00
hci_event.c Bluetooth: hci_event: clear HCI_LE_ADV only on a created connection 2026-08-24 13:11:42 -04:00
hci_sock.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
hci_sync.c Bluetooth: do not leak an hci_conn when a second LE connect is rejected 2026-08-24 13:14:35 -04:00
hci_sysfs.c Bluetooth: fix memory leak in error path of hci_alloc_dev() 2026-06-03 11:22:28 -04:00
iso.c Bluetooth: ISO: fix use-after-free of listener socket in iso_conn_ready 2026-08-24 13:13:06 -04:00
Kconfig Bluetooth: fix BT dependency for submodules 2026-08-07 15:38:30 -04:00
l2cap_core.c Bluetooth: add annotations for l2cap_data locking context 2026-08-07 15:38:32 -04:00
l2cap_sock.c Bluetooth: L2CAP: fix race l2cap_sock_cleanup_listen() vs. put_chan 2026-08-24 13:06:49 -04:00
leds.c Bluetooth: Use led_set_brightness() in LED trigger activate() callback 2024-09-10 13:06:11 -04:00
leds.h
lib.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
Makefile Bluetooth: enable context analysis 2026-08-07 12:27:20 -04:00
mgmt_config.c Bluetooth: mgmt: Add idle_timeout to configurable system parameters 2026-01-29 13:24:22 -05:00
mgmt_config.h Bluetooth: mgmt: Add commands for runtime configuration 2020-06-18 13:11:03 +03:00
mgmt_util.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
mgmt_util.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
mgmt.c Bluetooth: mgmt: fix 'hdev->discovery.uuids' NULL dereference 2026-08-24 13:06:39 -04:00
msft.c Bluetooth: MSFT: validate evt_prefix_len against the response length 2026-08-07 15:40:28 -04:00
msft.h Bluetooth: msft: fix slab-use-after-free in msft_do_close() 2024-05-03 13:05:28 -04:00
sco.c Bluetooth: SCO: give the socket its own sco_conn reference 2026-07-28 16:13:48 -04:00
selftest.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
selftest.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
smp.c Networking changes for 7.3. 2026-08-20 08:16:04 -07:00
smp.h Bluetooth: add annotations for l2cap_data locking context 2026-08-07 15:38:32 -04:00