From: netdev-bot+sashiko@kernel.org
To: quanyeyang@proton.me
Cc: edumazet@google.com, ncardwell@google.com, kuniyu@google.com,
davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, matttbe@kernel.org, geliang@kernel.org,
martineau@kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2] tcp: fix data-race in tcp_recv_should_stop
Date: Thu, 10 Sep 2026 02:56:22 +0000 [thread overview]
Message-ID: <178900898267.219967.2865361878538179994@kernel.org> (raw)
In-Reply-To: <20260909-mptcp-sk-err-net-v2-1-5044abecac90@proton.me>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider:
Critical: 0 · High: 1 · Medium: 0 · Low: 0
- [High] Incomplete data-race fix: the patch converts only the sk_err
load inside tcp_recv_should_stop() (include/net/tcp.h:3086) to…
--
tcp: fix data-race in tcp_recv_should_stop
This converts the sk_err load inside tcp_recv_should_stop() to READ_ONCE()
because do_recvmmsg() calls sock_error() without the socket lock and
sock_error() clears sk_err with xchg(). It carries a Fixes: tag for
eb477fdd6803 and a Closes: tag for the MPTCP syzkaller report.
Link: https://lore.kernel.org/all/14749060-d011-41e7-9a4b-754eb5bd9d5b@redhat.com/
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 436495ff2271..c61d8678eafd 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) ||
> sk->sk_state == TCP_CLOSE ||
> (sk->sk_shutdown & RCV_SHUTDOWN) ||
> signal_pending(current);
[Severity: High]
Is annotating only this read enough to close the reported race?
Every caller of tcp_recv_should_stop() keeps a plain read of the same
field in the other arm of the very same loop. In mptcp_recvmsg(), the
function named in the KCSAN splat:
net/mptcp/protocol.c:mptcp_recvmsg() {
...
if (copied) {
if (tcp_recv_should_stop(sk) ||
!timeo)
break;
} else {
if (sk->sk_err) {
copied = sock_error(sk);
break;
}
...
}
The same shape exists in tcp_recvmsg_locked():
net/ipv4/tcp.c:tcp_recvmsg_locked() {
...
if (copied) {
if (!timeo ||
tcp_recv_should_stop(sk))
break;
} else {
if (sock_flag(sk, SOCK_DONE))
break;
if (sk->sk_err) {
copied = sock_error(sk);
break;
}
...
}
and in tcp_splice_read() and mptcp_splice_read(), whose loops both end
with the now-annotated helper:
net/ipv4/tcp.c:tcp_splice_read() {
...
if (sk->sk_err) {
ret = sock_error(sk);
break;
}
...
if (tcp_recv_should_stop(sk))
break;
...
}
The writer described in the changelog, do_recvmmsg() calling
sock_error(sock->sk) with no lock_sock() and clearing the field with
xchg(&sk->sk_err, 0), races with those four plain reads exactly as it
raced with the one that was annotated, since lock_sock() in the readers
gives no exclusion against it.
Would a reproducer that lands in the blocking, copied == 0 arm still
produce the identical "data-race in do_recvmmsg / mptcp_recvmsg" report,
just attributed to mptcp_recvmsg() rather than to
tcp_recv_should_stop()? If so, should the Closes: tag be dropped, or
should the four remaining reads be converted in the same patch?
The Fixes: tag points at eb477fdd6803, but that commit only moved these
pre-existing plain reads into the new helper; the sibling reads left
behind are part of the same defect. Does the Fixes: attribution still
hold with only the helper annotated?
The added comment states "sk_err can be cleared locklessly by
sock_error()", which reads as a property of the field rather than of this
one call site. Should the write side conventions be noted too, since
the writers in these files already use WRITE_ONCE() and sock_error()
itself uses data_race() for its own read?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260909-mptcp-sk-err-net-v2-1-5044abecac90%40proton.me
prev parent reply other threads:[~2026-09-10 2:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 2:05 [PATCH net v2] tcp: fix data-race in tcp_recv_should_stop Quanye Yang via B4 Relay
2026-09-09 2:05 ` Quanye Yang
2026-09-09 2:57 ` Jiayuan Chen
2026-09-09 9:08 ` Matthieu Baerts
2026-09-10 6:00 ` quanyeyang
2026-09-10 2:56 ` netdev-bot+sashiko [this message]
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=178900898267.219967.2865361878538179994@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=geliang@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martineau@kernel.org \
--cc=matttbe@kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=quanyeyang@proton.me \
/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.