mptcp: fixes for SIOCINQ
Subsystems (2)
Geliang Tang
reviewerv3 cover mptcp: fixes for SIOCINQ
From: Geliang Tang <[email protected]>
v3:
- patch 3: fix Sashiko AI review comment
avoid comparing ack_seq with unset rcv_data_fin_seq (0) check TCP_CLOSE/RCV_SHUTDOWN directly, only call mptcp_data_fin() when rcv_data_fin is true, exclude MP_FASTCLOSE from +1
v2:
- patch 3: drop mptcp_data_fin_seq(), reuse mptcp_data_fin()
- u64 return couldn't distinguish "no DATA_FIN" from "DATA_FIN at seq 0"
- mptcp_inq_hint() checks rcv_data_fin/TCP_CLOSE/RCV_SHUTDOWN first
The goal of this series is to make MPTCP's SIOCINQ fully consistent with TCP's: both report the number of readable data bytes, excluding the FIN byte.
Patch 1 fixes mptcp_pending_data_fin() to use >= instead of == so that DATA_FIN is processed when ack_seq advances past rcv_data_fin_seq due to OFO queue processing.
Patch 2 adds missing smp_wmb/smp_rmb barriers for rcv_data_fin_seq on weakly-ordered architectures.
Patch 3 fixes mptcp_inq_hint() INT_MAX overflow on passive TFO by using mptcp_data_avail() instead of ack_seq minus map_seq, and reuses mptcp_data_fin() to guard the FIN byte (+1).
Patch 4 adds mptcp_inq() that excludes the FIN byte, matching TCP's tcp_inq() behavior, and switches SIOCINQ to it.
Geliang Tang (4):
mptcp: handle ack_seq advancing past rcv_data_fin_seq
mptcp: add missing memory barriers for rcv_data_fin_seq
mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
mptcp: add mptcp_inq() for SIOCINQ
net/mptcp/options.c | 1 + net/mptcp/protocol.c | 63 ++++++++++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 22 deletions(-)
Signature · 1 line
2.55.0
Geliang Tang
reviewerPATCH v3 1/4 mptcp: handle ack_seq advancing past rcv_data_fin_seq
From: Geliang Tang <[email protected]>
Change mptcp_pending_data_fin() to check if ack_seq >= rcv_data_fin_seq instead of ack_seq == rcv_data_fin_seq. This handles the case where out-of-order segments in the OFO queue advance ack_seq past rcv_data_fin_seq before mptcp_pending_data_fin() runs.
With the strict equality check, if ack_seq advances past rcv_data_fin_seq due to OFO processing, the DATA_FIN would never be processed. In ESTABLISHED state, this causes read() to never return EOF since RCV_SHUTDOWN is not set. In FIN_WAIT1 or TCP_FIN_WAIT2, the connection hangs until the close timer expires.
The new check using !before64(ack_seq, rcv_data_fin_seq) ensures DATA_FIN is processed even when ack_seq has moved past it.
--- net/mptcp/protocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mptcp/protocol.c +1 -1
@@ -569,7 +569,7 @@ static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq) (TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2))) {u64 rcv_data_fin_seq =READ_ONCE (msk->rcv_data_fin_seq); -if (READ_ONCE (msk->ack_seq) == rcv_data_fin_seq) { +if (!before64 (READ_ONCE (msk->ack_seq), rcv_data_fin_seq)) {if (seq) *seq = rcv_data_fin_seq;
Signature · 1 line
2.55.0
Geliang Tang
reviewerPATCH v3 2/4 mptcp: add missing memory barriers for rcv_data_fin_seq
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
mptcp_update_rcv_data_fin() writes rcv_data_fin_seq before setting rcv_data_fin, but there is no write barrier to ensure the ordering is visible to concurrent readers.
mptcp_pending_data_fin() checks rcv_data_fin and then reads rcv_data_fin_seq, but has no read barrier. On weakly-ordered architectures, the reader could observe rcv_data_fin == 1 with a stale (or zero) rcv_data_fin_seq, causing mptcp_check_data_fin() to either process the DATA_FIN prematurely or skip it entirely.
Add smp_wmb() in mptcp_update_rcv_data_fin() between the two writes and a matching smp_rmb() in mptcp_pending_data_fin() between the two reads.
--- net/mptcp/options.c | 1 + net/mptcp/protocol.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
net/mptcp/options.c +1 -0
@@ -1192,6 +1192,7 @@ bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool usWRITE_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 );return true;
net/mptcp/protocol.c +3 -1
@@ -567,8 +567,10 @@ static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq)if (READ_ONCE (msk->rcv_data_fin) && ((1 <<inet_sk_state_load (sk)) & (TCPF_ESTABLISHED |TCPF_FIN_WAIT1 |TCPF_FIN_WAIT2 ))) { -u64 rcv_data_fin_seq =READ_ONCE (msk->rcv_data_fin_seq); +u64 rcv_data_fin_seq; +smp_rmb ();/* pair with smp_wmb in mptcp_update_rcv_data_fin */ + rcv_data_fin_seq =READ_ONCE (msk->rcv_data_fin_seq);if (!before64 (READ_ONCE (msk->ack_seq), rcv_data_fin_seq)) {if (seq) *seq = rcv_data_fin_seq;
Signature · 1 line
2.55.0
Geliang Tang
reviewerPATCH v3 3/4 mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Fix mptcp_inq_hint() to compute available bytes using mptcp_data_avail() (bytes_received - bytes_consumed) instead of ack_seq minus the head skb's map_seq.
On passive TFO connections, the TFO skb has map_seq set to -skb->len. Without the removed __mptcp_fastopen_gen_msk_ackseq() to adjust the TFO skb's map_seq, mptcp_inq_hint() computes "ack_seq - map_seq = iasn + len", almost always >= INT_MAX, causing SIOCINQ/FIONREAD and TCP_CM_INQ to report INT_MAX. This also breaks receive buffer autotuning, as mptcp_rcv_space_adjust() uses mptcp_inq_hint() to measure consumed data. The bogus hint prevents mptcp_rcvbuf_grow() from being called until the entire TFO skb has been read.
Using mptcp_data_avail() avoids this by tracking bytes directly. Introduce a mptcp_data_fin() helper to check if ack_seq has passed rcv_data_fin_seq. The FIN byte (+1) is added for TCP_CLOSE or RCV_SHUTDOWN (excluding MP_FASTCLOSE), or for DATA_FIN when rcv_data_fin is set and ack_seq has caught up. Also reset rcv_data_fin_seq to 0 in mptcp_disconnect().
--- net/mptcp/protocol.c | 48 +++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 23 deletions(-)
net/mptcp/protocol.c +25 -23
@@ -559,6 +559,21 @@ static void mptcp_check_data_fin_ack(struct sock *sk) } } +static bool mptcp_data_fin (const struct mptcp_sock *msk,u64 *seq) +{ +u64 rcv_data_fin_seq; + +smp_rmb ();/* pair with smp_wmb() in mptcp_update_rcv_data_fin() */ + rcv_data_fin_seq =READ_ONCE (msk->rcv_data_fin_seq); +if (!before64 (READ_ONCE (msk->ack_seq), rcv_data_fin_seq)) { +if (seq) + *seq = rcv_data_fin_seq; + +return true; + } +return false; +} +/* can be called with no lock acquired */ static bool mptcp_pending_data_fin (struct sock *sk,u64 *seq) {
@@ -567,16 +582,7 @@ static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq)if (READ_ONCE (msk->rcv_data_fin) && ((1 <<inet_sk_state_load (sk)) & (TCPF_ESTABLISHED |TCPF_FIN_WAIT1 |TCPF_FIN_WAIT2 ))) { -u64 rcv_data_fin_seq; - -smp_rmb ();/* pair with smp_wmb in mptcp_update_rcv_data_fin */ - rcv_data_fin_seq =READ_ONCE (msk->rcv_data_fin_seq); -if (!before64 (READ_ONCE (msk->ack_seq), rcv_data_fin_seq)) { -if (seq) - *seq = rcv_data_fin_seq; - -return true; - } +return mptcp_data_fin (msk, seq); }return false;
@@ -2407,22 +2413,17 @@ static bool mptcp_move_skbs(struct sock *sk)static unsigned int mptcp_inq_hint (const struct sock *sk) {const struct mptcp_sock *msk =mptcp_sk (sk); -const struct sk_buff *skb; +u64 hint_val =mptcp_data_avail (msk); - skb =skb_peek (&sk->sk_receive_queue); -if (skb) { -u64 hint_val =READ_ONCE (msk->ack_seq) -MPTCP_SKB_CB (skb)->map_seq; +if (hint_val >=INT_MAX ) +return INT_MAX ; -if (hint_val >=INT_MAX ) -return INT_MAX ; +if (((sk->sk_state ==TCP_CLOSE || (sk->sk_shutdown &RCV_SHUTDOWN )) && + !READ_ONCE (msk->rcv_fastclose)) || + (READ_ONCE (msk->rcv_data_fin) &&mptcp_data_fin (msk,NULL ))) + hint_val +=1 ; -return (unsigned int )hint_val; - } - -if (sk->sk_state ==TCP_CLOSE || (sk->sk_shutdown &RCV_SHUTDOWN )) -return 1 ; - -return 0 ; +return (unsigned int )hint_val; } static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
@@ -3682,6 +3683,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)WRITE_ONCE (msk->can_ack, false);WRITE_ONCE (msk->fully_established, false);WRITE_ONCE (msk->rcv_data_fin, false); +WRITE_ONCE (msk->rcv_data_fin_seq,0 );WRITE_ONCE (msk->snd_data_fin_enable, false);WRITE_ONCE (msk->rcv_fastclose, false);WRITE_ONCE (msk->use_64bit_ack, false);
Signature · 1 line
2.55.0
Geliang Tang
reviewerPATCH v3 4/4 mptcp: add mptcp_inq() for SIOCINQ
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Add mptcp_inq() to compute readable bytes at the MPTCP level using mptcp_data_avail() (bytes_received - bytes_consumed). It returns 0 during handshake (TCPF_SYN_SENT/TCPF_SYN_RECV), INT_MAX when avail >= INT_MAX, otherwise the actual byte count.
Unlike mptcp_inq_hint(), mptcp_inq() does not include the FIN byte. Switch SIOCINQ from mptcp_inq_hint() to mptcp_inq() so that FIONREAD reports N (not N+1) when N bytes are unread with DATA_FIN pending, matching TCP's tcp_ioctl() which subtracts the FIN byte.
--- net/mptcp/protocol.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +16 -1
@@ -4181,6 +4181,21 @@ static int mptcp_ioctl_outq(const struct mptcp_sock *msk, u64 v)return (int )delta; } +static int mptcp_inq (struct sock *sk) +{ +const struct mptcp_sock *msk =mptcp_sk (sk); +u64 avail; + +if ((1 << sk->sk_state) & (TCPF_SYN_SENT |TCPF_SYN_RECV )) +return 0 ; + + avail =mptcp_data_avail (msk); +if (avail >=INT_MAX ) +return INT_MAX ; + +return (unsigned int )avail; +} +static int mptcp_ioctl (struct sock *sk,int cmd,int *karg) {struct mptcp_sock *msk =mptcp_sk (sk);
@@ -4194,7 +4209,7 @@ static int mptcp_ioctl(struct sock *sk, int cmd, int *karg)lock_sock (sk);if (mptcp_move_skbs (sk))mptcp_cleanup_rbuf (msk,0 ); - *karg =mptcp_inq_hint (sk); + *karg =mptcp_inq (sk);release_sock (sk);break ;case SIOCOUTQ :
Signature · 1 line
2.55.0
Hi Geliang,
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): Unstable: 1 failed test(s): selftest_mptcp_join ⚠️
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Perf: Unstable: 2 failed test(s): regression:sched-rmem validation:sched-loss(2) ⚠️ (105 new outliers to review)
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/45096063097
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/fe4d1aa6c043
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1219076
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-normalFor 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)
[email protected]
AI reviewRe: [PATCH mptcp-net v3 1/4] mptcp: handle ack_seq advancing past rcv_data_fin_seq
In reply to Geliang TangThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 2 · Medium: 1 · 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).
- [High] After the patch, mptcp_pending_data_fin() (protocol.c:571) returns true whenever ack_seq is at or after rcv_data_fin_seq, and…
- [High] Replacing the exact match with !before64(ack_seq, rcv_data_fin_seq) in mptcp_pending_data_fin() (protocol.c:571)…
- [Medium] The commit message gives a trigger the code cannot produce.
- [Low] The commit author is Geliang Tang <[email protected]>, but the only Signed-off-by is Geliang Tang <[email protected]>.
--
mptcp: handle ack_seq advancing past rcv_data_fin_seq
This commit changes the check in mptcp_pending_data_fin() from ack_seq == rcv_data_fin_seq to !before64(ack_seq, rcv_data_fin_seq). The goal is to process a DATA_FIN even after out-of-order processing has moved ack_seq past the DATA_FIN sequence number.
Quoted 3 lines
This handles the case where
out-of-order segments in the OFO queue advanceack_seqpastrcv_data_fin_seqbeforemptcp_pending_data_fin()runs.
[Severity: Medium]
Can this happen with a compliant peer?
In get_mapping_status(), a DATA_FIN sent with a data mapping uses one byte of sequence space, and the mapped payload is shortened by one:
net/mptcp/subflow.c:get_mapping_status() {
...
data_fin_seq = mpext->data_seq + data_len - 1;
...
/* Adjust for DATA_FIN using 1 byte of sequence space */
data_len--;
...
}So the mapped payload ends exactly at the DATA_FIN DSN. A DATA_FIN with data_len == 1 maps no data at all.
ack_seq only moves to the end of mapped data. In __mptcp_move_skb():
WRITE_ONCE(msk->ack_seq, msk->ack_seq + copy_len);
and in __mptcp_ofo_queue():
WRITE_ONCE(msk->ack_seq, end_seq);
The fallback dummy DATA_FIN in subflow_sched_work_if_closed() uses map_seq + map_data_len, which is also where ack_seq stops.
With well-formed mappings, ack_seq reaches rcv_data_fin_seq and stops there, so the old == test already matched. Getting ack_seq > rcv_data_fin_seq seems to need a misbehaving peer or a forged segment. That means either data mapped at or past its own DATA_FIN DSN, or a DATA_FIN DSN that is already behind ack_seq.
Could the commit message describe the real trigger, ideally with a reproducer or trace? As written, the Fixes: tag suggests a hang that ordinary connections can hit.
Quoted 1 line
Signed-off-by Geliang Tang <[email protected]>
[Severity: Low]
This isn't a bug, but the Author address ([email protected]) and the Signed-off-by address ([email protected]) differ, so checkpatch.pl will warn with FROM_SIGN_OFF_MISMATCH. .mailmap maps both addresses to the same person, so there is no DCO problem.
Could the sign-off use the author address, or could an in-body From: be added?
net/mptcp/protocol.c static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq) · line 571
Quoted 10 lines
net/mptcp/protocol.c +1
-1@@ -568,7 +568,7 @@ static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq) (TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2))) {u64 rcv_data_fin_seq =READ_ONCE (msk->rcv_data_fin_seq); -if (READ_ONCE (msk->ack_seq) == rcv_data_fin_seq) { +if (!before64 (READ_ONCE (msk->ack_seq), rcv_data_fin_seq)) {
[Severity: High]
Does the caller still assume ack_seq == rcv_data_fin_seq here?
mptcp_check_data_fin() ignores the rcv_data_fin_seq returned through *seq and increments the current ack_seq instead:
net/mptcp/protocol.c:mptcp_check_data_fin() {
...
* If we are caught up to the sequence number of the incoming
* DATA_FIN, send the DATA_ACK now and do state transition. If
...
if (mptcp_pending_data_fin(sk, &rcv_data_fin_seq)) {
WRITE_ONCE(msk->ack_seq, msk->ack_seq + 1);
WRITE_ONCE(msk->rcv_data_fin, 0);
...
}This patch only changes behaviour when ack_seq > rcv_data_fin_seq. In that case the DATA_FIN is counted at ack_seq + 1 instead of rcv_data_fin_seq + 1, and mptcp_send_ack() then sends that value to the peer.
On a Linux peer, ack_update_msk() ignores a DATA_ACK beyond snd_nxt:
if (unlikely(before64(snd_nxt, old_snd_una) || after64(new_snd_una, snd_nxt))) new_snd_una = old_snd_una;
So the peer's DATA_FIN can stay unacknowledged after the local side has moved to CLOSE_WAIT, CLOSING or CLOSE. The peer then waits for its own timeout.
If the peer does have data in flight past ack_seq, a DATA_ACK of ack_seq + 1 acknowledges a byte that was never received. When the real segment at the old ack_seq arrives, could mptcp_subflow_discard_data() or the partial-packet path in __mptcp_move_skb() drop its first byte?
Any data at or past the DATA_FIN DSN also stays in the receive queue and is counted in ack_seq and bytes_received, even though RCV_SHUTDOWN is set.
Would it be better to keep the exact-match check and validate the DSN when it is recorded? Another option is to decide explicitly how data past the DATA_FIN should be handled.
[Severity: High]
Does this change remove the only check on the DATA_FIN DSN sent by the peer?
That value is stored without validation. For a zero-length segment that carries a DSS DATA_FIN, mptcp_incoming_options() does:
if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
if (mp_opt.data_fin && mp_opt.data_len == 1 &&
mptcp_update_rcv_data_fin(msk, mp_opt.data_seq, mp_opt.dsn64))
mptcp_schedule_work((struct sock *)msk);This path has no DSS checksum and no window check. mptcp_update_rcv_data_fin() only refuses if rcv_data_fin is already set, and otherwise stores the value as is:
WRITE_ONCE(msk->rcv_data_fin_seq, mptcp_expand_seq(READ_ONCE(msk->ack_seq), data_fin_seq, use_64bit));
Before this patch, the DATA_FIN only took effect when its DSN was exactly ack_seq. After it, any DSN at or behind ack_seq takes effect right away (for example data_seq = 0 with dsn64):
mptcp_worker()
mptcp_check_data_fin()
mptcp_pending_data_fin() <- now true for any past DSN
sets RCV_SHUTDOWN, moves to CLOSE_WAIT/CLOSING/CLOSE
A DSN ahead of ack_seq also takes effect once a single skb move jumps past it.
Can one in-window segment on any single subflow now force what looks like a clean EOF on the whole MPTCP connection? The application would get a truncated stream that it cannot tell apart from a normal close.
mptcp_check_data_fin() then writes ack_seq + 1, so the DATA_ACK also acknowledges a byte that was never received. The peer's real segment starting at the old ack_seq would then lose its first byte.
A legitimate peer never sends a DATA_FIN DSN behind ack_seq, so the newly accepted inputs seem to come only from misbehaving peers or injected segments. An attacker still needs a segment the subflow will accept. However, instead of guessing the exact DSN, roughly half the sequence space now works.
Quoted 3 lines
net/mptcp/protocol.c +0
-0if (seq) *seq = rcv_data_fin_seq;
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795396910.git.tanggeliang%40kylinos.cn
[email protected]
AI reviewRe: [PATCH mptcp-net v3 2/4] mptcp: add missing memory barriers for rcv_data_fin_seq
In reply to Geliang TangThank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The From: and Signed-off-by: addresses do not match.
- [Low] The commit message says a stale rcv_data_fin_seq can make mptcp_check_data_fin() 'skip [the DATA_FIN] entirely'.
--
mptcp: add missing memory barriers for rcv_data_fin_seq
This patch adds an smp_wmb() in mptcp_update_rcv_data_fin() between the writes to rcv_data_fin_seq and rcv_data_fin. It also adds a matching smp_rmb() in mptcp_pending_data_fin() between the two reads. The goal is to stop a reader on a weakly-ordered architecture from seeing rcv_data_fin == 1 together with a stale rcv_data_fin_seq.
Quoted 5 lines
mptcp_pending_data_fin()checksrcv_data_finand then readsrcv_data_fin_seq, but has no read barrier. On weakly-ordered architectures, the reader could observercv_data_fin== 1 with a stale (or zero)rcv_data_fin_seq, causingmptcp_check_data_fin()to either process theDATA_FINprematurely or skip it entirely.
[Severity: Low]
Is "skip it entirely" accurate here?
Suppose the stale rcv_data_fin_seq makes the !before64() check fail. mptcp_pending_data_fin() then returns false and msk->rcv_data_fin stays set. The flag is only cleared in the success branch of mptcp_check_data_fin():
net/mptcp/protocol.c:mptcp_check_data_fin() {
...
if (mptcp_pending_data_fin(sk, &rcv_data_fin_seq)) {
WRITE_ONCE(msk->ack_seq, msk->ack_seq + 1);
WRITE_ONCE(msk->rcv_data_fin, 0);
...
}Each writer path also triggers a later re-check after rcv_data_fin is set. For example, get_mapping_status() does this:
if (updated) mptcp_schedule_work((struct sock *)msk);
The pure DATA_FIN path in options.c and the fallback path in subflow.c also call mptcp_schedule_work() after a successful mptcp_update_rcv_data_fin(). A DATA_FIN carried inside a data mapping is re-checked by move_skbs_to_msk() through mptcp_pending_data_fin(sk, NULL).
So the failing case only seems to delay the DATA_FIN. The harmful case is the premature one: a stale seq that passes !before64() bumps ack_seq and sets RCV_SHUTDOWN while data is still pending.
Could the commit message describe the impact that way, so backporters can judge the severity correctly?
Quoted 2 lines
Fixes 3721b9b64676 ("mptcp: Track received DATA_FIN sequence number and add related helpers")Signed-off-by Geliang Tang <[email protected]>
[Severity: Low]
This isn't a bug, but the author address ([email protected]) does not match the only Signed-off-by address ([email protected]). checkpatch.pl will report FROM_SIGN_OFF_MISMATCH for this.
The other patches in the series have the same mismatch:
mptcp: handle ack_seq advancing past rcv_data_fin_seq
mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
mptcp: add mptcp_inq() for SIOCINQ
Could the author address be changed, or a Signed-off-by from [email protected] be added?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795396910.git.tanggeliang%40kylinos.cn
[email protected]
AI reviewRe: [PATCH mptcp-net v3 3/4] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
In reply to Geliang TangThank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] mptcp_inq_hint() (net/mptcp/protocol.c:2384-2398) now adds a phantom FIN byte when no FIN or DATA_FIN was ever received.
--
mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
This patch changes mptcp_inq_hint() to compute the available bytes as bytes_received - bytes_consumed instead of ack_seq minus the head skb's map_seq. That avoids a bogus INT_MAX hint on passive TFO connections. It also adds a mptcp_data_fin() helper, adds a FIN byte under certain conditions, and resets rcv_data_fin_seq in mptcp_disconnect().
Quoted 4 lines
net/mptcp/protocol.c +0
-0
[ ... ]
Quoted 9 lines
net/mptcp/protocol.c +1
-3@@ -2378,22 +2384,17 @@ static bool mptcp_move_skbs(struct sock *sk)static unsigned int mptcp_inq_hint (const struct sock *sk) {const struct mptcp_sock *msk =mptcp_sk (sk); -const struct sk_buff *skb; +u64 hint_val =mptcp_data_avail (msk); - skb =skb_peek (&sk->sk_receive_queue); -if (skb) {
net/mptcp/protocol.c static bool mptcp_move_skbs(struct sock *sk) · line 2395
Quoted 10 lines
net/mptcp/protocol.c +6
-3-u64 hint_val =READ_ONCE (msk->ack_seq) -MPTCP_SKB_CB (skb)->map_seq; +if (hint_val >=INT_MAX ) +return INT_MAX ; -if (hint_val >=INT_MAX ) -return INT_MAX ; +if (((sk->sk_state ==TCP_CLOSE || (sk->sk_shutdown &RCV_SHUTDOWN )) && + !READ_ONCE (msk->rcv_fastclose)) || + (READ_ONCE (msk->rcv_data_fin) &&mptcp_data_fin (msk,NULL ))) + hint_val +=1 ;
[Severity: Low]
Can this add a FIN byte when no FIN or DATA_FIN was ever received?
The first half of the condition looks only at local socket state. It now adds 1 on top of unread data, where the old code only returned 1 when the queue was empty.
One way to hit this is a local shutdown(fd, SHUT_RD) with data still queued. inet_shutdown() sets RCV_SHUTDOWN:
net/ipv4/af_inet.c:inet_shutdown() {
...
WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | how);
...
}and mptcp_shutdown() only handles SEND_SHUTDOWN:
static void mptcp_shutdown(struct sock *sk, int how)
{
...
if ((how & SEND_SHUTDOWN) && mptcp_close_state(sk))
__mptcp_wr_shutdown(sk);
}bytes_received, bytes_consumed and ack_seq are left as they were, so with D unread bytes the hint becomes D + 1.
Another way is a TCP RST on a fallen-back msk. In that case __mptcp_subflow_error_report() moves the msk to TCP_CLOSE without setting rcv_fastclose or purging the receive queue:
if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD)) mptcp_set_state(sk, ssk_state); WRITE_ONCE(sk->sk_err, -err);
Before this patch, a non-empty queue gave ack_seq - map_seq. ack_seq only includes the FIN byte after mptcp_check_data_fin() advances it for a real DATA_FIN, so neither case above reported the extra byte.
For comparison, tcp_inq_hint() only forces the extra byte when the queue is empty and a FIN was actually received:
if (inq == 0 && sock_flag(sk, SOCK_DONE)) inq = 1;
A fallen-back MPTCP socket would therefore report a different TCP_CM_INQ value than plain TCP in the same situation.
The later commit "mptcp: add mptcp_inq() for SIOCINQ" moves SIOCINQ/FIONREAD to a new mptcp_inq() that leaves out the FIN byte, so the SIOCINQ side goes away there. The TCP_CM_INQ cmsg in mptcp_recvmsg() still calls mptcp_inq_hint(), and so does the autotuning measurement in mptcp_rcv_space_adjust():
copied -= mptcp_inq_hint(sk);
Both would still see the extra byte.
The changelog describes the +1 rule, but it doesn't say that the rule now applies with data queued and no FIN received. Should the TCP_CLOSE/RCV_SHUTDOWN branch only apply when mptcp_data_avail() is zero, to match the old behaviour and tcp_inq_hint()?
Quoted 10 lines
net/mptcp/protocol.c +1
-7-return (unsigned int )hint_val; - } - -if (sk->sk_state ==TCP_CLOSE || (sk->sk_shutdown &RCV_SHUTDOWN )) -return 1 ; - -return 0 ; +return (unsigned int )hint_val; }
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795396910.git.tanggeliang%40kylinos.cn
[email protected]
AI reviewRe: [PATCH mptcp-net v3 4/4] mptcp: add mptcp_inq() for SIOCINQ
In reply to Geliang TangThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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).
- [Medium] The commit message describes one user-visible change to SIOCINQ/FIONREAD: N is reported instead of N+1 when N bytes are unread…
--
mptcp: add mptcp_inq() for SIOCINQ
This adds mptcp_inq(), which computes the readable bytes at the MPTCP level using mptcp_data_avail(). SIOCINQ switches from mptcp_inq_hint() to mptcp_inq(), so FIONREAD no longer includes the FIN byte.
Quoted 4 lines
Unlike
mptcp_inq_hint(),mptcp_inq()does not include the FIN byte. Switch SIOCINQ frommptcp_inq_hint()tomptcp_inq()so that FIONREAD reports N (not N+1) when N bytes are unread withDATA_FINpending, matching TCP'stcp_ioctl()which subtracts the FIN byte.
[Severity: Medium]
Is this description complete? Switching mptcp_ioctl(SIOCINQ) to mptcp_inq() in net/mptcp/protocol.c changes FIONREAD in more cases than the pending DATA_FIN case described here.
Before this series, an empty receive queue in TCP_CLOSE or with RCV_SHUTDOWN set hit this exit in mptcp_inq_hint():
if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN)) return 1;
So FIONREAD returned 1, and mptcp_inq() now returns 0. The cases affected are:
- EOF after a processed DATA_FIN (mptcp_check_data_fin() sets RCV_SHUTDOWN)
- a never connected socket (mptcp_ioctl() only rejects TCP_LISTEN)
- a socket that moved to TCP_CLOSE after a reset
- a local shutdown(SHUT_RD)
After the previous patch in this series ("mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint"), mptcp_inq_hint() adds the extra byte based on socket state, whether or not a FIN was received:
if (((sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN)) && !READ_ONCE(msk->rcv_fastclose)) || (READ_ONCE(msk->rcv_data_fin) && mptcp_data_fin(msk, NULL))) hint_val += 1;
With N bytes queued after a local shutdown(SHUT_RD), or in a TCP_CLOSE state that is not a fastclose with no FIN received, SIOCINQ reported N+1 after that patch. This patch brings it back to N. TCP_CM_INQ still uses mptcp_inq_hint() and keeps the +1.
Since that +1 is not limited to a received DATA_FIN, is "mptcp_inq_hint() ... include the FIN byte" accurate?
The new values match what tcp_inq() returns, so the code change itself looks fine. This patch carries a Fixes: tag, so it is likely to be backported to stable. Could the commit message say that FIONREAD now returns 0 instead of 1 at EOF and on unconnected sockets? Could it also say that this patch needs to go with its parent to undo the N+1 that the parent introduced for SIOCINQ?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795396910.git.tanggeliang%40kylinos.cn