Skip to contentSkip to conversation

Bluetooth: L2CAP: Accept incomplete SDU

PATCH In review Frédéric Danis 3 participants 3 messages Nov 17, 2025

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

PATCH 1/1 Bluetooth: L2CAP: Accept incomplete SDU

During OBEX Abort command, iOS may return an incomplete SDU packet which ends with the reply to the Abort command.
During OBEX Abort command, iOS may return the L2CAP_SAR_END packet before the normal end of the SAR packets:

< ACL Data TX: Handle 21 [2/8] flags 0x00 dlen 11 #194 [hci0] 14.923741

      Channel: 3080 len 7 ctrl 0x060a [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: Unsegmented TxSeq 5 ReqSeq 6
        0a 06 ff 00 03 47 84                             .....G.

...

Quoted 1 line

ACL Data RX: Handle 21 flags 0x01 dlen 458 #382 [hci0] 19.701854

      Channel: 65 len 1006 ctrl 0x460e [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: Start (len 32767) TxSeq 7 ReqSeq 6
        0e 46 ff 7f 90 7f ff 48 7f fc 43 48 41 52 53 45  .F.....H..CHARSE
        ...
Quoted 2 lines

ACL Data RX: Handle 21 flags 0x02 dlen 552 #383 [hci0] 19.701854
ACL Data RX: Handle 21 flags 0x01 dlen 458 #384 [hci0] 19.755918

      Channel: 65 len 1006 ctrl 0xc610 [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: Continuation TxSeq 8 ReqSeq 6
        10 c6 6e 6f 73 61 69 72 65 73 64 65 73 69 67 6e  ..nosairesdesign
        ...
Quoted 2 lines

ACL Data RX: Handle 21 flags 0x02 dlen 552 #385 [hci0] 19.775016
ACL Data RX: Handle 21 flags 0x01 dlen 458 #386 [hci0] 19.775024

      Channel: 65 len 1006 ctrl 0xc612 [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: Continuation TxSeq 9 ReqSeq 6
        12 c6 69 63 6f 20 43 69 74 79 20 54 65 63 68 20  ..ico City Tech
        ...
Quoted 2 lines

ACL Data RX: Handle 21 flags 0x02 dlen 552 #387 [hci0] 19.775024
ACL Data RX: Handle 21 flags 0x01 dlen 458 #388 [hci0] 19.821542

      Channel: 65 len 1006 ctrl 0xc614 [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: Continuation TxSeq 10 ReqSeq 6
        14 c6 6c 74 69 6e 67 20 50 61 72 74 6e 65 72 0d  ..lting Partner.
        ...
Quoted 2 lines

ACL Data RX: Handle 21 flags 0x02 dlen 552 #389 [hci0] 19.821610
ACL Data RX: Handle 21 flags 0x01 dlen 458 #390 [hci0] 19.821610

      Channel: 65 len 1006 ctrl 0xc616 [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: Continuation TxSeq 11 ReqSeq 6
        16 c6 6c 74 69 6e 67 2e 63 6f 6d 0d 0a 55 49 44  ..lting.com..UID
        ...
Quoted 1 line

ACL Data RX: Handle 21 flags 0x02 dlen 11 #391 [hci0] 19.821610

      Channel: 65 len 7 ctrl 0x8618 [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: End TxSeq 12 ReqSeq 6
        18 86 a0 00 03 3e 5d                             .....>]

< ACL Data TX: Handle 21 [1/8] flags 0x00 dlen 12 #392 [hci0] 19.822491
L2CAP: Disconnection Request (0x06) ident 10 len 4
Destination CID: 3080
Source CID: 65

In this case the re-assembled packet should be 32767 bytes as defined in Start packet (#382), i.e. 33 segmented packets, but the End packet is sent as the 6th packet.

The l2cap_reassemble_sdu() function returns error -EINVAL if reassembled packet size != expected size, triggering the L2CAP disconnection, which disconnects the OBEX session, preventing further OBEX actions.

Log this, discard previous segmented packet data and only send data from SAR End packet to upstream.

---
 net/bluetooth/l2cap_core.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
net/bluetooth/l2cap_core.c +12 -5
index 35c57657bcf4..5fe1d058455e 100644
@@ -5703,13 +5703,20 @@ static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb,
 		if (!chan->sdu)
 			break;
 
-		append_skb_frag(chan->sdu, skb,
-				&chan->sdu_last_frag);
+		if (chan->sdu->len + skb->len != chan->sdu_len) {
+			BT_DBG("Incomplete SDU, expected: %u received: %u", chan->sdu_len,
+			       chan->sdu->len + skb->len);
+			/* Discard previous data and keep only L2CAP_SAR_END data */
+			kfree_skb(chan->sdu);
+			chan->sdu = skb;
+			chan->sdu_last_frag = skb;
+			chan->sdu_len = skb->len;
+		} else {
+			append_skb_frag(chan->sdu, skb,
+					&chan->sdu_last_frag);
+		}
 		skb = NULL;
 
-		if (chan->sdu->len != chan->sdu_len)
-			break;
-
 		err = chan->ops->recv(chan, chan->sdu);
 
 		if (!err) {
Signature · 1 line
2.43.0
#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=1024166

---Test result---

Test Summary:

CheckPatch                    PENDING   0.40 seconds
GitLint                       PENDING   0.33 seconds
SubjectPrefix                 PASS      0.07 seconds
BuildKernel                   PASS      24.80 seconds
CheckAllWarning               PASS      27.20 seconds
CheckSparse                   PASS      30.97 seconds
BuildKernel32                 PASS      25.10 seconds
TestRunnerSetup               PASS      502.50 seconds
TestRunner_l2cap-tester       PASS      24.12 seconds
TestRunner_iso-tester         PASS      91.19 seconds
TestRunner_bnep-tester        PASS      6.07 seconds
TestRunner_mgmt-tester        FAIL      113.26 seconds
TestRunner_rfcomm-tester      PASS      9.21 seconds
TestRunner_sco-tester         PASS      14.29 seconds
TestRunner_ioctl-tester       PASS      9.84 seconds
TestRunner_mesh-tester        FAIL      11.50 seconds
TestRunner_smp-tester         PASS      8.27 seconds
TestRunner_userchan-tester    PASS      6.31 seconds
IncrementalBuild              PENDING   0.77 seconds

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

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

##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner Output:
Total: 492, Passed: 486 (98.8%), Failed: 2, Not Run: 4

Failed Test Cases

Read Exp Feature - Success                           Failed       0.094 seconds
LL Privacy - Add Device 2 (2 Devices to AL)          Failed       0.179 seconds

##############################
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.050 seconds
Mesh - Send cancel - 2                               Timed out    1.998 seconds

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

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Frédéric Danis

Hi Frédéric,

Quoted 81 lines · Frédéric Danis

During OBEX Abort command, iOS may return an incomplete SDU packet which ends with the reply to the Abort command.
During OBEX Abort command, iOS may return the L2CAP_SAR_END packet before the normal end of the SAR packets:

< ACL Data TX: Handle 21 [2/8] flags 0x00 dlen 11 #194 [hci0] 14.923741

      Channel: 3080 len 7 ctrl 0x060a [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: Unsegmented TxSeq 5 ReqSeq 6
        0a 06 ff 00 03 47 84                             .....G.

...

Quoted 1 line

ACL Data RX: Handle 21 flags 0x01 dlen 458 #382 [hci0] 19.701854

      Channel: 65 len 1006 ctrl 0x460e [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: Start (len 32767) TxSeq 7 ReqSeq 6
        0e 46 ff 7f 90 7f ff 48 7f fc 43 48 41 52 53 45  .F.....H..CHARSE
        ...
Quoted 2 lines

ACL Data RX: Handle 21 flags 0x02 dlen 552 #383 [hci0] 19.701854
ACL Data RX: Handle 21 flags 0x01 dlen 458 #384 [hci0] 19.755918

      Channel: 65 len 1006 ctrl 0xc610 [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: Continuation TxSeq 8 ReqSeq 6
        10 c6 6e 6f 73 61 69 72 65 73 64 65 73 69 67 6e  ..nosairesdesign
        ...
Quoted 2 lines

ACL Data RX: Handle 21 flags 0x02 dlen 552 #385 [hci0] 19.775016
ACL Data RX: Handle 21 flags 0x01 dlen 458 #386 [hci0] 19.775024

      Channel: 65 len 1006 ctrl 0xc612 [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: Continuation TxSeq 9 ReqSeq 6
        12 c6 69 63 6f 20 43 69 74 79 20 54 65 63 68 20  ..ico City Tech
        ...
Quoted 2 lines

ACL Data RX: Handle 21 flags 0x02 dlen 552 #387 [hci0] 19.775024
ACL Data RX: Handle 21 flags 0x01 dlen 458 #388 [hci0] 19.821542

      Channel: 65 len 1006 ctrl 0xc614 [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: Continuation TxSeq 10 ReqSeq 6
        14 c6 6c 74 69 6e 67 20 50 61 72 74 6e 65 72 0d  ..lting Partner.
        ...
Quoted 2 lines

ACL Data RX: Handle 21 flags 0x02 dlen 552 #389 [hci0] 19.821610
ACL Data RX: Handle 21 flags 0x01 dlen 458 #390 [hci0] 19.821610

      Channel: 65 len 1006 ctrl 0xc616 [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: Continuation TxSeq 11 ReqSeq 6
        16 c6 6c 74 69 6e 67 2e 63 6f 6d 0d 0a 55 49 44  ..lting.com..UID
        ...
Quoted 1 line

ACL Data RX: Handle 21 flags 0x02 dlen 11 #391 [hci0] 19.821610

      Channel: 65 len 7 ctrl 0x8618 [PSM 4101 mode Enhanced
               Retransmission (0x03)] {chan 0}
      I-frame: End TxSeq 12 ReqSeq 6
        18 86 a0 00 03 3e 5d                             .....>]

< ACL Data TX: Handle 21 [1/8] flags 0x00 dlen 12 #392 [hci0] 19.822491
L2CAP: Disconnection Request (0x06) ident 10 len 4
Destination CID: 3080
Source CID: 65

In this case the re-assembled packet should be 32767 bytes as defined in Start packet (#382), i.e. 33 segmented packets, but the End packet is sent as the 6th packet.

The l2cap_reassemble_sdu() function returns error -EINVAL if reassembled packet size != expected size, triggering the L2CAP disconnection, which disconnects the OBEX session, preventing further OBEX actions.

Log this, discard previous segmented packet data and only send data from SAR End packet to upstream.

---
 net/bluetooth/l2cap_core.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
net/bluetooth/l2cap_core.c +0 -0
index 35c57657bcf4..5fe1d058455e 100644
@@ -5703,13 +5703,20 @@ static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb,
                if (!chan->sdu)
                        break;
 

net/bluetooth/l2cap_core.c static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb, · line 5713

Quoted 10 lines
net/bluetooth/l2cap_core.c +8 -2
-               append_skb_frag(chan->sdu, skb,
-                               &chan->sdu_last_frag);
+               if (chan->sdu->len + skb->len != chan->sdu_len) {
+                       BT_DBG("Incomplete SDU, expected: %u received: %u", chan->sdu_len,
+                              chan->sdu->len + skb->len);
+                       /* Discard previous data and keep only L2CAP_SAR_END data */
+                       kfree_skb(chan->sdu);
+                       chan->sdu = skb;
+                       chan->sdu_last_frag = skb;
+                       chan->sdu_len = skb->len;

I don't find anything supporting this on the core spec, in fact I believe this would hit the following condition:

I-frame with SAR bits that do not correspond to a normal sequence of
either unsegmented or start, continuation, end for the given CID. []https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-61/out/en/host/logical-link-control-and-adaptation-protocol-specification.html#UUID-7ad8e66b-9d04-f9b8-6745-628dff5b511a

Not sure if this perhaps is handled specifically for OBEX Abort command, since that has the effect of aborting the transfer, but in L2CAP there doesn't seem to be an equivalent of that, so it would have to finish transmitting the outstanding data to complete the packet (MTU) before it can abort, so it looks like Apple got creative and invented their own method of aborting without first checking if that is legal.

Quoted 16 lines
net/bluetooth/l2cap_core.c +4 -4
+               } else {
+                       append_skb_frag(chan->sdu, skb,
+                                       &chan->sdu_last_frag);
+               }
                skb = NULL;
 
-               if (chan->sdu->len != chan->sdu_len)
-                       break;
-
                err = chan->ops->recv(chan, chan->sdu);
 
                if (!err) {
--

2.43.0

Signature · 1 line
Luiz Augusto von Dentz