[PATCH ipsec v2 0/2] xfrm: refuse route optimization mode for ESP

From: Kyuwon Cho

Date: Tue Nov 24 2026 - 21:37:13 EST


From: ChoKyuWon <kyuwoncho18@xxxxxxxxx>

An ESP state in route optimization mode can be created, and its first
packet hits the WARN_ON_ONCE()s in xfrm_state_mtu() and
xfrm_inner_mode_input(). Patch 1 accepts the mode in
verify_newsa_info() only for DSTOPTS and ROUTING, as in v1. Patch 2,
as Sabrina suggested, also makes ah_init_state(), esp_init_state() and
esp6_init_state() refuse the modes they do not support, like
ah6_init_state() already does.

To Sabrina's questions: XFRM_MODE_IN_TRIGGER is already refused by
verify_newsa_info() ("Unsupported mode"). AH or ESP over IPv4 cannot
get route optimization mode at all: xfrm4_mode_map has no entry for it,
so __xfrm_init_state() fails with -EPROTONOSUPPORT before
ah_init_state() runs. So only ESP over IPv6 reaches these WARNs, and
the IPv4 part of patch 2 is for consistency.

The issue was found by an LLM-guided test generator that we are
developing as a research prototype.

v2:
- Patch 1: say that esp6_init_state() accepts any mode instead of
"treats" an unknown mode as transport (Sabrina).
- Patch 2 is new (Sabrina, Steffen).
v1: https://lore.kernel.org/netdev/179550330841.535592.4607028415857424638@xxxxxxxxx/

The patches were written with LLM assistance; we reviewed and tested
them on the ipsec tree. ESP over IPv6 in route optimization mode is
refused with -EINVAL with patch 1, with patch 2 alone, and with both,
and the reproducer no longer warns. ESP and AH in transport, tunnel and
BEET mode over IPv4 and IPv6, and DSTOPTS and ROUTING states in route
optimization mode, are still accepted.

Kyuwon Cho (2):
xfrm: allow route optimization mode only for DSTOPTS and ROUTING
states
xfrm: refuse modes that AH and ESP do not support

net/ipv4/ah4.c | 11 ++++++++++-
net/ipv4/esp4.c | 18 +++++++++++++++---
net/ipv6/esp6.c | 6 +++++-
net/xfrm/xfrm_user.c | 9 ++++++++-
4 files changed, 38 insertions(+), 6 deletions(-)

--
2.43.0