Skip to contentSkip to conversation

Bluetooth: L2CAP: CoC: Disconnect if received packet size exceeds MPS

PATCH Applied Luiz Augusto von Dentz 4 participants 6 messages Feb 26 – Feb 27

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/1 Bluetooth: L2CAP: CoC: Disconnect if received packet size exceeds MPS

From: Christian Eggers <[email protected]>

Core 6.0, Vol 3, Part A, 3.4.3:
"... If the payload size of any K-frame exceeds the receiver's MPS, the receiver shall disconnect the channel..."

This fixes L2CAP/LE/CFC/BV-27-C (running together with 'l2test -r -P 0x0027 -V le_public -I 100').

---
Note: due to lack of L2CAP CoC segmentation support in bthost the following test as expected to fail:

L2CAP LE Client - Read 32k Success
L2CAP LE Client - RX Timestamping 32k

 net/bluetooth/l2cap_core.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/bluetooth/l2cap_core.c +7 -0
index f550ceceb618..14131e427efd 100644
@@ -6669,6 +6669,13 @@ static int l2cap_ecred_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
 		return -ENOBUFS;
 	}
 
+	if (skb->len > chan->mps) {
+		BT_ERR("Too big LE L2CAP MPS: len %u > %u", skb->len,
+		       chan->mps);
+		l2cap_send_disconn_req(chan, ECONNRESET);
+		return -ENOBUFS;
+	}
+
 	chan->rx_credits--;
 	BT_DBG("chan %p: rx_credits %u -> %u",
 	       chan, chan->rx_credits + 1, chan->rx_credits);
Signature · 1 line
2.52.0
author maintainer
#1 lore raw

Hi Christian,

Quoted 10 lines · Luiz Augusto von Dentz

From: Christian Eggers <[email protected]>

Core 6.0, Vol 3, Part A, 3.4.3:
"... If the payload size of any K-frame exceeds the receiver's MPS, the receiver shall disconnect the channel..."

This fixes L2CAP/LE/CFC/BV-27-C (running together with 'l2test -r -P 0x0027 -V le_public -I 100').

Quoted 8 lines

---
Note: due to lack of L2CAP CoC segmentation support in bthost the following test as expected to fail:

L2CAP LE Client - Read 32k Success
L2CAP LE Client - RX Timestamping 32k

I didn't have to introduce any new fields btw since the above tests confirm the MPS is working. I reverted to just using chan->mps, remote mps is tracked by remote_mps field and I check that the remote cannot actually set our own MPS. I wonder if something else was at play or if there is some specific requirement for L2CAP/LE/CFC/BV-27-C (e.g. reconfigure?)

Quoted 25 lines
 net/bluetooth/l2cap_core.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/bluetooth/l2cap_core.c +7 -1
index f550ceceb618..14131e427efd 100644
@@ -6669,6 +6669,13 @@ static int l2cap_ecred_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
                return -ENOBUFS;
        }
 
+       if (skb->len > chan->mps) {
+               BT_ERR("Too big LE L2CAP MPS: len %u > %u", skb->len,
+                      chan->mps);
+               l2cap_send_disconn_req(chan, ECONNRESET);
+               return -ENOBUFS;
+       }
+
        chan->rx_credits--;
        BT_DBG("chan %p: rx_credits %u -> %u",
               chan, chan->rx_credits + 1, chan->rx_credits);
--

2.52.0

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

Hi Luiz,

Quoted 23 lines · Luiz Augusto von Dentz

Hi Christian,

Quoted 10 lines · Luiz Augusto von Dentz

From: Christian Eggers <[email protected]>

Core 6.0, Vol 3, Part A, 3.4.3:
"... If the payload size of any K-frame exceeds the receiver's MPS, the receiver shall disconnect the channel..."

This fixes L2CAP/LE/CFC/BV-27-C (running together with 'l2test -r -P 0x0027 -V le_public -I 100').

Quoted 8 lines

---
Note: due to lack of L2CAP CoC segmentation support in bthost the following test as expected to fail:

L2CAP LE Client - Read 32k Success
L2CAP LE Client - RX Timestamping 32k

Quoted 6 lines

I didn't have to introduce any new fields btw since the above tests confirm the MPS is working. I reverted to just using chan->mps, remote mps is tracked by remote_mps field and I check that the remote cannot actually set our own MPS. I wonder if something else was at play or if there is some specific requirement for L2CAP/LE/CFC/BV-27-C (e.g. reconfigure?)

Unfortunately I cannot tell anymore why simply checking chan->mps was not sufficient for me. I have tested your simplified version and L2CAP/LE/CFC/BV-27-C runs fine. So you can add this to bluetooth-next.

BTW: In the description of the other patch
"LE L2CAP: Disconnect if sum of payload sizes exceed SDU", the PTS test seem to be wrong:

L2CAP/LE/CFC/BV-27-C --> L2CAP/LE/CFC/BV-28-C

Maybe you would like to fix this in bluetooth-next

regards,
Christian

Quoted 29 lines
Quoted 26 lines

 net/bluetooth/l2cap_core.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/bluetooth/l2cap_core.c +7 -1
index f550ceceb618..14131e427efd 100644
@@ -6669,6 +6669,13 @@ static int l2cap_ecred_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
                return -ENOBUFS;
        }
 
+       if (skb->len > chan->mps) {
+               BT_ERR("Too big LE L2CAP MPS: len %u > %u", skb->len,
+                      chan->mps);
+               l2cap_send_disconn_req(chan, ECONNRESET);
+               return -ENOBUFS;
+       }
+
        chan->rx_credits--;
        BT_DBG("chan %p: rx_credits %u -> %u",
               chan, chan->rx_credits + 1, chan->rx_credits);
--

2.52.0

#3 lore raw
In reply to Luiz Augusto von Dentz

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=1058650

---Test result---

Test Summary:

CheckPatch                    PENDING   0.51 seconds
GitLint                       PENDING   0.41 seconds
SubjectPrefix                 PASS      0.06 seconds
BuildKernel                   PASS      26.47 seconds
CheckAllWarning               PASS      28.77 seconds
CheckSparse                   WARNING   32.37 seconds
BuildKernel32                 PASS      25.65 seconds
TestRunnerSetup               PASS      572.31 seconds
TestRunner_l2cap-tester       FAIL      33.20 seconds
TestRunner_iso-tester         FAIL      43.43 seconds
TestRunner_bnep-tester        PASS      6.53 seconds
TestRunner_mgmt-tester        FAIL      115.20 seconds
TestRunner_rfcomm-tester      PASS      9.37 seconds
TestRunner_sco-tester         FAIL      14.74 seconds
TestRunner_ioctl-tester       PASS      10.20 seconds
TestRunner_mesh-tester        FAIL      12.42 seconds
TestRunner_smp-tester         PASS      8.53 seconds
TestRunner_userchan-tester    PASS      6.57 seconds
IncrementalBuild              PENDING   0.81 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
net/bluetooth/l2cap_core.c:7792:1: error: bad constant expressionnet/bluetooth/l2cap_core.c:7793:1: error: bad constant expressionnet/bluetooth/l2cap_core.c:7795:1: error: bad constant expressionnet/bluetooth/l2cap_core.c:7796:1: error: bad constant expression
##############################
Test: TestRunner_l2cap-tester - FAIL
Desc: Run l2cap-tester with test-runner
Output:
Total: 96, Passed: 94 (97.9%), Failed: 2, Not Run: 0

Failed Test Cases

L2CAP LE Client - Read 32k Success                   Timed out    2.371 seconds
L2CAP LE Client - RX Timestamping 32k                Timed out    1.896 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.107 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.718 seconds
Mesh - Send cancel - 2                               Timed out    1.991 seconds

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth

Tested-by on v2 1/1
#4 lore raw
In reply to Luiz Augusto von Dentz
Quoted 30 lines · Luiz Augusto von Dentz

From: Christian Eggers <[email protected]>

Core 6.0, Vol 3, Part A, 3.4.3:
"... If the payload size of any K-frame exceeds the receiver's MPS, the receiver shall disconnect the channel..."

This fixes L2CAP/LE/CFC/BV-27-C (running together with 'l2test -r -P 0x0027 -V le_public -I 100').

---
Note: due to lack of L2CAP CoC segmentation support in bthost the following test as expected to fail:

L2CAP LE Client - Read 32k Success
L2CAP LE Client - RX Timestamping 32k

 net/bluetooth/l2cap_core.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/bluetooth/l2cap_core.c +0 -0
index f550ceceb618..14131e427efd 100644
@@ -6669,6 +6669,13 @@ static int l2cap_ecred_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
 		return -ENOBUFS;
 	}
 

net/bluetooth/l2cap_core.c static int l2cap_ecred_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb) · line 6681

Quoted 10 lines
net/bluetooth/l2cap_core.c +7 -0
+	if (skb->len > chan->mps) {
+		BT_ERR("Too big LE L2CAP MPS: len %u > %u", skb->len,
+		       chan->mps);
+		l2cap_send_disconn_req(chan, ECONNRESET);
+		return -ENOBUFS;
+	}
+
 	chan->rx_credits--;
 	BT_DBG("chan %p: rx_credits %u -> %u",
 	       chan, chan->rx_credits + 1, chan->rx_credits);
#5 lore raw
In reply to Luiz Augusto von Dentz
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 10 lines · On Thu, 26 Feb 2026 15:43:57 -0500 you wrote:

From: Christian Eggers <[email protected]>

Core 6.0, Vol 3, Part A, 3.4.3:
"... If the payload size of any K-frame exceeds the receiver's MPS, the receiver shall disconnect the channel..."

This fixes L2CAP/LE/CFC/BV-27-C (running together with 'l2test -r -P 0x0027 -V le_public -I 100').

[...]

Here is the summary with links:
- [v2] Bluetooth: L2CAP: CoC: Disconnect if received packet size exceeds MPS

    https://git.kernel.org/bluetooth/bluetooth-next/c/cb75c9a0505b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html