All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v20 1/2] Bluetooth: L2CAP: Restrict LE credits to connected CoCs
Date: Fri,  4 Dec 2026 10:31:04 -0500	[thread overview]
Message-ID: <20261204153105.1183145-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261204153105.1183145-1-luiz.dentz@gmail.com>

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 | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index edbfb775a375..6d1f56ff8059 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -5572,6 +5572,19 @@ 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, but not
+	 * for an Enhanced Credit Based one whose response has not been sent
+	 * since the peer doesn't know its CID yet.
+	 */
+	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) ||
+	    l2cap_chan_ecred_rsp_pending(chan))
+		goto unlock;
+
 	max_credits = LE_FLOWCTL_MAX_CREDITS - chan->tx_credits;
 	if (credits > max_credits) {
 		BT_ERR("LE credits overflow");
@@ -5585,6 +5598,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


  reply	other threads:[~2026-12-04 15:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 15:31 [PATCH v20 0/2] Bluetooth: L2CAP: Fix LE credits resuming channels pending security Luiz Augusto von Dentz
2026-12-04 15:31 ` Luiz Augusto von Dentz [this message]
2026-12-04 15:31 ` [PATCH v20 2/2] Bluetooth: L2CAP: Keep credits from completing security upgrades 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=20261204153105.1183145-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 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.