From: sashiko-bot@kernel.org
To: "Jiayuan Chen" <jiayuan.chen@linux.dev>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf 09/11] bpf, sockmap: Fix apply_bytes when a redirect sends only a part
Date: Sat, 21 Nov 2026 11:15:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-226975@kernel.org> (raw)
In-Reply-To: <20261121103222.88209-10-jiayuan.chen@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf, sockmap: partial ingress redirect re-corks and drops
verdict
--
commit 0323f7103abecfb3f1dce63a498066c469f02365
Author: Jiayuan Chen <jiayuan.chen@linux.dev>
bpf, sockmap: Fix apply_bytes when a redirect sends only a part
When a redirect in tcp_bpf_send_verdict() sends fewer than tosend bytes,
this commit restores the unsent portion to psock->apply_bytes and preserves
the __SK_REDIRECT verdict and target socket on psock.
> diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
> index da9caccfede79..25f222b569ec8 100644
> --- 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);
[Severity: Medium]
Can a partial ingress redirect of a message with msg->cork_bytes set end up
re-corking the unsent remainder and dropping the preserved __SK_REDIRECT
verdict?
If an sk_msg verdict program uses both bpf_msg_cork_bytes() and
bpf_msg_apply_bytes() (or flushes an existing psock->cork), and
bpf_tcp_ingress() transfers at least one scatterlist element before running
out of receive buffer space on a later element, bpf_tcp_ingress() returns 0
with 0 < sent < tosend and msg->sg.size > 0. When msg was psock->cork, the
preceding check:
net/ipv4/tcp_bpf.c:tcp_bpf_send_verdict() {
...
if (cork && msg->sg.size && !psock->cork) {
psock->cork = msg;
cork = false;
}
...
}
puts msg back into psock->cork and clears cork, so the new block restores
psock->apply_bytes and psock->eval = __SK_REDIRECT, and execution jumps to
more_data.
At more_data, sk_psock_msg_verdict() is skipped because psock->eval is no
longer __SK_NONE, but msg->cork_bytes still holds the original cork threshold
while msg->sg.size has shrunk by sent:
net/ipv4/tcp_bpf.c:tcp_bpf_send_verdict() {
more_data:
if (psock->eval == __SK_NONE) {
...
}
if (msg->cork_bytes &&
msg->cork_bytes > msg->sg.size && !enospc) {
psock->cork_bytes = msg->cork_bytes - msg->sg.size;
...
sk_msg_reset_curr(msg);
memcpy(psock->cork, msg, sizeof(*msg));
return 0;
}
}
Because msg->cork_bytes > msg->sg.size is now true, this re-corks the unsent
tail (and calls memcpy(psock->cork, msg, sizeof(*msg)) with psock->cork == msg
when msg was already psock->cork). On the next sendmsg(), once the new
psock->cork_bytes count is satisfied, tcp_bpf_sendmsg() resets
psock->eval = __SK_NONE, losing the preserved __SK_REDIRECT verdict and
re-running the BPF program in the middle of the message.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121103222.88209-1-jiayuan.chen@linux.dev?part=9
next prev parent reply other threads:[~2026-11-21 11:15 UTC|newest]
Thread overview: 21+ 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:59 ` sashiko-bot
2026-11-21 10:30 ` [PATCH bpf 02/11] selftests/bpf: Add test for unread SK_PASS data " Jiayuan Chen
2026-11-21 10:59 ` sashiko-bot
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:04 ` sashiko-bot
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:53 ` sashiko-bot
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 10:56 ` sashiko-bot
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
2026-11-21 11:15 ` sashiko-bot [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=sashiko-outbox-226975@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=jiayuan.chen@linux.dev \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox