From: sashiko-bot@kernel.org
To: "Quanye Yang" <quanyeyang@proton.me>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-net v3 3/3] tcp: fix data-race in do_recvmmsg / mptcp_recvmsg
Date: Mon, 07 Sep 2026 10:24:46 +0000 [thread overview]
Message-ID: <20260907102447.4C55E1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260907-mptcp-snd-una-race-v3-3-65ba0d5f0221@proton.me>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Incomplete fix for `sk->sk_err` data race leading to false EOFs. The patch fixes a lockless data race in `tcp_recv_should_stop()` by adding `READ_ONCE()`, but overlooks identical plain reads followed by `sock_error()` in `tcp_recvmsg_locked()`, `tcp_splice_read()`, `mptcp_recvmsg()`, and `tcp_bpf_sendmsg()`. If `sk->sk_err` is checked and evaluates to true, but is concurrently cleared to 0 by another thread calling `sock_error()` (e.g. via `do_recvmmsg` or `getsockopt(SO_ERROR)`), the subsequent assignment `copied = sock_error(sk)` will evaluate to 0. For receive and splice functions, this results in returning 0, which falsely signals a graceful connection closure (EOF) to the application rather than an error.
--
commit 0f561938f67b19245ef8889cb9ecc077fb82d7d0
Author: Quanye Yang <quanyeyang@proton.me>
tcp: fix data-race in do_recvmmsg / mptcp_recvmsg
This commit fixes a lockless data race in tcp_recv_should_stop() by using
READ_ONCE() for reading sk->sk_err. This prevents issues when sock_error()
atomically clears the error using xchg() without holding the socket lock.
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 436495ff2271d..c61d8678eafd3 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -3082,7 +3082,8 @@ enum skb_drop_reason tcp_inbound_hash(struct sock *sk,
>
> static inline int tcp_recv_should_stop(struct sock *sk)
> {
> - return sk->sk_err ||
> + /* sk_err can be cleared locklessly by sock_error(). */
> + return READ_ONCE(sk->sk_err) ||
[Severity: High]
This is a pre-existing issue, but does this fix also need to be applied to
other locations that read sk->sk_err locklessly?
If sk->sk_err is evaluated as non-zero, but the error is concurrently cleared
by another thread calling sock_error() (for example, via concurrent recvmmsg
or getsockopt calls), a subsequent call to sock_error(sk) will return 0. This
masks the socket error and falsely signals a graceful connection closure (EOF)
or 0 bytes sent.
This pattern appears to be present in several other functions:
net/ipv4/tcp.c:tcp_recvmsg_locked() {
...
if (sk->sk_err) {
copied = sock_error(sk);
break;
}
...
}
net/ipv4/tcp.c:tcp_splice_read() {
...
if (sk->sk_err) {
ret = sock_error(sk);
break;
}
...
}
net/mptcp/protocol.c:mptcp_recvmsg() {
...
if (sk->sk_err) {
copied = sock_error(sk);
break;
}
...
}
net/ipv4/tcp_bpf.c:tcp_bpf_sendmsg() {
...
if (sk->sk_err) {
err = -sk->sk_err;
goto out_err;
}
...
}
Would it be appropriate to update these instances as well to prevent
Time-Of-Check to Time-Of-Use races?
> sk->sk_state == TCP_CLOSE ||
> (sk->sk_shutdown & RCV_SHUTDOWN) ||
> signal_pending(current);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260907-mptcp-snd-una-race-v3-0-65ba0d5f0221@proton.me?part=3
next prev parent reply other threads:[~2026-09-07 10:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 10:15 [PATCH mptcp-net v3 0/3] mptcp: fix reported data-races quanyeyang
2026-09-07 10:15 ` [PATCH mptcp-net v3 1/3] mptcp: fix data-race in __mptcp_retrans / mptcp_incoming_options quanyeyang
2026-09-07 13:38 ` Paolo Abeni
2026-09-07 13:55 ` Matthieu Baerts
2026-09-07 10:15 ` [PATCH mptcp-net v3 2/3] mptcp: fix data-race in mptcp_subflow_get_send / tcp_ack Quanye Yang via B4 Relay
2026-09-07 10:15 ` Quanye Yang
2026-09-07 10:15 ` [PATCH mptcp-net v3 3/3] tcp: fix data-race in do_recvmmsg / mptcp_recvmsg Quanye Yang via B4 Relay
2026-09-07 10:15 ` Quanye Yang
2026-09-07 10:24 ` sashiko-bot [this message]
2026-09-07 13:23 ` quanyeyang
2026-09-07 13:46 ` Paolo Abeni
2026-09-07 14:38 ` quanyeyang
2026-09-07 11:28 ` [PATCH mptcp-net v3 0/3] mptcp: fix reported data-races 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=20260907102447.4C55E1F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=quanyeyang@proton.me \
--cc=sashiko-reviews@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.