Skip to content

Commit dcc403c

Browse files
jhedbergknutel-nordic
authored andcommitted
[nrf fromtree] Bluetooth: Host: Validate periodic advertising report length
The periodic advertising report handler checks that the event header is present and that the data fits in the reassembly buffer, but not that the event actually carries as many data bytes as its length field claims. With CONFIG_BT_PER_ADV_SYNC_BUF_SIZE > 0, a report with a length field larger than the remaining event payload makes net_buf_simple_add_mem() copy up to 255 bytes from beyond the end of the HCI event buffer into the reassembly buffer, and the result is passed on to the application. Drop such reports the same way as reports that do not fit in the reassembly buffer. Fixes #117587 Assisted-by: Claude:claude-fable-5 Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com> (cherry picked from commit e9c3252)
1 parent 9fa15fa commit dcc403c

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

subsys/bluetooth/host/scan.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,16 @@ static void bt_hci_le_per_adv_report_common(struct net_buf *buf)
11051105

11061106
if (!per_adv_sync->report_truncated) {
11071107
#if CONFIG_BT_PER_ADV_SYNC_BUF_SIZE > 0
1108+
if (evt->length > buf->len) {
1109+
/* The event does not carry the data it claims. Drop the report */
1110+
LOG_WRN("Periodic adv report corrupted (wants %u out of %u)", evt->length,
1111+
buf->len);
1112+
1113+
per_adv_sync->report_truncated = true;
1114+
net_buf_simple_reset(&per_adv_sync->reassembly);
1115+
return;
1116+
}
1117+
11081118
if (net_buf_simple_tailroom(&per_adv_sync->reassembly) < evt->length) {
11091119
/* The buffer is too small for the entire report. Drop it */
11101120
LOG_WRN("Buffer is too small to reassemble the report. "

0 commit comments

Comments
 (0)