// https://syzkaller.appspot.com/bug?id=5735d842f7ea3ed9220aca64952ac4aba7ba741c // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include static void execute_one(); extern unsigned long long procid; void loop() { while (1) { execute_one(); } } 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[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x0}; unsigned long long procid; void execute_call(int call) { long res; switch (call) { case 0: *(uint32_t*)0x200000c0 = 0; *(uint32_t*)0x200000c4 = 0; *(uint32_t*)0x200000c8 = 0; *(uint32_t*)0x200000cc = 0; *(uint32_t*)0x200000d0 = 0; *(uint32_t*)0x200000d4 = 0; break; case 1: res = syscall(__NR_socket, 0xa, 0x2100000000000002, 0); if (res != -1) r[0] = res; break; case 2: res = syscall(__NR_socket, 0x10, 3, 6); if (res != -1) r[1] = res; break; case 3: *(uint16_t*)0x20000080 = 0x10; *(uint16_t*)0x20000082 = 0; *(uint32_t*)0x20000084 = 0; *(uint32_t*)0x20000088 = 1; syscall(__NR_bind, r[1], 0x20000080, 0xc); break; case 4: *(uint16_t*)0x200003c0 = 0xa; *(uint16_t*)0x200003c2 = htobe16(0); *(uint32_t*)0x200003c4 = 0; *(uint8_t*)0x200003c8 = 0; *(uint8_t*)0x200003c9 = 0; *(uint8_t*)0x200003ca = 0; *(uint8_t*)0x200003cb = 0; *(uint8_t*)0x200003cc = 0; *(uint8_t*)0x200003cd = 0; *(uint8_t*)0x200003ce = 0; *(uint8_t*)0x200003cf = 0; *(uint8_t*)0x200003d0 = 0; *(uint8_t*)0x200003d1 = 0; *(uint8_t*)0x200003d2 = -1; *(uint8_t*)0x200003d3 = -1; *(uint32_t*)0x200003d4 = htobe32(0x7f000001); *(uint32_t*)0x200003d8 = 0; syscall(__NR_connect, r[0], 0x200003c0, 0x1c); break; case 5: *(uint8_t*)0x200001c0 = 0xfe; *(uint8_t*)0x200001c1 = 0x80; *(uint8_t*)0x200001c2 = 0; *(uint8_t*)0x200001c3 = 0; *(uint8_t*)0x200001c4 = 0; *(uint8_t*)0x200001c5 = 0; *(uint8_t*)0x200001c6 = 0; *(uint8_t*)0x200001c7 = 0; *(uint8_t*)0x200001c8 = 0; *(uint8_t*)0x200001c9 = 0; *(uint8_t*)0x200001ca = 0; *(uint8_t*)0x200001cb = 0; *(uint8_t*)0x200001cc = 0; *(uint8_t*)0x200001cd = 0; *(uint8_t*)0x200001ce = 0; *(uint8_t*)0x200001cf = 0xbb; *(uint64_t*)0x200001d0 = htobe64(0); *(uint64_t*)0x200001d8 = htobe64(1); *(uint16_t*)0x200001e0 = htobe16(0); *(uint16_t*)0x200001e2 = htobe16(0); *(uint16_t*)0x200001e4 = htobe16(0); *(uint16_t*)0x200001e6 = htobe16(0); *(uint16_t*)0x200001e8 = 2; *(uint8_t*)0x200001ea = 0; *(uint8_t*)0x200001eb = 0; *(uint8_t*)0x200001ec = 0; *(uint32_t*)0x200001f0 = 0; *(uint32_t*)0x200001f4 = 0; *(uint64_t*)0x200001f8 = 0; *(uint64_t*)0x20000200 = 0; *(uint64_t*)0x20000208 = 0; *(uint64_t*)0x20000210 = 0; *(uint64_t*)0x20000218 = 0; *(uint64_t*)0x20000220 = 0; *(uint64_t*)0x20000228 = 0; *(uint64_t*)0x20000230 = 0; *(uint64_t*)0x20000238 = 0; *(uint64_t*)0x20000240 = 0; *(uint64_t*)0x20000248 = 0; *(uint64_t*)0x20000250 = 0; *(uint32_t*)0x20000258 = 0; *(uint32_t*)0x2000025c = 0; *(uint8_t*)0x20000260 = 1; *(uint8_t*)0x20000261 = 0; *(uint8_t*)0x20000262 = 0; *(uint8_t*)0x20000263 = 0; *(uint8_t*)0x20000268 = 0xac; *(uint8_t*)0x20000269 = 0x14; *(uint8_t*)0x2000026a = 0x14; *(uint8_t*)0x2000026b = 0; *(uint32_t*)0x20000278 = htobe32(0); *(uint8_t*)0x2000027c = 0x2b; *(uint16_t*)0x20000280 = 0; *(uint64_t*)0x20000284 = htobe64(0); *(uint64_t*)0x2000028c = htobe64(1); *(uint32_t*)0x20000294 = 0; *(uint8_t*)0x20000298 = 0; *(uint8_t*)0x20000299 = 0; *(uint8_t*)0x2000029a = 0x90; *(uint32_t*)0x2000029c = 0; *(uint32_t*)0x200002a0 = 0; *(uint32_t*)0x200002a4 = 0; syscall(__NR_setsockopt, r[0], 0x29, 0x23, 0x200001c0, 0xe8); break; case 6: res = syscall(__NR_inotify_init1, 0); if (res != -1) r[2] = res; break; case 7: syscall(__NR_fcntl, r[2], 8, -1); break; case 8: res = syscall(__NR_fcntl, r[2], 0x10, 0x20000080); if (res != -1) r[3] = *(uint32_t*)0x20000084; break; case 9: syscall(__NR_ptrace, 0xd, r[3], 0x4e5, 0x20000000); break; case 10: syscall(__NR_ptrace, 0x4206, r[3], 0, 0); break; case 11: syscall(__NR_ptrace, 0x4207, r[3]); break; } } void execute_one() { execute(12); collide = 1; execute(12); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (procid = 0; procid < 8; procid++) { if (fork() == 0) { for (;;) { loop(); } } } sleep(1000000); return 0; }