Skip to content

Commit 15a9441

Browse files
Alain Michaudgregkh
Alain Michaud
authored andcommitted
Bluetooth: fix kernel oops in store_pending_adv_report
[ Upstream commit a2ec905 ] Fix kernel oops observed when an ext adv data is larger than 31 bytes. This can be reproduced by setting up an advertiser with advertisement larger than 31 bytes. The issue is not sensitive to the advertisement content. In particular, this was reproduced with an advertisement of 229 bytes filled with 'A'. See stack trace below. This is fixed by not catching ext_adv as legacy adv are only cached to be able to concatenate a scanable adv with its scan response before sending it up through mgmt. With ext_adv, this is no longer necessary. general protection fault: 0000 [#1] SMP PTI CPU: 6 PID: 205 Comm: kworker/u17:0 Not tainted 5.4.0-37-generic #41-Ubuntu Hardware name: Dell Inc. XPS 15 7590/0CF6RR, BIOS 1.7.0 05/11/2020 Workqueue: hci0 hci_rx_work [bluetooth] RIP: 0010:hci_bdaddr_list_lookup+0x1e/0x40 [bluetooth] Code: ff ff e9 26 ff ff ff 0f 1f 44 00 00 0f 1f 44 00 00 55 48 8b 07 48 89 e5 48 39 c7 75 0a eb 24 48 8b 00 48 39 f8 74 1c 44 8b 06 <44> 39 40 10 75 ef 44 0f b7 4e 04 66 44 39 48 14 75 e3 38 50 16 75 RSP: 0018:ffffbc6a40493c70 EFLAGS: 00010286 RAX: 4141414141414141 RBX: 000000000000001b RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffff9903e76c100f RDI: ffff9904289d4b28 RBP: ffffbc6a40493c70 R08: 0000000093570362 R09: 0000000000000000 R10: 0000000000000000 R11: ffff9904344eae38 R12: ffff9904289d4000 R13: 0000000000000000 R14: 00000000ffffffa3 R15: ffff9903e76c100f FS: 0000000000000000(0000) GS:ffff990434580000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007feed125a000 CR3: 00000001b860a003 CR4: 00000000003606e0 Call Trace: process_adv_report+0x12e/0x560 [bluetooth] hci_le_meta_evt+0x7b2/0xba0 [bluetooth] hci_event_packet+0x1c29/0x2a90 [bluetooth] hci_rx_work+0x19b/0x360 [bluetooth] process_one_work+0x1eb/0x3b0 worker_thread+0x4d/0x400 kthread+0x104/0x140 Fixes: c215e93 ("Bluetooth: Process extended ADV report event") Reported-by: Andy Nguyen <[email protected]> Reported-by: Linus Torvalds <[email protected]> Reported-by: Balakrishna Godavarthi <[email protected]> Signed-off-by: Alain Michaud <[email protected]> Tested-by: Sonny Sasaka <[email protected]> Acked-by: Marcel Holtmann <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent d9e8290 commit 15a9441

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

net/bluetooth/hci_event.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,9 @@ static void store_pending_adv_report(struct hci_dev *hdev, bdaddr_t *bdaddr,
13051305
{
13061306
struct discovery_state *d = &hdev->discovery;
13071307

1308+
if (len > HCI_MAX_AD_LENGTH)
1309+
return;
1310+
13081311
bacpy(&d->last_adv_addr, bdaddr);
13091312
d->last_adv_addr_type = bdaddr_type;
13101313
d->last_adv_rssi = rssi;
@@ -5317,7 +5320,8 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
53175320

53185321
static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
53195322
u8 bdaddr_type, bdaddr_t *direct_addr,
5320-
u8 direct_addr_type, s8 rssi, u8 *data, u8 len)
5323+
u8 direct_addr_type, s8 rssi, u8 *data, u8 len,
5324+
bool ext_adv)
53215325
{
53225326
struct discovery_state *d = &hdev->discovery;
53235327
struct smp_irk *irk;
@@ -5339,6 +5343,11 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
53395343
return;
53405344
}
53415345

5346+
if (!ext_adv && len > HCI_MAX_AD_LENGTH) {
5347+
bt_dev_err_ratelimited(hdev, "legacy adv larger than 31 bytes");
5348+
return;
5349+
}
5350+
53425351
/* Find the end of the data in case the report contains padded zero
53435352
* bytes at the end causing an invalid length value.
53445353
*
@@ -5398,7 +5407,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
53985407
*/
53995408
conn = check_pending_le_conn(hdev, bdaddr, bdaddr_type, type,
54005409
direct_addr);
5401-
if (conn && type == LE_ADV_IND) {
5410+
if (!ext_adv && conn && type == LE_ADV_IND && len <= HCI_MAX_AD_LENGTH) {
54025411
/* Store report for later inclusion by
54035412
* mgmt_device_connected
54045413
*/
@@ -5452,7 +5461,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
54525461
* event or send an immediate device found event if the data
54535462
* should not be stored for later.
54545463
*/
5455-
if (!has_pending_adv_report(hdev)) {
5464+
if (!ext_adv && !has_pending_adv_report(hdev)) {
54565465
/* If the report will trigger a SCAN_REQ store it for
54575466
* later merging.
54585467
*/
@@ -5487,7 +5496,8 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
54875496
/* If the new report will trigger a SCAN_REQ store it for
54885497
* later merging.
54895498
*/
5490-
if (type == LE_ADV_IND || type == LE_ADV_SCAN_IND) {
5499+
if (!ext_adv && (type == LE_ADV_IND ||
5500+
type == LE_ADV_SCAN_IND)) {
54915501
store_pending_adv_report(hdev, bdaddr, bdaddr_type,
54925502
rssi, flags, data, len);
54935503
return;
@@ -5527,7 +5537,7 @@ static void hci_le_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb)
55275537
rssi = ev->data[ev->length];
55285538
process_adv_report(hdev, ev->evt_type, &ev->bdaddr,
55295539
ev->bdaddr_type, NULL, 0, rssi,
5530-
ev->data, ev->length);
5540+
ev->data, ev->length, false);
55315541
} else {
55325542
bt_dev_err(hdev, "Dropping invalid advertising data");
55335543
}
@@ -5599,7 +5609,8 @@ static void hci_le_ext_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb)
55995609
if (legacy_evt_type != LE_ADV_INVALID) {
56005610
process_adv_report(hdev, legacy_evt_type, &ev->bdaddr,
56015611
ev->bdaddr_type, NULL, 0, ev->rssi,
5602-
ev->data, ev->length);
5612+
ev->data, ev->length,
5613+
!(evt_type & LE_EXT_ADV_LEGACY_PDU));
56035614
}
56045615

56055616
ptr += sizeof(*ev) + ev->length;
@@ -5797,7 +5808,8 @@ static void hci_le_direct_adv_report_evt(struct hci_dev *hdev,
57975808

57985809
process_adv_report(hdev, ev->evt_type, &ev->bdaddr,
57995810
ev->bdaddr_type, &ev->direct_addr,
5800-
ev->direct_addr_type, ev->rssi, NULL, 0);
5811+
ev->direct_addr_type, ev->rssi, NULL, 0,
5812+
false);
58015813

58025814
ptr += sizeof(*ev);
58035815
}

0 commit comments

Comments
 (0)