Article View: linux.kernel.netdev
Article #24922Re: [PATCH] netfilter: nft_set_rbtree: clear stale rbe_end on unexpired start element
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 02:58
Date: Tue, 01 Dec 2026 02:58
141 lines
12988 bytes
12988 bytes
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
Technical Details
Message-ID:
<179609393053.3146.3884162948995523449@kernel.org>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374649-linux-kernel-netdev=dewy.ruReferences:
<54EEAAE000DA2911+1796007358.199103-1-huxinyao@kylinsec.com.cn>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374649-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH] netfilter: nft_set_rbtree: clear stale rbe_end on unexpired start element Date: Tue, 01 Dec 2026 02:58:50 +0000 Organization: Usenet Network Message-ID: <179609393053.3146.3884162948995523449@kernel.org> References: <54EEAAE000DA2911+1796007358.199103-1-huxinyao@kylinsec.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1596336"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:KjLtcU/X0FvuyoDg5uaqkRYT60o= sha256:wHbUwjaFjHjilmfq0TXR4i5ykQm32du3/sKTMT8vB90= sha1:Pta0D1CQkjRzhnFwSQilAJrY0Kw= sha256:yyvDav6JJwVRDNN6+qao/yi5hCdYBPuglzecS6bp+h4= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 0FC4F11720C; Tue, 1 Dec 2026 05:59:12 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2KmPSEwGlEUl; Tue, 1 Dec 2026 05:59:08 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374649-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 0A534117203; Tue, 1 Dec 2026 05:58:58 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 6C2F4299DB; Tue, 1 Dec 2026 02:58:54 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796093933; b=TENNeuMqyx2S6EFzYpRsfq6nJ8At6HuE8sH8Evv3+uQ4Wo0i8KZz1CC612O0tc3yhCG6 9ouKvwECkcrJLbPQG+tZB7tvOlNfwDtOl9X0srfVpt+hc+W0+Y2tF4MFwHFnH6flfYXmo AX+1PGlxw1Oq8mKfDNNIL7vZO/70WMXaTPBbxiSVhHROuFQfBGsH3RIDY5kOEXPbbZMXT MzdmhMZdiMRVslBk8FcIauTBgb+JfhaRJ/lJFNX8spLR6JcPK2mIDHZGBsmHEpvFOYGMh qtqVJGYK3vmAOOWfOx+5ngDp9E5L5g0ZEJi2YH8FXdkvFkx3h9Sa0GAsX1kXK+zRixA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796093933; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=HPY9LjdCZix5uzy0Ajrk6sw+C/9cCdlG13rxRYO9+0M=; b=om36KoQOyhVyiGwlPsGxH4e2+bZP4lglH4J1dtnuNrRP4ZHVxF3kx7pO3M0nhu4SusYU WRoy6rtZW2TAtdEFWwn6MjdDIEbxm5LHjzhjH3Z4IvqGlBdeLxTm9ZeMmxpUwLHBKKAGH 60vWP/MJAUeRUGwW47fptryGWrcU+FFgrCkYkFeUBqL54HVPNGOll7AqhEPiQBDN05ypF Vf9nJ++lUX9Le4FGsup0iGVCXrpqLylJxjf1R9vTZX0Gy1QELg26PJERyLbt9kVVkokLJ GBQliD357BGMLJ6e961kebO0bcOV/QuGKZEslXxyefcGJr2rHTmI0Fw5M8JmdZW1z7Q== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Q0BVJqn6; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD9C8606A333; Tue, 1 Dec 2026 02:58:53 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Q0BVJqn6 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796093932; b=EuyrE5BiyX9BXSfS6NPYX3c86tQMR/JK1WFgRIlpTxc0sfIhWtRhmTRVOIhwlJcdFcMh ihPeq5x71s6VmU8DTt2Tgfxos/RgtLL3MwMamoc6MxelirQFH++1imPAiFocDWM7GkzHT omqVeWvrRmx2pxfn0t6uLdRRSAGfcFuUYU9Nkwn6ZzYyHh7RyP8QyD2WRsCdQIATjZCSr FB2fS43l/EyzGotsUXZWfI3wh1lGSVlKz9DOzZq3PoIB8H7xgXBydaIaJTPJs1oLMuZDa EgsweRANI4qUeZaQcxtzQjTBxaMT+jy0O407vId87gxln9+4yiA+Uac9kXIZs4MjVng== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796093932; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=HPY9LjdCZix5uzy0Ajrk6sw+C/9cCdlG13rxRYO9+0M=; b=vs2vdOwkeKb9bqNVIWCWj8GUDBBUqxX+TpUW5kun+e/3sImQRW9IbzW+1IgLHU/TwitZ WrSONofG0wFP5turTqAshTGnXnzmmAUcH97ZdFBlR8ZO+2lptz1eKnNAYxteUjLyaz8Pw xOhCqj9H8Zlk0AcNv/S5U4c82bU4RmcVDMCCTyqsEUzo8p13VnPZVjUOuHb5rgB0tyFzD 5zrE+du2xywXFWBnXQZ4xwyPanMVbuRBD09nC9Fw28j6s9Iq6wUWUSJcKSuqfn7QOxzGD KmX9ZS/6Jhsatwh2rSy8jAhm5WIS/fVMLjxwZrNhTFPFML8PVW52bBdOOJ+cSoPh/Ig== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Q0BVJqn6; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBE0A606A31A; Tue, 1 Dec 2026 02:58:52 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FF521F00898; Tue, 1 Dec 2026 02:58:50 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796093931; bh=HPY9LjdCZix5uzy0Ajrk6sw+C/9cCdlG13rxRYO9+0M=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Q0BVJqn6tZ4yC8b3wlMjWQzSUhH0UzNds+XD7Xk1XCcSpd301PoMIImhoqwKaLXUQ uFYm8syvTOkUG/gTBIgc0xMA11ElkqzKeEslh0UcOc9ljxiZDqMcjWRfd7PqrzUYcS bxM1rs5hUnteghVE7FPTD3BwgQR/wvoC5Lmd5JjTeINZ72GuEgfCGK6qH8t4Umtlzk KhFWv2vhCx/pPjQoQ1OpGi0M23cvYfV/4RM9czOiJVc1EyV/sP2Vx8PAKk/Zarx9/u rQQ80DMsDAMwR9itwIdY6zts5YMOwIdlOljQEjBnaX9T7Fad6pjjF/+0RFCHbqD5kQ Rxq0DZd+v7Z7Q== X-Cc: pablo@netfilter.org, fw@strlen.de, phil@nwl.cc, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org X-In-Reply-To: <54EEAAE000DA2911+1796007358.199103-1-huxinyao@kylinsec.com.cn> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list