pull request (net-next): ipsec-next 2026-06-12
Subsystems (6)
Steffen Klassert
maintainercover pull request (net-next): ipsec-next 2026-06-12
1) Replace the open-coded manual cleanup in xfrm_add_policy() error path with xfrm_policy_destroy() for consistency with xfrm_policy_construct().
From Deepanshu Kartikey.
2) Limit XFRMA_TFCPAD to a sensible maximum (max IP length, 64k) since u32 is excessive for traffic flow confidentiality padding. From David Ahern.
3) Add a new netlink message XFRM_MSG_MIGRATE_STATE that allows migrating individual IPsec SAs independently of their policies. The existing XFRM_MSG_MIGRATE is tightly coupled to policy+SA migration, lacks SPI for unique SA identification, and cannot express reqid changes or migrate Transport mode selectors. The new interface identifies the SA via SPI and mark, supports reqid changes, address family changes, encap removal, and uses an atomic create+install flow under x->lock to prevent SN/IV reuse during AEAD SA migration.
From Antony Antony.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit 790ead9394860e7d70c5e0e50a35b243e909a618:
Documentation: net/smc: correct old value of smcr_max_recv_wr (2026-04-27 16:49:39 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git tags/ipsec-next-2026-06-12
for you to fetch changes up to 355f808d8a11fa69b19dfd8811bc87d97830f5d6:
Merge branch 'xfrm: XFRM_MSG_MIGRATE_STATE new netlink message' (2026-06-09 16:02:12 +0200)
----------------------------------------------------------------
ipsec-next-2026-06-12
----------------------------------------------------------------
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
David Ahern (1):
xfrm: Reject excessive values for XFRMA_TFCPAD
Deepanshu Kartikey (1):
xfrm: cleanup error path in xfrm_add_policy()
Steffen Klassert (1):
Merge branch 'xfrm: XFRM_MSG_MIGRATE_STATE new netlink message'
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 | 481 ++++++++++++++++++--- security/selinux/nlmsgtab.c | 3 +- 13 files changed, 912 insertions(+), 142 deletions(-) create mode 100644 Documentation/networking/xfrm/xfrm_migrate_state.rst
Steffen Klassert
maintainerPATCH 1/18 xfrm: cleanup error path in xfrm_add_policy()
From: Deepanshu Kartikey <[email protected]>
Replace the open-coded manual cleanup in the error path of xfrm_add_policy() with xfrm_policy_destroy(), which already handles all the necessary cleanup internally. This is consistent with how xfrm_policy_construct() handles its own error paths.
The walk.dead flag must be set before calling xfrm_policy_destroy() as required by BUG_ON(!policy->walk.dead).
--- net/xfrm/xfrm_user.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/xfrm/xfrm_user.c +2 -3
@@ -2267,9 +2267,8 @@ static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh,if (err) {xfrm_dev_policy_delete (xp); -xfrm_dev_policy_free (xp); -security_xfrm_policy_free (xp->security); -kfree (xp); + xp->walk.dead =1 ; +xfrm_policy_destroy (xp);return err; }
Signature · 1 line
2.43.0
Re: [PATCH 01/18] xfrm: cleanup error path in xfrm_add_policy()
This series was applied to netdev/net-next.git (main) by Steffen Klassert <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Steffen Klassert <[email protected]>:
Quoted 8 lines · On Fri, 12 Jun 2026 09:46:17 +0200 you wrote:
From: Deepanshu Kartikey <[email protected]>
Replace the open-coded manual cleanup in the error path of
xfrm_add_policy()withxfrm_policy_destroy(), which already handles all the necessary cleanup internally. This is consistent with howxfrm_policy_construct()handles its own error paths.[...]
Here is the summary with links:
- [01/18] xfrm: cleanup error path in xfrm_add_policy()
https://git.kernel.org/netdev/net-next/c/a77d172177f3 - [02/18] xfrm: Reject excessive values for XFRMA_TFCPAD https://git.kernel.org/netdev/net-next/c/41c4d3b26f5e - [03/18] xfrm: remove redundant assignments https://git.kernel.org/netdev/net-next/c/440bf355d32e - [04/18] xfrm: add extack to xfrm_init_state https://git.kernel.org/netdev/net-next/c/231a1744dc43 - [05/18] xfrm: allow migration from UDP encapsulated to non-encapsulated ESP https://git.kernel.org/netdev/net-next/c/b8addb8884f2 - [06/18] xfrm: fix NAT-related field inheritance in SA migration https://git.kernel.org/netdev/net-next/c/364e165e0b63 - [07/18] xfrm: rename reqid in xfrm_migrate https://git.kernel.org/netdev/net-next/c/e2e92714d081 - [08/18] xfrm: split xfrm_state_migrate into create and install functions https://git.kernel.org/netdev/net-next/c/8de53883a4bf - [09/18] xfrm: check family before comparing addresses in migrate https://git.kernel.org/netdev/net-next/c/b2cb192b95e5 - [10/18] xfrm: add state synchronization after migration https://git.kernel.org/netdev/net-next/c/bac7a60e2678 - [11/18] xfrm: add error messages to state migration https://git.kernel.org/netdev/net-next/c/15e5d32de6bf - [12/18] xfrm: move encap and xuo into struct xfrm_migrate https://git.kernel.org/netdev/net-next/c/1d97daee3038 - [13/18] xfrm: refactor XFRMA_MTIMER_THRESH validation into a helper https://git.kernel.org/netdev/net-next/c/92550d30c69b - [14/18] xfrm: extract address family and selector validation helpers https://git.kernel.org/netdev/net-next/c/38d400e5d0fd - [15/18] xfrm: make xfrm_dev_state_add xuo parameter const https://git.kernel.org/netdev/net-next/c/8eed5ba25734 - [16/18] xfrm: add XFRM_MSG_MIGRATE_STATE for single SA migration https://git.kernel.org/netdev/net-next/c/a9d155ea9b44 - [17/18] xfrm: restrict netlink attributes for XFRM_MSG_MIGRATE_STATE https://git.kernel.org/netdev/net-next/c/c4460171d78a - [18/18] xfrm: add documentation for XFRM_MSG_MIGRATE_STATE https://git.kernel.org/netdev/net-next/c/c13c0cc6f52e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Steffen Klassert
maintainerPATCH 2/18 xfrm: Reject excessive values for XFRMA_TFCPAD
In reply to Steffen KlassertFrom: David Ahern <[email protected]>
tfcpad is a u32, but that full range is excessive for padding. Limit it to max IP length (64k).
--- net/xfrm/xfrm_user.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/xfrm/xfrm_user.c +7 -1
@@ -937,8 +937,14 @@ static struct xfrm_state *xfrm_state_construct(struct net *net, attrs[XFRMA_ALG_COMP], extack))) goto error; -if (attrs[XFRMA_TFCPAD ]) +if (attrs[XFRMA_TFCPAD ]) { x->tfcpad =nla_get_u32 (attrs[XFRMA_TFCPAD ]); +if (x->tfcpad >IP_MAX_MTU ) { +NL_SET_ERR_MSG (extack,"Excessive TFC padding" ); + err = -EINVAL ; + goto error; + } + }xfrm_mark_get (attrs, &x->mark);
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 3/18 xfrm: remove redundant assignments
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
These assignments are overwritten within the same function further down
commit e8961c50ee9cc ("xfrm: Refactor migration setup during the cloning process")x->props.family = m->new_family;
Which actually moved it in the
commit e03c3bba351f9 ("xfrm: Fix xfrm migrate issues when address family changes")
And the initial
commit 80c9abaabf428 ("[XFRM]: Extension for dynamic update of endpoint address(es)")
added x->props.saddr = orig->props.saddr; and memcpy(&xc->props.saddr, &m->new_saddr, sizeof(xc->props.saddr));
--- net/xfrm/xfrm_state.c | 2 -- 1 file changed, 2 deletions(-)
net/xfrm/xfrm_state.c +0 -2
@@ -1980,8 +1980,6 @@ static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig, x->props.mode = orig->props.mode; x->props.replay_window = orig->props.replay_window; x->props.reqid = orig->props.reqid; - x->props.family = orig->props.family; - x->props.saddr = orig->props.saddr;if (orig->aalg) { x->aalg =xfrm_algo_auth_clone (orig->aalg);
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 4/18 xfrm: add extack to xfrm_init_state
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
Add a struct extack parameter to xfrm_init_state() and pass it through to __xfrm_init_state(). This allows validation errors detected during state initialization to propagate meaningful error messages back to userspace.
xfrm_state_migrate() now passes extack so that errors from the XFRM_MSG_MIGRATE_STATE path are properly reported. Callers without an extack context (af_key, ipcomp4, ipcomp6) pass NULL, preserving their existing behaviour.
--- include/net/xfrm.h | 2 +- net/ipv4/ipcomp.c | 2 +- net/ipv6/ipcomp6.c | 2 +- net/key/af_key.c | 2 +- net/xfrm/xfrm_state.c | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-)
include/net/xfrm.h +1 -1
@@ -1774,7 +1774,7 @@ u32 xfrm_replay_seqhi(struct xfrm_state *x, __be32 net_seq);int xfrm_init_replay (struct xfrm_state *x,struct netlink_ext_ack *extack);u32 xfrm_state_mtu (struct xfrm_state *x,int mtu);int __xfrm_init_state (struct xfrm_state *x,struct netlink_ext_ack *extack); -int xfrm_init_state (struct xfrm_state *x); +int xfrm_init_state (struct xfrm_state *x,struct netlink_ext_ack *extack);int xfrm_input (struct sk_buff *skb,int nexthdr,__be32 spi,int encap_type);int xfrm_input_resume (struct sk_buff *skb,int nexthdr); int xfrm_trans_queue_net(struct net *net, struct sk_buff *skb,
net/ipv4/ipcomp.c +1 -1
@@ -77,7 +77,7 @@ static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x)memcpy (&t->mark, &x->mark,sizeof (t->mark)); t->if_id = x->if_id; -if (xfrm_init_state (t)) +if (xfrm_init_state (t,NULL )) goto error;atomic_set (&t->tunnel_users,1 );
net/ipv6/ipcomp6.c +1 -1
@@ -95,7 +95,7 @@ static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x)memcpy (&t->mark, &x->mark,sizeof (t->mark)); t->if_id = x->if_id; -if (xfrm_init_state (t)) +if (xfrm_init_state (t,NULL )) goto error;atomic_set (&t->tunnel_users,1 );
net/key/af_key.c +1 -1
@@ -1299,7 +1299,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, } } - err =xfrm_init_state (x); + err =xfrm_init_state (x,NULL );if (err) goto out;
net/xfrm/xfrm_state.c +3 -3
@@ -2143,7 +2143,7 @@ struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x,if (!xc)return NULL ; -if (xfrm_init_state (xc) <0 ) +if (xfrm_init_state (xc, extack) <0 ) goto error;/* configure the hardware if offload is requested */
@@ -3238,11 +3238,11 @@ int __xfrm_init_state(struct xfrm_state *x, struct netlink_ext_ack *extack)EXPORT_SYMBOL (__xfrm_init_state); -int xfrm_init_state (struct xfrm_state *x) +int xfrm_init_state (struct xfrm_state *x,struct netlink_ext_ack *extack) {int err; - err =__xfrm_init_state (x,NULL ); + err =__xfrm_init_state (x, extack);if (err)return err;
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 5/18 xfrm: allow migration from UDP encapsulated to non-encapsulated ESP
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
The current code prevents migrating an SA from UDP encapsulation to plain ESP. This is needed when moving from a NATed path to a non-NATed one, for example when switching from IPv4+NAT to IPv6.
Only copy the existing encapsulation during migration if the encap attribute is explicitly provided.
Note: PF_KEY's SADB_X_MIGRATE always passes encap=NULL and never supported encapsulation in migration. PF_KEY is deprecated and was in feature freeze when UDP encapsulation was added to xfrm.
--- net/xfrm/xfrm_state.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
net/xfrm/xfrm_state.c +2 -8
@@ -2008,14 +2008,8 @@ static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig, } x->props.calgo = orig->props.calgo; -if (encap || orig->encap) { -if (encap) - x->encap =kmemdup (encap,sizeof (*x->encap), -GFP_KERNEL ); -else - x->encap =kmemdup (orig->encap,sizeof (*x->encap), -GFP_KERNEL ); - +if (encap) { + x->encap =kmemdup (encap,sizeof (*x->encap),GFP_KERNEL );if (!x->encap) goto error; }
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 6/18 xfrm: fix NAT-related field inheritance in SA migration
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
During SA migration via xfrm_state_clone_and_setup(), nat_keepalive_interval was silently dropped and never copied to the new SA. mapping_maxage was unconditionally copied even when migrating to a non-encapsulated SA.
Both fields are only meaningful when UDP encapsulation (NAT-T) is in use. Move mapping_maxage and add nat_keepalive_interval inside the existing if (encap) block, so both are inherited when migrating with encapsulation and correctly absent when migrating without it.
--- net/xfrm/xfrm_state.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/xfrm/xfrm_state.c +2 -1
@@ -2012,6 +2012,8 @@ static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig, x->encap =kmemdup (encap,sizeof (*x->encap),GFP_KERNEL );if (!x->encap) goto error; + x->mapping_maxage = orig->mapping_maxage; + x->nat_keepalive_interval = orig->nat_keepalive_interval; }if (orig->security)
@@ -2046,7 +2048,6 @@ static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig, x->km.seq = orig->km.seq; x->replay = orig->replay; x->preplay = orig->preplay; - x->mapping_maxage = orig->mapping_maxage; x->lastused = orig->lastused; x->new_mapping =0 ; x->new_mapping_sport =0 ;
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 7/18 xfrm: rename reqid in xfrm_migrate
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
In preparation for a later patch in this series s/reqid/old_reqid/. No functional change.
--- include/net/xfrm.h | 2 +- net/key/af_key.c | 10 +++++----- net/xfrm/xfrm_policy.c | 4 ++-- net/xfrm/xfrm_state.c | 6 +++--- net/xfrm/xfrm_user.c | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-)
include/net/xfrm.h +1 -1
@@ -685,7 +685,7 @@ struct xfrm_migrate {u8 proto;u8 mode;u16 reserved; -u32 reqid; +u32 old_reqid;u16 old_family;u16 new_family; };
net/key/af_key.c +5 -5
@@ -2554,7 +2554,7 @@ static int ipsecrequests_to_migrate(struct sadb_x_ipsecrequest *rq1, int len,if ((mode =pfkey_mode_to_xfrm (rq1->sadb_x_ipsecrequest_mode)) <0 )return -EINVAL ; m->mode = mode; - m->reqid = rq1->sadb_x_ipsecrequest_reqid; + m->old_reqid = rq1->sadb_x_ipsecrequest_reqid;return ((int )(rq1->sadb_x_ipsecrequest_len + rq2->sadb_x_ipsecrequest_len));
@@ -3655,15 +3655,15 @@ static int pfkey_send_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,if (mode <0 ) goto err;if (set_ipsecrequest (skb, mp->proto, mode, - (mp->reqid ?IPSEC_LEVEL_UNIQUE :IPSEC_LEVEL_REQUIRE ), - mp->reqid, mp->old_family, + (mp->old_reqid ?IPSEC_LEVEL_UNIQUE :IPSEC_LEVEL_REQUIRE ), + mp->old_reqid, mp->old_family, &mp->old_saddr, &mp->old_daddr) <0 ) goto err;/* new ipsecrequest */ if (set_ipsecrequest (skb, mp->proto, mode, - (mp->reqid ?IPSEC_LEVEL_UNIQUE :IPSEC_LEVEL_REQUIRE ), - mp->reqid, mp->new_family, + (mp->old_reqid ?IPSEC_LEVEL_UNIQUE :IPSEC_LEVEL_REQUIRE ), + mp->old_reqid, mp->new_family, &mp->new_saddr, &mp->new_daddr) <0 ) goto err; }
net/xfrm/xfrm_policy.c +2 -2
@@ -4538,7 +4538,7 @@ static int migrate_tmpl_match(const struct xfrm_migrate *m, const struct xfrm_tmint match =0 ;if (t->mode == m->mode && t->id.proto == m->proto && - (m->reqid ==0 || t->reqid == m->reqid)) { + (m->old_reqid ==0 || t->reqid == m->old_reqid)) {switch (t->mode) {case XFRM_MODE_TUNNEL :case XFRM_MODE_BEET :
@@ -4632,7 +4632,7 @@ static int xfrm_migrate_check(const struct xfrm_migrate *m, int num_migrate, sizeof(m[i].old_saddr)) && m[i].proto == m[j].proto && m[i].mode == m[j].mode && - m[i].reqid == m[j].reqid && + m[i].old_reqid == m[j].old_reqid && m[i].old_family == m[j].old_family) {NL_SET_ERR_MSG (extack,"Entries in the MIGRATE attribute's list must be unique" );return -EINVAL ;
net/xfrm/xfrm_state.c +3 -3
@@ -2081,14 +2081,14 @@ struct xfrm_state *xfrm_migrate_state_find(struct xfrm_migrate *m, struct net *nspin_lock_bh (&net->xfrm.xfrm_state_lock); -if (m->reqid) { +if (m->old_reqid) { h =xfrm_dst_hash (net, &m->old_daddr, &m->old_saddr, - m->reqid, m->old_family); + m->old_reqid, m->old_family);hlist_for_each_entry (x,xfrm_state_deref_prot (net->xfrm.state_bydst, net) + h, bydst) {if (x->props.mode != m->mode || x->id.proto != m->proto)continue ; -if (m->reqid && x->props.reqid != m->reqid) +if (m->old_reqid && x->props.reqid != m->old_reqid)continue ;if (if_id !=0 && x->if_id != if_id)continue ;
net/xfrm/xfrm_user.c +2 -2
@@ -3110,7 +3110,7 @@ static int copy_from_user_migrate(struct xfrm_migrate *ma, ma->proto = um->proto; ma->mode = um->mode; - ma->reqid = um->reqid; + ma->old_reqid = um->reqid; ma->old_family = um->old_family; ma->new_family = um->new_family;
@@ -3193,7 +3193,7 @@ static int copy_to_user_migrate(const struct xfrm_migrate *m, struct sk_buff *skmemset (&um,0 ,sizeof (um)); um.proto = m->proto; um.mode = m->mode; - um.reqid = m->reqid; + um.reqid = m->old_reqid; um.old_family = m->old_family;memcpy (&um.old_daddr, &m->old_daddr,sizeof (um.old_daddr));memcpy (&um.old_saddr, &m->old_saddr,sizeof (um.old_saddr));
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 8/18 xfrm: split xfrm_state_migrate into create and install functions
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
To prepare for subsequent patches, split xfrm_state_migrate() into two functions:
- xfrm_state_migrate_create(): creates the migrated state
- xfrm_state_migrate_install(): installs it into the state table
splitting will help to avoid SN/IV reuse when migrating AEAD SA.
And add const whenever possible.
No functional change.
--- include/net/xfrm.h | 11 +++++++ net/xfrm/xfrm_state.c | 73 +++++++++++++++++++++++++++++++------------ 2 files changed, 64 insertions(+), 20 deletions(-)
include/net/xfrm.h +11 -0
@@ -1895,6 +1895,17 @@ int km_migrate(const struct xfrm_selector *sel, u8 dir, u8 type, const struct xfrm_encap_tmpl *encap);struct xfrm_state *xfrm_migrate_state_find (struct xfrm_migrate *m,struct net *net,u32 if_id); +struct xfrm_state *xfrm_state_migrate_create (struct xfrm_state *x, +const struct xfrm_migrate *m, +const struct xfrm_encap_tmpl *encap, +struct net *net, +struct xfrm_user_offload *xuo, +struct netlink_ext_ack *extack); +int xfrm_state_migrate_install (const struct xfrm_state *x, +struct xfrm_state *xc, +const struct xfrm_migrate *m, +struct xfrm_user_offload *xuo, +struct netlink_ext_ack *extack); struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x, struct xfrm_migrate *m, struct xfrm_encap_tmpl *encap,
net/xfrm/xfrm_state.c +53 -20
97 lines not on this page · raw message
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 9/18 xfrm: check family before comparing addresses in migrate
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
When migrating between different address families, xfrm_addr_equal() cannot meaningfully compare addresses, different lengths. Only call xfrm_addr_equal() when families match, and take the xfrm_state_insert() path when addresses are equal.
--- net/xfrm/xfrm_state.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/xfrm/xfrm_state.c +4 -3
@@ -2159,10 +2159,11 @@ int xfrm_state_migrate_install(const struct xfrm_state *x, struct xfrm_user_offload *xuo, struct netlink_ext_ack *extack) { - if (xfrm_addr_equal(&x->id.daddr, &m->new_daddr, m->new_family)) { +if (m->new_family == m->old_family && +xfrm_addr_equal (&x->id.daddr, &m->new_daddr, m->new_family)) {/* -* Care is needed when the destination address -* of the state is to be updated as it is a part of triplet. +* Care is needed when the destination address of the state is +* to be updated as it is a part of triplet. */ xfrm_state_insert (xc); }else {
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 10/18 xfrm: add state synchronization after migration
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
Add xfrm_migrate_sync() to copy curlft and replay state from the old SA to the new one before installation. The function allocates no memory, so it can be called under a spinlock. In preparation for a subsequent patch in this series.
A subsequent patch calls this under x->lock, atomically capturing the latest lifetime counters and replay state from the original SA and deleting it in the same critical section to prevent SN/IV reuse for XFRM_MSG_MIGRATE_STATE method.
No functional change.
--- include/net/xfrm.h | 46 ++++++++++++++++++++++++++++++++++--------- net/xfrm/xfrm_state.c | 11 ++++------- 2 files changed, 41 insertions(+), 16 deletions(-)
include/net/xfrm.h +37 -9
@@ -2024,23 +2024,51 @@ static inline unsigned int xfrm_replay_state_esn_len(struct xfrm_replay_state_es#ifdef CONFIG_XFRM_MIGRATE static inline int xfrm_replay_clone (struct xfrm_state *x, -struct xfrm_state *orig) +const struct xfrm_state *orig) { +/* Counters synced later in xfrm_replay_sync() */ - x->replay_esn =kmemdup (orig->replay_esn, + x->replay = orig->replay; + x->preplay = orig->preplay; + +if (orig->replay_esn) { + x->replay_esn =kmemdup (orig->replay_esn,xfrm_replay_state_esn_len (orig->replay_esn),GFP_KERNEL ); -if (!x->replay_esn) -return -ENOMEM ; - x->preplay_esn =kmemdup (orig->preplay_esn, -xfrm_replay_state_esn_len (orig->preplay_esn), -GFP_KERNEL ); -if (!x->preplay_esn) -return -ENOMEM ; +if (!x->replay_esn) +return -ENOMEM ; + x->preplay_esn =kmemdup (orig->preplay_esn, +xfrm_replay_state_esn_len (orig->preplay_esn), +GFP_KERNEL ); +if (!x->preplay_esn) +return -ENOMEM ; + }return 0 ; } +static inline void xfrm_replay_sync (struct xfrm_state *x,const struct xfrm_state *orig) +{ + x->replay = orig->replay; + x->preplay = orig->preplay; + +if (orig->replay_esn) { +memcpy (x->replay_esn, orig->replay_esn, +xfrm_replay_state_esn_len (orig->replay_esn)); + +memcpy (x->preplay_esn, orig->preplay_esn, +xfrm_replay_state_esn_len (orig->preplay_esn)); + } +} + +static inline void xfrm_migrate_sync (struct xfrm_state *x, +const struct xfrm_state *orig) +{ +/* called under lock so no race conditions or mallocs allowed */ +memcpy (&x->curlft, &orig->curlft,sizeof (x->curlft)); +xfrm_replay_sync (x, orig); +} +static inline struct xfrm_algo_aead *xfrm_algo_aead_clone (struct xfrm_algo_aead *orig) {return kmemdup (orig,aead_len (orig),GFP_KERNEL );
net/xfrm/xfrm_state.c +4 -7
@@ -2027,10 +2027,8 @@ static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig, goto error; } -if (orig->replay_esn) { -if (xfrm_replay_clone (x, orig)) - goto error; - } +if (xfrm_replay_clone (x, orig)) + goto error;memcpy (&x->mark, &orig->mark,sizeof (x->mark));memcpy (&x->props.smark, &orig->props.smark,sizeof (x->props.smark));
@@ -2043,11 +2041,8 @@ static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig, x->tfcpad = orig->tfcpad; x->replay_maxdiff = orig->replay_maxdiff; x->replay_maxage = orig->replay_maxage; -memcpy (&x->curlft, &orig->curlft,sizeof (x->curlft)); x->km.state = orig->km.state; x->km.seq = orig->km.seq; - x->replay = orig->replay; - x->preplay = orig->preplay; x->lastused = orig->lastused; x->new_mapping =0 ; x->new_mapping_sport =0 ;
@@ -2193,6 +2188,8 @@ struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x,if (!xc)return NULL ; +xfrm_migrate_sync (xc, x); +if (xfrm_state_migrate_install (x, xc, m, xuo, extack) <0 )return NULL ;
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 11/18 xfrm: add error messages to state migration
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
Add descriptive(extack) error messages for all error paths in state migration. This improves diagnostics by providing clear feedback when migration fails.
After xfrm_init_state() use NL_SET_ERR_MSG_WEAK() as fallback for error paths not yet propagating extack e.g. mode_cbs->init_state()
No functional change.
--- net/xfrm/xfrm_state.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/xfrm/xfrm_state.c +7 -2
@@ -2130,11 +2130,15 @@ struct xfrm_state *xfrm_state_migrate_create(struct xfrm_state *x,struct xfrm_state *xc; xc =xfrm_state_clone_and_setup (x, encap, m); -if (!xc) +if (!xc) { +NL_SET_ERR_MSG (extack,"Failed to clone and setup state" );return NULL ; + } -if (xfrm_init_state (xc, extack) <0 ) +if (xfrm_init_state (xc, extack) <0 ) { +NL_SET_ERR_MSG_WEAK (extack,"Failed to initialize migrated state" ); goto error; + }/* configure the hardware if offload is requested */ if (xuo &&xfrm_dev_state_add (net, xc, xuo, extack))
@@ -2163,6 +2167,7 @@ int xfrm_state_migrate_install(const struct xfrm_state *x,xfrm_state_insert (xc); }else {if (xfrm_state_add (xc) <0 ) { +NL_SET_ERR_MSG (extack,"Failed to add migrated state" );if (xuo)xfrm_dev_state_delete (xc); xc->km.state =XFRM_STATE_DEAD ;
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 12/18 xfrm: move encap and xuo into struct xfrm_migrate
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
In preparation for an upcoming patch, move the xfrm_encap_tmpl and xfrm_user_offload pointers from separate parameters into struct xfrm_migrate, reducing the parameter count of xfrm_state_migrate_create(), xfrm_state_migrate_install() and xfrm_state_migrate()
The fields are placed after the four xfrm_address_t members where the struct is naturally 8-byte aligned, avoiding padding.
No functional change.
--- include/net/xfrm.h | 7 ++----- net/xfrm/xfrm_policy.c | 4 +++- net/xfrm/xfrm_state.c | 20 +++++++------------- 3 files changed, 12 insertions(+), 19 deletions(-)
include/net/xfrm.h +2 -5
@@ -682,6 +682,8 @@ struct xfrm_migrate {xfrm_address_t old_saddr;xfrm_address_t new_daddr;xfrm_address_t new_saddr; +struct xfrm_encap_tmpl *encap; +struct xfrm_user_offload *xuo;u8 proto;u8 mode;u16 reserved;
@@ -1897,20 +1899,15 @@ struct xfrm_state *xfrm_migrate_state_find(struct xfrm_migrate *m, struct net *n u32 if_id);struct xfrm_state *xfrm_state_migrate_create (struct xfrm_state *x,const struct xfrm_migrate *m, -const struct xfrm_encap_tmpl *encap,struct net *net, -struct xfrm_user_offload *xuo,struct netlink_ext_ack *extack);int xfrm_state_migrate_install (const struct xfrm_state *x,struct xfrm_state *xc,const struct xfrm_migrate *m, -struct xfrm_user_offload *xuo,struct netlink_ext_ack *extack);struct xfrm_state *xfrm_state_migrate (struct xfrm_state *x,struct xfrm_migrate *m, -struct xfrm_encap_tmpl *encap,struct net *net, -struct xfrm_user_offload *xuo,struct netlink_ext_ack *extack); int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type, struct xfrm_migrate *m, int num_bundles,
net/xfrm/xfrm_policy.c +3 -1
@@ -4680,7 +4680,9 @@ int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,if ((x =xfrm_migrate_state_find (mp, net, if_id))) { x_cur[nx_cur] = x; nx_cur++; - xc =xfrm_state_migrate (x, mp, encap, net, xuo, extack); + mp->encap = encap; + mp->xuo = xuo; + xc =xfrm_state_migrate (x, mp, net, extack);if (xc) { x_new[nx_new] = xc; nx_new++;
net/xfrm/xfrm_state.c +7 -13
@@ -1966,7 +1966,6 @@ static inline int clone_security(struct xfrm_state *x, struct xfrm_sec_ctx *secu }static struct xfrm_state *xfrm_state_clone_and_setup (struct xfrm_state *orig, -const struct xfrm_encap_tmpl *encap,const struct xfrm_migrate *m) {struct net *net =xs_net (orig);
@@ -2008,8 +2007,8 @@ static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig, } x->props.calgo = orig->props.calgo; -if (encap) { - x->encap =kmemdup (encap,sizeof (*x->encap),GFP_KERNEL ); +if (m->encap) { + x->encap =kmemdup (m->encap,sizeof (*x->encap),GFP_KERNEL );if (!x->encap) goto error; x->mapping_maxage = orig->mapping_maxage;
@@ -2122,14 +2121,12 @@ EXPORT_SYMBOL(xfrm_migrate_state_find);struct xfrm_state *xfrm_state_migrate_create (struct xfrm_state *x,const struct xfrm_migrate *m, -const struct xfrm_encap_tmpl *encap,struct net *net, -struct xfrm_user_offload *xuo,struct netlink_ext_ack *extack) {struct xfrm_state *xc; - xc =xfrm_state_clone_and_setup (x, encap, m); + xc =xfrm_state_clone_and_setup (x, m);if (!xc) {NL_SET_ERR_MSG (extack,"Failed to clone and setup state" );return NULL ;
@@ -2141,7 +2138,7 @@ struct xfrm_state *xfrm_state_migrate_create(struct xfrm_state *x, }/* configure the hardware if offload is requested */ -if (xuo &&xfrm_dev_state_add (net, xc, xuo, extack)) +if (m->xuo &&xfrm_dev_state_add (net, xc, m->xuo, extack)) goto error;return xc;
@@ -2155,7 +2152,6 @@ EXPORT_SYMBOL(xfrm_state_migrate_create);int xfrm_state_migrate_install (const struct xfrm_state *x,struct xfrm_state *xc,const struct xfrm_migrate *m, -struct xfrm_user_offload *xuo,struct netlink_ext_ack *extack) { if (m->new_family == m->old_family &&
@@ -2168,7 +2164,7 @@ int xfrm_state_migrate_install(const struct xfrm_state *x, }else {if (xfrm_state_add (xc) <0 ) {NL_SET_ERR_MSG (extack,"Failed to add migrated state" ); -if (xuo) +if (m->xuo)xfrm_dev_state_delete (xc); xc->km.state =XFRM_STATE_DEAD ;xfrm_state_put (xc);
@@ -2182,20 +2178,18 @@ EXPORT_SYMBOL(xfrm_state_migrate_install);struct xfrm_state *xfrm_state_migrate (struct xfrm_state *x,struct xfrm_migrate *m, -struct xfrm_encap_tmpl *encap,struct net *net, -struct xfrm_user_offload *xuo,struct netlink_ext_ack *extack) {struct xfrm_state *xc; - xc =xfrm_state_migrate_create (x, m, encap, net, xuo, extack); + xc =xfrm_state_migrate_create (x, m, net, extack);if (!xc)return NULL ;xfrm_migrate_sync (xc, x); -if (xfrm_state_migrate_install (x, xc, m, xuo, extack) <0 ) +if (xfrm_state_migrate_install (x, xc, m, extack) <0 )return NULL ;return xc;
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 13/18 xfrm: refactor XFRMA_MTIMER_THRESH validation into a helper
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
Extract verify_mtimer_thresh() to consolidate the XFRMA_MTIMER_THRESH validation logic shared between the add_sa and upcoming patch.
--- net/xfrm/xfrm_user.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
net/xfrm/xfrm_user.c +18 -11
@@ -248,6 +248,22 @@ static inline int verify_replay(struct xfrm_usersa_info *p,return 0 ; } +static int verify_mtimer_thresh (bool has_encap,u8 dir, +struct netlink_ext_ack *extack) +{ +if (!has_encap) { +NL_SET_ERR_MSG (extack, +"MTIMER_THRESH requires encapsulation" ); +return -EINVAL ; + } +if (dir ==XFRM_SA_DIR_OUT ) { +NL_SET_ERR_MSG (extack, +"MTIMER_THRESH should not be set on output SA" ); +return -EINVAL ; + } +return 0 ; +} +static int verify_newsa_info (struct xfrm_usersa_info *p,struct nlattr **attrs,struct netlink_ext_ack *extack)
@@ -455,18 +471,9 @@ static int verify_newsa_info(struct xfrm_usersa_info *p, err =0 ;if (attrs[XFRMA_MTIMER_THRESH ]) { -if (!attrs[XFRMA_ENCAP ]) { -NL_SET_ERR_MSG (extack,"MTIMER_THRESH attribute can only be set on ENCAP states" ); - err = -EINVAL ; - goto out; - } - -if (sa_dir ==XFRM_SA_DIR_OUT ) { -NL_SET_ERR_MSG (extack, -"MTIMER_THRESH attribute should not be set on output SA" ); - err = -EINVAL ; + err =verify_mtimer_thresh (!!attrs[XFRMA_ENCAP ], sa_dir, extack); +if (err) goto out; - } }if (sa_dir ==XFRM_SA_DIR_OUT ) {
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 14/18 xfrm: extract address family and selector validation helpers
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
Extract verify_xfrm_family() and verify_selector_prefixlen() from verify_newsa_info() to allow reuse by other netlink handlers.
verify_xfrm_family() validates that a given address family is AF_INET or AF_INET6 (with CONFIG_IPV6 guard).
verify_selector_prefixlen() validates that the selector prefix lengths are within the bounds for the given address family.
No functional change.
--- net/xfrm/xfrm_user.c | 80 ++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 36 deletions(-)
net/xfrm/xfrm_user.c +44 -36
@@ -264,66 +264,74 @@ static int verify_mtimer_thresh(bool has_encap, u8 dir,return 0 ; } -static int verify_newsa_info (struct xfrm_usersa_info *p, -struct nlattr **attrs, -struct netlink_ext_ack *extack) +static int verify_xfrm_family (u16 family,struct netlink_ext_ack *extack) { -int err; -u8 sa_dir =nla_get_u8_default (attrs[XFRMA_SA_DIR ],0 ); -u16 family = p->sel.family; - - err = -EINVAL ; -switch (p->family) { +switch (family) {case AF_INET : -break ; - +return 0 ;case AF_INET6 :#if IS_ENABLED (CONFIG_IPV6 ) -break ; +return 0 ;#else - err = -EAFNOSUPPORT ;NL_SET_ERR_MSG (extack,"IPv6 support disabled" ); - goto out; +return -EAFNOSUPPORT ;#endif -default :NL_SET_ERR_MSG (extack,"Invalid address family" ); - goto out; +return -EINVAL ; } +} -if (!family && !(p->flags &XFRM_STATE_AF_UNSPEC )) - family = p->family; - +static int verify_selector_prefixlen (u16 family, +const struct xfrm_selector *sel, +struct netlink_ext_ack *extack) +{switch (family) {case AF_UNSPEC : -break ; - +return 0 ;case AF_INET : -if (p->sel.prefixlen_d >32 || p->sel.prefixlen_s >32 ) { -NL_SET_ERR_MSG (extack,"Invalid prefix length in selector (must be <= 32 for IPv4)" ); - goto out; +if (sel->prefixlen_d >32 || sel->prefixlen_s >32 ) { +NL_SET_ERR_MSG (extack, +"Invalid prefix length in selector (must be <= 32 for IPv4)" ); +return -EINVAL ; } - -break ; - +return 0 ;case AF_INET6 :#if IS_ENABLED (CONFIG_IPV6 ) -if (p->sel.prefixlen_d >128 || p->sel.prefixlen_s >128 ) { -NL_SET_ERR_MSG (extack,"Invalid prefix length in selector (must be <= 128 for IPv6)" ); - goto out; +if (sel->prefixlen_d >128 || sel->prefixlen_s >128 ) { +NL_SET_ERR_MSG (extack, +"Invalid prefix length in selector (must be <= 128 for IPv6)" ); +return -EINVAL ; } - -break ; +return 0 ;#else NL_SET_ERR_MSG (extack,"IPv6 support disabled" ); - err = -EAFNOSUPPORT ; - goto out; +return -EAFNOSUPPORT ;#endif -default :NL_SET_ERR_MSG (extack,"Invalid address family in selector" ); - goto out; +return -EINVAL ; } +} + +static int verify_newsa_info (struct xfrm_usersa_info *p, +struct nlattr **attrs, +struct netlink_ext_ack *extack) +{ +int err; +u8 sa_dir =nla_get_u8_default (attrs[XFRMA_SA_DIR ],0 ); +u16 family = p->sel.family; + + err =verify_xfrm_family (p->family, extack); +if (err) + goto out; + +if (!family && !(p->flags &XFRM_STATE_AF_UNSPEC )) + family = p->family; + + err =verify_selector_prefixlen (family, &p->sel, extack); +if (err) + goto out; err = -EINVAL ;switch (p->id.proto) {
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 15/18 xfrm: make xfrm_dev_state_add xuo parameter const
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
The xuo pointer is not modified by xfrm_dev_state_add(); make it const.
--- include/net/xfrm.h | 6 ++++-- net/xfrm/xfrm_device.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-)
include/net/xfrm.h +4 -2
@@ -2104,7 +2104,7 @@ void xfrm_dev_resume(struct sk_buff *skb);void xfrm_dev_backlog (struct softnet_data *sd);struct sk_buff *validate_xmit_xfrm (struct sk_buff *skb,netdev_features_t features,bool *again);int xfrm_dev_state_add (struct net *net,struct xfrm_state *x, -struct xfrm_user_offload *xuo, +const struct xfrm_user_offload *xuo,struct netlink_ext_ack *extack); int xfrm_dev_policy_add(struct net *net, struct xfrm_policy *xp, struct xfrm_user_offload *xuo, u8 dir,
@@ -2175,7 +2175,9 @@ static inline struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_feareturn skb; } -static inline int xfrm_dev_state_add (struct net *net,struct xfrm_state *x,struct xfrm_user_offload *xuo,struct netlink_ext_ack *extack) +static inline int xfrm_dev_state_add (struct net *net,struct xfrm_state *x, +const struct xfrm_user_offload *xuo, +struct netlink_ext_ack *extack) {return 0 ; }
net/xfrm/xfrm_device.c +1 -1
@@ -229,7 +229,7 @@ struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t featurEXPORT_SYMBOL_GPL (validate_xmit_xfrm);int xfrm_dev_state_add (struct net *net,struct xfrm_state *x, -struct xfrm_user_offload *xuo, +const struct xfrm_user_offload *xuo,struct netlink_ext_ack *extack) {int err;
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 16/18 xfrm: add XFRM_MSG_MIGRATE_STATE for single SA migration
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
Add a new netlink method to migrate a single xfrm_state. Unlike the existing migration mechanism (SA + policy), this supports migrating only the SA and allows changing the reqid.
The SA is looked up via xfrm_usersa_id, which uniquely identifies it, so old_saddr is not needed. old_daddr is carried in xfrm_usersa_id.daddr.
The reqid is invariant in the old migration.
--- include/net/xfrm.h | 10 +- include/uapi/linux/xfrm.h | 25 +++ net/xfrm/xfrm_compat.c | 5 +- net/xfrm/xfrm_policy.c | 17 ++ net/xfrm/xfrm_state.c | 29 +++- net/xfrm/xfrm_user.c | 333 +++++++++++++++++++++++++++++++++++- security/selinux/nlmsgtab.c | 3 +- 7 files changed, 405 insertions(+), 17 deletions(-)
include/net/xfrm.h +9 -1
@@ -684,12 +684,20 @@ struct xfrm_migrate {xfrm_address_t new_saddr;struct xfrm_encap_tmpl *encap;struct xfrm_user_offload *xuo; +struct xfrm_mark old_mark; +const struct xfrm_mark *new_mark; +struct xfrm_mark smark;u8 proto;u8 mode; -u16 reserved; +u16 msg_type;/* XFRM_MSG_MIGRATE or XFRM_MSG_MIGRATE_STATE */ +u32 flags;u32 old_reqid; +u32 new_reqid; +u32 nat_keepalive_interval; +u32 mapping_maxage;u16 old_family;u16 new_family; +const struct xfrm_selector *new_sel; };#define XFRM_KM_TIMEOUT 30
include/uapi/linux/xfrm.h +25 -0
@@ -227,6 +227,9 @@ enum {#define XFRM_MSG_SETDEFAULT XFRM_MSG_SETDEFAULT XFRM_MSG_GETDEFAULT,#define XFRM_MSG_GETDEFAULT XFRM_MSG_GETDEFAULT + + XFRM_MSG_MIGRATE_STATE, +#define XFRM_MSG_MIGRATE_STATE XFRM_MSG_MIGRATE_STATE __XFRM_MSG_MAX };#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)
@@ -507,6 +510,28 @@ struct xfrm_user_migrate {__u16 new_family; }; +struct xfrm_user_migrate_state { +struct xfrm_usersa_id id; +xfrm_address_t new_daddr; +xfrm_address_t new_saddr; +struct xfrm_mark old_mark; +struct xfrm_selector new_sel; +__u32 new_reqid; +__u32 flags; +__u16 new_family; +__u16 reserved; +}; + +/* Flags for xfrm_user_migrate_state.flags */ +enum xfrm_migrate_state_flags { +XFRM_MIGRATE_STATE_CLEAR_OFFLOAD =1 ,/* do not inherit offload from existing SA */ +XFRM_MIGRATE_STATE_UPDATE_H2H_SEL =2 ,/* update H2H selector from new daddr/saddr */ +}; + +/* All flags defined as of this header version; unknown bits are rejected. */ +#define XFRM_MIGRATE_STATE_KNOWN_FLAGS \ + (XFRM_MIGRATE_STATE_CLEAR_OFFLOAD | XFRM_MIGRATE_STATE_UPDATE_H2H_SEL) +struct xfrm_user_mapping {struct xfrm_usersa_id id;__u32 reqid;
net/xfrm/xfrm_compat.c +4 -1
@@ -94,7 +94,8 @@ static const int compat_msg_min[XFRM_NR_MSGTYPES] = { [XFRM_MSG_GETSADINFO - XFRM_MSG_BASE] = sizeof(u32), [XFRM_MSG_NEWSPDINFO - XFRM_MSG_BASE] = sizeof(u32), [XFRM_MSG_GETSPDINFO - XFRM_MSG_BASE] = sizeof(u32), - [XFRM_MSG_MAPPING -XFRM_MSG_BASE ] =XMSGSIZE (xfrm_user_mapping) + [XFRM_MSG_MAPPING - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_mapping), + [XFRM_MSG_MIGRATE_STATE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_migrate_state), };static const struct nla_policy compat_policy[XFRMA_MAX +1 ] = {
@@ -162,6 +163,7 @@ static struct nlmsghdr *xfrm_nlmsg_put_compat(struct sk_buff *skb,case XFRM_MSG_NEWAE :case XFRM_MSG_REPORT :case XFRM_MSG_MIGRATE : +case XFRM_MSG_MIGRATE_STATE :case XFRM_MSG_NEWSADINFO :case XFRM_MSG_NEWSPDINFO :case XFRM_MSG_MAPPING :
@@ -498,6 +500,7 @@ static int xfrm_xlate32(struct nlmsghdr *dst, const struct nlmsghdr *src,case XFRM_MSG_GETAE :case XFRM_MSG_REPORT :case XFRM_MSG_MIGRATE : +case XFRM_MSG_MIGRATE_STATE :case XFRM_MSG_NEWSADINFO :case XFRM_MSG_GETSADINFO :case XFRM_MSG_NEWSPDINFO :
net/xfrm/xfrm_policy.c +17 -0
@@ -4643,6 +4643,21 @@ static int xfrm_migrate_check(const struct xfrm_migrate *m, int num_migrate,return 0 ; } +/* +* Fill migrate fields that are invariant in XFRM_MSG_MIGRATE: inherited +* from the existing SA unchanged. XFRM_MSG_MIGRATE_STATE can update these. +*/ +static void xfrm_migrate_copy_old (const struct xfrm_state *x, +struct xfrm_migrate *mp) +{ + mp->msg_type =XFRM_MSG_MIGRATE ; + mp->smark = x->props.smark; + mp->new_reqid = x->props.reqid; + mp->nat_keepalive_interval = x->nat_keepalive_interval; + mp->mapping_maxage = x->mapping_maxage; + mp->new_mark = &x->mark; +} + int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type, struct xfrm_migrate *m, int num_migrate, struct xfrm_kmaddress *k, struct net *net,
@@ -4682,6 +4697,8 @@ int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type, nx_cur++; mp->encap = encap; mp->xuo = xuo; +xfrm_migrate_copy_old (x, mp); + xc =xfrm_state_migrate (x, mp, net, extack);if (xc) { x_new[nx_new] = xc;
net/xfrm/xfrm_state.c +22 -7
@@ -1974,11 +1974,25 @@ static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig, goto out;memcpy (&x->id, &orig->id,sizeof (x->id)); -memcpy (&x->sel, &orig->sel,sizeof (x->sel)); +if (m->msg_type ==XFRM_MSG_MIGRATE_STATE ) { +if (m->flags &XFRM_MIGRATE_STATE_UPDATE_H2H_SEL ) { +u8 prefixlen = (m->new_family ==AF_INET6 ) ?128 :32 ; + + x->sel = orig->sel; + x->sel.family = m->new_family; + x->sel.prefixlen_d = prefixlen; + x->sel.prefixlen_s = prefixlen; + x->sel.daddr = m->new_daddr; + x->sel.saddr = m->new_saddr; + }else { + x->sel = *m->new_sel; + } + }else { + x->sel = orig->sel; + }memcpy (&x->lft, &orig->lft,sizeof (x->lft)); x->props.mode = orig->props.mode; x->props.replay_window = orig->props.replay_window; - x->props.reqid = orig->props.reqid;if (orig->aalg) { x->aalg =xfrm_algo_auth_clone (orig->aalg);
@@ -2011,8 +2025,8 @@ static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig, x->encap =kmemdup (m->encap,sizeof (*x->encap),GFP_KERNEL );if (!x->encap) goto error; - x->mapping_maxage = orig->mapping_maxage; - x->nat_keepalive_interval = orig->nat_keepalive_interval; + x->mapping_maxage = m->mapping_maxage; + x->nat_keepalive_interval = m->nat_keepalive_interval; }if (orig->security)
@@ -2029,8 +2043,9 @@ static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig,if (xfrm_replay_clone (x, orig)) goto error; -memcpy (&x->mark, &orig->mark,sizeof (x->mark)); -memcpy (&x->props.smark, &orig->props.smark,sizeof (x->props.smark)); + x->mark = m->new_mark ? *m->new_mark : m->old_mark; + + x->props.smark = m->smark; x->props.flags = orig->props.flags; x->props.extra_flags = orig->props.extra_flags;
@@ -2053,7 +2068,7 @@ static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig, goto error; } - + x->props.reqid = m->new_reqid; x->props.family = m->new_family;memcpy (&x->id.daddr, &m->new_daddr,sizeof (x->id.daddr));memcpy (&x->props.saddr, &m->new_saddr,sizeof (x->props.saddr));
net/xfrm/xfrm_user.c +326 -7
388 lines not on this page · raw message
security/selinux/nlmsgtab.c +2 -1
@@ -128,6 +128,7 @@ static const struct nlmsg_perm nlmsg_xfrm_perms[] = { { XFRM_MSG_MAPPING, NETLINK_XFRM_SOCKET__NLMSG_READ }, { XFRM_MSG_SETDEFAULT, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, { XFRM_MSG_GETDEFAULT, NETLINK_XFRM_SOCKET__NLMSG_READ }, + { XFRM_MSG_MIGRATE_STATE, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, }; static const struct nlmsg_perm nlmsg_audit_perms[] = {
@@ -203,7 +204,7 @@ int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm)* structures at the top of this file with the new mappings * before updating the BUILD_BUG_ON() macro! */ -BUILD_BUG_ON (XFRM_MSG_MAX !=XFRM_MSG_GETDEFAULT ); +BUILD_BUG_ON (XFRM_MSG_MAX !=XFRM_MSG_MIGRATE_STATE );if (selinux_policycap_netlink_xperm ()) { *perm =NETLINK_XFRM_SOCKET__NLMSG ;
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 17/18 xfrm: restrict netlink attributes for XFRM_MSG_MIGRATE_STATE
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
Only accept XFRMA used in this method, reject the rest.
--- net/xfrm/xfrm_user.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
net/xfrm/xfrm_user.c +24 -0
@@ -3788,6 +3788,30 @@ static int xfrm_reject_unused_attr(int type, struct nlattr **attrs, } } +if (type ==XFRM_MSG_MIGRATE_STATE ) { +int i; + +for (i =0 ; i <=XFRMA_MAX ; i++) { +if (!attrs[i]) +continue ; + +switch (i) { +case XFRMA_MARK : +case XFRMA_ENCAP : +case XFRMA_OFFLOAD_DEV : +case XFRMA_SET_MARK : +case XFRMA_SET_MARK_MASK : +case XFRMA_MTIMER_THRESH : +case XFRMA_NAT_KEEPALIVE_INTERVAL : +break ; +default : +NL_SET_ERR_MSG_ATTR (extack, attrs[i], +"Unsupported attribute in XFRM_MSG_MIGRATE_STATE" ); +return -EINVAL ; + } + } + } +return 0 ; }
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 18/18 xfrm: add documentation for XFRM_MSG_MIGRATE_STATE
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
Add documentation for the new XFRM_MSG_MIGRATE_STATE netlink message, which migrates a single SA identified by SPI and mark without involving policies.
The document covers the motivation and design differences from the existing XFRM_MSG_MIGRATE, the SA lookup mechanism, supported attributes with their omit-to-inherit semantics, and usage examples.
--- Documentation/networking/xfrm/index.rst | 1 + .../networking/xfrm/xfrm_migrate_state.rst | 274 ++++++++++++++++++ 2 files changed, 275 insertions(+) create mode 100644 Documentation/networking/xfrm/xfrm_migrate_state.rst
Documentation/networking/xfrm/index.rst +1 -0
@@ -9,5 +9,6 @@ XFRM Framework xfrm_device xfrm_proc + xfrm_migrate_state xfrm_sync xfrm_sysctl
Documentation/networking/xfrm/xfrm_migrate_state.rst new file +274 -0
274 lines not on this page · raw message
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerQuoted 10 lines · On Fri, 12 Jun 2026 09:46:16 +0200 Steffen Klassert wrote:
3) Add a new netlink message
XFRM_MSG_MIGRATE_STATEthat allows migrating individual IPsec SAs independently of their policies. The existingXFRM_MSG_MIGRATEis tightly coupled to policy+SA migration, lacks SPI for unique SA identification, and cannot express reqid changes or migrate Transport mode selectors. The new interface identifies the SA via SPI and mark, supports reqid changes, address family changes, encap removal, and uses an atomic create+install flow underx->lockto prevent SN/IV reuse during AEAD SA migration.
From Antony Antony.
Hi! There are some Sashiko comments here, please follow up:
Quoted 12 lines · Jakub Kicinski
Quoted 10 lines · On Fri, 12 Jun 2026 09:46:16 +0200 Steffen Klassert wrote:
3) Add a new netlink message
XFRM_MSG_MIGRATE_STATEthat allows migrating individual IPsec SAs independently of their policies. The existingXFRM_MSG_MIGRATEis tightly coupled to policy+SA migration, lacks SPI for unique SA identification, and cannot express reqid changes or migrate Transport mode selectors. The new interface identifies the SA via SPI and mark, supports reqid changes, address family changes, encap removal, and uses an atomic create+install flow underx->lockto prevent SN/IV reuse during AEAD SA migration.
From Antony Antony.
Quoted 4 lines
Hi! There are some Sashiko comments here, please follow up:
Thanks Jakub. I have fixes and testing them now. And I will send fixes soon.
The comments didn't click until I realized xfrm_user_state_lookup() only keys on mark.v & mark.m, so distinct (v, m) pairs collapse to the same masked value. A lookup key of {0, 0} matches a source SA with mark {0, 0xffffff} (both mask to 0), but reusing {0, 0} as the migrated mark turns "match only mark 0x00" into "match all traffic".
Fix is copy from old SA than from old_mark passed along. This also pointed more issues.
-antony
Quoted 20 lines · Antony Antony
Quoted 12 lines · Jakub Kicinski
Quoted 10 lines · On Fri, 12 Jun 2026 09:46:16 +0200 Steffen Klassert wrote:
3) Add a new netlink message
XFRM_MSG_MIGRATE_STATEthat allows migrating individual IPsec SAs independently of their policies. The existingXFRM_MSG_MIGRATEis tightly coupled to policy+SA migration, lacks SPI for unique SA identification, and cannot express reqid changes or migrate Transport mode selectors. The new interface identifies the SA via SPI and mark, supports reqid changes, address family changes, encap removal, and uses an atomic create+install flow underx->lockto prevent SN/IV reuse during AEAD SA migration.
From Antony Antony.Quoted 4 lines
Hi! There are some Sashiko comments here, please follow up:
Thanks Jakub. I have fixes and testing them now. And I will send fixes soon.
Quoted 8 lines
The comments didn't click until I realized
xfrm_user_state_lookup()only keys on mark.v & mark.m, so distinct (v, m) pairs collapse to the same masked value. A lookup key of {0, 0} matches a source SA with mark {0,0xffffff} (both mask to 0), but reusing {0, 0} as the migrated mark turns "match only mark0x00" into "match all traffic".Fix is copy from old SA than from
old_markpassed along. This also pointed more issues.
I have fixes queued up for the issues Sashiko found, to send once the ipsec tree has net-next. What Sashiko pointed are corner cases. IMO a typical IKE/IPsec daemon would not trigger, but worth fixing.
The fixes address all four High findings and the Medium in patch 16/18. Finding 6 (patch 05/18, encap removal) was determined to be a false positive — already reviewed.
One tricky part worth noting: xfrm allows two SAs with the same SPI, src, dst, and proto, however different mark:
ip xfrm state add src 10.1.1.1 dst 10.1.1.2 spi 0x1000 .. mark 0x1 mask 0xff ip xfrm state add src 10.1.1.1 dst 10.1.1.2 spi 0x1000 .. mark 0x2 mask 0xff
ip x s
src 10.1.1.1 dst 10.1.1.2
proto esp spi 0x00001000 reqid 100 mode tunnel
replay-window 0
mark 0x2/0xff
aead rfc4106(gcm(aes)) 0x1111111111111111111111111111111111111111 96
anti-replay context: seq 0x0, oseq 0x0, bitmap 0x00000000
sel src 0.0.0.0/0 dst 0.0.0.0/0
src 10.1.1.1 dst 10.1.1.2
proto esp spi 0x00001000 reqid 100 mode tunnel
replay-window 0
mark 0x1/0xff
aead rfc4106(gcm(aes)) 0x1111111111111111111111111111111111111111 96
anti-replay context: seq 0x0, oseq 0x0, bitmap 0x00000000
sel src 0.0.0.0/0 dst 0.0.0.0/0Both are accepted: same SPI 0x1000, two distinct SAs with diffrent mark. Note that both SAs share the same key material and their independent oseq counters both start at 0 - the encrypted packets from each produces an identical AES-GCM IV.
Does anyone know whether this is intentional or accidental? Is there a use case that requires two SAs with identical crypto and replay counter, however, different marks?
This is also what makes state migration with Mark complex. Since xfrm permits two SAs to share the same SPI with different marks, migrating
a mark must check whether the target slot is already occupied.
The fix "xfrm: check mark changes for SA tuple collisions in XFRM_MSG_MIGRATE_STATE" does exactly that, using the effective lookup key m->v & m->m to detect a collision before proceeding.
Kernel selftests for this series are included in the tree. However, extensive testing is difficult on my end — *swan cannot easily create these cases.
Yan/Nathan,
would you be able to run the Android test suite against this branch? to test migrating SA with mark set.
https://github.com/antonyantony/linux/tree/migrate-state-fixes-v0
-antony
A message that is not in the archive (sent off-list or not yet received): CADHa2dAtGVsph3Kq0id7QqgNdJww0Q=Z1PK+=fomVxKE-Mmvjg@mail.gmail.com
Hi Antony,
I ran the following test cases and two—4.2 and 6—are worth disucssing:
1. Mark Inheritance: Creates one SA and migrates it without specifying a new mark. [PASSED]
2. Mark Update: Creates one SA with a specific mark and migrates it to a new specific mark. [PASSED]
3. State Update Isolation: Creates two SAs differing only by mark and verifies that migrating one does not affect the other. [PASSED]
4. Mark Collision:
4.1 [Specific Mark] Creates two SAs differing only by mark: SA
(mark_1) and an SA (mark_2). Verifies migrating SA (mark_1) to mark_2 fails with EEXIST and both SAs intact. [PASSED]
4.2 [Wildcard Mark] Creates two SAs differing only by mark: SA
(mark_1) and an SA (mark_none). Migrate the mark_none to mark_1. Expecting failure with EEXIST and both SAs intact. [FAILED: SA (mark_none) ends up being deleted]
5. Mark Mismatch:
5.1 Creates only a wildcard SA and verifying migration using a
specific mark fails with ESRCH; SA intact [PASSED]
5.2 Creates only one SA (mark_1) and verifying migration using amark_2 fails with ESRCH; SA intact [PASSED]
6. Mark Shadowing Failure:: Creates two SAs differing only by mark:
the first SA (mark_1) and the second SA (mark None). Migrating the SA (mark_1) fails with ESRCH, two SAs remain untouched [PASSED]
--------------------------------
My questions are as follows:
Regarding 4.2 I believe is a kernel bug. During the pre-migration collision check, the lookup for the mark_1 matches the wildcard SA itself first, causing the kernel to miss the collision with the existing specific SA with mark_1
At https://github.com/antonyantony/linux/blob/migrate-state-fixes-v0/net/xfrm/xfrm_user.c#L3450
x_new = xfrm_state_lookup(net, new_mark_key, &m.new_daddr, ----> BUG:
We are looking for the existence of SA (mark_1) but SA (mark_none) is returned.um->id.spi, um->id.proto, m.new_family);
if (x_new) {
xfrm_state_put(x_new);
if (x_new != x) { ----> BUG: We end up having x_new == x
NL_SET_ERR_MSG(extack, "New SA tuple already occupied");
err = -EEXIST;
goto out;
}/* self-match via wide mark mask; not a collision */
Would it be possible to traverse the entire list or create a lookup method for an exact match?
Regarding 6. I wrote the tests as per the kernel implementation but I'm not sure it is intended. Intuitively, this migration should succeed by finding and updating the specific SA (mark_1) instead of failing. Is this failure considered an acceptable limit, or should we aim to support exact-match lookup here?
Quoted 11 lines · Yan Yan
Hi Antony,
Sure, I'm happy to write and run some tests. I should be able to have the results by the end of the week.
--
--
Best,
Yan
--
--
Best,
Yan
Hi Yan,
thanks for testing. Would you please test on a new series?
Quoted 41 lines · Yan Yan
Hi Antony,
I ran the following test cases and two—4.2 and 6—are worth disucssing:
1. Mark Inheritance: Creates one SA and migrates it without specifying a new mark. [PASSED]
2. Mark Update: Creates one SA with a specific mark and migrates it to a new specific mark. [PASSED]
3. State Update Isolation: Creates two SAs differing only by mark and verifies that migrating one does not affect the other. [PASSED]
4. Mark Collision:
4.1 [Specific Mark] Creates two SAs differing only by mark: SA
(mark_1) and an SA (mark_2). Verifies migrating SA (mark_1) tomark_2fails with EEXIST and both SAs intact. [PASSED]
4.2 [Wildcard Mark] Creates two SAs differing only by mark: SA
(mark_1) and an SA (mark_none). Migrate themark_nonetomark_1. Expecting failure with EEXIST and both SAs intact. [FAILED: SA (mark_none) ends up being deleted]
5. Mark Mismatch:
5.1 Creates only a wildcard SA and verifying migration using a
specific mark fails with ESRCH; SA intact [PASSED]
5.2 Creates only one SA (mark_1) and verifying migration using amark_2fails with ESRCH; SA intact [PASSED]
6. Mark Shadowing Failure:: Creates two SAs differing only by mark:
the first SA (mark_1) and the second SA (mark None). Migrating the SA (mark_1) fails with ESRCH, two SAs remain untouched [PASSED]--------------------------------
My questions are as follows:Regarding 4.2 I believe is a kernel bug. During the pre-migration collision check, the lookup for the
mark_1matches the wildcard SA itself first, causing the kernel to miss the collision with the existing specific SA withmark_1At https://github.com/antonyantony/linux/blob/migrate-state-fixes-v0/net/xfrm/xfrm_user.c#L3450
x_new= xfrm_state_lookup(net,new_mark_key, &m.new_daddr, ----> BUG:
We are looking for the existence of SA (mark_1) but SA (mark_none) is returned.um->id.spi,um->id.proto, m.new_family);
Quoted 7 lines
if (x_new) {
xfrm_state_put(x_new);
if (x_new != x) { ----> BUG: We end up having x_new == x
NL_SET_ERR_MSG(extack, "New SA tuple already occupied");
err = -EEXIST;
goto out;
}this should be fixed no. Would please try again?
Quoted 10 lines
/* self-match via wide mark mask; not a collision */
Would it be possible to traverse the entire list or create a lookup method for an exact match?
Regarding 6. I wrote the tests as per the kernel implementation but I'm not sure it is intended. Intuitively, this migration should succeed by finding and updating the specific SA (
mark_1) instead of failing. Is this failure considered an acceptable limit, or should we aim to support exact-match lookup here?
While trying to fix MIGRATE_STATE I fell into a rabbit hole:)
I realized many methods have this issue. Just never noticed, as it would be a misconfiguration, and would likely cause operational issues rather than crashes.
However, given that xfrm accepts multiple identical SAs differing only in mark, a proper fix is to add __xfrm_state_locate_exact() for both spi and byaddr lookups. This should be used in all calls from userspace.
I just send a new series.
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
-antony
Hi Antony,
I agree it starts to feel very convoluted. Please see the results inline below
4.2. [Wildcard Mark] Creates two SAs differing only by mark: SA (mark_1) and an SA (mark_none). Migrating the mark_none to mark_1. Expecting it will fail with EEXIST and both SAs intact BUT the mark_none SA ends up being deleted.
The test fails the same way: EEXIST is returned and SA (mark_none) is deleted. I still think we need to fix the collision pre-check in the following block: x_new is expected to be SA(mark_1) but ends up being SA (mark_none)
// This probably should be xfrm_state_lookup_exact x_new = xfrm_state_lookup(net, new_mark_key, &m.new_daddr,
um->id.spi, um->id.proto,
m.new_family);
if (x_new) {
xfrm_state_put(x_new);
if (x_new != x) {
NL_SET_ERR_MSG(extack, "New SA tuple already occupied");
err = -EEXIST;
goto out;
}/* self-match via wide mark mask; not a collision */
6. Creates two SAs differing only by mark: first SA (mark_1) and secondly an SA (mark None).
Before the patch: Migrating the SA (mark_1) to mark_2 fails with ESRCH, two SAs remain untouched
After the patch: Migrating the SA (mark_1) to mark_2 fails with EEXIST, two SAs remain untouched
Thinking it through again I think the behavior of the new patch makes sense. This migration should not succeed because we also not allow adding a SA(mark_specific) after if there is a SA(mark_none) installed. So now the migration behavior is consistent with it.
All other tests still pass.
Quoted 81 lines · Antony Antony
Hi Yan,
thanks for testing. Would you please test on a new series?
Quoted 41 lines · Yan Yan
Hi Antony,
I ran the following test cases and two—4.2 and 6—are worth disucssing:
1. Mark Inheritance: Creates one SA and migrates it without specifying a new mark. [PASSED]
2. Mark Update: Creates one SA with a specific mark and migrates it to a new specific mark. [PASSED]
3. State Update Isolation: Creates two SAs differing only by mark and verifies that migrating one does not affect the other. [PASSED]
4. Mark Collision:
4.1 [Specific Mark] Creates two SAs differing only by mark: SA
(mark_1) and an SA (mark_2). Verifies migrating SA (mark_1) tomark_2fails with EEXIST and both SAs intact. [PASSED]
4.2 [Wildcard Mark] Creates two SAs differing only by mark: SA
(mark_1) and an SA (mark_none). Migrate themark_nonetomark_1. Expecting failure with EEXIST and both SAs intact. [FAILED: SA (mark_none) ends up being deleted]
5. Mark Mismatch:
5.1 Creates only a wildcard SA and verifying migration using a
specific mark fails with ESRCH; SA intact [PASSED]
5.2 Creates only one SA (mark_1) and verifying migration using amark_2fails with ESRCH; SA intact [PASSED]
6. Mark Shadowing Failure:: Creates two SAs differing only by mark:
the first SA (mark_1) and the second SA (mark None). Migrating the SA (mark_1) fails with ESRCH, two SAs remain untouched [PASSED]--------------------------------
My questions are as follows:Regarding 4.2 I believe is a kernel bug. During the pre-migration collision check, the lookup for the
mark_1matches the wildcard SA itself first, causing the kernel to miss the collision with the existing specific SA withmark_1At https://github.com/antonyantony/linux/blob/migrate-state-fixes-v0/net/xfrm/xfrm_user.c#L3450
x_new= xfrm_state_lookup(net,new_mark_key, &m.new_daddr, ----> BUG:
We are looking for the existence of SA (mark_1) but SA (mark_none) is returned.um->id.spi,um->id.proto, m.new_family);Quoted 7 lines
if (x_new) { xfrm_state_put(x_new); if (x_new != x) { ----> BUG: We end up having x_new == x NL_SET_ERR_MSG(extack, "New SA tuple already occupied"); err = -EEXIST; goto out; }this should be fixed no. Would please try again?
Quoted 10 lines
/* self-match via wide mark mask; not a collision */
Would it be possible to traverse the entire list or create a lookup method for an exact match?
Regarding 6. I wrote the tests as per the kernel implementation but I'm not sure it is intended. Intuitively, this migration should succeed by finding and updating the specific SA (
mark_1) instead of failing. Is this failure considered an acceptable limit, or should we aim to support exact-match lookup here?While trying to fix
MIGRATE_STATEI fell into a rabbit hole:)
I realized many methods have this issue. Just never noticed, as it would be a misconfiguration, and would likely cause operational issues rather than crashes.
However, given that xfrm accepts multiple identical SAs differing only in mark, a proper fix is to add__xfrm_state_locate_exact()for both spi and byaddr lookups. This should be used in all calls from userspace.I just send a new series.
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/-antony
Signature · 3 lines
-- Best, Yan