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=1796383222; b=2VE7vU5hXQhNcQAdUVwsh95YAnumXGzYkdUiM58MgODq4onkqzgq6LyL2wCyrxhCNN4u qY6CXjNAHrHXqeNzCkJ+pbAaoKGRtEDAGu/KrbMrB2NYdFQLuI5YbAp8zBadEf+tt9q6F aCQPT3n5B3iuHWidbzHYbaDs24EyfDS96dvPxDd/0pd/QewOw0sguLXMEzUvC1tuPvnoM 3dIZn4LqfSkxhelq29h9RImZw8XcJ2f9kqCbq/6DMRmZ2HQLeguDdAvxZ5Au1TQ7g3vjg O7NigshjGs83KJRt/Lz7uqKHcji4tw5t5bg0kJlHJWHunq/3Lqo33iaNXUmGCkUkA5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383222; 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=j4Ty6KSK+JQl/lIzdrSZkH8sXuY+8LwaO91LnWR9gQI=; b=QmKwwjs8L8la842rpp/6E4tdQsfGOpax6mFDA8kFu4LfHdwELmQ2Gv/JQd8d9QuEaLFa WJRETNAw5wmJpcOxV8s8ubi+1C/zfVfvxEq8cCwjsPkuTG7fE6whQnUvsixdAmgiK37NZ 1gYHaoy3+1tp208cXMrPNoTDAvv01VH/eJ2wTflYrS1+9k1p/P7w3AEdJ+TFIWSC6J58F UJLGmrcfSz8R03slZ1zYj4tULJh1b+T4PPcah/EUJeENUO9xmEcZKouoMvDly764+KhF0 7FL6X6/wbdZo7dlo41i8F4UGwinf+fVIkjgs/qXISTI9rYSvZ8DGIi9073JJVJqGbJw== 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=IKoLS42Q; 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 6952C606A322; Fri, 4 Dec 2026 11:20:22 +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=IKoLS42Q Received: by smtp.kernel.org (Postfix) with ESMTPSA id D18AF1F00897; Fri, 4 Dec 2026 11:20:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383222; bh=j4Ty6KSK+JQl/lIzdrSZkH8sXuY+8LwaO91LnWR9gQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IKoLS42QR72AKqzdvkcSYqtHNRGmW7UH3365W81EkQystomMeVz9xCY0cseMsDwTJ i7G/i4Q6zRxsF6fQQ7lY3xpMGUvdYvlGmUo4CbLTUNATr8+PI954rJlvGa+8bdxgl/ 0TqA9OJ5e2HKYBSqJVEl8v6YUnXKRrtll3XdeAeI= 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.12 093/555] netfilter: nf_dup: preserve guard across NFQUEUE reinjection Date: Fri, 4 Dec 2026 19:02:16 +0900 Message-ID: <20261204100610.767676440@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-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 Signed-off-by: Sasha Levin --- include/net/netfilter/nf_queue.h | 1 + net/netfilter/nf_queue.c | 1 + net/netfilter/nfnetlink_queue.c | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h index fc3e81c07364f..039622d489051 100644 --- a/include/net/netfilter/nf_queue.h +++ b/include/net/netfilter/nf_queue.h @@ -23,6 +23,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 c0c9ea5fc4e19..e25966a09fe31 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 = current->in_nf_duplicate, .state = *state, .hook_index = index, .size = sizeof(*entry) + route_key_size, diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 5d10a85a2f73d..1d827858155f9 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -344,21 +345,30 @@ static 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; + DEBUG_NET_WARN_ONCE(current->in_nf_duplicate && + !entry->in_nf_duplicate, + "%s called with unexpected duplication guard", + __func__); + local_bh_disable(); + old_in_nf_duplicate = current->in_nf_duplicate; + net = entry->state.net; pf = entry->state.pf; + current->in_nf_duplicate = entry->in_nf_duplicate; hooks = nf_hook_entries_head(net, pf, entry->state.hook); i = entry->hook_index; if (!hooks || i >= hooks->num_hook_entries) { kfree_skb_reason(skb, SKB_DROP_REASON_NETFILTER_DROP); nf_queue_entry_free(entry); - return; + goto out; } hook_entry = &hooks->hooks[i]; @@ -381,9 +391,7 @@ static 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); @@ -397,6 +405,9 @@ static void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) } nf_queue_entry_free(entry); +out: + current->in_nf_duplicate = old_in_nf_duplicate; + local_bh_enable(); } /* return true if the entry has an unconfirmed conntrack attached that isn't owned by us -- 2.53.0