Skip to content

Commit 2e63a2d

Browse files
committed
Merge tag 'for-net-2023-03-23' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth
Luiz Augusto von Dentz says: ==================== bluetooth pull request for net: - Fix MGMT add advmon with RSSI command - L2CAP: Fix responding with wrong PDU type - Fix race condition in hci_cmd_sync_clear - ISO: Fix timestamped HCI ISO data packet parsing - HCI: Fix global-out-of-bounds - hci_sync: Resume adv with no RPA when active scan * tag 'for-net-2023-03-23' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth: Bluetooth: HCI: Fix global-out-of-bounds Bluetooth: mgmt: Fix MGMT add advmon with RSSI command Bluetooth: btsdio: fix use after free bug in btsdio_remove due to unfinished work Bluetooth: L2CAP: Fix responding with wrong PDU type Bluetooth: btqcomsmd: Fix command timeout after setting BD address Bluetooth: btinel: Check ACPI handle for NULL before accessing Bluetooth: Remove "Power-on" check from Mesh feature Bluetooth: Fix race condition in hci_cmd_sync_clear Bluetooth: btintel: Iterate only bluetooth device ACPI entries Bluetooth: ISO: fix timestamped HCI ISO data packet parsing Bluetooth: btusb: Remove detection of ISO packets over bulk Bluetooth: hci_core: Detect if an ACL packet is in fact an ISO packet Bluetooth: hci_sync: Resume adv with no RPA when active scan ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 4f44d32 + bce5640 commit 2e63a2d

File tree

11 files changed

+206
-107
lines changed

11 files changed

+206
-107
lines changed

drivers/bluetooth/btintel.c

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@
2626
#define ECDSA_HEADER_LEN 320
2727

2828
#define BTINTEL_PPAG_NAME "PPAG"
29-
#define BTINTEL_PPAG_PREFIX "\\_SB_.PCI0.XHCI.RHUB"
29+
30+
/* structure to store the PPAG data read from ACPI table */
31+
struct btintel_ppag {
32+
u32 domain;
33+
u32 mode;
34+
acpi_status status;
35+
struct hci_dev *hdev;
36+
};
3037

3138
#define CMD_WRITE_BOOT_PARAMS 0xfc0e
3239
struct cmd_write_boot_params {
@@ -1295,17 +1302,16 @@ static acpi_status btintel_ppag_callback(acpi_handle handle, u32 lvl, void *data
12951302

12961303
status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
12971304
if (ACPI_FAILURE(status)) {
1298-
bt_dev_warn(hdev, "ACPI Failure: %s", acpi_format_exception(status));
1305+
bt_dev_warn(hdev, "PPAG-BT: ACPI Failure: %s", acpi_format_exception(status));
12991306
return status;
13001307
}
13011308

1302-
if (strncmp(BTINTEL_PPAG_PREFIX, string.pointer,
1303-
strlen(BTINTEL_PPAG_PREFIX))) {
1309+
len = strlen(string.pointer);
1310+
if (len < strlen(BTINTEL_PPAG_NAME)) {
13041311
kfree(string.pointer);
13051312
return AE_OK;
13061313
}
13071314

1308-
len = strlen(string.pointer);
13091315
if (strncmp((char *)string.pointer + len - 4, BTINTEL_PPAG_NAME, 4)) {
13101316
kfree(string.pointer);
13111317
return AE_OK;
@@ -1314,7 +1320,8 @@ static acpi_status btintel_ppag_callback(acpi_handle handle, u32 lvl, void *data
13141320

13151321
status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
13161322
if (ACPI_FAILURE(status)) {
1317-
bt_dev_warn(hdev, "ACPI Failure: %s", acpi_format_exception(status));
1323+
ppag->status = status;
1324+
bt_dev_warn(hdev, "PPAG-BT: ACPI Failure: %s", acpi_format_exception(status));
13181325
return status;
13191326
}
13201327

@@ -1323,8 +1330,9 @@ static acpi_status btintel_ppag_callback(acpi_handle handle, u32 lvl, void *data
13231330

13241331
if (p->type != ACPI_TYPE_PACKAGE || p->package.count != 2) {
13251332
kfree(buffer.pointer);
1326-
bt_dev_warn(hdev, "Invalid object type: %d or package count: %d",
1333+
bt_dev_warn(hdev, "PPAG-BT: Invalid object type: %d or package count: %d",
13271334
p->type, p->package.count);
1335+
ppag->status = AE_ERROR;
13281336
return AE_ERROR;
13291337
}
13301338

@@ -1335,6 +1343,7 @@ static acpi_status btintel_ppag_callback(acpi_handle handle, u32 lvl, void *data
13351343

13361344
ppag->domain = (u32)p->package.elements[0].integer.value;
13371345
ppag->mode = (u32)p->package.elements[1].integer.value;
1346+
ppag->status = AE_OK;
13381347
kfree(buffer.pointer);
13391348
return AE_CTRL_TERMINATE;
13401349
}
@@ -2314,42 +2323,48 @@ static int btintel_configure_offload(struct hci_dev *hdev)
23142323

23152324
static void btintel_set_ppag(struct hci_dev *hdev, struct intel_version_tlv *ver)
23162325
{
2317-
acpi_status status;
23182326
struct btintel_ppag ppag;
23192327
struct sk_buff *skb;
23202328
struct btintel_loc_aware_reg ppag_cmd;
2329+
acpi_handle handle;
23212330

2322-
/* PPAG is not supported if CRF is HrP2, Jfp2, JfP1 */
2331+
/* PPAG is not supported if CRF is HrP2, Jfp2, JfP1 */
23232332
switch (ver->cnvr_top & 0xFFF) {
23242333
case 0x504: /* Hrp2 */
23252334
case 0x202: /* Jfp2 */
23262335
case 0x201: /* Jfp1 */
23272336
return;
23282337
}
23292338

2339+
handle = ACPI_HANDLE(GET_HCIDEV_DEV(hdev));
2340+
if (!handle) {
2341+
bt_dev_info(hdev, "No support for BT device in ACPI firmware");
2342+
return;
2343+
}
2344+
23302345
memset(&ppag, 0, sizeof(ppag));
23312346

23322347
ppag.hdev = hdev;
2333-
status = acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
2334-
ACPI_UINT32_MAX, NULL,
2335-
btintel_ppag_callback, &ppag, NULL);
2348+
ppag.status = AE_NOT_FOUND;
2349+
acpi_walk_namespace(ACPI_TYPE_PACKAGE, handle, 1, NULL,
2350+
btintel_ppag_callback, &ppag, NULL);
23362351

2337-
if (ACPI_FAILURE(status)) {
2338-
/* Do not log warning message if ACPI entry is not found */
2339-
if (status == AE_NOT_FOUND)
2352+
if (ACPI_FAILURE(ppag.status)) {
2353+
if (ppag.status == AE_NOT_FOUND) {
2354+
bt_dev_dbg(hdev, "PPAG-BT: ACPI entry not found");
23402355
return;
2341-
bt_dev_warn(hdev, "PPAG: ACPI Failure: %s", acpi_format_exception(status));
2356+
}
23422357
return;
23432358
}
23442359

23452360
if (ppag.domain != 0x12) {
2346-
bt_dev_warn(hdev, "PPAG-BT Domain disabled");
2361+
bt_dev_warn(hdev, "PPAG-BT: domain is not bluetooth");
23472362
return;
23482363
}
23492364

23502365
/* PPAG mode, BIT0 = 0 Disabled, BIT0 = 1 Enabled */
23512366
if (!(ppag.mode & BIT(0))) {
2352-
bt_dev_dbg(hdev, "PPAG disabled");
2367+
bt_dev_dbg(hdev, "PPAG-BT: disabled");
23532368
return;
23542369
}
23552370

drivers/bluetooth/btintel.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,6 @@ struct intel_offload_use_cases {
137137
__u8 preset[8];
138138
} __packed;
139139

140-
/* structure to store the PPAG data read from ACPI table */
141-
struct btintel_ppag {
142-
u32 domain;
143-
u32 mode;
144-
struct hci_dev *hdev;
145-
};
146-
147140
struct btintel_loc_aware_reg {
148141
__le32 mcc;
149142
__le32 sel;

drivers/bluetooth/btqcomsmd.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ static int btqcomsmd_setup(struct hci_dev *hdev)
122122
return 0;
123123
}
124124

125+
static int btqcomsmd_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
126+
{
127+
int ret;
128+
129+
ret = qca_set_bdaddr_rome(hdev, bdaddr);
130+
if (ret)
131+
return ret;
132+
133+
/* The firmware stops responding for a while after setting the bdaddr,
134+
* causing timeouts for subsequent commands. Sleep a bit to avoid this.
135+
*/
136+
usleep_range(1000, 10000);
137+
return 0;
138+
}
139+
125140
static int btqcomsmd_probe(struct platform_device *pdev)
126141
{
127142
struct btqcomsmd *btq;
@@ -162,7 +177,7 @@ static int btqcomsmd_probe(struct platform_device *pdev)
162177
hdev->close = btqcomsmd_close;
163178
hdev->send = btqcomsmd_send;
164179
hdev->setup = btqcomsmd_setup;
165-
hdev->set_bdaddr = qca_set_bdaddr_rome;
180+
hdev->set_bdaddr = btqcomsmd_set_bdaddr;
166181

167182
ret = hci_register_dev(hdev);
168183
if (ret < 0)

drivers/bluetooth/btsdio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ static void btsdio_remove(struct sdio_func *func)
354354

355355
BT_DBG("func %p", func);
356356

357+
cancel_work_sync(&data->work);
357358
if (!data)
358359
return;
359360

drivers/bluetooth/btusb.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,21 +1050,11 @@ static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count)
10501050
hci_skb_expect(skb) -= len;
10511051

10521052
if (skb->len == HCI_ACL_HDR_SIZE) {
1053-
__u16 handle = __le16_to_cpu(hci_acl_hdr(skb)->handle);
10541053
__le16 dlen = hci_acl_hdr(skb)->dlen;
1055-
__u8 type;
10561054

10571055
/* Complete ACL header */
10581056
hci_skb_expect(skb) = __le16_to_cpu(dlen);
10591057

1060-
/* Detect if ISO packet has been sent over bulk */
1061-
if (hci_conn_num(data->hdev, ISO_LINK)) {
1062-
type = hci_conn_lookup_type(data->hdev,
1063-
hci_handle(handle));
1064-
if (type == ISO_LINK)
1065-
hci_skb_pkt_type(skb) = HCI_ISODATA_PKT;
1066-
}
1067-
10681058
if (skb_tailroom(skb) < hci_skb_expect(skb)) {
10691059
kfree_skb(skb);
10701060
skb = NULL;

include/net/bluetooth/hci_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,7 @@ void hci_conn_add_sysfs(struct hci_conn *conn);
16131613
void hci_conn_del_sysfs(struct hci_conn *conn);
16141614

16151615
#define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev))
1616+
#define GET_HCIDEV_DEV(hdev) ((hdev)->dev.parent)
16161617

16171618
/* ----- LMP capabilities ----- */
16181619
#define lmp_encrypt_capable(dev) ((dev)->features[0][0] & LMP_ENCRYPT)

net/bluetooth/hci_core.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,10 +2871,25 @@ int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb)
28712871
return -ENXIO;
28722872
}
28732873

2874-
if (hci_skb_pkt_type(skb) != HCI_EVENT_PKT &&
2875-
hci_skb_pkt_type(skb) != HCI_ACLDATA_PKT &&
2876-
hci_skb_pkt_type(skb) != HCI_SCODATA_PKT &&
2877-
hci_skb_pkt_type(skb) != HCI_ISODATA_PKT) {
2874+
switch (hci_skb_pkt_type(skb)) {
2875+
case HCI_EVENT_PKT:
2876+
break;
2877+
case HCI_ACLDATA_PKT:
2878+
/* Detect if ISO packet has been sent as ACL */
2879+
if (hci_conn_num(hdev, ISO_LINK)) {
2880+
__u16 handle = __le16_to_cpu(hci_acl_hdr(skb)->handle);
2881+
__u8 type;
2882+
2883+
type = hci_conn_lookup_type(hdev, hci_handle(handle));
2884+
if (type == ISO_LINK)
2885+
hci_skb_pkt_type(skb) = HCI_ISODATA_PKT;
2886+
}
2887+
break;
2888+
case HCI_SCODATA_PKT:
2889+
break;
2890+
case HCI_ISODATA_PKT:
2891+
break;
2892+
default:
28782893
kfree_skb(skb);
28792894
return -EINVAL;
28802895
}

net/bluetooth/hci_sync.c

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -643,13 +643,15 @@ void hci_cmd_sync_clear(struct hci_dev *hdev)
643643
cancel_work_sync(&hdev->cmd_sync_work);
644644
cancel_work_sync(&hdev->reenable_adv_work);
645645

646+
mutex_lock(&hdev->cmd_sync_work_lock);
646647
list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list) {
647648
if (entry->destroy)
648649
entry->destroy(hdev, entry->data, -ECANCELED);
649650

650651
list_del(&entry->list);
651652
kfree(entry);
652653
}
654+
mutex_unlock(&hdev->cmd_sync_work_lock);
653655
}
654656

655657
void __hci_cmd_sync_cancel(struct hci_dev *hdev, int err)
@@ -2367,6 +2369,45 @@ static int hci_resume_advertising_sync(struct hci_dev *hdev)
23672369
return err;
23682370
}
23692371

2372+
static int hci_pause_addr_resolution(struct hci_dev *hdev)
2373+
{
2374+
int err;
2375+
2376+
if (!use_ll_privacy(hdev))
2377+
return 0;
2378+
2379+
if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
2380+
return 0;
2381+
2382+
/* Cannot disable addr resolution if scanning is enabled or
2383+
* when initiating an LE connection.
2384+
*/
2385+
if (hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
2386+
hci_lookup_le_connect(hdev)) {
2387+
bt_dev_err(hdev, "Command not allowed when scan/LE connect");
2388+
return -EPERM;
2389+
}
2390+
2391+
/* Cannot disable addr resolution if advertising is enabled. */
2392+
err = hci_pause_advertising_sync(hdev);
2393+
if (err) {
2394+
bt_dev_err(hdev, "Pause advertising failed: %d", err);
2395+
return err;
2396+
}
2397+
2398+
err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00);
2399+
if (err)
2400+
bt_dev_err(hdev, "Unable to disable Address Resolution: %d",
2401+
err);
2402+
2403+
/* Return if address resolution is disabled and RPA is not used. */
2404+
if (!err && scan_use_rpa(hdev))
2405+
return err;
2406+
2407+
hci_resume_advertising_sync(hdev);
2408+
return err;
2409+
}
2410+
23702411
struct sk_buff *hci_read_local_oob_data_sync(struct hci_dev *hdev,
23712412
bool extended, struct sock *sk)
23722413
{
@@ -2402,7 +2443,7 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)
24022443
u8 filter_policy;
24032444
int err;
24042445

2405-
/* Pause advertising if resolving list can be used as controllers are
2446+
/* Pause advertising if resolving list can be used as controllers
24062447
* cannot accept resolving list modifications while advertising.
24072448
*/
24082449
if (use_ll_privacy(hdev)) {
@@ -3319,6 +3360,7 @@ static const struct hci_init_stage amp_init1[] = {
33193360
HCI_INIT(hci_read_flow_control_mode_sync),
33203361
/* HCI_OP_READ_LOCATION_DATA */
33213362
HCI_INIT(hci_read_location_data_sync),
3363+
{}
33223364
};
33233365

33243366
static int hci_init1_sync(struct hci_dev *hdev)
@@ -3353,6 +3395,7 @@ static int hci_init1_sync(struct hci_dev *hdev)
33533395
static const struct hci_init_stage amp_init2[] = {
33543396
/* HCI_OP_READ_LOCAL_FEATURES */
33553397
HCI_INIT(hci_read_local_features_sync),
3398+
{}
33563399
};
33573400

33583401
/* Read Buffer Size (ACL mtu, max pkt, etc.) */
@@ -5394,27 +5437,12 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval)
53945437

53955438
cancel_interleave_scan(hdev);
53965439

5397-
/* Pause advertising since active scanning disables address resolution
5398-
* which advertising depend on in order to generate its RPAs.
5399-
*/
5400-
if (use_ll_privacy(hdev) && hci_dev_test_flag(hdev, HCI_PRIVACY)) {
5401-
err = hci_pause_advertising_sync(hdev);
5402-
if (err) {
5403-
bt_dev_err(hdev, "pause advertising failed: %d", err);
5404-
goto failed;
5405-
}
5406-
}
5407-
5408-
/* Disable address resolution while doing active scanning since the
5409-
* accept list shall not be used and all reports shall reach the host
5410-
* anyway.
5440+
/* Pause address resolution for active scan and stop advertising if
5441+
* privacy is enabled.
54115442
*/
5412-
err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00);
5413-
if (err) {
5414-
bt_dev_err(hdev, "Unable to disable Address Resolution: %d",
5415-
err);
5443+
err = hci_pause_addr_resolution(hdev);
5444+
if (err)
54165445
goto failed;
5417-
}
54185446

54195447
/* All active scans will be done with either a resolvable private
54205448
* address (when privacy feature has been enabled) or non-resolvable

net/bluetooth/iso.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,6 @@ static void iso_disconn_cfm(struct hci_conn *hcon, __u8 reason)
16201620
void iso_recv(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
16211621
{
16221622
struct iso_conn *conn = hcon->iso_data;
1623-
struct hci_iso_data_hdr *hdr;
16241623
__u16 pb, ts, len;
16251624

16261625
if (!conn)
@@ -1642,22 +1641,28 @@ void iso_recv(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
16421641
}
16431642

16441643
if (ts) {
1644+
struct hci_iso_ts_data_hdr *hdr;
1645+
16451646
/* TODO: add timestamp to the packet? */
16461647
hdr = skb_pull_data(skb, HCI_ISO_TS_DATA_HDR_SIZE);
16471648
if (!hdr) {
16481649
BT_ERR("Frame is too short (len %d)", skb->len);
16491650
goto drop;
16501651
}
16511652

1653+
len = __le16_to_cpu(hdr->slen);
16521654
} else {
1655+
struct hci_iso_data_hdr *hdr;
1656+
16531657
hdr = skb_pull_data(skb, HCI_ISO_DATA_HDR_SIZE);
16541658
if (!hdr) {
16551659
BT_ERR("Frame is too short (len %d)", skb->len);
16561660
goto drop;
16571661
}
1662+
1663+
len = __le16_to_cpu(hdr->slen);
16581664
}
16591665

1660-
len = __le16_to_cpu(hdr->slen);
16611666
flags = hci_iso_data_flags(len);
16621667
len = hci_iso_data_len(len);
16631668

0 commit comments

Comments
 (0)