// https://syzkaller.appspot.com/bug?id=28f3c6f048653756fa6d137e67309ad83c7f2fde // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #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 #include #include #include #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 use_temporary_dir() { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) fail("failed to mkdtemp"); if (chmod(tmpdir, 0777)) fail("failed to chmod"); if (chdir(tmpdir)) fail("failed to chdir"); } 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 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); 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; } } } } uint64_t r[1] = {0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: res = syscall(__NR_socket, 2, 0x4000000000000001, 0); if (res != -1) r[0] = res; break; case 1: *(uint16_t*)0x20deb000 = 2; *(uint16_t*)0x20deb002 = htobe16(0x4e23); *(uint32_t*)0x20deb004 = htobe32(0xe0000001); *(uint8_t*)0x20deb008 = 0; *(uint8_t*)0x20deb009 = 0; *(uint8_t*)0x20deb00a = 0; *(uint8_t*)0x20deb00b = 0; *(uint8_t*)0x20deb00c = 0; *(uint8_t*)0x20deb00d = 0; *(uint8_t*)0x20deb00e = 0; *(uint8_t*)0x20deb00f = 0; syscall(__NR_bind, r[0], 0x20deb000, 0x10); break; case 2: *(uint16_t*)0x20e68000 = 2; *(uint16_t*)0x20e68002 = htobe16(0x4e23); *(uint32_t*)0x20e68004 = htobe32(0x7f000001); *(uint8_t*)0x20e68008 = 0; *(uint8_t*)0x20e68009 = 0; *(uint8_t*)0x20e6800a = 0; *(uint8_t*)0x20e6800b = 0; *(uint8_t*)0x20e6800c = 0; *(uint8_t*)0x20e6800d = 0; *(uint8_t*)0x20e6800e = 0; *(uint8_t*)0x20e6800f = 0; syscall(__NR_sendto, r[0], 0x20a88f88, 0x29f, 0x200007fd, 0x20e68000, 0x10); break; case 3: *(uint32_t*)0x200000c0 = -1; syscall(__NR_write, r[0], 0x200000c0, 0xffffffe7); break; case 4: *(uint64_t*)0x20000140 = 0x20000080; *(uint16_t*)0x20000080 = 0x10; *(uint16_t*)0x20000082 = 0; *(uint32_t*)0x20000084 = 0; *(uint32_t*)0x20000088 = 0; *(uint32_t*)0x20000148 = 0xc; *(uint64_t*)0x20000150 = 0x20000100; *(uint64_t*)0x20000100 = 0x200003c0; *(uint32_t*)0x200003c0 = 0x14; *(uint8_t*)0x200003c4 = 0; *(uint8_t*)0x200003c5 = 0; *(uint16_t*)0x200003c6 = 0; *(uint32_t*)0x200003c8 = 0; *(uint32_t*)0x200003cc = 0; *(uint8_t*)0x200003d0 = 0; *(uint8_t*)0x200003d1 = 0; *(uint16_t*)0x200003d2 = htobe16(0); *(uint64_t*)0x20000108 = 0x14; *(uint64_t*)0x20000158 = 1; *(uint64_t*)0x20000160 = 0; *(uint64_t*)0x20000168 = 0; *(uint32_t*)0x20000170 = 0; syscall(__NR_sendmsg, r[0], 0x20000140, 0); break; case 5: *(uint16_t*)0x20000000 = 0; *(uint8_t*)0x20000002 = 0; *(uint32_t*)0x20000004 = 0; syscall(__NR_connect, r[0], 0x20000000, 0x80); break; case 6: *(uint16_t*)0x20000180 = 2; *(uint16_t*)0x20000182 = htobe16(0x4e23); *(uint32_t*)0x20000184 = htobe32(0x7f000001); *(uint8_t*)0x20000188 = 0; *(uint8_t*)0x20000189 = 0; *(uint8_t*)0x2000018a = 0; *(uint8_t*)0x2000018b = 0; *(uint8_t*)0x2000018c = 0; *(uint8_t*)0x2000018d = 0; *(uint8_t*)0x2000018e = 0; *(uint8_t*)0x2000018f = 0; syscall(__NR_connect, r[0], 0x20000180, 0x10); break; } } void loop() { execute(7); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); use_temporary_dir(); loop(); return 0; }