__input_process_payload() copies outer MAC headers into skbs with up to 80 bytes of headroom. Longer headers (NBMA GRE) wrap the 16-bit offset, and the copy lands far past skb->head; reserve room for mac_len. BUG: KASAN: slab-use-after-free in __input_process_payload.isra.0+0x51c/0x1c70 The patch was written with an AI coding assistant and reviewed by the submitter. Fixes: 6c82d2433671 ("xfrm: iptfs: add basic receive packet (tunnel egress) handling") Link: https://lore.kernel.org/netdev/179524501671.3135.15869590714107061136@kernel.org/ Cc: stable@vger.kernel.org Signed-off-by: Andrii Tereshchenko --- netdev's AI review of Piyus Kedia's "xfrm: do not write the ethernet header when the mac header is unset" pointed out this write (Link: above). 7a505bb0168a ("net: clear skb->mac_len in skb_unset_mac_header()") does not cover it: here the MAC header is set. Found independently by an AI code review agent. Reproduced on ipsec master without kernel changes or fault injection. With this patch the reproducer passes, two boots each way, with panic_on_warn=1 and no KASAN report. A reproducer is available to the maintainers on request. Not tested: an architecture where L1_CACHE_BYTES is larger than 64. net/xfrm/xfrm_iptfs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c index 3fff835497b9..fe54979116de 100644 --- a/net/xfrm/xfrm_iptfs.c +++ b/net/xfrm/xfrm_iptfs.c @@ -242,7 +242,9 @@ static u64 __esp_seq(struct sk_buff *skb) * * When @l3resv is false, resv is XFRM_IPTFS_MIN_L2HEADROOM which arranges for * `skb->data - 16` which is a good guess for good cache alignment (placing the - * to be pushed L2 header at the start of a cacheline. + * to be pushed L2 header at the start of a cacheline. If @tpl's MAC header + * is longer, as with NBMA GRE, resv is its length rounded up, so the + * arrangement holds: it is copied in front of the inner packet. * * Otherwise, @l3resv is true and resv is set to the correct reserved space for * dst->dev plus the calculated L3 overhead for the xfrm dst or @@ -263,6 +265,11 @@ static struct sk_buff *iptfs_alloc_skb(struct sk_buff *tpl, u32 len, bool l3resv if (!l3resv) { resv = XFRM_IPTFS_MIN_L2HEADROOM; + /* A longer MAC header needs room too; round up to keep + * the cacheline arrangement. + */ + if (unlikely(tpl->mac_len > resv)) + resv += ALIGN(tpl->mac_len - resv, L1_CACHE_BYTES); } else { struct dst_entry *dst = skb_dst(tpl); base-commit: 2803867cf3defa294710088a4663b434e12b5e93 -- 2.53.0