public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v9] Bluetooth: mgmt: Fix race condition in mesh handling
@ 2026-02-14 13:06 Maiquel Paiva
  2026-02-14 14:02 ` [v9] " bluez.test.bot
  2026-02-17 18:50 ` [PATCH v9] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Maiquel Paiva @ 2026-02-14 13:06 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz, gregkh, marcel; +Cc: stable, Maiquel Paiva

This patch addresses race conditions in mesh handling within mgmt_util.c.

The functions mgmt_mesh_add and mgmt_mesh_find modify or traverse the
mesh_pending list without locking. This patch uses guard(mutex) with
the existing mgmt_pending_lock to protect the critical sections, as
suggested by maintainers in previous reviews.

Note: The heap buffer overflow fix previously included in earlier
versions of this patch series has already been merged upstream.

Fixes: b338d91703fa ("Bluetooth: Implement support for Mesh")
Cc: stable@vger.kernel.org
Signed-off-by: Maiquel Paiva <maiquelpaiva@gmail.com>
---
 net/bluetooth/mgmt_util.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/mgmt_util.c b/net/bluetooth/mgmt_util.c
index 6ccc3a3f68de..eee4bc05f6e5 100644
--- a/net/bluetooth/mgmt_util.c
+++ b/net/bluetooth/mgmt_util.c
@@ -397,8 +397,7 @@ struct mgmt_mesh_tx *mgmt_mesh_find(struct hci_dev *hdev, u8 handle)
 {
 	struct mgmt_mesh_tx *mesh_tx;
 
-	if (list_empty(&hdev->mesh_pending))
-		return NULL;
+	guard(mutex)(&hdev->mgmt_pending_lock);
 
 	list_for_each_entry(mesh_tx, &hdev->mesh_pending, list) {
 		if (mesh_tx->handle == handle)
@@ -420,6 +419,8 @@ struct mgmt_mesh_tx *mgmt_mesh_add(struct sock *sk, struct hci_dev *hdev,
 	if (!mesh_tx)
 		return NULL;
 
+	guard(mutex)(&hdev->mgmt_pending_lock);
+
 	hdev->mesh_send_ref++;
 	if (!hdev->mesh_send_ref)
 		hdev->mesh_send_ref++;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-17 18:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-14 13:06 [PATCH v9] Bluetooth: mgmt: Fix race condition in mesh handling Maiquel Paiva
2026-02-14 14:02 ` [v9] " bluez.test.bot
2026-02-17 18:50 ` [PATCH v9] " patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox