]> git.ipfire.org Git - thirdparty/linux.git/commit
Bluetooth: L2CAP: use chan timer to close channels in cleanup_listen()
authorSiwei Zhang <oss@fourdim.xyz>
Thu, 21 May 2026 02:12:20 +0000 (22:12 -0400)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 27 May 2026 20:44:01 +0000 (16:44 -0400)
commit8c8e620467a7b51562dbcefbd1f09f288d7d710d
tree947a53eadbec7a1cc42ce1498e01b7fc9e373e64
parent9dbd84990394c51f5cee1e8871bb5ff8af5ed939
Bluetooth: L2CAP: use chan timer to close channels in cleanup_listen()

l2cap_chan_close() removes the channel from conn->chan_l, which
must be done under conn->lock.  cleanup_listen() runs under the
parent sk_lock, so acquiring conn->lock would invert the
established conn->lock -> chan->lock -> sk_lock order.

Instead of calling l2cap_chan_close() directly, schedule
l2cap_chan_timeout with delay 0 to close the channel
asynchronously.  The timeout handler already acquires conn->lock
and chan->lock in the correct order.

The timer is only armed when chan->conn is still set: if it is
already NULL, l2cap_conn_del() has already processed this channel
(l2cap_chan_del + l2cap_sock_teardown_cb + l2cap_sock_close_cb),
so there is nothing left to do.  If l2cap_conn_del() races in
after the timer is armed, __clear_chan_timer() inside
l2cap_chan_del() cancels it; if the timer has already fired, the
handler returns harmlessly because chan->conn was cleared.

Fixes: 3df91ea20e74 ("Bluetooth: Revert to mutexes from RCU list")
Cc: <stable@vger.kernel.org> # 0b58004: Bluetooth: fix UAF in l2cap_sock_cleanup_listen() vs l2cap_conn_del()
Signed-off-by: Siwei Zhang <oss@fourdim.xyz>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
net/bluetooth/l2cap_sock.c