* [PATCH ipsec] xfrm: iptfs: give a runt-started inner packet a MAC header
@ 2026-11-27 22:32 Andrii Tereshchenko
2026-11-29 19:58 ` Andrii Tereshchenko
0 siblings, 1 reply; 2+ messages in thread
From: Andrii Tereshchenko @ 2026-11-27 22:32 UTC (permalink / raw)
To: Steffen Klassert, Herbert Xu, David S. Miller
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
Simon Horman, Christian Hopps, netdev, ipsec, linux-kernel
When an inner packet's IP header is split across two outer packets (a
runt, which RFC 9347 allows), iptfs_reassem_cont() allocates the skb
for the rest but never sets its MAC header. Any packet socket on the
device then pushes back toward the unset header and panics:
skbuff: skb_under_panic: text:ffffffff82071ea5 len:-65455 put:-65455
skb_push+0x53/0x60
tpacket_rcv+0x91f/0xee0
netif_receive_skb_list_internal+0x49b/0x10e0
An unprivileged user can set the whole thing up (both tunnel ends and
the capture in its own namespaces). With GRO on the ingress device,
gro_list_prepare() reads past the head the same way, with no socket
at all. Rebuild the MAC header from the outer packet.
The patch was written with an AI coding assistant and reviewed by the
submitter.
Fixes: 075694765446 ("xfrm: iptfs: handle received fragmented inner packets")
Cc: stable@vger.kernel.org
Signed-off-by: Andrii Tereshchenko <opensource@andrii.net>
---
Found by an AI code review agent while testing an unlocked runt state.
Validated with a shell + Python (cryptography) + C netlink reproducer,
no kernel changes or fault injection; a sender without the SA's keys
cannot reach it (ESP drops forged runts). Tested: the reproducer
panics unmodified kernels, as root and as an unprivileged uid, and
passes with the fix, with well-formed frames; KASAN and lockdep
builds, panic_on_warn=1 on the fixed kernel. GRO evidence (no packet
socket needed), on f0e68014f4ac: IPv6 ESP-in-UDP with runts through
GRO + rx-gro-list at ingress triggers KASAN slab reports in
dev_gro_receive() (read of size 8); the same traffic with runts=0 is
clean, and the fixed stack forwards everything with no report. Also
reproduced with the sender on one host and a KASAN victim on another,
needing only CONFIG_XFRM_IPTFS (the xfrm_iptfs module, or built in);
present since v6.14. A reproducer is available to the maintainers on
request. Depends-on
note: this copy relies on C1
([PATCH ipsec] xfrm: iptfs: reserve room for the outer MAC header in
new inner skbs, patchwork 15029420, posted 11-27) for long MAC headers.
net/xfrm/xfrm_iptfs.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
index 3fff835497b9..28b9fa109251 100644
--- a/net/xfrm/xfrm_iptfs.c
+++ b/net/xfrm/xfrm_iptfs.c
@@ -845,6 +845,20 @@ static u32 iptfs_reassem_cont(struct xfrm_iptfs_data *xtfs, u64 seq,
}
xtfs->ra_newskb = newskb;
+ /* Rebuild the mac header from the outer packet, as
+ * __input_process_payload() does for the skbs it allocates;
+ * packet taps push back to it on receive.
+ */
+ if (skb_mac_header_was_set(skb)) {
+ skb_set_mac_header(newskb, -skb->mac_len);
+ memcpy(skb_mac_header(newskb), skb_mac_header(skb),
+ skb->mac_len);
+ if (skb->mac_len)
+ eth_hdr(newskb)->h_proto =
+ (xtfs->ra_runt[0] >> 4) == 6 ?
+ htons(ETH_P_IPV6) : htons(ETH_P_IP);
+ }
+
/* Copy the runt data into the buffer, but leave data
* pointers the same as normal non-runt case. The extra `rrem`
* recopied bytes are basically cacheline free. Allows using
base-commit: 1213df0bc5993e479706c5eba5830243d778f164
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH ipsec] xfrm: iptfs: give a runt-started inner packet a MAC header
2026-11-27 22:32 [PATCH ipsec] xfrm: iptfs: give a runt-started inner packet a MAC header Andrii Tereshchenko
@ 2026-11-29 19:58 ` Andrii Tereshchenko
0 siblings, 0 replies; 2+ messages in thread
From: Andrii Tereshchenko @ 2026-11-29 19:58 UTC (permalink / raw)
To: Steffen Klassert, Herbert Xu, David S. Miller
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
Simon Horman, Christian Hopps, netdev, ipsec, linux-kernel
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@mid.andrii.net/
Andrii Tereshchenko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 19:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 22:32 [PATCH ipsec] xfrm: iptfs: give a runt-started inner packet a MAC header Andrii Tereshchenko
2026-11-29 19:58 ` Andrii Tereshchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®