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,
stable@vger.kernel.org, federico.kirschbaum@xbow.com
Subject: [PATCH v2 0/3] Bluetooth: MGMT: fix use-after-free of struct mgmt_mesh_tx
Date: Fri, 7 Aug 2026 19:15:26 +0900 [thread overview]
Message-ID: <20260807101529.17348-1-baul.lee@xbow.com> (raw)
hdev->mesh_pending is extended and walked from syscall context under
hdev->lock, and unlinked and freed from the hci_cmd_sync worker under
hci_req_sync_lock, so the list has no protection; the objects on it are
also handed to hci_cmd_sync_queue() as raw pointers, and those work
entries outlive the list. Three use-after-frees follow, all reproduced
under KASAN.
Patch 1 removes mgmt_cleanup(), the one walker of the list that cannot
take hdev->lock. Patch 2 puts the list under hdev->lock on the worker
side and asserts it in the helpers. Patch 3 gives the object a
reference count for the work entry. The order matters: the assertions
in patch 2 have no violating caller left once patch 1 is in, and the
reference in patch 3 is only well defined once every unlink happens
under one lock.
Reaching any of this needs CAP_NET_ADMIN in the init user namespace.
hci_sock.c sets HCI_SOCK_TRUSTED at bind under capable() rather than
ns_capable() and gates every later mgmt command on it, and the mesh
commands additionally need HCI_MESH_EXPERIMENTAL. Nothing in
hci_event.c touches hdev->mesh_pending.
Each reproducer was run at identical parameters on the unpatched and the
patched kernel, built with KASAN, PROVE_LOCKING, DEBUG_LIST and
DEBUG_ATOMIC_SLEEP: every splat the unpatched kernel produces is gone.
v2: rebased onto bluetooth-next, where send_cancel() no longer ends in
mgmt_pending_free(), so v1 did not apply for the CI. Context only,
no other change; v1 applies as posted to the bluetooth tree, which
still has that line.
Baul Lee (3):
Bluetooth: MGMT: remove the mesh walk from the socket destructor
Bluetooth: MGMT: protect hdev->mesh_pending with hdev->lock
Bluetooth: MGMT: reference-count struct mgmt_mesh_tx
include/net/bluetooth/bluetooth.h | 1 -
net/bluetooth/hci_sock.c | 1 -
net/bluetooth/mgmt.c | 72 ++++++++++++++++++++++++---------------
net/bluetooth/mgmt_util.c | 31 +++++++++++++++--
net/bluetooth/mgmt_util.h | 3 ++
5 files changed, 76 insertions(+), 32 deletions(-)
--
2.50.1 (Apple Git-155)
next 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 Baul Lee [this message]
2026-08-07 10:15 ` [PATCH v2 1/3] Bluetooth: MGMT: remove the mesh walk from the socket destructor Baul Lee
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-1-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