From: netdev-bot+sashiko@kernel.org
To: n0ps1edzz@gmail.com
Cc: netdev@vger.kernel.org, dsahern@kernel.org, idosch@nvidia.com,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, hangbin.liu@linux.dev,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH net] ipv6: route: fix use-after-free in ip6_confirm_neigh()
Date: Tue, 24 Nov 2026 07:01:26 +0000 [thread overview]
Message-ID: <179550368695.3135.12579094604954175182@kernel.org> (raw)
In-Reply-To: <20261123133000.1.n0ps1edzz@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 (2) · 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 RCU protection this patch adds to ip6_confirm_neigh() does
not cover the uncached-route flush, which is one of the two teardown…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the IPv4
sibling callback ipv4_confirm_neigh() (net/ipv4/route.c:441-457) has…
- [High] This problem wasn't introduced by this patch, but
ip6_dst_neigh_lookup(), the IPv6 dst_ops->neigh_lookup callback in the…
--
ipv6: route: fix use-after-free in ip6_confirm_neigh()
This commit takes rcu_read_lock() in ip6_confirm_neigh(), loads the device
with dst_dev_rcu() and holds the section through the dev->flags test and
__ipv6_confirm_neigh(). It is meant to stop a use-after-free when route
teardown swaps dst->dev to blackhole_netdev and the old net_device is freed.
That race is reached from rawv6_sendmsg() and udpv6_sendmsg() with
MSG_CONFIRM|MSG_PROBE.
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 1b2dcc066e198..6bdd4423ce784 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -257,16 +257,21 @@ static struct neighbour *ip6_dst_neigh_lookup(const struct dst_entry *dst,
> static void ip6_confirm_neigh(const struct dst_entry *dst, const void *daddr)
> {
> const struct rt6_info *rt = dst_rt6_info(dst);
> - struct net_device *dev = dst_dev(dst);
> + struct net_device *dev;
> +
> + rcu_read_lock();
> + dev = dst_dev_rcu(dst);
[Severity: High]
Does this RCU section cover the uncached-route flush that the commit
message names as one of the two teardown paths?
Since commit f12d2907992db7 ("ipv6: Batch rt6_uncached_list_flush_dev() in
netdev_run_todo()."), rt6_uncached_list_flush_dev(dev) returns early when
dev->dismantle is set. During unregister, the pointer swap now happens
from netdev_run_todo(), after that function's only rcu_barrier():
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)) {
...
dev = netdev_wait_allrefs_any(&list);
...
kobject_put(&dev->dev.kobj);
...
}
rt6_uncached_list_flush_dev(NULL) does:
rcu_assign_pointer(rt->dst.dev_rcu, blackhole_netdev);
netdev_ref_replace(rt_dev, blackhole_netdev,
&rt->dst.dev_tracker,
GFP_ATOMIC);
netdev_wait_allrefs_any() returns as soon as netdev_refcnt_read(dev) == 1.
kobject_put() then reaches netdev_release(), which frees the device right
away:
/* no need to wait for rcu grace period:
* device is dead and about to be freed.
*/
kfree(rcu_access_pointer(dev->ifalias));
kvfree(dev);
free_netdev() only reaches synchronize_net() through netdev_napi_exit()
when the device has NAPI instances. Dummy devices have none.
As far as I can tell, nothing between the swap and the free waits for
current RCU readers. Can a task that loaded the old device here with
dst_dev_rcu() just before the swap still read dev->flags, or dev_net(dev)
in __ipv6_neigh_lookup_noref(), after the device has been freed?
User space can get such a dst. rawv6_sendmsg() sets FLOWI_FLAG_KNOWN_NH for
hdrincl sockets, and ip6_pol_route() then puts the route on
rt6_uncached_list. MSG_CONFIRM|MSG_PROBE then reaches dst_confirm_neigh().
This is the same rawv6_sendmsg() path as in the KASAN report.
The dst_dev_put() path looks covered, because the NETDEV_UNREGISTER
notifiers are followed by synchronize_net() in
unregister_netdevice_many_notify().
Would netdev_run_todo() need a synchronize_net() or synchronize_rcu() after
the rt_flush_dev(NULL)/rt6_uncached_list_flush_dev(NULL) batch, before the
device can be freed, to close the uncached-flush case?
>
> daddr = choose_neigh_daddr(rt6_nexthop(rt, &in6addr_any), NULL, daddr);
> if (!daddr)
> - return;
> + goto out;
> if (dev->flags & (IFF_NOARP | IFF_LOOPBACK))
> - return;
> + goto out;
> if (ipv6_addr_is_multicast((const struct in6_addr *)daddr))
> - return;
> + goto out;
> __ipv6_confirm_neigh(dev, daddr);
> +out:
> + rcu_read_unlock();
> }
[Severity: High]
This isn't a bug introduced by this patch, but does the IPv4 callback
ipv4_confirm_neigh() in net/ipv4/route.c have the same use-after-free?
net/ipv4/route.c:ipv4_confirm_neigh() {
const struct rtable *rt = container_of(dst, struct rtable, dst);
struct net_device *dev = dst_dev(dst);
...
} else if (IS_ENABLED(CONFIG_IPV6) && rt->rt_gw_family == AF_INET6) {
return __ipv6_confirm_neigh(dev, &rt->rt_gw6);
...
__ipv4_confirm_neigh(dev, *(__force u32 *)pkey);
}
The device is loaded with a plain dst_dev() outside RCU.
__ipv4_confirm_neigh() and __ipv6_confirm_neigh() only take
rcu_read_lock() after that load. They then dereference the pointer:
dev_net(dev) and dev->flags in __ipv4_neigh_lookup_noref(), or
dev_net(dev) in __ipv6_neigh_lookup_noref().
IPv4 teardown drops the dst's device reference in the same way.
rt_flush_dev() does rcu_assign_pointer(rt->dst.dev_rcu, blackhole_netdev)
and then netdev_ref_replace(). During unregister this runs from
netdev_run_todo() through rt_flush_dev(NULL).
udp_sendmsg(), raw_sendmsg() and ping_v4_sendmsg() all reach
dst_confirm_neigh() with MSG_CONFIRM|MSG_PROBE. None of them holds RCU or a
device reference, and the UDP path needs no privilege.
The neighbouring ipv4_dst_neigh_lookup() already uses rcu_read_lock() with
dst_dev_rcu(). Should ipv4_confirm_neigh() be converted the same way? It
would also depend on the missing grace period in netdev_run_todo()
described above.
[Severity: High]
This is a pre-existing issue, but ip6_dst_neigh_lookup(), just above this
hunk, still uses the unpinned load that this patch removes from
ip6_confirm_neigh():
net/ipv6/route.c:ip6_dst_neigh_lookup() {
const struct rt6_info *rt = dst_rt6_info(dst);
return __ip6_dst_neigh_lookup(rt6_nexthop(rt, &in6addr_any),
dst_dev(dst), skb, daddr);
}
__ip6_dst_neigh_lookup() calls __ipv6_neigh_lookup(dev, daddr), which only
takes rcu_read_lock() after the pointer was loaded. On a cache miss it
calls ipv6_neigh_create(dev, daddr), which leads to ___neigh_create():
net/core/neighbour.c:___neigh_create() {
...
n->dev = dev;
netdev_hold(dev, &n->dev_tracker, GFP_ATOMIC);
...
}
After that it calls dev->netdev_ops->ndo_neigh_construct.
Suppose dst_dev_put() or the uncached-route flush moves the dst to
blackhole_netdev, and the old device is freed between the load and these
uses. Could netdev_hold() then increment a refcount in a freed net_device?
Some callers get here holding only a dst reference. For example,
irdma_addr_resolve_neigh_ipv6() in drivers/infiniband/hw/irdma/cm.c calls
dst_neigh_lookup() after ip6_route_output() without rcu_read_lock().
The IPv4 counterpart ipv4_dst_neigh_lookup() already holds rcu_read_lock()
around dst_dev_rcu() and the lookup/create.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123133000.1.n0ps1edzz%40gmail.com
prev parent reply other threads:[~2026-11-24 7:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 5:30 Zhou Qiuyue
2026-11-23 7:02 ` netdev-bot+sinfo
2026-11-24 7:01 ` 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=179550368695.3135.12579094604954175182@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=hangbin.liu@linux.dev \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=n0ps1edzz@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®