Re: [PATCH net v2] xfrm: do not write the ethernet header when the mac header is unset

From: Piyus Kedia

Date: Sat Nov 21 2026 - 04:14:53 EST


Thank you for the review. This issue has already been resolved through
a different patch (suggested by Eric) that has been merged into the
upstream kernel.

Best regards,
Piyus Kedia
Kapil Vaswani


On Sat, Nov 21, 2026 at 12:40 PM <netdev-bot+sashiko@xxxxxxxxxx> wrote:
>
> Thank you for your contribution! Sashiko AI review found 5 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 (1) · Medium: 2 · 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 stops the h_proto store, but the skb still leaves decap
> with an unset mac header.
> - [Medium] The changelog correctly finds where the malformed skb comes
> from but does not fix it there.
> - [Medium] In __input_process_payload() (net/xfrm/xfrm_iptfs.c) the
> commit message cites the old_mac branch as precedent ('what…
> - [Low] The patch fixes an out-of-bounds write but has no Fixes: tag and
> no Cc: stable.
> - [Low] The Signed-off-by chain is malformed.
>
> Pre-existing issues:
> - [High] This problem wasn't introduced by this patch, but it is the same
> out-of-bounds-write-via-mac_header pattern, in the function the patch…
>
> --
>
> 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 at three sites: xfrm4_remove_tunnel_encap(),
> xfrm6_remove_tunnel_encap(), and the IPTFS skb reuse path in
> __input_process_payload(). The skb state it guards against comes from
> end_dt_vrf_rcv(), which calls skb_unset_mac_header() and leaves mac_len
> at the Ethernet value.
>
> Link: https://lore.kernel.org/r/20261116174531.2540348-2-piyus@xxxxxxxxxxx
>
> > Signed-off-by: Kapil Vaswani <kapil@xxxxxxxxxxxxxxx>
> > Signed-off-by: Piyus Kedia <piyus@xxxxxxxxxxx>
>
> [Severity: Low]
> The author is Piyus Kedia, but Kapil Vaswani's Signed-off-by comes first
> and there is no Co-developed-by: tag.
>
> Should there be a Co-developed-by: Kapil Vaswani <kapil@xxxxxxxxxxxxxxx>
> line right before his Signed-off-by, as described in
> Documentation/process/submitting-patches.rst? If he did not co-write the
> patch, should the trailers be reordered?
>
> [Severity: Low]
> This fixes an out-of-bounds write, but it has no Fixes: tag and no Cc:
> stable. The notes say the introducing commit could not be found. The
> history is in tree, though:
>
> The producer, skb_unset_mac_header() in end_dt_vrf_rcv(), came in with
> 664d6f86868b ("seg6: add support for the SRv6 End.DT4 behavior").
>
> The xfrm_iptfs.c site came in with 3f3339885fb3 ("xfrm: iptfs: add
> reusing received skb for the tunnel egress packet").
>
> The xfrm_input.c lines blame to b3284df1c86f ("xfrm: remove input2
> indirection from xfrm_mode"), which moved older code.
>
> Should this carry separate Fixes: tags, or be split into two patches? The
> IPTFS hunk will not apply to trees that predate IPTFS.
>
> > 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;
> >
> > err = 0;
>
> [Severity: High]
> The store is now skipped, but xfrm4_remove_tunnel_encap() still returns 0
> with mac_header == 0xffff and mac_len still non-zero. Can the same skb
> still be read through the unset header later on, in GRO?
>
> In the tunnel decaps branch, xfrm_input() passes the skb to GRO:
>
> gro_cells_receive(&gro_cells, skb);
>
> skb->dev is the VRF device. It has NETIF_F_GRO, and ether_setup() gives it
> hard_header_len == ETH_HLEN, so GRO is not skipped:
>
> gro_cell_poll()
> napi_gro_receive()
> gro_receive_skb()
> dev_gro_receive()
> gro_list_prepare()
>
> For each held packet p with a matching hash, gro_list_prepare() does:
>
> if (maclen == ETH_HLEN)
> diffs |= compare_ether_header(skb_mac_header(p),
> skb_mac_header(skb));
>
> skb_mac_header() only issues a DEBUG_NET_WARN and returns
> skb->head + 0xffff. That makes this a 14-byte read, for both skbs, at the
> same fixed address 64KB past head that the commit message describes.
>
> The held packet p is also still unset. At found_ptype, dev_gro_receive()
> only calls skb_reset_mac_len(), which leaves mac_header at 0xffff. Two
> packets of one inner flow in the same NAPI poll, such as two consecutive
> TCP segments, look like enough to trigger this.
>
> The skb_reset_mac_len() warning used as the control in the test notes
> looks like this same skb reaching found_ptype in dev_gro_receive(), or
> __netif_receive_skb_core(), on the patched kernel.
>
> Would it work better to normalise the skb, either in end_dt_vrf_rcv() or
> here by resetting the mac header and setting mac_len = 0 when it was
> unset? That would remove both the write and this read.
>
> > @@ -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;
> >
> > err = 0;
>
> [Severity: Medium]
> The commit message identifies where the bad state comes from, but the fix
> is applied at three consumers instead. Is there a reason to leave
> end_dt_vrf_rcv() and skb_unset_mac_header() unchanged?
>
> net/ipv6/seg6_local.c:end_dt_vrf_rcv() {
> ...
> skb_unset_mac_header(skb);
>
> skb = dev->l3mdev_ops->l3mdev_l3_rcv(dev, skb, family);
> ...
> }
>
> skb_unset_mac_header() writes the ~0 sentinel and leaves mac_len alone.
> That breaks the rule skb_reset_mac_len() enforces:
>
> if (!skb_mac_header_was_set(skb)) {
> DEBUG_NET_WARN_ON_ONCE(1);
> skb->mac_len = 0;
>
> vrf_ip_rcv() and vrf_ip6_rcv() only rebuild the header when
> !list_empty(&vrf_dev->ptype_all). Without a sniffer attached, the skb goes
> through the IP stack and xfrm with mac_header unset and
> mac_len == ETH_HLEN.
>
> After this patch, the skb still leaves tunnel decap in that state through
> gro_cells_receive(). Any later consumer that trusts mac_len or
> skb_mac_header() is still exposed, and the GRO read above is one of them.
>
> There are two ways to fix this at the source. One is to give the skb a
> valid mac header with mac_len = 0 after l3mdev_l3_rcv() when VRF did not
> rebuild it. The other is to have skb_unset_mac_header() clear mac_len.
> Would either one make the original "if (skb->mac_len)" checks correct
> again?
>
> > diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
> > index 0313a43aa8a97..41af72a9206ad 100644
> > --- a/net/xfrm/xfrm_iptfs.c
> > +++ b/net/xfrm/xfrm_iptfs.c
> > @@ -1099,7 +1099,7 @@ static bool __input_process_payload(struct xfrm_state *x, u32 data,
> >
> > skb->protocol = protocol;
> > 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;
> >
> > /* all pointers could be changed now reset walk */
>
> [Severity: Medium]
> The commit message says:
>
> This mirrors what xfrm4_transport_input() already does, ... and what
> __input_process_payload() already does for old_mac
>
> Does the old_mac branch really check as much as this one? old_mac depends
> only on skb_mac_header_was_set():
>
> old_mac = skb_mac_header_was_set(skb) ? skb_mac_header(skb) : NULL;
>
> The alloc path then writes h_proto without looking at mac_len:
>
> 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;
> }
>
> When first_skb->mac_len is 0, the mac header lands at skb->data, which is
> the start of the inner IP header that was just copied in. The h_proto
> store then writes 0x0800 or 0x86dd at data + 12.
>
> For IPv4 that overwrites the first two bytes of saddr. For IPv6 it
> overwrites bytes 4-5 of saddr, after ESP authentication has already been
> done.
>
> A set mac header with mac_len == 0 is normal on L3 receive devices such as
> tun with IFF_TUN, ipgre without header_ops, and ip6_tunnel. Every inner
> packet after the first in an aggregated IPTFS payload takes this alloc
> path.
>
> Should both branches check old_mac && first_skb->mac_len, or, better,
> require a real Ethernet header?
>
> [Severity: High]
> This is a pre-existing issue, not one introduced by this patch. The same
> alloc path in __input_process_payload() has a related out-of-bounds write
> through mac_header. Is the headroom checked before these lines?
>
> skb_set_mac_header(skb, -first_skb->mac_len);
> memcpy(skb_mac_header(skb), old_mac, first_skb->mac_len);
>
> The new skb is allocated by iptfs_alloc_skb(..., false), called from
> iptfs_pskb_extract_seq() or iptfs_pskb_add_frags(). That only reserves:
>
> #define XFRM_IPTFS_MIN_L2HEADROOM (L1_CACHE_BYTES > 64 ? 64 : 64 + 16)
>
> If first_skb->mac_len is larger than that headroom, the u16 mac_header
> wraps to roughly 0xfff4-0xffff. memcpy() then writes mac_len bytes about
> 64KB past skb->head, and the h_proto store after it is out of bounds too.
>
> ipgre with ipgre_header_ops can get there, in ipgre_rcv():
>
> if (tunnel->dev->header_ops == &ipgre_header_ops)
> skb_pop_mac_header(skb);
>
> That sets mac_len to the outer IP header plus the GRE header, up to 76
> bytes. This is more than the 64 bytes reserved on arches with
> L1_CACHE_BYTES > 64, and the copied bytes come from outer headers that ESP
> does not authenticate.
>
> A tc ingress BPF program using bpf_skb_change_head() can also make mac_len
> larger than the headroom on any arch, though that needs privileges.
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117062046.3286096-1-piyus%40iiitd.ac.in