Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH ipsec v2] xfrm: use the frame's own socket in the too big checks
@ 2026-11-23 10:42 Rustam Mustafin
  0 siblings, 0 replies; only message 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] only message in thread

only message in thread, other threads:[~2026-11-23 10:42 UTC | newest]

Thread overview: (only message) (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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox