From: Nikolay Aleksandrov <razor@blackwall.org>
To: netdev-bot+sashiko@kernel.org
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
ast@kernel.org, kafai@fb.com, joe@wand.net.nz,
daniel@iogearbox.net, bpf@vger.kernel.org
Subject: Re: [PATCH net] net: keep skbs with a prefetched socket out of gro_cells gro
Date: Tue, 24 Nov 2026 10:39:47 +0200 [thread overview]
Message-ID: <38460544-04f5-41e0-b267-39c155bb08bb@blackwall.org> (raw)
In-Reply-To: <179548941922.3135.9577858774980848901@kernel.org>
On 24/11/2026 05:03, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · Medium: 0 · Low: 0
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [High] The fix is incomplete.
>
> --
>
> net: keep skbs with a prefetched socket out of gro_cells gro
>
> This patch makes gro_cells_receive() send skbs that carry a prefetched
> socket from bpf_sk_assign() to netif_rx() instead of the GRO cell. The
> goal is to stop GRO from clearing skb->sk and skb->destructor on merged
> skbs, which leaks one socket reference per merged skb.
>
>> diff --git a/net/core/gro_cells.c b/net/core/gro_cells.c
>> index 31352cac355ce..4e8b9c3cd7da0 100644
>> --- a/net/core/gro_cells.c
>> +++ b/net/core/gro_cells.c
>
> [ ... ]
>
>> @@ -26,7 +27,8 @@ int gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb)
>>
>> skb_unset_transport_header(skb);
>>
>> - if (!gcells->cells || skb_cloned(skb) || netif_elide_gro(dev)) {
>> + if (!gcells->cells || skb_cloned(skb) || netif_elide_gro(dev) ||
>> + unlikely(skb_sk_is_prefetched(skb))) {
>
> [Severity: High]
> Is matching only skb->destructor == sock_pfree enough here? An skb that
> got its socket from bpf_sk_assign() can still reach gro_cells_receive()
> with a different destructor that owns one sk_refcnt reference per skb.
>
> One path: bpf_sk_assign() at tc ingress attaches a non-refcounted socket,
> such as a TCP listener or a UDP socket. It sets sock_pfree and takes no
> reference. ip_rcv_core() keeps it. Then an NFQUEUE rule matches the outer
> ipip/gre/esp packet, and __nf_queue() converts it:
>
Oh well the bot seems right even though it's a weird case, I'd suggest to change
the check and orphan on any skb->sk set, i.e.: || unlikely(skb->sk)
instead of unlikely(skb_sk_is_prefetched(skb)), that is cache hot too as
skb->dev is read before and will catch
Also tried asking an LLM if I'm missing something and the only case it could come up
that will not be aggregated is:
"the only correct aggregation that's lost is software ESP over veth or netdevsim in tunnel mode"
IMO that is ok.
What do you think?
> net/netfilter/nf_queue.c:__nf_queue() {
> ...
> if (skb_sk_is_prefetched(skb)) {
> struct sock *sk = skb->sk;
>
> if (!sk_is_refcounted(sk)) {
> if (!refcount_inc_not_zero(&sk->sk_refcnt))
> return -ENOTCONN;
>
> /* drop refcount on skb_orphan */
> skb->destructor = sock_edemux;
> }
> }
> ...
> }
>
> After an NF_ACCEPT reinject, the packet is decapsulated. With !xnet,
> skb_scrub_packet() does not orphan it, so the skb arrives here with
> skb->sk set and destructor == sock_edemux. skb_sk_is_prefetched() now
> returns false, and the skb is queued for GRO.
>
> skb_gro_receive() then clears both fields on each merged skb without
> calling sock_edemux():
>
> net/core/gro.c:skb_gro_receive() {
> ...
> /* sk ownership - if any - completely transferred to the aggregated packet */
> skb->destructor = NULL;
> skb->sk = NULL;
> ...
> }
>
> The frag_list merge path in the same function does the same thing.
> gro_list_prepare() still allows the merge because p->sk == skb->sk.
>
> Wouldn't each merged skb then leak the reference that __nf_queue() took?
> That is the same socket and netns teardown leak described in the commit
> message.
>
> The tree already has a general rule for this in skb_prepare_for_gro():
>
> include/net/sock.h:skb_prepare_for_gro() {
> if (skb->destructor != sock_wfree) {
> skb_orphan(skb);
> return;
> }
> skb->slow_gro = 1;
> }
>
> veth_xdp_rcv_skb() calls it before napi_gro_receive(). Could
> gro_cells_receive() divert or orphan any skb that still has skb->sk set
> with a destructor other than sock_wfree, rather than checking for
> sock_pfree only? Checking skb->sk directly would be one way to do it.
>
> Separately, the "sk ownership - if any - completely transferred to the
> aggregated packet" comments in skb_gro_receive() look wrong for
> destructors that hold one reference per skb (sock_pfree on refcounted
> sockets, sock_edemux, sock_efree).
>
>> res = netif_rx(skb);
>> goto unlock;
>> }
>
next prev parent reply other threads:[~2026-11-24 8:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 16:02 [PATCH net] net: keep skbs with a prefetched socket out of gro_cells gro Nikolay Aleksandrov
2026-11-22 14:21 ` Nikolay Aleksandrov
2026-11-23 10:49 ` Eric Dumazet
2026-11-24 3:03 ` netdev-bot+sashiko
2026-11-24 8:39 ` Nikolay Aleksandrov [this message]
2026-11-26 0:36 ` willemb
2026-11-26 8:49 ` Nikolay Aleksandrov
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=38460544-04f5-41e0-b267-39c155bb08bb@blackwall.org \
--to=razor@blackwall.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=joe@wand.net.nz \
--cc=kafai@fb.com \
--cc=kuba@kernel.org \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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