๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #11013

Re: [PATCH net 07/15] netfilter: nf_dup: preserve guard across NFQUEUE reinjection

#11013
From: netdev-bot+sashiko
Date: Wed, 04 Nov 2026 14:29
129 lines
12376 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message for "netfilter: nf_dup: preserve guard across
  NFQUEUE reinjection" leaves out a behaviour change.
- [Low] The patch has Cc: stable@vger.kernel.org and Fixes: cd58bcd9787e
  (2010, xt_TEE), but it reads and writes current->in_nf_duplicate.

--

netfilter: nf_dup: preserve guard across NFQUEUE reinjection

This patch saves current->in_nf_duplicate in struct nf_queue_entry when
a packet is queued. nf_reinject() then restores it while hook traversal
resumes after a verdict, and puts back the verdict task's previous value
on exit. BH is now disabled for the whole of nf_reinject().

> Fixes: cd58bcd9787e ("netfilter: xt_TEE: have cloned packet travel through Xtables too")
> Cc: stable@vger.kernel.org

[Severity: Low]

Will this apply to the stable trees that this Fixes tag covers?

__nf_queue() and nf_reinject() read and write current->in_nf_duplicate.
That task_struct bit was only added by:

a1f1acb9c5db ("netfilter: nf_dup{4, 6}: Move duplication check to task_struct")

Older stable trees covered by the 2010 Fixes tag, such as 6.12, 6.6, 6.1,
5.15 and 5.10, still use the per-CPU nf_skb_duplicated guard. That flag
is also cleared after ip_local_out() returns, so the same bug seems to
exist there. This patch won't build against those trees, though.

Could a dependency note or backport hint be added? That would make it
clear those trees need a version that saves and restores the per-CPU
flag instead.

> diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
> index 90d887546f7db..a8aa7ad832c3f 100644
> --- a/net/netfilter/nfnetlink_queue.c
> +++ b/net/netfilter/nfnetlink_queue.c

[ ... ]

> @@ -365,21 +366,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;
> +

[ ... ]

> @@ -402,9 +412,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;

[ ... ]

> @@ -418,6 +426,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();
>  }

[Severity: Low]

This isn't a bug, but the commit message doesn't mention that the
BH-disabled region in nf_reinject() is now much wider.

Before this patch, local_bh_disable() and local_bh_enable() only wrapped
entry->state.okfn() in the NF_ACCEPT and NF_STOP case. Now every
reinjected NFQUEUE packet runs with BH disabled, duplicated or not. That
covers the NF_REPEAT hookfn re-run, nf_reroute(), nf_iterate() and the
nf_queue() re-queue path.

The change looks needed, because a softirq running on the current task
must not see the guard while it is set. Could the commit message say so
and explain why?

The message also only says that the guard is cleared:

  "The output call then returns and clears the guard before a later
  verdict resumes hook traversal."

It doesn't describe what users see. nf_dup_ipv4() clears the guard
unconditionally after the output call, and nf_dup_ipv6() does the same:

net/ipv4/netfilter/nf_dup_ipv4.c:nf_dup_ipv4() {
    ...
	if (nf_dup_ipv4_route(net, skb, gw, oif)) {
		current->in_nf_duplicate = true;
		ip_local_out(net, skb->sk, skb);
		current->in_nf_duplicate = false;
    ...
}

Say the duplicate is queued in LOCAL_OUT or POSTROUTING and reinjected
later. A TEE or nft dup rule further along then duplicates it again. That
new copy can be queued again, so each verdict makes another copy.

Could the changelog describe this behaviour?

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103140308.591690-3-pablo%40netfilter.org
Technical Details
Message-ID: <179380256596.488856.13512803385415062400@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356504-linux-kernel-netdev=dewy.ru
References: <20261103140308.591690-9-pablo@netfilter.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356504-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 07/15] netfilter: nf_dup: preserve guard across
 NFQUEUE reinjection
Date: Wed, 04 Nov 2026 14:29:25 +0000
Organization: Usenet Network
Message-ID: <179380256596.488856.13512803385415062400@kernel.org>
References: <20261103140308.591690-9-pablo@netfilter.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3410675"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:u08onGOWKrRf+NwKjz/lE65ZuWU= sha256:DOtaGR/H12vZOBt5zmigyG1t2QNP9p4sDZiRHb1c+Vk=
	sha1:Ks27WoC86c09tkL+WJK5WxOqXqU= sha256:eI+v3bWiiBCOTIiU7ZzHDYP9CSwrY0ZqZ94Fs1hEmQY=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id D2D91112C12; Wed,  4 Nov 2026 17:40:51 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id jsuET7BuOpLm;
	Wed,  4 Nov 2026 17:40:47 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-356504-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 2238D112C08; Wed,  4 Nov 2026 17:40:36 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 1963F3B990; Wed,  4 Nov 2026 14:29:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793802573;
	b=mqUiziN/EgdKq9JAkJJqU5l49z6OuW4MfpSX4IlSNE0JcmSV1mR/NJK204Oqt+503TQk
	 QEemSwt857376IpCJlQtJhUB9Wph9bGnhiJCRMvln8wAkYA0skK6yvvYII/Vz6qaYevrx
	 fwAjHDmykiBrVLCrPW0OHgCN3s2YBu9THgt6u650uqKeaS4Yne7bZ/oP30wtwoOpPGT/x
	 x2EXXtohmlAU0r11V1nis5mn/ZsmWLkD5jav2z9d5YtQjkjXCIbZVPaksOhnwsQtYrlAS
	 AGc1hmudsGWFQy92lnwDPc/icWC/9GZyqZhEFhYH32+io2H8zEx9df38cZEvxZ57dWw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793802573;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=Xz3sb8BWuunlpYCoTGvQBeihdIazj1yMmpL1EBO9/qs=;
	b=iqWMJduAeXh8SZgMFN4RP0bC4GMPOfSEc8qk3pukOZA+ItzhI2e71khbTW/NEAHxRSaY
	 BrcfQmYYtcqLnCsucNLNO9/dZI4lMhh0Uy927yRQD/DFkOdfHCbnaWja+O5HD6GIQb2jO
	 1VXN0CbS3adJs2uDJOx/QLFnE6QBIESYLZuIGUwLol0afuyw1JOqmS8CQxcorhvDrOVeO
	 Ch5B7Ejk19QIP7gWXha3ukarbUgQC1oNJbXorfE1wnJfghyw+BsKMPB1ogfM9dkhw4pS0
	 9Pcar4sZFVUXAVsyPm+3j353yqF8IIx5674bUkMWDshgLoB1VFcnBFyIg1nf8dUHY/g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gRS1rRHN;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 31FB4606A338;
	Wed,  4 Nov 2026 14:29:33 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gRS1rRHN
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793802567;
	b=1akcyFNC31iCruTVTHd5/WA9NKtn/j+ZxW47Lv3u+3rMqoZgI1WsJypujtG2Fnrp/Q7z
	 AJZ5M+0p/g+t2y9Gz4Q4zgY6DmT1Eii7CdtrzbMt7trSQXTtfCQvnFDVtEKUUBAy3jFyK
	 kDBiRIUmmWPOA2oUFm8xZhMJF9DKd8sAIXl/ftcJ+r+3kirUd+rbpAANG3ZcajDqWQP6J
	 2Chx8DfqVn2HhEa0o31jvtTak5HEfZbvBrPfBsDlC7qX78rE5V1Jbg/7MOdALyJvqbflf
	 AId7xPj91Sv/BbZ5PGaLfPjrM8uzHDpvwtsalSLnXD+/l/f884ocuXCQnLEGZAonyjw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793802567;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=Xz3sb8BWuunlpYCoTGvQBeihdIazj1yMmpL1EBO9/qs=;
	b=4DJ3vRsAbN2DaDmrsWJLn+LmDAlbK3E95Mcp9TdSbfcspdeSg+LZ3qWyAa1eaa1KTMQd
	 6XMkz2VENTh0S2JeYrqseaOyozm/YO5q1v9G+MCf5GcVHECl9JWPE9YCdROMaBJPPMeph
	 RniEmJ2/lsCXxYRe3GBlBh6E5sH2ULRGo7haHJourXlUyOYxZxMMxjvnZY4w8vm0ugoh5
	 Fab/OHG7sgime9t6dwVApsFVmI0NPDIMqlnsVAKJ6VisQx+eWVDh7jvOnxWufnphCQp+l
	 tO//NR6bS9QgcDk8NHs9Rq0p5fA+kz4keNCTSo34Lvf7DKb+CVx7m/JFfuq4ZDs/7gA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gRS1rRHN;
	arc=none smtp.remote-ip=100.103.45.18
X-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 105AC606A330;
	Wed,  4 Nov 2026 14:29:27 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6266B1F000C1;
	Wed,  4 Nov 2026 14:29:26 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793802566;
	bh=Xz3sb8BWuunlpYCoTGvQBeihdIazj1yMmpL1EBO9/qs=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=gRS1rRHNHRSJsts9JvGgJWF3hWpHvNoZuaISWb7KKCRXoc3M+ntSHJBgiKkAtdttR
	 y4wbhvzvQM8qTcWSI6ugqeLKZoS0OCIuFRIK/aHS+MZBA0fsnruwQN/CG6X+lS8ZRy
	 ZCHY1lXMRec+WCeL1uT/mi4d+Aejz8YCSDiqxf8GWO9JuEnUDXZQyAMrkKV6pXtIoC
	 lyxFNqAbUlEzkciJtQR08COMSJlD0r8ExWZley6pOq37uAOEMhbd9SWNDM0qenb2HX
	 +B2Ce1NGd65XXbKOmAXclPICYTsLYKMDyuA+ieGzZfsLPCZIXRbMToGPf3o2S2sFfh
	 uI6hEYbJWdauQ==
X-Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
 netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
 edumazet@kernel.org, horms@kernel.org, fw@strlen.de, ja@ssi.bg
X-In-Reply-To: <20261103140308.591690-9-pablo@netfilter.org>
X-sashiko-severity: Low
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list