From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v11 2/6] Bluetooth: L2CAP: Fix deferred LE channels being disconnected once accepted
Date: Tue, 1 Dec 2026 10:28:49 -0500 [thread overview]
Message-ID: <20261201152853.1118148-3-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261201152853.1118148-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
When userspace authorizes a deferred LE Credit Based or Enhanced Credit
Based channel, l2cap_sock_defer() moves it to BT_CONNECTED directly
instead of with l2cap_chan_ready(), so the timer armed when the request
was received is not stopped and CONF_NOT_COMPLETE is not cleared.
The timer then fires on the established channel and disconnects it, and
since CONF_NOT_COMPLETE is still set l2cap_chan_del() returns before
purging its tx queue.
Fix this by completing LE Credit Based channels with l2cap_chan_ready()
once the response is sent, as done for the ones that are not deferred.
Enhanced Credit Based channels stay in BT_CONNECTED while the response
of their request is pending, so their timer is stopped when they are
authorized, as only the channels still pending shall time out, and the
rest of what l2cap_chan_ready() does is done once the response is sent.
Fixes: 27e2d4c8d28b ("Bluetooth: Add basic LE L2CAP connect request receiving support")
Fixes: 15f02b910562 ("Bluetooth: L2CAP: Add initial code for Enhanced Credit Based Mode")
Assisted-by: OpenCode:claude-fable-5.2
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
net/bluetooth/l2cap_core.c | 18 ++++++++++++++++--
net/bluetooth/l2cap_sock.c | 6 ++++--
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 943effc86740..411b26b3de72 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -4042,6 +4042,11 @@ void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan)
l2cap_send_cmd(conn, chan->ident, L2CAP_LE_CONN_RSP, sizeof(rsp),
&rsp);
chan->ident = 0;
+
+ /* The response establishes the channel, which also stops its timer
+ * and completes its configuration like for one that is not deferred.
+ */
+ l2cap_chan_ready(chan);
}
static void l2cap_ecred_list_defer(struct l2cap_chan *chan, void *data)
@@ -4145,10 +4150,19 @@ static void l2cap_ecred_rsp_defer(struct l2cap_chan *chan, void *data)
rsp->pdu.rsp.result = cpu_to_le16(L2CAP_CR_LE_NO_MEM);
/* Include all channels pending with the same ident */
- if (!rsp->pdu.rsp.result)
+ if (!rsp->pdu.rsp.result) {
rsp_flex->dcid[rsp->count++] = cpu_to_le16(chan->scid);
- else
+
+ /* The response establishes the channel, which was already
+ * moved to BT_CONNECTED when userspace authorized it, so
+ * complete what l2cap_chan_ready() does.
+ */
+ chan->conf_state = 0;
+ if (!chan->tx_credits)
+ chan->ops->suspend(chan);
+ } else {
l2cap_chan_del(chan, ECONNRESET);
+ }
done:
if (locked)
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index d5663a4642a9..c1603495aab3 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1288,10 +1288,12 @@ static int l2cap_sock_defer(struct sock *sk)
sk->sk_state = BT_CONNECTED;
chan->state = BT_CONNECTED;
release_sock(sk);
+ /* The channel is accepted, only the ones still pending
+ * shall time out while waiting for the response.
+ */
+ __clear_chan_timer(chan);
__l2cap_ecred_conn_rsp_defer(chan);
} else if (bdaddr_type_is_le(chan->src_type)) {
- sk->sk_state = BT_CONNECTED;
- chan->state = BT_CONNECTED;
release_sock(sk);
__l2cap_le_connect_rsp_defer(chan);
} else {
--
2.56.0
next prev parent reply other threads:[~2026-12-01 15:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 15:28 [PATCH v11 0/6] L2CAP: Fix channels being established with insufficient security Luiz Augusto von Dentz
2026-12-01 15:28 ` [PATCH v11 1/6] Bluetooth: hci_event: Disconnect if the encryption key size is not valid Luiz Augusto von Dentz
2026-12-01 15:28 ` Luiz Augusto von Dentz [this message]
2026-12-01 15:28 ` [PATCH v11 3/6] Bluetooth: L2CAP: Fix rejecting all Enhanced Credit channels if one is refused Luiz Augusto von Dentz
2026-12-01 15:28 ` [PATCH v11 4/6] Bluetooth: L2CAP: Fix leaking sockets released before their channel is deleted Luiz Augusto von Dentz
2026-12-01 15:28 ` [PATCH v11 5/6] Bluetooth: L2CAP: Fix accepting channels with insufficient security Luiz Augusto von Dentz
2026-12-01 15:28 ` [PATCH v11 6/6] 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=20261201152853.1118148-3-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