// https://syzkaller.appspot.com/bug?id=5b91762c24dc0a4ff2a974ddf8d10713e0026f5a // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include 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; } } } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: memcpy((void*)0x20000140, "./file0/file0", 14); syscall(__NR_open, 0x20000140, 0, 0); break; case 1: memcpy((void*)0x200001c0, "./file0", 8); res = syscall(__NR_open, 0x200001c0, 0x1fffe, 0); if (res != -1) r[0] = res; break; case 2: res = syscall(__NR_socket, 2, 6, 0); if (res != -1) r[1] = res; break; case 3: memcpy((void*)0x20000880, "\x73\x65\x63\x75\x72\x69\x74\x79\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00", 32); *(uint32_t*)0x200008a0 = 3; *(uint64_t*)0x200008a8 = 0; *(uint64_t*)0x200008b0 = 0; *(uint64_t*)0x200008b8 = 0; *(uint64_t*)0x200008c0 = 0; *(uint64_t*)0x200008c8 = 0; *(uint64_t*)0x200008d0 = 0; syscall(__NR_setsockopt, r[1], 0, 0x41, 0x20000880, 0x58); break; case 4: *(uint64_t*)0x20000840 = 0x20000100; *(uint64_t*)0x20000848 = 0; syscall(__NR_pwritev, -1, 0x20000840, 1, 0); break; case 5: syscall(__NR_lseek, r[0], 0, 1); break; case 6: memcpy((void*)0x20000500, "./file0", 8); res = syscall(__NR_open, 0x20000500, 2, 0); if (res != -1) r[2] = res; break; case 7: memcpy((void*)0x20000300, "\xd8\x8a\x8d\x38\x14\x4e\x50\x13\xd4\x73\xc0\xac\x2c\xa6\x1f\xf3" "\xb7\x49\xa4\xf5\xc7\xe6\xe9\xc2\xce\x58\x6e\x5c\xfc\xa5\xd6\x0f" "\xfc\x9a\x4d\xf7\x18\x56\x92\x5b\x30\x0a\xb3\x9b\x1d\xd5\x92\x38" "\x58\x21\xfa\xec\xb0\x39\xbc\xdc\x47\x5f\xfb\xac\xb9\x82\x18\x70" "\x73\xfc\x47\x9f\x1c\xc6\xff\xa0\x00\x0a\xf0\x02\x6e\x75\x92\x1d" "\x8a\x83\x10\x07\x1e\xc2\x8e\x0e\x62\x92\x68\x07\x55\xe4\x70\xaa" "\x73", 97); syscall(__NR_write, r[2], 0x20000300, 0x61); break; case 8: *(uint64_t*)0x20000040 = 0; syscall(__NR_sendfile, r[2], r[2], 0x20000040, 0x7527fb3200000000); break; } } void loop() { execute(9); collide = 1; execute(9); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); loop(); return 0; }