Netdev List
 help / color / mirror / Atom feed
* [PATCH net] ipv6: skip walkers of other tables when a route leaves the tree
@ 2026-11-25 14:52 Kyuwon Cho
  2026-11-26 15:57 ` Ido Schimmel
  0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-11-25 14:52 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Ido Schimmel, Willem de Bruijn, Simon Horman, Thomas Graf,
	Cen Zhang, netdev

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")
Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
---
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(+)

diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index e1d49897d6ab..0d0748e31f57 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -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;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-26 15:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 14:52 [PATCH net] ipv6: skip walkers of other tables when a route leaves the tree Kyuwon Cho
2026-11-26 15:57 ` Ido Schimmel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox