Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: jianbol@nvidia.com
Cc: netdev@vger.kernel.org, ipsec@lists.linux.dev,
	steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, fw@strlen.de,
	linux-kernel@vger.kernel.org, cjubran@nvidia.com
Subject: Re: [PATCH ipsec 1/4] xfrm: Give GC list nodes their own storage
Date: Sun, 29 Nov 2026 02:14:39 +0000	[thread overview]
Message-ID: <179591847972.3135.16907973135135504288@kernel.org> (raw)
In-Reply-To: <20261125013412.1123866-2-jianbol@nvidia.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 commit fixes two aliasing bugs but has only one Fixes: tag,
  d737a5805581 ("xfrm: state: don't use lock anymore unless acquire…
- [Low] The message says the gclist/bydst linkage is overwritten "later,
  when the last reference is dropped", and then that "the same issue…

--

xfrm: Give GC list nodes their own storage

This patch stops struct xfrm_state from sharing storage between gclist
and bydst, and between dev_gclist and bysrc. Without the split, lock-free
RCU readers of the bydst and bysrc hash chains could follow linkage that
the GC lists had already overwritten. dev_gclist now shares a union with
byseq, which is only walked under xfrm_state_lock.

> Later, when the last reference is dropped, __xfrm_state_destroy()
> adds x->gclist to xfrm_state_gc_list. Since gclist and bydst
> currently share the same storage, adding the state to the GC list can
> overwrite the bydst linkage while an RCU reader is still using it.
> The same issue applies to dev_gclist and bysrc.

[Severity: Low]
Is "the same issue" accurate for the dev_gclist/bysrc half? Its mechanism
and its consequence look different from the gclist/bydst case.

dev_gclist is not written when the last reference is dropped. It is
written right after the RCU unlink, and no grace period passes first:

__xfrm_state_delete()
    hlist_del_init_rcu(&x->bysrc);   /* ->next kept for readers */
    ...
    spin_unlock(&net->xfrm.xfrm_state_lock);
    xfrm_dev_state_delete(x)
        hlist_add_head(&x->dev_gclist, &xfrm_state_dev_gc_list);

Then xfrm_dev_state_flush() calls xfrm_dev_state_free() right after
xfrm_state_delete(), with no synchronize_rcu(). xfrm_dev_state_free()
does this:

    if (!hlist_unhashed(&x->dev_gclist))
        hlist_del(&x->dev_gclist);

hlist_del() writes LIST_POISON1 into the storage that used to alias
x->bysrc.next.

Suppose a reader in __xfrm_state_lookup_byaddr() is on x at that point:

    hlist_for_each_entry_rcu(x, state_ptrs->bysrc + h, bysrc) {
        if (x->props.family != family ||

It can load LIST_POISON1. hlist_entry_safe() only filters NULL, so the
read of x->props.family would fault. The reader could also follow
x->bysrc.next into another state on the dev GC list, and that state may
already have been freed.

These lookups run from xfrm6_input_addr() on IPv6 receive, and from the
XFRM_MSG_DELSA/GETSA netlink path in xfrm_user.c.

For gclist/bydst, xfrm_state_gc_task() calls synchronize_rcu() before
freeing. The result there is mostly a diverted or truncated walk, so
SAs get missed.

Could the commit message say that the offload half fixes a possible oops
or use-after-free, and not only a corrupted walk?

> Fixes: d737a5805581 ("xfrm: state: don't use lock anymore unless acquire operation is needed")

[Severity: Low]
This tag covers the gclist/bydst alias. Does the dev_gclist/bysrc alias
need its own Fixes: tags?

Commit 07b87f9eea0c ("xfrm: Fix unregister netdevice hang on hardware
offload.") added the union of dev_gclist and bysrc in 2024.

Later, commit 2e460eefbd44 ("xfrm: state: make xfrm_state_lookup_byaddr
lockless") replaced spin_lock_bh(&net->xfrm.xfrm_state_lock) with
rcu_read_lock() in xfrm_state_lookup_byaddr().

Before that change, every bysrc walker held xfrm_state_lock. This
includes __xfrm_state_lookup_byaddr() through both
xfrm_state_lookup_byaddr() and __xfrm_state_locate(), and also
xfrm_migrate_state_find(). Reusing the bysrc storage only became unsafe
once both commits were in the tree.

Stable trees older than 6.10 don't have the dev_gclist union, so the
include/net/xfrm.h hunk won't apply there as-is.

Would Fixes: tags for 07b87f9eea0c and 2e460eefbd44 make it clearer
which trees need the bysrc half?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125013412.1123866-1-jianbol%40nvidia.com

  reply	other threads:[~2026-11-29  2:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  1:34 [PATCH ipsec 0/4] xfrm: Fix device state teardown races Jianbo Liu
2026-11-25  1:34 ` [PATCH ipsec 1/4] xfrm: Give GC list nodes their own storage Jianbo Liu
2026-11-29  2:14   ` netdev-bot+sashiko [this message]
2026-11-25  1:34 ` [PATCH ipsec 2/4] xfrm: Serialize device state teardown Jianbo Liu
2026-11-29  2:14   ` netdev-bot+sashiko
2026-11-25  1:34 ` [PATCH ipsec 3/4] xfrm: Wait for an RCU grace period before freeing device state Jianbo Liu
2026-11-29  2:14   ` netdev-bot+sashiko
2026-11-25  1:34 ` [PATCH ipsec 4/4] Revert "xfrm: serialize state GC with device state flush" Jianbo Liu
2026-11-29  2:14   ` netdev-bot+sashiko

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=179591847972.3135.16907973135135504288@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=cjubran@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=ipsec@lists.linux.dev \
    --cc=jianbol@nvidia.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 \
    /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