Skip to content

xfrm: XFRM_MSG_MIGRATE_STATE new netlink message

Antony Antony linux-doc lkml netdev selinux 9 versions – In review

Get series with b4
b4 am [email protected] change-id migrate-state-063ee0342680

Versions newest first

  1. v9 Latest16 patches 1 replyIn review
  2. v814 patches 15 repliesSuperseded
  3. v714 patches 0 repliesSuperseded
Earlier versions · 6
VersionPostedPatchesRepliesStatus
v614 patches3 repliesSuperseded inferred link
v58 patches25 repliesSuperseded inferred link
v45 patches5 repliesSuperseded inferred link
v2 posting 2/24 patches2 repliesSuperseded inferred link
v2 posting 1/24 patches0 repliesSuperseded inferred link
v16 patches6 repliesSuperseded

Patches in v9 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/16xfrm: remove redundant assignmentsnet/xfrm/xfrm_state.c+0 -20 replies
2/16xfrm: add extack to xfrm_init_stateinclude/net/xfrm.h net/ipv4/ipcomp.c net/ipv6/ipcomp6.c +2 more+7 -70 replies
3/16xfrm: allow migration from UDP encapsulated to non-encapsulated ESPnet/xfrm/xfrm_state.c+2 -80 replies
4/16xfrm: fix NAT-related field inheritance in SA migrationnet/xfrm/xfrm_state.c+2 -10 replies
5/16xfrm: rename reqid in xfrm_migrateinclude/net/xfrm.h net/key/af_key.c net/xfrm/xfrm_policy.c +2 more+13 -130 replies
6/16xfrm: split xfrm_state_migrate into create and install functionsinclude/net/xfrm.h net/xfrm/xfrm_state.c+64 -200 replies
7/16xfrm: check family before comparing addresses in migratenet/xfrm/xfrm_state.c+4 -30 replies
8/16xfrm: add state synchronization after migrationinclude/net/xfrm.h net/xfrm/xfrm_state.c+41 -160 replies
9/16xfrm: add error messages to state migrationnet/xfrm/xfrm_state.c+7 -20 replies
10/16xfrm: move encap and xuo into struct xfrm_migrateinclude/net/xfrm.h net/xfrm/xfrm_policy.c net/xfrm/xfrm_state.c+12 -190 replies
11/16xfrm: refactor XFRMA_MTIMER_THRESH validation into a helpernet/xfrm/xfrm_user.c+18 -110 replies
12/16xfrm: extract address family and selector validation helpersnet/xfrm/xfrm_user.c+44 -360 replies
13/16xfrm: make xfrm_dev_state_add xuo parameter constinclude/net/xfrm.h net/xfrm/xfrm_device.c+5 -30 replies
14/16xfrm: add XFRM_MSG_MIGRATE_STATE for single SA migrationinclude/net/xfrm.h include/uapi/linux/xfrm.h net/xfrm/xfrm_compat.c +4 more+405 -170 replies
15/16xfrm: restrict netlink attributes for XFRM_MSG_MIGRATE_STATEnet/xfrm/xfrm_user.c+24 -00 replies
16/16xfrm: add documentation for XFRM_MSG_MIGRATE_STATEDocumentation/networking/xfrm/index.rst Documentation/networking/xfrm/xfrm_migrate_state.rst+275 -00 replies

Reviews trailers per patch

7 of 16 patches have a Reviewed-by or Acked-by.

PatchSabrina DubrocaYan Yan
1/16R-b
2/16R-b
3/16R-b T-b
4/16R-b
5/16
6/16R-b
7/16
8/16
9/16R-b
10/16R-b
11/16
12/16
13/16
14/16
15/16
16/16

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v9 thread

Cover letter [PATCH ipsec-next v9 00/16] xfrm: XFRM_MSG_MIGRATE_STATE new netlink message

The current XFRM_MSG_MIGRATE interface is tightly coupled to policy and SA migration, and it lacks the information required to reliably migrate individual SAs. This makes it unsuitable for IKEv2 deployments, dual-stack setups (IPv4/IPv6), and scenarios where policies are managed externally (e.g., by daemons other than the IKE daemon).

Mandatory SA selector list
The current API requires a non-empty SA selector list, which does not reflect the IKEv2 use case.
A single Child SA may correspond to multiple policies,
and SA discovery already occurs via address and reqid matching. With dual-stack Child SAs this leads to excessive churn: the current method would have to be called up to six times (in/out/fwd × v4/v6) on SA, while the new method only requires two calls.

Selectors lack SPI (and marks)
XFRM_MSG_MIGRATE cannot uniquely identify an SA when multiple SAs share the same policies (per-CPU SAs, SELinux label-based SAs, etc.). Without the SPI, the kernel may update the wrong SA instance.

Reqid cannot be changed
Some implementations allocate reqids based on traffic selectors. In host-to-host or selector-changing scenarios, the reqid must change, which the current API cannot express.

Because strongSwan and other implementations manage policies independently of the kernel, an interface that updates only a specific SA - with complete and unambiguous identification - is required.

SA Selector, x->sel, can't be changed, especially Transport mode.

XFRM_MSG_MIGRATE_STATE provides that interface. It supports migration of a single SA via xfrm_usersa_id (including SPI) and we fix encap removal in this patch set, reqid updates, address changes, and other SA-specific parameters. It avoids the structural limitations of XFRM_MSG_MIGRATE and provides a simpler, extensible mechanism for precise per-SA migration without involving policies.
This method also allows migtrating SA selectors typically used with host-to-host in Transport mode.

New migration steps: first install block policy, remove the old policy, call XFRM_MSG_MIGRATE_STATE for each state, then re-install the policies and remove the block policy.

If the target SA tuple (daddr, SPI, proto, family) is already occupied, the operation returns -EEXIST. In this case the original SA is not preserved. Userspace must handle -EEXIST by re-establishing the SA at the IKE level and manage policies.

---
v8->v9: address v8 review Sabrina and Steffen
- split const xuo cleanup
- input validation

Link to v8: https://lore.kernel.org/all/[email protected]/
v7->v8: - removed the unknown-flags validation block

Link to v7: https://patch.msgid.link/[email protected]
v6->v7: - add SA selectoor migration
- fixes to commit messages
- white space removal

Link to v6: https://lore.kernel.org/r/[email protected]
v5->v6: - add mark to look up SA.
- restrict netlink attributes in new method
- address review feedback from Sabrina
- add new patch to fix existing inter-family address comparison
- add extack xfrm_state_init()
- Feedback from Yan : omit-to-inherit add migrating marks
- Drop missing __rcu annotation on nlsk, Sabrina has a better patch

Link to v5: https://lore.kernel.org/all/[email protected]/
v4->v5: add synchronize after migrate and delete it inside a lock
- split xfrm_state_migrate into create and install functions

Link to v4: https://lore.kernel.org/all/[email protected]/
v3->v4: add patch to fix pre-existing missing __rcu annotation on nlsk

v2->v3: - fix commit message formatting

Link to v2: https://lore.kernel.org/all/[email protected]/

Lint to v1: https://lore.kernel.org/all/[email protected]/
v1->v2: dropped 6/6. That check is already there where the func is called
- merged patch 4/6 and 5/6, to fix use uninitialized value
- fix commit messages

---
Antony Antony (16):
xfrm: remove redundant assignments
xfrm: add extack to xfrm_init_state
xfrm: allow migration from UDP encapsulated to non-encapsulated ESP
xfrm: fix NAT-related field inheritance in SA migration
xfrm: rename reqid in xfrm_migrate
xfrm: split xfrm_state_migrate into create and install functions
xfrm: check family before comparing addresses in migrate
xfrm: add state synchronization after migration
xfrm: add error messages to state migration
xfrm: move encap and xuo into struct xfrm_migrate
xfrm: refactor XFRMA_MTIMER_THRESH validation into a helper
xfrm: extract address family and selector validation helpers
xfrm: make xfrm_dev_state_add xuo parameter const
xfrm: add XFRM_MSG_MIGRATE_STATE for single SA migration
xfrm: restrict netlink attributes for XFRM_MSG_MIGRATE_STATE
xfrm: add documentation for XFRM_MSG_MIGRATE_STATE

 Documentation/networking/xfrm/index.rst            |   1 +
 .../networking/xfrm/xfrm_migrate_state.rst         | 274 ++++++++++++
 include/net/xfrm.h                                 |  78 +++-
 include/uapi/linux/xfrm.h                          |  25 ++
 net/ipv4/ipcomp.c                                  |   2 +-
 net/ipv6/ipcomp6.c                                 |   2 +-
 net/key/af_key.c                                   |  12 +-
 net/xfrm/xfrm_compat.c                             |   5 +-
 net/xfrm/xfrm_device.c                             |   2 +-
 net/xfrm/xfrm_policy.c                             |  25 +-
 net/xfrm/xfrm_state.c                              | 144 ++++---
 net/xfrm/xfrm_user.c                               | 468 ++++++++++++++++++---
 security/selinux/nlmsgtab.c                        |   3 +-
 13 files changed, 903 insertions(+), 138 deletions(-)

---
base-commit: a77d172177f3754ebd70123c78c75a6efa9eec2a
change-id: migrate-state-063ee0342680

Best regards,

Signature · 1 line
Antony Antony <[email protected]>