From: Steffen Klassert <steffen.klassert@secunet.com>
To: Antony Antony <antony@phenome.org>
Cc: Antony Antony <antony.antony@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
<netdev@vger.kernel.org>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Chiachang Wang <chiachangwang@google.com>,
Yan Yan <evitayan@google.com>, <devel@linux-ipsec.org>,
Simon Horman <horms@kernel.org>, Paul Moore <paul@paul-moore.com>,
Stephen Smalley <stephen.smalley.work@gmail.com>,
Ondrej Mosnacek <omosnace@redhat.com>,
<linux-kernel@vger.kernel.org>, <selinux@vger.kernel.org>
Subject: Re: [devel-ipsec] Re: [PATCH ipsec-next v4 5/5] xfrm: add XFRM_MSG_MIGRATE_STATE for single SA migration
Date: Fri, 23 Jan 2026 09:32:15 +0100 [thread overview]
Message-ID: <aXMyD4zss0wnXf7h@secunet.com> (raw)
In-Reply-To: <aXMN_m7_PFxr_AO8@Antony2201.local>
On Fri, Jan 23, 2026 at 06:58:22AM +0100, Antony Antony wrote:
> On Thu, Jan 22, 2026 at 11:50:16AM +0100, Steffen Klassert via Devel wrote:
> > On Thu, Jan 22, 2026 at 11:33:42AM +0100, Steffen Klassert wrote:
> > > On Mon, Jan 19, 2026 at 09:54:55AM +0100, Antony Antony wrote:
> > > > +
> > > > +static int xfrm_do_migrate_state(struct sk_buff *skb, struct nlmsghdr *nlh,
> > > > + struct nlattr **attrs, struct netlink_ext_ack *extack)
> > > > +{
> > > > + int err = -ESRCH;
> > > > + struct xfrm_state *x;
> > > > + struct net *net = sock_net(skb->sk);
> > > > + struct xfrm_encap_tmpl *encap = NULL;
> > > > + struct xfrm_user_offload *xuo = NULL;
> > > > + struct xfrm_migrate m = { .old_saddr.a4 = 0,};
> > > > + struct xfrm_user_migrate_state *um = nlmsg_data(nlh);
> > > > +
> > > > + if (!um->id.spi) {
> > > > + NL_SET_ERR_MSG(extack, "Invalid SPI 0x0");
> > > > + return -EINVAL;
> > > > + }
> > > > +
> > > > + err = copy_from_user_migrate_state(&m, um);
> > > > + if (err)
> > > > + return err;
> > > > +
> > > > + x = xfrm_user_state_lookup(net, &um->id, attrs, &err);
> > > > +
> > > > + if (x) {
> > > > + struct xfrm_state *xc;
> > > > +
> > > > + if (!x->dir) {
> > > > + NL_SET_ERR_MSG(extack, "State direction is invalid");
> > > > + err = -EINVAL;
> > > > + goto error;
> > > > + }
> > > > +
> > > > + if (attrs[XFRMA_ENCAP]) {
> > > > + encap = kmemdup(nla_data(attrs[XFRMA_ENCAP]),
> > > > + sizeof(*encap), GFP_KERNEL);
> > > > + if (!encap) {
> > > > + err = -ENOMEM;
> > > > + goto error;
> > > > + }
> > > > + }
> > > > + if (attrs[XFRMA_OFFLOAD_DEV]) {
> > > > + xuo = kmemdup(nla_data(attrs[XFRMA_OFFLOAD_DEV]),
> > > > + sizeof(*xuo), GFP_KERNEL);
> > > > + if (!xuo) {
> > > > + err = -ENOMEM;
> > > > + goto error;
> > > > + }
> > > > + }
> > > > + xc = xfrm_state_migrate(x, &m, encap, net, xuo, extack);
> > > > + if (xc) {
> > > > + xfrm_state_delete(x);
> > >
> > > This xfrm_state_delete() comes too late. You need to synchronize this
> > > with xfrm_state_clone_and_setup() by holding the state lock.
> > > Otherwise we might hand out the same sequence number etc. more than
> > > one time. Unfortunately xfrm_migrate() has the same problem, the
> > > error recovery mechanism in xfrm_migrate() looks broken.
> >
> > The xfrm_migrate() problem is nasty, looks like we can't recover
> > if the state migration fails. We probably have to delete the
> > states and wait for the userspace to insert new ones.
>
> userspace should notice the inconsistany. Most of them are ENOMEM or EMSGSIZE
>
> >
> > Another thing, xfrm_user_state_lookup() returns a reference on x,
> > you should drop it somewhere.
>
> There is a call a few lines bellow, the label was "error:" I renamed it to
> "out:" for clariy.
>
> +out:
> + xfrm_state_put(x);
Yes, this makes it more clear that we hit this even without error.
Maybe you should do a 'if (!X)' check on the retuen value of
xfrm_user_state_lookup(). This woulds make the structure of
the function even clearer.
next prev parent reply other threads:[~2026-01-23 8:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-19 8:53 [PATCH ipsec-next v4 0/5] xfrm: XFRM_MSG_MIGRATE_STATE new netlink message Antony Antony
2026-01-19 8:53 ` [PATCH ipsec-next v4 1/5] xfrm: add missing __rcu annotation to nlsk Antony Antony
2026-01-19 8:54 ` [PATCH ipsec-next v4 2/5] xfrm: remove redundant assignments Antony Antony
2026-01-19 8:54 ` [PATCH ipsec-next v4 3/5] xfrm: allow migration from UDP encapsulated to non-encapsulated ESP Antony Antony
2026-01-19 8:54 ` [PATCH ipsec-next v4 4/5] xfrm: rename reqid in xfrm_migrate Antony Antony
2026-01-19 8:54 ` [PATCH ipsec-next v4 5/5] xfrm: add XFRM_MSG_MIGRATE_STATE for single SA migration Antony Antony
2026-01-22 10:33 ` Steffen Klassert
2026-01-22 10:50 ` Steffen Klassert
2026-01-23 5:58 ` [devel-ipsec] " Antony Antony
2026-01-23 8:32 ` Steffen Klassert [this message]
2026-01-23 5:41 ` Antony Antony
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aXMyD4zss0wnXf7h@secunet.com \
--to=steffen.klassert@secunet.com \
--cc=antony.antony@secunet.com \
--cc=antony@phenome.org \
--cc=chiachangwang@google.com \
--cc=davem@davemloft.net \
--cc=devel@linux-ipsec.org \
--cc=edumazet@google.com \
--cc=evitayan@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=omosnace@redhat.com \
--cc=pabeni@redhat.com \
--cc=paul@paul-moore.com \
--cc=selinux@vger.kernel.org \
--cc=stephen.smalley.work@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox