Linux bluetooth development
 help / color / mirror / Atom feed
From: Oliver Neukum <oneukum@suse.com>
To: marcel@holtmann.org, luiz.dentz@gmail.com,
	linux-bluetooth@vger.kernel.org
Cc: Oliver Neukum <oneukum@suse.com>
Subject: [PATCH] Bluetooth: L2CAP: avoid deadlock with process_pending_rx
Date: Tue,  7 Jul 2026 14:36:56 +0200	[thread overview]
Message-ID: <20260707123656.76552-1-oneukum@suse.com> (raw)

The fix for the deadlock caused by cancelling works taking a lock
while holding the same lock in l2cap_conn_del()
shifted the cancellation of info_timer and id_addr_timer to a time
before taking the lock. However, it left cancelling
pending_rx_work() inside the scope of the lock. process_pending_rx(),
however, also takes the lock. It can deadlock.
Shift the cancellation to before the lock, too.

Signed-off-by: Oliver Neukum <oneukum@suse.com>
Fixes: ab4eedb790cae ("Bluetooth: L2CAP: Fix corrupted list in hci_chan_del")
---
 net/bluetooth/l2cap_core.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 62133eef9d2f..4b144eefdd33 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1772,8 +1772,14 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)
 
 	BT_DBG("hcon %p conn %p, err %d", hcon, conn, err);
 
+	/*
+	 * these take conn->lock
+	 * Hence a synchronous cancellation
+	 * would deadlock if done with the lock held
+	 */
 	disable_delayed_work_sync(&conn->info_timer);
 	disable_delayed_work_sync(&conn->id_addr_timer);
+	disable_work_sync(&conn->pending_rx_work);
 
 	mutex_lock(&conn->lock);
 
@@ -1781,13 +1787,6 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)
 
 	skb_queue_purge(&conn->pending_rx);
 
-	/* We can not call flush_work(&conn->pending_rx_work) here since we
-	 * might block if we are running on a worker from the same workqueue
-	 * pending_rx_work is waiting on.
-	 */
-	if (work_pending(&conn->pending_rx_work))
-		cancel_work_sync(&conn->pending_rx_work);
-
 	ida_destroy(&conn->tx_ida);
 
 	l2cap_unregister_all_users(conn);
-- 
2.54.0


             reply	other threads:[~2026-07-07 12:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 12:36 Oliver Neukum [this message]
2026-07-07 15:12 ` Bluetooth: L2CAP: avoid deadlock with process_pending_rx bluez.test.bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260707123656.76552-1-oneukum@suse.com \
    --to=oneukum@suse.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox