Netdev List
 help / color / mirror / Atom feed
From: willemb@google.com
To: Theodor Arsenij Larionov Trichkine <theodorlarionov@gmail.com>,
	"David S . Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
	Pablo Neira Ayuso <pablo@netfilter.org>,
	 Florian Westphal <fw@strlen.de>, Phil Sutter <phil@nwl.cc>,
	netdev@vger.kernel.org,  netfilter-devel@vger.kernel.org,
	coreteam@netfilter.org,
	 Theodor Arsenij Larionov Trichkine <theodorlarionov@gmail.com>
Subject: Re: [PATCH net v3 2/2] net: unset the mac header of a pskb copy that points into headroom
Date: Mon, 30 Nov 2026 21:32:01 -0500	[thread overview]
Message-ID: <willemb.16c5ebb9e573d@google.com> (raw)
In-Reply-To: <20261124163358.755345-3-theodorlarionov@gmail.com>

Theodor Arsenij Larionov Trichkine wrote:
> __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);

     skb_copy_header() copies skb->mac_header verbatim without adjusting for
     (headroom - skb_headroom(skb)). If a caller invokes __pskb_copy() with
     headroom < skb_headroom(skb) on an skb whose MAC header was pulled into
     headroom (skb_mac_offset(skb) < 0), skb_mac_offset(n) = skb->mac_header
     - headroom can be >= 0, leaving n->mac_header set and pointing at an
     arbitrary offset inside n->data (or even past n->tail/n->end).

     Checking (skb_mac_offset(skb) < 0 || skb_mac_offset(n) < 0) handles both
     cases: it unsets mac_header whenever the source MAC header was not
     copied (skb_mac_offset(skb) < 0) as well as when a larger headroom
     leaves the unadjusted offset in n's headroom (skb_mac_offset(n) < 0).

>   out:
>   	return n;
>   }
> --
> 2.34.1




      reply	other threads:[~2026-12-01  2:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-12-01  2:25       ` willemb
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
2026-12-01  2:32   ` willemb [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=willemb.16c5ebb9e573d@google.com \
    --to=willemb@google.com \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=phil@nwl.cc \
    --cc=theodorlarionov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox