[PATCH net v2 2/2] net: unset the mac header of a pskb copy that points into headroom

From
Theodor Arsenij Larionov Trichkine <hidden>
Date
2026-11-17 17:59:00
Also in
netfilter-devel
Reply to
Theodor Arsenij Larionov Trichkine, 2026-11-17
__pskb_copy_fclone() copies the data from skb->data onwards, while
skb_copy_header() keeps the mac_header offset. When the link-layer
header was pulled, the copy's mac header points into uninitialised
headroom. nft dup is one such caller: a link-layer payload read of the
duplicated packet on LOCAL_OUT or POST_ROUTING loads those bytes, and a
set element returns them to userspace:

  BUG: KMSAN: kernel-infoleak in _copy_to_iter

Unset the mac header of the copy in that case. Callers that need it,
such as the bridge, push the link-layer header before copying.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Suggested-by: Florian Westphal <fw@strlen.de>
Cc: <redacted>
Signed-off-by: Theodor Arsenij Larionov Trichkine <redacted>
---
 net/core/skbuff.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 1ac1e327ac4c..7f6d0344efa6 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
Thread (4 messages) 4 messages, 2 authors, last reply 1d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help