Re: [PATCH ipsec] xfrm6: gate the local error on the frame's own socket
From: Steffen Klassert
Date: Fri Nov 20 2026 - 02:56:53 EST
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
Author: Rustam Mustafin <rmustafin@xxxxxxxxxxxxxx>
xfrm6: gate the local error on the frame's own socket
This commit changes __xfrm6_output() to check skb_to_full_sk(skb) instead
of the sk argument before calling xfrm_local_error() on an oversized packet.
> diff --git a/net/ipv6/xfrm6_output.c b/net/ipv6/xfrm6_output.c
> index 44b221a09a0c8..54fcf4b430915 100644
> --- a/net/ipv6/xfrm6_output.c
> +++ b/net/ipv6/xfrm6_output.c
> @@ -95,7 +95,10 @@ static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
> } 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() reports to skb->sk; a forwarded frame
> + * sent through a UDP tunnel has none, sk is the tunnel's.
> + */
> xfrm_local_error(skb, mtu);
> kfree_skb(skb);
> return -EMSGSIZE;
Should the earlier xfrm6_local_dontfrag(sk) check in __xfrm6_output() also
use skb_to_full_sk(skb), as xfrm6_tunnel_check_size() does?
net/ipv6/xfrm6_output.c:__xfrm6_output() {
...
if (toobig && xfrm6_local_dontfrag(sk)) {
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 && skb_to_full_sk(skb)) {
...
}
When a caller passes sk == NULL while skb->sk is a local UDPv6 or RAWv6
socket with IPV6_DONTFRAG set, such as ip6_tnl_xmit() ->
ip6tunnel_xmit(NULL, skb, dev, 0) where skb_scrub_packet() clears
skb->ignore_df, xfrm6_local_dontfrag(sk) evaluates to false on NULL and
this change routes the packet into xfrm_local_error() instead of
xfrm6_local_rxpmtu() (or into ip6_fragment() via
ipvlan_process_v6_outbound() -> ip6_local_out(dev_net(dev), NULL, skb) when
skb->ignore_df remains 1).
Conversely, if a forwarded frame (skb->sk == NULL) is sent through
udp_tunnel6_xmit_skb() on a tunnel socket with IPV6_DONTFRAG set,
xfrm6_local_dontfrag(sk) returns true, xfrm6_local_rxpmtu() does nothing
because skb_to_full_sk(skb) is NULL, and the frame is dropped without
reaching ip6_fragment() to send an ICMPv6 Packet Too Big.
In addition, callers such as vrf_process_v6_outbound() pass raw skb->sk as
sk to dst_output(), so if skb->sk is a TCP_NEW_SYN_RECV or TCP_TIME_WAIT
mini-socket, xfrm6_local_dontfrag(sk) reads sk->sk_protocol and
inet_sk(sk)->inet_flags out-of-bounds past struct tcp6_request_sock or
struct tcp6_timewait_sock.