From: Baul Lee <baul.lee@xbow.com>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
Marcel Holtmann <marcel@holtmann.org>,
Brian Gix <brian.gix@intel.com>
Cc: Baul Lee <baul.lee@xbow.com>,
Luiz Augusto von Dentz <luiz.von.dentz@intel.com>,
Dmitry Antipov <dmantipov@yandex.ru>,
linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
federico.kirschbaum@xbow.com, stable@vger.kernel.org
Subject: [PATCH v2 1/3] Bluetooth: MGMT: remove the mesh walk from the socket destructor
Date: Fri, 7 Aug 2026 19:15:27 +0900 [thread overview]
Message-ID: <20260807101529.17348-2-baul.lee@xbow.com> (raw)
In-Reply-To: <20260807101529.17348-1-baul.lee@xbow.com>
hci_sock_destruct() calls mgmt_cleanup(), which walks hdev->mesh_pending
on every registered controller looking for entries owned by the socket
being destroyed, and completes the ones it finds.
It can never find one. mgmt_mesh_add() takes a reference on the owning
socket for every entry it links onto the list and mgmt_mesh_remove()
drops it again, so the socket's reference count cannot reach zero while
one of its entries is there.
The walk still races the list. mgmt_mesh_next() loads mesh_tx->sk from
every node it passes, including nodes owned by other sockets, while the
cmd_sync worker unlinks and frees nodes of the same list under a
different lock. mgmt_cleanup() cannot take hdev->lock: it holds
read_lock(&hci_dev_list_lock) across the walk, and hdev->lock sleeps.
It is the one user of hdev->mesh_pending that cannot be brought under
that lock.
Remove mgmt_cleanup() and its caller.
Discovered by XBOW, triaged by Baul Lee <baul.lee@xbow.com>
Fixes: b338d91703fa ("Bluetooth: Implement support for Mesh")
Cc: stable@vger.kernel.org
Signed-off-by: Baul Lee <baul.lee@xbow.com>
---
include/net/bluetooth/bluetooth.h | 1 -
net/bluetooth/hci_sock.c | 1 -
net/bluetooth/mgmt.c | 19 -------------------
3 files changed, 21 deletions(-)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index b624da5026f5..f49cec5f01e6 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -675,7 +675,6 @@ static inline bool iso_inited(void)
int mgmt_init(void);
void mgmt_exit(void);
-void mgmt_cleanup(struct sock *sk);
void bt_sock_reclassify_lock(struct sock *sk, int proto);
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 070ca388f9ac..5073f4fc3289 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -2164,7 +2164,6 @@ static int hci_sock_getsockopt(struct socket *sock, int level, int optname,
static void hci_sock_destruct(struct sock *sk)
{
- mgmt_cleanup(sk);
skb_queue_purge(&sk->sk_receive_queue);
skb_queue_purge(&sk->sk_write_queue);
skb_queue_purge(&sk->sk_error_queue);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 860c086011b7..97408904f74b 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -10894,22 +10894,3 @@ void mgmt_exit(void)
{
hci_mgmt_chan_unregister(&chan);
}
-
-void mgmt_cleanup(struct sock *sk)
-{
- struct mgmt_mesh_tx *mesh_tx;
- struct hci_dev *hdev;
-
- read_lock(&hci_dev_list_lock);
-
- list_for_each_entry(hdev, &hci_dev_list, list) {
- do {
- mesh_tx = mgmt_mesh_next(hdev, sk);
-
- if (mesh_tx)
- mesh_send_complete(hdev, mesh_tx, true);
- } while (mesh_tx);
- }
-
- read_unlock(&hci_dev_list_lock);
-}
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-08-07 10:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 10:15 [PATCH v2 0/3] Bluetooth: MGMT: fix use-after-free of struct mgmt_mesh_tx Baul Lee
2026-08-07 10:15 ` Baul Lee [this message]
2026-08-07 10:15 ` [PATCH v2 2/3] Bluetooth: MGMT: protect hdev->mesh_pending with hdev->lock Baul Lee
2026-08-07 10:15 ` [PATCH v2 3/3] Bluetooth: MGMT: reference-count struct mgmt_mesh_tx Baul Lee
2026-08-07 16:12 ` [PATCH v2 0/3] Bluetooth: MGMT: fix use-after-free of " Luiz Augusto von Dentz
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=20260807101529.17348-2-baul.lee@xbow.com \
--to=baul.lee@xbow.com \
--cc=brian.gix@intel.com \
--cc=dmantipov@yandex.ru \
--cc=federico.kirschbaum@xbow.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=luiz.von.dentz@intel.com \
--cc=marcel@holtmann.org \
--cc=stable@vger.kernel.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