From: sashiko-bot@kernel.org
To: "Jiayuan Chen" <jiayuan.chen@linux.dev>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf 01/11] bpf, sockmap: Fix copied_seq updates with strparser
Date: Sat, 21 Nov 2026 10:59:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-226963@kernel.org> (raw)
In-Reply-To: <20261121103222.88209-2-jiayuan.chen@linux.dev>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] bpf, sockmap: missing skb_orphan() on error in
sk_psock_skb_ingress()
- [High] bpf, sockmap: multi-segment strparser message rewinds
tp->copied_seq
--
commit 4f9dfdace1214b93f005e54687ec6d1b8e1449f2
Author: Jiayuan Chen <jiayuan.chen@linux.dev>
bpf, sockmap: Fix copied_seq updates with strparser
This commit updates tcp->copied_seq incrementally in
tcp_bpf_strp_read_sock() and tcp_bpf_recvmsg_parser(), moves
psock->ingress_bytes accounting to sk_psock_skb_ingress_self(), and
orphans strparser skbs when sk_psock_skb_ingress_enqueue() fails.
> diff --git a/net/core/skmsg.c b/net/core/skmsg.c
> index 8a3b8536c0c21..16f84dcb5acd9 100644
> --- a/net/core/skmsg.c
> +++ b/net/core/skmsg.c
> @@ -574,9 +574,6 @@ static int sk_psock_skb_ingress_enqueue(struct sk_buff *skb,
> return num_sge;
> }
>
> -#if IS_ENABLED(CONFIG_BPF_STREAM_PARSER)
> - psock->ingress_bytes += len;
> -#endif
> copied = len;
> msg->sg.start = 0;
> msg->sg.size = copied;
> @@ -642,8 +639,21 @@ static int sk_psock_skb_ingress_self(struct sk_psock *psock, struct sk_buff *skb
> */
> msg->sk = sk;
> err = sk_psock_skb_ingress_enqueue(skb, off, len, psock, sk, msg, take_ref);
> - if (err < 0)
> + if (err < 0) {
> kfree(msg);
> + /*
> + * A strparser skb comes in without an owner and read_sock counts
> + * it as consumed once it is left to the backlog. Drop the owner
> + * again, or sk_psock_skb_ingress() takes the skb->sk == sk path
> + * and recvmsg() counts it a second time.
> + */
> + if (skb_bpf_strparser(skb))
> + skb_orphan(skb);
> + }
> +#if IS_ENABLED(CONFIG_BPF_STREAM_PARSER)
> + else
> + psock->ingress_bytes += len;
> +#endif
> return err;
> }
[Severity: High]
Does sk_psock_skb_ingress() also need to orphan the skb when
sk_psock_skb_ingress_enqueue() fails?
net/core/skmsg.c:sk_psock_skb_ingress() {
if (unlikely(skb->sk == sk))
return sk_psock_skb_ingress_self(psock, skb, off, len, true);
msg = sk_psock_create_ingress_msg(sk, skb);
if (!msg)
return -EAGAIN;
skb_set_owner_r(skb, sk);
err = sk_psock_skb_ingress_enqueue(skb, off, len, psock, sk, msg, true);
if (err < 0)
kfree(msg);
return err;
}
When sk_psock_backlog() processes a strparser skb (or an skb redirected to
ingress from another socket), skb->sk != sk, so sk_psock_skb_ingress()
calls skb_set_owner_r(skb, sk) and then sk_psock_skb_ingress_enqueue(). If
sk_psock_skb_ingress_enqueue() fails with -EAGAIN (for instance, when an
skb with more than MAX_MSG_FRAGS fragments fails skb_linearize() under
memory pressure), the skb stays on psock->ingress_skb with skb->sk == sk
while sk_psock_backlog() has already stripped BPF_F_STRPARSER via
skb_bpf_redirect_clear().
On the next backlog run, sk_psock_skb_ingress() sees skb->sk == sk and
takes the sk_psock_skb_ingress_self() branch without holding the socket
lock. That modifies psock->ingress_bytes concurrently with
tcp_bpf_strp_read_sock() and sets msg->sk = sk, so
tcp_bpf_recvmsg_parser() adds the bytes to tcp->copied_seq a second time
(or counts foreign redirected bytes against this socket's
tcp->copied_seq), pushing tcp->copied_seq past rcv_nxt and stalling the
socket.
> diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
> index 788ce08eef4d7..e59103e77aa5f 100644
> --- a/net/ipv4/tcp_bpf.c
> +++ b/net/ipv4/tcp_bpf.c
[ ... ]
> @@ -756,6 +753,7 @@ int tcp_bpf_strp_read_sock(struct strparser *strp, read_descriptor_t *desc,
> struct sk_psock *psock;
> struct tcp_sock *tp;
> int copied = 0;
> + u32 seq;
>
> tp = tcp_sk(sk);
> rcu_read_lock();
> @@ -765,6 +763,7 @@ int tcp_bpf_strp_read_sock(struct strparser *strp, read_descriptor_t *desc,
> goto out;
> }
>
> + seq = psock->copied_seq;
> psock->ingress_bytes = 0;
> copied = tcp_read_sock_noack(sk, desc, recv_actor, true,
> &psock->copied_seq);
> @@ -775,7 +774,8 @@ int tcp_bpf_strp_read_sock(struct strparser *strp, read_descriptor_t *desc,
> * For SK_REDIRECT, we need to ack the frame immediately but for
> * SK_PASS, we want to delay the ack until tcp_bpf_recvmsg_parser().
> */
> - tp->copied_seq = psock->copied_seq - psock->ingress_bytes;
> + WRITE_ONCE(tp->copied_seq, tp->copied_seq + psock->copied_seq - seq -
> + psock->ingress_bytes);
> tcp_rcv_space_adjust(sk);
> __tcp_cleanup_rbuf(sk, copied - psock->ingress_bytes);
> out:
[Severity: High]
What happens here when a strparser message spans multiple TCP segments
across separate tcp_bpf_strp_read_sock() calls?
When the first segment of length L1 arrives and is buffered in
strp->skb_head awaiting the rest of the message, strp->cb.rcv_msg does not
run yet, so psock->copied_seq - seq is L1 and psock->ingress_bytes is 0.
tcp_bpf_strp_read_sock() advances tp->copied_seq by L1 and calls
__tcp_cleanup_rbuf(sk, L1) before any verdict runs (and if the partial
message later times out or hits a parser error, tp->copied_seq remains
permanently over-advanced by L1).
When the second segment of length L2 arrives and completes the message
with SK_PASS, sk_psock_verdict_apply() passes stm->full_len (L1 + L2) to
sk_psock_skb_ingress_self(), setting psock->ingress_bytes to L1 + L2 while
psock->copied_seq - seq is only L2. Subtracting psock->ingress_bytes then
adds L2 - (L1 + L2) = -L1, rewinding tp->copied_seq backwards, and makes
copied - psock->ingress_bytes negative, which suppresses immediate ACKs in
__tcp_cleanup_rbuf() for any SK_REDIRECT frame processed in the same call.
Holding back tp->copied_seq for unread SK_PASS messages in ingress_msg
also inflates strp_peek_len() (which queries tcp_inq(), i.e. tp->rcv_nxt -
tp->copied_seq), so strp_recv() can see stm->strp.full_len -
stm->accum_len <= strp_peek_len(strp) on an intermediate segment and skip
updating strp->need_bytes, causing strp_data_ready() not to wake the
parser once the earlier message is read.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121103222.88209-1-jiayuan.chen@linux.dev?part=1
next prev parent reply other threads:[~2026-11-21 10:59 UTC|newest]
Thread overview: 17+ 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 [this message]
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 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 10:30 ` [PATCH bpf 09/11] bpf, sockmap: Fix apply_bytes when a redirect sends only a part Jiayuan Chen
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-226963@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 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.