mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH ipsec 0/2] xfrm: iptfs: fix a panic and a use-after-free on output
@ 2026-11-18  0:54 Andrii Tereshchenko
  2026-11-18  0:54 ` [PATCH ipsec 1/2] xfrm: iptfs: don't modify the shared info of cloned skbs " Andrii Tereshchenko
  2026-11-18  0:54 ` [PATCH ipsec 2/2] xfrm: iptfs: hold the dst while a packet waits on the output queue Andrii Tereshchenko
  0 siblings, 2 replies; 3+ messages in thread
From: Andrii Tereshchenko @ 2026-11-18  0:54 UTC (permalink / raw)
  To: Steffen Klassert, Herbert Xu, David S. Miller
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Christian Hopps, netdev, ipsec, linux-kernel, security,
	Andrii Tereshchenko

TCP that a host sends through its own IP-TFS SA can panic the kernel.

The bugs are in the IP-TFS output path, net/xfrm/xfrm_iptfs.c. They
exist since v6.14 and reproduce on mainline v7.4-rc3, commit
aebb72744764 ("Linux 7.4-rc3"). Ordinary TCP retransmissions trigger
them; no crafted packet is involved. The kernel either panics with
skb_over_panic in the ESP output path, or the IP-TFS delay timer
reads a dst that was already freed. Where unprivileged user
namespaces are allowed, a user without capabilities can set up such
an SA in its own namespaces and panic the kernel. This series fixes
both bugs.

Details:

The panic: iptfs_output_queued() appends inner packets to
skb_shinfo(skb)->frag_list of the first skb of an aggregate without
owning that shared info. For local TCP the first skb is a clone of the
skb TCP keeps for retransmission, so the original gets a frag_list
that its len and data_len do not count. When TCP retransmits it and
the new clone is aggregated behind another skb,
iptfs_rehome_fraglist() subtracts the stale list's length and len goes
negative. ESP then copies the skb and skb_put() panics:

  skbuff: skb_over_panic: ... len:-340 put:-340 ... end:0x180
  kernel BUG at net/core/skbuff.c:215!
  Call Trace:
   skb_put
   skb_copy
   skb_cow_data
   esp_output_head
   esp_output
   xfrm_output_resume
   iptfs_delay_timer

The use-after-free: iptfs_output_collect() queues the skb for the
delay timer without taking a reference on its dst. Local TCP attaches
its dst with skb_dst_set_noref(), and RCU can free it while the skb
waits:

  BUG: KASAN: slab-use-after-free in iptfs_delay_timer
  The buggy address belongs to the cache xfrm_dst of size 296

The input path needs no such fix: xfrm_input() calls skb_dst_force()
before the type and mode input handlers run.

The series:

  1/2  Unclone the first skb before appending to it. Send a cloned
       skb that has a frag_list on its own, and do not take page
       frags from a cloned skb.
  2/2  Take the dst reference with skb_dst_force() in
       iptfs_output_collect(), before the skb is queued.

Affected: since commit 0e4fbf013fa5 ("xfrm: iptfs: add user packet
(tunnel ingress) handling"), v6.14. iptfs_output_collect(),
iptfs_enqueue(), iptfs_rehome_fraglist() and iptfs_output_queued()
are unchanged from v6.14 to:

  mainline    aebb72744764 (v7.4-rc3)
  ipsec       f0e68014f4ac
  ipsec-next  7b6ab4dbc156

CONFIG_XFRM_IPTFS defaults to n. Current Ubuntu, Fedora, Arch and
openSUSE Tumbleweed kernels build it as a module.

Conditions: CONFIG_XFRM_IPTFS, an SA in iptfs mode that carries TCP
originated on the host itself, and retransmissions, which any path
loss causes. TCP that the host only forwards into the tunnel did not
trigger either bug in 8 runs. Creating the SA needs CAP_NET_ADMIN,
which a user has inside its own user and network namespaces: on
v7.4-rc3, uid 65534 set up the SAs that way and hit the panic. Only
the crash is verified. Whether the use-after-free can be exploited
further was not assessed.

Discovery: the panic was observed on a machine in real use during the
andrii.cloud (ARIN: AS402801) rollout. That was a distribution kernel
tainted by an out-of-tree video card module, so it was reproduced on
an untainted distribution kernel and then on mainline. The
use-after-free appeared under KASAN while reproducing the panic on
mainline.

Reproduction: v7.4-rc3 on x86_64, defconfig plus kvm_guest.config
with KASAN, IP-TFS built in, in a KVM guest, not tainted. No kernel
modification and no fault injection. Three network namespaces form a
client, an IP-TFS gateway and an HTTPS server that is the other
IP-TFS endpoint. Clients fetch a 50 KB page for 40 seconds while
netem drops 5% of the packets sent to the client, so the server
retransmits through its SA. init-delay is 20 ms. The kernel config
and full console logs are available on request.

Fix verification: most boots of the unpatched kernel crashed, with
the use-after-free or, in a few boots, the panic. No boot with the
series crashed, and KASAN reported no use-after-free in any boot that
had 2/2.

The series applies to ipsec f0e68014f4ac and builds there and on
v7.4-rc3 without W=1 warnings. The boots ran v7.4-rc3, where
net/xfrm/xfrm_iptfs.c is identical. Kernel selftests were not run;
none of them covers IP-TFS.

A reproducer is available to maintainers on request.

Mitigation: use tunnel mode instead of iptfs mode on SAs that carry
locally generated TCP.

Related work: this is not commit d042487dc118 ("xfrm: iptfs: fix stack
OOB read in iptfs_skb_reset_frag_walk()"), CVE-2026-98372, and not the
pending series "xfrm: iptfs: fix queued receive state lifetime".
Neither touches the output path.

Link: https://lore.kernel.org/20260930050307.1978654-1-roshaen09@gmail.com

The crash analysis, the patches, the reproducer and this text were
produced with an AI coding assistant (without CVP) and reviewed by 
the submitter.

Andrii Tereshchenko (2):
  xfrm: iptfs: don't modify the shared info of cloned skbs on output
  xfrm: iptfs: hold the dst while a packet waits on the output queue

 net/xfrm/xfrm_iptfs.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)


base-commit: f0e68014f4ac1653b2980ab76744f4dfdffdbac5
-- 
2.53.0


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

end of thread, other threads:[~2026-11-18  0:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18  0:54 [PATCH ipsec 0/2] xfrm: iptfs: fix a panic and a use-after-free on output Andrii Tereshchenko
2026-11-18  0:54 ` [PATCH ipsec 1/2] xfrm: iptfs: don't modify the shared info of cloned skbs " Andrii Tereshchenko
2026-11-18  0:54 ` [PATCH ipsec 2/2] xfrm: iptfs: hold the dst while a packet waits on the output queue Andrii Tereshchenko

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®