[PATCH v15 1/2] Bluetooth: L2CAP: Restrict LE credits to connected CoCs
From: Kyle Pepper
Date: Sun Nov 29 2026 - 19:06:12 EST
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.
AI assistance: Codex prepared this attribution revision and assisted
with validation and commit text. Earlier revisions disclosed LLM
assistance for the credit-state guard.
Fixes: fad5fc89594d ("Bluetooth: Add LE flow control discipline")
Signed-off-by: Kyle Pepper <cochcoder@xxxxxxxxx>
---
Local validation at mail preparation:
- GCC/Clang sanitizer models: 134 expected outcomes, plus two
preceding-source comparisons.
- GCC/Clang/ECRED-off W=1 objects, sparse and strict CheckPatch pass.
Smatch retains two inherited v14 diagnostics.
- KCSAN and KASAN guest reruns use a separate workqueue prerequisite:
work_static() reads work->data through atomic_long_read(). This fixes
the preserved strict KCSAN report against queue_work_on(). The
prerequisite is outside this two-patch Bluetooth series; the four
reviewed Bluetooth files match the submitted source hashes.
- KCSAN focused: 16/16; no kernel alerts.
- KCSAN full: 138/142; no kernel alerts. All remaining failures match preserved v14 failures. One prior timeout now passes.
- KASAN focused: 16/16; no kernel alerts.
- KASAN full: 137/142; no kernel alerts. All remaining failures match preserved v14 failures.
The private tester waits for old-channel failure dispatch before requiring
a new request to succeed. The earlier premature-admission test is preserved.
The isolated checks ran alongside a kernel package build while its
exclusive trial lock excluded hardware capture; they did not acquire
that lock or delay the package install handoff. Lock protection was
checked throughout. The original exact-match comparison rejected the
improved KCSAN case; its raw FAIL record remains preserved.
Strict KCSAN, weak-memory checks, lockdep and panic-on-warning remain
active. The unmodified base still has the preserved KCSAN failure.
Full validation remains incomplete. No v15 remote CI or hardware/PTS
result is claimed. Inherited suite failures and Smatch findings remain.
Changes in v15:
- Keep a security upgrade pending while SMP key distribution runs;
complete or fail it when pairing ends (new l2cap_security_recheck()).
- Treat a latched SMP failure as failing every pending CoC upgrade
before the work item marks them.
- Consume the ECONNREFUSED returned to a deferred reader so it is not
reported twice.
- Reject BT_RCVMTU reconfiguration with EBUSY while a deferred ECRED
response is unsent.
- Restore shared-link pending security and MIC requirements after the
last pending upgrade, preserving achieved and surviving requirements;
revisit restoration on encryption-only confirmations too.
- Acquire every distinct sibling's nested lock before batch completion;
only the channel already locked by the caller skips acquisition (H1).
- Consume the whole rejected batch before teardown callbacks can revisit
another member and send a duplicate response (H2).
- Patch 1's code and commit message are unchanged; only its mail version
and series revision notes change.
Previous v14 (no cover letter):
https://lore.kernel.org/linux-bluetooth/6aff9cb5ebb1f1512734d5ecdac876a2cc0c86bc.1795650070.git.github.filter194@xxxxxxxxx/
Previous patch 2:
https://lore.kernel.org/linux-bluetooth/fc7072a78de49b72d9034349512983d95be4ba1a.1795650070.git.github.filter194@xxxxxxxxx/
V15 remote CI has not been run or verified. Local validation and limits
are recorded separately; these unsigned exports require human review
and DCO certification before sending.
net/bluetooth/l2cap_core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 943effc867402e232d4d4c4a93d4b7ba5d376367..8229bddca5df761dd1359b88752e3d5f6d6090cf 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -5469,6 +5469,11 @@ static inline int l2cap_le_credits(struct l2cap_conn *conn,
l2cap_chan_lock(chan);
+ if (chan->state != BT_CONNECTED ||
+ (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");
base-commit: f57f78086ab54f3b3122fbaeba2c842ba7bb6d00