Linux bluetooth development
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v2 1/2] Bluetooth: L2CAP: check security before completing a BR/EDR connection
Date: Thu, 19 Nov 2026 17:16:06 -0500	[thread overview]
Message-ID: <20261119221607.1311815-1-luiz.dentz@gmail.com> (raw)

From: Mohammed Alquraini <mohammed.saad.alquraini@gmail.com>

A BR/EDR L2CAP service that listens with BT_DEFER_SETUP asks the kernel
to enforce its BT_SECURITY level and only decides which peer to admit.
l2cap_security_cfm() does not honour that for a channel in BT_CONNECT2.

When the security procedure reports success, the BT_CONNECT2 branch only
verifies the encryption key size before answering the pending connection
request with L2CAP_CR_PEND (deferred setup) or L2CAP_CR_SUCCESS. A
successful status doesn't mean the channel's security level is met
though, e.g. if the peer disables encryption while the channel is
waiting for userspace to authorize it, the channel is offered to the
listener again and, once authorized, it is established over an
unencrypted link.

The non-deferred incoming path already checks
l2cap_chan_check_security() before answering, and l2cap_conn_start()
does the same for BT_CONNECT2 channels; only the l2cap_security_cfm()
path was missed. This is the BR/EDR counterpart of commit 522e9ed157e3
("Bluetooth: l2cap: Check encryption key size on incoming connection").

Also require l2cap_chan_check_security() next to
l2cap_check_enc_key_size() in the BT_CONNECT2 branch of
l2cap_security_cfm(), so the channel is only accepted or deferred once
the link meets the required security level and encryption key size, and
is otherwise denied with L2CAP_CR_SEC_BLOCK.

AI assistance was used in finding and preparing this patch.

Fixes: f66dc81f44d9 ("Bluetooth: Add support for deferring L2CAP connection setup")
Signed-off-by: Mohammed Alquraini <mohammed.saad.alquraini@gmail.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
v2: Drop BT_SK_ACCEPTED and the changes to l2cap_sock_defer(), only check
    l2cap_chan_check_security() in the BT_CONNECT2 branch of
    l2cap_security_cfm(). The early accept is handled by patch 2/2.
---
 net/bluetooth/l2cap_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 943effc86740..6bf3a162f865 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -8143,7 +8143,8 @@ static void l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
 			struct l2cap_conn_rsp rsp;
 			__u16 res, stat;
 
-			if (!status && l2cap_check_enc_key_size(hcon, chan)) {
+			if (!status && l2cap_check_enc_key_size(hcon, chan) &&
+			    l2cap_chan_check_security(chan, false)) {
 				if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) {
 					res = L2CAP_CR_PEND;
 					stat = L2CAP_CS_AUTHOR_PEND;
-- 
2.56.0


             reply	other threads:[~2026-11-19 22:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 22:16 Luiz Augusto von Dentz [this message]
2026-11-19 22:16 ` [PATCH v2 2/2] 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=20261119221607.1311815-1-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