Re: [PATCH ipsec 1/4] xfrm: Give GC list nodes their own storage
From: netdev-bot+sashiko
Date: Sat Nov 28 2026 - 21:14:58 EST
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