// https://syzkaller.appspot.com/bug?id=dae804a5c85a54c84091e3e971b8e43613da38f9 // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include const int kFailStatus = 67; const int kRetryStatus = 69; __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } __attribute__((noreturn)) static void fail(const char* msg, ...) { int e = errno; fflush(stdout); va_list args; va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); fprintf(stderr, " (errno %d)\n", e); doexit((e == ENOMEM || e == EAGAIN) ? kRetryStatus : kFailStatus); } static void vsnprintf_check(char* str, size_t size, const char* format, va_list args) { int rv; rv = vsnprintf(str, size, format, args); if (rv < 0) fail("tun: snprintf failed"); if ((size_t)rv >= size) fail("tun: string '%s...' doesn't fit into buffer", str); } static void snprintf_check(char* str, size_t size, const char* format, ...) { va_list args; va_start(args, format); vsnprintf_check(str, size, format, args); va_end(args); } #define COMMAND_MAX_LEN 128 static void execute_command(const char* format, ...) { va_list args; char command[COMMAND_MAX_LEN]; int rv; va_start(args, format); vsnprintf_check(command, sizeof(command), format, args); rv = system(command); if (rv != 0) fail("tun: command \"%s\" failed with code %d", &command[0], rv); va_end(args); } static int tunfd = -1; #define SYZ_TUN_MAX_PACKET_SIZE 1000 #define MAX_PIDS 32 #define ADDR_MAX_LEN 32 #define LOCAL_MAC "aa:aa:aa:aa:aa:%02hx" #define REMOTE_MAC "bb:bb:bb:bb:bb:%02hx" #define LOCAL_IPV4 "172.20.%d.170" #define REMOTE_IPV4 "172.20.%d.187" #define LOCAL_IPV6 "fe80::%02hxaa" #define REMOTE_IPV6 "fe80::%02hxbb" static void initialize_tun(uint64_t pid) { if (pid >= MAX_PIDS) fail("tun: no more than %d executors", MAX_PIDS); int id = pid; tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK); if (tunfd == -1) fail("tun: can't open /dev/net/tun"); char iface[IFNAMSIZ]; snprintf_check(iface, sizeof(iface), "syz%d", id); struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, iface, IFNAMSIZ); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) fail("tun: ioctl(TUNSETIFF) failed"); char local_mac[ADDR_MAX_LEN]; snprintf_check(local_mac, sizeof(local_mac), LOCAL_MAC, id); char remote_mac[ADDR_MAX_LEN]; snprintf_check(remote_mac, sizeof(remote_mac), REMOTE_MAC, id); char local_ipv4[ADDR_MAX_LEN]; snprintf_check(local_ipv4, sizeof(local_ipv4), LOCAL_IPV4, id); char remote_ipv4[ADDR_MAX_LEN]; snprintf_check(remote_ipv4, sizeof(remote_ipv4), REMOTE_IPV4, id); char local_ipv6[ADDR_MAX_LEN]; snprintf_check(local_ipv6, sizeof(local_ipv6), LOCAL_IPV6, id); char remote_ipv6[ADDR_MAX_LEN]; snprintf_check(remote_ipv6, sizeof(remote_ipv6), REMOTE_IPV6, id); execute_command("sysctl -w net.ipv6.conf.%s.accept_dad=0", iface); execute_command("sysctl -w net.ipv6.conf.%s.router_solicitations=0", iface); execute_command("ip link set dev %s address %s", iface, local_mac); execute_command("ip addr add %s/24 dev %s", local_ipv4, iface); execute_command("ip -6 addr add %s/120 dev %s", local_ipv6, iface); execute_command("ip neigh add %s lladdr %s dev %s nud permanent", remote_ipv4, remote_mac, iface); execute_command("ip -6 neigh add %s lladdr %s dev %s nud permanent", remote_ipv6, remote_mac, iface); execute_command("ip link set dev %s up", iface); } static void setup_tun(uint64_t pid, bool enable_tun) { if (enable_tun) initialize_tun(pid); } static void test(); void loop() { while (1) { test(); } } long r[66]; void* thr(void* arg) { switch ((long)arg) { case 0: r[0] = syscall(__NR_mmap, 0x20000000ul, 0xfff000ul, 0x3ul, 0x32ul, r[0], 0x0ul); break; case 1: r[1] = syscall(__NR_socket, 0xaul, 0x2ul, 0x0ul); break; case 2: *(uint32_t*)0x20eddf18 = (uint32_t)0x0; *(uint32_t*)0x20eddf28 = (uint32_t)0x80000; *(uint16_t*)0x20eddf38 = (uint16_t)0x204e; *(uint16_t*)0x20eddf3a = (uint16_t)0x0; *(uint16_t*)0x20eddf3c = (uint16_t)0x204e; *(uint16_t*)0x20eddf3e = (uint16_t)0x0; *(uint16_t*)0x20eddf40 = (uint16_t)0x2; *(uint8_t*)0x20eddf42 = (uint8_t)0x0; *(uint8_t*)0x20eddf43 = (uint8_t)0x80; *(uint8_t*)0x20eddf44 = (uint8_t)0x0; *(uint32_t*)0x20eddf48 = r[0]; *(uint32_t*)0x20eddf4c = r[0]; *(uint64_t*)0x20eddf50 = (uint64_t)0x0; *(uint64_t*)0x20eddf58 = (uint64_t)0x0; *(uint64_t*)0x20eddf60 = (uint64_t)0xffffffffffffffff; *(uint64_t*)0x20eddf68 = (uint64_t)0x0; *(uint64_t*)0x20eddf70 = (uint64_t)0x0; *(uint64_t*)0x20eddf78 = (uint64_t)0x0; *(uint64_t*)0x20eddf80 = (uint64_t)0x0; *(uint64_t*)0x20eddf88 = (uint64_t)0x2; *(uint64_t*)0x20eddf90 = (uint64_t)0x12; *(uint64_t*)0x20eddf98 = (uint64_t)0x0; *(uint64_t*)0x20eddfa0 = (uint64_t)0x0; *(uint64_t*)0x20eddfa8 = (uint64_t)0x3; *(uint32_t*)0x20eddfb0 = (uint32_t)0xfffffffffffffffc; *(uint32_t*)0x20eddfb4 = (uint32_t)0x0; *(uint8_t*)0x20eddfb8 = (uint8_t)0x0; *(uint8_t*)0x20eddfb9 = (uint8_t)0x0; *(uint8_t*)0x20eddfba = (uint8_t)0x0; *(uint8_t*)0x20eddfbb = (uint8_t)0x0; *(uint32_t*)0x20eddfc0 = (uint32_t)0x0; *(uint32_t*)0x20eddfd0 = (uint32_t)0x0; *(uint8_t*)0x20eddfd4 = (uint8_t)0x3; *(uint16_t*)0x20eddfd8 = (uint16_t)0x0; *(uint8_t*)0x20eddfdc = (uint8_t)0x0; *(uint8_t*)0x20eddfdd = (uint8_t)0x0; *(uint8_t*)0x20eddfde = (uint8_t)0x0; *(uint8_t*)0x20eddfdf = (uint8_t)0x0; *(uint8_t*)0x20eddfe0 = (uint8_t)0x0; *(uint8_t*)0x20eddfe1 = (uint8_t)0x0; *(uint8_t*)0x20eddfe2 = (uint8_t)0x0; *(uint8_t*)0x20eddfe3 = (uint8_t)0x0; *(uint8_t*)0x20eddfe4 = (uint8_t)0x0; *(uint8_t*)0x20eddfe5 = (uint8_t)0x0; *(uint8_t*)0x20eddfe6 = (uint8_t)0x0; *(uint8_t*)0x20eddfe7 = (uint8_t)0x0; *(uint8_t*)0x20eddfe8 = (uint8_t)0x0; *(uint8_t*)0x20eddfe9 = (uint8_t)0x0; *(uint8_t*)0x20eddfea = (uint8_t)0x0; *(uint8_t*)0x20eddfeb = (uint8_t)0x0; *(uint32_t*)0x20eddfec = (uint32_t)0x0; *(uint8_t*)0x20eddff0 = (uint8_t)0x0; *(uint8_t*)0x20eddff1 = (uint8_t)0x1; *(uint8_t*)0x20eddff2 = (uint8_t)0x4; *(uint32_t*)0x20eddff4 = (uint32_t)0x1; *(uint32_t*)0x20eddff8 = (uint32_t)0x5; *(uint32_t*)0x20eddffc = (uint32_t)0xffffffff; r[59] = syscall(__NR_setsockopt, r[1], 0x29ul, 0x23ul, 0x20eddf18ul, 0xe8ul); break; case 3: r[60] = syscall(__NR_socket, 0xful, 0x3ul, 0x2ul); break; case 4: *(uint16_t*)0x20abe000 = (uint16_t)0x1; memcpy((void*)0x20abe002, "\x2e\x2f\x66\x69\x6c\x65\x30\x00", 8); r[63] = syscall(__NR_recvfrom, r[60], 0x202f9fe8ul, 0x0ul, 0x2ul, 0x20abe000ul, 0xaul); break; case 5: memcpy((void*)0x20000ff0, "\x02\x12\xa1\x25\x02\x00\x00\x00\x09\x05" "\x00\xd9\x1d\xfb\x37\x00", 16); r[65] = syscall(__NR_write, r[60], 0x20000ff0ul, 0x10ul); break; } return 0; } void test() { long i; pthread_t th[12]; memset(r, -1, sizeof(r)); for (i = 0; i < 6; i++) { pthread_create(&th[i], 0, thr, (void*)i); usleep(rand() % 10000); } usleep(rand() % 100000); } int main() { setup_tun(0, true); loop(); return 0; }