* [PATCH nf] netfilter: ipset: do not exceed maxelem when reusing a deleted slot
@ 2026-12-04 15:43 Qing Lee
2026-12-04 15:47 ` netdev-bot+sinfo
0 siblings, 1 reply; 3+ messages in thread
From: Qing Lee @ 2026-12-04 15:43 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal, Phil Sutter
Cc: netfilter-devel, coreteam, netdev, linux-kernel, Qing Lee
In mtype_add(), reusing a previously deleted slot (!test_bit(i, n->used))
sets deleted = reuse = true and jumps directly to copy_data, incrementing
elements without checking elements >= maxelem. Because a deleted slot was
already decremented from elements when removed, reusing it when the set is
full allows the number of elements to exceed maxelem.
Only select a deleted slot for reuse when elements < maxelem. This also
allows the loop to keep scanning for a timed-out entry in the same bucket
when the set is full. For forceadd when no timed-out entry was found, pick
the first in-use slot with find_first_bit() instead of hardcoding slot 0
(which may be deleted), and fall back to set_full if the bucket has no
in-use entries.
Fixes: 18f84d41d34f ("netfilter: ipset: Introduce RCU locking in hash:* types")
Signed-off-by: Qing Lee <l.qing95@gmail.com>
---
net/netfilter/ipset/ip_set_hash_gen.h | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h
index 80ca523f3..fe56bf857 100644
--- a/net/netfilter/ipset/ip_set_hash_gen.h
+++ b/net/netfilter/ipset/ip_set_hash_gen.h
@@ -1039,8 +1039,8 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,
npos = smp_load_acquire(&n->pos);
for (i = 0; i < npos; i++) {
if (!test_bit(i, n->used)) {
- /* Reuse first deleted entry */
- if (j == -1) {
+ /* Reuse first deleted entry only if set is not full */
+ if (j == -1 && elements < maxelem) {
deleted = reuse = true;
j = i;
}
@@ -1063,8 +1063,11 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,
}
}
if (reuse || forceadd) {
- if (j == -1)
- j = 0;
+ if (j == -1) {
+ j = find_first_bit(n->used, npos);
+ if (j >= npos)
+ goto set_full;
+ }
data = ahash_data(n, j, set->dsize);
if (!deleted) {
mtype_del_cidr_all(set, h, data);
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH nf] netfilter: ipset: do not exceed maxelem when reusing a deleted slot
2026-12-04 15:43 [PATCH nf] netfilter: ipset: do not exceed maxelem when reusing a deleted slot Qing Lee
@ 2026-12-04 15:47 ` netdev-bot+sinfo
2026-12-04 16:04 ` Qing Lee
0 siblings, 1 reply; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-12-04 15:47 UTC (permalink / raw)
To: Qing Lee
Cc: Pablo Neira Ayuso, Florian Westphal, Phil Sutter, netfilter-devel,
coreteam, netdev, linux-kernel
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH nf] netfilter: ipset: do not exceed maxelem when reusing a deleted slot
2026-12-04 15:47 ` netdev-bot+sinfo
@ 2026-12-04 16:04 ` Qing Lee
0 siblings, 0 replies; 3+ messages in thread
From: Qing Lee @ 2026-12-04 16:04 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: Pablo Neira Ayuso, Florian Westphal, Phil Sutter, netfilter-devel,
coreteam, netdev, linux-kernel
Hi,
This bug was observed during real-world testing on an embedded Linux 6.18
system running an iptables rule with a hash:ip ipset configured with a
small maxelem (5) and a timeout.
After a previously inserted entry expired/was removed from a bucket and
5 other IPs subsequently filled the set to maxelem, inserting another IP
that hashed into the bucket with the deleted slot succeeded, resulting in
`ipset list` reporting 6 entries with `maxelem 5`.
From there, I traced the issue to mtype_add() in
net/netfilter/ipset/ip_set_hash_gen.h, verified it is still present in
nf.git, and compile-tested the patch with W=1.
Thanks,
Qing
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 16:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 15:43 [PATCH nf] netfilter: ipset: do not exceed maxelem when reusing a deleted slot Qing Lee
2026-12-04 15:47 ` netdev-bot+sinfo
2026-12-04 16:04 ` Qing Lee
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox