From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 7BC86282F1E for ; Wed, 6 May 2026 08:24:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778055863; cv=none; b=Q3v9xWr8ba4YToLsx6vA3KSwELY/nmnQa8yQq7vS/3K6uY5rkOglSdjnqOjuKZq/nv2qmK/lVSil9ty4+v8sOe84BMSN+EmDBA6OKMzp0DO2dzRHYsXNe5t8277lKPUUMR7BtC209gUtOs/ARMaRktu2B2gcziSb4D7NFDmgPxs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778055863; c=relaxed/simple; bh=FjT3tRekuKDQHAOGCXnDobwmU46yO/8SbxGfk0IJiv8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=iwtYFGC8SG9kCSd1qi/vmoGvXSeNhtpsPyNocoP6av7wYsMzwF3PuU70MwKfiKDR1Q+Z5Li0wIR8I/GfFmgiNyiJYCwg7JuX1XyR8aqEWP1AX7zaggEPHrF7t98yZWMx9J+0g7FLJIn2BSogwlWhgjfjjxWU0NRQJb/lYCA6j70= 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=BeXQoQP2; arc=none smtp.client-ip=209.85.216.53 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="BeXQoQP2" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-364ff382b0bso5034916a91.2 for ; Wed, 06 May 2026 01:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778055862; x=1778660662; 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=4+NLYhJbCV0yu/jhkzCiRqjYSwyB+jChRB9RgBBhFmY=; b=BeXQoQP2vifKulrLafOT8HIk4L/bJLZoPXDejSPzUtfseqyltiBlkfn/Ax0IBxgIE9 vHQ7pQnSpYHpFraBYjEEEGu1Ok2jICi6FPZKevibrJB8SKzBKV3zT1z8Z4V/uUj0mjgv pzbI2bUir9gbOpIOD0E3OeY3gDbc2WAugoIx5pYcAOp3fZgt+8pEp2Jzyq+D/U5oSNNp p5EIH7VxQR0yI0G/Tj9/z8USwLK3FcqOG5TP+E8Q8HRNXTFCIwsaexKkhlCcgGnHinf/ 2FHCUh4BcUUEcZiGmEYwVuH/oKEVeT8uZHyxtp6jh+MCbswJZlcwvcksdQ5JsLcMFfQR MNIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778055862; x=1778660662; 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=4+NLYhJbCV0yu/jhkzCiRqjYSwyB+jChRB9RgBBhFmY=; b=LTrm0i3tHmzk4YjwQcJUYw/D9zpos+RPB27huT1dLPQpZoeEB4FdU0scVtEXAoQ3ye LSAkL+JHH/f6FLC+7Iv3+BkqE8/IeTl6NXUyaJAfMDIHZujXlfvbSZQwNVRG9XSFDo28 oYf0YGN61o3NPMNvo1L3bbFDnRn0RDbn1yyl6vyjHznsvtxHGtAW7jG9RcgvtoS/tDms 0c9TXF4A7rkboHUXywk91Hr7S1EbPkh4J9Bvdq9IeGGxcnPk2Ttw2gziJ8Xu1tA1NI8Z Rvd+d2TQbY0nwqs7dFNWG8jZ30j2NsRIdiBBc9R1ojTm3tLqOLkTeNSZ+tvaHqDNO9OQ /5Tw== X-Forwarded-Encrypted: i=1; AFNElJ+Hmntp+QBtGDT8DWskp+qvc84DzIPFi+HPY7Jlip8jSo9J6kjpvHg31EauQnR7jhtSsNcGgtpkH14E2Rw=@vger.kernel.org X-Gm-Message-State: AOJu0YxNB46arE1EX5DEEPHghL8yQgC+OYOzFcM3TbmEj5q03Pa1Wffn 0/Mi2XeaSYZQ2We+3rCo9caBt2qAw4qIl2yyaJJaDKu6IWc7o2oxMMws X-Gm-Gg: AeBDietxuUM9bFrdMtEpluC+EoI4BXp/Ua7sY7h6VY7QLKC38oaWd38zhGyacuJfrcn cc6v4pD++F4rW5SBedq+BxZ4HP2Ig/5ePZqr48H7AnjG7D6WTKJh5nxQlYV3eVSqxuBs7saN9IJ kYyVxAKesGgein7urNC5hRUYnwUZlrtevN0Ro+xUbwsD0GIG026de5H66ImpYs7NFy/RwL4mz+D OvuGg+Kk5CLzquob6TzEtccKDlmpla2dyDymXLb9OZ6EbsUfNNe3dMzcSNfZuM0uprdMFCGi/HK lB2TtAg2rCpXt20OOLi00nJS3a6hFt/4BIw28XOL/bq+JJ+D/8iFxLydF7RihW4b9l8eB881gYb Uc0tF80/omjfoBfnWvQNBNf1+rjQ+O/USBbvDwe8jI9oazFsmsHLmwDwtej1Nlr6ftTW/IbgXSa sVNo1cJWYg8qcIz1Ja3qPFtTVZzBEuz+uhNxImvQXciIaa5rwiWBZP0ytyjnQ= X-Received: by 2002:a17:90b:1c84:b0:35f:b7f5:9b3 with SMTP id 98e67ed59e1d1-365ab8ba745mr2366825a91.3.1778055861651; Wed, 06 May 2026 01:24:21 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-365b12a1eddsm1000293a91.6.2026.05.06.01.24.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2026 01:24:21 -0700 (PDT) From: Maoyi Xie To: "David S . Miller" Cc: Jakub Kicinski , Paolo Abeni , Eric Dumazet , David Ahern , Alexey Kuznetsov , Willem de Bruijn , Willem de Bruijn , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Maoyi Xie Subject: [PATCH net v8 0/2] ipv6: flowlabel: per-netns budget for unprivileged callers Date: Wed, 6 May 2026 16:24:14 +0800 Message-Id: <20260506082416.2259567-1-maoyixie.tju@gmail.com> 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: 8bit From: Maoyi Xie This series fixes the cross-tenant DoS in net/ipv6/ip6_flowlabel.c. v1 through v6 were single-patch postings, each in its own thread. v6 review pointed out that the existing fl_size read in mem_check() and the corresponding write in fl_intern() are not in the same critical section. v7 split the work into 2 patches. Patch 1/2 is a prerequisite. It moves spin_lock_bh(&ip6_fl_lock) and the matching unlock from fl_intern() into its only caller ipv6_flowlabel_get(), so the mem_check() call runs under the same critical section as the fl_intern() insert. With all writers and the read of fl_size under the lock, fl_size is converted from atomic_t to plain int. This is independent of the per-netns budget. It also makes 2/2 backportable without conflicts. Patch 2/2 is the v6 patch, rebased on 1/2. - flowlabel_count is plain int rather than atomic_t, since the previous patch put all writers and readers under ip6_fl_lock. - In ip6_fl_gc(), fl_free() is now placed below the fl_size and flowlabel_count decrements, removing the v6 cache of fl->fl_net. - In ip6_fl_purge(), fl_free() stays in its original position. The function argument net is used for flowlabel_count. - mem_check() uses spaces around the / operator on all four expressions, addressing the checkpatch note in v6 review. Numeric budget (preserved from v6): pre-patch: global non-CAP_NET_ADMIN budget = FL_MAX_SIZE - FL_MAX_SIZE/4 = 4096 - 1024 = 3072 per-actor reach = 3072 post-patch: FL_MAX_SIZE doubled to 8192 global non-CAP_NET_ADMIN budget = 8192 - 2048 = 6144 per-netns ceiling = 6144 / 2 = 3072 per-actor reach = 3072 (preserved) CAP_NET_ADMIN against init_user_ns still bypasses both caps. Reproducer (KASAN VM, 4 cores, qemu): unprivileged netns A holds 3072 flowlabels via 100 procs. Fresh unprivileged netns B then allocates 32 flowlabels (the FL_MAX_PER_SOCK ceiling for one socket), the same as a clean baseline. Without the per-netns ceiling, netns A could push fl_size past FL_MAX_SIZE - FL_MAX_SIZE / 4 and netns B would see allocations denied. v8: - 1/2: replaced the "Caller must hold ip6_fl_lock" comment in fl_intern() with lockdep_assert_held(&ip6_fl_lock), matching the runtime check already used in mem_check(), per Willem's review. - 1/2: added Fixes: 1da177e4c3f4 trailer to match 2/2, per Willem's review. - Carried forward Reviewed-by: Willem de Bruijn on both patches. - No code change beyond the lockdep_assert_held swap. v7: - 2-patch series: 1/2 (lock prep) and 2/2 (v6 rebased on 1/2). - 2/2: flowlabel_count int, fl_free() reorder removed in ip6_fl_purge(), checkpatch / spacing in mem_check() fixed. v6: rebased onto current net (resolves the conflict on include/net/netns/ipv6.h that v5 hit). fl_free() restored to its pre-series position, with fl->fl_net cached locally in ip6_fl_gc(). v5: replaced the per-netns ceiling FL_MAX_SIZE/8 with the computed unpriv_user_limit = (FL_MAX_SIZE - FL_MAX_SIZE/4)/2, which evaluates to 3072. 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". 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. Maoyi Xie (2): ipv6: flowlabel: take ip6_fl_lock across mem_check and fl_intern ipv6: flowlabel: enforce per-netns limit for unprivileged callers include/net/netns/ipv6.h | 1 + net/ipv6/ip6_flowlabel.c | 46 +++++++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 15 deletions(-) base-commit: ebb639024ebd47a13a511cce6ae630c15e4b3126 -- 2.34.1