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=1796386027; b=z4KLFLtqDHmgS9fiqD3vaDddaLtnfMiPDWdR2I2Fuxh16IeN1+DT8gFQCq1ay5wjLTeM afU3A8Yv4ZoorzwweyfmOaBgDO5EQh1OEQoIfVXfU3C1LoB1f7Hzd0Cu9zQgZToSYVDMJ U2pTzygrFJqg3PVJ+fvm4xd7Il95KphZhskWPC5uh5CjRV0c6HQ88rQzylH+cDqBp5UuT /QYCmPcscueBzTZRXf96en1dyCgxEVEwwDXaCWV9J9Zd0+O6yjSnA1PsXQuvfNyIv4zrl Tyzv7J2Kk7jrcOhyjp08hD5aHOy1B51Vmjn1NMJJkETxSi4rGh6OUEtcMXpfPZ5AFBA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386027; 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=B/2T8XO8bPgFxs5zOlDXbcuQYRpnz24Hy+wVYQ8Q3Fk=; b=y2Q+g4A8pOlWvuF3Ghkz2Rq+Mj+LDlYqgx4RYpvHBHvGHS4sz2laOmWArw/IDTOL7FQk Eg6Fuj6GIGAx5VndfBNOI01fBYhFlCOAVI734lQwO95Y2NePmfw+dD0a/1lwVznqRADrK RWakyWN/c+o2gvrA19DWzklorATgUfdhgyOTwfhj7Lyq4TpBoQw2pycg8GhWwqZtyZYeH MUx4rA0iVd1M5Z8ILHs1y/l56KUfKTqfT0Z6/agHC0nuUMuA8cWpBeak6BSaXCvau90ZP N+9JlKdEVQmFrsKDbxopY8c9CkKezouAL3wmL1gOIIe7bq8xwaGlMDh1ObXY+pDqe3Q== 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=EPaYxHZF; 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 B1E08606A322; Fri, 4 Dec 2026 12:07:07 +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=EPaYxHZF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29A5F1F000C2; Fri, 4 Dec 2026 12:07:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386027; bh=B/2T8XO8bPgFxs5zOlDXbcuQYRpnz24Hy+wVYQ8Q3Fk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EPaYxHZFonHKjYcTWE1ju1et1FfKwFG42sH+vVDoD9YRkgj25kv78RK/yMgJnez2W sHfObHA1oIPcKWgwKnebQKXnp0bO8bz6jGMDbwAesn4AFjBTbeQiYSZPbENXpmlqmA sotr5Jd71FhwDVG5Tx41Svk2rjsESuhrEJzwkMNs= 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.6 0794/1167] netfilter: nf_dup: preserve guard across NFQUEUE reinjection Date: Fri, 4 Dec 2026 19:03:41 +0900 Message-ID: <20261204100722.805734996@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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: Replaced the task flag current->in_nf_duplicate with the per-CPU nf_skb_duplicated and moved the nf_reinject() change into nf_queue.c, dropping the DEBUG_NET_WARN_ONCE check. ] 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