IPV6_LEAVE_ANYCAST no longer holds RTNL, so a join of the same address can run between the two halves of its last leave. __ipv6_dev_ac_dec() unlinks the aca from idev->ac_list under idev->lock but deletes its anycast route only after dropping the lock. A join in that window finds no aca and creates a new one, and its ip6_ins_rt() fails with -EEXIST because the old route is still in the table. __ipv6_dev_ac_inc() ignores that error, the leave then deletes the old route, and the address stays joined without an anycast route in the local table. Delete the route before dropping idev->lock. Fixes: f7fdf13bf103 ("ipv6: anycast: Don't hold RTNL for IPV6_LEAVE_ANYCAST and IPV6_ADDRFORM.") Signed-off-by: Kyuwon Cho --- 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 drops the last membership of an anycast address on lo while another joins it again on a second socket, and the main thread then looks for the anycast route in /proc/net/ipv6_route. #define _GNU_SOURCE #include #include #include #include #include #include #include #include struct in6_ifreq { struct in6_addr addr; unsigned int prefixlen; int ifindex; }; static struct ipv6_mreq mr = { .ipv6mr_interface = 1 }; /* lo */ static pthread_barrier_t bar; static int sl, sj, joined; /* one thread drops the last membership while the other joins again */ static void *race(void *join) { for (;;) { pthread_barrier_wait(&bar); if (join) joined = !setsockopt(sj, IPPROTO_IPV6, IPV6_JOIN_ANYCAST, &mr, sizeof(mr)); else setsockopt(sl, IPPROTO_IPV6, IPV6_LEAVE_ANYCAST, &mr, sizeof(mr)); pthread_barrier_wait(&bar); } return NULL; } /* the anycast route of 2001:db8::100 in table local */ static int route(void) { char line[256]; int n = 0; FILE *f = fopen("/proc/net/ipv6_route", "r"); while (fgets(line, sizeof(line), f)) n += !strncmp(line, "20010db8000000000000000000000100 80", 35); fclose(f); return n; } int main(void) { struct ifreq up = { .ifr_name = "lo", .ifr_flags = IFF_UP }; struct in6_ifreq ifr = { .prefixlen = 64, .ifindex = 1 }; int s, lost = 0; pthread_t t; /* CAP_NET_ADMIN for IPV6_JOIN_ANYCAST */ if (unshare(CLONE_NEWUSER | CLONE_NEWNET)) return perror("unshare"), 1; s = socket(AF_INET6, SOCK_DGRAM, 0); inet_pton(AF_INET6, "2001:db8::1", &ifr.addr); if (ioctl(s, SIOCSIFFLAGS, &up) || ioctl(s, SIOCSIFADDR, &ifr)) return perror("lo"), 1; inet_pton(AF_INET6, "2001:db8::100", &mr.ipv6mr_multiaddr); pthread_barrier_init(&bar, NULL, 3); pthread_create(&t, NULL, race, NULL); pthread_create(&t, NULL, race, "join"); for (int i = 0; i < 10000; i++) { sl = socket(AF_INET6, SOCK_DGRAM, 0); sj = socket(AF_INET6, SOCK_DGRAM, 0); setsockopt(sl, IPPROTO_IPV6, IPV6_JOIN_ANYCAST, &mr, sizeof(mr)); pthread_barrier_wait(&bar); pthread_barrier_wait(&bar); lost += joined && !route(); close(sj); close(sl); } printf("joined without an anycast route: %d of 10000\n", lost); return 0; } Without the patch, a few of the 10000 joins leave the address without its route; with it, none do, and lockdep stays quiet. The patch was written with LLM assistance; we reviewed and tested it. net/ipv6/anycast.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c index be6dac8a8566..d66d0154ac3a 100644 --- a/net/ipv6/anycast.c +++ b/net/ipv6/anycast.c @@ -415,12 +415,11 @@ int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr) rcu_assign_pointer(prev_aca->aca_next, aca->aca_next); else rcu_assign_pointer(idev->ac_list, aca->aca_next); + ip6_del_rt(dev_net(idev->dev), aca->aca_rt, false); write_unlock_bh(&idev->lock); ipv6_del_acaddr_hash(aca); addrconf_leave_solict(idev, &aca->aca_addr); - ip6_del_rt(dev_net(idev->dev), aca->aca_rt, false); - inet6_ifacaddr_notify(idev->dev, aca, RTM_DELANYCAST); aca_put(aca); -- 2.43.0