// https://syzkaller.appspot.com/bug?id=de23f6e644d3432614a9ee76939949c960abea97 // 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 __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #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 uint64_t current_time_ms() { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) fail("clock_gettime failed"); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void execute_one(); extern unsigned long long procid; static void loop() { int iter; for (iter = 0;; iter++) { int pid = fork(); if (pid < 0) fail("clone failed"); if (pid == 0) { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); execute_one(); int fd; for (fd = 3; fd < 30; fd++) close(fd); doexit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { int res = waitpid(-1, &status, __WALL | WNOHANG); if (res == pid) { break; } usleep(1000); if (current_time_ms() - start < 5 * 1000) continue; kill(-pid, SIGKILL); kill(pid, SIGKILL); while (waitpid(-1, &status, __WALL) != pid) { } break; } } } 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 (__atomic_load_n(&running, __ATOMIC_RELAXED)) usleep((call == num_calls - 1) ? 10000 : 1000); break; } } } } uint64_t r[8] = {0xffffffffffffffff, 0x0, 0x0, 0xffffffffffffffff, 0x0, 0xffffffffffffffff, 0x0, 0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: res = syscall(__NR_inotify_init); if (res != -1) r[0] = res; break; case 1: res = syscall(__NR_fstat, 0xffffff9c, 0x20000000); if (res != -1) r[1] = *(uint32_t*)0x2000000c; break; case 2: *(uint32_t*)0x200000c0 = 0xc; res = syscall(__NR_getsockopt, -1, 1, 0x11, 0x20000080, 0x200000c0); if (res != -1) r[2] = *(uint32_t*)0x20000088; break; case 3: syscall(__NR_fchown, r[0], r[1], r[2]); break; case 4: *(uint64_t*)0x20000100 = 0; *(uint64_t*)0x20000108 = 0; syscall(__NR_nanosleep, 0x20000100, 0x20000140); break; case 5: res = syscall(__NR_socket, 2, 2, 0); if (res != -1) r[3] = res; break; case 6: *(uint32_t*)0x20000180 = 1; syscall(__NR_ioctl, r[3], 0x894c, 0x20000180); break; case 7: memcpy((void*)0x200001c0, "pkcs7_test", 11); *(uint8_t*)0x20000200 = 0x73; *(uint8_t*)0x20000201 = 0x79; *(uint8_t*)0x20000202 = 0x7a; *(uint8_t*)0x20000203 = 0x20; *(uint8_t*)0x20000204 = 0; res = syscall(__NR_add_key, 0x200001c0, 0x20000200, 0x20000240, 0, 0xfffffff8); if (res != -1) r[4] = res; break; case 8: syscall(__NR_keyctl, 5, r[4], 0x8200a00); break; case 9: res = syscall(__NR_dup2, r[0], r[0]); if (res != -1) r[5] = res; break; case 10: syscall(__NR_ioctl, r[5], 0x894b, 0x20000280); break; case 11: memcpy((void*)0x200002c0, "\x6e\x61\x74\x00\x00\x00\x00\x00\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*)0x200002e0 = 0; *(uint32_t*)0x200002e4 = 0; *(uint32_t*)0x200002e8 = 0; *(uint64_t*)0x200002f0 = 0; *(uint64_t*)0x200002f8 = 0; *(uint64_t*)0x20000300 = 0; *(uint64_t*)0x20000308 = 0; *(uint64_t*)0x20000310 = 0; *(uint64_t*)0x20000318 = 0; *(uint32_t*)0x20000320 = 0; *(uint64_t*)0x20000328 = 0; *(uint64_t*)0x20000330 = 0; *(uint32_t*)0x20000340 = 0x78; syscall(__NR_getsockopt, r[3], 0, 0x80, 0x200002c0, 0x20000340); break; case 12: memcpy((void*)0x20000380, "\x62\x72\x6f\x75\x74\x65\x00\x00\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*)0x200003a0 = 0; *(uint32_t*)0x200003a4 = 0; *(uint32_t*)0x200003a8 = 0; *(uint64_t*)0x200003b0 = 0; *(uint64_t*)0x200003b8 = 0; *(uint64_t*)0x200003c0 = 0; *(uint64_t*)0x200003c8 = 0; *(uint64_t*)0x200003d0 = 0; *(uint64_t*)0x200003d8 = 0; *(uint32_t*)0x200003e0 = 0; *(uint64_t*)0x200003e8 = 0; *(uint64_t*)0x200003f0 = 0; *(uint32_t*)0x20000400 = 0x78; syscall(__NR_getsockopt, r[3], 0, 0x80, 0x20000380, 0x20000400); break; case 13: syscall(__NR_fcntl, r[0], 2, 1); break; case 14: *(uint16_t*)0x20000440 = 0xa; *(uint16_t*)0x20000442 = htobe16(0x4e23); *(uint32_t*)0x20000444 = 0x99; *(uint64_t*)0x20000448 = htobe64(0); *(uint64_t*)0x20000450 = htobe64(1); *(uint32_t*)0x20000458 = 6; *(uint16_t*)0x200004c0 = 5; *(uint16_t*)0x200004c2 = 0xff; *(uint32_t*)0x200004c4 = 0; memcpy((void*)0x200004c8, "\x72\x4f\xde\x1b\xd5\xaf\x49\x05\x0b\xc9\x8a\xa5\x5d\x0c\xf6\x54" "\x19\xb7\x47\xa7\xbf\x6a\xaf\x6a\x84\x13\xe6\xae\xe9\x46\xd3\x96" "\x9f\xe7\x02\x3a\x86\x82\xba\x6c\x1d\x73\xa7\xdc\x49\x28\x2b\xc7" "\x43\x20\xb1\x8f\x45\x2f\xd4\xed\x65\x0c\x3c\xcb\x61\xc0\xa1\x90" "\x75\xe6\x76\x01\xb8\x47\xd2\xc1\xfd\x7d\x54\x73\xa0\x2a\xb1\x04", 80); syscall(__NR_setsockopt, r[5], 6, 0xe, 0x20000440, 0xd8); break; case 15: syscall(__NR_ioctl, r[5], 0x5413, 0x20000540); break; case 16: memcpy((void*)0x20000580, "trusted.", 8); memcpy((void*)0x20000588, "{em0.]ppp0wlan0", 16); memcpy((void*)0x200005c0, "broute", 7); syscall(__NR_fsetxattr, r[5], 0x20000580, 0x200005c0, 7, 1); break; case 17: res = syscall(__NR_shmget, 0x798dd815, 0x3000, 0x54000004, 0x20ffa000); if (res != -1) r[6] = res; break; case 18: syscall(__NR_shmctl, r[6], 0xe, 0x20000600); break; case 19: memcpy((void*)0x20000640, "./file0", 8); *(uint64_t*)0x20000680 = 4; *(uint64_t*)0x20000688 = 0xc84; syscall(__NR_utime, 0x20000640, 0x20000680); break; case 20: memcpy((void*)0x200006c0, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); *(uint16_t*)0x200006d0 = 2; *(uint16_t*)0x200006d2 = htobe16(0x4e20); *(uint32_t*)0x200006d4 = htobe32(0xe0000002); *(uint8_t*)0x200006d8 = 0; *(uint8_t*)0x200006d9 = 0; *(uint8_t*)0x200006da = 0; *(uint8_t*)0x200006db = 0; *(uint8_t*)0x200006dc = 0; *(uint8_t*)0x200006dd = 0; *(uint8_t*)0x200006de = 0; *(uint8_t*)0x200006df = 0; syscall(__NR_ioctl, r[5], 0x8917, 0x200006c0); break; case 21: syscall(__NR_keyctl, 0x13, r[4], 0x7fff, 0x80, r[4]); break; case 22: syscall(__NR_socket, 2, 2, 1); break; case 23: memcpy((void*)0x20000780, "/dev/ptmx", 10); res = syscall(__NR_openat, 0xffffffffffffff9c, 0x20000780, 0x101000, 0); if (res != -1) r[7] = res; break; case 24: syscall(__NR_read, r[7], 0x200007c0, 0xa7); break; } } void execute_one() { execute(25); collide = 1; execute(25); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (;;) { loop(); } }