🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Nikolay Aleksandrov Thu, 26 Nov 2026 17:30
[PATCH net v2] net: keep skbs that carry a socket out of gro_cells gro
#23198
Author: Nikolay Aleksandrov
Date: Thu, 26 Nov 2026 17:30
98 lines
14728 bytes
bpf_sk_assign at tc ingress holds a reference on a socket that isn't 
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. A socket
that is rcu freed carries no reference, but if NFQUEUE queues the packet
__nf_queue takes one and switches the destructor to sock_edemux, so the
skb owns a reference when it reaches gro_cells_receive as well. 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 that carry a socket to netif_rx instead as gro_cells_receive
already does for cloned skbs, where each skb is consumed on its own and
no ref is lost.

This also diverts sock_wfree skbs which GRO can merge when slow_gro
is set. They only get here via esp software GRO, e.g. from veth in
napi mode or netdevsim, and those lose GRO.

tun with IFF_NAPI passes sock_wfree skbs to GRO without slow_gro so
gro_cells could merge skbs from different tun queues and uncharge all of
their wmem from the aggregate's socket only.

skb->sk shares a cache line with skb->dev that is read at the start of
gro_cells_receive 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>
---
Eric, I didn't add your reviewed-by as this is a different check.

v2: changed the check to skb->sk instead of skb_sk_is_prefetched (Sashiko)
    changed the commit message & subject to reflect it
    rebased and retested

v1: https://lore.kernel.org/netdev/20261121160204.4024204-1-razor@blackwall.org/

local Sashiko review says:
 [Severity: Medium]
 Does this regress GRO for sock_wfree-owned ESP packets?  A veth NAPI
 packet can retain its socket through ESP decapsulation and reach this
 branch.  netif_rx() then delivers the inner packet without another GRO
 pass, increasing receive-side work.

 Nik: That is understood and documented in the commit message.

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: Willem de Bruijn <willemb@google.com>
CC: bpf@vger.kernel.org

 net/core/gro_cells.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/core/gro_cells.c b/net/core/gro_cells.c
index 31352cac355c..4bb7316a8be3 100644
--- a/net/core/gro_cells.c
+++ b/net/core/gro_cells.c
@@ -26,7 +26,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)) {
 		res = netif_rx(skb);
 		goto unlock;
 	}
-- 
2.47.3
Re: [PATCH net v2] net: keep skbs that carry a socket out of gro_cells gro
#25611
Author: patchwork-bot+netdevbpf
Date: Wed, 02 Dec 2026 04:20
29 lines
9093 bytes
Hello:

This patch was applied to netdev/net.git (main)
by Willem de Bruijn <willemb@google.com>:

On Thu, 26 Nov 2026 19:30:34 +0200 you wrote:
> bpf_sk_assign at tc ingress holds a reference on a socket that isn't
> 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. A socket
> that is rcu freed carries no reference, but if NFQUEUE queues the packet
> __nf_queue takes one and switches the destructor to sock_edemux, so the
> skb owns a reference when it reaches gro_cells_receive as well. 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.
> 
> [...]

Here is the summary with links:
  - [net,v2] net: keep skbs that carry a socket out of gro_cells gro
    https://git.kernel.org/netdev/net/c/7a3ee12c2009

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads