[PATCH v2 2/2] Bluetooth: hci_core: preserve LE feature holds across encryption events
From: Andrei A. Bykov
Date: Tue Nov 24 2026 - 09:11:33 EST
LE feature discovery now owns its connection hold until its asynchronous
completion callback. Encryption Change and Key Refresh Complete can run
while that discovery is pending in BT_CONFIG. Neither path owns a second
setup hold, so dropping one there consumes the upper-layer hold after
feature discovery finishes and disconnects an active ATT connection.
Keep the BT_CONFIG drop for BR/EDR, whose configuration path still owns
that hold. Route LE key refresh through the same confirmation helper.
On LE setup failure, explicitly request disconnection instead of relying
on a drop of the feature worker-owned hold. The abort request records
abort_reason before queuing its work. Do not let a later encryption or
feature-complete event announce such a connection as successful while
that abort is pending. Apply the check to both LE feature event formats.
The feature worker still releases its own hold and device reference.
Fixes: a106e50be74b ("Bluetooth: HCI: Add support for LL Extended Feature Set")
Signed-off-by: Andrei A. Bykov <andreiab9019@xxxxxxxxx>
---
include/net/bluetooth/hci_core.h | 9 ++++++++-
net/bluetooth/hci_event.c | 10 +++-------
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 7cf63bc0f..469d4f077 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -2272,11 +2272,18 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status)
__u8 encrypt;
if (conn->state == BT_CONFIG) {
+ if (conn->type == LE_LINK && conn->abort_reason)
+ return;
+
if (!status)
conn->state = BT_CONNECTED;
hci_connect_cfm(conn, status);
- hci_conn_drop(conn);
+ /* LE feature discovery releases its own hold asynchronously. */
+ if (conn->type != LE_LINK)
+ hci_conn_drop(conn);
+ else if (status)
+ hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
return;
}
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 477b876fd..b224d4d69 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -5435,11 +5435,7 @@ static void hci_key_refresh_complete_evt(struct hci_dev *hdev, void *data,
}
if (conn->state == BT_CONFIG) {
- if (!ev->status)
- conn->state = BT_CONNECTED;
-
- hci_connect_cfm(conn, ev->status);
- hci_conn_drop(conn);
+ hci_encrypt_cfm(conn, ev->status);
} else {
hci_auth_cfm(conn, ev->status);
@@ -6961,7 +6957,7 @@ static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev, void *data,
}
}
- if (conn->state == BT_CONFIG) {
+ if (conn->state == BT_CONFIG && !conn->abort_reason) {
__u8 status;
/* If the local controller supports peripheral-initiated
@@ -7639,7 +7635,7 @@ static void hci_le_read_all_remote_features_evt(struct hci_dev *hdev,
}
}
- if (conn->state == BT_CONFIG) {
+ if (conn->state == BT_CONFIG && !conn->abort_reason) {
__u8 status;
/* If the local controller supports peripheral-initiated
--
2.56.1