// https://syzkaller.appspot.com/bug?id=851fe012db565ade456cf85782c651b7d1624bd9 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #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 int inject_fault(int nth) { int fd; fd = open("/proc/thread-self/fail-nth", O_RDWR); if (fd == -1) exit(1); char buf[16]; sprintf(buf, "%d", nth + 1); if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) exit(1); return fd; } static void setup_fault() { static struct { const char* file; const char* val; bool fatal; } files[] = { {"/sys/kernel/debug/failslab/ignore-gfp-wait", "N", true}, {"/sys/kernel/debug/fail_futex/ignore-private", "N", false}, {"/sys/kernel/debug/fail_page_alloc/ignore-gfp-highmem", "N", false}, {"/sys/kernel/debug/fail_page_alloc/ignore-gfp-wait", "N", false}, {"/sys/kernel/debug/fail_page_alloc/min-order", "0", false}, }; unsigned i; for (i = 0; i < sizeof(files) / sizeof(files[0]); i++) { if (!write_file(files[i].file, files[i].val)) { if (files[i].fatal) exit(1); } } } uint64_t r[7] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; int main(void) { syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x32ul, -1, 0); setup_fault(); intptr_t res = 0; syscall(__NR_socket, 0xaul, 1ul, 0ul); syscall(__NR_perf_event_open, 0ul, 0, 0ul, -1, 0ul); syscall(__NR_getsockopt, -1, 1ul, 0x11ul, 0ul, 0ul); syscall(__NR_setuid, 0); syscall(__NR_mkdir, 0ul, 0ul); syscall(__NR_openat, 0xffffff9c, 0ul, 0x275aul, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x3000ul, 0ul, 0x10ul, -1, 0); syscall(__NR_socket, 1ul, 1ul, 0ul); syscall(__NR_socket, 0xaul, 3ul, 7); res = syscall(__NR_socket, 0x10ul, 3ul, 0ul); if (res != -1) r[0] = res; res = syscall(__NR_socketpair, 1ul, 1ul, 0ul, 0x20000000ul); if (res != -1) r[1] = *(uint32_t*)0x20000004; res = syscall(__NR_dup, r[1]); if (res != -1) r[2] = res; *(uint32_t*)0x20000040 = 0x12; res = syscall(__NR_getpeername, r[2], 0x20000000ul, 0x20000040ul); if (res != -1) r[3] = *(uint32_t*)0x20000004; res = syscall(__NR_socketpair, 1ul, 1ul, 0ul, 0x20000000ul); if (res != -1) r[4] = *(uint32_t*)0x20000004; res = syscall(__NR_dup, r[4]); if (res != -1) r[5] = res; *(uint32_t*)0x20000040 = 0x12; res = syscall(__NR_getpeername, r[5], 0x20000000ul, 0x20000040ul); if (res != -1) r[6] = *(uint32_t*)0x20000004; *(uint64_t*)0x20000180 = 0; *(uint32_t*)0x20000188 = 0xe002; *(uint64_t*)0x20000190 = 0x20000000; *(uint64_t*)0x20000000 = 0x20000040; memcpy((void*)0x20000040, "\x40\x00\x00\x00\x10\x00\x01\x06\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00", 20); *(uint32_t*)0x20000054 = 0; memcpy((void*)0x20000058, "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x12\x00" "\x08\x00\x01\x00\x68\x73\x72\x00\x14\x00\x02\x00" "\x08\x00\x02\x00", 28); *(uint32_t*)0x20000074 = r[3]; memcpy((void*)0x20000078, "\x08\x00\x01\x00", 4); *(uint32_t*)0x2000007c = r[6]; *(uint64_t*)0x20000008 = 0x40; *(uint64_t*)0x20000198 = 1; *(uint64_t*)0x200001a0 = 0; *(uint64_t*)0x200001a8 = 0; *(uint32_t*)0x200001b0 = 0; inject_fault(10); syscall(__NR_sendmsg, r[0], 0x20000180ul, 0ul); return 0; }