// https://syzkaller.appspot.com/bug?id=2b6a5e7ed9c189aadc974fc5ff168b131c005947 // 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 #include __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #include #include const int kFailStatus = 67; const int kRetryStatus = 69; static void fail(const char* msg, ...) { int e = errno; 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 #define PATH_PREFIX \ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin " #define PATH_PREFIX_LEN (sizeof(PATH_PREFIX) - 1) static void execute_command(const char* format, ...) { va_list args; char command[PATH_PREFIX_LEN + COMMAND_MAX_LEN]; int rv; va_start(args, format); memcpy(command, PATH_PREFIX, PATH_PREFIX_LEN); vsnprintf_check(command + PATH_PREFIX_LEN, COMMAND_MAX_LEN, 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; static int tun_frags_enabled; #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" #define IFF_NAPI 0x0010 #define IFF_NAPI_FRAGS 0x0020 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) { printf( "tun: can't open /dev/net/tun: please enable CONFIG_TUN=y\n"); printf("otherwise fuzzing or reproducing might not work as " "intended\n"); return; } 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 | IFF_NAPI | IFF_NAPI_FRAGS; if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) { ifr.ifr_flags = IFF_TAP | IFF_NO_PI; if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) fail("tun: ioctl(TUNSETIFF) failed"); } if (ioctl(tunfd, TUNGETIFF, (void*)&ifr) < 0) fail("tun: ioctl(TUNGETIFF) failed"); tun_frags_enabled = (ifr.ifr_flags & IFF_NAPI_FRAGS) != 0; 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(); } } struct thread_t { int created, running, call; pthread_t th; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static int collide; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { while (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &th->running, FUTEX_WAIT, 0, 0); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 0, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); } return 0; } static void execute(int num_calls) { int call, thread; running = 0; for (call = 0; call < num_calls; call++) { for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); pthread_create(&th->th, &attr, thr, th); } if (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) { th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); if (collide && call % 2) break; struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 20 * 1000 * 1000; syscall(SYS_futex, &th->running, FUTEX_WAIT, 1, &ts); if (running) usleep((call == num_calls - 1) ? 10000 : 1000); break; } } } } long r[3]; uint64_t procid; void execute_call(int call) { switch (call) { case 0: syscall(__NR_mmap, 0x20000000, 0xfff000, 0x3, 0x32, 0xffffffff, 0x0); break; case 1: memcpy((void*)0x20000000, "./file0", 8); syscall(__NR_open, 0x20000000, 0x82000, 0x1); break; case 2: memcpy((void*)0x20000ff7, "/dev/kvm", 9); r[0] = syscall(__NR_openat, 0xffffffffffffff9c, 0x20000ff7, 0x0, 0x0); break; case 3: *(uint32_t*)0x209ff000 = 0x81; *(uint32_t*)0x209ff004 = 0xbef; *(uint64_t*)0x209ff008 = 0x20021000; *(uint64_t*)0x209ff010 = 0x205af000; *(uint8_t*)0x209ff018 = 0xe3; *(uint8_t*)0x209ff019 = 0x0; *(uint8_t*)0x209ff01a = 0x0; *(uint8_t*)0x209ff01b = 0x0; *(uint8_t*)0x209ff01c = 0x0; *(uint8_t*)0x209ff01d = 0x0; *(uint8_t*)0x209ff01e = 0x0; *(uint8_t*)0x209ff01f = 0x0; *(uint8_t*)0x209ff020 = 0x0; *(uint8_t*)0x209ff021 = 0x0; *(uint8_t*)0x209ff022 = 0x0; *(uint8_t*)0x209ff023 = 0x0; *(uint8_t*)0x209ff024 = 0x0; *(uint8_t*)0x209ff025 = 0x0; *(uint8_t*)0x209ff026 = 0x0; *(uint8_t*)0x209ff027 = 0x0; *(uint8_t*)0x209ff028 = 0x0; *(uint8_t*)0x209ff029 = 0x0; *(uint8_t*)0x209ff02a = 0x0; *(uint8_t*)0x209ff02b = 0x0; *(uint8_t*)0x209ff02c = 0x0; *(uint8_t*)0x209ff02d = 0x0; *(uint8_t*)0x209ff02e = 0x0; *(uint8_t*)0x209ff02f = 0x0; *(uint8_t*)0x209ff030 = 0x0; *(uint8_t*)0x209ff031 = 0x0; *(uint8_t*)0x209ff032 = 0x0; *(uint8_t*)0x209ff033 = 0x0; *(uint8_t*)0x209ff034 = 0x0; *(uint8_t*)0x209ff035 = 0x0; *(uint8_t*)0x209ff036 = 0x0; *(uint8_t*)0x209ff037 = 0x0; memcpy((void*)0x20021000, "\x58\x82\xa9\xd3\xe5\x65\x41\xe5\x7f\x43\x7c\x7d\x4f\x2d" "\x47\x66\xc8\x11\xdd\xb6\x83\x0c\xb0\x5a\x2c\x38\x64\x6b" "\xd1\x93\xbd\x81\x89\xe5\xb9\x9a\xe5\xf0\xfe\xec\x40\x85" "\x30\x01\xf9\xda\x41\xc9\x6b\x08\x86\x8c\x40\xb2\x13\xc5" "\x27\xab\x2c\x43\x1a\x93\x35\x68\x8c\xdf\x9d\x84\xf1\x9c" "\x0e\x44\x5d\xe5\x03\x67\x14\x9b\x3e\xf9\x0e\x1a\x67\x3a" "\x72\x06\xb7\xaa\x80\xc3\xe4\x3d\x87\x62\xed\xad\x45\xd0" "\x0c\x91\x33\xd9\x16\x7d\x20\x5d\x45\xd8\x59\xe9\x5a\x2f" "\x9c\x72\x5c\xb2\x62\xa6\x3c\xf0\xbd\xcb\xbd\x30\x20\x7d" "\x3c\xd8\xa4\x0d\x80\xbf\x80\x45\xdb\xba\x0f\xf0\xd8\x44" "\x84\xab\x29\xcd\x8b\xf0\xe2\x3c\x60\x3a\x0b\xdd\x64\x7b" "\x3d\xcf\x01\x34\x30\xd5\x0d\x07\xad\x96\xb7\xad\xd6\x2b" "\x1a\xc6\x3a\xc0\x73\x92\x26\x73\xab\x2c\x72\x1c\x02\xfc" "\x19\xae\x00\xba\x1a\x3c\xf6\xb0\x91\x1c\xf9\x02\x49\x9e" "\x68\xf1\x28\x3f\xbd\x78\x6f\xa5\xa0\x51\x06\x24\x78\x60" "\x1f\x30\x42\xdf\x30\x2f\x3c\xce\xe9\x8a\xfc\x92\x52\x28" "\x22\xf1\x94", 227); syscall(__NR_ioctl, 0xffffffff, 0x4038ae7a, 0x209ff000); break; case 4: *(uint32_t*)0x2001d000 = 0x2; *(uint32_t*)0x2001d004 = 0x78; *(uint8_t*)0x2001d008 = 0xe3; *(uint8_t*)0x2001d009 = 0x0; *(uint8_t*)0x2001d00a = 0x0; *(uint8_t*)0x2001d00b = 0x0; *(uint32_t*)0x2001d00c = 0x0; *(uint64_t*)0x2001d010 = 0x0; *(uint64_t*)0x2001d018 = 0x0; *(uint64_t*)0x2001d020 = 0x0; *(uint8_t*)0x2001d028 = 0xfe; *(uint8_t*)0x2001d029 = 0x0; *(uint8_t*)0x2001d02a = 0x0; *(uint8_t*)0x2001d02b = 0x0; *(uint32_t*)0x2001d02c = 0x0; *(uint32_t*)0x2001d030 = 0x0; *(uint32_t*)0x2001d034 = 0x0; *(uint64_t*)0x2001d038 = 0x0; *(uint64_t*)0x2001d040 = 0x0; *(uint64_t*)0x2001d048 = 0x0; *(uint64_t*)0x2001d050 = 0x0; *(uint64_t*)0x2001d058 = 0x0; *(uint32_t*)0x2001d060 = 0x0; *(uint64_t*)0x2001d068 = 0x0; *(uint32_t*)0x2001d070 = 0x0; *(uint16_t*)0x2001d074 = 0x0; *(uint16_t*)0x2001d076 = 0x0; syscall(__NR_perf_event_open, 0x2001d000, 0x0, 0xffffffffffffffff, 0xffffffff, 0x0); break; case 5: *(uint16_t*)0x207ec000 = 0xffff; *(uint16_t*)0x207ec002 = 0x0; *(uint16_t*)0x207ec004 = 0x4; *(uint32_t*)0x207ec008 = 0x0; *(uint32_t*)0x207ec00c = 0x1fd; *(uint32_t*)0x207ec010 = 0x0; *(uint32_t*)0x207ec014 = 0x1; *(uint32_t*)0x207ec018 = 0xfffffff8; *(uint32_t*)0x207ec01c = 0x0; syscall(__NR_setsockopt, 0xffffffff, 0x84, 0xa, 0x207ec000, 0x20); break; case 6: r[1] = syscall(__NR_ioctl, r[0], 0xae01, 0x0); break; case 7: r[2] = syscall(__NR_ioctl, r[1], 0xae41, 0x0); break; case 8: syscall(__NR_clock_gettime, 0x0, 0x20000000); break; case 9: *(uint32_t*)0x20001000 = 0x10005; *(uint32_t*)0x20001004 = 0x0; *(uint64_t*)0x20001008 = 0x0; *(uint64_t*)0x20001010 = 0x2000; *(uint64_t*)0x20001018 = 0x20000000; syscall(__NR_ioctl, r[1], 0x4020ae46, 0x20001000); break; case 10: syscall(__NR_ioctl, r[2], 0xaeb7); break; case 11: *(uint32_t*)0x202ccffc = 0xe8; syscall(__NR_getsockopt, 0xffffffff, 0x29, 0x23, 0x2070bf18, 0x202ccffc); break; case 12: syscall(__NR_ioctl, r[2], 0xae80, 0x0); break; case 13: syscall(__NR_ioctl, r[2], 0xae80, 0x0); break; } } void test() { memset(r, -1, sizeof(r)); execute(14); collide = 1; execute(14); } int main() { int i; for (i = 0; i < 8; i++) { if (fork() == 0) { procid = i; setup_tun(i, true); loop(); return 0; } } sleep(1000000); return 0; }