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; 3+ 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] 3+ 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-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, 0 replies; 3+ 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] 3+ 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; 3+ 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] 3+ messages in thread

end of thread, other threads:[~2026-11-24 16:34 UTC | newest]

Thread overview: 3+ 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-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