Bluetooth: L2CAP: Fix ERTM re-init and zero pdu_len infinite loop
Subsystems (2)
PATCH 1/1 Bluetooth: L2CAP: Fix ERTM re-init and zero pdu_len infinite loop
l2cap_config_req() accepts CONFIG_REQ when the channel is already in BT_CONNECTED state. This causes l2cap_ertm_init() to be called a second time, re-initializing tx_q, srej_q, srej_list, and retrans_list without freeing the previous allocations, and setting 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 by removing BT_CONNECTED from the allowed states in l2cap_config_req() and adding a pdu_len zero check in l2cap_segment_sdu() as a safeguard.
--- net/bluetooth/l2cap_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/bluetooth/l2cap_core.c +4 -2
@@ -2381,6 +2381,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 ;
@@ -4267,8 +4270,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,return 0 ; } -if (chan->state !=BT_CONFIG && chan->state !=BT_CONNECT2 && - chan->state !=BT_CONNECTED ) { +if (chan->state !=BT_CONFIG && chan->state !=BT_CONNECT2 ) {cmd_reject_invalid_cid (conn, cmd->ident, chan->scid, chan->dcid); goto unlock;
Signature · 1 line
2.43.0
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=1069346
---Test result---
Test Summary:
CheckPatch PENDING 0.67 seconds GitLint PENDING 0.50 seconds SubjectPrefix PASS 0.05 seconds BuildKernel PASS 26.37 seconds CheckAllWarning PASS 28.52 seconds CheckSparse PASS 27.38 seconds BuildKernel32 PASS 25.35 seconds TestRunnerSetup PASS 564.19 seconds TestRunner_l2cap-tester PASS 27.33 seconds TestRunner_iso-tester FAIL 29.99 seconds TestRunner_bnep-tester PASS 6.30 seconds TestRunner_mgmt-tester FAIL 112.94 seconds TestRunner_rfcomm-tester PASS 9.29 seconds TestRunner_sco-tester FAIL 14.23 seconds TestRunner_ioctl-tester PASS 13.73 seconds TestRunner_mesh-tester FAIL 11.48 seconds TestRunner_smp-tester PASS 8.37 seconds TestRunner_userchan-tester PASS 6.66 seconds IncrementalBuild PENDING 0.70 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
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.105 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 1.938 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
Luiz Augusto von Dentz
maintainerHi Hyunwoo,
Quoted 14 lines · Hyunwoo Kim
l2cap_config_req()acceptsCONFIG_REQwhen the channel is already inBT_CONNECTEDstate. This causesl2cap_ertm_init()to be called a second time, re-initializingtx_q,srej_q,srej_list, andretrans_listwithout freeing the previous allocations, and settingchan->sduto NULL without freeing the existing skb. This leaks all previously allocated ERTM resources.Additionally,
l2cap_parse_conf_req()does not validate the minimum value ofremote_mpsderived from the RFCmax_pdu_sizeoption. A zero value propagates tol2cap_segment_sdu()wherepdu_lenbecomes zero, causing the while loop to never terminate since len is never decremented, exhausting all available memory.
Quoted 3 lines
Fix by removing
BT_CONNECTEDfrom the allowed states inl2cap_config_req()and adding apdu_lenzero check inl2cap_segment_sdu()as a safeguard.
This part is not clerarm it should be allowed to change the MTU while connected.
Quoted 33 lines
Fixes 96298f640104 ("Bluetooth: L2CAP: handle l2cap config request during open state")Signed-off-by Hyunwoo Kim <[email protected]>--- net/bluetooth/l2cap_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)net/bluetooth/l2cap_core.c +4
-3@@ -2381,6 +2381,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 ;@@ -4267,8 +4270,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,return 0 ; } -if (chan->state !=BT_CONFIG && chan->state !=BT_CONNECT2 && - chan->state !=BT_CONNECTED ) { +if (chan->state !=BT_CONFIG && chan->state !=BT_CONNECT2 ) {cmd_reject_invalid_cid (conn, cmd->ident, chan->scid, chan->dcid); goto unlock; --2.43.0
Signature · 1 line
Luiz Augusto von Dentz
Luiz Augusto von Dentz
maintainerHi Hyunwoo,
Quoted 18 lines · Luiz Augusto von Dentz
Hi Hyunwoo,
Quoted 14 lines · Hyunwoo Kim
l2cap_config_req()acceptsCONFIG_REQwhen the channel is already inBT_CONNECTEDstate. This causesl2cap_ertm_init()to be called a second time, re-initializingtx_q,srej_q,srej_list, andretrans_listwithout freeing the previous allocations, and settingchan->sduto NULL without freeing the existing skb. This leaks all previously allocated ERTM resources.Additionally,
l2cap_parse_conf_req()does not validate the minimum value ofremote_mpsderived from the RFCmax_pdu_sizeoption. A zero value propagates tol2cap_segment_sdu()wherepdu_lenbecomes zero, causing the while loop to never terminate since len is never decremented, exhausting all available memory.
Quoted 5 lines
Quoted 3 lines
Fix by removing
BT_CONNECTEDfrom the allowed states inl2cap_config_req()and adding apdu_lenzero check inl2cap_segment_sdu()as a safeguard.This part is not clerarm it should be allowed to change the MTU while connected.
Looks like AI agree with me (Second point, first point is probably not possible):
https://sashiko.dev/#/patchset/abwTCkavRurEcEGO%40v4bel
Quoted 38 lines
Quoted 32 lines
Fixes 96298f640104 ("Bluetooth: L2CAP: handle l2cap config request during open state")Signed-off-by Hyunwoo Kim <[email protected]>--- net/bluetooth/l2cap_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)net/bluetooth/l2cap_core.c +4
-3@@ -2381,6 +2381,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 ;@@ -4267,8 +4270,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,return 0 ; } -if (chan->state !=BT_CONFIG && chan->state !=BT_CONNECT2 && - chan->state !=BT_CONNECTED ) { +if (chan->state !=BT_CONFIG && chan->state !=BT_CONNECT2 ) {cmd_reject_invalid_cid (conn, cmd->ident, chan->scid, chan->dcid); goto unlock; --Quoted 2 lines
2.43.0
--
Luiz Augusto von Dentz
Signature · 1 line
Luiz Augusto von Dentz