* Re: [PATCH] netfilter: nft_set_rbtree: clear stale rbe_end on unexpired start element
2026-11-30 2:55 [PATCH] netfilter: nft_set_rbtree: clear stale rbe_end on unexpired start element Hu Xinyao
@ 2026-11-30 2:59 ` netdev-bot+sinfo
2026-11-30 3:09 ` Hu Xinyao
2026-11-30 11:45 ` Pablo Neira Ayuso
2026-12-01 2:58 ` netdev-bot+sashiko
2 siblings, 1 reply; 5+ messages in thread
From: netdev-bot+sinfo @ 2026-11-30 2:59 UTC (permalink / raw)
To: Hu Xinyao
Cc: Pablo Neira Ayuso, Florian Westphal, Phil Sutter, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
Simon Horman, 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] 5+ messages in thread
* Re: [PATCH] netfilter: nft_set_rbtree: clear stale rbe_end on unexpired start element
2026-11-30 2:55 [PATCH] netfilter: nft_set_rbtree: clear stale rbe_end on unexpired start element Hu Xinyao
2026-11-30 2:59 ` netdev-bot+sinfo
@ 2026-11-30 11:45 ` Pablo Neira Ayuso
2026-12-01 2:58 ` netdev-bot+sashiko
2 siblings, 0 replies; 5+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-30 11:45 UTC (permalink / raw)
To: Hu Xinyao
Cc: Florian Westphal, Phil Sutter, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
netfilter-devel, coreteam, netdev, linux-kernel
On Mon, Nov 30, 2026 at 11:55:58AM +0900, Hu Xinyao wrote:
> nft_rbtree_gc_scan() iterates the rbtree from highest to lowest key and
> records each active NFT_SET_ELEM_INTERVAL_END node in rbe_end so it can
> be removed alongside its matching start element.
>
> When the start element is not expired, the loop skips it without
> clearing rbe_end. If a subsequent lower-valued expired start element is
> not preceded by its own active end node (for instance, after its end
> marker was separately removed via NFT_MSG_DELSETELEM), gc_scan()
> deactivates and erases the stale rbe_end belonging to the live interval.
I guess you are dealing with a random set with intervals with
incremental updates on left,right sides of the interval.
> Reset rbe_end to NULL when skipping an unexpired start element.
We have received patches like this already with scenarios that we
don't consider valid (ie. userspace nft does support).
> Fixes: 8d8540c4f5e0 ("netfilter: nft_set_rbtree: add timeout support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hu Xinyao <huxinyao@kylinsec.com.cn>
> ---
> net/netfilter/nft_set_rbtree.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/net/netfilter/nft_set_rbtree.c b/net/netfilter/nft_set_rbtree.c
> index 9d68589..2f7887e 100644
> --- a/net/netfilter/nft_set_rbtree.c
> +++ b/net/netfilter/nft_set_rbtree.c
> @@ -911,8 +911,10 @@ static void nft_rbtree_gc_scan(struct nft_set *set)
> rbe_end = rbe;
> continue;
> }
> - if (!__nft_set_elem_expired(&rbe->ext, tstamp))
> + if (!__nft_set_elem_expired(&rbe->ext, tstamp)) {
> + rbe_end = NULL;
> continue;
> + }
>
> /* end element needs to be removed first, it has
> * no timeout extension.
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] netfilter: nft_set_rbtree: clear stale rbe_end on unexpired start element
2026-11-30 2:55 [PATCH] netfilter: nft_set_rbtree: clear stale rbe_end on unexpired start element Hu Xinyao
2026-11-30 2:59 ` netdev-bot+sinfo
2026-11-30 11:45 ` Pablo Neira Ayuso
@ 2026-12-01 2:58 ` netdev-bot+sashiko
2 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 2:58 UTC (permalink / raw)
To: huxinyao
Cc: pablo, fw, phil, davem, edumazet, kuba, pabeni, willemb, horms,
netfilter-devel, coreteam, netdev, linux-kernel
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 2 · Medium: 0 · 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).
- [High] The fix is incomplete: the insert-time GC has the same flaw and
the patch does not touch it.
- [High] The fix is also incomplete inside nft_rbtree_gc_scan().
--
netfilter: nft_set_rbtree: clear stale rbe_end on unexpired start element
This patch resets rbe_end to NULL in nft_rbtree_gc_scan() when the loop
skips an unexpired start element. The aim is to stop the scan from erasing
a live interval's end element along with a lower, expired start element
whose own end was removed separately.
> diff --git a/net/netfilter/nft_set_rbtree.c b/net/netfilter/nft_set_rbtree.c
> index 9d685899da701..2f7887e97ce1e 100644
> --- a/net/netfilter/nft_set_rbtree.c
> +++ b/net/netfilter/nft_set_rbtree.c
> @@ -911,8 +911,10 @@ static void nft_rbtree_gc_scan(struct nft_set *set)
> rbe_end = rbe;
> continue;
> }
> - if (!__nft_set_elem_expired(&rbe->ext, tstamp))
> + if (!__nft_set_elem_expired(&rbe->ext, tstamp)) {
> + rbe_end = NULL;
> continue;
> + }
[Severity: High]
Does the insert-time GC in nft_rbtree_gc_elem() need the same fix?
Its rb_prev() walk skips every node that is not an active end element.
That includes the start elements of live intervals:
net/netfilter/nft_set_rbtree.c:nft_rbtree_gc_elem() {
...
while (prev) {
rbe_prev = rb_entry(prev, struct nft_rbtree_elem, node);
if (nft_rbtree_interval_end(rbe_prev) &&
nft_set_elem_active(&rbe_prev->ext, NFT_GENMASK_ANY))
break;
prev = rb_prev(prev);
}
rbe_prev = NULL;
if (prev) {
rbe_prev = rb_entry(prev, struct nft_rbtree_elem, node);
nft_rbtree_gc_elem_move(net, set, priv, rbe_prev);
}
...
}
Take the precondition from the commit message: start_B has expired and
end_B was removed via NFT_MSG_DELSETELEM. The tree, from high to low key,
is then:
end_A, start_A (live), start_B (expired)
Suppose a NEWSETELEM's overlap walk in __nft_rbtree_insert() reaches
start_B. It would then do:
__nft_rbtree_insert()
nft_rbtree_gc_elem(set, priv, start_B)
skips start_A
nft_rbtree_gc_elem_move(end_A)
end_A matches neither rbe_le nor rbe_ge, so the -EAGAIN branch is not
taken and the insert goes on:
removed_end = nft_rbtree_gc_elem(set, priv, rbe);
if (removed_end == rbe_le || removed_end == rbe_ge)
return -EAGAIN;
At commit, nft_rbtree_commit() rebuilds the array with start_A unpaired.
There are two possible results:
- start_A's .from slot is overwritten by the next start element, and
interval A drops out of lookups.
- If A is the highest interval, it is emitted with to == NULL and
becomes open-ended.
The insert path and the commit-time scan use the same batch tstamp. So
this can happen before nft_rbtree_gc_scan() ever runs, and the change
above does not prevent it.
Should the walk in nft_rbtree_gc_elem() stop at the first active start
element without erasing anything?
[Severity: High]
Can rbe_end still go stale through the earlier inactive-element check in
this loop?
if (!nft_set_elem_active(&rbe->ext, NFT_GENMASK_ANY))
continue;
This path leaves rbe_end unchanged.
nft_rbtree_gc_scan() is called from nft_rbtree_commit(), which
nft_set_commit_update() calls from nf_tables_commit() before the
generation cursor flips. At that point, elements added in the current
batch still have ext->genmask = nft_genmask_cur() from nft_add_set_elem().
This check therefore skips them.
Start from end_X, start_X, end_Y, start_Y, with start_Y expired, and
consider a single batch:
1) DELSETELEM start_X
2) NEWSETELEM start_X' between end_Y and end_X. The overlap walk stops
at end_Y, so the insert-path GC does not run on start_Y.
3) DELSETELEM end_Y only. This is allowed because __nft_rbtree_insert()
cleared start_rbe_cookie in step 2, so
nft_rbtree_deactivate_same_interval() returns true.
At commit, nft_trans_elems_remove() erases start_X and end_Y before
set->ops->commit() is called. nft_rbtree_gc_scan() then does:
sees end_X -> rbe_end = end_X
sees start_X' (pending) -> inactive continue, rbe_end kept
sees start_Y (expired) -> nft_rbtree_gc_elem_move(end_X)
After the generation flip, start_X' is live, but its end element has
already been erased and queued for freeing.
Should rbe_end also be cleared when an inactive start element is skipped?
Alternatively, should the code check that rbe_end is the immediate in-tree
neighbour of rbe before collecting it?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/54EEAAE000DA2911%2B1796007358.199103-1-huxinyao%40kylinsec.com.cn
^ permalink raw reply [flat|nested] 5+ messages in thread