From: netdev-bot+sashiko@kernel.org
To: onleaf322@gmail.com
Cc: pablo@netfilter.org, fw@strlen.de, phil@nwl.cc,
kadlec@netfilter.org, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH net] netfilter: ipset: exclude add-path GC during resize
Date: Thu, 19 Nov 2026 21:27:37 +0000 [thread overview]
Message-ID: <179512365704.3136.7898068439962970821@kernel.org> (raw)
In-Reply-To: <20261117092731.14656-1-onleaf322@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 1 · High: 0 (1) · Medium: 0 · Low: 1
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).
- [Critical] The fix is incomplete.
- [Low] The commit carries `Cc: stable@vger.kernel.org` and `Fixes:
f66ee0410b1c`, a 2020 commit, so stable maintainers will try to apply…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but a successful
resize leaks the comment extensions of elements that had already…
--
netfilter: ipset: exclude add-path GC during resize
This patch takes h->gc.lock around the direct mtype_gc_do() call in
mtype_add() and skips the collection when the pinned table has resizing
set. The goal is to keep the packet-side add path from freeing extensions
of old-table elements that mtype_resize() has already copied into the new
table.
> Fixes: f66ee0410b1c ("netfilter: ipset: Fix "INFO: rcu detected stall in hash_xxx" reports")
> Cc: stable@vger.kernel.org
[Severity: Low]
The new code uses h->gc.lock and t->resizing. Both were added by
cffcf57bf03c ("netfilter: ipset: exclude gc when resize is in progress"),
which has no Fixes: or Cc: stable tag. The commit message mentions it only
as background.
Stable trees that have f66ee0410b1c but not cffcf57bf03c won't build this
patch. A hand-adapted backport could also add the add-path check without
the matching resize-side flag and lock.
Should the stable tag record the dependency, for example
"Cc: stable@vger.kernel.org # depends on cffcf57bf03c", or ask for
cffcf57bf03c to be backported as well?
> diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h
> index 80ca523f304bb..70f768ba7b443 100644
> --- a/net/netfilter/ipset/ip_set_hash_gen.h
> +++ b/net/netfilter/ipset/ip_set_hash_gen.h
> @@ -1009,8 +1009,12 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,
> maxelem = t->maxelem;
> if (elements >= maxelem) {
> u32 e;
> - if (SET_WITH_TIMEOUT(set))
> - mtype_gc_do(set, h, t, r);
> + if (SET_WITH_TIMEOUT(set)) {
> + spin_lock_bh(&h->gc.lock);
> + if (!t->resizing)
> + mtype_gc_do(set, h, t, r);
> + spin_unlock_bh(&h->gc.lock);
> + }
> maxelem = h->maxelem;
> elements = 0;
> for (e = 0; e < ahash_numof_locks(t->htable_bits); e++)
[Severity: Critical]
Does this fully close the double free? Only the direct mtype_gc_do() call
is guarded. Other packet-path sites still call ip_set_ext_destroy() on
elements of the pinned old table while mtype_resize() runs.
mtype_resize() makes a shallow copy of each live element. It holds only
rcu_read_lock_bh() and no hregion locks:
d = ahash_data(m, m->pos, dsize);
memcpy(d, data, dsize);
After the copy, both tables point to the same ip_set_comment_rcu. Hash
types set region_lock, so packet-side ip_set_add() and ip_set_del() can
run at the same time as this copy.
The first site is the reuse/forceadd branch later in mtype_add():
if (reuse || forceadd) {
if (j == -1)
j = 0;
data = ahash_data(n, j, set->dsize);
if (!deleted) {
mtype_del_cidr_all(set, h, data);
ip_set_ext_destroy(set, data);
t->hregion[r].elements--;
}
goto copy_data;
}
This branch can free the comment of an element that was live when copied
and has expired since. That is the same timing as the race in the commit
message. With forceadd it evicts slot 0, a live element that has already
been copied, so no expiry timing is needed.
GC is now skipped on a resizing table. When expired entries are present,
the recomputed elements stays >= maxelem. Doesn't that make forceadd more
likely to take this eviction path?
The second site is mtype_del():
mtype_del_cidr_all(set, h, d);
ip_set_ext_destroy(set, data);
if (t->resizing && ext && ext->target) {
...
x->ad = IPSET_DEL;
This frees the comment in the old table and queues an IPSET_DEL record.
After the new table is published, mtype_resize() replays the record:
mtype_del(set, &x->d, NULL, NULL, 0);
The replay finds the copied element in the new table and calls
ip_set_ext_destroy() again on the same comment pointer.
ip_set_comment_free() clears only the slot it is given:
atomic64_sub(sizeof(*c) + strlen(c->str) + 1, &set->ext_size);
rcu_assign_pointer(comment->c, NULL);
kfree_rcu(c, rcu);
In each case the new table keeps a dangling pointer. The next GC, delete,
flush/destroy or backlog replay on it then calls strlen() on freed memory
and does a second kfree_rcu(). A dump would also read freed memory
through ip_set_put_comment().
Would it be better to stop or defer all extension destruction on the old
table while t->resizing is set? Another option is to have the new table
take ownership of the extensions during resize, by transfer or deep copy.
[Severity: High]
This is a pre-existing issue, but does a successful resize leak the
comment extensions of elements that had already expired but had not been
collected yet?
mtype_resize() skips those elements during the copy:
if (SET_ELEM_EXPIRED(set, data))
continue;
It then frees the old table without extension cleanup:
if (atomic_dec_and_test(&orig->uref)) {
pr_debug("Table destroy by resize %p\n", orig);
mtype_ahash_destroy(set, orig, false);
}
With ext_destroy set to false, mtype_ahash_destroy() skips
mtype_ext_cleanup(). orig->resizing stays true after a successful resize,
so mtype_gc() never runs mtype_gc_do() on orig. With this patch the add
path doesn't either:
if (!t->resizing)
mtype_gc_do(set, h, t, r);
So the ip_set_comment_rcu objects that ip_set_init_comment() allocated
for those elements are never freed. set->ext_size is never reduced for
them either.
Before this patch, the add-path GC could still free some of those
uncopied expired comments while running on orig. This check closes that
window as well.
ipset netlink commands need only CAP_NET_ADMIN in the caller's own user
and network namespace, and these allocations are not memcg accounted. Can
a user repeat create, expire, resize and destroy to use up host memory?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117092731.14656-1-onleaf322%40gmail.com
next prev parent reply other threads:[~2026-11-19 21:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 9:27 [PATCH net] netfilter: ipset: exclude add-path GC during resize onLeaf
2026-11-17 9:57 ` Greg KH
2026-11-19 21:27 ` netdev-bot+sashiko [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-11-17 9:26 onLeaf
2026-11-17 9:57 ` Greg KH
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=179512365704.3136.7898068439962970821@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=kadlec@netfilter.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=onleaf322@gmail.com \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
--cc=stable@vger.kernel.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