Linux bluetooth development
 help / color / mirror / Atom feed
From: Roland Schober <rolandschober1968@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Roland Schober <rolandschober1968@gmail.com>
Subject: [PATCH BlueZ v2 3/6] monitor: Fix PHY decoding of LE Ext Create Connection
Date: Thu, 19 Nov 2026 08:13:29 +0100	[thread overview]
Message-ID: <20261119071332.32424-4-rolandschober1968@gmail.com> (raw)
In-Reply-To: <20261119071332.32424-1-rolandschober1968@gmail.com>

The LE Extended Create Connection decoder reads one block of connection
parameters for each bit set in Initiating_PHYs without checking that the
command carries that many blocks, so a truncated command makes it decode
octets which are not part of it:

< HCI Command: LE Extended Create Connection (0x08|0x0043) plen 10
        ...
        Initiating PHYs: 0x01
        Entry 0: LE 1M
          Scan interval: 0.000 msec (0x0000)
          Scan window: 0.000 msec (0x0000)
          ...

Check the size of the command before decoding each block:

        Initiating PHYs: 0x01
          invalid packet size

Fixes: e29ef3b85116 ("monitor: Add LE Extended Scan commands decoding")
Assisted-by: Claude:claude-opus-5-5
---
 monitor/packet.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/monitor/packet.c b/monitor/packet.c
index 0adc0144a..ee9e63496 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -8816,7 +8816,8 @@ static const struct bitfield_data ext_conn_phys_table[] = {
 	{ }
 };
 
-static void print_ext_conn_phys(const void *data, uint8_t flags)
+static void print_ext_conn_phys(const void *data, uint8_t size,
+							uint8_t flags)
 {
 	const struct bt_hci_le_ext_create_conn *entry;
 	uint8_t mask = flags;
@@ -8827,9 +8828,16 @@ static void print_ext_conn_phys(const void *data, uint8_t flags)
 
 	for (i = 0; ext_conn_phys_table[i].str; i++) {
 		if (flags & (1 << ext_conn_phys_table[i].bit)) {
-			entry = data + bits_set * sizeof(*entry);
 			mask &= ~(1 << ext_conn_phys_table[i].bit);
 
+			if ((bits_set + 1) * sizeof(*entry) > size) {
+				print_text(COLOR_ERROR,
+						"  invalid packet size");
+				break;
+			}
+
+			entry = data + bits_set * sizeof(*entry);
+
 			print_field("Entry %d: %s", bits_set,
 						ext_conn_phys_table[i].str);
 			print_slot_625("  Scan interval", entry->scan_interval);
@@ -8880,7 +8888,7 @@ static void le_ext_create_conn_cmd(uint16_t index, const void *data,
 	print_own_addr_type(cmd->own_addr_type);
 	print_peer_addr_type("Peer address type", cmd->peer_addr_type);
 	print_addr("Peer address", cmd->peer_addr, cmd->peer_addr_type);
-	print_ext_conn_phys(cmd->data, cmd->phys);
+	print_ext_conn_phys(cmd->data, size - sizeof(*cmd), cmd->phys);
 }
 
 static const struct bitfield_data create_sync_cte_type[] = {
-- 
2.47.3


  parent reply	other threads:[~2026-11-19  7:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  7:13 [PATCH BlueZ v2 0/6] monitor: Decode Periodic Advertising with Responses Roland Schober
2026-11-19  7:13 ` [PATCH BlueZ v2 1/6] monitor: Fix handle decoding of status_handle_rsp Roland Schober
2026-11-19  7:13 ` [PATCH BlueZ v2 2/6] monitor: Fix data length of LE PA Report decoding Roland Schober
2026-11-19  7:13 ` Roland Schober [this message]
2026-11-19  7:13 ` [PATCH BlueZ v2 4/6] monitor: Split LE PA Report decoding into helpers Roland Schober
2026-11-19  7:13 ` [PATCH BlueZ v2 5/6] monitor: Add PAwR HCI commands decoding Roland Schober
2026-11-19  7:13 ` [PATCH BlueZ v2 6/6] monitor: Add PAwR HCI events decoding 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=20261119071332.32424-4-rolandschober1968@gmail.com \
    --to=rolandschober1968@gmail.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