From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: sashiko-reviews@lists.linux.dev, bpf@vger.kernel.org
Subject: Re: [PATCH bpf v3 1/9] bpf, sockmap: Fix copied_seq updates with strparser
Date: Wed, 2 Dec 2026 23:40:14 +0800 [thread overview]
Message-ID: <a93e6c37-fa15-47fe-925e-995361884755@linux.dev> (raw)
In-Reply-To: <sashiko-outbox-246031@kernel.org>
On 12/2/26 11:00 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] bpf, sockmap: double tp->copied_seq update in
> sk_psock_strp_read() on drop
> --
>
> commit be2f7daeee373229683cdb43d95e41c6b5f12935
> Author: Jiayuan Chen <jiayuan.chen@linux.dev>
>
> bpf, sockmap: Fix copied_seq updates with strparser
>
> This commit updates tcp_bpf_recvmsg_parser() and tcp_bpf_strp_read_sock()
> to advance tp->copied_seq by per-call deltas, restricts psock->ingress_bytes
> accounting to sk_psock_skb_ingress_self(), and adjusts error and drop paths
> in skmsg so strparser skbs are not double-counted.
>
>> diff --git a/net/core/skmsg.c b/net/core/skmsg.c
>> index 4089901a95812..5c730eb56bc06 100644
>> --- a/net/core/skmsg.c
>> +++ b/net/core/skmsg.c
>
> [ ... ]
>
>> @@ -1061,8 +1074,9 @@ static int sk_psock_verdict_apply(struct sk_psock *psock, struct sk_buff *skb,
>> case __SK_DROP:
>> default:
>> out_free:
>> - skb_bpf_redirect_clear(skb);
>> + /* tcp_eat_skb() checks the strparser bit, clear it after */
>> tcp_eat_skb(psock->sk, skb);
>> + skb_bpf_redirect_clear(skb);
>> sock_drop(psock->sk, skb);
>> }
>
> [Severity: Medium]
> Can this double-count a dropped strparser skb in tp->copied_seq when
> psock->progs.stream_verdict is NULL?
>
> sk_psock_strp_read() only calls skb_bpf_set_strparser(skb) when prog is
> non-NULL:
>
> net/core/skmsg.c:sk_psock_strp_read() {
> ...
> prog = READ_ONCE(psock->progs.stream_verdict);
> if (likely(prog)) {
> skb->sk = sk;
> skb_dst_drop(skb);
> skb_bpf_redirect_clear(skb);
> ret = bpf_prog_run_pin_on_cpu(prog, skb);
> skb_bpf_set_strparser(skb);
> ret = sk_psock_map_verd(ret, skb_bpf_redirect_fetch(skb));
> skb->sk = NULL;
> }
> sk_psock_verdict_apply(psock, skb, ret);
> ...
> }
>
> If the socket is removed from a sockmap while strparser work is running,
> the two paths race because they synchronize on different locks:
>
> CPU0 CPU1
> do_strp_work()
> lock_sock(sk)
> ...
> tcp_bpf_strp_read_sock()
> tcp_read_sock_noack()
> sock_map_delete_elem()
> ...
> write_lock_bh(&sk->sk_callback_lock)
> sk_psock_stop_verdict()
> psock->progs.stream_verdict = NULL
> ...
> sk_psock_strp_read()
> prog == NULL
> sk_psock_verdict_apply(..., __SK_DROP)
> tcp_eat_skb()
> tp->copied_seq += skb->len
> tp->copied_seq += psock->copied_seq - seq <-- counted twice
>
> Because BPF_F_STRPARSER is not set on skb when prog is NULL, tcp_eat_skb()
> does not return early and adds skb->len to tp->copied_seq.
> tcp_bpf_strp_read_sock() now adds its delta to tp->copied_seq instead of
> overwriting it, advancing tp->copied_seq twice and pushing it ahead of
> queued receive data or past tp->rcv_nxt.
>
> Setting skb_bpf_set_strparser(skb) in sk_psock_strp_read() even when prog
> is NULL (or before sk_psock_verdict_apply()) would ensure tcp_eat_skb()
> skips the skb.
>
Yes, but only when the socket is deleted from the map while the
strparser work is in the middle of a read. That window is much smaller
than what this patch fixes, where copied_seq goes wrong as soon as the
parser runs twice before a read. I can fix it in a follow-up rather than
respin the series for it.
Alternatively, I'm planning retire strparser with sockmap in bpf-next.
next prev parent reply other threads:[~2026-12-02 15:40 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 14:30 [PATCH bpf v3 0/9] fix misc sockmap issues Jiayuan Chen
2026-12-02 14:30 ` [PATCH bpf v3 1/9] bpf, sockmap: Fix copied_seq updates with strparser Jiayuan Chen
2026-12-02 15:00 ` sashiko-bot
2026-12-02 15:40 ` Jiayuan Chen [this message]
2026-12-02 14:30 ` [PATCH bpf v3 2/9] selftests/bpf: Add test for unread SK_PASS data " Jiayuan Chen
2026-12-02 14:30 ` [PATCH bpf v3 3/9] bpf, sockmap: Fix empty sk_msg queued by ingress redirect Jiayuan Chen
2026-12-02 14:30 ` [PATCH bpf v3 4/9] bpf, sockmap: Fix concurrent senders on one psock Jiayuan Chen
2026-12-02 14:30 ` [PATCH bpf v3 5/9] bpf, sockmap: Fix reconnect with a psock by rejecting connect Jiayuan Chen
2026-12-02 14:30 ` [PATCH bpf v3 6/9] bpf, sockmap: Fix socket lock taken on a child before accept() Jiayuan Chen
2026-12-02 14:30 ` [PATCH bpf v3 7/9] bpf, sockmap: Fix apply_bytes when a redirect sends only a part Jiayuan Chen
2026-12-02 14:30 ` [PATCH bpf v3 8/9] selftests/bpf: Fix errno expected by the wait send mem test of test_sockmap Jiayuan Chen
2026-12-02 14:30 ` [PATCH bpf v3 9/9] 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=a93e6c37-fa15-47fe-925e-995361884755@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=bpf@vger.kernel.org \
--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.