* [PATCH v17 0/2] Bluetooth: L2CAP: Fix LE credits resuming channels pending security
@ 2026-12-03 18:13 Luiz Augusto von Dentz
2026-12-03 18:14 ` [PATCH v17 1/2] Bluetooth: L2CAP: Restrict LE credits to connected CoCs Luiz Augusto von Dentz
2026-12-03 18:14 ` [PATCH v17 2/2] Bluetooth: L2CAP: Keep credits from completing security upgrades Luiz Augusto von Dentz
0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2026-12-03 18:13 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
An LE Flow Control Credit packet resumes the channel, which on a CoC
waiting for a security upgrade requested with BT_SECURITY drains queued
data and clears the socket suspension before the upgrade completes.
This version is a simplified rework of v16: rather than tracking the
upgrade with a separate work, an established CoC is now moved to
BT_CONFIG with FLAG_PENDING_SECURITY set, like ATT, while the upgrade is
pending, so credits are only accounted, not acted upon, and the existing
l2cap_security_cfm() path resumes or closes the channel once the upgrade
completes.
This set has a companion userspace set for BlueZ adding l2cap-tester
cases covering it:
[PATCH BlueZ v1 0/2] l2cap-tester: Add tests for changing LE security
with SMP pending
Changes in v17:
- Drop the security work, SMP hooks and the ECRED/BT_RCVMTU changes.
- Move established CoCs to BT_CONFIG while a BT_SECURITY upgrade is
pending and accept credits and data in that state.
v16: https://lore.kernel.org/linux-bluetooth/20261201022855.1483888-1-cochcoder@proton.me/
Kyle Pepper (2):
Bluetooth: L2CAP: Restrict LE credits to connected CoCs
Bluetooth: L2CAP: Keep credits from completing security upgrades
net/bluetooth/l2cap_core.c | 38 +++++++++++++++++++++++++++++++++++++-
net/bluetooth/l2cap_sock.c | 19 +++++++++++++++++--
2 files changed, 54 insertions(+), 3 deletions(-)
--
2.56.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v17 1/2] Bluetooth: L2CAP: Restrict LE credits to connected CoCs
2026-12-03 18:13 [PATCH v17 0/2] Bluetooth: L2CAP: Fix LE credits resuming channels pending security Luiz Augusto von Dentz
@ 2026-12-03 18:14 ` Luiz Augusto von Dentz
2026-12-03 18:14 ` [PATCH v17 2/2] Bluetooth: L2CAP: Keep credits from completing security upgrades Luiz Augusto von Dentz
1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2026-12-03 18:14 UTC (permalink / raw)
To: linux-bluetooth
From: Kyle Pepper <cochcoder@proton.me>
Do not let credit indications change fixed channels or complete pending
connection setup. Validate the channel state and mode before accounting
credits, checking overflow or invoking its resume callback.
Fixes: fad5fc89594d ("Bluetooth: Add LE flow control discipline")
Signed-off-by: Kyle Pepper <cochcoder@proton.me>
Assisted-by: OpenCode:claude-opus-5.5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
net/bluetooth/l2cap_core.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index edbfb775a375..211d6ad23774 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -5572,6 +5572,15 @@ static inline int l2cap_le_credits(struct l2cap_conn *conn,
l2cap_chan_lock(chan);
+ /* Credits are only accounted for established channels, including
+ * the ones waiting for a security upgrade requested with BT_SECURITY
+ * so the credits granted by the peer meanwhile are not lost.
+ */
+ if ((chan->state != BT_CONNECTED && chan->state != BT_CONFIG) ||
+ (chan->mode != L2CAP_MODE_LE_FLOWCTL &&
+ chan->mode != L2CAP_MODE_EXT_FLOWCTL))
+ goto unlock;
+
max_credits = LE_FLOWCTL_MAX_CREDITS - chan->tx_credits;
if (credits > max_credits) {
BT_ERR("LE credits overflow");
@@ -5585,6 +5594,12 @@ static inline int l2cap_le_credits(struct l2cap_conn *conn,
chan->tx_credits += credits;
+ /* Don't resume a channel with a pending security upgrade, it is
+ * resumed by l2cap_security_cfm() once the upgrade completes.
+ */
+ if (chan->state != BT_CONNECTED)
+ goto unlock;
+
/* Resume sending */
l2cap_le_flowctl_send(chan);
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v17 2/2] Bluetooth: L2CAP: Keep credits from completing security upgrades
2026-12-03 18:13 [PATCH v17 0/2] Bluetooth: L2CAP: Fix LE credits resuming channels pending security Luiz Augusto von Dentz
2026-12-03 18:14 ` [PATCH v17 1/2] Bluetooth: L2CAP: Restrict LE credits to connected CoCs Luiz Augusto von Dentz
@ 2026-12-03 18:14 ` Luiz Augusto von Dentz
1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2026-12-03 18:14 UTC (permalink / raw)
To: linux-bluetooth
From: Kyle Pepper <cochcoder@proton.me>
A credit indication can drain queued CoC data and clear socket suspension
while BT_SECURITY is waiting for stronger security. Keep the request
pending until the required encryption, level, key size and MIC are met.
Fixes: fad5fc89594d ("Bluetooth: Add LE flow control discipline")
Signed-off-by: Kyle Pepper <cochcoder@proton.me>
Assisted-by: OpenCode:claude-opus-5.5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
net/bluetooth/l2cap_core.c | 23 ++++++++++++++++++++++-
net/bluetooth/l2cap_sock.c | 19 +++++++++++++++++--
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 211d6ad23774..30233278c56d 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -2751,6 +2751,10 @@ static void l2cap_le_flowctl_send(struct l2cap_chan *chan)
BT_DBG("chan %p", chan);
+ /* Hold the data while a security upgrade is pending */
+ if (chan->state != BT_CONNECTED)
+ return;
+
while (chan->tx_credits && !skb_queue_empty(&chan->tx_q)) {
l2cap_do_send(chan, skb_dequeue(&chan->tx_q));
chan->tx_credits--;
@@ -7549,7 +7553,14 @@ static void l2cap_data_channel(struct l2cap_conn *conn, u16 cid,
if (chan->chan_type == L2CAP_CHAN_FIXED)
l2cap_chan_ready(chan);
- if (chan->state != BT_CONNECTED)
+ /* The peer may keep sending while a security upgrade requested on an
+ * established credit based channel is pending.
+ */
+ if (chan->state != BT_CONNECTED &&
+ !(chan->state == BT_CONFIG &&
+ test_bit(FLAG_PENDING_SECURITY, &chan->flags) &&
+ (chan->mode == L2CAP_MODE_LE_FLOWCTL ||
+ chan->mode == L2CAP_MODE_EXT_FLOWCTL)))
goto drop;
switch (chan->mode) {
@@ -8382,6 +8393,16 @@ static void l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
*/
if (!unmet)
chan->ops->resume(chan);
+
+ /* Send the data held while the upgrade was pending */
+ if (!unmet && chan->state == BT_CONNECTED &&
+ (chan->mode == L2CAP_MODE_LE_FLOWCTL ||
+ chan->mode == L2CAP_MODE_EXT_FLOWCTL)) {
+ l2cap_le_flowctl_send(chan);
+ if (!chan->tx_credits)
+ chan->ops->suspend(chan);
+ }
+
l2cap_check_encryption(chan, encrypt);
l2cap_chan_unlock(chan);
continue;
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 4e7787ec033c..739cda63b802 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1029,10 +1029,25 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) ||
sk->sk_state == BT_CONNECTED) {
l2cap_sock_set_sec_level(chan, sec.level);
- if (!l2cap_chan_check_security(chan, true))
+ if (!l2cap_chan_check_security(chan, true)) {
set_bit(BT_SK_SUSPEND, &bt_sk(sk)->flags);
- else
+
+ /* Like ATT, an established credit based channel
+ * is not ready until the upgrade completes, so
+ * credits and data don't resume it early. The
+ * socket stays connected so senders block on
+ * BT_SK_SUSPEND instead of failing.
+ */
+ if (chan->state == BT_CONNECTED &&
+ (chan->mode == L2CAP_MODE_LE_FLOWCTL ||
+ chan->mode == L2CAP_MODE_EXT_FLOWCTL)) {
+ set_bit(FLAG_PENDING_SECURITY,
+ &chan->flags);
+ chan->state = BT_CONFIG;
+ }
+ } else {
sk->sk_state_change(sk);
+ }
} else {
err = -EINVAL;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-03 18:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 18:13 [PATCH v17 0/2] Bluetooth: L2CAP: Fix LE credits resuming channels pending security Luiz Augusto von Dentz
2026-12-03 18:14 ` [PATCH v17 1/2] Bluetooth: L2CAP: Restrict LE credits to connected CoCs Luiz Augusto von Dentz
2026-12-03 18:14 ` [PATCH v17 2/2] Bluetooth: L2CAP: Keep credits from completing security upgrades Luiz Augusto von Dentz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox