Skip to content

Commit f5bf1cd

Browse files
kozdracarlescufi
authored andcommitted
bluetooth: host: Check bounds on num_completed_packets event
If an event with corrupted length arrives, the extra check makes the handler return early to avoid reading data out of bounds. Signed-off-by: Arkadiusz Kozdra <[email protected]>
1 parent 29cc07e commit f5bf1cd

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

subsys/bluetooth/host/hci_core.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,14 @@ static void hci_num_completed_packets(struct net_buf *buf)
425425
struct bt_hci_evt_num_completed_packets *evt = (void *)buf->data;
426426
int i;
427427

428+
if (sizeof(*evt) + sizeof(evt->h[0]) * evt->num_handles > buf->len) {
429+
LOG_ERR("evt num_handles (=%u) too large (%u > %u)",
430+
evt->num_handles,
431+
sizeof(*evt) + sizeof(evt->h[0]) * evt->num_handles,
432+
buf->len);
433+
return;
434+
}
435+
428436
LOG_DBG("num_handles %u", evt->num_handles);
429437

430438
for (i = 0; i < evt->num_handles; i++) {

0 commit comments

Comments
 (0)