// https://syzkaller.appspot.com/bug?id=af3a0728c8cbf6903ec2b0836441287cced00c1c // 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(); 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 < 3 * 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, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: res = syscall(__NR_socket, 1, 7, 0); if (res != -1) r[0] = res; break; case 1: res = syscall(__NR_dup, -1); if (res != -1) r[1] = res; break; case 2: memcpy((void*)0x20000000, "\x54\x50\x52\x4f\x58\x59\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00", 29); *(uint8_t*)0x2000001d = 0; *(uint32_t*)0x20000680 = 0x1e; syscall(__NR_getsockopt, r[1], 0, 0x43, 0x20000000, 0x20000680); break; case 3: syscall(__NR_dup, r[1]); break; case 4: *(uint64_t*)0x200006c0 = 0x20000100; *(uint64_t*)0x20000100 = 0; *(uint32_t*)0x20000108 = 0; *(uint32_t*)0x2000010c = 0; *(uint16_t*)0x20000110 = 7; *(uint16_t*)0x20000112 = 0xf12; *(uint32_t*)0x20000114 = r[0]; *(uint64_t*)0x20000118 = 0x20000040; *(uint64_t*)0x20000120 = 0; *(uint64_t*)0x20000128 = 9; *(uint64_t*)0x20000130 = 0; *(uint32_t*)0x20000138 = 1; *(uint32_t*)0x2000013c = r[1]; *(uint64_t*)0x200006c8 = 0x20000200; *(uint64_t*)0x20000200 = 0; *(uint32_t*)0x20000208 = 0; *(uint32_t*)0x2000020c = 0; *(uint16_t*)0x20000210 = 7; *(uint16_t*)0x20000212 = 0x46; *(uint32_t*)0x20000214 = r[0]; *(uint64_t*)0x20000218 = 0x20000140; *(uint64_t*)0x20000220 = 0; *(uint64_t*)0x20000228 = 5; *(uint64_t*)0x20000230 = 0; *(uint32_t*)0x20000238 = 0; *(uint32_t*)0x2000023c = r[1]; *(uint64_t*)0x200006d0 = 0x200002c0; *(uint64_t*)0x200002c0 = 0; *(uint32_t*)0x200002c8 = 0; *(uint32_t*)0x200002cc = 0; *(uint16_t*)0x200002d0 = 5; *(uint16_t*)0x200002d2 = 8; *(uint32_t*)0x200002d4 = r[0]; *(uint64_t*)0x200002d8 = 0x20000240; *(uint64_t*)0x200002e0 = 0; *(uint64_t*)0x200002e8 = 1; *(uint64_t*)0x200002f0 = 0; *(uint32_t*)0x200002f8 = 0; *(uint32_t*)0x200002fc = r[1]; *(uint64_t*)0x200006d8 = 0x20000400; *(uint64_t*)0x20000400 = 0; *(uint32_t*)0x20000408 = 0; *(uint32_t*)0x2000040c = 0; *(uint16_t*)0x20000410 = 0xd; *(uint16_t*)0x20000412 = 1; *(uint32_t*)0x20000414 = r[0]; *(uint64_t*)0x20000418 = 0x20000300; *(uint64_t*)0x20000420 = 0; *(uint64_t*)0x20000428 = 0xfff; *(uint64_t*)0x20000430 = 0; *(uint32_t*)0x20000438 = 1; *(uint32_t*)0x2000043c = r[1]; *(uint64_t*)0x200006e0 = 0x20000480; *(uint64_t*)0x20000480 = 0; *(uint32_t*)0x20000488 = 0; *(uint32_t*)0x2000048c = 0; *(uint16_t*)0x20000490 = 8; *(uint16_t*)0x20000492 = 0; *(uint32_t*)0x20000494 = r[1]; *(uint64_t*)0x20000498 = 0x20000440; *(uint64_t*)0x200004a0 = 0; *(uint64_t*)0x200004a8 = 3; *(uint64_t*)0x200004b0 = 0; *(uint32_t*)0x200004b8 = 1; *(uint32_t*)0x200004bc = r[1]; *(uint64_t*)0x200006e8 = 0x20000580; *(uint64_t*)0x20000580 = 0; *(uint32_t*)0x20000588 = 0; *(uint32_t*)0x2000058c = 0; *(uint16_t*)0x20000590 = 1; *(uint16_t*)0x20000592 = 6; *(uint32_t*)0x20000594 = r[0]; *(uint64_t*)0x20000598 = 0x200004c0; *(uint64_t*)0x200005a0 = 0; *(uint64_t*)0x200005a8 = 1; *(uint64_t*)0x200005b0 = 0; *(uint32_t*)0x200005b8 = 0; *(uint32_t*)0x200005bc = r[1]; *(uint64_t*)0x200006f0 = 0x20000640; *(uint64_t*)0x20000640 = 0; *(uint32_t*)0x20000648 = 0; *(uint32_t*)0x2000064c = 0; *(uint16_t*)0x20000650 = 1; *(uint16_t*)0x20000652 = 0xfffb; *(uint32_t*)0x20000654 = r[1]; *(uint64_t*)0x20000658 = 0x200005c0; *(uint64_t*)0x20000660 = 0; *(uint64_t*)0x20000668 = 0xfff; *(uint64_t*)0x20000670 = 0; *(uint32_t*)0x20000678 = 1; *(uint32_t*)0x2000067c = r[1]; syscall(__NR_io_submit, 0, 7, 0x200006c0); break; case 5: *(uint64_t*)0x200015c0 = 0x20000180; *(uint32_t*)0x200015c8 = 0x80; *(uint64_t*)0x200015d0 = 0x20001540; *(uint64_t*)0x20001540 = 0x20000200; *(uint64_t*)0x20001548 = 0x1000; *(uint64_t*)0x20001550 = 0x20001200; *(uint64_t*)0x20001558 = 0xfd; *(uint64_t*)0x20001560 = 0x20001300; *(uint64_t*)0x20001568 = 0x1d; *(uint64_t*)0x20001570 = 0x20001340; *(uint64_t*)0x20001578 = 0xf1; *(uint64_t*)0x20001580 = 0x20001440; *(uint64_t*)0x20001588 = 0x73; *(uint64_t*)0x20001590 = 0x200014c0; *(uint64_t*)0x20001598 = 0x7a; *(uint64_t*)0x200015d8 = 6; *(uint64_t*)0x200015e0 = 0; *(uint64_t*)0x200015e8 = 0; *(uint32_t*)0x200015f0 = 1; res = syscall(__NR_recvmsg, 0xffffff9c, 0x200015c0, 0x40000002); if (res != -1) r[2] = *(uint32_t*)0x2000018a; break; case 6: *(uint16_t*)0x20001600 = 2; *(uint16_t*)0x20001602 = htobe16(0x4e23); *(uint8_t*)0x20001604 = 0xac; *(uint8_t*)0x20001605 = 0x14; *(uint8_t*)0x20001606 = 0x14; *(uint8_t*)0x20001607 = 0xa; *(uint8_t*)0x20001608 = 0; *(uint8_t*)0x20001609 = 0; *(uint8_t*)0x2000160a = 0; *(uint8_t*)0x2000160b = 0; *(uint8_t*)0x2000160c = 0; *(uint8_t*)0x2000160d = 0; *(uint8_t*)0x2000160e = 0; *(uint8_t*)0x2000160f = 0; syscall(__NR_bind, r[2], 0x20001600, 0x10); break; case 7: res = syscall(__NR_io_setup, 0, 0x200000c0); if (res != -1) r[3] = *(uint64_t*)0x200000c0; break; case 8: *(uint64_t*)0x20000080 = 0x77359400; *(uint64_t*)0x20000088 = 0; syscall(__NR_io_getevents, r[3], 0xffffffffffff0103, 0x7fffffffffffcfc, 0x20000000, 0x20000080); break; case 9: syscall(__NR_io_setup, 7, 0x20000000); break; case 10: *(uint32_t*)0x20000040 = 0; res = syscall(__NR_accept, 0xffffff9c, 0, 0x20000040); if (res != -1) r[4] = res; break; case 11: *(uint32_t*)0x20000140 = 8; syscall(__NR_getsockopt, r[4], 1, 0xd, 0x20000100, 0x20000140); break; case 12: res = syscall(__NR_socket, 1, 1, 0); if (res != -1) r[5] = res; break; case 13: res = syscall(__NR_socket, 0xa, 0x80807, -1); if (res != -1) r[6] = res; break; case 14: *(uint16_t*)0x20000000 = 0x303; *(uint16_t*)0x20000002 = 0x33; syscall(__NR_setsockopt, r[6], 6, 1, 0x20000000, 4); break; case 15: *(uint32_t*)0x200001c0 = 0; *(uint32_t*)0x200001c4 = 0; syscall(__NR_setsockopt, r[5], 1, 0xd, 0x200001c0, 0xfffffffffffffe5e); break; case 16: *(uint16_t*)0x20002500 = 0; *(uint64_t*)0x20002508 = 0x200024c0; syscall(__NR_ioctl, -1, 0x4b66, 0x20002500); break; case 17: memcpy((void*)0x20000000, "/dev/ptmx", 10); res = syscall(__NR_openat, 0xffffffffffffff9c, 0x20000000, 0x280, 0); if (res != -1) r[7] = res; break; case 18: syscall(__NR_read, r[7], 0x20000040, 0x27); break; } } void execute_one() { execute(19); collide = 1; execute(19); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (;;) { loop(); } }