🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21867

Re: [PATCH net-next 13/15] netfilter: ipset: also report mem size for cidr storage to userspace

#21867
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 14:39
119 lines
11927 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The comment above mtype_rht_size() in
  net/netfilter/ipset/ip_set_hash_gen.h says it returns 'the current…
- [Low] In mtype_rht_size(), the new cidr accounting uses ksize(nets),
  which returns the slab-rounded size of the allocation.
- [Low] The new ksize(nets) call in mtype_rht_size() is used only to
  report memory usage, but ksize() has a side effect.

--

netfilter: ipset: also report mem size for cidr storage to userspace

This patch changes mtype_rht_size() so the ext_size it reports also
includes the dynamically allocated net_prefixes arrays in h->rnets[].
That way the cidr storage added by commit 8e5fd2a55e24 ("netfilter: ipset:
rework cidr bookkeeping") shows up in the memsize reported to userspace.

> diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h
> index 8ac1b0f048560..e7f2e584a7a50 100644
> --- a/net/netfilter/ipset/ip_set_hash_gen.h
> +++ b/net/netfilter/ipset/ip_set_hash_gen.h
> @@ -616,6 +616,23 @@ mtype_rht_size(struct ip_set *set, u32 *elements, size_t *ext_size)
>  	*elements = ipset_hash_nelems(h);
>  	*ext_size = *elements *
>  		    (offsetof(struct mtype_rht_elem, elem) + set->dsize);
> +
> +#ifdef IP_SET_HASH_WITH_NETS
> +	{
> +		const struct net_prefixes *nets;
> +		int i;
> +
> +		rcu_read_lock();
> +
> +		for (i = 0; i < IPSET_NET_COUNT; i++) {
> +			nets = rcu_dereference(h->rnets[i]);
> +			if (nets)
> +				*ext_size += ksize(nets);

[Severity: Low]
This isn't a bug, but the comment above mtype_rht_size() still says:

/* Get the current number of elements and per-element memory in the set */

After this change *ext_size also includes the h->rnets[] arrays. That
storage belongs to the whole set and is sized by the number of distinct
cidr values. It is also non-zero for an empty set.

Should the comment say that ext_size now covers the per-set cidr storage
as well?

[Severity: Low]
Should this count the requested size instead of ksize()?

Every other term in IPSET_ATTR_MEMSIZE uses the exact requested size:
sizeof(*h), the per-element term just above, and
sizeof(*c) + strlen(c->str) + 1 in ip_set_init_comment().

The nets arrays are allocated with kzalloc_obj(*nets) at create time, and
in mtype_add_cidr() with:

	tmp = kzalloc_flex(*tmp, nets, len, GFP_ATOMIC);

ksize() rounds these up to the kmalloc bucket size. If KFENCE served the
object, ksize() returns kfence_ksize() instead, which is the requested
size. So two identical sets can report different memsize values,
depending on the config and on which allocator served the object.

Would struct_size(nets, nets, nets->len) match how the other terms are
counted?

[Severity: Low]
Is ksize() a good fit for a call that only reports memory usage? Under
CONFIG_SLUB_DEBUG it has a side effect:

mm/slub.c:__ksize() {
    ...
#ifdef CONFIG_SLUB_DEBUG
	skip_orig_size_check(slab->slab_cache, object);
#endif
    ...
}

and skip_orig_size_check() does:

	set_orig_size(s, (void *)object, s->object_size);

On kmalloc caches that record the original size (slub_debug with
store-user/redzone), this replaces the recorded request size of the
net_prefixes object with the full object size. The object is long-lived
and RCU-published. For the rest of its life, the kmalloc redzone check no
longer covers the slack after the flex array.

Any user with CAP_NET_ADMIN in the netns can reach this on every ipset
list or header dump:

mtype_head()->mtype_rht_size()->ksize()->__ksize()->skip_orig_size_check()

The ksize() kernel-doc also says it is meant for internal use and points
callers to kmalloc_size_roundup().

Would struct_size(nets, nets, nets->len), read under the same RCU
protection, avoid this side effect?

> +		}
> +
> +		rcu_read_unlock();
> +	}
> +#endif

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123135726.3940688-2-pablo%40netfilter.org
Technical Details
Message-ID: <179553118436.3135.12549536301575412131@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.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-370469-linux-kernel-netdev=dewy.ru
References: <20261123135726.3940688-14-pablo@netfilter.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.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-370469-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next 13/15] netfilter: ipset: also report mem size for
 cidr storage to userspace
Date: Tue, 24 Nov 2026 14:39:44 +0000
Organization: Usenet Network
Message-ID: <179553118436.3135.12549536301575412131@kernel.org>
References: <20261123135726.3940688-14-pablo@netfilter.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4160211"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:6OEbYBZpbkQ9kpFee03IFyFFX1s= sha256:4e3ij30HL/lwX1ETij50dE2QLI8bECyWTkCS+QgxNs0=
	sha1:tJXyzt2eAxhCi8ODWcPovpchHtI= sha256:2GA0IRRbp9Prp6FoHhM/16eYjdzwvzivPnJn/ck2puc=
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 A11C8125E1B; Tue, 24 Nov 2026 17:40:30 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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] 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 fFLMg77X4kjw;
	Tue, 24 Nov 2026 17:40:27 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-370469-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id B8796125E18; Tue, 24 Nov 2026 17:40:18 +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 6F50336EC4; Tue, 24 Nov 2026 14:39:54 +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=1795531187;
	b=ptarU40d93UKiZHnkU9bvbXjGQf8znMi/TETxoW42qr2uJQBfEJpgQdmeTbCkaQDjukR
	 joyx91lsD44++1aU98+YrITH24JmJGMpsBb1G4TPuPxYeCablXQuImFzfWbW/qJ8pOFBp
	 mkehaFR0nx+blsWapZgi/6CQMq1qqbn+H+X7aTS7y3OAIagjfut1Z5I5dyzlu1LJ5gfZD
	 MvBeQE2GphpMlJEwUdhxm9fJEQDFgj2LA8W49pkBlVtTlIvnyvh1IFmt66J9rMDOODsUD
	 M2Ml1wB9nQikTe43s+ejopTYthBZ5+TPKWRyDImK/elHC9r8PJZ4wKnVoOzH4igDZUQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795531187;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=Pc+nKV8j+HMFJVuzSfYPNMwp9+aUKEG5lmf4DY8ejKo=;
	b=kf0BakVr5KC+wJUGi5UTniuCXDUTysyyKiYf4XYYesWV8tDkTDh5vxHF/j177Fkkc7p0
	 re/cRdwtyH+dn2IISljvxXgZ5CfYcqUH9N5+Ged2SInGQwm5LIzaGRpYPVYKbNfMiwqNC
	 qzf6Dk+CrgCtoHovl1QsqG3d/O2LhHEvL2myx4sqLt+IQaSjhLZ/fv2smt2tE2O360vWl
	 qVnGMT1K6uJ+GnMKH7l08vTehLqC3sEGQEdfSRurOMvCjzRIWMwVppnOXIjD/j6xg08Us
	 FHHLEwgKtQcjwDjG7ysZF9P2T9g2KExWypHNbCPk4sGQG6AmU+BWRNF90geeStlGf9Q==
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=mEkRupPo;
	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 E11D4606A698;
	Tue, 24 Nov 2026 14:39:46 +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=mEkRupPo
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795531186;
	b=uAPi8hgwv5kxJzo1w8b1qxU8tBEKxVKfvzQUYe/gk/TV+UrAQKmTG9qdp6OX/jrF7tV7
	 At5k6PzdBLO26nff23hTCFU792ZeeP1ojT+sE9iZR9d9XLpIyblxlvDE68Zfj5IgCCm3A
	 pE615eWltgnsZ4OBGpTDZJ2KiqEHPXPIzxNjf4iLxEiMGJwX+NWVzXm4SRfM1dvO8m9cw
	 x94R6L3gul7WbV5LE8oEcl/JTMtun8lS5lnqb2fWqfhl5XuULnI2+Ily9R51Wz7FHJqiP
	 WIiB2OXDbAdB1D2u5A5BvDFLFSVcEUHbYdg6h25r8iBHxi/VIgh9mevI/Lz5GRjwHrA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795531186;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=Pc+nKV8j+HMFJVuzSfYPNMwp9+aUKEG5lmf4DY8ejKo=;
	b=CxXaFeZruu3u7rT0yUV1ywStQDsp820cbOED3hgWdyBUG+SIrxLUdqr/u+wXcoV7AvOU
	 mrBKvZq6t/IvfGtoP0Mgz1Q+FQ62j9sal71fWQGlZHt2SqUWgJAmPOFbGwyWlBFZ/NyJV
	 mwUyCLH5AEIQOrGyUT9B6bp/MaVYQxDTmp1SJvYbOCbGIMmvB1bHZqNW4RDzbFIBkL0bP
	 lr7xNH5Ho2VIGSe1Y9lgbS9F7ODUA0V59M3idKoNWiJMoWVLGe6ehGwAwr/kjGDcs25SO
	 +shWLioLgUAclHekXXBCzUANAMF306YXOMQzL5lBTruZHuNhN1V3n7FG1nFaDU2DzLA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mEkRupPo;
	arc=none 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 0D050606A332;
	Tue, 24 Nov 2026 14:39:45 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0A431F000C0;
	Tue, 24 Nov 2026 14:39:44 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795531185;
	bh=Pc+nKV8j+HMFJVuzSfYPNMwp9+aUKEG5lmf4DY8ejKo=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=mEkRupPomOgcu4TzcZQe2kf646uR2eMP3JI0yikA7u6EBA8R5Q+3oq45jsGwCV8Fx
	 mFKTyeENRAl2X99TCiFuGepEdnlRmnBIaLwYmAxqq0puupCjcXdStXGb6wL3Sob4Ge
	 qAndLP5+BF96zLzygWB9MNsUVOzUdgts03EFSm3F7/6vzzY4BHU58epGXwNdkSbmdW
	 dinTIbjrvf+Zoo7xrR37pGTyy5m0vUPoMilItmCBqEKrN1D8co/AYUqghWMP2ubKuL
	 dFBqtvEriV+0zyP2nRDt4o82d2wJVsC1dfuYs93JXMCOeR2KtuJ9ymAup8ONlVkTBh
	 qd1/Fon5cn9WA==
X-Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
 netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
 edumazet@kernel.org, horms@kernel.org, fw@strlen.de, ja@ssi.bg
X-In-Reply-To: <20261123135726.3940688-14-pablo@netfilter.org>
X-sashiko-severity: Low
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