From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v2 2/2] Bluetooth: L2CAP: Don't offer deferred channels before security is met
Date: Thu, 19 Nov 2026 17:16:07 -0500 [thread overview]
Message-ID: <20261119221607.1311815-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261119221607.1311815-1-luiz.dentz@gmail.com>
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
prev parent 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 [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 [this message]
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-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