// https://syzkaller.appspot.com/bug?id=20461e24e6d47cb591e04bed283907f38ee50633 // 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 #include __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #include #include #include #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 void exitf(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(kRetryStatus); } 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 loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 160 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 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); if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } } int wait_for_loop(int pid) { if (pid < 0) fail("sandbox fork failed"); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); sandbox_common(); if (unshare(CLONE_NEWNET)) { } loop(); doexit(1); } static int inject_fault(int nth) { int fd; char buf[16]; fd = open("/proc/thread-self/fail-nth", O_RDWR); if (fd == -1) exitf("failed to open /proc/thread-self/fail-nth"); sprintf(buf, "%d", nth + 1); if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) exitf("failed to write /proc/thread-self/fail-nth"); return fd; } uint64_t r[1] = {0xffffffffffffffff}; void loop() { long res = 0; memcpy((void*)0x20000000, "./file0", 8); syscall(__NR_mkdir, 0x20000000, 0); memcpy((void*)0x2000a000, "./file0", 8); memcpy((void*)0x20026ff8, "./file0", 8); memcpy((void*)0x20000300, "ramfs", 6); syscall(__NR_mount, 0x2000a000, 0x20026ff8, 0x20000300, 0, 0x200007c0); memcpy((void*)0x20d04000, "./file0", 8); memcpy((void*)0x20903000, "./file0", 8); memcpy((void*)0x20000340, "bdev", 5); syscall(__NR_mount, 0x20d04000, 0x20903000, 0x20000340, 0x100000, 0x200002c0); res = syscall(__NR_socket, 0xa, 0x1000000000002, 0); if (res != -1) r[0] = res; syscall(__NR_ioctl, r[0], 0x8912, 0x20000280); memcpy((void*)0x20000000, "./file0", 8); memcpy((void*)0x200000c0, ".", 1); memcpy((void*)0x20000140, "vxfs", 5); syscall(__NR_mount, 0x20000000, 0x200000c0, 0x20000140, 0x3080, 0x20000200); memcpy((void*)0x200008c0, ".", 1); memcpy((void*)0x20000080, ".", 1); memcpy((void*)0x20753000, "mslos", 6); syscall(__NR_mount, 0x200008c0, 0x20000080, 0x20753000, 0x5010, 0x20000ac0); memcpy((void*)0x20377ff8, ".", 1); memcpy((void*)0x20187ff8, ".", 1); memcpy((void*)0x20753000, "mslos", 6); syscall(__NR_mount, 0x20377ff8, 0x20187ff8, 0x20753000, 0x5010, 0x200e7000); memcpy((void*)0x20000000, "./file0", 8); memcpy((void*)0x200000c0, "./file0", 8); memcpy((void*)0x20000280, "\x73\x79\x73\x66\x73\x00\x2a\x86\x4f\x4b\xc0\x0b\xce\x1b\xdb\x20\x63" "\x72\x13\xb1\xe8\x94\xd1\x20\x71\x5f\x9d\xc1\x12\x5b\x04\x2c\x72\x26" "\xeb\x01\x36\xd9\x62\x4e\xa1\xd2\x33\x74\xa6\x60\xfe\x5a\xc1\x73\x72" "\x2f\xd3\x67\xad\x22\xe8\x55\x30\x25\xa2\xe8\xbe\x0b\xc5\x51\x43\x79" "\xaf\x72\x13\xd3\x2b\x8d\x5d\x06\xdc\x8f\xbf\x2c\x84\x9e\xd9\xcd\xef" "\xc7\x4b\x03\xdf\xa9\xcb\x5a\x90\xb2\x8b\x4b\x24\xd7\x86\x2c\x3d\x66" "\xfc\xa5\x31\x67\xd5\x42\x42\x35\x43\x5a\x3d\xbb\x76\xbc\x7d\x3c\x42" "\xfc\x2e\x9c\x69\x61\x14\xa6\xf8\x88\xf0\xda\x85\x27\x76\x83\xcf\xc1" "\xc4\xd2\xbf\x71\xc2\x55\xa3\x13\x4d\x64\xcc\x3f\xed\x8e\x97\x79\x8d" "\xeb\x86\x31\xcb\xf7\x68\x2c\x9f\xa2\xed\x03\x14\x65\xaa\x19\x1d\xf9" "\x22\xf7\x64\x29\x7c\xba\x22\xa8\x49\x9d\x17\x7f\x49\xfb\xa9\x40\xf5" "\x5b\xbc\x8b\x72\x3f\xd3\x74\xf1\xfe\xd7\x8c\x8a\xee\xc6\x81\x1d\x9b" "\x58\x79\x48\x73\x87\xd5\x65\x94\xa1\x4c\x25\x88\x27\x4d\xe8\x4f\xa2" "\x76\x10\x30\x2b\x3f\xb5\x41\x72\xa8\xc9\x10\xa0\x7e\x7c\x76\xea\x46" "\x5a\xa6\x84\x02", 242); write_file("/sys/kernel/debug/failslab/ignore-gfp-wait", "N"); write_file("/sys/kernel/debug/fail_futex/ignore-private", "N"); inject_fault(9); syscall(__NR_mount, 0x20000000, 0x200000c0, 0x20000280, 0, 0x20000180); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); do_sandbox_none(); return 0; }