Skip to contentSkip to conversation

Bluetooth: MGMT: validate Add Extended Advertising Data length

PATCH Applied Michael Bommarito 4 participants 5 messages May 15 – Jun 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: MGMT: validate Add Extended Advertising Data length

MGMT_OP_ADD_EXT_ADV_DATA is registered as a variable-length command, with MGMT_ADD_EXT_ADV_DATA_SIZE as the fixed header size. The handler then uses cp->adv_data_len and cp->scan_rsp_len to validate and copy cp->data, but it never checks that those bytes are part of the mgmt command payload.

A short command can therefore make add_ext_adv_data() pass an out-of-bounds pointer into tlv_data_is_valid(). If the bytes beyond the command buffer are addressable, they can also be copied into the advertising instance as scan response data, where the caller can read them back via MGMT_OP_GET_ADV_INSTANCE. The trigger requires CAP_NET_ADMIN in the initial user namespace; KASAN reports an 8-byte slab-out-of-bounds read.

Reject commands whose length does not match the fixed header plus both advertising data lengths before parsing cp->data.

Fixes 12410572833a ("Bluetooth: Break add adv into two mgmt commands")
Assisted-by Claude:claude-opus-4-7
---
 net/bluetooth/mgmt.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/bluetooth/mgmt.c +6 -0
index b05bb380e5f8..de5bd6b637b2 100644
@@ -9110,9 +9110,15 @@ static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data,
 	struct adv_info *adv_instance;
 	int err = 0;
 	struct mgmt_pending_cmd *cmd;
+	u16 expected_len;
 
 	BT_DBG("%s", hdev->name);
 
+	expected_len = struct_size(cp, data, cp->adv_data_len + cp->scan_rsp_len);
+	if (expected_len != data_len)
+		return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA,
+				       MGMT_STATUS_INVALID_PARAMS);
+
 	hci_dev_lock(hdev);
 
 	adv_instance = hci_find_adv_instance(hdev, cp->instance);
Signature · 1 line
2.53.0
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1095484

---Test result---

Test Summary:

CheckPatch                    PASS      0.53 seconds
GitLint                       PASS      0.22 seconds
SubjectPrefix                 PASS      0.08 seconds
BuildKernel                   PASS      24.24 seconds
CheckAllWarning               PASS      26.60 seconds
CheckSparse                   PASS      25.46 seconds
BuildKernel32                 PASS      23.27 seconds
TestRunnerSetup               PASS      519.32 seconds
TestRunner_mgmt-tester        PASS      2022.40 seconds
TestRunner_mesh-tester        PASS      59.05 seconds
IncrementalBuild              PASS      22.61 seconds

https://github.com/bluez/bluetooth-next/pull/197

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Michael Bommarito
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 14 lines · On Fri, 15 May 2026 10:38:19 -0400 you wrote:

MGMT_OP_ADD_EXT_ADV_DATA is registered as a variable-length command, with MGMT_ADD_EXT_ADV_DATA_SIZE as the fixed header size. The handler then uses cp->adv_data_len and cp->scan_rsp_len to validate and copy cp->data, but it never checks that those bytes are part of the mgmt command payload.

A short command can therefore make add_ext_adv_data() pass an out-of-bounds pointer into tlv_data_is_valid(). If the bytes beyond the command buffer are addressable, they can also be copied into the advertising instance as scan response data, where the caller can read them back via MGMT_OP_GET_ADV_INSTANCE. The trigger requires CAP_NET_ADMIN in the initial user namespace; KASAN reports an 8-byte slab-out-of-bounds read.

Quoted 1 line

[...]

Here is the summary with links:
- Bluetooth: MGMT: validate Add Extended Advertising Data length

    https://git.kernel.org/bluetooth/bluetooth-next/c/8f5b6b4b198e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#3 lore raw
In reply to Michael Bommarito

Hi,

Quoted 32 lines · Michael Bommarito

MGMT_OP_ADD_EXT_ADV_DATA is registered as a variable-length command, with MGMT_ADD_EXT_ADV_DATA_SIZE as the fixed header size. The handler then uses cp->adv_data_len and cp->scan_rsp_len to validate and copy cp->data, but it never checks that those bytes are part of the mgmt command payload.

A short command can therefore make add_ext_adv_data() pass an out-of-bounds pointer into tlv_data_is_valid(). If the bytes beyond the command buffer are addressable, they can also be copied into the advertising instance as scan response data, where the caller can read them back via MGMT_OP_GET_ADV_INSTANCE. The trigger requires CAP_NET_ADMIN in the initial user namespace; KASAN reports an 8-byte slab-out-of-bounds read.

Reject commands whose length does not match the fixed header plus both advertising data lengths before parsing cp->data.

Fixes 12410572833a ("Bluetooth: Break add adv into two mgmt commands")
Assisted-by Claude:claude-opus-4-7
---
 net/bluetooth/mgmt.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/bluetooth/mgmt.c +0 -0
index b05bb380e5f8..de5bd6b637b2 100644
@@ -9110,9 +9110,15 @@ static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data,
        struct adv_info *adv_instance;

net/bluetooth/mgmt.c static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data, · line 9120

Quoted 10 lines
net/bluetooth/mgmt.c +5 -0
        int err = 0;
        struct mgmt_pending_cmd *cmd;
+       u16 expected_len;
 
        BT_DBG("%s", hdev->name);
 
+       expected_len = struct_size(cp, data, cp->adv_data_len + cp->scan_rsp_len);
+       if (expected_len != data_len)
+               return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA,
+                                      MGMT_STATUS_INVALID_PARAMS);

So it appears this was never tested with the likes of bluetoothd/bluetoothctl> advertise on:

bluetoothd[40]: @ MGMT Command: Add Extende.. {0x0001} [hci0] 16:04:53.318270
Instance: 1
Advertising data length: 3
Advertising Data[3]:
02 01 06 ...
Flags: 0x06
LE General Discoverable Mode
BR/EDR Not Supported
Scan response length: 0
00 00 00 00 00 00 00 00 ........
<- Extra bytes
@ MGMT Event: Command Status (0x0002) plen 3 {0x0001} [hci0] 16:04:53.318287

      Add Extended Advertising Data (0x0055)
        Status: Invalid Parameters (0x0d)

That is probably a bug in bluetoothd but it breaks backward compatibility.

Quoted 6 lines
net/bluetooth/mgmt.c +0 -1
        hci_dev_lock(hdev);
 
        adv_instance = hci_find_adv_instance(hdev, cp->instance);
--

2.53.0

Signature · 1 line
Luiz Augusto von Dentz
#4 lore raw
Quoted 1 line · Luiz Augusto von Dentz

That is probably a bug in bluetoothd but it breaks backward compatibility.

Ah, darn. Should we config gate the kernel side to make it easier for distros to decide or make backport decisions easier? Or just hold back on pulling the change unless / until the bluetoothd issues are resolved?

Thanks,
Mike