Re: [PATCH ipsec] xfrm: iptfs: give a runt-started inner packet a MAC header

From: Andrii Tereshchenko

Date: Sun Nov 29 2026 - 14:58:24 EST


Both AI reviews [1][2] raise the same issue with this patch, which
another of my patches fixes, plus two older issues outside it. Neither
review was mailed to the list, so I am answering here.

Sashiko (netdev AI review) wrote:
> Can this write past the end of the newskb buffer when skb->mac_len is
> larger than the headroom of newskb?
>
> newskb comes from iptfs_alloc_skb(skb, ipremain, false). That call reserves
> a fixed amount of headroom and ignores tpl->mac_len:
[...]
> The note below the --- line says "this copy relies on C1 ... for long MAC
> headers". That patch is not in this tree. git am also drops the note, and
> the Cc: stable tag lists no prerequisite.
>
> Would it be safer to check skb->mac_len against skb_headroom(newskb), or to
> call skb_cow_head(), before the copy? Another option is to send this with
> C1 as one ordered series.
>
> __input_process_payload() already has the same unchecked pattern:
[...]
> So a fix would need to cover both places.

Sashiko (sashiko.dev) raised the same point.

Yes. "xfrm: iptfs: reserve room for the outer MAC header in new inner
skbs" [3] fixes it in iptfs_alloc_skb(), which both places allocate
from: it reserves at least tpl->mac_len, rounded up to a cache line.
Without it, this patch adds a second place with the overflow that
__input_process_payload() already has, so it has to be applied after
[3], and stable needs both, in that order.

Steffen, could you take [3] first? If you would rather have them as one
series, I will resend both as a v2, with the order spelled out for
stable.

Sashiko (sashiko.dev) wrote:
> Also, if skb->mac_len is non-zero but smaller than ETH_HLEN, writing
> eth_hdr(newskb)->h_proto writes past the end of the skb->mac_len-byte MAC
> header into the IP header at newskb->data.

That is true of every h_proto store on the xfrm receive path: the
reuse branch of __input_process_payload() and
xfrm4_remove_tunnel_encap() and xfrm6_remove_tunnel_encap() guard with
"if (skb->mac_len)" too. This patch follows them. I don't know of a
device that hands ESP up with a MAC header shorter than ETH_HLEN, so I
have left it as is.

Sashiko (netdev AI review) wrote:
> This issue was not introduced by this patch. The new comment names
> __input_process_payload() as its model, but the allocate path in that
> function does not have this mac_len guard:
[...]
> Should that store also be guarded with if (first_skb->mac_len)?

Sashiko (sashiko.dev) raised the same point.

Yes. Over IPIP, point-to-point GRE, ip6ip6 and ip6gre, only one inner
packet per outer packet survives it. I have a fix ready that adds that
guard, and will post it separately, with other IP-TFS receive fixes.

Sashiko (sashiko.dev) wrote:
> This problem wasn't introduced by this patch, but earlier in
> iptfs_reassem_cont() the blkoff == 0 handling triggers [...] an
> out-of-bounds read when skb is completely non-linear:
[...]
> Direct dereference of *skb->data neither checks that linear data is present
> nor reads from the sequential state st at offset data, so it reads past the
> empty linear buffer on a fully non-linear skb and otherwise inspects the
> outer IP-TFS header subtype byte instead of the inner padding byte.

Yes, that check reads the IP-TFS header instead of the data block. The
fix, which reads the first octet of the data block with
skb_copy_bits(), is in the same receive series.

[1] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/e7d0ab12-61be-4ba7-9a2d-4a71ca73dc4e%40mid.andrii.net
[2] https://sashiko.dev/#/patchset/e7d0ab12-61be-4ba7-9a2d-4a71ca73dc4e%40mid.andrii.net
[3] https://lore.kernel.org/all/a502a95c-de83-4f8d-986e-80f804ebe76c@xxxxxxxxxxxxxx/

Andrii Tereshchenko