From: Zhou Qiuyue <n0ps1edzz@gmail.com>
To: netdev@vger.kernel.org
Cc: David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>,
David S. Miller <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Willem de Bruijn <willemb@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
Hangbin Liu <hangbin.liu@linux.dev>
Subject: [PATCH net v2 4/4] ipv6: route: fix use-after-free in ip6_dst_neigh_lookup()
Date: Fri, 27 Nov 2026 12:03:46 +0800 [thread overview]
Message-ID: <0cd69817db8a8efff95403ae1ff108bd460b9ccf.1795754281.git.n0ps1edzz@gmail.com> (raw)
In-Reply-To: <cover.1795754281.git.n0ps1edzz@gmail.com>
ip6_dst_neigh_lookup() can be called without an RCU read lock. One such
caller is irdma_addr_resolve_neigh_ipv6(), after its route lookup.
The callback loads the egress device with dst_dev() and passes the pointer
to __ip6_dst_neigh_lookup(). On a neighbour-cache miss, that helper calls
ipv6_neigh_create(), which dereferences the device and can invoke its
operations. Concurrent route teardown can replace dst->dev with
blackhole_netdev, drop the route's reference to the old net_device, and
free it while the lookup is still using the pointer.
Hold the RCU read lock across the lookup and use dst_dev_rcu() to load the
device, matching the protection in ipv4_dst_neigh_lookup().
Ido Schimmel identified this unprotected callback during review. The
lifetime and non-RCU caller were validated by source inspection; this path
has not been triggered independently at runtime.
Fixes: 9514528d92d4 ("ipv6: call dst_dev_put() properly")
Cc: stable@vger.kernel.org
Suggested-by: Ido Schimmel <idosch@nvidia.com>
Link: https://lore.kernel.org/netdev/20261125190113.GA421469@shredder/
Signed-off-by: Zhou Qiuyue <n0ps1edzz@gmail.com>
---
net/ipv6/route.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 6bdd4423c..a9f197bf5 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -249,9 +249,16 @@ static struct neighbour *ip6_dst_neigh_lookup(const struct dst_entry *dst,
const void *daddr)
{
const struct rt6_info *rt = dst_rt6_info(dst);
+ struct net_device *dev;
+ struct neighbour *n;
+
+ rcu_read_lock();
+ dev = dst_dev_rcu(dst);
+ n = __ip6_dst_neigh_lookup(rt6_nexthop(rt, &in6addr_any),
+ dev, skb, daddr);
+ rcu_read_unlock();
- return __ip6_dst_neigh_lookup(rt6_nexthop(rt, &in6addr_any),
- dst_dev(dst), skb, daddr);
+ return n;
}
static void ip6_confirm_neigh(const struct dst_entry *dst, const void *daddr)
--
2.56.1.windows.1
prev parent reply other threads:[~2026-11-27 5:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 4:38 [PATCH net v2 0/4] net: fix dst->dev lifetime races Zhou Qiuyue
2026-11-27 4:03 ` [PATCH net v2 1/4] net: wait for RCU readers after flushing routes Zhou Qiuyue
2026-11-27 4:03 ` [PATCH net v2 2/4] ipv4: route: fix use-after-free in ipv4_confirm_neigh() Zhou Qiuyue
2026-11-27 4:03 ` [PATCH net v2 3/4] ipv6: route: fix use-after-free in ip6_confirm_neigh() Zhou Qiuyue
2026-11-27 4:03 ` Zhou Qiuyue [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=0cd69817db8a8efff95403ae1ff108bd460b9ccf.1795754281.git.n0ps1edzz@gmail.com \
--to=n0ps1edzz@gmail.com \
--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=kuniyu@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.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;
as well as URLs for NNTP newsgroup(s).