Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH ipsec] xfrm: iptfs: report the too big error to the frame's own socket
@ 2026-11-27 14:25 Rustam Mustafin
  2026-11-28 14:56 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: Rustam Mustafin @ 2026-11-27 14:25 UTC (permalink / raw)
  To: Steffen Klassert, Herbert Xu, David S. Miller
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman, Christian Hopps, netdev, ipsec, linux-kernel,
	Rustam Mustafin, Sashiko, stable

iptfs_is_too_big() calls xfrm_local_error() when its sk argument is set,
but xfrm_local_error() reports to skb->sk and dereferences it. vxlan
passes its tunnel socket as sk for a forwarded frame that has no
skb->sk, so an oversized forwarded frame on an IP-TFS SA with dont-frag
oopses:

  KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017]
  RIP: 0010:xfrm_local_error+0x92/0x190
  Call Trace:
   iptfs_output_collect+0x2c2/0x1170
   udp_tunnel6_xmit_skb+0x713/0xd90
   vxlan_xmit_one+0x1ebc/0x3490
   ip6_forward+0x1573/0x35c0

Check the frame's own full socket instead, as xfrm4_tunnel_check_size()
does, so a forwarded frame gets the ICMP error. Drop the now unused sk
argument.

Reproduced on a KASAN kernel with vxlan forwarding over an IP-TFS SA;
with the fix the oops is gone and an ICMPv6 Packet Too Big is sent. The
xfrm_state.sh, xfrm_policy.sh, xfrm_policy_add_speed.sh,
vrf-xfrm-tests.sh, pmtu.sh and ipsec selftests pass with and without the
fix.

Fixes: 0e4fbf013fa5 ("xfrm: iptfs: add user packet (tunnel ingress) handling")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/179551712630.3135.52212996809224784@kernel.org/
Cc: stable@vger.kernel.org
Signed-off-by: Rustam Mustafin <rmustafin@cloudlinux.com>
---
Assisted by Claude Opus 5.5 (claude-opus-5-5).

A KASAN reproducer (single VM, vxlan forwarding over an IP-TFS SA) is
available on request.

 net/xfrm/xfrm_iptfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
index 0313a43aa8a9..ccdde630a825 100644
--- a/net/xfrm/xfrm_iptfs.c
+++ b/net/xfrm/xfrm_iptfs.c
@@ -1813,7 +1813,7 @@ static int iptfs_get_cur_pmtu(struct xfrm_state *x, struct xfrm_iptfs_data *xtfs
 	return pmtu;
 }
 
-static int iptfs_is_too_big(struct sock *sk, struct sk_buff *skb, u32 pmtu)
+static int iptfs_is_too_big(struct sk_buff *skb, u32 pmtu)
 {
 	if (skb->len <= pmtu)
 		return 0;
@@ -1824,7 +1824,7 @@ static int iptfs_is_too_big(struct sock *sk, struct sk_buff *skb, u32 pmtu)
 	if (skb->dev)
 		XFRM_INC_STATS(dev_net(skb->dev), LINUX_MIB_XFRMOUTERROR);
 
-	if (sk)
+	if (skb_to_full_sk(skb))
 		xfrm_local_error(skb, pmtu);
 	else if (ip_hdr(skb)->version == 4)
 		icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(pmtu));
@@ -1908,7 +1908,7 @@ static int iptfs_output_collect(struct net *net, struct sock *sk, struct sk_buff
 		/* If the user indicated no iptfs fragmenting check before
 		 * enqueue.
 		 */
-		if (xtfs->cfg.dont_frag && iptfs_is_too_big(sk, skb, pmtu)) {
+		if (xtfs->cfg.dont_frag && iptfs_is_too_big(skb, pmtu)) {
 			trace_iptfs_too_big(skb, xtfs, pmtu, was_gso);
 			kfree_skb_reason(skb, SKB_DROP_REASON_PKT_TOO_BIG);
 			continue;
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH ipsec] xfrm: iptfs: report the too big error to the frame's own socket
  2026-11-27 14:25 [PATCH ipsec] xfrm: iptfs: report the too big error to the frame's own socket Rustam Mustafin
@ 2026-11-28 14:56 ` netdev-bot+sashiko
  0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 14:56 UTC (permalink / raw)
  To: rmustafin
  Cc: steffen.klassert, herbert, davem, edumazet, kuba, pabeni, willemb,
	horms, chopps, netdev, ipsec, linux-kernel, sashiko-bot, stable

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 (1) · Medium: 0 · Low: 1

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 is incomplete.
- [Low] The commit message says the new check works "as
  xfrm4_tunnel_check_size() does".

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
  iptfs_output_collect() takes spin_lock_bh(&x->lock)…

--

xfrm: iptfs: report the too big error to the frame's own socket

This patch changes iptfs_is_too_big() to pick between xfrm_local_error()
and an ICMP error using skb_to_full_sk(skb). Before, it used the sk
argument passed to dst_output(). This fixes a NULL pointer dereference in
xfrm_local_error() when vxlan forwards an oversized frame over an IP-TFS
SA with dont-frag set.

Closes: https://lore.kernel.org/all/179551712630.3135.52212996809224784@kernel.org/

> Check the frame's own full socket instead, as xfrm4_tunnel_check_size()
> does, so a forwarded frame gets the ICMP error. Drop the now unused sk
> argument.

[Severity: Low]
Is the comparison to xfrm4_tunnel_check_size() accurate? That function
checks:

net/xfrm/xfrm_output.c:xfrm4_tunnel_check_size() {
    ...
		if (skb->sk && sk_fullsock(skb->sk))
			xfrm_local_error(skb, mtu);
		else
			icmp_send(skb, ICMP_DEST_UNREACH,
				  ICMP_FRAG_NEEDED, htonl(mtu));
    ...
}

The skb_to_full_sk(skb) check used here is the one in
xfrm6_tunnel_check_size(). The two checks behave differently for request
sockets. sk_to_full_sk() maps a TCP_NEW_SYN_RECV socket to its listener,
while sk_fullsock() returns false for it.

So an oversized IPv4 SYN-ACK goes to xfrm_local_error() here, where
xfrm4_tunnel_check_size() would call icmp_send(). That is harmless,
because xfrm4_local_error() resolves skb_to_full_sk() itself. Still, the
wording could be more precise.

Also, the oops described only happens with an IPv6 outer header. For
IPv4, xfrm_local_error()->xfrm4_local_error() found no full socket and
returned without doing anything, so the old behaviour was a silent drop.
With this patch those frames now get icmp_send(ICMP_FRAG_NEEDED).

Could the commit message mention this change in IPv4 behaviour?

> diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
> index 76272b0a18296..8a5276c1c002e 100644
> --- a/net/xfrm/xfrm_iptfs.c
> +++ b/net/xfrm/xfrm_iptfs.c

[ ... ]

> @@ -1832,7 +1832,7 @@ static int iptfs_is_too_big(struct sock *sk, struct sk_buff *skb, u32 pmtu)
>  	if (skb->dev)
>  		XFRM_INC_STATS(dev_net(skb->dev), LINUX_MIB_XFRMOUTERROR);
>  
> -	if (sk)
> +	if (skb_to_full_sk(skb))
>  		xfrm_local_error(skb, pmtu);

[Severity: High]
This fixes the IP-TFS caller. Is the same NULL dereference still
reachable through __xfrm6_output() when the SA is a plain IPv6
tunnel-mode ESP SA rather than IP-TFS?

__xfrm6_output() still checks the sk argument from dst_output():

net/ipv6/xfrm6_output.c:__xfrm6_output() {
    ...
	} else if (!skb->ignore_df && toobig && sk) {
		xfrm_local_error(skb, mtu);
		kfree_skb(skb);
		return -EMSGSIZE;
	}
    ...
}

For IPv6, xfrm_local_error() dereferences skb->sk without a NULL check:

net/xfrm/xfrm_output.c:xfrm_local_error() {
    ...
	else if (skb->protocol == htons(ETH_P_IPV6) &&
		 skb->sk->sk_family == AF_INET6)
    ...
}

With routed vxlan over an IPv6 underlay, the path looks like this:

ip6_forward()
  vxlan_xmit_one()
    skb_tunnel_check_pmtu(..., reply=false)   /* returns 0 */
    skb_scrub_packet()                         /* ignore_df = 0 */
    udp_tunnel6_xmit_skb(ndst, sock6->sk, skb, ...)
      ip6tunnel_xmit()
        ip6_local_out(net, sk, skb)  /* sk = vxlan sock, skb->sk NULL */
          dst_output()
            xfrm6_output()
              __xfrm6_output()
                xfrm_local_error()   /* skb->sk->sk_family */

xfrm6_local_dontfrag(sk) is false, because vxlan never sets DONTFRAG.
xfrm6_noneed_fragment() returns 0, because nexthdr is UDP. So the first
forwarded frame larger than the xfrm dst MTU minus the vxlan headroom
seems to hit the same oops. The only difference is that __xfrm6_output()
crashes instead of iptfs_output_collect().

The check in __xfrm6_output() came from commit 1620c88887b1 ("xfrm: Fix
the usage of skb->sk").

Since this is tagged for stable, could __xfrm6_output() also check
skb_to_full_sk(skb)? Another option is to harden xfrm_local_error()
itself, so it uses skb_to_full_sk() or bails out when skb->sk is NULL.
xfrm4_local_error() and xfrm6_local_error() already do that internally.

[ ... ]

> @@ -1916,7 +1916,7 @@ static int iptfs_output_collect(struct net *net, struct sock *sk, struct sk_buff
>  		/* If the user indicated no iptfs fragmenting check before
>  		 * enqueue.
>  		 */
> -		if (xtfs->cfg.dont_frag && iptfs_is_too_big(sk, skb, pmtu)) {
> +		if (xtfs->cfg.dont_frag && iptfs_is_too_big(skb, pmtu)) {

[Severity: High]
This isn't a bug introduced by this patch, but can this deadlock on
x->lock?

iptfs_output_collect() holds spin_lock_bh(&x->lock) across the whole
segment loop. iptfs_is_too_big() sends the ICMP error synchronously from
inside that loop:

iptfs_output_collect()
  spin_lock_bh(&x->lock)
  iptfs_is_too_big()
    icmp_send() / icmpv6_send()
      ip_push_pending_frames()->ip_send_skb()->ip_local_out()
        dst_output()
          iptfs_output_collect()   /* dst->output of an IP-TFS bundle */
            spin_lock_bh(&x'->lock)

xfrm_bundle_create() installs mode_cbs->output as dst->output. If the
ICMP route back to the sender resolves to an IP-TFS SA, this function is
entered again while x->lock is still held.

If x' == x, the CPU spins on its own lock with BH disabled. One example is
a forwarded flow that hairpins back through the same tunnel.

With two IP-TFS dont-frag SAs in a hub-and-spoke setup, the lock order can
invert. CPU0 forwards A->B and CPU1 forwards B->A, so they could
deadlock on x_A->lock and x_B->lock.

If the return SA is not IP-TFS, xfrm_output_one() takes a lock of the same
lockdep class, which would produce a recursive locking report.

This patch sends a few more frames to the ICMP branch: vxlan frames with
skb->sk == NULL and frames owned by a TIME_WAIT socket. Most of the risk
comes from the existing forwarded path.

Would it be safer to send the ICMP or local error after spin_unlock_bh()?
That could mean doing the too-big check before taking the lock, or
collecting the rejected skbs and handling them after unlocking.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127142550.66326-1-rmustafin%40cloudlinux.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-28 14:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 14:25 [PATCH ipsec] xfrm: iptfs: report the too big error to the frame's own socket Rustam Mustafin
2026-11-28 14:56 ` 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