// https://syzkaller.appspot.com/bug?id=da6d800ad783579325e4fc13335a3be6c58dd091 #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void set_sysctl(const char *path, const char *val) { int fd = open(path, O_RDWR); if (fd < 0) { printf("[-] Failed to open sysctl %s: %s\n", path, strerror(errno)); exit(1); } printf("[+] Opened sysctl %s successfully.\n", path); ssize_t written = write(fd, val, strlen(val)); if (written < 0) { printf("[-] Failed to write '%s' to sysctl %s: %s\n", val, path, strerror(errno)); close(fd); exit(1); } printf("[+] Wrote '%s' to sysctl %s successfully.\n", val, path); int res = close(fd); if (res < 0) { printf("[-] Failed to close sysctl %s: %s\n", path, strerror(errno)); exit(1); } printf("[+] Closed sysctl %s successfully.\n", path); } static void addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, int alen) { int len = RTA_LENGTH(alen); struct rtattr *rta; if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > (unsigned int)maxlen) { printf("[-] addattr_l error: buffer overflow\n"); exit(1); } rta = (struct rtattr *)(((char *)n) + NLMSG_ALIGN(n->nlmsg_len)); rta->rta_type = type; rta->rta_len = len; if (alen > 0) memcpy(RTA_DATA(rta), data, alen); n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len); } static void add_address(int nl_fd, unsigned int ifindex, const char *addr_str) { struct { struct nlmsghdr n; struct ifaddrmsg ifa; char buf[256]; } req; struct in6_addr in6; int res = inet_pton(AF_INET6, addr_str, &in6); if (res <= 0) { printf("[-] Failed inet_pton for %s: %s\n", addr_str, strerror(errno)); exit(1); } memset(&req, 0, sizeof(req)); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_REPLACE | NLM_F_ACK; req.n.nlmsg_type = RTM_NEWADDR; req.n.nlmsg_seq = 1; req.ifa.ifa_family = AF_INET6; req.ifa.ifa_prefixlen = 128; req.ifa.ifa_flags = IFA_F_PERMANENT; req.ifa.ifa_scope = 0; req.ifa.ifa_index = ifindex; addattr_l(&req.n, sizeof(req), IFA_LOCAL, &in6, sizeof(in6)); addattr_l(&req.n, sizeof(req), IFA_ADDRESS, &in6, sizeof(in6)); struct sockaddr_nl sa; memset(&sa, 0, sizeof(sa)); sa.nl_family = AF_NETLINK; struct iovec iov = { &req.n, req.n.nlmsg_len }; struct msghdr msg = { .msg_name = &sa, .msg_namelen = sizeof(sa), .msg_iov = &iov, .msg_iovlen = 1, }; res = sendmsg(nl_fd, &msg, 0); if (res < 0) { printf("[-] Failed to sendmsg RTM_NEWADDR: %s\n", strerror(errno)); exit(1); } printf("[+] sendmsg RTM_NEWADDR sent successfully.\n"); char reply_buf[4096]; iov.iov_base = reply_buf; iov.iov_len = sizeof(reply_buf); res = recvmsg(nl_fd, &msg, 0); if (res < 0) { printf("[-] Failed to recvmsg netlink ACK: %s\n", strerror(errno)); exit(1); } struct nlmsghdr *nlh = (struct nlmsghdr *)reply_buf; if (nlh->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(nlh); if (err->error != 0 && err->error != -EEXIST) { printf("[-] Netlink error for RTM_NEWADDR: %s\n", strerror(-err->error)); exit(1); } } printf("[+] Address %s added to interface index %u successfully.\n", addr_str, ifindex); } static volatile int stop_threads = 0; static void *thread_mtu(void *arg) { (void)arg; int sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { printf("[-] thread_mtu socket failed: %s\n", strerror(errno)); return NULL; } struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, "lo", IFNAMSIZ - 1); while (!stop_threads) { ifr.ifr_mtu = 1200; ioctl(sock, SIOCSIFMTU, &ifr); usleep(1000); ifr.ifr_mtu = 1500; ioctl(sock, SIOCSIFMTU, &ifr); usleep(1000); } close(sock); return NULL; } static void *thread_flags(void *arg) { (void)arg; int sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { printf("[-] thread_flags socket failed: %s\n", strerror(errno)); return NULL; } struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, "lo", IFNAMSIZ - 1); while (!stop_threads) { if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) { ifr.ifr_flags ^= IFF_NOARP; ioctl(sock, SIOCSIFFLAGS, &ifr); } usleep(500); if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) { short orig = ifr.ifr_flags; ifr.ifr_flags &= ~IFF_UP; ioctl(sock, SIOCSIFFLAGS, &ifr); ifr.ifr_flags = orig | IFF_UP; ioctl(sock, SIOCSIFFLAGS, &ifr); } usleep(500); } close(sock); return NULL; } static void *thread_addr(void *arg) { unsigned int ifindex = (unsigned int)(uintptr_t)arg; int nl_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (nl_fd < 0) { printf("[-] thread_addr socket failed: %s\n", strerror(errno)); return NULL; } struct in6_addr in6; inet_pton(AF_INET6, "::ffff:127.0.0.1", &in6); struct { struct nlmsghdr n; struct ifaddrmsg ifa; char buf[256]; } req; struct sockaddr_nl sa; memset(&sa, 0, sizeof(sa)); sa.nl_family = AF_NETLINK; struct iovec iov = { &req.n, 0 }; struct msghdr msg = { .msg_name = &sa, .msg_namelen = sizeof(sa), .msg_iov = &iov, .msg_iovlen = 1, }; while (!stop_threads) { memset(&req, 0, sizeof(req)); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_REPLACE; req.n.nlmsg_type = RTM_NEWADDR; req.n.nlmsg_seq = 100; req.ifa.ifa_family = AF_INET6; req.ifa.ifa_prefixlen = 128; req.ifa.ifa_flags = IFA_F_PERMANENT; req.ifa.ifa_scope = 0; req.ifa.ifa_index = ifindex; addattr_l(&req.n, sizeof(req), IFA_LOCAL, &in6, sizeof(in6)); addattr_l(&req.n, sizeof(req), IFA_ADDRESS, &in6, sizeof(in6)); iov.iov_len = req.n.nlmsg_len; sendmsg(nl_fd, &msg, 0); usleep(2000); } close(nl_fd); return NULL; } int main(void) { setvbuf(stdout, NULL, _IONBF, 0); printf("[*] Starting reproducer for missing host route on lo...\n"); /* Step 1: Configure sysctls */ set_sysctl("/proc/sys/net/ipv6/conf/all/keep_addr_on_down", "1\n"); set_sysctl("/proc/sys/net/ipv6/conf/lo/keep_addr_on_down", "1\n"); set_sysctl("/proc/sys/net/ipv6/conf/all/router_solicitation_delay", "0\n"); set_sysctl("/proc/sys/net/ipv6/conf/lo/router_solicitation_delay", "0\n"); /* Step 2: Open sockets and resolve interface */ int nl_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (nl_fd < 0) { printf("[-] Failed to create NETLINK_ROUTE socket: %s\n", strerror(errno)); exit(1); } printf("[+] NETLINK_ROUTE socket created successfully.\n"); int sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { printf("[-] Failed to create AF_INET socket: %s\n", strerror(errno)); close(nl_fd); exit(1); } printf("[+] AF_INET socket created successfully.\n"); unsigned int ifindex = if_nametoindex("lo"); if (ifindex == 0) { printf("[-] Failed to resolve interface index for 'lo': %s\n", strerror(errno)); close(nl_fd); close(sock); exit(1); } printf("[+] Resolved interface 'lo' to ifindex %u.\n", ifindex); /* Ensure 'lo' is UP */ struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, "lo", IFNAMSIZ - 1); int res = ioctl(sock, SIOCGIFFLAGS, &ifr); if (res < 0) { printf("[-] Failed SIOCGIFFLAGS on 'lo': %s\n", strerror(errno)); close(nl_fd); close(sock); exit(1); } if (!(ifr.ifr_flags & IFF_UP)) { ifr.ifr_flags |= IFF_UP; res = ioctl(sock, SIOCSIFFLAGS, &ifr); if (res < 0) { printf("[-] Failed to bring 'lo' UP: %s\n", strerror(errno)); close(nl_fd); close(sock); exit(1); } printf("[+] Interface 'lo' brought UP.\n"); } /* Step 3: Assign IPv4-mapped address ::ffff:127.0.0.1/128 */ add_address(nl_fd, ifindex, "::ffff:127.0.0.1"); /* Step 4: Execute MTU Reduction and Flag Toggling (Deterministic Path) */ printf("[*] Executing deterministic MTU reduction and flag toggling iterations...\n"); for (int i = 0; i < 30; i++) { /* Set MTU of lo to 1200 (< IPV6_MIN_MTU 1280) */ ifr.ifr_mtu = 1200; res = ioctl(sock, SIOCSIFMTU, &ifr); if (res < 0) { printf("[-] Failed SIOCSIFMTU (1200) on 'lo': %s\n", strerror(errno)); exit(1); } /* Restore MTU of lo to 1500 */ ifr.ifr_mtu = 1500; res = ioctl(sock, SIOCSIFMTU, &ifr); if (res < 0) { printf("[-] Failed SIOCSIFMTU (1500) on 'lo': %s\n", strerror(errno)); exit(1); } /* Query flags and toggle IFF_NOARP twice */ res = ioctl(sock, SIOCGIFFLAGS, &ifr); if (res < 0) { printf("[-] Failed SIOCGIFFLAGS on 'lo': %s\n", strerror(errno)); exit(1); } short orig_flags = ifr.ifr_flags; ifr.ifr_flags ^= IFF_NOARP; res = ioctl(sock, SIOCSIFFLAGS, &ifr); if (res < 0) { printf("[-] Failed SIOCSIFFLAGS (toggle NOARP) on 'lo': %s\n", strerror(errno)); exit(1); } ifr.ifr_flags = orig_flags; res = ioctl(sock, SIOCSIFFLAGS, &ifr); if (res < 0) { printf("[-] Failed SIOCSIFFLAGS (restore NOARP) on 'lo': %s\n", strerror(errno)); exit(1); } /* Allow DAD workqueue to process */ usleep(15000); } printf("[+] Deterministic trigger iterations completed.\n"); /* Step 5: Execute concurrent state racing */ printf("[*] Launching concurrent state racing threads...\n"); pthread_t th1, th2, th3; res = pthread_create(&th1, NULL, thread_mtu, NULL); if (res != 0) { printf("[-] Failed to create thread_mtu: %s\n", strerror(res)); exit(1); } res = pthread_create(&th2, NULL, thread_flags, NULL); if (res != 0) { printf("[-] Failed to create thread_flags: %s\n", strerror(res)); exit(1); } res = pthread_create(&th3, NULL, thread_addr, (void *)(uintptr_t)ifindex); if (res != 0) { printf("[-] Failed to create thread_addr: %s\n", strerror(res)); exit(1); } printf("[+] Concurrent threads started, running race for 2 seconds...\n"); sleep(2); stop_threads = 1; pthread_join(th1, NULL); pthread_join(th2, NULL); pthread_join(th3, NULL); printf("[+] Concurrent threads joined.\n"); /* Final sleep to let asynchronous timers and workqueues complete */ printf("[*] Waiting for asynchronous kernel tasks to finish...\n"); sleep(1); close(sock); close(nl_fd); printf("[+] Reproducer finished execution successfully.\n"); return 0; }