From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82B3B384CD6 for ; Thu, 17 Sep 2026 02:19:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789611548; cv=none; b=fk7xZdP/tnladmIQmR+er5EPEB9OTL5dHgtPwedNmDa4cQI/36y18oa6Hy08Vv+9XmorZDT1rp7rj0l2ErCO7IvGEsr/VzAgJMUBSeG5vqOJEeqzYeJ9AIo4tBpWOG4PBwtA+eAtY9UP2pnTKn/IvAO2uKZlf1MMfbcARlvtPeM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789611548; c=relaxed/simple; bh=PVQn0EHfOqfMXrHYs5wHI5pxSC2E96Ovpda/TEtiwUw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ij4aRrGWY8E8bpGtLvb4eUknbWHG9QmB5hbD2IeNq5W5Uz8Y7K7uRi6arOMBbtu2jaCuegSJ68FdBFTHZTL/fRxrFuoQ2lZXCLdNSQZ2vMqMBvV7zVA3O4pP2Tg1NjY3PKs218lS/OM31DZ9k11j6skaBNgYG9iDSWmgadC//Eo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iP/Z1zOy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iP/Z1zOy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF3461F000FF; Thu, 17 Sep 2026 02:19:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789611547; bh=rroNUoRZ6MkHYhtYjQZbBtGsrHPyi6EMnDSWludjER4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iP/Z1zOyILcEOP3t+cO77lxpO0ZwlR2Fu1j8UABxaxuKdNNOlPMwvNKgdkCdxbj6w 1v/nTRKkxHgX3eSY/5TARmm5II6vjEA5pUFcDk6gL5TkxaOfTU+oZtmmW++m3B72hU GOFEPvgr2/7ZfBLu1tq6msmiOfh/qs6Z8l7reCCbzGcDpcpgvqbhydRts8RdiWQvm4 2FgKc39zMbISD+xy4x+zZNef7bwKu+rw9nnJiiqXQL6ppQAL8gL1XoalReOmcFHig9 GGaNsgPnfKdzAimm6EB35+mvTf6JD0JKm1xb0Ic2d1ZP897H4PPz11YM3a0suPHqKE VTY4IJoOETwqw== From: Sasha Levin To: stable@vger.kernel.org Cc: Zhiling Zou , Vega , Ido Schimmel , Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.12.y 7/7] ipv6: flowlabel: cap duplicate leases per socket Date: Wed, 16 Sep 2026 22:18:59 -0400 Message-ID: <20260917021859.3810309-7-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260917021859.3810309-1-sashal@kernel.org> References: <2026091655-dejected-hammock-755e@gregkh> <20260917021859.3810309-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Zhiling Zou [ Upstream commit 8d6cd188508513503805c156165de38e4e4a8615 ] ipv6_flowlabel_get() allocates an ipv6_fl_socklist entry for every successful GET. The recheck path for a compatible existing flowlabel links another lease without applying any lease admission check. Repeated GET requests for one shareable label can therefore grow a socket's lease list without bound. Reject a new unprivileged lease once the socket already holds FL_MAX_PER_SOCK leases. Check this on the shared recheck path so reuse of a globally interned label, including the fl_intern() collision path, is covered as well. New-label admission remains under the existing mem_check() policy. Use capable(CAP_NET_ADMIN) rather than ns_capable(), matching mem_check(). An unprivileged user must not bypass the cap by creating a user namespace and a netns where they have CAP_NET_ADMIN, which would still consume host memory. Check the capability only when the socket reaches the limit, so successful unprivileged GET requests below the cap do not generate a capability audit. Do the admission check before updating linger and expires so a rejected GET does not refresh the shared label, matching the existing socket-list allocation failure path. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Reported-by: Vega Suggested-by: Ido Schimmel Signed-off-by: Zhiling Zou Reviewed-by: Eric Dumazet Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/83f8535972ff6e3741548476a1d50dec24c758be.1788415194.git.zhilinz@nebusec.ai Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv6/ip6_flowlabel.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/net/ipv6/ip6_flowlabel.c b/net/ipv6/ip6_flowlabel.c index ad9210266b77e..ce6c2b551ef51 100644 --- a/net/ipv6/ip6_flowlabel.c +++ b/net/ipv6/ip6_flowlabel.c @@ -462,6 +462,21 @@ fl_create(struct net *net, struct sock *sk, struct in6_flowlabel_req *freq, return NULL; } +static bool fl_sock_at_lease_limit(const struct sock *sk) +{ + const struct ipv6_fl_socklist *sfl; + int count = 0; + + rcu_read_lock(); + for_each_sk_fl_rcu(sk, sfl) { + if (++count >= FL_MAX_PER_SOCK) + break; + } + rcu_read_unlock(); + + return count >= FL_MAX_PER_SOCK; +} + static int mem_check(struct sock *sk) { const int unpriv_total_limit = FL_MAX_SIZE - (FL_MAX_SIZE / 4); @@ -673,6 +688,10 @@ static int ipv6_flowlabel_get(struct sock *sk, struct in6_flowlabel_req *freq, err = -ENOMEM; if (!sfl1) goto release; + err = -ENOBUFS; + if (fl_sock_at_lease_limit(sk) && + !capable(CAP_NET_ADMIN)) + goto release; if (fl->linger > fl1->linger) fl1->linger = fl->linger; if ((long)(fl->expires - fl1->expires) > 0) -- 2.53.0