linux/net/bluetooth
Chengfeng Ye c783399efc Bluetooth: RFCOMM: Fix session UAF in set_termios
rfcomm_tty_set_termios() tests dlc->session without rfcomm_mutex and
later passes the pointer to rfcomm_send_rpn(). The latter dereferences
both session->initiator and session->sock. Meanwhile, krfcommd can
unlink the DLC and free the session while holding rfcomm_mutex.

The race can proceed as follows:

  TTY ioctl task                 krfcommd
  --------------                 --------
  load dlc->session
  enter rfcomm_send_rpn()
                                 lock rfcomm_mutex
                                 clear dlc->session
                                 free session
                                 unlock rfcomm_mutex
  read session->initiator

KASAN reported:

  BUG: KASAN: slab-use-after-free in rfcomm_send_rpn+0x297/0x2a0
  Read of size 4 at addr ffff88810012a850 by task poc/92

  Call Trace:
   rfcomm_send_rpn+0x297/0x2a0
   rfcomm_tty_set_termios+0x50d/0x850
   tty_set_termios+0x596/0x950
   set_termios+0x46a/0x6e0
   tty_mode_ioctl+0x152/0xbd0
   tty_ioctl+0x915/0x1240
   __x64_sys_ioctl+0x134/0x1c0

  Allocated by task 92:
   rfcomm_session_add+0x9e/0x2e0
   rfcomm_dlc_open+0x8b1/0xe00
   rfcomm_dev_activate+0x85/0x1a0
   rfcomm_tty_open+0x90/0x280

  Freed by task 68:
   kfree+0x131/0x3c0
   rfcomm_session_del+0x119/0x180
   rfcomm_run+0x737/0x4710

Add rfcomm_dlc_send_rpn(), which holds rfcomm_mutex while it verifies
that the DLC is still attached and sends the RPN frame. Have the TTY
path use the helper and drop its unlocked session check. This keeps the
session valid through both the frame construction and socket send.

Fixes: 3a5e903c09 ("[Bluetooth]: Implement RFCOMM remote port negotiation")
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-07-20 17:41:07 -04:00
..
bnep Bluetooth: bnep: pin L2CAP connection during netdev registration 2026-07-06 10:46:57 -04:00
hidp Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
rfcomm Bluetooth: RFCOMM: Fix session UAF in set_termios 2026-07-20 17:41:07 -04:00
6lowpan.c Bluetooth: L2CAP: Fix use-after-free in l2cap_sock_new_connection_cb() 2026-07-06 10:46:58 -04:00
af_bluetooth.c Bluetooth: fix UAF in bt_accept_dequeue() 2026-07-06 10:46:57 -04:00
aosp.c Bluetooth: aosp: Fix typo in comment 2025-07-23 10:30:18 -04:00
aosp.h
coredump.c Bluetooth: hci_devcd_dump: fix out-of-bounds via dev_coredumpv 2025-07-23 10:33:57 -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 stack OOB write when prepending the Flags AD 2026-06-11 14:24:40 -04:00
eir.h
hci_codec.c Bluetooth: hci: validate codec capability element length 2026-06-11 14:24:41 -04:00
hci_codec.h
hci_conn.c Bluetooth: hci_conn: Fix null ptr deref in hci_abort_conn() 2026-07-06 10:46:57 -04:00
hci_core.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
hci_debugfs.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -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
hci_event.c Bluetooth: mgmt: Translate HCI reason in Device Disconnected event 2026-07-13 10:10:13 -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: hci_sync: Protect UUID list traversal 2026-07-20 17:34:40 -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 malformed ISO_END/CONT handling 2026-07-06 10:46:58 -04:00
Kconfig Bluetooth: SMP: Use AES-CMAC library API 2026-06-11 14:24:38 -04:00
l2cap_core.c Bluetooth: L2CAP: fix tx ident leak for commands without a response 2026-07-06 10:46:58 -04:00
l2cap_sock.c Bluetooth: L2CAP: Fix use-after-free in l2cap_sock_new_connection_cb() 2026-07-06 10:46:58 -04:00
leds.c
leds.h
lib.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
Makefile net: remove ISDN subsystem and Bluetooth CMTP 2026-04-23 10:24:02 -07:00
mgmt_config.c Bluetooth: mgmt: Add idle_timeout to configurable system parameters 2026-01-29 13:24:22 -05:00
mgmt_config.h
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: Translate HCI reason in Device Disconnected event 2026-07-13 10:10:13 -04:00
msft.c Bluetooth: MGMT: Fix adv monitor add failure cleanup 2026-07-06 10:46:57 -04:00
msft.h
sco.c Bluetooth: sco: Fix a race condition in sco_sock_timeout() 2026-07-06 10:46:57 -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 Bluetooth: L2CAP: Fix use-after-free in l2cap_sock_new_connection_cb() 2026-07-06 10:46:58 -04:00
smp.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00