// 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 #include #include #include #include static bool write_file(const char * file, const char * what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } static void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {} } 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 = (200 << 20); setrlimit(RLIMIT_AS, & rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, & rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 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); if (unshare(CLONE_NEWNS)) {} if (unshare(CLONE_NEWIPC)) {} if (unshare(0x02000000)) {} if (unshare(CLONE_NEWUTS)) {} if (unshare(CLONE_SYSVSEM)) {} typedef struct { const char * name; const char * value; } sysctl_t; static const sysctl_t sysctls[] = { { "/proc/sys/kernel/shmmax", "16777216" }, { "/proc/sys/kernel/shmall", "536870912" }, { "/proc/sys/kernel/shmmni", "1024" }, { "/proc/sys/kernel/msgmax", "8192" }, { "/proc/sys/kernel/msgmni", "1024" }, { "/proc/sys/kernel/msgmnb", "1024" }, { "/proc/sys/kernel/sem", "1024 1048576 500 1024" }, }; unsigned i; return; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, & status, __WALL) != pid) {} printf("child done\n"); return WEXITSTATUS(status); } static int do_sandbox_none(void) { //if (unshare(CLONE_NEWPID)) {} int pid = fork(); if (pid != 0) return wait_for_loop(pid); //pause(); // child continues here setup_common(); sandbox_common(); // if (unshare(CLONE_NEWNET)) {} loop(); printf("child exiting \n"); exit(1); } void loop(void) { memcpy((void * ) 0x20000000, "/dev/vhost-vsock\000", 17); syscall(__NR_openat, 0xffffffffffffff9c, 0x20000000, 2, 0); syscall(__NR_dup2, -1, -1); } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); do_sandbox_none(); return 0; }