From mboxrd@z Thu Jan 1 00:00:00 1970 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 DCAAD483BF0; Thu, 20 Aug 2026 17:56:28 +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=1787248590; cv=none; b=FcqXjo8NBsivXVphRiduYK0egtgX77yiQmaM6t8Wvfc9zeas8Fi1lHgT47loZFU+GV77pwqD+l3mlEV8xpNlTGPTdchA96jJHgNVbdq4mAs1m6+Q0j6V4xBKK8NHwLpqnq+7VucotKCWCvAZx7vcELorALKTW++rra79oVFlCsw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787248590; c=relaxed/simple; bh=AixrsyL/1I+oG7Ph7NXWPFrlMdvqkSIsT1wLhhSmf/I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bSkiL8aEt0kOHt9gaflnn5z9whDFebpz1eggKNlpixhEsMYyGn3+s+u7WpphNcUvaey6hJ922zYtviFaG3nEffYrsVInTV0LLJgwsBztxL4beiX9pKc8T8LKbLLs7hbkvrO6iWcsYC7abJGWJUOTvFXPtIzVpBguf/D8QL2S8MQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=i/wHBA8O; 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="i/wHBA8O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21DC61F000E9; Thu, 20 Aug 2026 17:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1787248588; bh=iJ0vwLAZqYPBPbsIu0zHFS3PotKsdg0zhFHWfymtCWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=i/wHBA8OU286OD16TpVMz4qX6BeZ27q7Hu+Sui5/7k/UMYAP5X2ZG4gSxfLbzJQxn F3sBSjB5XICssTy6naBoRZL05nZGfgcCBbCwVC+U8J7rWabQf42CGThwoH1pcYjYQc UUvcjp3x5qxXYOUJRywD5yOKXfVTQHAWJ/hvTuqA= 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.1 281/303] netfilter: flowtable: publish GC-visible tuple last Date: Thu, 20 Aug 2026 16:56:57 +0200 Message-ID: <20260820145301.912575493@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260820145253.200766705@linuxfoundation.org> References: <20260820145253.200766705@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.1-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 9edc627d94b9e..be74dccfe1410 100644 --- a/net/netfilter/nf_flow_table_core.c +++ b/net/netfilter/nf_flow_table_core.c @@ -276,17 +276,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