From: Pavel Begunkov <asml.silence@gmail.com>
To: Kaifeng Wang <kaifengw@google.com>, netdev@vger.kernel.org
Cc: edumazet@google.com, ncardwell@google.com, kuniyu@google.com,
davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, almasrymina@google.com, willemb@google.com,
kaiyuanz@google.com, sdf@fomichev.me,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] tcp: reject devmem tx with fastopen and repair
Date: Thu, 8 Oct 2026 13:53:51 +0100 [thread overview]
Message-ID: <7f377853-ae56-450b-889b-688ec335e81c@gmail.com> (raw)
In-Reply-To: <20261005214002.3226574-1-kaifengw@google.com>
On 10/5/26 22:40, Kaifeng Wang wrote:
> tcp_sendmsg_locked() enforces that devmem TX can only proceed if the
> zero-copy path is active and a valid dmabuf binding exists. However,
> subsequent branches in tcp_sendmsg_locked() can still intercept the
> message before it reaches the devmem zero-copy loop:
>
> 1. TCP Fast Open (MSG_FASTOPEN or DEFER_CONNECT):
> If TCP_FASTOPEN_CONNECT is set, the socket may have a valid dst with
> NETIF_F_SG (so zc == MSG_ZEROCOPY and binding is present), but
> tcp_sendmsg_fastopen() -> tcp_send_syn_data() will use
> copy_page_from_iter() to byte-copy from the iterator. Since iov_base
> represents dma-buf offsets rather than user virtual addresses, this
> misinterprets offsets as user pointers and copies arbitrary user memory
> into the SYN packet.
>
> 2. TCP repair mode:
> If tp->repair is enabled with TCP_RECV_QUEUE, tcp_send_rcvq() similarly
> calls skb_copy_datagram_from_iter(), byte-copying from the iterator.
>
> Neither path supports or makes sense for devmem transmission. Reject devmem
> sends if Fast Open or repair mode is active.
>
> This pre-existing issue was identified by Sashiko AI review on commit
> 125755776bc6 ("tcp: reject non zerocopy devmem tx") and has not been
> hit in production.
>
> Fixes: 125755776bc6 ("tcp: reject non zerocopy devmem tx")
> Fixes: bd61848900bf ("net: devmem: Implement TX path")
> Signed-off-by: Kaifeng Wang <kaifengw@google.com>
> ---
> net/ipv4/tcp.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 87ef6d5cbfeb..225e758c194a 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -1169,7 +1169,9 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
> zc = MSG_SPLICE_PAGES;
> }
>
> - if (!sockc_err && sockc.dmabuf_id && (zc != MSG_ZEROCOPY || !binding)) {
> + if (!sockc_err && sockc.dmabuf_id &&
> + (zc != MSG_ZEROCOPY || !binding || tp->repair ||
> + (flags & MSG_FASTOPEN) || inet_test_bit(DEFER_CONNECT, sk))) {
It becomes unhandy, and taking into account the issue Stan commented
about, I think it'd make sense to do the checks under the repair and
fast open "ifs".
if (((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) &&
!tcp_passive_fastopen(sk)) {
if (binding) // fail;
}
if (unlikely(tp->repair)) {
if (binding) // fail;
}
--
Pavel Begunkov
next prev parent reply other threads:[~2026-10-08 12:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 21:40 Kaifeng Wang
2026-10-06 22:16 ` Stanislav Fomichev
2026-10-08 9:40 ` netdev-bot+sashiko
2026-10-08 12:53 ` Pavel Begunkov [this message]
2026-10-08 22:04 ` Kaifeng Wang
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=7f377853-ae56-450b-889b-688ec335e81c@gmail.com \
--to=asml.silence@gmail.com \
--cc=almasrymina@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kaifengw@google.com \
--cc=kaiyuanz@google.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=willemb@google.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®