* [PATCH v2 1/2] Bluetooth: L2CAP: check security before completing a BR/EDR connection
@ 2026-11-19 22:16 Luiz Augusto von Dentz
2026-11-19 22:16 ` [PATCH v2 2/2] Bluetooth: L2CAP: Don't offer deferred channels before security is met Luiz Augusto von Dentz
2026-11-20 0:04 ` [v2,1/2] Bluetooth: L2CAP: check security before completing a BR/EDR connection bluez.test.bot
0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2026-11-19 22:16 UTC (permalink / raw)
To: linux-bluetooth
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2 2/2] Bluetooth: L2CAP: Don't offer deferred channels before security is met
2026-11-19 22:16 [PATCH v2 1/2] Bluetooth: L2CAP: check security before completing a BR/EDR connection Luiz Augusto von Dentz
@ 2026-11-19 22:16 ` Luiz Augusto von Dentz
2026-11-20 0:04 ` [v2,1/2] Bluetooth: L2CAP: check security before completing a BR/EDR connection bluez.test.bot
1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2026-11-19 22:16 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
A BR/EDR channel is moved to BT_CONNECT2 as soon as the connection
request is answered as pending, no matter if it is waiting for the
information exchange, for the link security or for userspace to
authorize it, and the socket state follows the channel state.
bt_accept_poll() and bt_accept_dequeue() assume that a child in
BT_CONNECT2 of a listener using BT_DEFER_SETUP is waiting to be
authorized, so although the listener is only notified once the security
is met, a listener that doesn't wait for it can accept() the child and
then authorize it with recvmsg() while authentication is still pending.
l2cap_sock_defer() then moves the channel to BT_CONFIG and responds with
L2CAP_CR_SUCCESS, and if authentication fails afterwards the channel is
left open since l2cap_security_cfm() doesn't close channels in
BT_CONFIG.
Fix this by only moving the socket to BT_CONNECT2 when the channel is
offered to the listener with l2cap_sock_defer_cb(), which is only called
once the security is met, and by not letting accept() return a child of
a listener using BT_DEFER_SETUP while it is still in BT_OPEN. The child
stays in the accept queue so the backlog limit and the cleanup done when
the listener is closed are not affected.
Fixes: f66dc81f44d9 ("Bluetooth: Add support for deferring L2CAP connection setup")
Assisted-by: OpenCode:claude-fable-5.2
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
v2: New patch.
---
net/bluetooth/af_bluetooth.c | 6 +++++-
net/bluetooth/l2cap_sock.c | 10 +++++++++-
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 7758e9ea3848..81f4ee0223cc 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -330,8 +330,12 @@ struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock)
continue;
}
+ /* With deferred setup a child still in BT_OPEN has not been
+ * offered to the listener yet.
+ */
if (sk->sk_state == BT_CONNECTED || !newsock ||
- test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags)) {
+ (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags) &&
+ sk->sk_state != BT_OPEN)) {
bt_accept_unlink(sk);
if (newsock)
sock_graft(sk, newsock);
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index d5663a4642a9..57ada00f76eb 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1812,7 +1812,13 @@ static void l2cap_sock_state_change_cb(struct l2cap_chan *chan, int state,
lock_sock(sk);
- sk->sk_state = state;
+ /* BT_CONNECT2 also covers a channel still waiting for the information
+ * exchange or link security. Only l2cap_sock_defer_cb() moves the
+ * socket to BT_CONNECT2, once the channel can be offered to the
+ * listener.
+ */
+ if (state != BT_CONNECT2)
+ sk->sk_state = state;
if (err)
sk->sk_err = err;
@@ -1880,6 +1886,8 @@ static void l2cap_sock_defer_cb(struct l2cap_chan *chan)
lock_sock(sk);
+ sk->sk_state = BT_CONNECT2;
+
parent = bt_sk(sk)->parent;
if (parent)
parent->sk_data_ready(parent);
--
2.56.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [v2,1/2] Bluetooth: L2CAP: check security before completing a BR/EDR connection
2026-11-19 22:16 [PATCH v2 1/2] Bluetooth: L2CAP: check security before completing a BR/EDR connection Luiz Augusto von Dentz
2026-11-19 22:16 ` [PATCH v2 2/2] Bluetooth: L2CAP: Don't offer deferred channels before security is met Luiz Augusto von Dentz
@ 2026-11-20 0:04 ` bluez.test.bot
1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2026-11-20 0:04 UTC (permalink / raw)
To: linux-bluetooth, luiz.dentz
[-- Attachment #1: Type: text/plain, Size: 2475 bytes --]
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/series/1216713/
---Test result---
Test Summary:
CheckPatch FAIL 1.15 seconds
VerifyFixes PASS 0.07 seconds
VerifySignedoff PASS 0.06 seconds
GitLint PASS 0.39 seconds
SubjectPrefix PASS 0.12 seconds
BuildKernel PASS 23.40 seconds
CheckAllWarning PASS 26.48 seconds
CheckSparse PASS 29.21 seconds
BuildKernel32 PASS 23.70 seconds
CheckKernelLLVM PASS 25.68 seconds
TestRunnerSetup PASS 552.07 seconds
TestRunner_l2cap-tester PASS 15.43 seconds
TestRunner_iso-tester PASS 13.43 seconds
TestRunner_bnep-tester PASS 2.82 seconds
TestRunner_mgmt-tester PASS 84.92 seconds
TestRunner_rfcomm-tester PASS 4.08 seconds
TestRunner_sco-tester PASS 5.14 seconds
TestRunner_ioctl-tester PASS 4.24 seconds
TestRunner_mesh-tester PASS 4.15 seconds
TestRunner_smp-tester PASS 3.99 seconds
TestRunner_userchan-tester PASS 2.93 seconds
TestRunner_6lowpan-tester PASS 4.06 seconds
IncrementalBuild PASS 24.98 seconds
Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[v2,2/2] Bluetooth: L2CAP: Don't offer deferred channels before security is met
WARNING: Non-standard signature: Assisted-by:
#145:
Assisted-by: OpenCode:claude-fable-5.2
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2'
#145:
Assisted-by: OpenCode:claude-fable-5.2
total: 1 errors, 1 warnings, 0 checks, 35 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/15003387.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
https://github.com/bluez/bluetooth-next/pull/1162
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-20 0:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 22:16 [PATCH v2 1/2] Bluetooth: L2CAP: check security before completing a BR/EDR connection Luiz Augusto von Dentz
2026-11-19 22:16 ` [PATCH v2 2/2] Bluetooth: L2CAP: Don't offer deferred channels before security is met Luiz Augusto von Dentz
2026-11-20 0:04 ` [v2,1/2] Bluetooth: L2CAP: check security before completing a BR/EDR connection bluez.test.bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.