From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FF521F00898; Tue, 1 Dec 2026 02:58:50 +0000 (UTC) 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== Subject: Re: [PATCH] netfilter: nft_set_rbtree: clear stale rbe_end on unexpired start element From: netdev-bot+sashiko@kernel.org To: huxinyao@kylinsec.com.cn 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 Date: Tue, 01 Dec 2026 02:58:50 +0000 Message-ID: <179609393053.3146.3884162948995523449@kernel.org> In-Reply-To: <54EEAAE000DA2911+1796007358.199103-1-huxinyao@kylinsec.com.cn> References: <54EEAAE000DA2911+1796007358.199103-1-huxinyao@kylinsec.com.cn> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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