Article View: linux.kernel.netdev
Article #23198[PATCH net v2] net: keep skbs that carry a socket out of gro_cells gro
From: Nikolay Aleksandrov
Date: Thu, 26 Nov 2026 17:30
Date: Thu, 26 Nov 2026 17:30
98 lines
14728 bytes
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
Technical Details
Message-ID:
<20261126173034.1860377-1-razor@blackwall.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372261-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372261-linux-kernel-netdev=dewy.ru
From: razor@blackwall.org (Nikolay Aleksandrov)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2] net: keep skbs that carry a socket out of gro_cells gro
Date: Thu, 26 Nov 2026 19:30:34 +0200
Organization: Usenet Network
Message-ID: <20261126173034.1860377-1-razor@blackwall.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="521874"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Y8wEzTO5/rU3CN/GEV7k79GuN1g= sha256:cdWTnLZjyoPhdTteRC3Uzk9zFlTvvRA+dywv9cy16dE=
sha1:0y0WleFm7ItdrfZpU1nxNP+XkXE= sha256:1YuCGLEmnr9+w51bJVtkSMwrug1KnrkT4ZwTJ2wax2E=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 6B063125EF1; Thu, 26 Nov 2026 20:32:49 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.15
X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=blackwall.org
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 628nNKH3FT3Z;
Thu, 26 Nov 2026 20:32:40 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-372261-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=blackwall.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 7AF84125EEE; Thu, 26 Nov 2026 20:32:30 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 8197E2D424; Thu, 26 Nov 2026 17:32:28 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1795714348;
b=cM4BVk8KbdSV+OSEKgboFJZ7QZAEELzZhBQt1kHZvLymfVvevGCijNG4yIn/AyRBO8qm
sW7Fe5uLEo1L13laDydg5iXwBzNtawT92WMv5KmrwEW1U4lyXfdhkckjE3Fxg2+99roas
+XAHZNqNEDSfe2rgOcQtCOSFKjRqszKF3L5p8HYuUnpsrSW+YXv4//JmobmVPVh5MUjYe
oFqeO9QKqC187L/l3la3Nn3lsaEZ9/xTuY6YkTFT+jiyWI8S+GGY+JpLoY4n8uyj51d8J
mhgQSEA8D5b7LSz4w9bbWdchWHCdrCjYeRtwok8urJMHXokMK7WtYdx3LlvDtCPxp9g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795714348;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:X-Mailing-List:
List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding;
bh=HGUEFbhyMPHvtc3QryNaymed5lzjFNWIsxM5k1JO/oI=;
b=IKTUv7g5B2tnseWIcl05VeX2lfE6Twe8YZfYy7MAVqVPcrbQRgx6cgsj0Atig5gNWDDB
NpEiJlRI/+2EhmCV1yft6jzoME87kXqQeA33IdTG+tpITkgI/8/Opj+Y8HrKKqTpmXlhR
09mmoSQga9Gh+8rgz18trBxkCwg+mEyk8yUNdlTPHuMIgaNMj69uWlg/aY9eYgFFJXdUD
OXEm8xEzIlN5z6IYins41AJCrYQHzcHmiOD3LM2qEdxBVxfP5JBGlUKVxaictB0hF/ple
LWLku/ys2Tan2RcdRzLFD08tddVMnSS+y0SjG60j2wuhtv2Kv2J8shmuBP2KaDH0Mxg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=blackwall.org header.i=@blackwall.org header.a=rsa-sha256 header.s=google header.b=c0PHCRsS;
dmarc=none header.from=blackwall.org;
spf=none smtp.mailfrom=blackwall.org;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 0004F606A327;
Thu, 26 Nov 2026 17:32:27 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=blackwall.org header.i=@blackwall.org header.a=rsa-sha256 header.s=google header.b=c0PHCRsS
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.47
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795714347;
b=0Kl8QYRsWcptIkYQspRjJDdaUBYYwXLTRbYimab38xY8wkz2e+doeD/jlcQdhu3bl1QA
8jcObY5jXwixedBuWb7hpbTPQHKiDshfnXM+NRY/mqsp/q+TAe0cg1LA3t+Y6l5dS9icV
0OGqAYhYwx9dXIzUFQM0b9BxzjZAEeOXL1g9bXpPlGak5XyO5dWX19l9MR3hErZahoQme
c6EmXQxBxeOMrdO2x/dOt4Hj9f5V7cqhDLgOiICJr7gDtXbXmG7fGSpQ78HzmJQ3UuRFY
HpWNVssXH70iAVa0rsN5NZEp96xtlT4YvJWWdBwdK+FltcK0NWwdiGtkkhWkeWRrOhg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795714347;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding;
bh=HGUEFbhyMPHvtc3QryNaymed5lzjFNWIsxM5k1JO/oI=;
b=JuotADuACPooJ2ebJB4kCXL554DFPNMjzzkVC1yZ9QDbvt/GhqZ0GjBu9Q6CVySR4pRc
vdlIFa+//9VEdd+S1Ri5P1CBmJ2bKpuKGpQgEGsIJfcsbE4IO+lTHo6Xv9tuSD0ncJS0p
YzQ+PUDSK2COjnGPA+UyXlw5tVH8f/lagOXPbgr/JUoR+FMhWP2qvi5c/ztwb1apqvfEc
nfe2qiWOlWT2RmH4Zb0hVTVC++oBo1CWQtLxoYfohZwlyoJhWU2Tw+I+sHGays6Of7I+b
nVSTa0tbpdEK1rO0BdA+z6L/9BmLbLwCJmKLuAeJFu42elqFsrhNwEu9W/2gLniOprw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=none header.from=blackwall.org;
spf=none smtp.mailfrom=blackwall.org;
dkim=pass header.d=blackwall.org header.i=@blackwall.org header.a=rsa-sha256 header.s=google header.b=c0PHCRsS;
arc=none smtp.remote-ip=209.85.128.47
X-Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0B98606A31C
for <netdev@vger.kernel.org>; Thu, 26 Nov 2026 17:32:26 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B0B98606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=blackwall.org
X-Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=blackwall.org
X-Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4bb85e07aadso89727485e9.1
for <netdev@vger.kernel.org>; Thu, 26 Nov 2026 09:32:26 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=blackwall.org; s=google; t=1795714345; x=1796319145; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=HGUEFbhyMPHvtc3QryNaymed5lzjFNWIsxM5k1JO/oI=;
b=c0PHCRsSqx+4QTbIaJGYJRjTvVGLARj7ZW3OeaMLrkbBYVJNw8GniuuESSJFDN8gyq
ioHZsUkpS0wfAldrG2ANQTahQM3Bp2XGdSa6IpjmpBjHiCJz/gaBfU/QvhLQlOkneVLX
XB7135vdtOWKBlYRDXNvQj9NW/HT3ecz//PpUkH6L9EkahndC/KWA98s/gw3m7eY2uLI
Rz+WfMc83qk1meAdJaJCrtptlG88dzQnIf4rZERn1cM+A0NgZ5h8b/xjA6wjkQoB6n7P
RKT9zmXNEGYdR1Hgr87cYPV/nEBs4Jigb2DbxiRvW4VtIQm+kw8Xs/HWRmEZ58AOZP3c
klgQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1795714345; x=1796319145;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=HG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mAHKW
YHH13w1ZBRq8G5nBH1hH6/+1hhJOrERIt87aI0c4kFQ25WBH/fqVmRw7O4N1Ihfwxkof1icMexp
IZp2i+8P3nZ/nPkrVnQ8klSdoyvvla5cvDiqIo+n3tuE1GHzLuY=
X-Received: by 2002:a05:600c:8b83:b0:4a3:59c9:a747 with SMTP id 5b1f17b1804b1-4bb8880642cmr417929205e9.17.1795714344564;
Thu, 26 Nov 2026 09:32:24 -0800 (PST)
X-Received: from localhost (78-154-14-127.ip.btc-net.bg. [78.154.14.127])
by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-4ab65cb41f4sm40608361f8f.7.2026.11.26.09.32.23
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 26 Nov 2026 09:32:24 -0800 (PST)
X-Cc: Nikolay Aleksandrov <razor@blackwall.org>,
"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>,
Willem de Bruijn <willemb@google.com>,
bpf@vger.kernel.org
X-Mailer: git-send-email 2.47.3
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list