From: Jakub Kicinski <kuba@kernel.org>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: davem@davemloft.net, linux-bluetooth@vger.kernel.org,
netdev@vger.kernel.org
Subject: Re: [GIT PULL] bluetooth 2025-09-20
Date: Sat, 20 Sep 2025 13:38:41 -0700 [thread overview]
Message-ID: <20250920133841.38a98746@kernel.org> (raw)
In-Reply-To: <20250920150453.2605653-1-luiz.dentz@gmail.com>
On Sat, 20 Sep 2025 11:04:53 -0400 Luiz Augusto von Dentz wrote:
> Bluetooth: MGMT: Fix possible UAFs
Are you amenable to rewriting this one? The conditional locking really
doesn't look great. It's just a few more lines for the caller to take
the lock, below completely untested but to illustrate..
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 1e7886ccee40..23cb19b9915d 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1358,8 +1358,10 @@ static int set_powered_sync(struct hci_dev *hdev, void *data)
struct mgmt_pending_cmd *cmd = data;
struct mgmt_mode cp;
+ mutex_lock(&hdev->mgmt_pending_lock);
+
/* Make sure cmd still outstanding. */
- if (!mgmt_pending_valid(hdev, cmd, false))
+ if (!__mgmt_pending_listed(hdev, cmd))
return -ECANCELED;
memcpy(&cp, cmd->param, sizeof(cp));
diff --git a/net/bluetooth/mgmt_util.c b/net/bluetooth/mgmt_util.c
index 258c22d38809..11b1d1667d08 100644
--- a/net/bluetooth/mgmt_util.c
+++ b/net/bluetooth/mgmt_util.c
@@ -320,28 +320,38 @@ void mgmt_pending_remove(struct mgmt_pending_cmd *cmd)
mgmt_pending_free(cmd);
}
-bool mgmt_pending_valid(struct hci_dev *hdev, struct mgmt_pending_cmd *cmd,
- bool remove_unlock)
+bool __mgmt_pending_listed(struct hci_dev *hdev, struct mgmt_pending_cmd *cmd)
{
struct mgmt_pending_cmd *tmp;
+ lockdep_assert_held(&hdev->mgmt_pending_lock);
if (!cmd)
return false;
- mutex_lock(&hdev->mgmt_pending_lock);
-
list_for_each_entry(tmp, &hdev->mgmt_pending, list) {
- if (cmd == tmp) {
- if (remove_unlock) {
- list_del(&cmd->list);
- mutex_unlock(&hdev->mgmt_pending_lock);
- }
+ if (cmd == tmp)
return true;
- }
}
+ return false;
+}
+
+bool mgmt_pending_valid(struct hci_dev *hdev, struct mgmt_pending_cmd *cmd)
+{
+ struct mgmt_pending_cmd *tmp;
+ bool listed;
+
+ if (!cmd)
+ return false;
+
+ mutex_lock(&hdev->mgmt_pending_lock);
+
+ listed = __mgmt_pending_listed(hdev, cmd);
+ if (listed)
+ list_del(&cmd->list);
mutex_unlock(&hdev->mgmt_pending_lock);
- return false;
+
+ return listed;
}
void mgmt_mesh_foreach(struct hci_dev *hdev,
next prev parent reply other threads:[~2025-09-20 20:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-20 15:04 [GIT PULL] bluetooth 2025-09-20 Luiz Augusto von Dentz
2025-09-20 20:38 ` Jakub Kicinski [this message]
2025-09-22 13:59 ` Luiz Augusto von Dentz
2025-09-22 19:34 ` Jakub Kicinski
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=20250920133841.38a98746@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=netdev@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;
as well as URLs for NNTP newsgroup(s).