From: Roland Schober <rolandschober1968@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: luiz.dentz@gmail.com, Roland Schober <rolandschober1968@gmail.com>
Subject: [RFC PATCH BlueZ v3 08/12] emulator/btdev: Check the length of PA commands
Date: Thu, 3 Dec 2026 23:15:28 +0100 [thread overview]
Message-ID: <20261203221532.682750-9-rolandschober1968@gmail.com> (raw)
In-Reply-To: <20261203221532.682750-1-rolandschober1968@gmail.com>
btdev hands a command of any length to its handler. The handlers of
LE Set Periodic Advertising Parameters, Data and Enable and of LE
Remove Advertising Set read their parameters without a look at the
length: a command which is too short makes them read beyond the
packet, and LE Set Periodic Advertising Data copies as many octets as
its length field says, whatever the command holds.
Answer a command of the wrong length with Invalid HCI Command
Parameters. The following patches add to these handlers.
Assisted-by: Claude:claude-fable-5-2
---
emulator/btdev.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/emulator/btdev.c b/emulator/btdev.c
index 7c6307180..3987972ac 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -5977,6 +5977,9 @@ static int cmd_remove_adv_set(struct btdev *dev, const void *data,
struct le_ext_adv *ext_adv;
uint8_t status = BT_HCI_ERR_SUCCESS;
+ if (len != sizeof(*cmd))
+ return -EINVAL;
+
ext_adv = queue_find(dev->le_ext_adv, match_ext_adv_handle,
UINT_TO_PTR(cmd->handle));
if (!ext_adv) {
@@ -6034,6 +6037,9 @@ static int cmd_set_pa_params(struct btdev *dev, const void *data,
const struct bt_hci_cmd_le_set_pa_params *cmd = data;
uint8_t status;
+ if (len != sizeof(*cmd))
+ return -EINVAL;
+
if (dev->le_pa_enable) {
status = BT_HCI_ERR_COMMAND_DISALLOWED;
} else {
@@ -6053,7 +6059,12 @@ static int cmd_set_pa_data(struct btdev *dev, const void *data,
{
const struct bt_hci_cmd_le_set_pa_data *cmd = data;
uint8_t status = BT_HCI_ERR_SUCCESS;
- uint8_t data_len = cmd->data_len;
+ uint8_t data_len;
+
+ if (len < sizeof(*cmd) || cmd->data_len != len - sizeof(*cmd))
+ return -EINVAL;
+
+ data_len = cmd->data_len;
if (data_len > MAX_PA_DATA_LEN)
data_len = MAX_PA_DATA_LEN;
@@ -6267,6 +6278,9 @@ static int cmd_set_pa_enable(struct btdev *dev, const void *data, uint8_t len)
uint8_t status;
int i;
+ if (len != sizeof(*cmd))
+ return -EINVAL;
+
if (dev->le_pa_enable == cmd->enable) {
status = BT_HCI_ERR_COMMAND_DISALLOWED;
} else {
--
2.47.3
next prev parent reply other threads:[~2026-12-03 22:16 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 22:15 [RFC PATCH BlueZ v3 00/12] Periodic advertising and PAwR over MGMT Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 01/12] doc/mgmt: Add PA and PAwR commands and events Roland Schober
2026-12-04 8:23 ` Periodic advertising and PAwR over MGMT bluez.test.bot
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 02/12] lib/mgmt: Add periodic advertising and PAwR definitions Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 03/12] monitor: Decode PA and PAwR MGMT commands and events Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 04/12] client/mgmt: Fix length of byte arrays with empty entries Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 05/12] client/mgmt: Refuse negative values in byte arrays Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 06/12] client/mgmt: Add pa-params, pa-data and pawr-serve commands Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 07/12] monitor: Add PAwR HCI definitions Roland Schober
2026-12-03 22:15 ` Roland Schober [this message]
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 09/12] emulator/btdev: Keep the advertising set after a timeout Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 10/12] emulator/btdev: Keep advertising sets with PA enabled Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 11/12] emulator/btdev: Add PAwR advertiser Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 12/12] mgmt-tester: Add periodic advertising and PAwR tests Roland Schober
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=20261203221532.682750-9-rolandschober1968@gmail.com \
--to=rolandschober1968@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.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