// https://syzkaller.appspot.com/bug?id=31e9db1e7d8d3891aeb5fa09ab596ca27654cc52 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } #define __syscall syscall static void sandbox_common() { if (setsid() == -1) exit(1); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; memcpy((void*)0x20000000, "/dev/rvnd0c\000", 12); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000000ul, 0ul, 0ul); if (res != -1) r[0] = res; syscall(SYS_ioctl, r[0], 0x20006473ul, 0ul); memcpy((void*)0x20000000, "/dev/rvnd0c\000", 12); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000000ul, 0ul, 0ul); if (res != -1) r[1] = res; syscall(SYS_ioctl, -1, 0xc4104603ul, 0ul); memcpy((void*)0x20000040, "./file0\000", 8); res = syscall(SYS_open, 0x20000040ul, 0x70eul, 0ul); if (res != -1) r[2] = res; *(uint64_t*)0x20000000 = 0x200004c0; memcpy((void*)0x200004c0, "\x0e\xc4\x65\xcd\xab\x1a\xb6\x92\x5c\xb8\x12\x35\xdb\xb1\x73\x99\xc0" "\x70\xdd\xe2\x03\xe5\x02\x10\x6f\x69\x0d\x99\x47\x36\x4f\xe3\x56\x95" "\x60\xe7\x3b\xfa\x90\x12\x26\x3c\x0e\xf6\xeb\x62\x6a\xd7\x9d\x51\xe7" "\xb4\x60\x78\x79\x07\x2c\xa3\x38\x09\xa8\x54\x43\xbe\xf8\xe0\x11\xb3" "\xe2\xe6\x3d\xe6\xf9\x63\x7c\xa6\xe4\x22\x10\x6a\x6a\x17\x62\xb6\x7f" "\x56\x08\x14\xee\xf6\xdc\xb3\xf3\x9a\x2e\x51\x60\x02\x51\xfb\xad\x1e" "\xe8\x20\x88\xa7\x5c\xa3\x76\x47\x29\xaf\x3f\x3d\x4d\x96\x7c\xe8\xaa" "\xdb\x3c\x3f\xd7\xf9\xae\x4f\x4c\x83\xb2", 129); *(uint64_t*)0x20000008 = 0xfffffe1a; syscall(SYS_writev, r[2], 0x20000000ul, 1ul); *(uint64_t*)0x20000680 = 0x20000600; memcpy((void*)0x20000600, "./file0\000", 8); *(uint64_t*)0x20000688 = 0x10001; *(uint64_t*)0x20000690 = 0x20000280; memcpy((void*)0x20000280, "./file0/../file0\000", 17); *(uint32_t*)0x20000698 = 0x11; syscall(SYS_ioctl, r[1], 0xc0384600ul, 0x20000680ul); syscall(SYS_ioctl, r[2], 0xc0384600ul, 0ul); } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul); do_sandbox_none(); return 0; }