[PATCH net v2 0/3] xfrm: fix vti tunnel device use-after-free across async crypto resumption

From: Qihang

Date: Tue Oct 13 2026 - 03:50:25 EST


This replaces the v1 vti/vti6 series.

vti_input() and vti6_input_proto() cache the tunnel pointer in the skb
control buffer without taking a reference. With async crypto the
receive callback runs from the crypto completion, after a possible
device teardown, and dereferences the freed tunnel device.

The reference cannot simply be held in the input path and dropped in
the callback: the callback is not reached on every path (IPTFS frees
the outer skb itself, and the early drop for a non-valid state runs
with family still AF_UNSPEC), and on the success path the callback may
drop the last reference before xfrm_input() is done with skb->dev.

Make the reference travel with the skb instead: the receive callbacks
install the device in skb->dev and leave their reference with it, and
xfrm_input() releases it once the packet has been delivered.

Patch 3 covers vti, vti6 and xfrmi, the only receive callbacks that
replace skb->dev (esp, ah and ipcomp do not).

For Chris: patch 2 covers the outer-skb free paths in
__input_process_payload(), iptfs_input_ordered() and the reorder-window
free list. The deferred fragment (consume_skb(defer)), the reassembly
drop timer / __iptfs_reassem_done() and the state teardown still free
the skb directly; I left those alone for now.

Changes since v1:
- split into three patches: the first two fix the paths where the
receive callback is not dispatched at all, the third is the device
reference handling
- the reference is taken before delivery and released through a saved
pointer afterwards, instead of holding skb->dev after the callback
- v1: https://lore.kernel.org/netdev/20260930090813.73901-1-q.h.hack.winter@xxxxxxxxx/

Qihang (3):
xfrm: set the address family before the early invalid-state drop
xfrm: iptfs: run the receive callbacks before freeing the skb
xfrm: transfer the skb->dev reference to the input path

net/ipv4/ip_vti.c | 6 ++++++
net/ipv6/ip6_vti.c | 7 +++++++
net/xfrm/xfrm_inout.h | 2 ++
net/xfrm/xfrm_input.c | 35 ++++++++++++++++++++++++++++++++--
net/xfrm/xfrm_interface_core.c | 9 ++++++++-
net/xfrm/xfrm_iptfs.c | 6 +++---
6 files changed, 59 insertions(+), 6 deletions(-)

--
2.54.0 (Apple Git-157)