Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH v1] Bluetooth: btintel: fix buffer over-read in fw payload
@ 2026-10-23  6:00 Catherine L
  2026-10-23  7:31 ` [v1] " bluez.test.bot
  2026-10-23 21:00 ` [PATCH v1] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Catherine L @ 2026-10-23  6:00 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: kiran.k, chethan.tumkur.narayan, Catherine L

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")
Signed-off-by: Catherine L <catherine.l@intel.com>
Tested-by: Kiran K <kiran.k@intel.com>
---
 drivers/bluetooth/btintel.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c
index f298c91f4f4e..d245fe4fb1e9 100644
--- a/drivers/bluetooth/btintel.c
+++ b/drivers/bluetooth/btintel.c
@@ -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;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [v1] Bluetooth: btintel: fix buffer over-read in fw payload
  2026-10-23  6:00 [PATCH v1] Bluetooth: btintel: fix buffer over-read in fw payload Catherine L
@ 2026-10-23  7:31 ` bluez.test.bot
  2026-10-23 21:00 ` [PATCH v1] " patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2026-10-23  7:31 UTC (permalink / raw)
  To: linux-bluetooth, catherine.l

[-- Attachment #1: Type: text/plain, Size: 1019 bytes --]

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] Bluetooth: btintel: fix buffer over-read in fw payload
  2026-10-23  6:00 [PATCH v1] Bluetooth: btintel: fix buffer over-read in fw payload Catherine L
  2026-10-23  7:31 ` [v1] " bluez.test.bot
@ 2026-10-23 21:00 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2026-10-23 21:00 UTC (permalink / raw)
  To: Catherine L; +Cc: linux-bluetooth, kiran.k, chethan.tumkur.narayan

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

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.
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-23 21:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23  6:00 [PATCH v1] Bluetooth: btintel: fix buffer over-read in fw payload Catherine L
2026-10-23  7:31 ` [v1] " bluez.test.bot
2026-10-23 21:00 ` [PATCH v1] " patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox