// https://syzkaller.appspot.com/bug?id=a56ef51971de0eed577b691850688344f0f2a0d3 // autogenerated by syzkaller (http://github.com/google/syzkaller) #ifndef __NR_bpf #define __NR_bpf 321 #endif #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include const int kFailStatus = 67; const int kRetryStatus = 69; __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } __attribute__((noreturn)) static 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); } static __thread int skip_segv; static __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)) { _longjmp(segv_env, 1); } doexit(sig); for (;;) { } } static void install_segv_handler() { 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); 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); \ } static void use_temporary_dir() { 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 = 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() { while (1) { test(); } } long r[15]; void test() { memset(r, -1, sizeof(r)); r[0] = syscall(__NR_mmap, 0x20000000ul, 0x81b000ul, 0x3ul, 0x32ul, 0xfffffffffffffffful, 0x0ul); NONFAILING(*(uint32_t*)0x20001fec = (uint32_t)0x1); NONFAILING(*(uint32_t*)0x20001ff0 = (uint32_t)0x87); NONFAILING(*(uint32_t*)0x20001ff4 = (uint32_t)0x3); NONFAILING(*(uint32_t*)0x20001ff8 = (uint32_t)0x1); NONFAILING(*(uint32_t*)0x20001ffc = (uint32_t)0x5); NONFAILING(*(uint32_t*)0x20002000 = (uint32_t)0x0); NONFAILING(*(uint32_t*)0x20002004 = (uint32_t)0xffffffffffff8b7b); r[8] = syscall(__NR_bpf, 0x0ul, 0x20001fecul, 0x1cul); NONFAILING(*(uint32_t*)0x20006000 = r[8]); NONFAILING(*(uint64_t*)0x20006008 = (uint64_t)0x2000d000); NONFAILING(*(uint64_t*)0x20006010 = (uint64_t)0x20009000); NONFAILING(*(uint64_t*)0x20006018 = (uint64_t)0x0); NONFAILING(memcpy( (void*)0x20009000, "\x63\xd9\xdf\x0d\xcd\xf2\x96\x99\xdb\xb8\x18\x24\x55\xb1\x0e\x52" "\x24\x1b\x6f\x5a\x50\x26\xce\xac\x47\xd3\x56\x10\x8b\x9b\x54\x65" "\xca\x62\xa4\xe5\x67\xd9\xa5\x86\xf3\x09\xf0\x0d\x64\x91\xba\x35" "\xc5\x6f\x0d\x5d\xb4\xb7\xec\x3f\x9a\xf9\xef\xb7\xda\xad\x91\xda" "\x19\x19\xc2\x1a\xc8\x40\x4e\xbc\xb1\x49\x61\x99\x45\x69\xb7\x57" "\xf4\xd8\x55\x31\x66\x8b\xf7\x9b\x4c\xea\x3f\x69\xc7\xf9\x39", 95)); r[14] = syscall(__NR_bpf, 0x2ul, 0x20006000ul, 0x20ul); } int main() { int i; for (i = 0; i < 8; i++) { if (fork() == 0) { install_segv_handler(); use_temporary_dir(); int pid = do_sandbox_none(i, false); int status = 0; while (waitpid(pid, &status, __WALL) != pid) { } return 0; } } sleep(1000000); return 0; }