From: netdev-bot+sashiko@kernel.org
To: geliang@kernel.org
Cc: mptcp@lists.linux.dev, kuba@kernel.org
Subject: Re: [PATCH mptcp-next v28 09/11] mptcp: drop data after DATA_FIN before skb init
Date: Tue, 17 Nov 2026 22:41:13 +0000 [thread overview]
Message-ID: <179495527373.3133.7304844081942280548@kernel.org> (raw)
In-Reply-To: <0b6321dafceaf638b198d43b6918ed87a58cf5f1.1794810809.git.tanggeliang@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 7 potential
issue(s) to consider.
Critical: 1 · High: 2 · Medium: 3 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Critical] In __mptcp_move_skbs_from_subflow() (net/mptcp/protocol.c),
the else branch now also runs when len > 0 && data_fin.
- [High] mptcp_seq_after_data_fin() goes into its fin_seq comparison
whenever `sk->sk_shutdown & RCV_SHUTDOWN` is set.
- [High] The fix does not close the bug class its commit message claims
to close: data at or after DATA_FIN still reaching the msk receive…
- [Medium] Bisectability / series ordering.
- [Medium] mptcp_seq_after_data_fin() returns true when the DSN range
[seq, seq+len) only straddles fin_seq (`!before64(seq + len, fin_seq +…
- [Medium] The explicit `if (offset < skb->len)` guard was replaced by
`len = skb->len - offset; ... if (len > 0 && !data_fin)` in…
- [Low] The patch adds smp_wmb() in mptcp_update_rcv_data_fin()
(options.c:1180), and the commit message says the barriers order…
--
mptcp: drop data after DATA_FIN before skb init
This commit adds mptcp_seq_after_data_fin() and calls it from
__mptcp_move_skbs_from_subflow(). Subflow skbs whose DSN range overlaps or
follows the recorded DATA_FIN are now freed before mptcp_init_skb(). It also
adds an smp_wmb()/smp_rmb() pair around rcv_data_fin_seq and rcv_data_fin,
and limits the DSS corruption warning in the drop branch to len == 0.
> After the previous commit, data arriving at or after DATA_FIN must be
> explicitly dropped to prevent state corruption. Without this check, such
> data could cause offset wraparound in __mptcp_recvmsg_mskq(), leading to
> bytes_consumed exceeding bytes_received, mptcp_data_avail() wrapping to
> U64_MAX, SIOCINQ reporting unread data after EOF, and improper connection
> closure.
[Severity: Medium]
Doesn't this leave the previous commit ("mptcp: remove CB offset field")
in a state that breaks bisection?
In that commit, once DATA_FIN has been processed, msk->ack_seq is F + 1
while msk->copied_seq stays at F. __mptcp_move_skb() accepts an skb with
map_seq F + 1 as in sequence. Then __mptcp_recvmsg_mskq() does:
net/mptcp/protocol.c:__mptcp_recvmsg_mskq() {
...
u64 offset = *seq - MPTCP_SKB_CB(skb)->map_seq;
...
if (offset >= skb->len) {
if (!(flags & MSG_PEEK))
mptcp_eat_recv_skb(sk, skb);
...
}
The offset wraps, and the skb is eaten without bytes_consumed being
updated. A bisect or backport that lands only on the previous commit would
get the peer-triggerable accounting corruption described above.
Could this fix be folded into, or ordered before, the commit that
introduces the problem? Also, this commit does not seem to close the
problem completely; see the comments below about the race and the OFO
queue.
> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
> index 71579238a951c..425a7fe94e0c4 100644
> --- a/net/mptcp/options.c
> +++ b/net/mptcp/options.c
> @@ -1177,6 +1177,7 @@ bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool us
>
> WRITE_ONCE(msk->rcv_data_fin_seq,
> mptcp_expand_seq(READ_ONCE(msk->ack_seq), data_fin_seq, use_64bit));
> + smp_wmb(); /* ensure rcv_data_fin_seq is visible before rcv_data_fin */
> WRITE_ONCE(msk->rcv_data_fin, 1);
[Severity: Low]
This barrier pairs with the new smp_rmb() in mptcp_seq_after_data_fin().
However, mptcp_pending_data_fin() is documented as "can be called with no
lock acquired", and it reads the same pair without a read barrier:
net/mptcp/protocol.c:mptcp_pending_data_fin() {
...
if (READ_ONCE(msk->rcv_data_fin) &&
...
u64 rcv_data_fin_seq = READ_ONCE(msk->rcv_data_fin_seq);
...
}
Should it get a matching smp_rmb() as well?
In mptcp_seq_after_data_fin(), the condition can be true only because of
RCV_SHUTDOWN. In that case the smp_rmb() follows a plain read of
sk->sk_shutdown, and no writer issues a write barrier before setting
RCV_SHUTDOWN. The smp_mb__before_atomic() in mptcp_check_data_fin() comes
after the store. So the "ensure we see the updated rcv_data_fin_seq"
comment doesn't hold on that path.
KCSAN would also report the plain sk->sk_shutdown read, since the writers
use WRITE_ONCE().
>
> return true;
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index ddc98497f0eb0..78ca580c6d9c5 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -811,6 +811,25 @@ static void __mptcp_add_backlog(struct sock *sk,
> msk->backlog_unaccounted += delta;
> }
>
> +static bool mptcp_seq_after_data_fin(struct mptcp_sock *msk,
> + struct sock *ssk, u32 len)
> +{
> + struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
> + struct sock *sk = (struct sock *)msk;
> +
> + if (READ_ONCE(msk->rcv_data_fin) || (sk->sk_shutdown & RCV_SHUTDOWN)) {
[Severity: High]
What value does rcv_data_fin_seq have when only RCV_SHUTDOWN is set?
Its only writer is mptcp_update_rcv_data_fin(), which runs only when a
DATA_FIN is received. On a fresh socket it is 0. mptcp_disconnect() clears
rcv_data_fin but leaves rcv_data_fin_seq stale.
RCV_SHUTDOWN can be set without any DATA_FIN:
- a local shutdown(fd, SHUT_RD) through inet_shutdown(), since
mptcp_shutdown() ignores RCV_SHUTDOWN
- mptcp_do_fastclose() and __mptcp_close(), which set SHUTDOWN_MASK
With fin_seq == 0, !before64(seq, 0) is true for every DSN with bit 63
clear. That means on roughly half of all connections, every incoming skb
would be dropped after SHUT_RD.
msk->ack_seq then stops advancing, so the peer gets no DATA_ACK and keeps
retransmitting. Each drop also hits the copied_seq problem described
further below. Before this patch, data received after SHUT_RD was still
queued, as with TCP.
Is the RCV_SHUTDOWN arm intended here? The commit message doesn't mention
it.
[Severity: High]
Does this check fully stop data at or after DATA_FIN from reaching the msk
receive queue, as the commit message describes?
There seem to be two ways around it.
First, mptcp_check_data_fin() runs in process context with the msk owned,
but without the msk data lock:
net/mptcp/protocol.c:mptcp_check_data_fin() {
...
WRITE_ONCE(msk->ack_seq, msk->ack_seq + 1);
WRITE_ONCE(msk->rcv_data_fin, 0);
WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN);
...
}
At the same time, mptcp_data_ready() for another subflow can run in BH,
see that the socket is owned by the user, and call
__mptcp_move_skbs_from_subflow(msk, ssk, false).
Suppose that reader sees rcv_data_fin already cleared but RCV_SHUTDOWN not
yet set. Both checks are false, so an skb at fin_seq + 1 goes to
msk->backlog_list. __mptcp_move_skb() later accepts it as in sequence,
since dsn == ack_seq.
Second, an skb at DSN F + 1 that arrives before the DATA_FIN goes into the
msk OFO queue without this check. After mptcp_check_data_fin() sets
ack_seq = F + 1, the next __mptcp_ofo_queue() call (move_skbs_to_msk()
calls it unconditionally) does:
net/mptcp/protocol.c:__mptcp_ofo_queue() {
...
if (after64(mptcp_dsn(skb), msk->ack_seq))
break;
...
__skb_queue_tail(&sk->sk_receive_queue, skb);
...
}
This moves the F + 1 skb into sk_receive_queue. __mptcp_recvmsg_mskq() then
computes offset = *seq - map_seq as a wrapped u64 and eats the skb without
updating bytes_consumed.
Could a peer still trigger the bytes_received/bytes_consumed corruption
this way, by sending data beyond its DATA_FIN out of order and then one
more segment?
> + u64 seq = mptcp_subflow_get_mapped_dsn(subflow);
> + u64 fin_seq;
> +
> + smp_rmb(); /* ensure we see the updated rcv_data_fin_seq */
> + fin_seq = READ_ONCE(msk->rcv_data_fin_seq);
> + if (!before64(seq, fin_seq) ||
> + !before64(seq + len, fin_seq + 1))
> + return true;
[Severity: Medium]
If [seq, seq + len) only straddles fin_seq, this returns true and
__mptcp_move_skbs_from_subflow() frees the whole skb. That includes the
valid bytes in [seq, fin_seq). Should the skb be trimmed at fin_seq
instead?
Within a single DATA_FIN mapping this can't happen, because
get_mapping_status() sets the fin seq to data_seq + data_len - 1.
It can happen when the DATA_FIN comes from a separate data-less DSS, or
from another subflow, and falls inside an existing mapping.
Unless the peer resends those bytes under a different mapping, msk->ack_seq
stays below rcv_data_fin_seq. This check in mptcp_pending_data_fin() then
never matches:
if (READ_ONCE(msk->ack_seq) == rcv_data_fin_seq) {
so the receive side stalls instead of closing.
The drop also goes through sk_eat_skb() with no drop reason and no MPTCP
MIB counter, unlike other MPTCP receive drops such as MPTCP_MIB_DUPDATA.
> + }
> + return false;
> +}
> +
> static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
> struct sock *ssk, bool own_msk)
> {
> @@ -826,7 +845,8 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
> u32 map_remaining, offset;
> u32 seq = tp->copied_seq;
> struct sk_buff *skb;
> - bool fin;
> + bool fin, data_fin;
> + size_t len;
>
> /* try to move as much data as available */
> map_remaining = subflow->map_data_len -
> @@ -850,9 +870,9 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
> if (fin)
> seq++;
>
> - if (offset < skb->len) {
> - size_t len = skb->len - offset;
> -
> + len = skb->len - offset;
> + data_fin = mptcp_seq_after_data_fin(msk, ssk, len);
> + if (len > 0 && !data_fin) {
> mptcp_init_skb(ssk, skb, offset, len);
[Severity: Medium]
Is this equivalent to the removed offset < skb->len check?
skb->len and offset are both u32. When offset > skb->len, the subtraction
wraps to a large value and len > 0 is true.
That wrapped value then goes to mptcp_init_skb(), whose offset and
copy_len parameters are int. The result is a negative copy_len and an skb
with end_seq below map_seq, which is then handed to __mptcp_move_skb() or
the backlog.
mptcp_subflow_discard_data() still guards the same computation with
WARN_ON_ONCE(offset > skb->len). The copied_seq issue below produces
exactly offset > skb->len for later skbs.
If mptcp_seq_after_data_fin() returns false in that state, for example in
the rcv_data_fin/RCV_SHUTDOWN window, can these values reach
mptcp_init_skb()?
The else branch now only reports DSS corruption for len == 0, so this case
would no longer trigger fallback or reset either.
[ ... ]
> @@ -870,7 +890,7 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
> } else {
> sk_eat_skb(ssk, skb);
>
> - if (unlikely(!fin)) {
> + if (len == 0 && unlikely(!fin)) {
> DEBUG_NET_WARN_ON_ONCE(1);
> mptcp_dss_corruption(msk, ssk);
> }
[Severity: Critical]
When data_fin is true and len > 0, this else branch now frees an skb that
still holds len unread bytes. seq += len only happens in the accept
branch, so the write-back after the if/else:
WRITE_ONCE(tp->copied_seq, seq);
stores the old copied_seq, or old + 1 if the skb carries a TCP FIN. Doesn't
that leave tp->copied_seq behind TCP_SKB_CB(skb)->seq for every later skb
on this subflow?
mptcp_subflow_discard_data() handles the same situation by advancing
copied_seq by the discarded amount, plus the FIN byte, before calling
sk_eat_skb().
With copied_seq stuck, mptcp_subflow_get_map_offset() stops moving, and
copied_seq - skb->seq wraps for later skbs. One remote sequence that gets
there, with checksums off and two subflows:
1. the peer sends a data-less DATA_FIN at F on subflow B, which
mptcp_update_rcv_data_fin() records
2. the peer sends seg1 of a mapping [S, S+100) with S < F < S+50 on
subflow A; mptcp_seq_after_data_fin() returns true, seg1 is eaten,
and copied_seq stays at seg1's seq
3. the peer sends [S, F) on subflow B; ack_seq reaches F and
mptcp_check_data_fin() sets ack_seq = F + 1
4. the peer sends seg2 of the same mapping on subflow A
In step 4, subflow_check_data_avail() sees an identical mapping. The
mapped DSN S is below old_ack, so it calls mptcp_subflow_discard_data():
net/mptcp/subflow.c:mptcp_subflow_discard_data() {
...
offset = tp->copied_seq - TCP_SKB_CB(skb)->seq;
if (WARN_ON_ONCE(offset > skb->len))
goto out;
...
out:
if (!before(tcp_sk(ssk)->copied_seq, TCP_SKB_CB(skb)->end_seq))
sk_eat_skb(ssk, skb);
if (mptcp_subflow_get_map_offset(subflow) >= subflow->map_data_len)
subflow->map_valid = 0;
}
Here the offset wraps, nothing is eaten, copied_seq does not move, and
map_valid stays set. subflow_check_data_avail() then continues its for (;;)
loop.
Can that loop spin forever in softirq with the ssk lock held?
The same desync has other effects:
- a new mapping can see a wrapped skb_consumed in skb_is_fully_mapped()
and get MAPPING_INVALID, which leads to fallback or a subflow reset
- tcp_prune_queue()->tcp_collapse() is called with tp->copied_seq as
start, which could reach BUG_ON(offset < 0) in tcp_collapse()
- rcv_nxt - copied_seq stays non-zero for good
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794810809.git.tanggeliang%40kylinos.cn
next prev parent reply other threads:[~2026-11-17 22:41 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 6:38 [PATCH mptcp-next v28 00/11] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
2026-11-16 6:38 ` [PATCH mptcp-net v28 01/11] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Geliang Tang
2026-11-17 22:41 ` netdev-bot+sashiko
2026-11-16 6:38 ` [PATCH mptcp-next v28 02/11] selftests: mptcp: connect: check TFO SIOCINQ overflow Geliang Tang
2026-11-16 6:57 ` sashiko-bot
2026-11-17 22:41 ` netdev-bot+sashiko
2026-11-16 6:38 ` [PATCH mptcp-net v28 03/11] mptcp: fix fallback dummy mapping anchor Geliang Tang
2026-11-16 6:38 ` [PATCH mptcp-next v28 04/11] mptcp: drop the mptcp_ooo_try_coalesce() helper Geliang Tang
2026-11-16 6:38 ` [PATCH mptcp-next v28 05/11] mptcp: drop the cant_coalesce CB field Geliang Tang
2026-11-16 6:38 ` [PATCH mptcp-next v28 06/11] mptcp: add flags field to mptcp_skb_cb Geliang Tang
2026-11-17 22:41 ` netdev-bot+sashiko
2026-11-16 6:39 ` [PATCH mptcp-next v28 07/11] mptcp: encapsulate CB DSN field access with helpers Geliang Tang
2026-11-17 22:41 ` netdev-bot+sashiko
2026-11-16 6:39 ` [PATCH mptcp-next v28 08/11] mptcp: remove CB offset field Geliang Tang
2026-11-17 22:41 ` netdev-bot+sashiko
2026-11-16 6:39 ` [PATCH mptcp-next v28 09/11] mptcp: drop data after DATA_FIN before skb init Geliang Tang
2026-11-16 7:37 ` sashiko-bot
2026-11-17 22:41 ` netdev-bot+sashiko [this message]
2026-11-16 6:39 ` [PATCH mptcp-next v28 10/11] mptcp: sync mptcp skb cb layout with tcp one Geliang Tang
2026-11-16 8:10 ` sashiko-bot
2026-11-17 22:41 ` netdev-bot+sashiko
2026-11-16 6:39 ` [PATCH mptcp-next v28 11/11] mptcp: defer read_sock cleanup to mptcp_worker Geliang Tang
2026-11-17 22:41 ` netdev-bot+sashiko
2026-11-16 8:33 ` [PATCH mptcp-next v28 00/11] Reduce the differences between TCP and MPTCP for TLS usage MPTCP CI
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179495527373.3133.7304844081942280548@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=geliang@kernel.org \
--cc=kuba@kernel.org \
--cc=mptcp@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.