// https://syzkaller.appspot.com/bug?id=8e030beda49b8e549cfeb17ed369414ed27331e6 // 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } 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 long syz_open_procfs(volatile long a0, volatile long a1) { char buf[128]; memset(buf, 0, sizeof(buf)); if (a0 == 0) { snprintf(buf, sizeof(buf), "/proc/self/%s", (char*)a1); } else if (a0 == -1) { snprintf(buf, sizeof(buf), "/proc/thread-self/%s", (char*)a1); } else { snprintf(buf, sizeof(buf), "/proc/self/task/%d/%s", (int)a0, (char*)a1); } int fd = open(buf, O_RDWR); if (fd == -1) fd = open(buf, O_RDONLY); return fd; } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); for (int i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); write_file("/proc/self/oom_score_adj", "1000"); } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter = 0; for (;; iter++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { setup_test(); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { sleep_ms(10); if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } } } uint64_t r[1] = {0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // mmap arguments: [ // addr: VMA[0xe7e000] // len: len = 0xe7e000 (8 bytes) // prot: mmap_prot = 0xfffffffffcffffff (8 bytes) // flags: mmap_flags = 0x20031 (8 bytes) // fd: fd (resource) // offset: intptr = 0xbe9f5000 (8 bytes) // ] syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0xe7e000ul, /*prot=PROT_SEM|PROT_WRITE|PROT_READ|PROT_EXEC|0xfffffffffcfffff0*/ 0xfffffffffcfffffful, /*flags=MAP_STACK|MAP_FIXED|MAP_ANONYMOUS|MAP_SHARED*/ 0x20031ul, /*fd=*/(intptr_t)-1, /*offset=*/0xbe9f5000ul); // mmap arguments: [ // addr: VMA[0x200000] // len: len = 0x200000 (8 bytes) // prot: mmap_prot = 0x300000b (8 bytes) // flags: mmap_flags = 0x204031 (8 bytes) // fd: fd (resource) // offset: intptr = 0xec776000 (8 bytes) // ] syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x200000ul, /*prot=PROT_GROWSUP|PROT_GROWSDOWN|PROT_SEM|PROT_WRITE|PROT_READ*/ 0x300000bul, /*flags=MAP_NORESERVE|MAP_FIXED|MAP_ANONYMOUS|MAP_SHARED|0x200000*/ 0x204031ul, /*fd=*/(intptr_t)-1, /*offset=*/0xec776000ul); // sendmmsg$inet arguments: [ // fd: sock (resource) // mmsg: ptr[in, array[mmsghdr_inet]] { // array[mmsghdr_inet] { // mmsghdr_inet { // msg_hdr: msghdr_inet { // msg_name: nil // msg_namelen: len = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // msg_iov: ptr[in, array[iovec[in, array[int8]]]] { // array[iovec[in, array[int8]]] { // iovec[in, array[int8]] { // addr: ptr[in, buffer] { // buffer: {ec 49 69 ce 12 ae e5 cb cb 87 44 8d 7b 8d 39 e5 // 91 f0 81 7d 13 f2 30 e3 60 36 31 a8 55 80 2b 48 3c} // (length 0x21) // } // len: len = 0x21 (8 bytes) // } // } // } // msg_iovlen: len = 0x1 (8 bytes) // msg_control: nil // msg_controllen: bytesize = 0x0 (8 bytes) // msg_flags: const = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // } // msg_len: const = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // } // } // } // vlen: len = 0x1 (8 bytes) // f: send_flags = 0x20000800 (8 bytes) // ] *(uint64_t*)0x200000000300 = 0; *(uint32_t*)0x200000000308 = 0; *(uint64_t*)0x200000000310 = 0x200000000280; *(uint64_t*)0x200000000280 = 0x2000000001c0; memcpy((void*)0x2000000001c0, "\xec\x49\x69\xce\x12\xae\xe5\xcb\xcb\x87\x44\x8d\x7b\x8d\x39\xe5\x91" "\xf0\x81\x7d\x13\xf2\x30\xe3\x60\x36\x31\xa8\x55\x80\x2b\x48\x3c", 33); *(uint64_t*)0x200000000288 = 0x21; *(uint64_t*)0x200000000318 = 1; *(uint64_t*)0x200000000320 = 0; *(uint64_t*)0x200000000328 = 0; *(uint32_t*)0x200000000330 = 0; *(uint32_t*)0x200000000338 = 0; syscall(__NR_sendmmsg, /*fd=*/(intptr_t)-1, /*mmsg=*/0x200000000300ul, /*vlen=*/1ul, /*f=MSG_FASTOPEN|MSG_CONFIRM*/ 0x20000800ul); // syz_open_procfs arguments: [ // pid: pid (resource) // file: ptr[in, buffer] { // buffer: {6d 61 70 73 00} (length 0x5) // } // ] // returns fd memcpy((void*)0x2000000001c0, "maps\000", 5); res = -1; res = syz_open_procfs(/*pid=*/0, /*file=*/0x2000000001c0); if (res != -1) r[0] = res; // ioctl$KVM_SET_USER_MEMORY_REGION arguments: [ // fd: fd_kvmvm (resource) // cmd: const = 0xc0686611 (4 bytes) // arg: ptr[in, kvm_userspace_memory_region] { // kvm_userspace_memory_region { // slot: kvm_mem_slots = 0x68 (4 bytes) // flags: kvm_mem_region_flags = 0x0 (4 bytes) // paddr: kvm_guest_addrs = 0x17 (8 bytes) // size: len = 0x2000 (8 bytes) // addr: VMA[0x2000] // } // } // ] *(uint32_t*)0x200000000180 = 0x68; *(uint32_t*)0x200000000184 = 0; *(uint64_t*)0x200000000188 = 0x17; *(uint64_t*)0x200000000190 = 0x2000; *(uint64_t*)0x200000000198 = 0x200000ffd000; syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc0686611, /*arg=*/0x200000000180ul); } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; loop(); return 0; }