Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH v21 0/2] Bluetooth: L2CAP: Fix LE credits resuming channels pending security
@ 2026-12-04 20:29 Luiz Augusto von Dentz
  2026-12-04 20:29 ` [PATCH v21 1/2] Bluetooth: L2CAP: Restrict LE credits to connected CoCs Luiz Augusto von Dentz
  2026-12-04 20:29 ` [PATCH v21 2/2] Bluetooth: L2CAP: Keep credits from completing security upgrades Luiz Augusto von Dentz
  0 siblings, 2 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2026-12-04 20:29 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.

While the upgrade is pending, an established CoC is now moved to
BT_CONFIG with FLAG_PENDING_SECURITY set, like ATT, 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 v21:
- Only move connection oriented channels to BT_CONFIG, LE raw sockets
  have no credits to resume them once the upgrade completes.
- Don't treat an established channel waiting for a security upgrade as
  refused when checking the ident of an Enhanced Credit Based request.
- Rebase on bluetooth-next.

Changes in v20:
- Read the channel state under its lock in l2cap_chan_connect(), so
  connect() returning EISCONN doesn't race with BT_SECURITY.

Changes in v19:
- Ignore credits for an Enhanced Credit Based channel whose response
  has not been sent, the peer doesn't know its CID yet.
- Only clear FLAG_DEFER_SETUP of a sibling under its lock when sending
  the Enhanced Credit Based response, so BT_SECURITY can't move it to
  BT_CONFIG after seeing the response pending.
- Only complete a pending upgrade from BT_SECURITY if the link meets the
  security level of the channel.
- Return EISCONN from connect() while an upgrade is pending.
- Check for a NULL socket in l2cap_sock_suspend_cb().

Changes in v18:
- Ignore credits on non connection oriented channels.
- Don't move an Enhanced Credit Based channel whose response has not
  been sent to BT_CONFIG.
- Let senders racing with BT_SECURITY queue data while the upgrade is
  pending instead of failing with ENOTCONN.
- Return the RX credits not returned while the upgrade was pending, and
  only resume the socket once the held data is sent and credits remain.
- Complete a pending upgrade when BT_SECURITY sets a level the link
  already meets.
- Don't claim key size and MIC are enforced in the commit message.

v20: https://lore.kernel.org/linux-bluetooth/20261204153105.1183145-1-luiz.dentz@gmail.com/

Kyle Pepper (2):
  Bluetooth: L2CAP: Restrict LE credits to connected CoCs
  Bluetooth: L2CAP: Keep credits from completing security upgrades

 include/net/bluetooth/l2cap.h | 14 ++++++
 net/bluetooth/l2cap_core.c    | 95 ++++++++++++++++++++++++++++++++---
 net/bluetooth/l2cap_sock.c    | 38 ++++++++++++--
 3 files changed, 136 insertions(+), 11 deletions(-)

-- 
2.56.1


^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH v18 1/2] Bluetooth: L2CAP: Restrict LE credits to connected CoCs
@ 2026-12-03 20:46 Luiz Augusto von Dentz
  2026-12-04  2:15 ` Bluetooth: L2CAP: Fix LE credits resuming channels pending security bluez.test.bot
  0 siblings, 1 reply; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2026-12-03 20:46 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 | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index edbfb775a375..5811c3791993 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -5572,6 +5572,16 @@ 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->chan_type != L2CAP_CHAN_CONN_ORIENTED ||
+	    (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 +5595,13 @@ 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, nor
+	 * an Enhanced Credit Based one whose response has not been sent.
+	 */
+	if (chan->state != BT_CONNECTED || l2cap_chan_ecred_rsp_pending(chan))
+		goto unlock;
+
 	/* Resume sending */
 	l2cap_le_flowctl_send(chan);
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-04 22:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 20:29 [PATCH v21 0/2] Bluetooth: L2CAP: Fix LE credits resuming channels pending security Luiz Augusto von Dentz
2026-12-04 20:29 ` [PATCH v21 1/2] Bluetooth: L2CAP: Restrict LE credits to connected CoCs Luiz Augusto von Dentz
2026-12-04 22:20   ` Bluetooth: L2CAP: Fix LE credits resuming channels pending security bluez.test.bot
2026-12-04 20:29 ` [PATCH v21 2/2] Bluetooth: L2CAP: Keep credits from completing security upgrades Luiz Augusto von Dentz
  -- strict thread matches above, loose matches on Subject: below --
2026-12-03 20:46 [PATCH v18 1/2] Bluetooth: L2CAP: Restrict LE credits to connected CoCs Luiz Augusto von Dentz
2026-12-04  2:15 ` Bluetooth: L2CAP: Fix LE credits resuming channels pending security bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox