Bluetooth: L2CAP: Restrict LE credits to connected CoCs
Subsystems (2)
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.
---
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
@@ -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
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.
--- 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
@@ -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
@@ -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);
PATCH v11 1/2 Bluetooth: L2CAP: Restrict LE credits to connected CoCs
In reply to Kyle PepperDo 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.
---
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
@@ -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
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:
ERROR: Unrecognized email address: 'LLM'
#89:
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
PATCH v12 1/2 Bluetooth: L2CAP: Restrict LE credits to connected CoCs
In reply to Kyle PepperDo 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.
---
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/
net/bluetooth/l2cap_core.c | 5 +++++ 1 file changed, 5 insertions(+)
net/bluetooth/l2cap_core.c +5 -0
@@ -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
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.
---
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
@@ -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
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:
ERROR: Unrecognized email address: 'LLM'
#92:
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
PATCH v14 1/2 Bluetooth: L2CAP: Restrict LE credits to connected CoCs
In reply to Kyle PepperDo 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.
---
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
@@ -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
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
PATCH v14 2/2 Bluetooth: L2CAP: Keep credits from completing security upgrades
In reply to Kyle PepperA 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.
---
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
@@ -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
@@ -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);
PATCH v13 2/2 Bluetooth: L2CAP: Keep credits from completing security upgrades
In reply to Kyle PepperA 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.
--- 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
@@ -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
@@ -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);
PATCH v12 2/2 Bluetooth: L2CAP: Keep credits from completing security upgrades
In reply to Kyle PepperA 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.
--- 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
@@ -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
@@ -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);
PATCH v11 2/2 Bluetooth: L2CAP: Keep credits from completing security upgrades
In reply to Kyle PepperA 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.
--- 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
@@ -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
@@ -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);