Re: [PATCH net 2/2] xfrm: fix use-after-free in xfrm_lookup_with_ifid()
From: netdev-bot+sashiko
Date: Sat Nov 28 2026 - 04:36:31 EST
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch does not fix the use-after-free it claims to fix.
--
xfrm: fix use-after-free in xfrm_lookup_with_ifid()
This patch changes the no-policy path of xfrm_lookup_with_ifid(). It now
reads the device of dst_orig through dst_dev_rcu() inside an RCU read-side
critical section, instead of dereferencing dst_orig->dev directly. The
commit message says this depends on a netdev_run_todo() change that waits
for RCU readers.
Link: https://lore.kernel.org/netdev/20260908224901.1591334-1-kuba@xxxxxxxxxx/
> diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
> index cea6842e6454d..eafd090e3aebc 100644
> --- a/net/xfrm/xfrm_policy.c
> +++ b/net/xfrm/xfrm_policy.c
[ ... ]
> @@ -3312,7 +3314,12 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net,
> return dst;
>
> nopol:
> - if ((!dst_orig->dev || !(dst_orig->dev->flags & IFF_LOOPBACK)) &&
> + rcu_read_lock();
> + dev = dst_dev_rcu(dst_orig);
> + is_loopback = dev && (dev->flags & IFF_LOOPBACK);
> + rcu_read_unlock();
[Severity: High]
In this tree, does this RCU section close the race?
The commit message says:
This requires netdev_run_todo() to wait for RCU readers after flushing
routes; that fix is a prerequisite of this patch.
That change isn't in this tree. Neither this patch nor the earlier
"ipv4: route: fix use-after-free in ip_route_output_flow()" touches
net/core/. The only rcu_barrier() in netdev_run_todo() still runs before
the route flush, and nothing waits for readers after the flush:
net/core/dev.c:netdev_run_todo() {
...
if (!list_empty(&list))
rcu_barrier();
...
if (!list_empty(&list)) {
rt_flush_dev(NULL);
rt6_uncached_list_flush_dev(NULL);
}
cnt = 0;
while (!list_empty(&list)) {
struct net *net;
dev = netdev_wait_allrefs_any(&list);
...
}
rt_flush_dev() and rt6_uncached_list_flush_dev() call
rcu_assign_pointer(rt->dst.dev_rcu, blackhole_netdev). They then drop the
old device reference at once through netdev_ref_replace().
netdev_wait_allrefs_any() returns immediately when netdev_refcnt_read(dev)
is 1. The device is then released through kobject_put() and
netdev_release(), which calls kvfree(dev) without waiting for an RCU grace
period.
The only grace period on the free path is the synchronize_net() in
netdev_napi_exit(). It is skipped when napi_list is empty, which is the
case for the dummy device used in the reproducer.
If dst_orig is an uncached output route, can this sequence still happen?
CPU A
xfrm_lookup_with_ifid()
rcu_read_lock();
dev = dst_dev_rcu(dst_orig);
<preempted under CONFIG_PREEMPT_RCU>
CPU B
netdev_run_todo()
rt_flush_dev(NULL)
rcu_assign_pointer(rt->dst.dev_rcu, blackhole_netdev);
netdev_ref_replace(...);
netdev_wait_allrefs_any() <-- refcnt is 1, returns at once
kobject_put(&dev->dev.kobj)
netdev_release()
kvfree(dev);
CPU A
is_loopback = dev && (dev->flags & IFF_LOOPBACK); <-- freed dev
As far as I can tell, this makes the window smaller but doesn't close it.
That would need a synchronize_rcu() or synchronize_net() in
netdev_run_todo() after the flush and before the devices are freed.
The commit message doesn't give a SHA, Link or Depends-on for the
prerequisite, and the patch is tagged Cc: stable with Fixes: 2d151d39073a.
Could the prerequisite be named explicitly, or sent in the same series as
this patch? Otherwise a stable backport could pick up this patch without
it.
The commit message also names dst_dev_put() as the writer:
dst_dev_put() can replace a dst's device with the blackhole device and
drop the reference to the original device.
The dst_dev_put() calls made from NETDEV_UNREGISTER notifiers are followed
by synchronize_net() in unregister_netdevice_many_notify(). The pointer
swap with no grace period after it seems to be the rt_flush_dev(NULL) and
rt6_uncached_list_flush_dev(NULL) calls in netdev_run_todo(). Would it be
more accurate to describe those calls instead?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795769101.git.n0ps1edzz%40gmail.com