From: netdev-bot+sashiko@kernel.org
To: zzzccc427@gmail.com
Cc: steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, antony.antony@secunet.com,
baijiaju1990@gmail.com, jjzuming@gmail.com
Subject: Re: [PATCH ipsec v2 2/2] xfrm: use cached offload ifindex when migrating an SA
Date: Sun, 01 Nov 2026 03:30:23 +0000 [thread overview]
Message-ID: <179350382315.3131.13286442217714808392@kernel.org> (raw)
In-Reply-To: <pm-xfrm-core-objects-candidate-0050-v4-3c6b8c5369a802e9be0e-2@gmail.com>
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The patch's only AI-disclosure trailer, 'Assisted-by: LLM', sits
below the '---' separator, after 'Signed-off-by: Cen Zhang'.
Pre-existing issues:
- [Low] This problem wasn't introduced by this patch, but the patch now
reads the cached xso->ifindex as a stable snapshot while the rest of…
--
xfrm: use cached offload ifindex when migrating an SA
This patch changes xso_to_xuo() to use the ifindex cached in the offload
record instead of dereferencing xso->dev. This closes a NULL dereference
when xfrm_dev_state_flush() races with XFRM_MSG_MIGRATE_STATE. It also
annotates the xso.dev check in xfrm_do_migrate_state() with READ_ONCE().
> Fixes: a9d155ea9b44 ("xfrm: add XFRM_MSG_MIGRATE_STATE for single SA migration")
> Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
>
> ---
> Assisted-by: LLM
[Severity: Low]
This isn't a bug, but the Assisted-by tag is below the "---" separator,
so git am and b4 drop it when the patch is applied. The applied commit
ends at the Signed-off-by line and has no Assisted-by trailer.
Documentation/process/submitting-patches.rst ("Using Assisted-by:") asks
contributors to acknowledge tool use with an Assisted-by tag. Earlier
xfrm commits such as c4a5f0071cc6 ("xfrm: cache the offload ifindex for
netlink dumps") put it in the regular tag block.
Could the tag be moved above the "---" line, next to Fixes: and
Signed-off-by:?
> diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
> index 781d4ec565aae..1cea24380797d 100644
> --- a/net/xfrm/xfrm_user.c
> +++ b/net/xfrm/xfrm_user.c
> @@ -1240,7 +1240,7 @@ static void xso_to_xuo_ifindex(const struct xfrm_dev_offload *xso, int ifindex,
> static void xso_to_xuo(const struct xfrm_dev_offload *xso,
> struct xfrm_user_offload *xuo)
> {
> - xso_to_xuo_ifindex(xso, xso->dev->ifindex, xuo);
> + xso_to_xuo_ifindex(xso, READ_ONCE(xso->ifindex), xuo);
> }
> #endif
>
> @@ -3462,7 +3462,7 @@ static int xfrm_do_migrate_state(struct sk_buff *skb, struct nlmsghdr *nlh,
> } else {
> bool inherit_offload = !(um->flags & XFRM_MIGRATE_STATE_CLEAR_OFFLOAD);
>
> - if (inherit_offload && x->xso.dev) {
> + if (inherit_offload && READ_ONCE(x->xso.dev)) {
> xso_to_xuo(&x->xso, &xuo);
> m.xuo = &xuo;
> }
[Severity: Low]
This is a pre-existing issue and was not introduced by this patch. The
patch now treats the cached ifindex as a stable snapshot, but the rest of
the inherited xuo still comes from fields that teardown changes.
The dev check and xso_to_xuo() run without x->lock.
xso_to_xuo_ifindex() does plain reads of xso->dir and xso->type:
net/xfrm/xfrm_user.c:xso_to_xuo_ifindex() {
xuo->ifindex = ifindex;
if (xso->dir == XFRM_DEV_OFFLOAD_IN)
xuo->flags = XFRM_OFFLOAD_INBOUND;
if (xso->type == XFRM_DEV_OFFLOAD_PACKET)
xuo->flags |= XFRM_OFFLOAD_PACKET;
}
At the same time, under RTNL, xfrm_dev_state_flush()->xfrm_dev_state_free()
does:
net/xfrm/xfrm_state.c:xfrm_dev_state_free() {
...
WRITE_ONCE(xso->dev, NULL);
xso->type = XFRM_DEV_OFFLOAD_UNSPECIFIED;
netdev_put(dev, &xso->dev_tracker);
...
}
Migration holds xfrm_cfg_mutex and the notifier holds RTNL. Nothing
orders the plain store and the plain load of xso->type.
Would KCSAN report this as a data race?
Suppose the flush lands between the READ_ONCE(x->xso.dev) check and the
type read. The xuo then gets the valid cached ifindex but loses
XFRM_OFFLOAD_PACKET. xfrm_state_migrate_create() then tries
xfrm_dev_state_add() on the clone in crypto offload mode.
As far as I can tell, this is contained. xfrm_dev_state_flush() calls
xfrm_state_delete() before xfrm_dev_state_free(), so this later locked
check in xfrm_do_migrate_state() throws away the clone:
spin_lock_bh(&x->lock);
if (x->km.state != XFRM_STATE_VALID) {
spin_unlock_bh(&x->lock);
NL_SET_ERR_MSG(extack, "State already deleted");
err = -ESRCH;
goto out_xc;
}
The dump path has the same plain reads of dir and type, through
copy_user_state_offload(). The xso->dev NULL dereference described in the
commit message does look fixed.
Should the dir and type reads be annotated too, or the snapshot taken
under x->lock, so the inherited xuo stays consistent?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/pm-xfrm-core-objects-candidate-0050-v4-3c6b8c5369a802e9be0e-0%40gmail.com
prev parent reply other threads:[~2026-11-01 3:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-31 3:28 [PATCH ipsec v2 0/2] xfrm: fix offload state use racing with device teardown Cen Zhang
2026-10-31 3:28 ` [PATCH ipsec v2 1/2] xfrm: protect offload statistics updates from " Cen Zhang
2026-11-01 3:30 ` netdev-bot+sashiko
2026-10-31 3:28 ` [PATCH ipsec v2 2/2] xfrm: use cached offload ifindex when migrating an SA Cen Zhang
2026-11-01 3:30 ` netdev-bot+sashiko [this message]
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=179350382315.3131.13286442217714808392@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=antony.antony@secunet.com \
--cc=baijiaju1990@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=jjzuming@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=steffen.klassert@secunet.com \
--cc=zzzccc427@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