Netdev List
 help / color / mirror / Atom feed
From: Nikolay Aleksandrov <razor@blackwall.org>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Joe Stringer <joe@wand.net.nz>,
	Daniel Borkmann <daniel@iogearbox.net>,
	bpf@vger.kernel.org
Subject: Re: [PATCH net] net: keep skbs with a prefetched socket out of gro_cells gro
Date: Sun, 22 Nov 2026 16:21:45 +0200	[thread overview]
Message-ID: <c953972c-dc7e-4b97-b271-5137f0cb2cbc@blackwall.org> (raw)
In-Reply-To: <20261121160204.4024204-1-razor@blackwall.org>

On 21/11/2026 18:02, Nikolay Aleksandrov wrote:
> bpf_sk_assign at tc ingress holds a reference on a socket that is not
> rcu freed, such as an established tcp socket, until the receive path
> steals it. ip_rcv_core keeps a prefetched socket so when the assigned
> packet is an ipip, gre or esp packet the socket stays attached after
> decap and their rx paths pass the skb to gro_cells_receive. GRO merges
> skbs with the same skb->sk into one flow and clears skb->sk and
> skb->destructor of each merged skb without calling the destructor so
> every merged skb leaks a socket ref.
> 
> Send skbs with a prefetched socket to netif_rx instead as
> gro_cells_receive already does for cloned skbs, where each skb is
> consumed on its own and no reference is lost.
> 
> skb_sk_is_prefetched tests skb->destructor which shares a cache line
> with skb->cloned that is read just before so the common case adds a single
> cheap test.
> 
> Reproduced with a tcx ingress program on a veth in a receiver netns with
> an ipip tunnel which assigns an established tcp socket to ipip packets.
> The sender sends 32 tcp segments of one flow inside ipip through a netem
> slot qdisc so they are decapsulated in one batch and merged by gro.
> Then the socket is closed and the receiver netns is deleted. The leaked
> socket holds a ref on the netns so it is never torn down and its devices
> are never unregistered:
> 
> Before:
>    bpf_sk_assign() calls 32, sk_refcnt 32 after the burst
>    receiver netns deleted, 30s later its veth peer still exists
> 
> After:
>    bpf_sk_assign() calls 32, sk_refcnt 1 after the burst
>    receiver netns deleted, its veth peer is gone
> 
> The problem was found during reviews of patches that add bpf_sk_assign
> egress support.
> 
> Fixes: cf7fbe660f2d ("bpf: Add socket assign support")
> Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
> ---
> CC: David S. Miller <davem@davemloft.net>
> CC: Eric Dumazet <edumazet@kernel.org>
> CC: Jakub Kicinski <kuba@kernel.org>
> CC: Paolo Abeni <pabeni@redhat.com>
> CC: Simon Horman <horms@kernel.org>
> CC: Alexei Starovoitov <ast@kernel.org>
> CC: Martin KaFai Lau <kafai@fb.com>
> CC: Joe Stringer <joe@wand.net.nz>
> CC: Daniel Borkmann <daniel@iogearbox.net>
> CC: bpf@vger.kernel.org
> 
>   net/core/gro_cells.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 

TBH it can be applied to next, this is an old problem ("never worked") that is
a corner case found by LLM reviews of a patch-set, which would make it easier to
reach. I've tested it with net-next as well.

Cheers,
  Nik


  reply	other threads:[~2026-11-22 14:21 UTC|newest]

Thread overview: 4+ 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 [this message]
2026-11-23 10:49 ` Eric Dumazet
2026-11-24  3:03 ` netdev-bot+sashiko

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=c953972c-dc7e-4b97-b271-5137f0cb2cbc@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@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