Skip to contentSkip to conversation

ipv6: skip walkers of other tables when a route leaves the tree

PATCH Applied Kyuwon Cho 3 participants 3 messages Nov 25 – Dec 2

Subsystems (3)
lore
Share & tools
lore

Kyuwon Cho

author
#0 lore raw

PATCH 1/1 ipv6: skip walkers of other tables when a route leaves the tree

fib6_walkers_replace_leaf() runs under the tb6_lock of the route's table but checks every walker of the netns, including walkers of other tables, which run under their own table's lock. Such a walker can be anywhere in its walk: fib6_walk_continue() sets w->state to FWS_C before it sets w->leaf, and the walker of fib6_clean_tree() starts with an uninitialized w->leaf on the stack. A route delete in one table while a link change cleans another one compares that value:

  BUG: KMSAN: uninit-value in fib6_del (net/ipv6/ip6_fib.c:103)
   fib6_del (net/ipv6/ip6_fib.c:103 ip6_fib.c:123 ip6_fib.c:2056)
   __ip6_del_rt_siblings (net/ipv6/route.c:4086)
   ip6_route_del (net/ipv6/route.c:4235)
   inet6_rtm_delroute (net/ipv6/route.c:5686)
   rtnetlink_rcv_msg (net/core/rtnetlink.c:7169)
  Local variable c.i created at:
   __fib6_clean_all (net/ipv6/ip6_fib.c:2315 net/ipv6/ip6_fib.c:2344)
   fib6_clean_all (net/ipv6/ip6_fib.c:2355)

A walker of another table never rests on a route of this table, so skip it.

Fixes c71099acce93 ("[IPV6]: Multiple Routing Tables")

---
The issue was found by an LLM-guided test generator that we are developing as a research prototype. A reproducer, which runs as any
user: one thread toggles lo, so that fib6_clean_all() walks every table, while the main thread adds and deletes a route in the main table.

#define _GNU_SOURCE
#include <arpa/inet.h>
#include <net/if.h>
#include <net/route.h>
#include <pthread.h>
#include <sched.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <unistd.h>

static int s;

/* link changes walk every FIB table with fib6_clean_all() */ static void *toggle(void *arg)

{
	struct ifreq lo = { .ifr_name = "lo" };

	for (;;) {
		lo.ifr_flags = 0;
		ioctl(s, SIOCSIFFLAGS, &lo);
		lo.ifr_flags = IFF_UP;
		ioctl(s, SIOCSIFFLAGS, &lo);
	}
	return arg;
}

/* route deletes scan the walkers of all tables */ int main(void)

{
	struct in6_rtmsg rt = {
		.rtmsg_dst_len = 64,
		.rtmsg_metric = 1,
		.rtmsg_flags = RTF_UP,
		.rtmsg_ifindex = 1,	/* lo */
	};
	pthread_t t;

	if (unshare(CLONE_NEWUSER | CLONE_NEWNET))
		return perror("unshare"), 1;
	s = socket(AF_INET6, SOCK_DGRAM, 0);
	inet_pton(AF_INET6, "2001:db8:1::", &rt.rtmsg_dst);
	pthread_create(&t, NULL, toggle, NULL);
	for (int i = 0; i < 2000000; i++) {
		ioctl(s, SIOCADDRT, &rt);
		ioctl(s, SIOCDELRT, &rt);
	}
	return 0;
}

Without the patch, KMSAN reports the uninit-value above; with it, the reproducer runs to the end without a report.

The patch was written with LLM assistance; we reviewed and tested it.

 net/ipv6/ip6_fib.c | 3 +++
 1 file changed, 3 insertions(+)
net/ipv6/ip6_fib.c +3 -0
index e1d49897d6ab..0d0748e31f57 100644
@@ -100,6 +100,9 @@ static void fib6_walkers_replace_leaf(struct net *net, struct fib6_info *old,
 
 	read_lock(&net->ipv6.fib6_walker_lock);
 	FOR_WALKERS(net, w) {
+		/* Only walkers of this table are serialized by its tb6_lock */
+		if (w->root != &old->fib6_table->tb6_root)
+			continue;
 		if (w->state == FWS_C && w->leaf == old) {
 			pr_debug("walker %p adjusted by unlink of %p\n", w, old);
 			w->leaf = new;
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Kyuwon Cho

fib6_walkers_replace_leaf() runs under the tb6_lock of the route's table but checks every walker of the netns, including walkers of other tables, which run under their own table's lock. Such a walker can be anywhere in its walk: fib6_walk_continue() sets w->state to FWS_C before it sets w->leaf, and the walker of fib6_clean_tree() starts with an uninitialized w->leaf on the stack. A route delete in one table while a link change cleans another one compares that value:

  BUG: KMSAN: uninit-value in fib6_del (net/ipv6/ip6_fib.c:103)
   fib6_del (net/ipv6/ip6_fib.c:103 ip6_fib.c:123 ip6_fib.c:2056)
   __ip6_del_rt_siblings (net/ipv6/route.c:4086)
   ip6_route_del (net/ipv6/route.c:4235)
   inet6_rtm_delroute (net/ipv6/route.c:5686)
   rtnetlink_rcv_msg (net/core/rtnetlink.c:7169)
  Local variable c.i created at:
   __fib6_clean_all (net/ipv6/ip6_fib.c:2315 net/ipv6/ip6_fib.c:2344)
   fib6_clean_all (net/ipv6/ip6_fib.c:2355)
Quoted 5 lines

A walker of another table never rests on a route of this table, so skip it.

Fixes c71099acce93 ("[IPV6]: Multiple Routing Tables")
#2 lore raw
In reply to Kyuwon Cho
This patch was applied to netdev/net.git (main) by Willem de Bruijn <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Willem de Bruijn <[email protected]>:

Quoted 9 lines · On Wed, 25 Nov 2026 23:52:58 +0900 you wrote:

fib6_walkers_replace_leaf() runs under the tb6_lock of the route's table but checks every walker of the netns, including walkers of other tables, which run under their own table's lock. Such a walker can be anywhere in its walk: fib6_walk_continue() sets w->state to FWS_C before it sets w->leaf, and the walker of fib6_clean_tree() starts with an uninitialized w->leaf on the stack. A route delete in one table while a link change cleans another one compares that value:

[...]

Here is the summary with links:
- [net] ipv6: skip walkers of other tables when a route leaves the tree

    https://git.kernel.org/netdev/net/c/5e16fbd6c96b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html