// https://syzkaller.appspot.com/bug?id=632e462853f2cf2644dea8c3f5ce98185f33da66 // 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 #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 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 loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &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); unshare(CLONE_NEWNS); unshare(CLONE_NEWIPC); unshare(CLONE_IO); } static int do_sandbox_none(int executor_pid, bool enable_tun) { int pid = fork(); if (pid) return pid; sandbox_common(); loop(); doexit(1); } static void test(); 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(); test(); 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) { kill(-pid, SIGKILL); kill(pid, SIGKILL); while (waitpid(-1, &status, __WALL) != pid) { } break; } } } } long r[30]; void* thr(void* arg) { switch ((long)arg) { case 0: r[0] = syscall(__NR_mmap, 0x20000000ul, 0x218000ul, 0x3ul, 0x32ul, 0xfffffffffffffffful, 0x0ul); break; case 1: r[1] = syscall(__NR_socket, 0x26ul, 0x5ul, 0x0ul); break; case 2: *(uint16_t*)0x20000000 = (uint16_t)0x26; memcpy((void*)0x20000002, "\x73\x6b\x63\x69\x70\x68\x65\x72\x00\x00\x00\x00\x00\x00", 14); *(uint32_t*)0x20000010 = (uint32_t)0x0; *(uint32_t*)0x20000014 = (uint32_t)0x0; memcpy((void*)0x20000018, "\x63\x68\x61\x63\x68\x61\x32\x30\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\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00", 64); r[7] = syscall(__NR_bind, r[1], 0x20000000ul, 0x58ul); break; case 3: r[8] = syscall(__NR_accept, r[1], 0x0ul, 0x0ul); break; case 4: memcpy((void*)0x2007ff6f, "\x9f\xa0\x29\x1e\x41\x79\x7c\x3d\x71\x85" "\x4a\x9f\xe2\xcd\x85\x86\x74\xc8\x29\x88" "\x34\x8b\x5c\xa3\xa6\x10\x3d\x5c\xa1\xcb" "\x9e\xef", 32); r[10] = syscall(__NR_setsockopt, r[1], 0x117ul, 0x1ul, 0x2007ff6ful, 0x20ul); break; case 5: r[11] = syscall(__NR_close, 0xfffffffffffffffful); break; case 6: *(uint64_t*)0x2008dfc8 = (uint64_t)0x200eafe4; *(uint32_t*)0x2008dfd0 = (uint32_t)0x1c; *(uint64_t*)0x2008dfd8 = (uint64_t)0x20216000; *(uint64_t*)0x2008dfe0 = (uint64_t)0x5; *(uint64_t*)0x2008dfe8 = (uint64_t)0x20216000; *(uint64_t*)0x2008dff0 = (uint64_t)0x0; *(uint32_t*)0x2008dff8 = (uint32_t)0x3; *(uint64_t*)0x20216000 = (uint64_t)0x20216000; *(uint64_t*)0x20216008 = (uint64_t)0x0; *(uint64_t*)0x20216010 = (uint64_t)0x20216000; *(uint64_t*)0x20216018 = (uint64_t)0x0; *(uint64_t*)0x20216020 = (uint64_t)0x20123f7b; *(uint64_t*)0x20216028 = (uint64_t)0x0; *(uint64_t*)0x20216030 = (uint64_t)0x20176000; *(uint64_t*)0x20216038 = (uint64_t)0x0; *(uint64_t*)0x20216040 = (uint64_t)0x20216f27; *(uint64_t*)0x20216048 = (uint64_t)0xd9; r[29] = syscall(__NR_recvmsg, r[8], 0x2008dfc8ul, 0x40010101ul); break; } return 0; } void test() { long i; pthread_t th[14]; memset(r, -1, sizeof(r)); srand(getpid()); for (i = 0; i < 7; i++) { pthread_create(&th[i], 0, thr, (void*)i); usleep(rand() % 10000); } for (i = 0; i < 7; i++) { pthread_create(&th[7 + i], 0, thr, (void*)i); if (rand() % 2) usleep(rand() % 10000); } usleep(rand() % 100000); } int main() { int i; for (i = 0; i < 8; i++) { if (fork() == 0) { int pid = do_sandbox_none(i, false); int status = 0; while (waitpid(pid, &status, __WALL) != pid) { } return 0; } } sleep(1000000); return 0; }