// autogenerated by syzkaller (http://github.com/google/syzkaller) #ifndef __NR_mmap #define __NR_mmap 9 #endif #ifndef __NR_rt_sigprocmask #define __NR_rt_sigprocmask 14 #endif #ifndef __NR_timer_create #define __NR_timer_create 222 #endif #ifndef __NR_getsockopt #define __NR_getsockopt 55 #endif #ifndef __NR_getpid #define __NR_getpid 39 #endif #ifndef __NR_gettid #define __NR_gettid 186 #endif #ifndef __NR_timer_settime #define __NR_timer_settime 223 #endif #ifndef __NR_rt_tgsigqueueinfo #define __NR_rt_tgsigqueueinfo 297 #endif #ifndef __NR_rt_sigtimedwait #define __NR_rt_sigtimedwait 128 #endif #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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include const int kFailStatus = 67; const int kErrorStatus = 68; const int kRetryStatus = 69; __attribute__((noreturn)) void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } __attribute__((noreturn)) void fail(const char* msg, ...) { int e = errno; fflush(stdout); 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); } __attribute__((noreturn)) void exitf(const char* msg, ...) { int e = errno; fflush(stdout); va_list args; va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); fprintf(stderr, " (errno %d)\n", e); doexit(kRetryStatus); } static int flag_debug; void debug(const char* msg, ...) { if (!flag_debug) return; va_list args; va_start(args, msg); vfprintf(stdout, msg, args); va_end(args); fflush(stdout); } __thread int skip_segv; __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* uctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { debug("SIGSEGV on %p, skipping\n", addr); _longjmp(segv_env, 1); } debug("SIGSEGV on %p, exiting\n", addr); doexit(sig); for (;;) { } } static void install_segv_handler() { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } #define BITMASK_LEN(type, bf_len) (type)((1ull << (bf_len)) - 1) #define BITMASK_LEN_OFF(type, bf_off, bf_len) \ (type)(BITMASK_LEN(type, (bf_len)) << (bf_off)) #define STORE_BY_BITMASK(type, addr, val, bf_off, bf_len) \ if ((bf_off) == 0 && (bf_len) == 0) { \ *(type*)(addr) = (type)(val); \ } else { \ type new_val = *(type*)(addr); \ new_val &= ~BITMASK_LEN_OFF(type, (bf_off), (bf_len)); \ new_val |= ((type)(val)&BITMASK_LEN(type, (bf_len))) << (bf_off); \ *(type*)(addr) = new_val; \ } struct csum_inet { uint32_t acc; }; void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i; for (i = 0; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += (uint16_t)data[length - 1]; while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } static uintptr_t execute_syscall(int nr, uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7, uintptr_t a8) { switch (nr) { default: return syscall(nr, a0, a1, a2, a3, a4, a5); } } static void setup_main_process() { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); install_segv_handler(); char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) fail("failed to mkdtemp"); if (chmod(tmpdir, 0777)) fail("failed to chmod"); if (chdir(tmpdir)) fail("failed to chdir"); } 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 = 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_setuid(int executor_pid, bool enable_tun) { int pid = fork(); if (pid) return pid; sandbox_common(); const int nobody = 65534; if (setgroups(0, NULL)) fail("failed to setgroups"); if (syscall(SYS_setresgid, nobody, nobody, nobody)) fail("failed to setresgid"); if (syscall(SYS_setresuid, nobody, nobody, nobody)) fail("failed to setresuid"); prctl(PR_SET_DUMPABLE, 1, 0, 0, 0); loop(); doexit(1); } long r[39]; void loop() { memset(r, -1, sizeof(r)); r[0] = execute_syscall(__NR_mmap, 0x20000000ul, 0x1c000ul, 0x3ul, 0x32ul, 0xfffffffffffffffful, 0x0ul, 0, 0, 0); NONFAILING(*(uint64_t*)0x20003000 = (uint64_t)0xfffffffffffff051); r[2] = execute_syscall(__NR_rt_sigprocmask, 0x2ul, 0x20003000ul, 0x20011ff8ul, 0x8ul, 0, 0, 0, 0, 0); r[3] = execute_syscall(__NR_getpid, 0, 0, 0, 0, 0, 0, 0, 0, 0); r[4] = execute_syscall(__NR_gettid, 0, 0, 0, 0, 0, 0, 0, 0, 0); NONFAILING(*(uint64_t*)0x2001afb0 = (uint64_t)0x0); NONFAILING(*(uint32_t*)0x2001afb8 = (uint32_t)0x8); NONFAILING(*(uint32_t*)0x2001afbc = (uint32_t)0x2); NONFAILING(*(uint64_t*)0x2001afc0 = (uint64_t)0x7f); NONFAILING(*(uint64_t*)0x2001afc8 = (uint64_t)0xbd); NONFAILING(*(uint64_t*)0x2001afd0 = (uint64_t)0x86); NONFAILING(*(uint64_t*)0x2001afd8 = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x2001afe0 = (uint64_t)0x100); NONFAILING(*(uint64_t*)0x2001afe8 = (uint64_t)0x4); NONFAILING(*(uint64_t*)0x2001aff0 = (uint64_t)0xffff); NONFAILING(*(uint64_t*)0x2001aff8 = (uint64_t)0x7); r[16] = execute_syscall(__NR_timer_create, 0x3ul, 0x2001afb0ul, 0x2000b000ul, 0, 0, 0, 0, 0, 0); if (r[16] != -1) NONFAILING(r[17] = *(uint32_t*)0x2000b000); NONFAILING(*(uint32_t*)0x2000b000 = (uint32_t)0x0); NONFAILING(*(uint16_t*)0x2000b004 = (uint16_t)0x3f7d); NONFAILING(*(uint16_t*)0x2000b006 = (uint16_t)0x21); NONFAILING(*(uint64_t*)0x2000b008 = (uint64_t)0x1); NONFAILING(*(uint64_t*)0x2000b010 = (uint64_t)0x2); NONFAILING(*(uint32_t*)0x2001b000 = (uint32_t)0x18); r[24] = execute_syscall(__NR_getsockopt, 0xfffffffffffffffful, 0x84ul, 0x73ul, 0x2000b000ul, 0x2001b000ul, 0, 0, 0, 0); NONFAILING(*(uint64_t*)0x20011fe0 = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x20011fe8 = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x20011ff0 = (uint64_t)0x77359400); NONFAILING(*(uint64_t*)0x20011ff8 = (uint64_t)0x0); r[29] = execute_syscall(__NR_timer_settime, r[17], 0x1ul, 0x20011fe0ul, 0x2001afe0ul, 0, 0, 0, 0, 0); NONFAILING(*(uint32_t*)0x2000aff0 = (uint32_t)0x0); NONFAILING(*(uint32_t*)0x2000aff4 = (uint32_t)0x3); NONFAILING(*(uint32_t*)0x2000aff8 = (uint32_t)0x10001); NONFAILING(*(uint32_t*)0x2000affc = (uint32_t)0x3d9d); r[34] = execute_syscall(__NR_rt_tgsigqueueinfo, r[3], r[4], 0x32ul, 0x2000aff0ul, 0, 0, 0, 0, 0); NONFAILING(*(uint64_t*)0x20012000 = (uint64_t)0xfffffffffffffffc); NONFAILING(*(uint64_t*)0x20014ff0 = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x20014ff8 = (uint64_t)0x98967c); r[38] = execute_syscall(__NR_rt_sigtimedwait, 0x20012000ul, 0x20015ff0ul, 0x20014ff0ul, 0x8ul, 0, 0, 0, 0, 0); } int main() { setup_main_process(); int pid = do_sandbox_setuid(0, false); int status = 0; while (waitpid(pid, &status, __WALL) != pid) { } return 0; }