Skip to contentSkip to conversation

mptcp: push queued data on passive TFO subflows becoming established

PATCH Superseded T S Rameshkumar 5 participants 6 messages Oct 8 – Oct 13 1 message not in the archive

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

PATCH v4 1/1 mptcp: push queued data on passive TFO subflows becoming established

With TCP Fast Open on an MPTCP listener, if the server application writes data while the passive subflow is still in SYN_RECV (after consuming the client's SYN data but before the MP_CAPABLE third ACK arrives), __mptcp_subflow_active() refuses transmission and the data is queued into the msk write queue.

When the MPC third ACK arrives, the subflow transitions to TCP_ESTABLISHED and is marked fully established in check_fully_established(), but because the third ACK carries no DSS data, the queued bytes remain stranded until the peer sends more data.

Fix this in check_fully_established() by checking if the subflow was doing passive TFO (subflow->is_mptfo). Under mptcp_data_lock(), flush queued bytes via __mptcp_check_push() and clear is_mptfo.

Fixes fb7084501a61 ("mptcp: add support for TCP_FASTOPEN sockopt")
Assisted-by Gemini 3.7
---
 net/mptcp/options.c | 9 +++++++++
 1 file changed, 9 insertions(+)
net/mptcp/options.c +9 -0
index ce0de02f5..b865ee6af 100644
@@ -1042,6 +1042,15 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
 
 	mptcp_data_lock((struct sock *)msk);
 	__mptcp_subflow_fully_established(msk, subflow, mp_opt);
+	/* Passive TFO: the application may have written data while the
+	 * subflow was still in SYN_RECV; __mptcp_subflow_active() refused
+	 * it then and nothing else spools the msk write queue when the
+	 * MPC third ack (no DSS) arrives. Push it now.
+	 */
+	if (subflow->is_mptfo) {
+		subflow->is_mptfo = 0;
+		__mptcp_check_push((struct sock *)msk, ssk);
+	}
 	mptcp_data_unlock((struct sock *)msk);
 
 check_notify:
Signature · 1 line
2.34.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] net/mptcp: data race in subflow bitfields causes list corruption --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net/mptcp: data race in subflow bitfields causes list corruption --

commit 91c44c97db7bbddaa206314ca428111bec1fb73f
Author: T S Rameshkumar <[email protected]>

mptcp: push queued data on passive TFO subflows becoming established

With TCP Fast Open on an MPTCP listener, passive subflows that receive data during SYN_RECV queue it into the msk write queue. This patch flushes the queued bytes when the MPC third ACK arrives by checking if the subflow was doing passive TFO.

net/mptcp/options.c static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk, · line 1051

Quoted 13 lines
net/mptcp/options.c +7 -0
@@ -1042,6 +1042,15 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
 
 	mptcp_data_lock((struct sock *)msk);
 	__mptcp_subflow_fully_established(msk, subflow, mp_opt);
+	/* Passive TFO: the application may have written data while the
+	 * subflow was still in SYN_RECV; __mptcp_subflow_active() refused
+	 * it then and nothing else spools the msk write queue when the
+	 * MPC third ack (no DSS) arrives. Push it now.
+	 */
+	if (subflow->is_mptfo) {
+		subflow->is_mptfo = 0;

[Severity: High]
Could this bitfield modification race with mptcp_close_ssk() and corrupt the conn_list linked list?

In check_fully_established(), the new modification to subflow->is_mptfo is protected by mptcp_data_lock(msk) and lock_sock(ssk).

However, there are asynchronous paths (like mptcp_pm_nl_rm_subflow_received() or mptcp_worker()) that call mptcp_close_ssk(). That function modifies the subflow->close_event_done bitfield while holding only lock_sock(msk).

In struct mptcp_subflow_context, these two bitfields share the same memory word:

        valid_csum_seen : 1,        /* at least one csum validated */
        is_mptfo : 1,               /* subflow is doing TFO */
        close_event_done : 1,       /* has done the post-closed part */
        mpc_drop : 1,               /* the MPC option has been dropped */

Since the lock_sock(msk) mutex does not overlap with the locks held in this code block, concurrent execution could result in a read-modify-write data race.

If the close_event_done = true update is overwritten by is_mptfo = 0, mptcp_close_ssk() could be re-executed on the same subflow later. This would result in a double list_del(&subflow->node) inside __mptcp_close_ssk(), corrupting the conn_list.

Is there a safe way to update is_mptfo without introducing a read-modify-write race on the shared bitfield word?

Quoted 5 lines
net/mptcp/options.c +2 -0
+		__mptcp_check_push((struct sock *)msk, ssk);
+	}
 	mptcp_data_unlock((struct sock *)msk);
 
 check_notify:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to T S Rameshkumar

Hi T,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Perf: Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/37777427552

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/e76f38387d94
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1181596

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

A message that is not in the archive (sent off-list or not yet received): CADRhS2uk-P8TSmyiM=X5JQXHtzdm68vg6+vyBDr-UCf0EAu0HA@mail.gmail.com

maintainer
#4 lore raw

Hi T S,

+cc Petar.

Quoted 4 lines · T S RAMESHKUMAR

Hi Matt, Petar,

Thank you both!

Quoted 9 lines

I have prepared [PATCH mptcp-net v2] based on the export branch. In v2:
- Reverted bitfield modifications: check_fully_established() is only called once upon receiving the MPC 3rd-ACK, so is_mptfo is read-only at that stage and safe from concurrency races.
- Added "Suggested-by: Petar Sakic <[email protected]>" and "Reported-by: Petar Sakic <[email protected]>".
- Kept the Fixes tag pointing to fb7084501a61 ("mptcp: add support for TCP_FASTOPEN sockopt") to ensure backports cover 6.8 and all stable trees.

Thank you. I will try to review this after the automated tests.

Quoted 11 lines

Regarding Packetdrill:
I have prepared the packetdrill test case (server-TCP_FASTOPEN-early- write.pkt) which simulates the server writing data in SYN_RECV before the 3rd ACK arrives and verifies that the 100 bytes are pushed immediately with DSS mapping once the 3rd ACK is received. All 51 fastopen tests pass.

I can submit the packetdrill test via a PR on https://github.com/
multipath-tcp/packetdrill <https://github.com/multipath-tcp/
packetdrill>, or send it directly to the list if preferred. Here is the test script for reference:

Please open a new PR.

Quoted 25 lines

--- server-TCP_FASTOPEN-early-write.pkt ---
// SPDX-License-Identifier: GPL-2.0
// Test MPTCP passive Fast Open early write before 3rd ACK arrives --tolerance_usecs=100000
../common/defaults.sh

 0.0    socket(..., SOCK_STREAM, IPPROTO_MPTCP) = 3 +0.0    setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 +0.0    setsockopt(3, SOL_TCP, TCP_FASTOPEN, [2], 4) = 0

+0.0    bind(3, ..., ...) = 0
+0.0    listen(3, 1) = 0

// Client connects with TFO Cookie and 500 bytes of SYN data +0.1      <  S   0:500(500)                win 65535  <mss 1460, sackOK, TS val 100 ecr 0,   nop, wscale 8, FO TFO_COOKIE, nop, nop, mpcapable v1 flags[flag_h] nokey>
+0.0      >  S.  0:0(0)          ack 501              <mss 1460, sackOK, TS val 100 ecr 100, nop, wscale 8,                          mpcapable v1 flags[flag_h] key[skey]>

// Server accepts while still in SYN_RECV and reads the SYN data +0.0    accept(3, ..., ...) = 4
+0.0    read(4, ..., 500) = 500

Quoted 7 lines

// Server writes early reply data before receiving client's 3rd ACK +0.0    write(4, ..., 100) = 100

// Client's 3rd ACK arrives with no data, establishing the MPTCP connection +0.2      <   .  501:501(0)      ack 1     win 450    < mpcapable v1 flags[flag_h] key[ckey, skey]>

Here, you are dropping TCP Timestamps (TS) negotiated before. Probably better to keep it (or you don't inject it in he first SYN, clearer).

Quoted 3 lines

// Server must immediately push the queued 100 bytes with DSS mapping +0.0      >  P.  1:101(100)      ack 501              <nop, nop, TS val 100 ecr 100, dss dack8=0 dsn8=1 ssn=1 dll=100 nocs>

"dack8=0"? That's strange...

Also, TCP options are not padded correctly to ensure TCP header is a multiple of 4 bytes: 2 excess bytes → you are missing two "nop" at the end.

How did you test it?

 $ cd <Packetdrill DIR>/gtests/net
 $ run_all.py -lv mptcp/fastopen/server-TCP_FASTOPEN-early-write.pkt

Don't forget to add the "Assisted-by: LLM" tag if used, and mention what you did, how you tested things. You can use this docker image to ease the testing part:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
Tested-by
#5 lore raw

Hi Matthieu and T S

I hope replying here is OK.

Tested v2 on top of 6.12.111 (applies with a 15-line offset, no other change).

Setup: two netns over a veth pair, netem 50 ms each way (100 ms RTT). MPTCP listener with TCP_FASTOPEN=16; the server replies as soon as accept() returns, while the TFO child is still SYN_RECV (checked via TCP_INFO). Client: first connection fetches the cookie, the next ones use TCP_FASTOPEN_CONNECT so the request rides the SYN. Checked per run: TCPFastOpenActive/Passive, MPCapableSYNTX/ACKRX, MPCapableFallbackACK = 0.

- 6.12.111 unpatched: reply stranded on every TFO connection (3/3).
- 6.12.111 + v2: reply delivered on every TFO connection (3/3), ~2 RTT. Plain TCP control unchanged.

One case v2 does not cover, same setup: a cookie-bearing SYN with no data (sendmsg MSG_FASTOPEN, zero bytes), server speaking first. tcp_fastopen_create_child() still creates the child (TCPFastOpenPassive increments, accept() returns in SYN_RECV), but mptcp_fastopen_subflow_synack_set_params() returns before setting subflow->is_mptfo because the receive queue is empty, so the new check never fires and the reply is stranded again (2/2, with and without v2). Plain TCP handles it. Moving the assignment above the early return makes both cases pass here (3/3 and 2/2), no splats:

net/mptcp/fastopen.c +2 -2
@@ -25,13 +25,13 @@
        tp = tcp_sk(ssk);
 
+       subflow->is_mptfo = 1;
+
        /* A valid TFO cookie does not guarantee SYN data. */
        skb = skb_peek(&ssk->sk_receive_queue);
        if (!skb)
                return;
 
-       subflow->is_mptfo = 1;
-
        /* dequeue the skb from sk receive queue */
 

Up to you whether that belongs in this patch or a follow-up.

Cheers,
- Petar

Quoted 97 lines · Matthieu Baerts

Hi T S,

+cc Petar.

Quoted 4 lines · T S RAMESHKUMAR

Hi Matt, Petar,

Thank you both!

Quoted 9 lines

I have prepared [PATCH mptcp-net v2] based on the export branch. In v2:
- Reverted bitfield modifications: check_fully_established() is only called once upon receiving the MPC 3rd-ACK, so is_mptfo is read-only at that stage and safe from concurrency races.
- Added "Suggested-by: Petar Sakic <[email protected]>" and "Reported-by: Petar Sakic <[email protected]>".
- Kept the Fixes tag pointing to fb7084501a61 ("mptcp: add support for TCP_FASTOPEN sockopt") to ensure backports cover 6.8 and all stable trees.

Thank you. I will try to review this after the automated tests.

Quoted 11 lines

Regarding Packetdrill:
I have prepared the packetdrill test case (server-TCP_FASTOPEN-early- write.pkt) which simulates the server writing data in SYN_RECV before the 3rd ACK arrives and verifies that the 100 bytes are pushed immediately with DSS mapping once the 3rd ACK is received. All 51 fastopen tests pass.

I can submit the packetdrill test via a PR on https://github.com/
multipath-tcp/packetdrill <https://github.com/multipath-tcp/
packetdrill>, or send it directly to the list if preferred. Here is the test script for reference:

Please open a new PR.

Quoted 25 lines

--- server-TCP_FASTOPEN-early-write.pkt ---
// SPDX-License-Identifier: GPL-2.0
// Test MPTCP passive Fast Open early write before 3rd ACK arrives --tolerance_usecs=100000
../common/defaults.sh

 0.0    socket(..., SOCK_STREAM, IPPROTO_MPTCP) = 3
+0.0    setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+0.0    setsockopt(3, SOL_TCP, TCP_FASTOPEN, [2], 4) = 0

+0.0 bind(3, ..., ...) = 0
+0.0 listen(3, 1) = 0

// Client connects with TFO Cookie and 500 bytes of SYN data
+0.1 < S 0:500(500) win 65535 <mss 1460, sackOK,
TS val 100 ecr 0, nop, wscale 8, FO TFO_COOKIE, nop, nop, mpcapable v1
flags[flag_h] nokey>
+0.0 > S. 0:0(0) ack 501 <mss 1460, sackOK,
TS val 100 ecr 100, nop, wscale 8, mpcapable v1
flags[flag_h] key[skey]>

// Server accepts while still in SYN_RECV and reads the SYN data
+0.0 accept(3, ..., ...) = 4
+0.0 read(4, ..., 500) = 500

Quoted 7 lines

// Server writes early reply data before receiving client's 3rd ACK
+0.0 write(4, ..., 100) = 100

// Client's 3rd ACK arrives with no data, establishing the MPTCP connection
+0.2 < . 501:501(0) ack 1 win 450 <
mpcapable
v1 flags[flag_h] key[ckey, skey]>

Here, you are dropping TCP Timestamps (TS) negotiated before. Probably better to keep it (or you don't inject it in he first SYN, clearer).

Quoted 3 lines

// Server must immediately push the queued 100 bytes with DSS mapping
+0.0 > P. 1:101(100) ack 501 <nop, nop, TS val
100 ecr 100, dss dack8=0 dsn8=1 ssn=1 dll=100 nocs>

"dack8=0"? That's strange...

Also, TCP options are not padded correctly to ensure TCP header is a multiple of 4 bytes: 2 excess bytes → you are missing two "nop" at the end.

How did you test it?

 $ cd <Packetdrill DIR>/gtests/net
 $ run_all.py -lv mptcp/fastopen/server-TCP_FASTOPEN-early-write.pkt

Don't forget to add the "Assisted-by: LLM" tag if used, and mention what you did, how you tested things. You can use this docker image to ease the testing part:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Cheers,
Matt
--
Sponsored by the NGI0 Core fund.

maintainer
#6 lore raw
Quoted 13 lines · Petar Sakic

Hi Matthieu and T S

I hope replying here is OK.

Tested v2 on top of 6.12.111 (applies with a 15-line offset, no other change).

Setup: two netns over a veth pair, netem 50 ms each way (100 ms RTT). MPTCP listener with TCP_FASTOPEN=16; the server replies as soon as accept() returns, while the TFO child is still SYN_RECV (checked via TCP_INFO). Client: first connection fetches the cookie, the next ones use TCP_FASTOPEN_CONNECT so the request rides the SYN. Checked per run: TCPFastOpenActive/Passive, MPCapableSYNTX/ACKRX, MPCapableFallbackACK = 0.

Quoted 5 lines

- 6.12.111 unpatched: reply stranded on every TFO connection (3/3).
- 6.12.111 + v2: reply delivered on every TFO connection (3/3), ~2 RTT. Plain TCP control unchanged.

Thank you for having tested that.

Quoted 26 lines

One case v2 does not cover, same setup: a cookie-bearing SYN with no data (sendmsg MSG_FASTOPEN, zero bytes), server speaking first. tcp_fastopen_create_child() still creates the child (TCPFastOpenPassive increments, accept() returns in SYN_RECV), but mptcp_fastopen_subflow_synack_set_params() returns before setting subflow->is_mptfo because the receive queue is empty, so the new check never fires and the reply is stranded again (2/2, with and without v2). Plain TCP handles it. Moving the assignment above the early return makes both cases pass here (3/3 and 2/2), no splats:

net/mptcp/fastopen.c +2 -2
@@ -25,13 +25,13 @@
        tp = tcp_sk(ssk);
 
+       subflow->is_mptfo = 1;
+
        /* A valid TFO cookie does not guarantee SYN data. */
        skb = skb_peek(&ssk->sk_receive_queue);
        if (!skb)
                return;
 
-       subflow->is_mptfo = 1;
-
        /* dequeue the skb from sk receive queue */
 
Quoted 1 line

Up to you whether that belongs in this patch or a follow-up.

Probably better in a follow-up in this form, but not with this patch:
here, you are reverting this:

https://git.kernel.org/torvalds/c/e00b63056fb4

What about calling __mptcp_check_push() if (subflow->mp_capable) instead?

@T S: please wait for the discussions to settle before sending new versions.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.