Bluetooth: L2CAP: Fix deadlock in l2cap_conn_del()
PATCH 1/1 Bluetooth: L2CAP: Fix deadlock in l2cap_conn_del()
From: Hyunwoo Kim <[email protected]>
[ Upstream commit 00fdebbbc557a2fc21321ff2eaa22fd70c078608 ]
l2cap_conn_del() calls cancel_delayed_work_sync() for both info_timer and id_addr_timer while holding conn->lock. However, the work functions l2cap_info_timeout() and l2cap_conn_update_id_addr() both acquire conn->lock, creating a potential AB-BA deadlock if the work is already executing when l2cap_conn_del() takes the lock.
Move the work cancellations before acquiring conn->lock and use disable_delayed_work_sync() to additionally prevent the works from being rearmed after cancellation, consistent with the pattern used in hci_conn_del().
--- net/bluetooth/l2cap_core.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/bluetooth/l2cap_core.c +3 -5
@@ -1756,6 +1756,9 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)BT_DBG ("hcon %p conn %p, err %d" , hcon, conn, err); +disable_delayed_work_sync (&conn->info_timer); +disable_delayed_work_sync (&conn->id_addr_timer); +mutex_lock (&conn->lock);kfree_skb (conn->rx_skb);
@@ -1769,8 +1772,6 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)if (work_pending (&conn->pending_rx_work))cancel_work_sync (&conn->pending_rx_work); -cancel_delayed_work_sync (&conn->id_addr_timer); -l2cap_unregister_all_users (conn);/* Force the connection to be immediately dropped */
@@ -1789,9 +1790,6 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)l2cap_chan_put (chan); } -if (conn->info_state &L2CAP_INFO_FEAT_MASK_REQ_SENT ) -cancel_delayed_work_sync (&conn->info_timer); -hci_chan_del (conn->hchan); conn->hchan =NULL ;
Signature · 1 line
2.43.0
Quoted 6 lines · Wenshan Lan
From: Hyunwoo Kim <[email protected]>
[ Upstream commit
00fdebbbc557a2fc21321ff2eaa22fd70c078608]
l2cap_conn_del()callscancel_delayed_work_sync()for bothinfo_timerandid_addr_timerwhile holdingconn->lock.
Queued for 6.12, thanks.
--
Sasha