Skip to contentSkip to conversation

Bluetooth: L2CAP: fix list corruption in l2cap_ecred_conn_rsp

PATCH In review Zhenghang Xiao 2 participants 2 messages May 26

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

PATCH 1/1 Bluetooth: L2CAP: fix list corruption in l2cap_ecred_conn_rsp

The duplicate DCID handling in l2cap_ecred_conn_rsp() calls l2cap_chan_del() on the channel found by __l2cap_get_chan_by_dcid(), which may be the 'tmp' pointer of the enclosing list_for_each_entry_safe loop. list_del() poisons tmp->list.next with LIST_POISON1, and the next iteration dereferences it:

  KASAN: wild-memory-access in range [0xdead000000000100-0xdead000000000107]
  pc : l2cap_recv_frame+0x3b7c/0x7360

Break out of the loop after the duplicate handling to avoid iterating with the corrupted pointer. Remaining pending channels for the same ident are not processed; they will time out via the standard L2CAP channel timeout since the response indicates a misbehaving peer. Add a NULL check on the second __l2cap_get_chan_by_dcid() call for robustness.

Fixes 15f02b910562 ("Bluetooth: L2CAP: Add initial code for Enhanced Credit Based Mode")
---
 net/bluetooth/l2cap_core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
net/bluetooth/l2cap_core.c +6 -4
index 7701528f1167..3456d741fb1c 100644
@@ -5292,10 +5292,12 @@ static inline int l2cap_ecred_conn_rsp(struct l2cap_conn *conn,
 			l2cap_chan_del(chan, ECONNREFUSED);
 			l2cap_chan_unlock(chan);
 			chan = __l2cap_get_chan_by_dcid(conn, dcid);
-			l2cap_chan_lock(chan);
-			l2cap_chan_del(chan, ECONNRESET);
-			l2cap_chan_unlock(chan);
-			continue;
+			if (chan) {
+				l2cap_chan_lock(chan);
+				l2cap_chan_del(chan, ECONNRESET);
+				l2cap_chan_unlock(chan);
+			}
+			break;
 		}
 
 		switch (result) {
Signature · 1 line
2.50.1 (Apple Git-155)
#1 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/project/bluetooth/list/?series=1100866

---Test result---

Test Summary:

CheckPatch                    FAIL      0.75 seconds
VerifyFixes                   PASS      0.14 seconds
VerifySignedoff               PASS      0.14 seconds
GitLint                       PASS      0.34 seconds
SubjectPrefix                 PASS      0.13 seconds
BuildKernel                   PASS      27.86 seconds
CheckAllWarning               PASS      30.00 seconds
CheckSparse                   PASS      29.08 seconds
BuildKernel32                 PASS      26.70 seconds
TestRunnerSetup               PASS      591.10 seconds
TestRunner_l2cap-tester       FAIL      61.70 seconds
IncrementalBuild              PASS      25.95 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[bluetooth-next] Bluetooth: L2CAP: fix list corruption in l2cap_ecred_conn_rsp
WARNING: Prefer a maximum 75 chars per line (possible unwrapped commit description?) #103:

  KASAN: wild-memory-access in range [0xdead000000000100-0xdead000000000107]

total: 0 errors, 1 warnings, 0 checks, 16 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.

/github/workspace/src/patch/14594665.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.

##############################
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 3M Failed 0.277 seconds

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

---
Regards,
Linux Bluetooth