From: Catherine L <catherine.l@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: kiran.k@intel.com, chethan.tumkur.narayan@intel.com,
Catherine L <catherine.l@intel.com>
Subject: [PATCH v1] Bluetooth: btintel: fix buffer over-read in fw payload
Date: Fri, 23 Oct 2026 11:30:26 +0530 [thread overview]
Message-ID: <20261023060026.524147-1-catherine.l@intel.com> (raw)
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
next reply other threads:[~2026-10-23 6:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 6:00 Catherine L [this message]
2026-10-23 7:31 ` [v1] Bluetooth: btintel: fix buffer over-read in fw payload bluez.test.bot
2026-10-23 21:00 ` [PATCH v1] " patchwork-bot+bluetooth
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=20261023060026.524147-1-catherine.l@intel.com \
--to=catherine.l@intel.com \
--cc=chethan.tumkur.narayan@intel.com \
--cc=kiran.k@intel.com \
--cc=linux-bluetooth@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