From: bot+bpf-ci@kernel.org
To: jiayuan.chen@linux.dev,bpf@vger.kernel.org,ast@kernel.org
Cc: jiayuan.chen@linux.dev,john.fastabend@gmail.com,jakub@cloudflare.com,davem@davemloft.net,edumazet@kernel.org,kuba@kernel.org,pabeni@redhat.com,horms@kernel.org,kuniyu@google.com,willemb@google.com,ncardwell@google.com,andrii@kernel.org,eddyz87@gmail.com,ihor.solodrai@linux.dev,daniel@iogearbox.net,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,shuah@kernel.org,rhkrqnwk98@gmail.com,mattia.meleleo@coralogix.com,mhal@rbox.co,linux-kernel@vger.kernel.org,netdev@vger.kernel.org,linux-kselftest@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf 09/11] bpf, sockmap: Fix apply_bytes when a redirect sends only a part
Date: Sat, 21 Nov 2026 11:11:11 +0000 (UTC) [thread overview]
Message-ID: <10c5af49a70a8f40bbcf3afaddefa15089060a8d1d1aac01d5810c5b088adc47@mail.kernel.org> (raw)
In-Reply-To: <20261121103222.88209-10-jiayuan.chen@linux.dev>
[-- Attachment #1: Type: text/plain, Size: 3716 bytes --]
> bpf, sockmap: Fix apply_bytes when a redirect sends only a part
TL;DR: The apply_bytes give-back in tcp_bpf_send_verdict() may leave a source
socket permanently failing sendmsg() with -EPIPE after its redirect target
closes, since the restored redirect verdict is never cleared.
> diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
> --- a/net/ipv4/tcp_bpf.c
> +++ b/net/ipv4/tcp_bpf.c
[ ... ]
> @@ -566,6 +563,21 @@ static int tcp_bpf_send_verdict(struct sock *sk, struct sk_psock *psock,
> msg = NULL;
> ret = 0;
> }
> + /*
> + * Bytes that were not sent and come back, in msg or in the
> + * next sendmsg(), are still covered by the verdict.
> + */
> + if (apply && sent < tosend && !cork) {
> + psock->apply_bytes += tosend - sent;
> + if (eval == __SK_REDIRECT) {
> + psock->eval = eval;
> + psock->sk_redir = sk_redir;
> + eval = __SK_NONE;
> + }
> + }
> + if (eval == __SK_REDIRECT)
> + sock_put(sk_redir);
> + sock_put(sk_redir);
> break;
Can this give-back leave the source socket unable to send after the redirect
target goes away?
The give-back runs for every short redirect, whatever the error. Some
errors from tcp_bpf_sendmsg_redir() are permanent and send nothing
(sent == 0):
if (!READ_ONCE(sk->sk_socket))
return sock_flag(sk, SOCK_DEAD) ? -EPIPE : -EINVAL;
psock = sk_psock_get(sk);
if (unlikely(!psock))
return -EPIPE;
They happen when the target was closed (__tcp_close() -> sock_orphan()) or
removed from the sockmap. The same goes for an egress target whose
connection was reset, where tcp_sendmsg_locked() returns -EPIPE.
In those cases sk_msg_apply_bytes(psock, tosend) takes off tosend bytes and
the new code adds tosend - 0 back, so psock->apply_bytes ends up at its old
value. When apply_bytes had reached 0, the code also puts back
psock->eval = __SK_REDIRECT and psock->sk_redir = <dead target>.
Nothing else clears that state. The only writers of psock->eval,
apply_bytes and sk_redir are this function, sk_psock_msg_verdict() (which
runs only when psock->eval == __SK_NONE), the cork_bytes reset in
tcp_bpf_sendmsg(), and sk_psock_destroy(). So every later sendmsg() on the
source socket follows the same path:
tcp_bpf_sendmsg() -> tcp_bpf_send_verdict()
psock->eval == __SK_REDIRECT, prog not run
tcp_bpf_sendmsg_redir(dead target) -> -EPIPE, sent = 0
apply_bytes restored, verdict restored
-> sk_stream_error() -> -EPIPE (plus SIGPIPE unless MSG_NOSIGNAL)
The source socket's own connection is healthy, but it can no longer send
while it is in the sockmap. The sk_msg program never runs again, so it
cannot pick a new target or drop. The dead target's struct sock also stays
pinned by psock->sk_redir until the psock is destroyed.
Before this patch the verdict always used up tosend bytes, even on failure.
A redirect to a dead target failed at most about apply_bytes / tosend times.
Then psock->eval went back to __SK_NONE, the prog ran again, and with the
closed target gone from the map the lookup failed and the prog returned
SK_DROP (or chose another target).
The give-back is right for short sends the user is expected to retry
(-EAGAIN, -ENOMEM from bpf_tcp_ingress(), a partial ret == 0). Should it be
skipped, or should the verdict be cleared, when the target cannot take data
any more (for example -EPIPE)?
No later commit in the series changes net/ipv4/tcp_bpf.c; the rest of the
series only adds selftests.
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44896626218
next prev parent reply other threads:[~2026-11-21 11:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 10:30 [PATCH bpf 00/11] fix misc sockmap issues Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 01/11] bpf, sockmap: Fix copied_seq updates with strparser Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 02/11] selftests/bpf: Add test for unread SK_PASS data " Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 03/11] bpf, sockmap: Fix strparser reinit after the parser link is removed Jiayuan Chen
2026-11-21 11:26 ` bot+bpf-ci
2026-11-21 10:30 ` [PATCH bpf 04/11] bpf, sockmap: Fix empty sk_msg queued by ingress redirect Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 05/11] bpf, sockmap: Fix concurrent senders on one psock Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 06/11] bpf, sockmap: Fix reconnect with a psock by rejecting disconnect Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 07/11] bpf, sockmap: Fix psock refcnt taken in sk_psock_backlog() Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 08/11] bpf, sockmap: Fix socket lock taken on a child before accept() Jiayuan Chen
2026-11-21 11:26 ` bot+bpf-ci
2026-11-21 10:30 ` [PATCH bpf 09/11] bpf, sockmap: Fix apply_bytes when a redirect sends only a part Jiayuan Chen
2026-11-21 11:11 ` bot+bpf-ci [this message]
2026-11-21 10:30 ` [PATCH bpf 10/11] selftests/bpf: Fix errno expected by the wait send mem test of test_sockmap Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 11/11] selftests/bpf: Add test for apply_bytes when a redirect sends a part Jiayuan Chen
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=10c5af49a70a8f40bbcf3afaddefa15089060a8d1d1aac01d5810c5b088adc47@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=jakub@cloudflare.com \
--cc=jiayuan.chen@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--cc=mattia.meleleo@coralogix.com \
--cc=memxor@gmail.com \
--cc=mhal@rbox.co \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rhkrqnwk98@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=willemb@google.com \
--cc=yonghong.song@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 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®