Skip to contentSkip to conversation

Bluetooth: L2CAP: Restrict LE credits to connected CoCs

PATCH Superseded Kyle Pepper 3 participants 25 messages Nov 13 – Dec 4

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v10 1/2 Bluetooth: L2CAP: Restrict LE credits to connected CoCs

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")
Assisted-by LLM

---
Hi Luiz,

I split the credit validation into its own patch and reworked the security handling to use the existing HCI workqueue. There is no new workqueue or pairing timeout. The original l2cap-tester and smp-tester now pass without changing their expectations.

I also checked failure handling, repeated security
requests, key refresh and deferred LE/ECRED setup so fixing that bypass doesn't leave sockets stuck.

Hopefully this brings the patch to a more usable state.

Thanks,
Kyle

v10:
- Separate malformed-credit validation from security request completion.
- Use the existing HCI workqueue and SMP/HCI timeouts.
- Keep pending upgrades gated through failure, refresh and deferred setup.

Previous v9: https://lore.kernel.org/linux-bluetooth/[email protected]/
Threading uses the Message-ID from sent mail; the archive lookup is not yet available. Luiz's reply Message-ID was not supplied.

Validation: original l2cap-tester 111/111 and smp-tester 8/8; 27 private native cases; GCC/Clang/ECRED-off W=1 builds; 42 modeled cases per compiler with ASan/UBSan and 10 expected mutation failures. Guest tests use emulated controllers and checked module identities. Physical hardware, PTS, KCSAN and remote CI were not run. Private fixtures and traces are not included.

 net/bluetooth/l2cap_core.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bluetooth/l2cap_core.c +5 -0
index 09ff32394..4e8aec98e 100644
@@ -5464,6 +5464,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: da3cc02587c629420603df4395179ec82955c941

#1 lore raw

PATCH v10 2/2 Bluetooth: L2CAP: Keep credits from completing security upgrades

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.

Finish requests on the existing HCI workqueue, outside the confirmation list walk. Hold selected channels before callbacks can remove siblings. Latch SMP failure before admitting a fresh request, and fail pending requests even if a later confirmation would otherwise satisfy them. Use the existing pairing and HCI timeouts without a new request deadline.

Drain retained data when security completes or the requested requirement is lowered to an achieved level. Return EACCES and restore the old request when SMP starts no procedure and the requirements remain unmet. Preserve each CoC's requested level across shared-link confirmations.

Keep deferred reads pending during an upgrade. Send an ECRED response before releasing accepted children's data and reject the batch on security failure. Preserve ordinary deferred rejection behavior.

Fixes fad5fc89594d ("Bluetooth: Add LE flow control discipline")
Assisted-by LLM
---
 include/net/bluetooth/l2cap.h |   7 +
 net/bluetooth/l2cap_core.c    | 295 ++++++++++++++++++++++++++++++++--
 net/bluetooth/l2cap_sock.c    | 169 +++++++++++--------
 net/bluetooth/smp.c           |   1 +
 4 files changed, 394 insertions(+), 78 deletions(-)
include/net/bluetooth/l2cap.h +7 -0
index cf5c2df68..7b95bd407 100644
@@ -604,6 +604,7 @@ struct l2cap_chan {
 	__u32		remote_flush_to;
 
 	struct delayed_work	chan_timer;
+	struct list_head	security_list;
 	struct delayed_work	retrans_timer;
 	struct delayed_work	monitor_timer;
 	struct delayed_work	ack_timer;
@@ -644,6 +645,8 @@ struct l2cap_conn {
 
 	struct sk_buff_head	pending_rx;
 	struct work_struct	pending_rx_work;
+	struct work_struct	security_work;
+	atomic_t		security_failure;
 	bool			pending_rx_blocked __guarded_by(&lock);
 
 	struct delayed_work	id_addr_timer;
@@ -767,6 +770,8 @@ enum {
 	FLAG_ECRED_CONN_REQ_SENT,
 	FLAG_ECRED_RECONF_REQ_SENT,
 	FLAG_PENDING_SECURITY,
+	FLAG_SECURITY_CFM,
+	FLAG_SECURITY_FAILED,
 	FLAG_HOLD_HCI_CONN,
 	FLAG_DEL,
 };
@@ -993,6 +998,8 @@ void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
 void l2cap_chan_rx_avail(struct l2cap_chan *chan, ssize_t rx_avail);
 void l2cap_chan_req_mic_len(struct l2cap_chan *chan, struct hci_conn *hcon);
 int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator);
+int l2cap_chan_set_security(struct l2cap_chan *chan, u8 level, u8 mic_len);
+void l2cap_security_failure(struct l2cap_conn *conn);
 void l2cap_chan_set_defaults(struct l2cap_chan *chan, struct l2cap_chan *pchan);
 int l2cap_ertm_init(struct l2cap_chan *chan);
 void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan);
net/bluetooth/l2cap_core.c +282 -13

412 lines not on this page · raw message

net/bluetooth/l2cap_sock.c +104 -65

215 lines not on this page · raw message

net/bluetooth/smp.c +1 -0
index f8f86b8f7..84d85613c 100644
@@ -785,6 +785,7 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason)
 			     &reason);
 
 	mgmt_auth_failed(hcon, HCI_ERROR_AUTH_FAILURE);
+	l2cap_security_failure(conn);
 
 	if (chan->data)
 		smp_chan_destroy(conn);
#2 lore raw

PATCH v11 1/2 Bluetooth: L2CAP: Restrict LE credits to connected CoCs

In reply to Kyle Pepper

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")
Assisted-by LLM

---
Changes in v11:
- Purge retained deferred CoC data before incomplete-configuration teardown.
- Clear pending work flags on close and recheck channel state in the worker.
- Return EBUSY for overlapping SMP/encryption requests, including key distribution; restore pending_sec_level when rejecting an idle request.
- Complete ECRED child cleanup and propagate deferred security rejection.
- Preserve ordinary accept/close behavior and socket/SMP lock ordering.

Previous v10 (this series has no cover letter):
https://lore.kernel.org/linux-bluetooth/[email protected]/

 net/bluetooth/l2cap_core.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bluetooth/l2cap_core.c +5 -0
index 09ff32394..4e8aec98e 100644
@@ -5464,6 +5464,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: da3cc02587c629420603df4395179ec82955c941

#3 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1210580/

---Test result---

Test Summary:

CheckPatch                    FAIL      0.65 seconds
VerifyFixes                   PASS      0.09 seconds
VerifySignedoff               PASS      0.09 seconds
GitLint                       PASS      0.26 seconds
SubjectPrefix                 PASS      0.08 seconds
BuildKernel                   PASS      30.81 seconds
CheckAllWarning               PASS      34.66 seconds
CheckSparse                   PASS      37.43 seconds
BuildKernel32                 PASS      30.52 seconds
CheckKernelLLVM               PASS      34.69 seconds
TestRunnerSetup               PASS      752.68 seconds
TestRunner_l2cap-tester       PASS      14.88 seconds
IncrementalBuild              PASS      28.59 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[v11,1/2] Bluetooth: L2CAP: Restrict LE credits to connected CoCs
WARNING: Non-standard signature: Assisted-by:
#89:

Assisted-by LLM

ERROR: Unrecognized email address: 'LLM'
#89:

Assisted-by LLM

total: 1 errors, 1 warnings, 0 checks, 11 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14980058.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

https://github.com/bluez/bluetooth-next/pull/1127

---
Regards,
Linux Bluetooth

#4 lore raw

PATCH v12 1/2 Bluetooth: L2CAP: Restrict LE credits to connected CoCs

In reply to Kyle Pepper

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")
Assisted-by LLM

---
Changes in v12:
- Reject the deferred ECRED batch when an accepted child closes before the connection response; close all siblings instead of disconnecting early.
- Patch 1 is unchanged.

Previous v11 (no cover letter):
https://lore.kernel.org/linux-bluetooth/4278a9caf4dc8e949092452c141a5be465ec77e1.1794550328.git.github.filter194@slmail.me/

Review:
https://sashiko.dev/#/patchset/4278a9caf4dc8e949092452c141a5be465ec77e1.1794550328.git.github.filter194%40slmail.me

 net/bluetooth/l2cap_core.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bluetooth/l2cap_core.c +5 -0
index 09ff32394..4e8aec98e 100644
@@ -5464,6 +5464,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: da3cc02587c629420603df4395179ec82955c941

#5 lore raw

PATCH v13 1/2 Bluetooth: L2CAP: Restrict LE credits to connected CoCs

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")
Assisted-by LLM

---
Changes in v13:
- Rebase on current bluetooth-next; patch 1's code is unchanged.
- Keep deferred ECRED data gated until the response is queued.
- Exclude outgoing authentication retries from incoming ECRED batches.
- Wait for a new shared-link encryption procedure before completing security.
- Preserve rejection cleanup and explicit per-channel locking.

Previous v12 (no cover letter):
https://lore.kernel.org/linux-bluetooth/4278a9caf4dc8e949092452c141a5be465ec77e1.1794617024.git.github.filter194@slmail.me/

AI assistance: Codex prepared and tested the supplied follow-up fixes and updated this revision's source, commit explanation and revision notes.

 net/bluetooth/l2cap_core.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bluetooth/l2cap_core.c +5 -0
index 943effc86..8229bddca 100644
@@ -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: ffb95458a0f70dcab620eee0ecf5ef7750971b2f

#6 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1220931/

---Test result---

Test Summary:

CheckPatch                    FAIL      0.59 seconds
VerifyFixes                   PASS      0.09 seconds
VerifySignedoff               PASS      0.10 seconds
GitLint                       PASS      0.27 seconds
SubjectPrefix                 PASS      0.09 seconds
BuildKernel                   PASS      24.49 seconds
CheckAllWarning               PASS      27.91 seconds
CheckSparse                   PASS      29.82 seconds
BuildKernel32                 PASS      25.18 seconds
CheckKernelLLVM               PASS      24.71 seconds
TestRunnerSetup               PASS      572.47 seconds
TestRunner_l2cap-tester       PASS      15.27 seconds
IncrementalBuild              PASS      23.86 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[v13,1/2] Bluetooth: L2CAP: Restrict LE credits to connected CoCs
WARNING: Non-standard signature: Assisted-by:
#92:

Assisted-by LLM

ERROR: Unrecognized email address: 'LLM'
#92:

Assisted-by LLM

total: 1 errors, 1 warnings, 0 checks, 11 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/home/runner/work/bluetooth-next/bluetooth-next/src/patch/15017328.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

https://github.com/bluez/bluetooth-next/pull/1217

---
Regards,
Linux Bluetooth

#7 lore raw

PATCH v14 1/2 Bluetooth: L2CAP: Restrict LE credits to connected CoCs

In reply to Kyle Pepper

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")

---
Changes in v14:
- Replace the obsolete Assisted-by trailer with AI disclosure in each commit message, following current kernel tool-generated content guidance.
- Rebase on current bluetooth-next; both patches' code is unchanged.

Previous v13 (no cover letter):
https://lore.kernel.org/linux-bluetooth/9d9d37680044266dbd1d6919b08564026afcd87d.1795528595.git.github.filter194@slmail.me/

V13 CI passed all 12 other jobs, including the kernel builds and l2cap-tester. CheckPatch rejected the obsolete Assisted-by: LLM trailer. Those are v13 results; v14 remote CI has not run.

 net/bluetooth/l2cap_core.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bluetooth/l2cap_core.c +5 -0
index 943effc867402e232d4d4c4a93d4b7ba5d376367..8229bddca5df761dd1359b88752e3d5f6d6090cf 100644
@@ -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

#8 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1222694/

---Test result---

Test Summary:

CheckPatch                    PASS      0.38 seconds
VerifyFixes                   PASS      0.05 seconds
VerifySignedoff               PASS      0.04 seconds
GitLint                       PASS      0.15 seconds
SubjectPrefix                 PASS      0.04 seconds
BuildKernel                   PASS      20.00 seconds
CheckAllWarning               PASS      23.08 seconds
CheckSparse                   PASS      24.55 seconds
BuildKernel32                 PASS      20.45 seconds
CheckKernelLLVM               PASS      21.50 seconds
TestRunnerSetup               PASS      482.98 seconds
TestRunner_l2cap-tester       PASS      13.70 seconds
IncrementalBuild              PASS      19.11 seconds

https://github.com/bluez/bluetooth-next/pull/1231

---
Regards,
Linux Bluetooth

#9 lore raw

PATCH v15 1/2 Bluetooth: L2CAP: Restrict LE credits to connected CoCs

In reply to Kyle Pepper

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")

---
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@slmail.me/
Previous patch 2:
https://lore.kernel.org/linux-bluetooth/fc7072a78de49b72d9034349512983d95be4ba1a.1795650070.git.github.filter194@slmail.me/

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(+)
net/bluetooth/l2cap_core.c +5 -0
index 943effc867402e232d4d4c4a93d4b7ba5d376367..8229bddca5df761dd1359b88752e3d5f6d6090cf 100644
@@ -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

#10 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1226096/

---Test result---

Test Summary:

CheckPatch                    PASS      0.49 seconds
VerifyFixes                   PASS      0.06 seconds
VerifySignedoff               PASS      0.06 seconds
GitLint                       FAIL      0.19 seconds
SubjectPrefix                 PASS      0.05 seconds
BuildKernel                   PASS      24.05 seconds
CheckAllWarning               PASS      27.42 seconds
CheckSparse                   PASS      30.61 seconds
BuildKernel32                 PASS      24.35 seconds
CheckKernelLLVM               PASS      26.15 seconds
TestRunnerSetup               PASS      564.97 seconds
TestRunner_l2cap-tester       PASS      15.42 seconds
IncrementalBuild              PASS      23.31 seconds

Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[v15,1/2] Bluetooth: L2CAP: Restrict LE credits to connected CoCs

24: B1 Line exceeds max length (123>80): "- KCSAN full: 138/142; no kernel alerts. All remaining failures match preserved v14 failures. One prior timeout now passes." 26: B1 Line exceeds max length (93>80): "- KASAN full: 137/142; no kernel alerts. All remaining failures match preserved v14 failures."

https://github.com/bluez/bluetooth-next/pull/1250

---
Regards,
Linux Bluetooth

#11 lore raw

PATCH v16 1/2 Bluetooth: L2CAP: Restrict LE credits to connected CoCs

In reply to Kyle Pepper

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")

---
Local v16 validation (unsigned review only):
- GCC/Clang ASan/UBSan: 172 expected outcomes, including 50 mutation controls.
- GCC/Clang/ECRED-off W=1 objects and sparse pass.
- Smatch retains two inherited diagnostics.
- KASAN: focused 16/16; full 137/142, with all five failures matching the preserved v14 baseline and no kernel alerts.
- Strict KCSAN: 16/16 focused on the initial two images. First full run panicked in move_linked_works / queue_work_on. The control panicked in process_one_work / queue_work_on.
The second control passed 16/16 focused; its full run panicked in skb_queue_tail / vhci_poll [hci_vhci].
The sanitizer guests use separate test-only workqueue changes. No v16 remote CI, hardware or PTS result is claimed.

Changes in v16:
- Return EBUSY from BT_SECURITY until a latched SMP result, queued confirmation or link requirement restore has been dispatched.
- Return a deferred ECRED rejection from BT_SECURITY completion and consume teardown's duplicate socket error.
- Answer the whole deferred ECRED batch when the peer disconnects one child, so an accepted sibling is not left without a response.
- Count accepted-but-unanswered children when rejecting a reused ECRED identifier.
- Wrap validation notes to fix the v15 GitLint B1 failures in PR1250.
https://github.com/bluez/bluetooth-next/pull/1250
- Rebase onto current bluetooth-next, preserving upstream ECRED key-size validation and the MPS-adjustment removal.

Previous v15: https://lore.kernel.org/linux-bluetooth/6aff9cb5ebb1f1512734d5ecdac876a2cc0c86bc.1795807576.git.github.filter194@slmail.me/

 net/bluetooth/l2cap_core.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bluetooth/l2cap_core.c +5 -0
index b8c85c478..6ee19d98f 100644
@@ -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: e0e943a9dbcd7675652e2900d09e8595f28f724e

#12 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1227512/

---Test result---

Test Summary:

CheckPatch                    PASS      0.66 seconds
VerifyFixes                   PASS      0.12 seconds
VerifySignedoff               PASS      0.12 seconds
GitLint                       PASS      0.31 seconds
SubjectPrefix                 PASS      0.11 seconds
BuildKernel                   PASS      24.36 seconds
CheckAllWarning               PASS      27.92 seconds
CheckSparse                   PASS      29.68 seconds
BuildKernel32                 PASS      24.02 seconds
CheckKernelLLVM               PASS      24.61 seconds
TestRunnerSetup               PASS      574.30 seconds
TestRunner_l2cap-tester       PASS      15.37 seconds
IncrementalBuild              PASS      22.81 seconds

https://github.com/bluez/bluetooth-next/pull/1264

---
Regards,
Linux Bluetooth

author
#13 lore raw
In reply to Kyle Pepper

Hi Luiz,

Before I continue down the path of repeatedly trying to fix the security issues Sashiko finds. Is there anything you have a issue with how this patch series implements the changes? I'd love to hear your feedback.

Thanks,
Kyle

-------- Original Message --------
On Monday, 11/30/26 at 21:29 Kyle Pepper <[email protected]> wrote:
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")

---
Local v16 validation (unsigned review only):
- GCC/Clang ASan/UBSan: 172 expected outcomes, including 50 mutation controls.
- GCC/Clang/ECRED-off W=1 objects and sparse pass.
- Smatch retains two inherited diagnostics.
- KASAN: focused 16/16; full 137/142, with all five failures matching the preserved v14 baseline and no kernel alerts.
- Strict KCSAN: 16/16 focused on the initial two images. First full run panicked in move_linked_works / queue_work_on. The control panicked in process_one_work / queue_work_on.
The second control passed 16/16 focused; its full run panicked in skb_queue_tail / vhci_poll [hci_vhci].
The sanitizer guests use separate test-only workqueue changes. No v16 remote CI, hardware or PTS result is claimed.

Changes in v16:
- Return EBUSY from BT_SECURITY until a latched SMP result, queued confirmation or link requirement restore has been dispatched.
- Return a deferred ECRED rejection from BT_SECURITY completion and consume teardown's duplicate socket error.
- Answer the whole deferred ECRED batch when the peer disconnects one child, so an accepted sibling is not left without a response.
- Count accepted-but-unanswered children when rejecting a reused ECRED identifier.
- Wrap validation notes to fix the v15 GitLint B1 failures in PR1250.
https://github.com/bluez/bluetooth-next/pull/1250
- Rebase onto current bluetooth-next, preserving upstream ECRED key-size validation and the MPS-adjustment removal.

Previous v15: https://lore.kernel.org/linux-bluetooth/6aff9cb5ebb1f1512734d5ecdac876a2cc0c86bc.1795807576.git.github.filter194@slmail.me/

 net/bluetooth/l2cap_core.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bluetooth/l2cap_core.c +5 -0
index b8c85c478..6ee19d98f 100644
@@ -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: e0e943a9dbcd7675652e2900d09e8595f28f724e

#14 lore raw

Hi,

Quoted 7 lines · cochcoder

Hi Luiz,

Before I continue down the path of repeatedly trying to fix the security issues Sashiko finds. Is there anything you have a issue with how this patch series implements the changes? I'd love to hear your feedback.

I think I already commented that adding a work for security cfm is going in the wrong direction, the premise that the credit update while anything is pending is wrong, we shall only process credits if the channel is established/BT_CONNECTED.

Quoted 73 lines

Thanks,
Kyle

-------- Original Message --------
On Monday, 11/30/26 at 21:29 Kyle Pepper <[email protected]> wrote:
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")

---
Local v16 validation (unsigned review only):
- GCC/Clang ASan/UBSan: 172 expected outcomes, including 50 mutation controls.
- GCC/Clang/ECRED-off W=1 objects and sparse pass.
- Smatch retains two inherited diagnostics.
- KASAN: focused 16/16; full 137/142, with all five failures matching the preserved v14 baseline and no kernel alerts.
- Strict KCSAN: 16/16 focused on the initial two images. First full run panicked in move_linked_works / queue_work_on. The control panicked in process_one_work / queue_work_on.
The second control passed 16/16 focused; its full run panicked in skb_queue_tail / vhci_poll [hci_vhci].
The sanitizer guests use separate test-only workqueue changes. No v16 remote CI, hardware or PTS result is claimed.

Changes in v16:
- Return EBUSY from BT_SECURITY until a latched SMP result, queued confirmation or link requirement restore has been dispatched.
- Return a deferred ECRED rejection from BT_SECURITY completion and consume teardown's duplicate socket error.
- Answer the whole deferred ECRED batch when the peer disconnects one child, so an accepted sibling is not left without a response.
- Count accepted-but-unanswered children when rejecting a reused ECRED identifier.
- Wrap validation notes to fix the v15 GitLint B1 failures in PR1250.
https://github.com/bluez/bluetooth-next/pull/1250
- Rebase onto current bluetooth-next, preserving upstream ECRED key-size validation and the MPS-adjustment removal.

Previous v15: https://lore.kernel.org/linux-bluetooth/6aff9cb5ebb1f1512734d5ecdac876a2cc0c86bc.1795807576.git.github.filter194@slmail.me/

 net/bluetooth/l2cap_core.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bluetooth/l2cap_core.c +5 -0
index b8c85c478..6ee19d98f 100644
@@ -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: e0e943a9dbcd7675652e2900d09e8595f28f724e

Signature · 1 line
Luiz Augusto von Dentz
#15 lore raw

PATCH v17 1/1 Bluetooth: L2CAP: Restrict LE credits to connected CoCs

In reply to Kyle Pepper

Only established LE credit-based channels can use a credit indication. Check the channel state and mode under the channel lock before checking for credit overflow, adding credits, or resuming transmission. Ignore credits for other channels instead of acting on them or saving them.

AI assistance: gpt-6.2-sol

Fixes fad5fc89594d ("Bluetooth: Add LE flow control discipline")

---
Changes in v17:
- Keep the state/mode guard as a standalone patch.
- Drop v16 patch 2/2. Do not add security-confirmation work or change security completion.
- Rebase onto bluetooth-next at 738af1958d2e.

Validation: exact-base replay and warning-free GCC W=1 compilation of l2cap_core.o passed. Strict CheckPatch passed with the commit lookup and sign-off checks excluded for the unsigned archive-based review. No runtime testing.

v16:
https://lore.kernel.org/linux-bluetooth/[email protected]/

 net/bluetooth/l2cap_core.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bluetooth/l2cap_core.c +5 -0
@@ -5572,6 +5572,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");
#16 lore raw

Hi Kyle,

Quoted 8 lines · Kyle Pepper

Only established LE credit-based channels can use a credit indication. Check the channel state and mode under the channel lock before checking for credit overflow, adding credits, or resuming transmission. Ignore credits for other channels instead of acting on them or saving them.

AI assistance: gpt-6.2-sol

Quoted 8 lines
Fixes fad5fc89594d ("Bluetooth: Add LE flow control discipline")

---
Changes in v17:
- Keep the state/mode guard as a standalone patch.
- Drop v16 patch 2/2. Do not add security-confirmation work or change security completion.
- Rebase onto bluetooth-next at 738af1958d2e.

In case you didn't realize it yet, I've sent a v17 with the changes myself and changes to l2cap-tester adding test to cover the interation of BT_SECURITY with credit updates.

Quoted 27 lines

Validation: exact-base replay and warning-free GCC W=1 compilation of l2cap_core.o passed. Strict CheckPatch passed with the commit lookup and sign-off checks excluded for the unsigned archive-based review. No runtime testing.

v16:
https://lore.kernel.org/linux-bluetooth/[email protected]/

 net/bluetooth/l2cap_core.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bluetooth/l2cap_core.c +5 -0
@@ -5572,6 +5572,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");
Signature · 1 line
Luiz Augusto von Dentz
author
#17 lore raw

Hi Luiz,

I didn't see that, thanks for letting me know.

Thanks,
Kyle

Quoted 57 lines · Luiz Augusto von Dentz

Hi Kyle,

Quoted 8 lines · Kyle Pepper

Only established LE credit-based channels can use a credit indication. Check the channel state and mode under the channel lock before checking for credit overflow, adding credits, or resuming transmission. Ignore credits for other channels instead of acting on them or saving them.

AI assistance: gpt-6.2-sol

Quoted 8 lines
Fixes fad5fc89594d ("Bluetooth: Add LE flow control discipline")

---
Changes in v17:
- Keep the state/mode guard as a standalone patch.
- Drop v16 patch 2/2. Do not add security-confirmation work or change security completion.
- Rebase onto bluetooth-next at 738af1958d2e.

In case you didn't realize it yet, I've sent a v17 with the changes myself and changes to l2cap-tester adding test to cover the interation of BT_SECURITY with credit updates.

Quoted 17 lines

Validation: exact-base replay and warning-free GCC W=1 compilation of l2cap_core.o passed. Strict CheckPatch passed with the commit lookup and sign-off checks excluded for the unsigned archive-based review. No runtime testing.

v16:
https://lore.kernel.org/linux-bluetooth/[email protected]/

 net/bluetooth/l2cap_core.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bluetooth/l2cap_core.c +0 -0
@@ -5572,6 +5572,11 @@ static inline int l2cap_le_credits(struct l2cap_conn *conn,
 

net/bluetooth/l2cap_core.c static inline int l2cap_le_credits(struct l2cap_conn *conn, · line 5582

Quoted 10 lines
net/bluetooth/l2cap_core.c +5 -0
        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");

--
Luiz Augusto von Dentz

#18 lore raw
In reply to Kyle Pepper

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1231005/

---Test result---

Test Summary:

CheckPatch                    PASS      0.66 seconds
VerifyFixes                   PASS      0.12 seconds
VerifySignedoff               PASS      0.12 seconds
GitLint                       PASS      0.31 seconds
SubjectPrefix                 PASS      0.12 seconds
BuildKernel                   PASS      23.14 seconds
CheckAllWarning               PASS      26.90 seconds
CheckSparse                   PASS      28.97 seconds
BuildKernel32                 PASS      23.68 seconds
CheckKernelLLVM               PASS      25.88 seconds
TestRunnerSetup               PASS      555.67 seconds
TestRunner_l2cap-tester       PASS      15.31 seconds
IncrementalBuild              PASS      22.35 seconds

https://github.com/bluez/bluetooth-next/pull/1281

---
Regards,
Linux Bluetooth

#19 lore raw

PATCH v16 2/2 Bluetooth: L2CAP: Keep credits from completing security upgrades

In reply to Kyle Pepper

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.

Finish requests on the existing HCI workqueue, outside the confirmation list walk. Hold selected channels before callbacks can remove siblings. Latch SMP failure before admitting a fresh request, clear pending flags on close, and recheck channel state before processing deferred confirmations. Use the existing pairing and HCI timeouts without a new request deadline.

Reject overlapping requests with EBUSY while pairing, key distribution or encryption is in progress. This includes repeated and lowered requests; applications can retry after the current procedure completes. Return EACCES when SMP starts no procedure and the requirements remain unmet, restoring the channel requirements and both pending link requirements. Preserve each CoC's requested level across shared-link confirmations.

Keep deferred reads pending during an upgrade. Send an ECRED response before releasing accepted children's data, let rejection override pending siblings, and close every deleted child. Return the batch's security error to a deferred reader while preserving ordinary accept/close behavior. Purge retained CoC data even if deferred acceptance left configuration incomplete. Acquire the SMP channel lock without holding the socket lock, and suspend pending ATT sockets until their confirmation resumes them.

Reject an incoming deferred ECRED batch when an accepted child closes before the connection response, so its siblings cannot stay suspended.

Keep deferred ECRED identifiers and flags until the response is queued, then release accepted children under their own channel locks. Clear those fields on rejection too. Exclude outgoing authentication retries from incoming batches even when their signaling identifiers collide.

Always acquire a distinct sibling's nested channel lock before completing the batch. Only the channel already locked by the caller skips acquisition. Consume every rejected sibling's identifier and deferred flag before any teardown callback, preventing callback re-entry from answering it again.

If another shared-link encryption procedure starts after a confirmation was queued, keep security pending until its confirmation arrives rather than closing a channel whose requirements may still be satisfied.

Keep upgrades pending through SMP Phase 3 key distribution, even after encryption completes. Recheck pending channels after successful pairing destroys its SMP state; a pairing failure closes them with ECONNREFUSED.

Treat a latched SMP failure as failing every pending upgrade before the worker marks the channels. Consume the ECONNREFUSED returned to a deferred reader so teardown's socket error does not report the same failure twice.

Reject BT_RCVMTU reconfiguration with EBUSY while a deferred ECRED response is unsent, preserving its identifier and receive MTU until the batch is answered. Restore pending link requirements after upgrades finish without lowering the achieved security or a surviving channel's requirements. Revisit restoration on encryption-only confirmations after failed channels have closed, even when no channel remains pending.

AI assistance: Codex prepared and tested the security-upgrade and deferred-ECRED changes in prior revisions and these supplied v15 Phase 3, latched-failure, deferred-reader and receive-MTU revisions. It also hardened sibling locking and rejected-batch consumption, repaired shared-link requirement restoration, and assisted with this commit message and revision notes.
Work followed the reported failures and supplied review findings; validation uses compiler builds and source-extracted sanitizer models with mutation controls.

Also defer new BT_SECURITY requests until prior link results and requirements are dispatched. Return synchronous ECRED rejection, consume its socket error, reject batches on peer child withdrawal, and count accepted children when checking identifier reuse.

AI assistance: Codex applied the supplied v16 diff and prepared these separate source exports and validation notes.

Fixes fad5fc89594d ("Bluetooth: Add LE flow control discipline")

---
Local v16 validation (unsigned review only):
- GCC/Clang ASan/UBSan: 172 expected outcomes, including 50 mutation controls.
- GCC/Clang/ECRED-off W=1 objects and sparse pass.
- Smatch retains two inherited diagnostics.
- KASAN: focused 16/16; full 137/142, with all five failures matching the preserved v14 baseline and no kernel alerts.
- Strict KCSAN: 16/16 focused on the initial two images. First full run panicked in move_linked_works / queue_work_on. The control panicked in process_one_work / queue_work_on.
The second control passed 16/16 focused; its full run panicked in skb_queue_tail / vhci_poll [hci_vhci].
The sanitizer guests use separate test-only workqueue changes. No v16 remote CI, hardware or PTS result is claimed.

Changes in v16:
- Return EBUSY from BT_SECURITY until a latched SMP result, queued confirmation or link requirement restore has been dispatched.
- Return a deferred ECRED rejection from BT_SECURITY completion and consume teardown's duplicate socket error.
- Answer the whole deferred ECRED batch when the peer disconnects one child, so an accepted sibling is not left without a response.
- Count accepted-but-unanswered children when rejecting a reused ECRED identifier.
- Wrap validation notes to fix the v15 GitLint B1 failures in PR1250.
https://github.com/bluez/bluetooth-next/pull/1250
- Rebase onto current bluetooth-next, preserving upstream ECRED key-size validation and the MPS-adjustment removal.

Previous v15: https://lore.kernel.org/linux-bluetooth/6aff9cb5ebb1f1512734d5ecdac876a2cc0c86bc.1795807576.git.github.filter194@slmail.me/

 include/net/bluetooth/l2cap.h |  14 +-
 net/bluetooth/l2cap_core.c    | 567 +++++++++++++++++++++++++++++++---
 net/bluetooth/l2cap_sock.c    | 190 ++++++++----
 net/bluetooth/smp.c           |   3 +-
 4 files changed, 663 insertions(+), 111 deletions(-)
include/net/bluetooth/l2cap.h +13 -1
index 72d9d56c6..c21edb426 100644
@@ -609,6 +609,7 @@ struct l2cap_chan {
 	__u32		remote_flush_to;
 
 	struct delayed_work	chan_timer;
+	struct list_head	security_list;
 	struct delayed_work	retrans_timer;
 	struct delayed_work	monitor_timer;
 	struct delayed_work	ack_timer;
@@ -649,6 +650,12 @@ struct l2cap_conn {
 
 	struct sk_buff_head	pending_rx;
 	struct work_struct	pending_rx_work;
+	struct work_struct	security_work;
+	atomic_t		security_failure;
+	atomic_t		security_recheck;
+	__u8			security_pending_sec_level;
+	__u8			security_req_mic_len;
+	bool			security_restore;
 	bool			pending_rx_blocked __guarded_by(&lock);
 
 	struct delayed_work	id_addr_timer;
@@ -772,6 +779,8 @@ enum {
 	FLAG_ECRED_CONN_REQ_SENT,
 	FLAG_ECRED_RECONF_REQ_SENT,
 	FLAG_PENDING_SECURITY,
+	FLAG_SECURITY_CFM,
+	FLAG_SECURITY_FAILED,
 	FLAG_HOLD_HCI_CONN,
 	FLAG_DEL,
 };
@@ -979,7 +988,7 @@ void l2cap_cleanup_sockets(void);
 bool l2cap_is_socket(struct socket *sock);
 
 void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan);
-void __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan)
+int __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan)
 	__must_hold(&chan->lock) __must_hold(&chan->conn->lock);
 void __l2cap_connect_rsp_defer(struct l2cap_chan *chan);
 
@@ -998,6 +1007,9 @@ void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
 void l2cap_chan_rx_avail(struct l2cap_chan *chan, ssize_t rx_avail);
 void l2cap_chan_req_mic_len(struct l2cap_chan *chan, struct hci_conn *hcon);
 int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator);
+int l2cap_chan_set_security(struct l2cap_chan *chan, u8 level, u8 mic_len);
+void l2cap_security_failure(struct l2cap_conn *conn);
+void l2cap_security_recheck(struct l2cap_conn *conn);
 void l2cap_chan_set_defaults(struct l2cap_chan *chan, struct l2cap_chan *pchan);
 int l2cap_ertm_init(struct l2cap_chan *chan);
 void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan);
net/bluetooth/l2cap_core.c +525 -42

774 lines not on this page · raw message

net/bluetooth/l2cap_sock.c +123 -67

239 lines not on this page · raw message

net/bluetooth/smp.c +2 -1
index 62a6b1e8f..b94182e18 100644
@@ -785,6 +785,7 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason)
 			     &reason);
 
 	mgmt_auth_failed(hcon, HCI_ERROR_AUTH_FAILURE);
+	l2cap_security_failure(conn);
 
 	if (chan->data)
 		smp_chan_destroy(conn);
@@ -1365,8 +1366,8 @@ static void smp_distribute_keys(struct smp_chan *smp)
 
 	set_bit(SMP_FLAG_COMPLETE, &smp->flags);
 	smp_notify_keys(conn);
-
 	smp_chan_destroy(conn);
+	l2cap_security_recheck(conn);
 }
 
 static void smp_timeout(struct work_struct *work)
#20 lore raw

PATCH v15 2/2 Bluetooth: L2CAP: Keep credits from completing security upgrades

In reply to Kyle Pepper

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.

Finish requests on the existing HCI workqueue, outside the confirmation list walk. Hold selected channels before callbacks can remove siblings. Latch SMP failure before admitting a fresh request, clear pending flags on close, and recheck channel state before processing deferred confirmations. Use the existing pairing and HCI timeouts without a new request deadline.

Reject overlapping requests with EBUSY while pairing, key distribution or encryption is in progress. This includes repeated and lowered requests; applications can retry after the current procedure completes. Return EACCES when SMP starts no procedure and the requirements remain unmet, restoring the channel requirements and both pending link requirements. Preserve each CoC's requested level across shared-link confirmations.

Keep deferred reads pending during an upgrade. Send an ECRED response before releasing accepted children's data, let rejection override pending siblings, and close every deleted child. Return the batch's security error to a deferred reader while preserving ordinary accept/close behavior. Purge retained CoC data even if deferred acceptance left configuration incomplete. Acquire the SMP channel lock without holding the socket lock, and suspend pending ATT sockets until their confirmation resumes them.

Reject an incoming deferred ECRED batch when an accepted child closes before the connection response, so its siblings cannot stay suspended.

Keep deferred ECRED identifiers and flags until the response is queued, then release accepted children under their own channel locks. Clear those fields on rejection too. Exclude outgoing authentication retries from incoming batches even when their signaling identifiers collide.

Always acquire a distinct sibling's nested channel lock before completing the batch. Only the channel already locked by the caller skips acquisition. Consume every rejected sibling's identifier and deferred flag before any teardown callback, preventing callback re-entry from answering it again.

If another shared-link encryption procedure starts after a confirmation was queued, keep security pending until its confirmation arrives rather than closing a channel whose requirements may still be satisfied.

Keep upgrades pending through SMP Phase 3 key distribution, even after encryption completes. Recheck pending channels after successful pairing destroys its SMP state; a pairing failure closes them with ECONNREFUSED.

Treat a latched SMP failure as failing every pending upgrade before the worker marks the channels. Consume the ECONNREFUSED returned to a deferred reader so teardown's socket error does not report the same failure twice.

Reject BT_RCVMTU reconfiguration with EBUSY while a deferred ECRED response is unsent, preserving its identifier and receive MTU until the batch is answered. Restore pending link requirements after upgrades finish without lowering the achieved security or a surviving channel's requirements. Revisit restoration on encryption-only confirmations after failed channels have closed, even when no channel remains pending.

AI assistance: Codex prepared and tested the security-upgrade and deferred-ECRED changes in prior revisions and these supplied v15 Phase 3, latched-failure, deferred-reader and receive-MTU revisions. It also hardened sibling locking and rejected-batch consumption, repaired shared-link requirement restoration, and assisted with this commit message and revision notes.
Work followed the reported failures and supplied review findings; validation uses compiler builds and source-extracted sanitizer models with mutation controls.

Fixes fad5fc89594d ("Bluetooth: Add LE flow control discipline")

---
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@slmail.me/
Previous patch 2:
https://lore.kernel.org/linux-bluetooth/fc7072a78de49b72d9034349512983d95be4ba1a.1795650070.git.github.filter194@slmail.me/

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.

 include/net/bluetooth/l2cap.h |  14 +-
 net/bluetooth/l2cap_core.c    | 508 +++++++++++++++++++++++++++++++---
 net/bluetooth/l2cap_sock.c    | 186 ++++++++-----
 net/bluetooth/smp.c           |   3 +-
 4 files changed, 603 insertions(+), 108 deletions(-)
include/net/bluetooth/l2cap.h +13 -1
index 72d9d56c6f2a2e513acd41f9d1e0d08d99d9cdf8..c21edb4260e88539188a695a402c4e68ac6f3bd9 100644
@@ -609,6 +609,7 @@ struct l2cap_chan {
 	__u32		remote_flush_to;
 
 	struct delayed_work	chan_timer;
+	struct list_head	security_list;
 	struct delayed_work	retrans_timer;
 	struct delayed_work	monitor_timer;
 	struct delayed_work	ack_timer;
@@ -649,6 +650,12 @@ struct l2cap_conn {
 
 	struct sk_buff_head	pending_rx;
 	struct work_struct	pending_rx_work;
+	struct work_struct	security_work;
+	atomic_t		security_failure;
+	atomic_t		security_recheck;
+	__u8			security_pending_sec_level;
+	__u8			security_req_mic_len;
+	bool			security_restore;
 	bool			pending_rx_blocked __guarded_by(&lock);
 
 	struct delayed_work	id_addr_timer;
@@ -772,6 +779,8 @@ enum {
 	FLAG_ECRED_CONN_REQ_SENT,
 	FLAG_ECRED_RECONF_REQ_SENT,
 	FLAG_PENDING_SECURITY,
+	FLAG_SECURITY_CFM,
+	FLAG_SECURITY_FAILED,
 	FLAG_HOLD_HCI_CONN,
 	FLAG_DEL,
 };
@@ -979,7 +988,7 @@ void l2cap_cleanup_sockets(void);
 bool l2cap_is_socket(struct socket *sock);
 
 void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan);
-void __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan)
+int __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan)
 	__must_hold(&chan->lock) __must_hold(&chan->conn->lock);
 void __l2cap_connect_rsp_defer(struct l2cap_chan *chan);
 
@@ -998,6 +1007,9 @@ void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
 void l2cap_chan_rx_avail(struct l2cap_chan *chan, ssize_t rx_avail);
 void l2cap_chan_req_mic_len(struct l2cap_chan *chan, struct hci_conn *hcon);
 int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator);
+int l2cap_chan_set_security(struct l2cap_chan *chan, u8 level, u8 mic_len);
+void l2cap_security_failure(struct l2cap_conn *conn);
+void l2cap_security_recheck(struct l2cap_conn *conn);
 void l2cap_chan_set_defaults(struct l2cap_chan *chan, struct l2cap_chan *pchan);
 int l2cap_ertm_init(struct l2cap_chan *chan);
 void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan);
net/bluetooth/l2cap_core.c +469 -39

700 lines not on this page · raw message

net/bluetooth/l2cap_sock.c +119 -67

235 lines not on this page · raw message

net/bluetooth/smp.c +2 -1
index 62a6b1e8f7cb11eed874dbacf211fe861513f2fa..b94182e1870d363a86fb845e134794dcfbc08e80 100644
@@ -785,6 +785,7 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason)
 			     &reason);
 
 	mgmt_auth_failed(hcon, HCI_ERROR_AUTH_FAILURE);
+	l2cap_security_failure(conn);
 
 	if (chan->data)
 		smp_chan_destroy(conn);
@@ -1365,8 +1366,8 @@ static void smp_distribute_keys(struct smp_chan *smp)
 
 	set_bit(SMP_FLAG_COMPLETE, &smp->flags);
 	smp_notify_keys(conn);
-
 	smp_chan_destroy(conn);
+	l2cap_security_recheck(conn);
 }
 
 static void smp_timeout(struct work_struct *work)
#21 lore raw

PATCH v14 2/2 Bluetooth: L2CAP: Keep credits from completing security upgrades

In reply to Kyle Pepper

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.

Finish requests on the existing HCI workqueue, outside the confirmation list walk. Hold selected channels before callbacks can remove siblings. Latch SMP failure before admitting a fresh request, clear pending flags on close, and recheck channel state before processing deferred confirmations. Use the existing pairing and HCI timeouts without a new request deadline.

Reject overlapping requests with EBUSY while pairing, key distribution or encryption is in progress. This includes repeated and lowered requests; applications can retry after the current procedure completes. Return EACCES when SMP starts no procedure and the requirements remain unmet, restoring the channel requirements and both pending link requirements. Preserve each CoC's requested level across shared-link confirmations.

Keep deferred reads pending during an upgrade. Send an ECRED response before releasing accepted children's data, let rejection override pending siblings, and close every deleted child. Return the batch's security error to a deferred reader while preserving ordinary accept/close behavior. Purge retained CoC data even if deferred acceptance left configuration incomplete. Acquire the SMP channel lock without holding the socket lock, and suspend pending ATT sockets until their confirmation resumes them.

Reject an incoming deferred ECRED batch when an accepted child closes before the connection response, so its siblings cannot stay suspended.

Keep deferred ECRED identifiers and flags until the response is queued, then release accepted children under their own channel locks. Clear those fields on rejection too. Exclude outgoing authentication retries from incoming batches even when their signaling identifiers collide.

If another shared-link encryption procedure starts after a confirmation was queued, keep security pending until its confirmation arrives rather than closing a channel whose requirements may still be satisfied.

AI assistance: Codex prepared and tested the security-upgrade and deferred-ECRED changes in prior revisions, including the supplied v13 follow-up fixes, and assisted with this commit message and revision notes. Work followed the reported credit/security failures and supplied review findings; validation used compiler builds and source-extracted sanitizer models with mutation controls.

Fixes fad5fc89594d ("Bluetooth: Add LE flow control discipline")

---
Changes in v14:
- Replace the obsolete Assisted-by trailer with AI disclosure in each commit message, following current kernel tool-generated content guidance.
- Rebase on current bluetooth-next; both patches' code is unchanged.

Previous v13 (no cover letter):
https://lore.kernel.org/linux-bluetooth/9d9d37680044266dbd1d6919b08564026afcd87d.1795528595.git.github.filter194@slmail.me/

V13 CI passed all 12 other jobs, including the kernel builds and l2cap-tester. CheckPatch rejected the obsolete Assisted-by: LLM trailer. Those are v13 results; v14 remote CI has not run.

 include/net/bluetooth/l2cap.h |   9 +-
 net/bluetooth/l2cap_core.c    | 378 +++++++++++++++++++++++++++++++---
 net/bluetooth/l2cap_sock.c    | 181 ++++++++++------
 net/bluetooth/smp.c           |   1 +
 4 files changed, 470 insertions(+), 99 deletions(-)
include/net/bluetooth/l2cap.h +8 -1
index 72d9d56c6f2a2e513acd41f9d1e0d08d99d9cdf8..8519099c0a701422c2a0270c98cc35e4f67c3a6f 100644
@@ -609,6 +609,7 @@ struct l2cap_chan {
 	__u32		remote_flush_to;
 
 	struct delayed_work	chan_timer;
+	struct list_head	security_list;
 	struct delayed_work	retrans_timer;
 	struct delayed_work	monitor_timer;
 	struct delayed_work	ack_timer;
@@ -649,6 +650,8 @@ struct l2cap_conn {
 
 	struct sk_buff_head	pending_rx;
 	struct work_struct	pending_rx_work;
+	struct work_struct	security_work;
+	atomic_t		security_failure;
 	bool			pending_rx_blocked __guarded_by(&lock);
 
 	struct delayed_work	id_addr_timer;
@@ -772,6 +775,8 @@ enum {
 	FLAG_ECRED_CONN_REQ_SENT,
 	FLAG_ECRED_RECONF_REQ_SENT,
 	FLAG_PENDING_SECURITY,
+	FLAG_SECURITY_CFM,
+	FLAG_SECURITY_FAILED,
 	FLAG_HOLD_HCI_CONN,
 	FLAG_DEL,
 };
@@ -979,7 +984,7 @@ void l2cap_cleanup_sockets(void);
 bool l2cap_is_socket(struct socket *sock);
 
 void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan);
-void __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan)
+int __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan)
 	__must_hold(&chan->lock) __must_hold(&chan->conn->lock);
 void __l2cap_connect_rsp_defer(struct l2cap_chan *chan);
 
@@ -998,6 +1003,8 @@ void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
 void l2cap_chan_rx_avail(struct l2cap_chan *chan, ssize_t rx_avail);
 void l2cap_chan_req_mic_len(struct l2cap_chan *chan, struct hci_conn *hcon);
 int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator);
+int l2cap_chan_set_security(struct l2cap_chan *chan, u8 level, u8 mic_len);
+void l2cap_security_failure(struct l2cap_conn *conn);
 void l2cap_chan_set_defaults(struct l2cap_chan *chan, struct l2cap_chan *pchan);
 int l2cap_ertm_init(struct l2cap_chan *chan);
 void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan);
net/bluetooth/l2cap_core.c +346 -32

543 lines not on this page · raw message

net/bluetooth/l2cap_sock.c +115 -66

231 lines not on this page · raw message

net/bluetooth/smp.c +1 -0
index 62a6b1e8f7cb11eed874dbacf211fe861513f2fa..bc54e0e65e19624c775edb94a0e8fca2c8fc5305 100644
@@ -785,6 +785,7 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason)
 			     &reason);
 
 	mgmt_auth_failed(hcon, HCI_ERROR_AUTH_FAILURE);
+	l2cap_security_failure(conn);
 
 	if (chan->data)
 		smp_chan_destroy(conn);
#22 lore raw

PATCH v13 2/2 Bluetooth: L2CAP: Keep credits from completing security upgrades

In reply to Kyle Pepper

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.

Finish requests on the existing HCI workqueue, outside the confirmation list walk. Hold selected channels before callbacks can remove siblings. Latch SMP failure before admitting a fresh request, clear pending flags on close, and recheck channel state before processing deferred confirmations. Use the existing pairing and HCI timeouts without a new request deadline.

Reject overlapping requests with EBUSY while pairing, key distribution or encryption is in progress. This includes repeated and lowered requests; applications can retry after the current procedure completes. Return EACCES when SMP starts no procedure and the requirements remain unmet, restoring the channel requirements and both pending link requirements. Preserve each CoC's requested level across shared-link confirmations.

Keep deferred reads pending during an upgrade. Send an ECRED response before releasing accepted children's data, let rejection override pending siblings, and close every deleted child. Return the batch's security error to a deferred reader while preserving ordinary accept/close behavior. Purge retained CoC data even if deferred acceptance left configuration incomplete. Acquire the SMP channel lock without holding the socket lock, and suspend pending ATT sockets until their confirmation resumes them.

Reject an incoming deferred ECRED batch when an accepted child closes before the connection response, so its siblings cannot stay suspended.

Keep deferred ECRED identifiers and flags until the response is queued, then release accepted children under their own channel locks. Clear those fields on rejection too. Exclude outgoing authentication retries from incoming batches even when their signaling identifiers collide.

If another shared-link encryption procedure starts after a confirmation was queued, keep security pending until its confirmation arrives rather than closing a channel whose requirements may still be satisfied.

Fixes fad5fc89594d ("Bluetooth: Add LE flow control discipline")
Assisted-by LLM
---
 include/net/bluetooth/l2cap.h |   9 +-
 net/bluetooth/l2cap_core.c    | 378 +++++++++++++++++++++++++++++++---
 net/bluetooth/l2cap_sock.c    | 181 ++++++++++------
 net/bluetooth/smp.c           |   1 +
 4 files changed, 470 insertions(+), 99 deletions(-)
include/net/bluetooth/l2cap.h +8 -1
index 72d9d56c6..8519099c0 100644
@@ -609,6 +609,7 @@ struct l2cap_chan {
 	__u32		remote_flush_to;
 
 	struct delayed_work	chan_timer;
+	struct list_head	security_list;
 	struct delayed_work	retrans_timer;
 	struct delayed_work	monitor_timer;
 	struct delayed_work	ack_timer;
@@ -649,6 +650,8 @@ struct l2cap_conn {
 
 	struct sk_buff_head	pending_rx;
 	struct work_struct	pending_rx_work;
+	struct work_struct	security_work;
+	atomic_t		security_failure;
 	bool			pending_rx_blocked __guarded_by(&lock);
 
 	struct delayed_work	id_addr_timer;
@@ -772,6 +775,8 @@ enum {
 	FLAG_ECRED_CONN_REQ_SENT,
 	FLAG_ECRED_RECONF_REQ_SENT,
 	FLAG_PENDING_SECURITY,
+	FLAG_SECURITY_CFM,
+	FLAG_SECURITY_FAILED,
 	FLAG_HOLD_HCI_CONN,
 	FLAG_DEL,
 };
@@ -979,7 +984,7 @@ void l2cap_cleanup_sockets(void);
 bool l2cap_is_socket(struct socket *sock);
 
 void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan);
-void __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan)
+int __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan)
 	__must_hold(&chan->lock) __must_hold(&chan->conn->lock);
 void __l2cap_connect_rsp_defer(struct l2cap_chan *chan);
 
@@ -998,6 +1003,8 @@ void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
 void l2cap_chan_rx_avail(struct l2cap_chan *chan, ssize_t rx_avail);
 void l2cap_chan_req_mic_len(struct l2cap_chan *chan, struct hci_conn *hcon);
 int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator);
+int l2cap_chan_set_security(struct l2cap_chan *chan, u8 level, u8 mic_len);
+void l2cap_security_failure(struct l2cap_conn *conn);
 void l2cap_chan_set_defaults(struct l2cap_chan *chan, struct l2cap_chan *pchan);
 int l2cap_ertm_init(struct l2cap_chan *chan);
 void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan);
net/bluetooth/l2cap_core.c +346 -32

543 lines not on this page · raw message

net/bluetooth/l2cap_sock.c +115 -66

231 lines not on this page · raw message

net/bluetooth/smp.c +1 -0
index 62a6b1e8f..bc54e0e65 100644
@@ -785,6 +785,7 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason)
 			     &reason);
 
 	mgmt_auth_failed(hcon, HCI_ERROR_AUTH_FAILURE);
+	l2cap_security_failure(conn);
 
 	if (chan->data)
 		smp_chan_destroy(conn);
#23 lore raw

PATCH v12 2/2 Bluetooth: L2CAP: Keep credits from completing security upgrades

In reply to Kyle Pepper

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.

Finish requests on the existing HCI workqueue, outside the confirmation list walk. Hold selected channels before callbacks can remove siblings. Latch SMP failure before admitting a fresh request, clear pending flags on close, and recheck channel state before processing deferred confirmations. Use the existing pairing and HCI timeouts without a new request deadline.

Reject overlapping requests with EBUSY while pairing, key distribution or encryption is in progress. This includes repeated and lowered requests; applications can retry after the current procedure completes. Return EACCES when SMP starts no procedure and the requirements remain unmet, restoring the channel requirements and both pending link requirements. Preserve each CoC's requested level across shared-link confirmations.

Keep deferred reads pending during an upgrade. Send an ECRED response before releasing accepted children's data, let rejection override pending siblings, and close every deleted child. Return the batch's security error to a deferred reader while preserving ordinary accept/close behavior. Purge retained CoC data even if deferred acceptance left configuration incomplete. Acquire the SMP channel lock without holding the socket lock, and suspend pending ATT sockets until their confirmation resumes them.

Reject an incoming deferred ECRED batch when an accepted child closes before the connection response, so its siblings cannot stay suspended.

Fixes fad5fc89594d ("Bluetooth: Add LE flow control discipline")
Assisted-by LLM
---
 include/net/bluetooth/l2cap.h |   9 +-
 net/bluetooth/l2cap_core.c    | 333 +++++++++++++++++++++++++++++++---
 net/bluetooth/l2cap_sock.c    | 181 +++++++++++-------
 net/bluetooth/smp.c           |   1 +
 4 files changed, 435 insertions(+), 89 deletions(-)
include/net/bluetooth/l2cap.h +8 -1
index cf5c2df68..b004cc643 100644
@@ -604,6 +604,7 @@ struct l2cap_chan {
 	__u32		remote_flush_to;
 
 	struct delayed_work	chan_timer;
+	struct list_head	security_list;
 	struct delayed_work	retrans_timer;
 	struct delayed_work	monitor_timer;
 	struct delayed_work	ack_timer;
@@ -644,6 +645,8 @@ struct l2cap_conn {
 
 	struct sk_buff_head	pending_rx;
 	struct work_struct	pending_rx_work;
+	struct work_struct	security_work;
+	atomic_t		security_failure;
 	bool			pending_rx_blocked __guarded_by(&lock);
 
 	struct delayed_work	id_addr_timer;
@@ -767,6 +770,8 @@ enum {
 	FLAG_ECRED_CONN_REQ_SENT,
 	FLAG_ECRED_RECONF_REQ_SENT,
 	FLAG_PENDING_SECURITY,
+	FLAG_SECURITY_CFM,
+	FLAG_SECURITY_FAILED,
 	FLAG_HOLD_HCI_CONN,
 	FLAG_DEL,
 };
@@ -974,7 +979,7 @@ void l2cap_cleanup_sockets(void);
 bool l2cap_is_socket(struct socket *sock);
 
 void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan);
-void __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan)
+int __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan)
 	__must_hold(&chan->lock) __must_hold(&chan->conn->lock);
 void __l2cap_connect_rsp_defer(struct l2cap_chan *chan);
 
@@ -993,6 +998,8 @@ void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
 void l2cap_chan_rx_avail(struct l2cap_chan *chan, ssize_t rx_avail);
 void l2cap_chan_req_mic_len(struct l2cap_chan *chan, struct hci_conn *hcon);
 int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator);
+int l2cap_chan_set_security(struct l2cap_chan *chan, u8 level, u8 mic_len);
+void l2cap_security_failure(struct l2cap_conn *conn);
 void l2cap_chan_set_defaults(struct l2cap_chan *chan, struct l2cap_chan *pchan);
 int l2cap_ertm_init(struct l2cap_chan *chan);
 void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan);
net/bluetooth/l2cap_core.c +311 -22

486 lines not on this page · raw message

net/bluetooth/l2cap_sock.c +115 -66

231 lines not on this page · raw message

net/bluetooth/smp.c +1 -0
index f8f86b8f7..84d85613c 100644
@@ -785,6 +785,7 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason)
 			     &reason);
 
 	mgmt_auth_failed(hcon, HCI_ERROR_AUTH_FAILURE);
+	l2cap_security_failure(conn);
 
 	if (chan->data)
 		smp_chan_destroy(conn);
#24 lore raw

PATCH v11 2/2 Bluetooth: L2CAP: Keep credits from completing security upgrades

In reply to Kyle Pepper

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.

Finish requests on the existing HCI workqueue, outside the confirmation list walk. Hold selected channels before callbacks can remove siblings. Latch SMP failure before admitting a fresh request, clear pending flags on close, and recheck channel state before processing deferred confirmations. Use the existing pairing and HCI timeouts without a new request deadline.

Reject overlapping requests with EBUSY while pairing, key distribution or encryption is in progress. This includes repeated and lowered requests; applications can retry after the current procedure completes. Return EACCES when SMP starts no procedure and the requirements remain unmet, restoring the channel requirements and both pending link requirements. Preserve each CoC's requested level across shared-link confirmations.

Keep deferred reads pending during an upgrade. Send an ECRED response before releasing accepted children's data, let rejection override pending siblings, and close every deleted child. Return the batch's security error to a deferred reader while preserving ordinary accept/close behavior. Purge retained CoC data even if deferred acceptance left configuration incomplete. Acquire the SMP channel lock without holding the socket lock, and suspend pending ATT sockets until their confirmation resumes them.

Fixes fad5fc89594d ("Bluetooth: Add LE flow control discipline")
Assisted-by LLM
---
 include/net/bluetooth/l2cap.h |   9 +-
 net/bluetooth/l2cap_core.c    | 326 +++++++++++++++++++++++++++++++---
 net/bluetooth/l2cap_sock.c    | 181 ++++++++++++-------
 net/bluetooth/smp.c           |   1 +
 4 files changed, 428 insertions(+), 89 deletions(-)
include/net/bluetooth/l2cap.h +8 -1
index cf5c2df68..b004cc643 100644
@@ -604,6 +604,7 @@ struct l2cap_chan {
 	__u32		remote_flush_to;
 
 	struct delayed_work	chan_timer;
+	struct list_head	security_list;
 	struct delayed_work	retrans_timer;
 	struct delayed_work	monitor_timer;
 	struct delayed_work	ack_timer;
@@ -644,6 +645,8 @@ struct l2cap_conn {
 
 	struct sk_buff_head	pending_rx;
 	struct work_struct	pending_rx_work;
+	struct work_struct	security_work;
+	atomic_t		security_failure;
 	bool			pending_rx_blocked __guarded_by(&lock);
 
 	struct delayed_work	id_addr_timer;
@@ -767,6 +770,8 @@ enum {
 	FLAG_ECRED_CONN_REQ_SENT,
 	FLAG_ECRED_RECONF_REQ_SENT,
 	FLAG_PENDING_SECURITY,
+	FLAG_SECURITY_CFM,
+	FLAG_SECURITY_FAILED,
 	FLAG_HOLD_HCI_CONN,
 	FLAG_DEL,
 };
@@ -974,7 +979,7 @@ void l2cap_cleanup_sockets(void);
 bool l2cap_is_socket(struct socket *sock);
 
 void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan);
-void __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan)
+int __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan)
 	__must_hold(&chan->lock) __must_hold(&chan->conn->lock);
 void __l2cap_connect_rsp_defer(struct l2cap_chan *chan);
 
@@ -993,6 +998,8 @@ void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
 void l2cap_chan_rx_avail(struct l2cap_chan *chan, ssize_t rx_avail);
 void l2cap_chan_req_mic_len(struct l2cap_chan *chan, struct hci_conn *hcon);
 int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator);
+int l2cap_chan_set_security(struct l2cap_chan *chan, u8 level, u8 mic_len);
+void l2cap_security_failure(struct l2cap_conn *conn);
 void l2cap_chan_set_defaults(struct l2cap_chan *chan, struct l2cap_chan *pchan);
 int l2cap_ertm_init(struct l2cap_chan *chan);
 void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan);
net/bluetooth/l2cap_core.c +304 -22

473 lines not on this page · raw message

net/bluetooth/l2cap_sock.c +115 -66

231 lines not on this page · raw message

net/bluetooth/smp.c +1 -0
index f8f86b8f7..84d85613c 100644
@@ -785,6 +785,7 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason)
 			     &reason);
 
 	mgmt_auth_failed(hcon, HCI_ERROR_AUTH_FAILURE);
+	l2cap_security_failure(conn);
 
 	if (chan->data)
 		smp_chan_destroy(conn);