From: netdev-bot+sashiko@kernel.org
To: pablo@netfilter.org
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
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 [thread overview]
Message-ID: <179553118436.3135.12549536301575412131@kernel.org> (raw)
In-Reply-To: <20261123135726.3940688-14-pablo@netfilter.org>
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
next prev parent reply other threads:[~2026-11-24 14:39 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 13:57 [PATCH net-next,v2 00/15] Netfilter updates for net-next Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 01/15] netfilter: conntrack: prevent nf_conntrack_buckets race condition Pablo Neira Ayuso
2026-11-23 14:02 ` netdev-bot+sinfo
2026-11-23 14:17 ` Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 02/15] netfilter: conntrack: validate skb->_nfct and packet headers Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 03/15] netfilter: conntrack: refactor helper call logic in nf_confirm() Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 04/15] netfilter: conntrack: verify L4 protocol before calling helper Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 05/15] netfilter: conntrack: replace open-coded helper invocation Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 06/15] netfilter: conntrack: harden helper invocation with tuple revalidation Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 07/15] netfilter: nft_ct: validate timeout object protocol Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 08/15] netfilter: nft_synproxy: only handle pure SYN and ACK packets Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 09/15] netfilter: nft_ct: validate hook and priority for ct zone set Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 10/15] rhashtable: Add rhashtable_flush_and_free helper Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 11/15] netfilter: ipset: add rhashtable boilerplate stubs Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 12/15] netfilter: ipset: replace internal hash table with rhashtable Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 13/15] netfilter: ipset: also report mem size for cidr storage to userspace Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko [this message]
2026-11-23 13:57 ` [PATCH net-next 14/15] netfilter: ipset: re-add IP_SET_HASH_WITH_MULTI support Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 15/15] netfilter: ipset: re-add forceadd support Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-24 12:27 ` [PATCH net-next,v2 00/15] Netfilter updates for net-next Paolo Abeni
2026-11-24 12:36 ` Florian Westphal
2026-11-24 13:47 ` Paolo Abeni
2026-11-24 13:33 ` Pablo Neira Ayuso
2026-11-24 13:43 ` Paolo Abeni
-- strict thread matches above, loose matches on Subject: below --
2026-11-23 13:54 [PATCH net-next " Pablo Neira Ayuso
2026-11-23 13:54 ` [PATCH net-next 13/15] netfilter: ipset: also report mem size for cidr storage to userspace Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179553118436.3135.12549536301575412131@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=ja@ssi.bg \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox