* [PATCH v2] Bluetooth: L2CAP: Fix ERTM re-init and zero pdu_len infinite loop
@ 2026-03-20 11:23 Hyunwoo Kim
2026-03-20 12:14 ` [v2] " bluez.test.bot
2026-03-23 19:40 ` [PATCH v2] " patchwork-bot+bluetooth
0 siblings, 2 replies; 3+ messages in thread
From: Hyunwoo Kim @ 2026-03-20 11:23 UTC (permalink / raw)
To: marcel, johan.hedberg, luiz.dentz; +Cc: linux-bluetooth, imv4bel
l2cap_config_req() processes CONFIG_REQ for channels in BT_CONNECTED
state to support L2CAP reconfiguration (e.g. MTU changes). However,
since both CONF_INPUT_DONE and CONF_OUTPUT_DONE are already set from
the initial configuration, the reconfiguration path falls through to
l2cap_ertm_init(), which re-initializes tx_q, srej_q, srej_list, and
retrans_list without freeing the previous allocations and sets
chan->sdu to NULL without freeing the existing skb. This leaks all
previously allocated ERTM resources.
Additionally, l2cap_parse_conf_req() does not validate the minimum
value of remote_mps derived from the RFC max_pdu_size option. A zero
value propagates to l2cap_segment_sdu() where pdu_len becomes zero,
causing the while loop to never terminate since len is never
decremented, exhausting all available memory.
Fix the double-init by skipping l2cap_ertm_init() and
l2cap_chan_ready() when the channel is already in BT_CONNECTED state,
while still allowing the reconfiguration parameters to be updated
through l2cap_parse_conf_req(). Also add a pdu_len zero check in
l2cap_segment_sdu() as a safeguard.
Fixes: 96298f640104 ("Bluetooth: L2CAP: handle l2cap config request during open state")
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
---
Changes in v2:
- Keep BT_CONNECTED in allowed states for l2cap_config_req()
- Skip l2cap_ertm_init() and l2cap_chan_ready() when already connected
- v1: https://lore.kernel.org/all/abwTCkavRurEcEGO@v4bel/
---
net/bluetooth/l2cap_core.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 5deb6c4f1e41..b80667c263ef 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -2377,6 +2377,9 @@ static int l2cap_segment_sdu(struct l2cap_chan *chan,
/* Remote device may have requested smaller PDUs */
pdu_len = min_t(size_t, pdu_len, chan->remote_mps);
+ if (!pdu_len)
+ return -EINVAL;
+
if (len <= pdu_len) {
sar = L2CAP_SAR_UNSEGMENTED;
sdu_len = 0;
@@ -4312,14 +4315,16 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,
if (test_bit(CONF_INPUT_DONE, &chan->conf_state)) {
set_default_fcs(chan);
- if (chan->mode == L2CAP_MODE_ERTM ||
- chan->mode == L2CAP_MODE_STREAMING)
- err = l2cap_ertm_init(chan);
+ if (chan->state != BT_CONNECTED) {
+ if (chan->mode == L2CAP_MODE_ERTM ||
+ chan->mode == L2CAP_MODE_STREAMING)
+ err = l2cap_ertm_init(chan);
- if (err < 0)
- l2cap_send_disconn_req(chan, -err);
- else
- l2cap_chan_ready(chan);
+ if (err < 0)
+ l2cap_send_disconn_req(chan, -err);
+ else
+ l2cap_chan_ready(chan);
+ }
goto unlock;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* RE: [v2] Bluetooth: L2CAP: Fix ERTM re-init and zero pdu_len infinite loop
2026-03-20 11:23 [PATCH v2] Bluetooth: L2CAP: Fix ERTM re-init and zero pdu_len infinite loop Hyunwoo Kim
@ 2026-03-20 12:14 ` bluez.test.bot
2026-03-23 19:40 ` [PATCH v2] " patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2026-03-20 12:14 UTC (permalink / raw)
To: linux-bluetooth, imv4bel
[-- Attachment #1: Type: text/plain, Size: 3101 bytes --]
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/project/bluetooth/list/?series=1069857
---Test result---
Test Summary:
CheckPatch PENDING 0.39 seconds
GitLint PENDING 0.30 seconds
SubjectPrefix PASS 0.09 seconds
BuildKernel PASS 26.91 seconds
CheckAllWarning PASS 29.45 seconds
CheckSparse PASS 28.54 seconds
BuildKernel32 PASS 26.27 seconds
TestRunnerSetup PASS 584.59 seconds
TestRunner_l2cap-tester FAIL 29.51 seconds
TestRunner_iso-tester FAIL 35.89 seconds
TestRunner_bnep-tester PASS 6.66 seconds
TestRunner_mgmt-tester FAIL 118.03 seconds
TestRunner_rfcomm-tester PASS 9.67 seconds
TestRunner_sco-tester FAIL 14.74 seconds
TestRunner_ioctl-tester PASS 10.65 seconds
TestRunner_mesh-tester FAIL 12.67 seconds
TestRunner_smp-tester PASS 9.00 seconds
TestRunner_userchan-tester PASS 6.85 seconds
IncrementalBuild PENDING 0.58 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: TestRunner_l2cap-tester - FAIL
Desc: Run l2cap-tester with test-runner
Output:
Total: 96, Passed: 95 (99.0%), Failed: 1, Not Run: 0
Failed Test Cases
L2CAP BR/EDR Server - Set PHY 2M Failed 0.125 seconds
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
Output:
BUG: KASAN: slab-use-after-free in le_read_features_complete+0x7e/0x2b0
Total: 141, Passed: 141 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4
Failed Test Cases
Read Exp Feature - Success Failed 0.117 seconds
##############################
Test: TestRunner_sco-tester - FAIL
Desc: Run sco-tester with test-runner
Output:
WARNING: possible circular locking dependency detected
BUG: sleeping function called from invalid context at net/core/sock.c:3782
Total: 30, Passed: 30 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner
Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0
Failed Test Cases
Mesh - Send cancel - 1 Timed out 2.608 seconds
Mesh - Send cancel - 2 Timed out 1.995 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] Bluetooth: L2CAP: Fix ERTM re-init and zero pdu_len infinite loop
2026-03-20 11:23 [PATCH v2] Bluetooth: L2CAP: Fix ERTM re-init and zero pdu_len infinite loop Hyunwoo Kim
2026-03-20 12:14 ` [v2] " bluez.test.bot
@ 2026-03-23 19:40 ` patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2026-03-23 19:40 UTC (permalink / raw)
To: Hyunwoo Kim; +Cc: marcel, johan.hedberg, luiz.dentz, linux-bluetooth
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Fri, 20 Mar 2026 20:23:10 +0900 you wrote:
> l2cap_config_req() processes CONFIG_REQ for channels in BT_CONNECTED
> state to support L2CAP reconfiguration (e.g. MTU changes). However,
> since both CONF_INPUT_DONE and CONF_OUTPUT_DONE are already set from
> the initial configuration, the reconfiguration path falls through to
> l2cap_ertm_init(), which re-initializes tx_q, srej_q, srej_list, and
> retrans_list without freeing the previous allocations and sets
> chan->sdu to NULL without freeing the existing skb. This leaks all
> previously allocated ERTM resources.
>
> [...]
Here is the summary with links:
- [v2] Bluetooth: L2CAP: Fix ERTM re-init and zero pdu_len infinite loop
https://git.kernel.org/bluetooth/bluetooth-next/c/acf374fce194
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-23 19:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20 11:23 [PATCH v2] Bluetooth: L2CAP: Fix ERTM re-init and zero pdu_len infinite loop Hyunwoo Kim
2026-03-20 12:14 ` [v2] " bluez.test.bot
2026-03-23 19:40 ` [PATCH v2] " patchwork-bot+bluetooth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox