Bluetooth: hci_event: Fix checking for invalid handle on error status
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH 1/1 Bluetooth: hci_event: Fix checking for invalid handle on error status
From: Luiz Augusto von Dentz <[email protected]>
Commit d5ebaa7c5f6f6 introduces checks for handle range (e.g HCI_CONN_HANDLE_MAX) but controllers like Intel AX200 don't seem to respect the valid range in case of error status:
Quoted 1 line
HCI Event: Connect Complete (
0x03) plen 11
Status: Page Timeout (0x04)
Handle: 65535
Address: 94:DB:56:XX:XX:XX (Sony Home Entertainment&
Sound Products Inc)
Link type: ACL (0x01)
Encryption: Disabled (0x00)
[1644965.827560] Bluetooth: hci0: Ignoring HCI_Connection_Complete forinvalid handle
When the above happens it prevents to cleanup the connections since the stack would attempt to cancel the connection which is no longer in progress causing the following trace:
< HCI Command: Create Connection Cancel (0x01|0x0008) plen 6
Address: 94:DB:56:XX:XX:XX (Sony Home Entertainment& Sound Products Inc)
= bluetoothd: src/profile.c:record_cb() Unable to get Hands-Free Voice
gateway SDP record: Connection timed out
Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 10
Create Connection Cancel (0x01|0x0008) ncmd 1
Status: Unknown Connection Identifier (0x02)
Address: 94:DB:56:XX:XX:XX (Sony Home Entertainment& Sound Products Inc)
< HCI Command: Create Connection Cancel (0x01|0x0008) plen 6
Address: 94:DB:56:XX:XX:XX (Sony Home Entertainment& Sound Products Inc)
---
v2: Check if handle is valid just before assigning it to hci_conn object and in case it is invalid reset the status to HCI_ERROR_INVALID_PARAMETERS(0x12) so it can be passed to the likes of hci_connect_cfm and then is translated to EINVAL by bt_to_errno.
include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_event.c | 44 ++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 20 deletions(-)
include/net/bluetooth/hci.h +1 -0
@@ -587,6 +587,7 @@ enum {#define HCI_ERROR_CONNECTION_TIMEOUT 0x08#define HCI_ERROR_REJ_LIMITED_RESOURCES 0x0d#define HCI_ERROR_REJ_BAD_ADDR 0x0f +#define HCI_ERROR_INVALID_PARAMETERS 0x12#define HCI_ERROR_REMOTE_USER_TERM 0x13#define HCI_ERROR_REMOTE_LOW_RESOURCES 0x14#define HCI_ERROR_REMOTE_POWER_OFF 0x15
net/bluetooth/hci_event.c +24 -20
92 lines not on this page · raw message
Signature · 1 line
2.35.1
Luiz Augusto von Dentz
maintainerPATCH 1/1 Bluetooth: hci_event: Fix creating hci_conn object on error status
From: Luiz Augusto von Dentz <[email protected]>
It is useless to create a hci_conn object if on error status as the result would be it being freed in the process and anyway it is likely a result of controller and host stack being out of sync for some reason.
--- net/bluetooth/hci_event.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
net/bluetooth/hci_event.c +18 -5
@@ -3074,6 +3074,12 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data, conn =hci_conn_hash_lookup_ba (hdev, ev->link_type, &ev->bdaddr);if (!conn) { +/* In case of error status and there is no connection pending +* just unlock as there is nothing to cleanup. +*/ +if (ev->status) + goto unlock; +/* Connection may not exist if auto-connected. Check the bredr * allowlist to see if this device is allowed to auto connect. * If link is an ACL type, create a connection class
@@ -3120,8 +3126,8 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data,if (!ev->status) { conn->handle =__le16_to_cpu (ev->handle);if (conn->handle >HCI_CONN_HANDLE_MAX ) { -bt_dev_err (hdev,"Invalid handle: 0x%4.4x" , - conn->handle); +bt_dev_err (hdev,"Invalid handle: 0x%4.4x > 0x%4.4x" , + conn->handle,HCI_CONN_HANDLE_MAX ); ev->status =HCI_ERROR_INVALID_PARAMETERS ; goto done; }
@@ -4729,8 +4735,8 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev, void *data,case 0x00 : conn->handle =__le16_to_cpu (ev->handle);if (conn->handle >HCI_CONN_HANDLE_MAX ) { -bt_dev_err (hdev,"Invalid handle: 0x%4.4x" , - conn->handle); +bt_dev_err (hdev,"Invalid handle: 0x%4.4x > 0x%4.4x" , + conn->handle,HCI_CONN_HANDLE_MAX ); ev->status =HCI_ERROR_INVALID_PARAMETERS ; conn->state =BT_CLOSED ;break ;
@@ -5540,6 +5546,12 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, conn =hci_lookup_le_connect (hdev);if (!conn) { +/* In case of error status and there is no connection pending +* just unlock as there is nothing to cleanup. +*/ +if (status) + goto unlock; + conn =hci_conn_add (hdev,LE_LINK , bdaddr, role);if (!conn) {bt_dev_err (hdev,"no memory for new connection" );
@@ -5603,7 +5615,8 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, conn->dst_type =ev_bdaddr_type (hdev, conn->dst_type,NULL );if (handle >HCI_CONN_HANDLE_MAX ) { -bt_dev_err (hdev,"Invalid handle: 0x%4.4x" , conn->handle); +bt_dev_err (hdev,"Invalid handle: 0x%4.4x > 0x%4.4x" , handle, +HCI_CONN_HANDLE_MAX ); status =HCI_ERROR_INVALID_PARAMETERS ; }
Signature · 1 line
2.35.1
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=634373
---Test result---
Test Summary:
CheckPatch PASS 1.87 seconds GitLint FAIL 0.98 seconds SubjectPrefix PASS 0.89 seconds BuildKernel PASS 31.73 seconds BuildKernel32 PASS 27.95 seconds Incremental Build with patchesPASS 38.16 seconds TestRunner: Setup PASS 474.65 seconds TestRunner: l2cap-tester PASS 17.75 seconds TestRunner: bnep-tester PASS 6.35 seconds TestRunner: mgmt-tester PASS 105.77 seconds TestRunner: rfcomm-tester PASS 9.94 seconds TestRunner: sco-tester PASS 9.76 seconds TestRunner: smp-tester PASS 9.67 seconds TestRunner: userchan-tester PASS 6.59 seconds
Details
##############################
Test: GitLint - FAIL - 0.98 seconds
Run gitlint with rule in .gitlint
Bluetooth: hci_event: Fix checking for invalid handle on error status
13: B3 Line contains hard tab characters (\t): " Sound Products Inc)"
25: B3 Line contains hard tab characters (\t): " Sound Products Inc)"
27: B3 Line contains hard tab characters (\t): " gateway SDP record: Connection timed out"
32: B3 Line contains hard tab characters (\t): " Sound Products Inc)"
35: B3 Line contains hard tab characters (\t): " Sound Products Inc)"
---
Regards,
Linux Bluetooth