Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63790481A98; Thu, 20 Aug 2026 17:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787247709; cv=none; b=BsjxaA9gzjWx2p2kwoyuoDAkCRM4OVnIpRUhmzlXtojf1MHKrxCL7iY6SQNwxQbeDCdMnw2Ng9OUyecJFmHTSRfOoAPWpnGa7TCgfk+0PIW5vtOoowF2C7KvUyqIZrXhB7kQqoOT1zQF4oYTvQk9OHw1MOHJgkyLD8hj+1CF59w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787247709; c=relaxed/simple; bh=w2bA8mY0kp4RQ1AJDRp6TCC3yYaVGK5rDEJexbSYrUY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=d+4COY4JkHGWwpoZzur7xR9QbbB8rymqGiiJxYJiGOJZgHgA5VeViG3xFlS0A8luRYnQpik6KMvWm8TPWB9wBASX/tiGpsueKgouB4LDnjBB/FuPsLd9InaEeIOLSKcyve96Huv8ncDvJYurxSrG+4I4V6DqxNZmDQTbRWk2LMI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vGedWV1K; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="vGedWV1K" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0E731F000E9; Thu, 20 Aug 2026 17:41:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1787247708; bh=3E922BNLSCK9EZHEW83T53iNWEVwPoAByMJV695GivQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vGedWV1KicGD+ABLwKAEq5G6m6ozOr2n1fSW2ECtSsskznQP6NdcoCsQWuwyvNDwe Af9zvaWiWF5BxonKqONVMvyqirPnO8eOOrBcV9dCFH3oVyuiEHsFahZ7e6PELv6tcZ sIeWakL+iNFbJ7LgsC8p5dKG1Y52jQLdjQytW4qg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?J=C3=A9r=C3=A9my=20Jean?= , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 6.6 141/166] netfilter: flowtable: publish GC-visible tuple last Date: Thu, 20 Aug 2026 16:56:40 +0200 Message-ID: <20260820145215.413238518@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260820145211.194104353@linuxfoundation.org> References: <20260820145211.194104353@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jérémy Jean [ Upstream commit 2014ac62df9d45bb9a004a043e85df7be09ed780 ] nf_flow_table_iterate() only treats original-direction tuple nodes as owning entries. Publishing the original node first lets GC observe and free a flow while flow_offload_add() is still inserting the reply node. Publish the reply node first and the original node last so GC never sees a partially installed flow. KASAN can trigger slab-use-after-free read and write reports in the flowtable/rhashtable path (rht_deferred_worker, jhash, flow_offload_del, flow_offload_lookup, etc.). Fixes: ac2a66665e23 ("netfilter: add generic flow table infrastructure") Signed-off-by: Jérémy Jean Assisted-by: Codex:gpt-5 Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_flow_table_core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c index 5c1ff07eaee0b..acfbaf9db58bc 100644 --- a/net/netfilter/nf_flow_table_core.c +++ b/net/netfilter/nf_flow_table_core.c @@ -279,17 +279,18 @@ int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow) flow->timeout = nf_flowtable_time_stamp + flow_offload_get_timeout(flow); err = rhashtable_insert_fast(&flow_table->rhashtable, - &flow->tuplehash[0].node, + &flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].node, nf_flow_offload_rhash_params); if (err < 0) return err; + /* GC only iterates original-direction entries; publish original last. */ err = rhashtable_insert_fast(&flow_table->rhashtable, - &flow->tuplehash[1].node, + &flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].node, nf_flow_offload_rhash_params); if (err < 0) { rhashtable_remove_fast(&flow_table->rhashtable, - &flow->tuplehash[0].node, + &flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].node, nf_flow_offload_rhash_params); return err; } -- 2.53.0