]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Bluetooth: hci: validate codec capability element length
authorSamuel Moelius <sam.moelius@trailofbits.com>
Mon, 8 Jun 2026 23:56:28 +0000 (23:56 +0000)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 11 Jun 2026 18:24:41 +0000 (14:24 -0400)
Read Local Codec Capabilities returns a sequence of capability elements.
Each element starts with a one-byte length followed by that many payload
bytes.

hci_read_codec_capabilities() checks that the skb contains the length
byte, but then validates only caps->len against the remaining skb
length.  A malformed controller response with one remaining byte and
caps->len set to one passes that check even though the element needs two
bytes.  The parser then records a two-byte capability and copies one
byte beyond the advertised response payload into the codec list.

Validate the full element size, including the length byte, before adding
it to the accumulated capability length.  This preserves all well-formed
capability elements and drops only truncated controller responses.

Fixes: 8961987f3f5f ("Bluetooth: Enumerate local supported codec and cache details")
Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
net/bluetooth/hci_codec.c

index 3cc135bb1d30ca675053251b7b8b93c53d1d985b..5bc5003c387c66d5f51f8c8d138a18ef4d42932c 100644 (file)
@@ -100,7 +100,7 @@ static void hci_read_codec_capabilities(struct hci_dev *hdev, __u8 transport,
                                caps = (void *)skb->data;
                                if (skb->len < sizeof(*caps))
                                        goto error;
-                               if (skb->len < caps->len)
+                               if (skb->len < sizeof(caps->len) + caps->len)
                                        goto error;
                                len += sizeof(caps->len) + caps->len;
                                skb_pull(skb,  sizeof(caps->len) + caps->len);