* [PATCH ipsec v2] xfrm: use the frame's own socket in the too big checks
@ 2026-11-23 10:42 Rustam Mustafin
2026-11-24 10:45 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Rustam Mustafin @ 2026-11-23 10:42 UTC (permalink / raw)
To: Steffen Klassert, Herbert Xu, David S. Miller
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, netdev,
ipsec, linux-kernel, Rustam Mustafin, stable
__xfrm6_output() decides how to report a too big frame by looking at
its sk argument, but xfrm_local_error() reports to skb->sk and
dereferences it unchecked. The two differ for a UDP tunnel: vxlan,
geneve and other udp_tunnel6_xmit_skb() users pass the tunnel socket as
sk, while a frame they forward has no skb->sk. When such a frame takes
an IPv6 tunnel mode xfrm bundle and exceeds its MTU, xfrm_local_error()
oopses:
Oops: general protection fault, probably for non-canonical address
0xdffffc0000000002: 0000 [#1] SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017]
RIP: 0010:xfrm_local_error+0x92/0x190
Call Trace:
<IRQ>
xfrm6_output+0x599/0xae0
udp_tunnel6_xmit_skb+0x713/0xd90
vxlan_xmit_one+0x1ebc/0x3490
vxlan_xmit+0x1369/0x6540
dev_hard_start_xmit+0xe3/0x5b0
__dev_queue_xmit+0x18e7/0x3550
ip6_output+0x360/0xec0
ip6_forward+0x1573/0x35c0
Commit 1620c88887b1 ("xfrm: Fix the usage of skb->sk") changed both the
IPV6_DONTFRAG test and the local error test from skb->sk to sk. Test
skb_to_full_sk(skb) in both, as xfrm6_tunnel_check_size() does.
A frame without a socket then goes to ip6_fragment(), which sends an
ICMPv6 Packet Too Big, also when the tunnel socket sets IPV6_DONTFRAG,
where it was dropped silently. For callers that pass a NULL sk, such as
ip6_tunnel, the error goes to skb->sk again, as before 1620c88887b1, and
a request or timewait socket that vrf passes as sk is no longer read as
a full socket.
Fixes: 1620c88887b1 ("xfrm: Fix the usage of skb->sk")
Cc: stable@vger.kernel.org
Signed-off-by: Rustam Mustafin <rmustafin@cloudlinux.com>
---
Notes:
v2: also use skb_to_full_sk(skb) for the IPV6_DONTFRAG test, as the
review of v1 suggested; drop the code comment.
v1: https://lore.kernel.org/all/20261114125552.1319352-1-rmustafin@cloudlinux.com/
Tested with KASAN on 7e1392a42ea2: a frame forwarded through vxlan over
IPv6 ESP oopses without the patch and not with it. Through ip6ip6 over
the same ESP tunnel, a too big frame is dropped as before; ping now gets
EMSGSIZE on its error queue instead of a Packet Too Big.
Not touched here:
- iptfs_is_too_big() has the same mismatch (IPv6 oops, IPv4 silent drop);
it was pointed out in two reviews:
https://lore.kernel.org/all/20260908224856.1591189-1-kuba@kernel.org/
https://lore.kernel.org/all/179369310739.488856.16665150928122536725@kernel.org/
- skb_to_full_sk() can read a freed listener when a bpf syncookie request
socket is redirected and queued; the bpf_sk_assign series handles it:
https://lore.kernel.org/all/20261119142231.2612515-2-razor@blackwall.org/
net/ipv6/xfrm6_output.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/ipv6/xfrm6_output.c b/net/ipv6/xfrm6_output.c
index 44b221a09a0c..d38311645908 100644
--- a/net/ipv6/xfrm6_output.c
+++ b/net/ipv6/xfrm6_output.c
@@ -88,14 +88,14 @@ static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
toobig = skb->len > mtu && !skb_is_gso(skb);
- if (toobig && xfrm6_local_dontfrag(sk)) {
+ if (toobig && xfrm6_local_dontfrag(skb_to_full_sk(skb))) {
xfrm6_local_rxpmtu(skb, mtu);
kfree_skb(skb);
return -EMSGSIZE;
} else if (toobig && xfrm6_noneed_fragment(skb)) {
skb->ignore_df = 1;
goto skip_frag;
- } else if (!skb->ignore_df && toobig && sk) {
+ } else if (!skb->ignore_df && toobig && skb_to_full_sk(skb)) {
xfrm_local_error(skb, mtu);
kfree_skb(skb);
return -EMSGSIZE;
--
2.52.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH ipsec v2] xfrm: use the frame's own socket in the too big checks
2026-11-23 10:42 [PATCH ipsec v2] xfrm: use the frame's own socket in the too big checks Rustam Mustafin
@ 2026-11-24 10:45 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 10:45 UTC (permalink / raw)
To: rmustafin
Cc: steffen.klassert, herbert, davem, edumazet, kuba, pabeni, horms,
netdev, ipsec, linux-kernel, stable
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 0 · Low: 0
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 misses one of the too-big checks.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is a kernel
heap info leak on the same path.
--
xfrm: use the frame's own socket in the too big checks
This patch makes __xfrm6_output() test skb_to_full_sk(skb) instead of its
sk argument in both the IPV6_DONTFRAG check and the local error check. It
fixes a NULL pointer dereference in xfrm_local_error(). The dereference
happens when vxlan, geneve or another udp_tunnel6_xmit_skb() user forwards
a frame that has no skb->sk over an IPv6 tunnel mode xfrm bundle, and the
frame exceeds the MTU.
> diff --git a/net/ipv6/xfrm6_output.c b/net/ipv6/xfrm6_output.c
> index 44b221a09a0c8..d383116459089 100644
> --- a/net/ipv6/xfrm6_output.c
> +++ b/net/ipv6/xfrm6_output.c
> @@ -88,14 +88,14 @@ static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
>
> toobig = skb->len > mtu && !skb_is_gso(skb);
>
> - if (toobig && xfrm6_local_dontfrag(sk)) {
> + if (toobig && xfrm6_local_dontfrag(skb_to_full_sk(skb))) {
> xfrm6_local_rxpmtu(skb, mtu);
> kfree_skb(skb);
> return -EMSGSIZE;
> } else if (toobig && xfrm6_noneed_fragment(skb)) {
> skb->ignore_df = 1;
> goto skip_frag;
> - } else if (!skb->ignore_df && toobig && sk) {
> + } else if (!skb->ignore_df && toobig && skb_to_full_sk(skb)) {
[Severity: High]
Does iptfs_is_too_big() in net/xfrm/xfrm_iptfs.c still have the same
mismatch? It tests the sk passed to dst_output(), not the frame's own
socket:
net/xfrm/xfrm_iptfs.c:iptfs_is_too_big() {
...
if (sk)
xfrm_local_error(skb, pmtu);
else if (ip_hdr(skb)->version == 4)
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(pmtu));
...
}
IP-TFS states replace dst->output in xfrm_bundle_create():
dst1->output = xfrm[i]->mode_cbs->output;
As a result, __xfrm6_output() never runs for these frames, and the check
changed here does not cover them.
Take a frame forwarded into vxlan or geneve on an IPv6 underlay, routed
over an IP-TFS SA with dont_frag set:
udp_tunnel6_xmit_skb()
ip6tunnel_xmit(sock6->sk, ...)
ip6_local_out(net, sk, skb)
dst_output()
iptfs_output_collect(net, sk, skb)
iptfs_is_too_big(sk, skb, pmtu)
xfrm_local_error(skb, pmtu)
Here sk is the tunnel socket and skb->sk is NULL. Wouldn't
xfrm_local_error() then hit the same skb->sk->sk_family NULL dereference
shown in the trace in the commit message?
For IPv4, udp_tunnel_xmit_skb()->iptunnel_xmit()->ip_local_out() ends up
in xfrm4_local_error(). That function returns early because
skb_to_full_sk() is NULL. Since sk is non-NULL, the icmp_send() fallback
is skipped, so the frame seems to be dropped without a Frag Needed being
sent.
The subject says "use the frame's own socket in the too big checks", but
the commit message never mentions the IP-TFS site. It appears only in the
notes below the --- line, which won't go into git, even though two earlier
reviews pointed it out:
https://lore.kernel.org/all/20260908224856.1591189-1-kuba@kernel.org/
https://lore.kernel.org/all/179369310739.488856.16665150928122536725@kernel.org/
Could iptfs_is_too_big() get the same one line change to test
skb_to_full_sk(skb), either in this patch or in a companion patch?
[Severity: High]
This isn't a bug introduced by this patch, but this branch leads into
xfrm6_local_error(), which looks like it can leak kernel heap memory:
net/ipv6/xfrm6_output.c:xfrm6_local_error() {
...
hdr = skb->encapsulation ? inner_ipv6_hdr(skb) : ipv6_hdr(skb);
fl6.fl6_dport = inet_sk(sk)->inet_dport;
fl6.daddr = hdr->daddr;
...
}
Nothing checks that the inner packet is IPv6. The only family check is the
socket check in xfrm_local_error():
else if (skb->protocol == htons(ETH_P_IPV6) &&
skb->sk->sk_family == AF_INET6)
An AF_INET6 UDP socket connected to a v4-mapped address passes this check
while it sends IPv4 packets.
Suppose such a socket has IPV6_RECVERR set and sends through a vxlan
device whose IPv6 underlay is routed over an IPv6 tunnel mode ESP bundle.
vxlan advertises NETIF_F_SG | NETIF_F_HW_CSUM. With MSG_SPLICE_PAGES or
MSG_ZEROCOPY, __ip_append_data() takes the paged path. The linear head
then holds only the 20 byte IPv4 header and the 8 byte UDP header, with
CHECKSUM_PARTIAL.
Along the way:
- skb_scrub_packet() in the same netns keeps skb->sk and clears ignore_df.
- iptunnel_handle_offloads() keeps encapsulation set for CHECKSUM_PARTIAL,
and inner_network_header points at the inner IPv4 header.
- skb_tunnel_check_pmtu() returns 0 for local, non-bridged traffic.
Next, __xfrm6_output()->xfrm_local_error()->xfrm6_local_error() reads
hdr->daddr from offsets 24..39 of the inner IPv4 header. Bytes 24..27 are
the UDP length and checksum. Bytes 28..39 are past the skb tail, in
uninitialized tailroom of the head buffer.
ipv6_local_error() copies these bytes into the error skb. ip6_recv_error()
then returns them to userspace in sin6_addr when serr->port is non-zero,
which it is for a connected socket.
Can this expose up to 12 bytes of uninitialized slab memory per error to
an unprivileged user? It could be repeated, for example with
IP_PMTUDISC_PROBE so that every send exceeds the xfrm MTU.
Even without the paged path, isn't the reported address wrong, since an
IPv4 packet is being read as an ipv6hdr?
Before this patch, the local vxlan path already reached this code because
sk was the non-NULL tunnel socket. This patch keeps that path reachable;
it neither opens nor closes it.
> xfrm_local_error(skb, mtu);
> kfree_skb(skb);
> return -EMSGSIZE;
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123104236.4179425-1-rmustafin%40cloudlinux.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-24 10:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 10:42 [PATCH ipsec v2] xfrm: use the frame's own socket in the too big checks Rustam Mustafin
2026-11-24 10:45 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox