🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27357

[PATCH 6.18.y 2/2] ipv6: flowlabel: enforce per-netns limit for unprivileged callers

#27357
From: Dickson Wu via B4 Relay
Date: Sat, 05 Dec 2026 11:58
134 lines
15273 bytes
From: Maoyi Xie <maoyi.xie@ntu.edu.sg>

commit e68eadffb724b36ffd3d5619e0efcaf29ec2a175 upstream.

fl_size, fl_ht and ip6_fl_lock in net/ipv6/ip6_flowlabel.c are
file scope and shared across netns. mem_check() reads fl_size to
decide whether to deny non-CAP_NET_ADMIN callers. capable() runs
against init_user_ns, so an unprivileged user in any non-init
userns can push fl_size past FL_MAX_SIZE - FL_MAX_SIZE / 4 and
starve every other unprivileged userns on the host.

Add struct netns_ipv6::flowlabel_count, bumped and decremented
next to fl_size in fl_intern, ip6_fl_gc and ip6_fl_purge. The new
field fills the existing 4-byte hole after ipmr_seq, so struct
netns_ipv6 stays the same size on 64-bit builds.

Bump FL_MAX_SIZE from 4096 to 8192. It has been 4096 since the
file was added. Machines and connection counts have grown.

mem_check() folds an extra per-netns ceiling into the existing
non-CAP_NET_ADMIN conditional. The ceiling is half of the total
budget that unprivileged callers have ever been able to use, i.e.
(FL_MAX_SIZE - FL_MAX_SIZE / 4) / 2 = 3072 entries. With
FL_MAX_SIZE doubled, this preserves the original per-user reach
of 3K (what an unprivileged caller could already obtain before
this change), while forcing an attacker to spread allocations
across at least two netns to exhaust the global non-CAP_NET_ADMIN
budget.

CAP_NET_ADMIN against init_user_ns still bypasses both caps.

The previous patch took ip6_fl_lock across mem_check and
fl_intern, so the new flowlabel_count read in mem_check and the
new flowlabel_count++ in fl_intern run under the same critical
section. flowlabel_count is therefore plain int, like fl_size.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Suggested-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Cc: stable@vger.kernel.org # v5.15+
Signed-off-by: Maoyi Xie <maoyi.xie@ntu.edu.sg>
Link: https://patch.msgid.link/20260506082416.2259567-3-maoyixie.tju@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
[ adapted to 6.18.y: retain the target ipmr_seq declaration ]
Signed-off-by: Dickson Wu <dickson.wu@certik.com>
---
Only the netns_ipv6 context differs: 6.18.y declares ipmr_seq as an
unsigned int. Tested on v6.18.66, see the cover letter.

The backport and the test runs were prepared with AI coding tools
(OpenAI Codex agents, with review by Claude). I went over the result
before signing off.

 include/net/netns/ipv6.h |  1 +
 net/ipv6/ip6_flowlabel.c | 14 +++++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
index 47dc70d8100a..c928445c4d07 100644
--- a/include/net/netns/ipv6.h
+++ b/include/net/netns/ipv6.h
@@ -114,6 +114,7 @@ struct netns_ipv6 {
 	struct fib_notifier_ops	*notifier_ops;
 	struct fib_notifier_ops	*ip6mr_notifier_ops;
 	unsigned int ipmr_seq; /* protected by rtnl_mutex */
+	int			flowlabel_count;
 	struct {
 		struct hlist_head head;
 		spinlock_t	lock;
diff --git a/net/ipv6/ip6_flowlabel.c b/net/ipv6/ip6_flowlabel.c
index d3c9c06e4c08..0fabc8b6fd74 100644
--- a/net/ipv6/ip6_flowlabel.c
+++ b/net/ipv6/ip6_flowlabel.c
@@ -36,7 +36,7 @@
 /* FL hash table */
 
 #define FL_MAX_PER_SOCK	32
-#define FL_MAX_SIZE	4096
+#define FL_MAX_SIZE	8192
 #define FL_HASH_MASK	255
 #define FL_HASH(l)	(ntohl(l)&FL_HASH_MASK)
 
@@ -162,8 +162,9 @@ static void ip6_fl_gc(struct timer_list *unused)
 				ttd = fl->expires;
 				if (time_after_eq(now, ttd)) {
 					*flp = fl->next;
-					fl_free(fl);
 					fl_size--;
+					fl->fl_net->ipv6.flowlabel_count--;
+					fl_free(fl);
 					continue;
 				}
 				if (!sched || time_before(ttd, sched))
@@ -197,6 +198,7 @@ static void __net_exit ip6_fl_purge(struct net *net)
 				*flp = fl->next;
 				fl_free(fl);
 				fl_size--;
+				net->ipv6.flowlabel_count--;
 				continue;
 			}
 			flp = &fl->next;
@@ -243,6 +245,7 @@ static struct ip6_flowlabel *fl_intern(struct net *net,
 	fl->next = fl_ht[FL_HASH(fl->label)];
 	rcu_assign_pointer(fl_ht[FL_HASH(fl->label)], fl);
 	fl_size++;
+	net->ipv6.flowlabel_count++;
 	return NULL;
 }
 
@@ -475,6 +478,9 @@ static bool fl_sock_at_lease_limit(const struct sock *sk)
 
 static int mem_check(struct sock *sk)
 {
+	const int unpriv_total_limit = FL_MAX_SIZE - (FL_MAX_SIZE / 4);
+	const int unpriv_user_limit = unpriv_total_limit / 2;
+	struct net *net = sock_net(sk);
 	int room;
 	struct ipv6_fl_socklist *sfl;
 	int count = 0;
@@ -493,7 +499,9 @@ static int mem_check(struct sock *sk)
 
 	if (room <= 0 ||
 	    ((count >= FL_MAX_PER_SOCK ||
-	      (count > 0 && room < FL_MAX_SIZE/2) || room < FL_MAX_SIZE/4) &&
+	      (count > 0 && room < FL_MAX_SIZE / 2) ||
+	      room < FL_MAX_SIZE / 4 ||
+	      net->ipv6.flowlabel_count >= unpriv_user_limit) &&
 	     !capable(CAP_NET_ADMIN)))
 		return -ENOBUFS;
 

-- 
2.43.0
Technical Details
Message-ID: <20261205-flowlabel-618b-v1-2-d81e833c0c60@certik.com>
Path: mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377963-linux-kernel-netdev=dewy.ru
References: <2026051901-actress-ambition-70c4@gregkh>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377963-linux-kernel-netdev=dewy.ru
From: devnull+dickson.wu.certik.com@kernel.org (Dickson Wu via B4 Relay)
Newsgroups: linux.kernel.netdev
Subject: [PATCH 6.18.y 2/2] ipv6: flowlabel: enforce per-netns limit for
 unprivileged callers
Date: Sat, 05 Dec 2026 11:58:22 +0000
Organization: Usenet Network
Message-ID: <20261205-flowlabel-618b-v1-2-d81e833c0c60@certik.com>
References: <2026051901-actress-ambition-70c4@gregkh>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="3019995"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:/bl+uh4EMca3jci4NF/EQ3jyg1Y= sha256:55dYe56moi5/KAIeG4/DSt1Z1bRRp3800uweq+2a2eI=
	sha1:2MWQy73GqXuEDaUOnWq0PDxZpxc= sha256:ibC1KOXYCPOMyt585GSUH9VRkYu5Bqp1ir1pQD0lebU=
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 4E070117E07; Sat,  5 Dec 2026 15:01:34 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.539
X-Spam-Status: No, score=-3.539 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.14, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	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=kernel.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 nOtp77OyNXZ7;
	Sat,  5 Dec 2026 15:01:32 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377963-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id C42BE117D21; Sat,  5 Dec 2026 15:01:22 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id E5FDB33E8D; Sat,  5 Dec 2026 12:01:19 +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=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796472079;
	b=i15LzatYd39T1CEfuAf0JR1N5KI+he05N//4QtUVylHGS0H5L1MmApgIp9IxPqzFNHuM
	 sEdWaVUMaDHWsS5kHualDYL6WtECGt2m2sYSRf8ECoRXjblKNxz0i6X5Xwz67iocbtqW6
	 L6THo9xVh1fiGc839MY5TvmaRXu5omGkQ1fNG9P0Y7l4sl6cQDlSLd4ULi4nO1NzOQzgZ
	 zKMm/oOFRKJtmnDN3onNaTn77ROhMSD1Lt9I8naCrCAh/PkSppfW/a9CQekY/bDR1YwWE
	 2WpPsQ96Vs6TP/pL+/roHK0oIWAGwLMQvZq2ot1uUI7C8lPBIZePhXxOXl9/fRpwotg==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796472079;
	h=X-Original-To:Received:Received:DKIM-Signature:Received:From:Date:
	 Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:Message-Id:In-Reply-To:References:To:Cc:
	 X-Mailer:X-Developer-Signature:X-Developer-Key:X-Endpoint-Received:
	 X-Original-From:Reply-To;
	bh=BMXsltnu0hSJ9gjS6ELvSgpYU46SrJPqnQiVUIY1vLQ=;
	b=WULrxMhW2mwWcbkagHkfG3ZsYFJJa/yZzqRBQMqflEfvE0pZzddKUUPpB83rpsN4ZH8r
	 5xWqAIKUT1dMBjj6mpZSYhLvvsbB9GzohsTlsYN2Yfin+r0haD5X6dk0c0QPz/9rXROzZ
	 earLiJmfjdxNnTaPfq+GruSuKFV90QP0CIvBAEIBg0OMD8nrMEz/xiN8gtc36zUjt9Xcz
	 iJAmKM3nmxzPZ2/jNtEzQZYPhfs7HYls5jQ8E8R5merGGK+WSuE9lWbg08IjiCa2Jav4G
	 pyAyZPnTc1HOD7/m3iu74nQs3g6qx6Aa0hf0EZrn/+JQYiNBMYMr+qYQ9wGRuQUkc+g==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Aagj1nsG;
	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 9F6AD606A33E;
	Sat,  5 Dec 2026 12:01:19 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Aagj1nsG
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796472078;
	b=Prax9e8SWR0/aW6GUaqwCocDDQZLD088xDBducrHBhuODltAEQ9NZeqvq/DnSLly9B9B
	 KuyP314+NyaUihw9hnMxVlj5HyztiFrKK3WG//+UW/7b6/RAf31Ib1Vqo0mb1WuSMnn3P
	 TOtV1ur9SdqijFRd1j/PpPXN27yE4mODpTvT/AUGdXDecCLJYAmEQGvjdtXzNTPTp+ydC
	 ZyRip4+kk+w9JcuLUMn5Tf1YNiIBRQx0/D68ojbTYVznh6hF7YvZ0Q2TWNBWMMPJnKL2o
	 qXcSBFkKnvjdgrOlSDTAWlCrRgmP3qAe9ah1TfmSrMSitwp2Sko/IchUbxaY66uNtIw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796472078;
	h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version:
	 Content-Type:Content-Transfer-Encoding:Message-Id:In-Reply-To:
	 References:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key:
	 X-Endpoint-Received:X-Original-From:Reply-To;
	bh=BMXsltnu0hSJ9gjS6ELvSgpYU46SrJPqnQiVUIY1vLQ=;
	b=IoAswla86nJHNUC+l4TjvSr/pzvW0T/LQW8MGNrByqwQe7cApOhxxPfelU7NtlOx9z7B
	 n3tptaXpMaTLc11MxdK73kZWWQ0kPZesCS3zKFHAqt5HT/P6KZ9hBsrUKovHLAhzn8UD9
	 R+104GEAeAnrciGN6FscuSRurj0taGac2yJ6+h6W6hemdxiViyIFwO5dHMc3WtTS0d/8J
	 i5MEc80szp0wMDlQIx3W2mmkayTJejusCKfUvwz+catUWYw0pHaMl+olWQOG4AY6EbmZK
	 XSXPspZVedQGnRAS6naRfs1Bdxvh3TJEuRjJRlhSr0qKk9U8sfVkz8w77LMxKswpgeQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Aagj1nsG;
	arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC56A606A330;
	Sat,  5 Dec 2026 12:01:18 +0000 (UTC)
X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77
X-ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none;
	t=1796472078;
	b=yrA1uBfjRxebWbESWPMIiH6ebaqBna6uwbsvkGLUf+i7rmIfc0n0Tg2ZUNj05i1BQzsD
	 qlSpEwCdh11oqFwbj1YTIb/gWCtMTDfpVyJvORJTbusuRQnp8Xw6I4LaAP+9ZOLHHIJ6J
	 k/FI6PlWNP/1365uHEzmQ5gWRpVwAU3Q7nnmU8T/X1roFEB0ZCT88h1KPNFeGcczlA4QJ
	 TPjpPPTF3VWkp48HxFsai+xeIKoUBex9RVkUdEqHl1QvOJ2lmD6Q2GDsdX3LlxNurMvb1
	 4/TlwOfmneXXY8QtZb83rgwdZ1em3sWgjGEcRZHZsd2OL9thaRsdEyO9C25SytAIJjQ==
X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256;
	c=relaxed/relaxed; t=1796472078;
	h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:Message-Id:In-Reply-To:References:To:Cc:
	 X-Mailer:X-Developer-Signature:X-Developer-Key:X-Endpoint-Received:
	 X-Original-From:Reply-To;
	bh=BMXsltnu0hSJ9gjS6ELvSgpYU46SrJPqnQiVUIY1vLQ=;
	b=cC7XFc/W3RfxgnPgyzs6rfZecUXVqIEG85xonjZP6MV+XFlH++RYkm5o0HofPV3Rzpe3
	 9HNkfba89XW0FLY2hHrpZ7GrFASwhXWP1IvpefgVNRUZ5m3tqFsY2Clym9NB8jq+JGuhE
	 Ejeuy+plNVz2QbO435nbo6NIdp/mFAiNMvVq1f3L8RGvjuQ7Ia+noQP9d7cKFp4r+EjTP
	 CBpzQs2qvu48A8YQvvtZYR9j2GHhPhp+AhXyfC7f8y+/e7sje0Culkw75vK2YWNIxoeuX
	 kX6M0gmxHnPs7k3cW4jeTQxiyqQZBVNPNEYGINmPklLcdm6coEgpLhNSmez/UesZ9Kw==
X-ARC-Authentication-Results: i=1; smtp.kernel.org; 
	arc=none smtp.remote-ip=100.80.115.77
X-Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.kernel.org (Postfix) with ESMTPS id 199EF1F00A07;
	Sat,  5 Dec 2026 12:01:18 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796472078;
	bh=BMXsltnu0hSJ9gjS6ELvSgpYU46SrJPqnQiVUIY1vLQ=;
	h=From:Date:Subject:In-Reply-To:References:To:Cc:Reply-To;
	b=Aagj1nsGJ/Ysuotu3hkjpfx+/oq7mpfCBtDLbJvoFtcy4N+IGn6HBToYnFrvG1vmH
	 V+O3RvbSvlwGr/rzZqSEwfnMehQEZWWpokeQDkjMvmAorIk1YcQAnYkPQVOC+vjBgn
	 cbarN1M3S4oOXg+2orVrZkJC99x8uicUVXHqeWibrNvPej1C3vGTW34dM9UdDrgdBv
	 UjmNUTDaULrsc44kr2S/vGu+jNIisl9JpBxP6VeMrYfpo7CqPfLDLpwRLEigy9wBRU
	 zyHT8n5ExEfv8Czwz0AgHM4V0GQwLw+Ht12Qrrf3O7drffVOu/IBRRH13g/vLYNWvl
	 5rUGKmGevHaAw==
X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1])
	by lkml.kernel.org (Postfix) with ESMTP id A25DE50300;
	Sat,  5 Dec 2026 12:01:17 +0000 (UTC)
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
X-In-Reply-To: <2026051901-actress-ambition-70c4@gregkh>
X-Cc: maoyi.xie@ntu.edu.sg, kuba@kernel.org, willemb@google.com, 
 netdev@vger.kernel.org
X-Mailer: b4 0.16.0
X-Developer-Signature: v=1; a=ed25519-sha256; t=1796471900; l=4915;
 i=dickson.wu@certik.com; s=dickson-b4; h=from:subject:message-id;
 bh=BhpuPFK/NfymdwH7yHbJbrr2J4EDwpmYRJJantArRUM=;
 b=trLsVNcyairLOJL9zRXKoFeWhUbYDEVkg4KsDLs0f0MKOF90mZ2jw18aFPIc6MDjBWgvJcya6
 uHTByAEfFIPBa7pQYfW/6oQmMP3LoGRg8+aWaENGrLyAUY/P2BxjsWw
X-Developer-Key: i=dickson.wu@certik.com; a=ed25519;
 pk=fxH7FS4FdojeJSGLJzgKdfO51Rvr4EW30yinj2mc1vg=
X-Endpoint-Received: by B4 Relay for dickson.wu@certik.com/dickson-b4 with
 auth_id=1647
X-Original-From: Dickson Wu <dickson.wu@certik.com>
X-Reply-To: dickson.wu@certik.com