Skip to contentSkip to conversation

Bluetooth: btintel: fix buffer over-read in fw payload

PATCH Applied Catherine L 3 participants 3 messages Oct 23 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: btintel: fix buffer over-read in fw payload

The firmware decoder cast fw_ptr + frag_len to struct hci_command_hdr and read cmd->plen before confirming the header and payload still fit in the remaining firmware buffer.

Add explicit bounds checks before each dereference:
1. Reject if the command header is not fully contained in remain.
2. Reject if the full command including payload exceeds remain.
3. Log the offending fragment length and remaining size before returning -EINVAL.

Fixes fbbe83c52bc0d ("Bluetooth: btintel: Create common function for firmware download")
---
 drivers/bluetooth/btintel.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/bluetooth/btintel.c +23 -1
index f298c91f4f4e..d245fe4fb1e9 100644
@@ -1185,7 +1185,29 @@ static int btintel_download_firmware_payload(struct hci_dev *hdev,
 	err = -EINVAL;
 
 	while (fw_ptr - fw->data < fw->size) {
-		struct hci_command_hdr *cmd = (void *)(fw_ptr + frag_len);
+		struct hci_command_hdr *cmd;
+		size_t remain = fw->size - (fw_ptr - fw->data);
+
+		/* Ensure the header fits before dereferencing */
+		if (frag_len + sizeof(*cmd) > remain) {
+			bt_dev_err(hdev,
+				   "Firmware buffer overrun at header (frag_len %u, need %zu, remain %zu)",
+				   frag_len, frag_len + sizeof(*cmd), remain);
+			err = -EINVAL;
+			goto done;
+		}
+
+		cmd = (void *)(fw_ptr + frag_len);
+
+		/* Ensure the full command (header + payload) fits before use */
+		if (frag_len + sizeof(*cmd) + cmd->plen > remain) {
+			bt_dev_err(hdev,
+				   "Firmware buffer overrun at payload (frag_len %u, plen %u, need %zu, remain %zu)",
+				   frag_len, cmd->plen,
+				   frag_len + sizeof(*cmd) + cmd->plen, remain);
+			err = -EINVAL;
+			goto done;
+		}
 
 		frag_len += sizeof(*cmd) + cmd->plen;
 
Signature · 1 line
2.43.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/series/1191810/

---Test result---

Test Summary:

CheckPatch                    PASS      0.61 seconds
VerifyFixes                   PASS      0.09 seconds
VerifySignedoff               PASS      0.09 seconds
GitLint                       PASS      0.26 seconds
SubjectPrefix                 PASS      0.09 seconds
BuildKernel                   PASS      28.40 seconds
CheckAllWarning               PASS      32.96 seconds
CheckSparse                   PASS      35.62 seconds
BuildKernel32                 PASS      31.70 seconds
CheckKernelLLVM               PASS      36.49 seconds
TestRunnerSetup               PASS      661.43 seconds
IncrementalBuild              PASS      27.86 seconds

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

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Catherine L
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 13 lines · On Fri, 23 Oct 2026 11:30:26 +0530 you wrote:

The firmware decoder cast fw_ptr + frag_len to struct hci_command_hdr and read cmd->plen before confirming the header and payload still fit in the remaining firmware buffer.

Add explicit bounds checks before each dereference:
1. Reject if the command header is not fully contained in remain.
2. Reject if the full command including payload exceeds remain.
3. Log the offending fragment length and remaining size before returning -EINVAL.

Quoted 1 line

[...]

Here is the summary with links:
- [v1] Bluetooth: btintel: fix buffer over-read in fw payload

    https://git.kernel.org/bluetooth/bluetooth-next/c/4891a9f76d0f

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html