Netdev List
 help / color / mirror / Atom feed
* [PATCH net v3 0/2] net: do not point a pskb copy's mac header into uninitialised headroom
@ 2026-11-24 16:33 Theodor Arsenij Larionov Trichkine
  2026-11-24 16:33 ` [PATCH net v3 1/2] netfilter: nf_dup: do not duplicate packets from br_netfilter Theodor Arsenij Larionov Trichkine
  2026-11-24 16:33 ` [PATCH net v3 2/2] net: unset the mac header of a pskb copy that points into headroom Theodor Arsenij Larionov Trichkine
  0 siblings, 2 replies; 5+ messages in thread
From: Theodor Arsenij Larionov Trichkine @ 2026-11-24 16:33 UTC (permalink / raw)
  To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, Pablo Neira Ayuso, Florian Westphal, Phil Sutter,
	netdev, netfilter-devel, coreteam,
	Theodor Arsenij Larionov Trichkine

pskb_copy() keeps the mac_header offset but not the headroom, so the mac
header of a copy of a received packet points at uninitialised memory,
which nft dup can hand to userspace. Patch 2 unsets the mac header in
that case, as Florian suggested on v1.

Patch 1 makes nf_dup skip skbs with bridge netfilter info, as Florian
suggested on v2. It fixes a second leak, where a tcp reset reject of
such a copy builds the RST's Ethernet header from the same bytes, and
it has to go in before patch 2, which would otherwise turn that reject
into an out-of-bounds read.

Patch 1 also stops dup for packets that come in on a bridge port and
are then delivered locally or routed, because br_netfilter keeps
SKB_EXT_BRIDGE_NF on the skb until the bridge transmits it. Is that
acceptable, or should nf_dup keep duplicating them and call
skb_ext_del(skb, SKB_EXT_BRIDGE_NF) on the copy?

Found with a custom syzkaller-based fuzzer.

v3: add patch 1; without it, patch 2 turns the tcp reset reject of a
bridged dup copy into an out-of-bounds read in nf_send_reset() and
nf_send_reset6(). Drop the nfnetlink_queue patch, since nothing
produces a bridged copy without a mac header anymore.
v2: fix in __pskb_copy_fclone() instead of nf_dup; add the
nfnetlink_queue patch.
Link to v2: https://lore.kernel.org/netdev/20261117175835.745796-1-theodorlarionov@gmail.com/
v1: https://lore.kernel.org/netfilter-devel/20261116105113.128791-1-theodorlarionov@gmail.com/

Theodor Arsenij Larionov Trichkine (2):
  netfilter: nf_dup: do not duplicate packets from br_netfilter
  net: unset the mac header of a pskb copy that points into headroom

 net/core/skbuff.c                | 2 ++
 net/ipv4/netfilter/nf_dup_ipv4.c | 6 ++++++
 net/ipv6/netfilter/nf_dup_ipv6.c | 6 ++++++
 3 files changed, 14 insertions(+)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net v3 1/2] netfilter: nf_dup: do not duplicate packets from br_netfilter
  2026-11-24 16:33 [PATCH net v3 0/2] net: do not point a pskb copy's mac header into uninitialised headroom Theodor Arsenij Larionov Trichkine
@ 2026-11-24 16:33 ` Theodor Arsenij Larionov Trichkine
  2026-11-26  7:35   ` netdev-bot+sashiko
  2026-11-24 16:33 ` [PATCH net v3 2/2] net: unset the mac header of a pskb copy that points into headroom Theodor Arsenij Larionov Trichkine
  1 sibling, 1 reply; 5+ messages in thread
From: Theodor Arsenij Larionov Trichkine @ 2026-11-24 16:33 UTC (permalink / raw)
  To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, Pablo Neira Ayuso, Florian Westphal, Phil Sutter,
	netdev, netfilter-devel, coreteam,
	Theodor Arsenij Larionov Trichkine

nf_dup_ipv4() and nf_dup_ipv6() copy the skb with pskb_copy(). If the
skb came through br_netfilter, the copy keeps the bridge netfilter info,
and its mac header points into headroom that pskb_copy() did not
initialise.

A tcp reset reject of the copy on LOCAL_OUT then takes the bridge path
in nf_send_reset() or nf_send_reset6() and builds the RST's Ethernet
header from those bytes:

  BUG: KMSAN: kernel-infoleak in _copy_to_iter+0x1c9/0x2650
  ...
  Uninit was stored to memory at:
   eth_header+0xbe/0x150
   nf_send_reset+0x15e4/0x1850
   nft_reject_ipv4_eval+0x1b5/0x2b0

Skip skbs that carry bridge netfilter info. br_netfilter only drops the
info when the bridge transmits the skb, so this also disables dup for
packets that came in on a bridge port and are delivered locally or
routed.

Fixes: affe759dbaa9 ("netfilter: ip[6]t_REJECT: tcp-reset using wrong MAC source if bridged")
Suggested-by: Florian Westphal <fw@strlen.de>
Cc: stable@vger.kernel.org
Signed-off-by: Theodor Arsenij Larionov Trichkine <theodorlarionov@gmail.com>
---
 net/ipv4/netfilter/nf_dup_ipv4.c | 6 ++++++
 net/ipv6/netfilter/nf_dup_ipv6.c | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/net/ipv4/netfilter/nf_dup_ipv4.c b/net/ipv4/netfilter/nf_dup_ipv4.c
index 9a773502f10a..a4ad26a564a4 100644
--- a/net/ipv4/netfilter/nf_dup_ipv4.c
+++ b/net/ipv4/netfilter/nf_dup_ipv4.c
@@ -11,6 +11,7 @@
 #include <linux/route.h>
 #include <linux/skbuff.h>
 #include <linux/netfilter.h>
+#include <linux/netfilter_bridge.h>
 #include <net/checksum.h>
 #include <net/flow.h>
 #include <net/icmp.h>
@@ -53,6 +54,11 @@ void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,
 {
 	struct iphdr *iph;
 
+#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
+	if (nf_bridge_info_exists(skb))
+		return;
+#endif
+
 	local_bh_disable();
 	if (current->in_nf_duplicate)
 		goto out;
diff --git a/net/ipv6/netfilter/nf_dup_ipv6.c b/net/ipv6/netfilter/nf_dup_ipv6.c
index 6da3102b7c1b..ba8243bcd56a 100644
--- a/net/ipv6/netfilter/nf_dup_ipv6.c
+++ b/net/ipv6/netfilter/nf_dup_ipv6.c
@@ -9,6 +9,7 @@
 #include <linux/percpu.h>
 #include <linux/skbuff.h>
 #include <linux/netfilter.h>
+#include <linux/netfilter_bridge.h>
 #include <net/ipv6.h>
 #include <net/ip6_route.h>
 #include <net/netfilter/ipv6/nf_dup_ipv6.h>
@@ -47,6 +48,11 @@ static bool nf_dup_ipv6_route(struct net *net, struct sk_buff *skb,
 void nf_dup_ipv6(struct net *net, struct sk_buff *skb, unsigned int hooknum,
 		 const struct in6_addr *gw, int oif)
 {
+#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
+	if (nf_bridge_info_exists(skb))
+		return;
+#endif
+
 	local_bh_disable();
 	if (current->in_nf_duplicate)
 		goto out;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net v3 2/2] net: unset the mac header of a pskb copy that points into headroom
  2026-11-24 16:33 [PATCH net v3 0/2] net: do not point a pskb copy's mac header into uninitialised headroom Theodor Arsenij Larionov Trichkine
  2026-11-24 16:33 ` [PATCH net v3 1/2] netfilter: nf_dup: do not duplicate packets from br_netfilter Theodor Arsenij Larionov Trichkine
@ 2026-11-24 16:33 ` Theodor Arsenij Larionov Trichkine
  1 sibling, 0 replies; 5+ messages in thread
From: Theodor Arsenij Larionov Trichkine @ 2026-11-24 16:33 UTC (permalink / raw)
  To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, Pablo Neira Ayuso, Florian Westphal, Phil Sutter,
	netdev, netfilter-devel, coreteam,
	Theodor Arsenij Larionov Trichkine

__pskb_copy_fclone() copies the data from skb->data onwards but keeps
the mac_header offset, so if the link-layer header was pulled, the
copy's mac header points into uninitialised headroom. With nft dup, a
link-layer payload load on the copy at LOCAL_OUT or POST_ROUTING reads
those bytes, and a set element hands them to userspace:

  BUG: KMSAN: kernel-infoleak in _copy_to_iter

Unset the mac header in that case. Callers that use the copy's mac
header push the link-layer header before copying, as
maybe_deliver_addr() in the bridge does, so the header is copied and
stays valid.

Depends on "netfilter: nf_dup: do not duplicate packets from
br_netfilter"; without it, a tcp reset reject of a bridged dup copy
reads out of bounds.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Suggested-by: Florian Westphal <fw@strlen.de>
Cc: stable@vger.kernel.org
Signed-off-by: Theodor Arsenij Larionov Trichkine <theodorlarionov@gmail.com>
---
 net/core/skbuff.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 85d5caa08887..e38d0de59e06 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -2278,6 +2278,8 @@ struct sk_buff *__pskb_copy_fclone(struct sk_buff *skb, int headroom,
 	}
 
 	skb_copy_header(n, skb);
+	if (skb_mac_header_was_set(n) && skb_mac_offset(n) < 0)
+		skb_unset_mac_header(n);
 out:
 	return n;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net v3 1/2] netfilter: nf_dup: do not duplicate packets from br_netfilter
  2026-11-24 16:33 ` [PATCH net v3 1/2] netfilter: nf_dup: do not duplicate packets from br_netfilter Theodor Arsenij Larionov Trichkine
@ 2026-11-26  7:35   ` netdev-bot+sashiko
  2026-11-26  7:47     ` Florian Westphal
  0 siblings, 1 reply; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-26  7:35 UTC (permalink / raw)
  To: theodorlarionov
  Cc: davem, edumazet, kuba, pabeni, horms, pablo, fw, phil, netdev,
	netfilter-devel, coreteam

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] nf_dup_ipv4() and nf_dup_ipv6() now return early, doing
  nothing, for every skb that carries SKB_EXT_BRIDGE_NF.

--

netfilter: nf_dup: do not duplicate packets from br_netfilter

This commit makes nf_dup_ipv4() and nf_dup_ipv6() return early when the
skb carries bridge netfilter info. It does this to avoid a KMSAN infoleak.
The leak happens when a tcp reset reject of the pskb_copy() duplicate takes
the bridge path in nf_send_reset() or nf_send_reset6() and builds the
Ethernet header from uninitialised headroom.

> diff --git a/net/ipv4/netfilter/nf_dup_ipv4.c b/net/ipv4/netfilter/nf_dup_ipv4.c
> index 9a773502f10ac..a4ad26a564a46 100644
> --- a/net/ipv4/netfilter/nf_dup_ipv4.c
> +++ b/net/ipv4/netfilter/nf_dup_ipv4.c

[ ... ]

> @@ -53,6 +54,11 @@ void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,
>  {
>  	struct iphdr *iph;
>  
> +#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
> +	if (nf_bridge_info_exists(skb))
> +		return;
> +#endif
> +

[Severity: Medium]
Does this turn off TEE and nft dup completely for any packet that has
passed through br_netfilter?

The check runs on the original skb before pskb_copy(). With
bridge-nf-call-iptables or bridge-nf-call-ip6tables enabled, a rule like
this one no longer sends any copy:

  iptables -t mangle -A PREROUTING -m physdev --physdev-in X \
           -j TEE --gateway G

The same applies to packets that enter on a bridge port and are then routed
or delivered locally. That is common on container and VM hosts.

Nothing reports the skip. Both functions return void, and the xt_TEE
callers always continue:

net/netfilter/xt_TEE.c:tee_tg4() {
	...
	nf_dup_ipv4(xt_net(par), skb, xt_hooknum(par), &info->gw.in, oif);

	return XT_CONTINUE;
}

So the rule still matches and its counters still go up, but no copy is
sent. Because of Cc: stable, this change would also reach stable trees.

The commit message mentions the routed and local delivery side effect. It
does not say that mirroring of bridged traffic stops completely.

Would it work to remove the extension from the copy instead? For example,
call skb_ext_del() with SKB_EXT_BRIDGE_NF on the new skb right after
pskb_copy().

nf_dup_ipv4_route() gives the duplicate its own dst and dev, and
ip_local_out() sends it, so the bridge info it inherits is stale. Both
reject paths choose the bridge path only by checking for the extension:

net/ipv4/netfilter/nf_reject_ipv4.c:nf_send_reset() {
	...
	if (nf_bridge_info_exists(oldskb)) {
		struct ethhdr *oeth = eth_hdr(oldskb);
	...
}

nf_send_reset6() has the same check.

Without the extension, a reject of the copy would go down the normal
ip_local_out() or ip6_local_out() path. Physdev and other bridge info users
would also stop seeing the original's ports on the copy. Dup would keep
working for bridged traffic.

The later patch in this series, "net: unset the mac header of a pskb copy
that points into headroom", relies on this skip to avoid an out-of-bounds
eth_hdr() read in the reject bridge path. Would removing the extension from
the copy also meet that need?

The same question applies to the identical check added to nf_dup_ipv6().

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124163358.755345-1-theodorlarionov%40gmail.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net v3 1/2] netfilter: nf_dup: do not duplicate packets from br_netfilter
  2026-11-26  7:35   ` netdev-bot+sashiko
@ 2026-11-26  7:47     ` Florian Westphal
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Westphal @ 2026-11-26  7:47 UTC (permalink / raw)
  To: netdev-bot+sashiko
  Cc: theodorlarionov, davem, edumazet, kuba, pabeni, horms, pablo,
	phil, netdev, netfilter-devel, coreteam

netdev-bot+sashiko@kernel.org <netdev-bot+sashiko@kernel.org> wrote:
> [Severity: Medium]
> Does this turn off TEE and nft dup completely for any packet that has
> passed through br_netfilter?
> 
> The check runs on the original skb before pskb_copy(). With
> bridge-nf-call-iptables or bridge-nf-call-ip6tables enabled, a rule like
> this one no longer sends any copy:
> 
>   iptables -t mangle -A PREROUTING -m physdev --physdev-in X \
>            -j TEE --gateway G

AI is right BUT I think this 'breakage' is good.
We should absolutely start to break these use cases, little by little.

I intend to remove nfqueue support for br_netfilter, for instance.
I hope we can remove the entire br_netfilter module by summer 2027.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-26  7:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 16:33 [PATCH net v3 0/2] net: do not point a pskb copy's mac header into uninitialised headroom Theodor Arsenij Larionov Trichkine
2026-11-24 16:33 ` [PATCH net v3 1/2] netfilter: nf_dup: do not duplicate packets from br_netfilter Theodor Arsenij Larionov Trichkine
2026-11-26  7:35   ` netdev-bot+sashiko
2026-11-26  7:47     ` Florian Westphal
2026-11-24 16:33 ` [PATCH net v3 2/2] net: unset the mac header of a pskb copy that points into headroom Theodor Arsenij Larionov Trichkine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox