// https://syzkaller.appspot.com/bug?id=2a622455acd7051c6cf85c360cd116118a587726 // 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 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 (__atomic_load_n(&running, __ATOMIC_RELAXED)) usleep((call == num_calls - 1) ? 10000 : 1000); break; } } } } #ifndef __NR_userfaultfd #define __NR_userfaultfd 323 #endif uint64_t r[3] = {0xffffffffffffffff, 0x0, 0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: res = syscall(__NR_pipe2, 0x20000140, 0); if (res != -1) r[0] = *(uint32_t*)0x20000144; break; case 1: memcpy((void*)0x20000080, "bbr", 4); syscall(__NR_setsockopt, r[0], 6, 0xd, 0x20000080, 4); break; case 2: res = syscall(__NR_getpgrp, -1); if (res != -1) r[1] = res; break; case 3: syscall(__NR_ptrace, 1, r[1], 0x20000200); break; case 4: syscall(__NR_userfaultfd, 0); break; case 5: memcpy((void*)0x20000100, "./file0", 8); res = syscall(__NR_creat, 0x20000100, 0); if (res != -1) r[2] = res; break; case 6: memcpy((void*)0x20000600, "\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*)0x20000620 = 0x20; *(uint32_t*)0x20000624 = 1; *(uint32_t*)0x20000628 = 0x218; *(uint64_t*)0x20000630 = 0; *(uint64_t*)0x20000638 = 0; *(uint64_t*)0x20000640 = 0; *(uint64_t*)0x20000648 = 0; *(uint64_t*)0x20000650 = 0; *(uint64_t*)0x20000658 = 0x20000240; *(uint32_t*)0x20000660 = 0; *(uint64_t*)0x20000668 = 0x20000080; *(uint64_t*)0x20000670 = 0x20000240; *(uint32_t*)0x20000240 = 0; memcpy((void*)0x20000244, "\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\x00\x00\x00", 32); *(uint32_t*)0x20000264 = 0; *(uint32_t*)0x20000268 = -1; *(uint32_t*)0x2000026c = 0; *(uint32_t*)0x20000270 = 0; memcpy((void*)0x20000274, "\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\x00\x00\x00", 32); *(uint32_t*)0x20000294 = 0; *(uint32_t*)0x20000298 = -1; *(uint32_t*)0x2000029c = 0; *(uint32_t*)0x200002a0 = 0; memcpy((void*)0x200002a4, "\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\x00\x00\x00", 32); *(uint32_t*)0x200002c4 = 0; *(uint32_t*)0x200002c8 = -1; *(uint32_t*)0x200002cc = 1; *(uint32_t*)0x200002d0 = 0x11; *(uint32_t*)0x200002d4 = 0; *(uint16_t*)0x200002d8 = htobe16(0); memcpy((void*)0x200002da, "\x6e\x72\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); memcpy((void*)0x200002ea, "\x79\x61\x6d\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); memcpy((void*)0x200002fa, "\x79\x61\x6d\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); memcpy((void*)0x2000030a, "\x76\x65\x74\x68\x31\x5f\x74\x6f\x5f\x74\x65\x61\x6d\x00\x00\x00", 16); *(uint8_t*)0x2000031a = 1; *(uint8_t*)0x2000031b = 0x80; *(uint8_t*)0x2000031c = 0xc2; *(uint8_t*)0x2000031d = 0; *(uint8_t*)0x2000031e = 0; *(uint8_t*)0x2000031f = 0; *(uint8_t*)0x20000320 = 0; *(uint8_t*)0x20000321 = 0; *(uint8_t*)0x20000322 = 0; *(uint8_t*)0x20000323 = 0; *(uint8_t*)0x20000324 = 0; *(uint8_t*)0x20000325 = 0; *(uint8_t*)0x20000326 = 0xaa; *(uint8_t*)0x20000327 = 0xaa; *(uint8_t*)0x20000328 = 0xaa; *(uint8_t*)0x20000329 = 0xaa; *(uint8_t*)0x2000032a = 0xaa; *(uint8_t*)0x2000032b = 0; *(uint8_t*)0x2000032c = 0; *(uint8_t*)0x2000032d = 0; *(uint8_t*)0x2000032e = 0; *(uint8_t*)0x2000032f = 0; *(uint8_t*)0x20000330 = 0; *(uint8_t*)0x20000331 = 0; *(uint32_t*)0x20000334 = 0xb0; *(uint32_t*)0x20000338 = 0x158; *(uint32_t*)0x2000033c = 0x188; memcpy((void*)0x20000340, "\x64\x65\x76\x67\x72\x6f\x75\x70\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*)0x20000360 = 0x18; *(uint32_t*)0x20000368 = 0; *(uint32_t*)0x2000036c = 0; *(uint32_t*)0x20000370 = 0; *(uint32_t*)0x20000374 = 0; *(uint32_t*)0x20000378 = 0; memcpy((void*)0x20000380, "\x72\x65\x64\x69\x72\x65\x63\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", 32); *(uint32_t*)0x200003a0 = 8; *(uint32_t*)0x200003a8 = 0xfffffffc; memcpy((void*)0x200003b0, "\x6e\x66\x6c\x6f\x67\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*)0x200003d0 = 0x50; *(uint32_t*)0x200003d8 = 0; *(uint16_t*)0x200003dc = 0; *(uint16_t*)0x200003de = 0; *(uint16_t*)0x200003e0 = 0; *(uint16_t*)0x200003e2 = 0; memcpy((void*)0x200003e4, "\xec\x8c\xc3\x59\x09\x61\x55\xb1\x33\x58\x06\x76\x5b\xdf\x9d\x8d" "\xc3\x02\x47\x24\xca\x1b\x94\x27\xf5\xab\xa6\xe4\x0e\x93\xc3\xa7" "\xb3\x9e\x15\x1d\x82\x92\x25\x86\x03\x8d\xd3\x4e\x1e\xf7\xb1\x41" "\x0a\xc3\xd9\xce\x09\xd5\xe7\xd0\x23\x36\xf7\x7e\x3d\x76\xc9\x19", 64); memcpy((void*)0x20000428, "\x41\x55\x44\x49\x54\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*)0x20000448 = 8; *(uint8_t*)0x20000450 = 4; syscall(__NR_setsockopt, -1, 0, 0x80, 0x20000600, 0x290); break; case 7: memcpy((void*)0x20000000, "./file0", 8); memcpy((void*)0x20000040, "9p", 3); memcpy((void*)0x200001c0, "trans=fd,", 9); memcpy((void*)0x200001c9, "rfdno", 5); *(uint8_t*)0x200001ce = 0x3d; sprintf((char*)0x200001cf, "0x%016llx", (long long)r[0]); *(uint8_t*)0x200001e1 = 0x2c; memcpy((void*)0x200001e2, "wfdno", 5); *(uint8_t*)0x200001e7 = 0x3d; sprintf((char*)0x200001e8, "0x%016llx", (long long)r[2]); *(uint8_t*)0x200001fa = 0x2c; *(uint8_t*)0x200001fb = 0; syscall(__NR_mount, 0, 0x20000000, 0x20000040, 0, 0x200001c0); break; } } void execute_one() { execute(8); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (;;) { loop(); } }