All of lore.kernel.org
 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 v4 03/10] monitor: Fix PHY decoding of LE Ext Create Connection
Date: Fri, 20 Nov 2026 07:38:49 +0100	[thread overview]
Message-ID: <20261120063856.16585-4-rolandschober1968@gmail.com> (raw)
In-Reply-To: <20261120063856.16585-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, and report
octets left over after the last block. The blocks are indexed through
a pointer to the block type, not by adding their size to a void
pointer:

        Initiating PHYs: 0x01
          invalid packet size

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

diff --git a/monitor/packet.c b/monitor/packet.c
index 0e40300fd..9814e0e96 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -8816,10 +8816,13 @@ 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 *entries = data;
 	const struct bt_hci_le_ext_create_conn *entry;
 	uint8_t mask = flags;
+	bool truncated = false;
 	int bits_set = 0;
 	int i;
 
@@ -8827,9 +8830,20 @@ 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 (truncated)
+				continue;
+
+			if ((bits_set + 1) * sizeof(*entry) > size) {
+				print_text(COLOR_ERROR,
+						"  invalid packet size");
+				truncated = true;
+				continue;
+			}
+
+			entry = &entries[bits_set];
+
 			print_field("Entry %d: %s", bits_set,
 						ext_conn_phys_table[i].str);
 			print_slot_625("  Scan interval", entry->scan_interval);
@@ -8852,6 +8866,12 @@ static void print_ext_conn_phys(const void *data, uint8_t flags)
 		}
 	}
 
+	if (!truncated && bits_set * sizeof(*entry) < size) {
+		print_text(COLOR_ERROR, "  invalid packet size");
+		packet_hexdump((const void *) &entries[bits_set],
+					size - bits_set * sizeof(*entry));
+	}
+
 	if (mask)
 		print_text(COLOR_UNKNOWN_ADV_FLAG, "  Unknown scanning PHYs"
 							" (0x%2.2x)", mask);
@@ -8880,7 +8900,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-20  6:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  6:38 [PATCH BlueZ v4 00/10] monitor: Decode Periodic Advertising with Responses Roland Schober
2026-11-20  6:38 ` [PATCH BlueZ v4 01/10] monitor: Fix handle decoding of status_handle_rsp Roland Schober
2026-11-20 14:51   ` monitor: Decode Periodic Advertising with Responses bluez.test.bot
2026-11-20  6:38 ` [PATCH BlueZ v4 02/10] monitor: Fix data length of LE PA Report decoding Roland Schober
2026-11-20  6:38 ` Roland Schober [this message]
2026-11-20  6:38 ` [PATCH BlueZ v4 04/10] monitor: Fix advertising handle of LE PA commands Roland Schober
2026-11-20  6:38 ` [PATCH BlueZ v4 05/10] monitor: Fix TX power and CTE Type of LE PA Report Roland Schober
2026-11-20  6:38 ` [PATCH BlueZ v4 06/10] monitor: Fix LE PAST Received decoding Roland Schober
2026-11-20  6:38 ` [PATCH BlueZ v4 07/10] monitor: Fix byte order of LE PA Sync Handle and Properties Roland Schober
2026-11-20  6:38 ` [PATCH BlueZ v4 08/10] monitor: Split LE PA Report decoding into helpers Roland Schober
2026-11-20  6:38 ` [PATCH BlueZ v4 09/10] monitor: Add PAwR HCI commands decoding Roland Schober
2026-11-20  6:38 ` [PATCH BlueZ v4 10/10] monitor: Add PAwR HCI events decoding Roland Schober
2026-11-20 15:34 ` [PATCH BlueZ v4 00/10] monitor: Decode Periodic Advertising with Responses Luiz Augusto von Dentz

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=20261120063856.16585-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.