Netdev List
 help / color / mirror / Atom feed
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 11/15] netfilter: ipset: add rhashtable boilerplate stubs
Date: Tue, 24 Nov 2026 14:39:41 +0000	[thread overview]
Message-ID: <179553118161.3135.18226469983779759073@kernel.org> (raw)
In-Reply-To: <20261123135726.3940688-12-pablo@netfilter.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] ipset hash sets lose memcg accounting for their bucket
  storage.

--

netfilter: ipset: add rhashtable boilerplate stubs

This preparation patch adds a struct rhashtable to the generic ipset hash
type. It initialises the table in the create path and destroys it in
mtype_destroy(). No elements are added yet; the conversion itself is done
in a follow-up patch.

> diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h
> index 80ca523f304bb..a3f6c0aa47f75 100644
> --- a/net/netfilter/ipset/ip_set_hash_gen.h
> +++ b/net/netfilter/ipset/ip_set_hash_gen.h

[ ... ]

> @@ -1749,15 +1839,27 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set,
>  
>  #ifdef IP_SET_PROTO_UNDEF
>  	hsize = sizeof(struct htype);
> +	params = mtype_rht_params;
>  #else

[ ... ]

>  #endif
>  	h = kzalloc(hsize, GFP_KERNEL);
>  	if (!h)
>  		return -ENOMEM;
>  
> +	/* maxsize: maximum bucket table size to expand to */
> +	params.max_size = maxelem;
> +
> +	err = rhashtable_init(&h->ht, &params);

[Severity: Medium]
Does this drop memcg accounting for the hash bucket storage?

Until now, ipset hash table storage (the htable with its bucket array, and
hregion) has been allocated through ip_set_alloc(), which charges the
memcg:

net/netfilter/ipset/ip_set_core.c:ip_set_alloc() {
	return kvzalloc(size, GFP_KERNEL_ACCOUNT);
}

rhashtable_init() leads to an allocation that is not accounted. Also,
struct rhashtable_params has no way to ask for __GFP_ACCOUNT:

rhashtable_init()
  __rhashtable_init_noprof()
    bucket_table_alloc(ht, size, GFP_KERNEL)
      kvmalloc_node_align_noprof(..., gfp|__GFP_ZERO, NUMA_NO_NODE)

With only this patch applied, every ipset create of a hash:* type makes
one extra uncharged allocation. It is a struct bucket_table with the
default 64 bucket pointers, because no nelem_hint or min_size is set.

That seems to conflict with this statement in the commit message:

    This change is supposed to be devoid of side effects

The larger effect comes with the follow-up commit "netfilter: ipset:
replace internal hash table with rhashtable". That commit removes the
accounted htable entirely, so all bucket array memory lives in rhashtable
bucket tables. Growth also goes through the unaccounted path:

rht_deferred_worker()
  rhashtable_rehash_alloc()
    bucket_table_alloc(ht, size, GFP_KERNEL)

These tables can grow up to params.max_size = maxelem buckets.
IPSET_CMD_CREATE only needs CAP_NET_ADMIN in the user namespace that owns
the netns. That means a container could use this memory beyond its memcg
limit.

Element objects were already allocated with GFP_ATOMIC and no accounting
before the series. The difference here is only the bucket arrays, which
used to be charged.

Nothing later in the series appears to restore the accounting for the
bucket tables. Should the rhashtable bucket allocations be charged to the
memcg, as the htable storage was before?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123135726.3940688-2-pablo%40netfilter.org

  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 [this message]
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
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 11/15] netfilter: ipset: add rhashtable boilerplate stubs 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=179553118161.3135.18226469983779759073@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