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=1796388810; b=UIiBdfya/t8lpEwe5GPvwCfEoiDuAhk3upqNGYvB98XoLYGUYX6665vwYg5jOmOfkEHP agUh7lrJI7x+zHklrFQ1ltgUTvBG9yUH21JNlLx1h4+Edn134R4dQBffphlyPqCo95mYD EhtE6j/VCTcJ/txUdQE2yB28WcdMXug5ZuikHVepKpO+1F1AKjC1qo+sihVMIz23ogWuB QjZ/UOV/dppMYLOAOTbbC1+sqceaC9574sQCx8dJiv2y0agxTfoYUzjmYIGqLYrt11or3 inUH6WRaPc+++PMC2lfRI6e61GAl/cNGkWFpEWrOAGPHQMF6T2xqmfTWz/bkhSEtRww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388810; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=dxO/MSib+04c1J+azQCrRatU5bwPTJ0CF4f/RKSxPkg=; b=uW91VgpS6ARuoLbjhyMJe6h4fM8zTak0+5T97YENblksS6zbSKjWDImXvyrek9Vqdgrl ucV7cv8EkbAOq8pX9yqeGhi0GsquXqCdqBdd/yfYwOMrdKYi23ceiR3GOsFcTQGHcNdWa LN5CjsDb30Hw/eE2FzUg6mKwbdTMpAqFBIDZ+ptIMzKD3Yw0ZSt40+BE9qGy2uRzwHwR4 cDL4riV5dpc0kkvhNaLzq2oMZYPAtPwOsJsfAx7taPkraFDBuqr4kaZ/JftUuiNQppaWa i9EJIyi2eM0Z3ZdiLaIddy2AKKd7VzTG9km6XwwSnZM558TNOfvt23Shjvn9tQx7bxg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="Mb2L/MlZ"; 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 35FB4606A339; Fri, 4 Dec 2026 12:53:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Mb2L/MlZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B15F1F000C2; Fri, 4 Dec 2026 12:53:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388810; bh=dxO/MSib+04c1J+azQCrRatU5bwPTJ0CF4f/RKSxPkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Mb2L/MlZxcLOZMbqC9I1UxrAnWU3yNZkDqKxpjLuk15esA4QTAG8J2JKlNAhq0OJC NXC9xLAQiuMxC1zLEVt7haG+Ily9YF3b9ElyOvXJ/cVE7i0KsFzWlvjFoE80G7/bds kEGRBs/2zXQQNYv5uZOZTmzxrZhEywfDtOVnYd1Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Vega , Luxing Yin , Zihan Xi , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 6.1 0710/1059] netfilter: nf_dup: preserve guard across NFQUEUE reinjection Date: Fri, 4 Dec 2026 19:04:01 +0900 Message-ID: <20261204100702.366598651@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zihan Xi [ Upstream commit 82052e5b5ec36504fe1b9c3c28a711a78fcacf37 ] NFQUEUE can suspend traversal of a duplicated packet while the task-local duplication guard is set. The output call then returns and clears the guard before a later verdict resumes hook traversal. Save the guard in the queue entry and restore it while reinjection continues hook traversal. Preserve and restore the verdict task's prior state, including nested synchronous reinjection. Fixes: cd58bcd9787e ("netfilter: xt_TEE: have cloned packet travel through Xtables too") Cc: stable@vger.kernel.org Reported-by: Vega Assisted-by: LLM Co-developed-by: Luxing Yin Signed-off-by: Luxing Yin Signed-off-by: Zihan Xi Signed-off-by: Pablo Neira Ayuso [ sashal: adapted to use the per-CPU nf_skb_duplicated guard instead of current->in_nf_duplicate, and moved the nf_reinject changes into nf_queue.c with its older WARN_ON_ONCE/kfree_skb code. ] Signed-off-by: Sasha Levin --- include/net/netfilter/nf_queue.h | 1 + net/netfilter/nf_queue.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h index 4cf158b5ea698..1aedf2967a56f 100644 --- a/include/net/netfilter/nf_queue.h +++ b/include/net/netfilter/nf_queue.h @@ -21,6 +21,7 @@ struct nf_queue_entry { struct net_device *physout; #endif struct nf_hook_state state; + bool in_nf_duplicate; bool nf_ct_is_unconfirmed; u16 size; /* sizeof(entry) + saved route keys */ diff --git a/net/netfilter/nf_queue.c b/net/netfilter/nf_queue.c index 2579f94e37444..7f3c24dccf015 100644 --- a/net/netfilter/nf_queue.c +++ b/net/netfilter/nf_queue.c @@ -218,6 +218,7 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state, *entry = (struct nf_queue_entry) { .skb = skb, .skb_dev = skb->dev, + .in_nf_duplicate = this_cpu_read(nf_skb_duplicated), .state = *state, .hook_index = index, .size = sizeof(*entry) + route_key_size, @@ -315,21 +316,26 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) const struct nf_hook_entry *hook_entry; const struct nf_hook_entries *hooks; struct sk_buff *skb = entry->skb; + bool old_in_nf_duplicate; const struct net *net; unsigned int i; int err; u8 pf; + local_bh_disable(); + old_in_nf_duplicate = __this_cpu_read(nf_skb_duplicated); + net = entry->state.net; pf = entry->state.pf; + __this_cpu_write(nf_skb_duplicated, entry->in_nf_duplicate); hooks = nf_hook_entries_head(net, pf, entry->state.hook); i = entry->hook_index; if (WARN_ON_ONCE(!hooks || i >= hooks->num_hook_entries)) { kfree_skb(skb); nf_queue_entry_free(entry); - return; + goto out; } hook_entry = &hooks->hooks[i]; @@ -352,9 +358,7 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) switch (verdict & NF_VERDICT_MASK) { case NF_ACCEPT: case NF_STOP: - local_bh_disable(); entry->state.okfn(entry->state.net, entry->state.sk, skb); - local_bh_enable(); break; case NF_QUEUE: err = nf_queue(skb, &entry->state, i, verdict); @@ -368,5 +372,8 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) } nf_queue_entry_free(entry); +out: + __this_cpu_write(nf_skb_duplicated, old_in_nf_duplicate); + local_bh_enable(); } EXPORT_SYMBOL(nf_reinject); -- 2.53.0