🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #12420

Re: [PATCH] netfilter: br_netfilter: reject unsafe neighbour devices for DNAT

#12420
From: Florian Westphal
Date: Sat, 07 Nov 2026 07:25
79 lines
10295 bytes
Kyle Zeng <kylebot@openai.com> wrote:
> The IPv4 and IPv6 bridge prerouting callbacks classify DNAT traffic using
> the logical input device saved in skb->dev. The physical input port can
> have a different bridge master when prerouting resumes, for example after
> an NFQUEUE verdict. Netfilter reassembly can also combine the first
> fragment's bridge information with a different fragment's input device.
> 
> br_nf_pre_routing_finish_bridge() replaces skb->dev with the port's
> current bridge master, but looks up the neighbour using the existing
> route. This can put an skb with skb->dev pointing to bridge B on an
> unresolved neighbour of bridge A. Deleting B and resolving the neighbour
> on A then causes a use-after-free in __dev_queue_xmit().
> 
> Before calling the neighbour output method, check that the neighbour
> keeps skb->dev alive. A neighbour holds its device, and a VLAN device
> also holds its real device, so allow a VLAN whose real device is the
> bridge. Release the neighbour and drop the skb on a mismatch.
> 
> Doing this in the shared continuation covers both protocol families,
> including a queue in the remaining bridge prerouting hooks. Leave the
> cached-header path unchanged since it does not enqueue the skb.
> 
> Signed-off-by: Kyle Zeng <kylebot@openai.com>
> ---
> I have a reproducer for this issue and can share via DM
> 
>  net/bridge/br_netfilter_hooks.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hooks.c
> index e15355ff215a..726a2d17ed3a 100644
> --- a/net/bridge/br_netfilter_hooks.c
> +++ b/net/bridge/br_netfilter_hooks.c
> @@ -307,6 +307,18 @@ int br_nf_pre_routing_finish_bridge(struct net *net, struct sock *sk, struct sk_
>  
>  			ret = br_handle_frame_finish(net, sk, skb);
>  		} else {
> +			struct net_device *dev = neigh->dev;
> +
> +			/* The neighbour queue must keep skb->dev alive. A VLAN
> +			 * device also holds a reference to its real device.
> +			 */
> +			if (is_vlan_dev(dev))
> +				dev = vlan_dev_real_dev(dev);
> +			if (dev != skb->dev) {
> +				neigh_release(neigh);
> +				goto free_skb;
> +			}
> +

I don't understand the vlan check. Why is that needed?
The call to br_nf_pre_routing_finish_bridge is gated via:

 405                         if (skb_dst(skb)->dev == dev) {
 406                                 skb->dev = br_indev;
 407                                 nf_bridge_update_protocol(skb);
 408                                 nf_bridge_push_encap_header(skb);
 409                                 br_nf_hook_thresh(NF_BR_PRE_ROUTING,
 410                                                   net, sk, skb, skb->dev,
 411                                                   NULL,
 412                                                   br_nf_pre_routing_finish_bridge);


... so this patch ought to be sufficient?

--- a/net/bridge/br_netfilter_hooks.c
+++ b/net/bridge/br_netfilter_hooks.c
@@ -283,6 +283,10 @@ int br_nf_pre_routing_finish_bridge(struct net *net, struct sock *sk, struct sk_
        if (!skb->dev)
                goto free_skb;
        dst = skb_dst(skb);
+
+       if (dst->dev != skb->dev)
+               goto free_skb;
+
        neigh = dst_neigh_lookup_skb(dst, skb);

(I can't see how neigh->dev != skb->dev after the extra test).
Technical Details
Message-ID: <au7SdYQrIqAQOU24@strlen.de>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358317-linux-kernel-netdev=dewy.ru
References: <20261030042155.73844-1-kylebot@openai.com>

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-358317-linux-kernel-netdev=dewy.ru
From: fw@strlen.de (Florian Westphal)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] netfilter: br_netfilter: reject unsafe neighbour devices
 for DNAT
Date: Sat, 7 Nov 2026 08:25:41 +0100
Organization: Usenet Network
Message-ID: <au7SdYQrIqAQOU24@strlen.de>
References: <20261030042155.73844-1-kylebot@openai.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="4057684"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:VeN+1gqJGb+8a304kZ05/ChQ7BI= sha256:bm6j/QUG/GQJB5b+jkAs8sKGVwXHxwIYLvHwGj5vl9I=
	sha1:YvqdvDacXH+m75wiaga0AX3yYIs= sha256:mVSz2pivfEh4+8ZVY1mfm3OmB+ADU/x0uibNNBSiykY=
Content-Disposition: inline
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 CEA4E112E3D; Sat,  7 Nov 2026 10:27:07 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.051
X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31
	tests=[HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
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 ExD0utF7EQ9q;
	Sat,  7 Nov 2026 10:26:56 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-358317-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=strlen.de
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 284B111332B; Sat,  7 Nov 2026 10:26:50 +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 5522D3A48C; Sat,  7 Nov 2026 07:26:05 +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=1794036365;
	b=riaj4p4Z4ZrwQQZx+oS68+Kb8+ce2PTcjSJdl3QcW2DfEXBqFWqetkHznguvx/3mFRCw
	 NRqkALuxvUCxUbu+XNAvbM60KkZB7lk2Vw+6euhw9qvGoL2tuPusBMgPQE2i2qlwGohup
	 +o508J8MDKKwjby3rE/yFV7d2Ug0XuLpqNqYwQhaQcDlwHeg13dskNMaB3LAUAzne2xLp
	 ogEdghR6KBZHmr2GftEqryKuM+b2Nkz36gV8R3zi/2IG8gHE8dZgn/dIfpKogN+ESypWT
	 aW3FzmEHvK5cSMw1CEbMFd1sJmQjfgf5RNqlsN3Q3oW2sYAkG6bHk+DcOSozgJ3HaJQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794036365;
	h=X-Original-To:Received:DMARC-Filter:Received:Date:From:To:Cc:Subject:
	 Message-ID:References:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To;
	bh=SNDereXwlb4/dZxRH96h3UJKC884sqCQjQ+XSkDhBBk=;
	b=4rhSBSfmDMGJhI1XOG2J5FSxUEIzP2S46pg6FQko71xU6IaLZ44YRY9da1ZbHcMPJPjR
	 9JD/gZHi0xctxMj1qLRaXTsV8AZ59/cwYVz8FxLGNdEJgOR0r/0WFX/XwCowO8oRg+vK+
	 rkF3FOLzUMQdSlBpJVFpmf5nrB+KLjkJ2dhD3KEosCaAKqTSddC6sNY1rmm0vKjujO7jl
	 /0His0iPhuKc7KvIm52GQnobvxOdKenqFyD5DPUaDghs4LDiy9kn+12tF8Drih/GzA66+
	 1NFsP7jjEfxg8FMhtMkIDAo/EBceHIOkrMuxopIZLbCiojI/4idaipd4T9K3kKimMew==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dmarc=none header.from=strlen.de;
	spf=pass smtp.mailfrom=strlen.de;
	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 27E72606A32C;
	Sat,  7 Nov 2026 07:26:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.216.245.30
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794036349;
	b=sfbsffnQCLM0DfWi/WFBhEShY2twnucDRYYZAzB2BBintestRbZTCorbDwBs5kQdOH8A
	 yaNlSEjFYLrIbv/2LoWZLQJIWDJ8cFqDXdXGCr4/LMXB43J9dXMb+Zs+XGTx/aBtyEXNC
	 e9oSrVXmm4EFw4auvm6PumqLFs328ns+WbqZFSbicdJr7jTrWdNq6pL42+zcpEa5vfZyi
	 owyl2kKBHqRt85ui8P5vev+xtgGyBxK5c1uxK7li85zaC/5iRK0c8fvtFQGkH7aw/b5HC
	 LigMbbhkOxD6A6Jbp4uvSkbi/H2dVtjS+AdekkFEdWfqg94xFX653rxOj5EdbrCeQ8A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794036349;
	h=DMARC-Filter:Received:Date:From:To:Cc:Subject:Message-ID:References:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=SNDereXwlb4/dZxRH96h3UJKC884sqCQjQ+XSkDhBBk=;
	b=X6ZOVjjJVXDeUNYrPdSlb2MK29PSTjLPj5mJDDNk5kzpqL+tDeOboI0qKGOUTMzSiMGh
	 /c0D8NKrnUazM132JMxUjm9vMcEWxkOiLlbb9X2w0nidMhx0yurCC8nEBKF4y6wJTJhR+
	 yehU38sbTzXB4+JifuVUfhXVyBwFwCpT7W2Prfh/btepoK2NmabJenuR4wqYlBWsiUYpZ
	 d5U6CdvJX15pxVhCbcWu0KaPcrZprnjlWlBwSSR+YJci5K6Nc62w15/MmWbWbK5OPHWVA
	 cM8cDa5aBZl0sl8RLofKeBPJcr6K7Fyq3K538rTvCUZkbb7fzJ/bAcEuRMzHgjDbluQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=strlen.de;
	spf=pass smtp.mailfrom=strlen.de;
	arc=none smtp.remote-ip=91.216.245.30
X-Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [91.216.245.30])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 208D2606A326;
	Sat,  7 Nov 2026 07:25:47 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 208D2606A326
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=strlen.de
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=strlen.de
X-Received: by Chamillionaire.breakpoint.cc (Postfix, from userid 1003)
	id ACFA2604DD; Sat, 07 Nov 2026 08:25:45 +0100 (CET)
X-Cc: netfilter-devel@vger.kernel.org,
	Pablo Neira Ayuso <pablo@netfilter.org>, coreteam@netfilter.org,
	bridge@lists.linux.dev, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, outbounddisclosures@openai.com
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
X-In-Reply-To: <20261030042155.73844-1-kylebot@openai.com>