From: Jeremy Dean Clifton <deaner92@yahoo.com>
To: marcel@holtmann.org, luiz.dentz@gmail.com
Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
william.xuanziyang@huawei.com, johan.hedberg@intel.com,
hdanton@sina.com, Jeremy Dean Clifton <deaner92@yahoo.com>
Subject: [PATCH v2 2/3] Bluetooth: hci_conn: Refuse new connections once HCI_UP is cleared
Date: Tue, 17 Nov 2026 02:33:43 +0000 [thread overview]
Message-ID: <20261117023344.278269-3-deaner92@yahoo.com> (raw)
In-Reply-To: <20261117023344.278269-1-deaner92@yahoo.com>
hci_dev_close_sync() clears HCI_UP and later calls hci_conn_hash_flush()
to delete every connection. A connection created by __hci_conn_add()
after the flush has run is never deleted. It keeps the hci_dev_hold()
reference and the sysfs device taken in __hci_conn_add(), so the
hci_dev is never freed, and its works can still be queued after the
workqueue is drained.
Check HCI_UP in __hci_conn_add(), which serves both hci_conn_add() and
hci_conn_add_unset(). All callers hold hdev->lock: the HCI event
handlers, create_pa_complete() in hci_sync.c, and the l2cap, sco, iso
and mgmt paths that reach the hci_connect_*() and hci_bind_*() helpers.
hci_conn_hash_flush() runs under hdev->lock too, so a connection is
either added before the flush and deleted by it, or refused.
Also include lockdep_assert_held() so the locking rule is checked.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jeremy Dean Clifton <deaner92@yahoo.com>
---
net/bluetooth/hci_conn.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index d729a72f2f77..7f0250653189 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1001,6 +1001,15 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type,
struct hci_conn *conn;
struct smp_irk *irk = NULL;
+ lockdep_assert_held(&hdev->lock);
+
+ /* hci_dev_close_sync() clears HCI_UP before hci_conn_hash_flush().
+ * A connection added after that would never be flushed, so refuse
+ * it. The caller holds hdev->lock, which the flush also takes.
+ */
+ if (!test_bit(HCI_UP, &hdev->flags))
+ return ERR_PTR(-ENETDOWN);
+
switch (type) {
case ACL_LINK:
if (!hdev->acl_mtu)
--
2.43.0
next prev parent reply other threads:[~2026-11-17 2:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261117023344.278269-1-deaner92.ref@yahoo.com>
2026-11-17 2:33 ` [PATCH v2 0/3] Bluetooth: Fix work queued while hci_dev_close_sync() drains Jeremy Dean Clifton
2026-11-17 2:33 ` [PATCH v2 1/3] Bluetooth: hci_conn: Free the unset handle when adding a connection fails Jeremy Dean Clifton
2026-11-17 11:23 ` Bluetooth: Fix work queued while hci_dev_close_sync() drains bluez.test.bot
2026-11-17 2:33 ` Jeremy Dean Clifton [this message]
2026-11-17 2:33 ` [PATCH v2 3/3] Bluetooth: hci_sync: Disable connection works before draining Jeremy Dean Clifton
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=20261117023344.278269-3-deaner92@yahoo.com \
--to=deaner92@yahoo.com \
--cc=hdanton@sina.com \
--cc=johan.hedberg@intel.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=william.xuanziyang@huawei.com \
/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