From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v8 1/5] Bluetooth: hci_event: Disconnect if the encryption key size is not valid
Date: Mon, 30 Nov 2026 14:56:50 -0500 [thread overview]
Message-ID: <20261130195654.560637-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261130195654.560637-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
When the encryption key size can't be read, or is smaller than the
minimum, hci_conn_enc_key_size_set() clears the encryption flags,
downgrades the security level and notifies the upper layers with an
error, but unlike hci_change_encrypt() when the encryption fails it
doesn't disconnect the link.
The channels that were already established are not closed by the
upper layers for a status other than success, so they stay open over
a link that is not encrypted anymore.
Fix this by disconnecting the link with HCI_ERROR_AUTH_FAILURE, as
hci_change_encrypt() does, after notifying the upper layers.
Fixes: 04a342cc49a8 ("Bluetooth: Add more enc key size check")
Assisted-by: OpenCode:claude-fable-5.2
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
net/bluetooth/hci_event.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index a9b6a6ccaa03..7f86b71a3f80 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -782,6 +782,14 @@ static u8 hci_conn_enc_key_size_set(struct hci_dev *hdev, struct hci_conn *conn,
hci_encrypt_cfm(conn, status);
+ /* The link was reported as encrypted but it can't be used if the key
+ * size couldn't be read or is too small, so disconnect it as
+ * hci_change_encrypt() does when the encryption fails, now that the
+ * upper layers have been notified so they can cleanup.
+ */
+ if (status && conn->state == BT_CONNECTED)
+ hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
+
/* mgmt_security_level_changed() only reports the change for
* connections already announced to userspace (it checks
* HCI_CONN_MGMT_CONNECTED itself); otherwise it is a no-op here and
--
2.56.0
next prev parent reply other threads:[~2026-11-30 19:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 19:56 [PATCH v8 0/5] L2CAP: Fix channels being established with insufficient security Luiz Augusto von Dentz
2026-11-30 19:56 ` Luiz Augusto von Dentz [this message]
2026-11-30 19:56 ` [PATCH v8 2/5] Bluetooth: L2CAP: Fix rejecting all Enhanced Credit channels if one is refused Luiz Augusto von Dentz
2026-11-30 19:56 ` [PATCH v8 3/5] Bluetooth: L2CAP: Fix leaking sockets released before their channel is deleted Luiz Augusto von Dentz
2026-11-30 19:56 ` [PATCH v8 4/5] Bluetooth: L2CAP: Fix accepting channels with insufficient security Luiz Augusto von Dentz
2026-11-30 19:56 ` [PATCH v8 5/5] Bluetooth: L2CAP: Don't offer deferred channels before security is met Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130195654.560637-2-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox