From nobody Sun Jun 14 06:14:56 2026 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AF2A175A92 for ; Sat, 2 May 2026 05:00:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777698045; cv=none; b=Dt0s4AZBCwAM/B0n9HnfW+c/OBISneAzySdsoo8MEeFc+P0/4DSj1tnXf4YmnEfvSLs9bbJ9Ggl82gjHx02/p8Lsvv4mIM9cbX0/kwTJnPx1Oesj6iiq402ZHC3mf47JPUGdvg4E59YQ5ZM5MHy7lOhVGKpHYGEtCdRd+St5/bo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777698045; c=relaxed/simple; bh=ver2UoWpS2YcfE27GaQTuIn81K78hKcA2yLnGa8/hiQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=eTqF+AOoBocEDPxZuthP+TNoiBUcpUhz3s03xgAFeXIBh8nOiNQ6gzDzULB+jXwyySGV1otipLps9UldjxtHESh32LyTCwvPeEq+uVwjSjzHpnGRVf6UI6Ky2g1ee3cbNvM0QSgB+cxZ9Mhj8huKjbn/emFdmdfasMW/TuNklKA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XI/tRLa6; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XI/tRLa6" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-364e5d895e3so1188641a91.2 for ; Fri, 01 May 2026 22:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777698043; x=1778302843; 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; bh=Rd4mi+oKC8Y6Z2wEWlSkY1p2DPTiyoqQPePQg0Iz5kc=; b=XI/tRLa6sYagm2yYw51q9lWcK22L6ZqGnIdLX6qXMUeK8SajyUhORqqcvXzEYcFol5 Vs2lO6Qr2ImfZ5+rUBtFHlLBCbz4n1sLCqhMdsrB+zuNvbRxV9DgduovYoNf64juSpdM EGbgDMQSrLYmRiPo2zASDlhNu2OKpKI9Bss59j4joWwZdphUF8mmTbzJoY0mB4euV6o2 sVCw0KnKImJHTyDViF/AO0cBkHkhqB8BR/U5YhGy1VjOeiWzft64nsdo5uN1BHur8a46 fumZy8JoS4byyv+d0BSERdnGzVh5ZSs0FVke8eRXE05rFAnPwfC2tRHQJkANcfH8M92n 2HlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777698043; x=1778302843; 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; bh=Rd4mi+oKC8Y6Z2wEWlSkY1p2DPTiyoqQPePQg0Iz5kc=; b=ADImes1HQGMB5bV+6gRVD13J/fEiuomqFipFgyRENx11r3BGxuOtC9ZAVoAfA45Sf9 PnyaGv43Iif0N+yFYRiMORQUQOnj0QlC20R8KdJLCbVS2E9jJQFQE3DgEk5WycZJPE8v kfEjy6RYvUAT8PhHTKIpTu6p+XOBmR7iMKxzenC2TRZAWNe47ic5tMPbw4IVx39K+MCR pR9rKzZRPbz4ezfq29HD6NvOVcBgWOM6jOd8Hs+IBk4+++a5mLZwm/zhbP6zjOooPcHK yPAN8YuUHE/KnM3WrMAu4aZl6FEehzDlfqWRIT5wDLvGYoH8gKoJBxm0KwagWcJsJLar 1GXw== X-Forwarded-Encrypted: i=1; AFNElJ/w3DjjR2A9cvu1lm5maWu+RO4bW82EZ6+EvRl5NRjCuVZVdnp2qEeqnifzQLbkXXKjd3wKTHynJB+QKUY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy940kYshLTnhJKbguMlqLncE5K4CVjV3xMIlih1ODBbMKUyiKh 2jKqZh5Ye6TnRetHYCNb0jxlKF/86q7CsYGZgx58P4pLv2b1+wrjVAsF X-Gm-Gg: AeBDievvtNJ5mYEC4M5zx8o9ARxjhdhiEzAHTrotkdmeX0wRde2D37h1SuRJucga59p UV8xLPHtKG71YwKip4FQKJ2/kCyvKeFvklZZh6JSMNQieZYd3YLk4XypoOCVO/VfKqCmu0vtcyP KjRAgDF4UHcaEJbY1spQsNPrc/hdTh3fmAuXZ5qmOxdzIuhM3oWUze5/dcfbHXCaHqYg18iIqvA Qag3ip8OZkKkHYLikekqcr2krw9M/RcP4w6Uyw19X3EPj3vHILVt1sBKIdVcctRGUYYCBeaiIih 5IYrZenYP21pcpUp9XwiVxleD8uQ4X8PMXia3ouzNPkEA/D7A76bISIDmwtgjMkeaX5QGhdHEjm vK+AwvssVTziFHZ16pGUUHYWHPsTJTOJdcISWFZxzm2C/oeTSyaRL37w/mcO/wnMuqNa6+BE6s8 iN90RMGxCwJZ512F0E4nNasxssjoSfvTGTIb+BCdzDXl7JN2Yh3uZY6RrOws8WNKOuLHQ= X-Received: by 2002:a17:90b:17d0:b0:35a:cf:64a6 with SMTP id 98e67ed59e1d1-3650ce552camr2070944a91.23.1777698043292; Fri, 01 May 2026 22:00:43 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-364ec03c944sm3822498a91.15.2026.05.01.22.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 22:00:42 -0700 (PDT) From: Maoyi Xie X-Google-Original-From: Maoyi Xie To: netdev@vger.kernel.org Cc: willemdebruijn.kernel@gmail.com, willemb@google.com, edumazet@google.com, pabeni@redhat.com, kuba@kernel.org, davem@davemloft.net, dsahern@kernel.org, kuznet@ms2.inr.ac.ru, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH net v5] ipv6: flowlabel: enforce per-netns limit for unprivileged callers Date: Sat, 2 May 2026 13:00:37 +0800 Message-Id: <20260502050037.3800122-1-maoyi.xie@ntu.edu.sg> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 is placed in 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 =3D 3072 entries. With FL_MAX_SIZE doubled, this preserves the original per-user reach (~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. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Suggested-by: Willem de Bruijn Cc: stable@vger.kernel.org # v5.15+ Signed-off-by: Maoyi Xie --- v5 (this submission, addressing v4 review by Willem): - Replaced the per-netns ceiling FL_MAX_SIZE/8 with the computed unpriv_user_limit =3D (FL_MAX_SIZE - FL_MAX_SIZE/4)/2, which evaluates to 3072. v4's FL_MAX_SIZE/8 =3D 1024 would have reduced the per-user budget below the ~3K an unprivileged caller could already obtain before any of this work, defeating the reason FL_MAX_SIZE was doubled in the first place. The new ceiling preserves the original per-user reach while still requiring an attacker to spread across at least two netns to drain the global non-CAP_NET_ADMIN budget. - Reworded the corresponding paragraph in the commit body. v4: addressed Willem's v3 review on netdev. Dropped the flowlabel_has_excl cacheline argument in favour of "fills the existing 4-byte hole after ipmr_seq", and reordered atomic_dec(&...flowlabel_count) to sit immediately after atomic_dec(&fl_size) in ip6_fl_gc and ip6_fl_purge. v3: addressed Willem's review on the private security@ thread. Merged FL_MAX_SIZE doubling, dropped test data, moved flowlabel_count near ipmr_seq, inlined fl->fl_net in ip6_fl_gc. v2: per-netns counter + cap, sent to security@ as a 2-patch series. v1: fix-shape sketch in original disclosure. include/net/netns/ipv6.h | 1 + net/ipv6/ip6_flowlabel.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h index 34bdb1308..329482373 100644 --- a/include/net/netns/ipv6.h +++ b/include/net/netns/ipv6.h @@ -119,6 +119,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 */ + atomic_t 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 c92f98c6f..758a2fc4d 100644 --- a/net/ipv6/ip6_flowlabel.c +++ b/net/ipv6/ip6_flowlabel.c @@ -36,7 +36,7 @@ /* FL hash table */ =20 #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) =20 @@ -162,8 +162,9 @@ static void ip6_fl_gc(struct timer_list *unused) ttd =3D fl->expires; if (time_after_eq(now, ttd)) { *flp =3D fl->next; - fl_free(fl); atomic_dec(&fl_size); + atomic_dec(&fl->fl_net->ipv6.flowlabel_count); + fl_free(fl); continue; } if (!sched || time_before(ttd, sched)) @@ -195,8 +196,9 @@ static void __net_exit ip6_fl_purge(struct net *net) if (net_eq(fl->fl_net, net) && atomic_read(&fl->users) =3D=3D 0) { *flp =3D fl->next; - fl_free(fl); atomic_dec(&fl_size); + atomic_dec(&net->ipv6.flowlabel_count); + fl_free(fl); continue; } flp =3D &fl->next; @@ -245,6 +247,7 @@ static struct ip6_flowlabel *fl_intern(struct net *net, fl->next =3D fl_ht[FL_HASH(fl->label)]; rcu_assign_pointer(fl_ht[FL_HASH(fl->label)], fl); atomic_inc(&fl_size); + atomic_inc(&net->ipv6.flowlabel_count); spin_unlock_bh(&ip6_fl_lock); rcu_read_unlock(); return NULL; @@ -464,6 +467,9 @@ fl_create(struct net *net, struct sock *sk, struct in6_= flowlabel_req *freq, =20 static int mem_check(struct sock *sk) { + const int unpriv_total_limit =3D FL_MAX_SIZE - (FL_MAX_SIZE / 4); + const int unpriv_user_limit =3D unpriv_total_limit / 2; + struct net *net =3D sock_net(sk); int room =3D FL_MAX_SIZE - atomic_read(&fl_size); struct ipv6_fl_socklist *sfl; int count =3D 0; @@ -478,7 +484,9 @@ static int mem_check(struct sock *sk) =20 if (room <=3D 0 || ((count >=3D 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 || + atomic_read(&net->ipv6.flowlabel_count) >=3D unpriv_user_limit) && !capable(CAP_NET_ADMIN))) return -ENOBUFS; =20 --=20 2.34.1