Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: piyus@iiitd.ac.in
Cc: steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
	davem@davemloft.net, andrea.mayer@uniroma2.it,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	horms@kernel.org, netdev@vger.kernel.org, ipsec@lists.linux.dev,
	linux-kernel@vger.kernel.org, kapil@presceralabs.ai
Subject: Re: [PATCH] xfrm: do not write the ethernet header when the mac header is unset
Date: Thu, 19 Nov 2026 11:47:39 +0000	[thread overview]
Message-ID: <179508885903.3136.15048597271351937392@kernel.org> (raw)
In-Reply-To: <20261116174531.2540348-2-piyus@iiitd.ac.in>

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

Critical: 0 · High: 1 (1) · Medium: 1 · Low: 2

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).

- [High] The fix is incomplete.
- [Medium] The patch guards consumers instead of fixing the producer of
  the bad skb state.
- [Low] The patch fixes a KASAN-confirmed slab out-of-bounds write but
  has no Fixes: tag and no Cc: stable.
- [Low] The Signed-off-by chain doesn't match the authorship.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is a
  related mac-header bug in the same IP-TFS decap function.

--

xfrm: do not write the ethernet header when the mac header is unset

This patch adds a skb_mac_header_was_set() check before the eth_hdr()
h_proto store in xfrm4_remove_tunnel_encap() and
xfrm6_remove_tunnel_encap(). It addresses a two byte out-of-bounds write at
skb->head + 0xffff + 12 when an skb arrives with an unset mac header and a
stale mac_len, as produced by end_dt_vrf_rcv() on the SRv6 End.DT4/End.DT6
receive path.

> Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
> Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>

[Severity: Low]
The From: author is Piyus Kedia, but the first Signed-off-by is Kapil
Vaswani, and there is no Co-developed-by: tag.

Documentation/process/submitting-patches.rst says the first SoB signals
primary authorship. It also says co-authors other than the From: author
need a Co-developed-by: tag, followed immediately by their Signed-off-by:.

If Kapil Vaswani co-developed this patch, is a Co-developed-by: line
missing? If not, should the SoB order change?

> checkpatch reports one thing, the missing Fixes: tag.  Neither tree we
> reproduced on carries history for the file, so we could not determine the
> introducing commit; we will add the tag if you can name it.

[Severity: Low]
In mainline, blame on the lines changed here points to:

b3284df1c86f ("xfrm: remove input2 indirection from xfrm_mode")

That commit moved the code out of xfrm{4,6}_mode_tunnel.c. The
skb_unset_mac_header() call in end_dt_vrf_rcv(), which leaves the header
unset with a stale mac_len, came from:

664d6f86868b ("seg6: add support for the SRv6 End.DT4 behavior")

Could one of these be the Fixes: target? Since this is a slab
out-of-bounds write, should Cc: stable be added as well?

> diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
> index 5ed87d51392a5..624ff8055e470 100644
> --- a/net/xfrm/xfrm_input.c
> +++ b/net/xfrm/xfrm_input.c
> @@ -254,7 +254,7 @@ static int xfrm4_remove_tunnel_encap(struct xfrm_state *x, struct sk_buff *skb)
>  
>  	skb_reset_network_header(skb);
>  	skb_mac_header_rebuild(skb);
> -	if (skb->mac_len)
> +	if (skb_mac_header_was_set(skb) && skb->mac_len)
>  		eth_hdr(skb)->h_proto = skb->protocol;

[Severity: High]
The IP-TFS decap path still seems to have the same write. In
net/xfrm/xfrm_iptfs.c, the reuse branch of __input_process_payload() has
no skb_mac_header_was_set() check:

net/xfrm/xfrm_iptfs.c:__input_process_payload() {
    ...
				skb->protocol = protocol;
				skb_mac_header_rebuild(skb);
				if (skb->mac_len)
					eth_hdr(skb)->h_proto = skb->protocol;
    ...
}

Take the End.DT4 path from the commit message, but with the SA in iptfs
mode instead of tunnel mode. The skb then gets here through:

xfrm_input()
  xfrm_inner_mode_input()   /* default case: x->mode_cbs->input */
    iptfs_input()
      iptfs_input_ordered()
        __input_process_payload()

With mac_header == 0xffff and mac_len == 14, would this store land at
skb->head + 0xffff + 12? That is the same out-of-bounds write this patch
fixes.

The same function already computes:

	old_mac = skb_mac_header_was_set(skb) ? skb_mac_header(skb) : NULL;

The non-reuse branch only writes h_proto under if (old_mac), so the reuse
branch is the only one missing the check.

Should this site get the same guard as part of this fix?

[Severity: High]
This isn't a bug introduced by this patch, but there is a related mac
header problem in the non-reuse branch of the same function:

net/xfrm/xfrm_iptfs.c:__input_process_payload() {
    ...
			skb->protocol = protocol;
			if (old_mac) {
				/* rebuild the mac header */
				skb_set_mac_header(skb, -first_skb->mac_len);
				memcpy(skb_mac_header(skb), old_mac, first_skb->mac_len);
				eth_hdr(skb)->h_proto = skb->protocol;
			}
    ...
}

This store checks that the mac header is set, but it does not check
mac_len.

When the outer ESP skb arrives over an L3 device, the mac header can be
set while mac_len is 0. ipip_tunnel_rcv(), ip_gre and wireguard all reset
the mac header to the inner IP header. __netif_receive_skb_core() then
computes mac_len as 0.

In that case skb_set_mac_header(skb, 0) puts the mac header at skb->data.
Can the h_proto store then overwrite bytes 12-13 of the inner IP header
with 0x0800 or 0x86dd?

For IPv4 those bytes are the start of saddr, so the header checksum would
fail and the packet would be dropped. For IPv6 they are bytes 4-5 of
saddr, so the packet could be delivered with a rewritten source address.

This would affect every inner packet after the first one in an aggregated
payload. It would also affect the first one whenever it can't be reused.

The reuse branch checks skb->mac_len before the same store. Should the
non-reuse branch also check first_skb->mac_len?

[ ... ]

> @@ -291,7 +291,7 @@ static int xfrm6_remove_tunnel_encap(struct xfrm_state *x, struct sk_buff *skb)
>  
>  	skb_reset_network_header(skb);
>  	skb_mac_header_rebuild(skb);
> -	if (skb->mac_len)
> +	if (skb_mac_header_was_set(skb) && skb->mac_len)
>  		eth_hdr(skb)->h_proto = skb->protocol;

[Severity: Medium]
Would it make sense to also clear mac_len where the bad state comes from,
in end_dt_vrf_rcv()?

net/ipv6/seg6_local.c:end_dt_vrf_rcv() {
    ...
	/* the decap packet IPv4/IPv6 does not come with any mac header info.
	 * We must unset the mac header to allow the VRF device to rebuild it,
	 * just in case there is a sniffer attached on the device.
	 */
	skb_unset_mac_header(skb);
    ...
}

Other code treats an unset mac header as having mac_len == 0.
skb_reset_mac_len() sets mac_len to 0 when the header is unset.
skb_carve_reset_headers() clears mac_len right after calling
skb_unset_mac_header().

If mac_len stays at 14 here, any code that reads mac_len as "there is a mac
header" is still exposed, including the IP-TFS reuse branch above.
Clearing mac_len in end_dt_vrf_rcv() would cover both xfrm_input.c sites
and the IP-TFS site on this path.

It would not silence the skb_reset_mac_len() warnings used as the control
in the testing notes, since those fire on any unset header regardless of
mac_len.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116174531.2540348-2-piyus%40iiitd.ac.in

      reply	other threads:[~2026-11-19 11:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 17:45 [BUG] xfrm: unprivileged 64KB out-of-bounds write in xfrm4_remove_tunnel_encap through an unset mac header left with a stale mac_len (reproduced on v7.4-rc3) Piyus Kedia
2026-11-16 17:45 ` [PATCH] xfrm: do not write the ethernet header when the mac header is unset Piyus Kedia
2026-11-19 11:47   ` netdev-bot+sashiko [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=179508885903.3136.15048597271351937392@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrea.mayer@uniroma2.it \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=ipsec@lists.linux.dev \
    --cc=kapil@presceralabs.ai \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=piyus@iiitd.ac.in \
    --cc=steffen.klassert@secunet.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