From: Andrii Tereshchenko <opensource@andrii.net>
To: Steffen Klassert <steffen.klassert@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>,
Christian Hopps <chopps@labn.net>,
netdev@vger.kernel.org, ipsec@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [PATCH ipsec] xfrm: iptfs: reserve room for the outer MAC header in new inner skbs
Date: Fri, 27 Nov 2026 03:03:55 -0800 [thread overview]
Message-ID: <a502a95c-de83-4f8d-986e-80f804ebe76c@mid.andrii.net> (raw)
__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 <opensource@andrii.net>
---
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
reply other threads:[~2026-11-27 11:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=a502a95c-de83-4f8d-986e-80f804ebe76c@mid.andrii.net \
--to=opensource@andrii.net \
--cc=chopps@labn.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=ipsec@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=steffen.klassert@secunet.com \
--cc=willemb@google.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
all inboxes | Powered by JetHome®