// https://syzkaller.appspot.com/bug?id=a58ef01f0578e659755cfac51368cc2373d4324f // 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 unsigned long long procid; 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_dev(volatile long a0, volatile long a1, volatile long a2) { if (a0 == 0xc || a0 == 0xb) { char buf[128]; sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1, (uint8_t)a2); return open(buf, O_RDWR, 0); } else { unsigned long nb = a1; char buf[1024]; char* hash; strncpy(buf, (char*)a0, sizeof(buf) - 1); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(nb % 10); nb /= 10; } return open(buf, a2 & ~O_CREAT, 0); } } 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[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // syz_open_procfs arguments: [ // pid: pid (resource) // file: nil // ] // returns fd syz_open_procfs(/*pid=*/0, /*file=*/0); // timer_create arguments: [ // id: clock_id = 0x0 (8 bytes) // ev: ptr[in, sigevent] { // sigevent { // val: const = 0x0 (8 bytes) // signo: int32 = 0x100021 (4 bytes) // notify: sigev_notify = 0x0 (4 bytes) // u: union sigevent_u { // thr: sigevent_thread { // func: nil // attr: ptr[in, buffer] { // buffer: {} (length 0x0) // } // } // } // pad = 0x0 (32 bytes) // } // } // timerid: ptr[out, timerid] { // timerid (resource) // } // ] *(uint64_t*)0x200000000080 = 0; *(uint32_t*)0x200000000088 = 0x100021; *(uint32_t*)0x20000000008c = 0; *(uint64_t*)0x200000000090 = 0; *(uint64_t*)0x200000000098 = 0x200000000340; syscall(__NR_timer_create, /*id=*/0ul, /*ev=*/0x200000000080ul, /*timerid=*/0x200000000300ul); // fcntl$lock arguments: [ // fd: fd (resource) // cmd: fcntl_lock = 0x6 (8 bytes) // lock: ptr[in, flock] { // flock { // type: flock_type = 0x0 (2 bytes) // whence: seek_whence = 0x0 (2 bytes) // pad = 0x0 (4 bytes) // start: intptr = 0x60d6 (8 bytes) // len: intptr = 0x5 (8 bytes) // pid: pid (resource) // pad = 0x0 (4 bytes) // } // } // ] *(uint16_t*)0x200000000040 = 0; *(uint16_t*)0x200000000042 = 0; *(uint64_t*)0x200000000048 = 0x60d6; *(uint64_t*)0x200000000050 = 5; *(uint32_t*)0x200000000058 = 0; syscall(__NR_fcntl, /*fd=*/(intptr_t)-1, /*cmd=F_SETLK*/ 6ul, /*lock=*/0x200000000040ul); // syz_open_dev$video4linux arguments: [ // dev: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 76 34 6c 2d 73 75 62 64 65 76 23 00} (length // 0x11) // } // id: intptr = 0x5 (8 bytes) // flags: open_flags = 0x40000 (8 bytes) // ] // returns fd_video memcpy((void*)0x200000000280, "/dev/v4l-subdev#\000", 17); res = -1; res = syz_open_dev(/*dev=*/0x200000000280, /*id=*/5, /*flags=O_NOATIME*/ 0x40000); if (res != -1) r[0] = res; // ioctl$VIDIOC_S_CTRL arguments: [ // fd: fd_video (resource) // cmd: const = 0xc008561c (4 bytes) // arg: nil // ] syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc008561c, /*arg=*/0ul); // openat$ptp0 arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 70 74 70 30 00} (length 0xa) // } // flags: open_flags = 0x400001 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_ptp memcpy((void*)0x200000000000, "/dev/ptp0\000", 10); syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000000ul, /*flags=__O_TMPFILE|O_WRONLY*/ 0x400001, /*mode=*/0); // timer_settime arguments: [ // timerid: timerid (resource) // flags: timer_flags = 0x1 (8 bytes) // new: ptr[in, itimerspec] { // itimerspec { // interv: timespec { // sec: time_sec (resource) // nsec: time_nsec (resource) // } // value: timespec { // sec: time_sec (resource) // nsec: time_nsec (resource) // } // } // } // old: nil // ] *(uint64_t*)0x200000000040 = 0; *(uint64_t*)0x200000000048 = 0; *(uint64_t*)0x200000000050 = 0; *(uint64_t*)0x200000000058 = 0x989680; syscall(__NR_timer_settime, /*timerid=*/0, /*flags=TIMER_ABSTIME*/ 1ul, /*new=*/0x200000000040ul, /*old=*/0ul); // mremap arguments: [ // addr: VMA[0x1000] // len: len = 0x1000 (8 bytes) // newlen: len = 0x400000 (8 bytes) // flags: mremap_flags = 0x3 (8 bytes) // newaddr: VMA[0x400000] // ] syscall(__NR_mremap, /*addr=*/0x200000a96000ul, /*len=*/0x1000ul, /*newlen=*/0x400000ul, /*flags=MREMAP_FIXED|MREMAP_MAYMOVE*/ 3ul, /*newaddr=*/0x200000000000ul); // openat$kvm arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 6b 76 6d 00} (length 0x9) // } // flags: open_flags = 0x2702 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_kvm memcpy((void*)0x200000000240, "/dev/kvm\000", 9); res = syscall( __NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000240ul, /*flags=O_TRUNC|O_NOCTTY|FASYNC|O_APPEND|O_RDWR*/ 0x2702, /*mode=*/0); if (res != -1) r[1] = res; // ioctl$KVM_CREATE_VM arguments: [ // fd: fd_kvm (resource) // cmd: const = 0xae01 (4 bytes) // type: intptr = 0x0 (8 bytes) // ] // returns fd_kvmvm res = syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0xae01, /*type=*/0ul); if (res != -1) r[2] = res; // ioctl$KVM_CREATE_IRQCHIP arguments: [ // fd: fd_kvmvm (resource) // cmd: const = 0xae60 (4 bytes) // ] syscall(__NR_ioctl, /*fd=*/r[2], /*cmd=*/0xae60, 0); // ioctl$KVM_CREATE_PIT2 arguments: [ // fd: fd_kvmvm (resource) // cmd: const = 0x4040ae77 (4 bytes) // arg: ptr[in, kvm_pit_config] { // kvm_pit_config { // flags: int32 = 0x6 (4 bytes) // pad: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} (length // 0x3c) // } // } // ] *(uint32_t*)0x200000000040 = 6; memset((void*)0x200000000044, 0, 60); syscall(__NR_ioctl, /*fd=*/r[2], /*cmd=*/0x4040ae77, /*arg=*/0x200000000040ul); // ioctl$KVM_CREATE_VCPU arguments: [ // fd: fd_kvmvm (resource) // cmd: const = 0xae41 (4 bytes) // id: intptr = 0x0 (8 bytes) // ] // returns fd_kvmcpu res = syscall(__NR_ioctl, /*fd=*/r[2], /*cmd=*/0xae41, /*id=*/0ul); if (res != -1) r[3] = res; // ioctl$KVM_SET_PIT2 arguments: [ // fd: fd_kvmvm (resource) // cmd: const = 0x4070aea0 (4 bytes) // arg: ptr[in, kvm_pit_state2] { // kvm_pit_state2 { // chans: array[kvm_pit_channel_state] { // kvm_pit_channel_state { // count: int32 = 0x2 (4 bytes) // lcount: int16 = 0x95c (2 bytes) // latched: int8 = 0x61 (1 bytes) // lstatus: int8 = 0x7 (1 bytes) // status: int8 = 0x2 (1 bytes) // rstate: int8 = 0xe (1 bytes) // wstate: int8 = 0x81 (1 bytes) // wlatch: int8 = 0x4b (1 bytes) // rw: int8 = 0xf (1 bytes) // mode: int8 = 0x4 (1 bytes) // bcd: int8 = 0x3 (1 bytes) // gate: int8 = 0x1b (1 bytes) // ltime: int64 = 0x7 (8 bytes) // } // kvm_pit_channel_state { // count: int32 = 0x2 (4 bytes) // lcount: int16 = 0x6 (2 bytes) // latched: int8 = 0x0 (1 bytes) // lstatus: int8 = 0x2 (1 bytes) // status: int8 = 0x0 (1 bytes) // rstate: int8 = 0x12 (1 bytes) // wstate: int8 = 0x5 (1 bytes) // wlatch: int8 = 0x1 (1 bytes) // rw: int8 = 0x7a (1 bytes) // mode: int8 = 0xc0 (1 bytes) // bcd: int8 = 0x5 (1 bytes) // gate: int8 = 0xa6 (1 bytes) // ltime: int64 = 0x401 (8 bytes) // } // kvm_pit_channel_state { // count: int32 = 0x4 (4 bytes) // lcount: int16 = 0x15 (2 bytes) // latched: int8 = 0x40 (1 bytes) // lstatus: int8 = 0x1 (1 bytes) // status: int8 = 0x20 (1 bytes) // rstate: int8 = 0xc8 (1 bytes) // wstate: int8 = 0xad (1 bytes) // wlatch: int8 = 0xe (1 bytes) // rw: int8 = 0x7 (1 bytes) // mode: int8 = 0x0 (1 bytes) // bcd: int8 = 0x2f (1 bytes) // gate: int8 = 0x1 (1 bytes) // ltime: int64 = 0xc (8 bytes) // } // } // flags: int32 = 0x6 (4 bytes) // pad: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} (length 0x24) // } // } // ] *(uint32_t*)0x200000000080 = 2; *(uint16_t*)0x200000000084 = 0x95c; *(uint8_t*)0x200000000086 = 0x61; *(uint8_t*)0x200000000087 = 7; *(uint8_t*)0x200000000088 = 2; *(uint8_t*)0x200000000089 = 0xe; *(uint8_t*)0x20000000008a = 0x81; *(uint8_t*)0x20000000008b = 0x4b; *(uint8_t*)0x20000000008c = 0xf; *(uint8_t*)0x20000000008d = 4; *(uint8_t*)0x20000000008e = 3; *(uint8_t*)0x20000000008f = 0x1b; *(uint64_t*)0x200000000090 = 7; *(uint32_t*)0x200000000098 = 2; *(uint16_t*)0x20000000009c = 6; *(uint8_t*)0x20000000009e = 0; *(uint8_t*)0x20000000009f = 2; *(uint8_t*)0x2000000000a0 = 0; *(uint8_t*)0x2000000000a1 = 0x12; *(uint8_t*)0x2000000000a2 = 5; *(uint8_t*)0x2000000000a3 = 1; *(uint8_t*)0x2000000000a4 = 0x7a; *(uint8_t*)0x2000000000a5 = 0xc0; *(uint8_t*)0x2000000000a6 = 5; *(uint8_t*)0x2000000000a7 = 0xa6; *(uint64_t*)0x2000000000a8 = 0x401; *(uint32_t*)0x2000000000b0 = 4; *(uint16_t*)0x2000000000b4 = 0x15; *(uint8_t*)0x2000000000b6 = 0x40; *(uint8_t*)0x2000000000b7 = 1; *(uint8_t*)0x2000000000b8 = 0x20; *(uint8_t*)0x2000000000b9 = 0xc8; *(uint8_t*)0x2000000000ba = 0xad; *(uint8_t*)0x2000000000bb = 0xe; *(uint8_t*)0x2000000000bc = 7; *(uint8_t*)0x2000000000bd = 0; *(uint8_t*)0x2000000000be = 0x2f; *(uint8_t*)0x2000000000bf = 1; *(uint64_t*)0x2000000000c0 = 0xc; *(uint32_t*)0x2000000000c8 = 6; memset((void*)0x2000000000cc, 0, 36); syscall(__NR_ioctl, /*fd=*/r[2], /*cmd=*/0x4070aea0, /*arg=*/0x200000000080ul); // ioctl$KVM_SET_IRQCHIP arguments: [ // fd: fd_kvmvm (resource) // cmd: const = 0x8208ae63 (4 bytes) // arg: ptr[in, kvm_irqchip] { // kvm_irqchip { // chipid: kvm_chip_id = 0x0 (4 bytes) // pad: const = 0x0 (4 bytes) // chip: union kvm_irq_chip { // pic: kvm_pic_state { // lastirr: int8 = 0x0 (1 bytes) // irr: int8 = 0x3 (1 bytes) // imr: int8 = 0x6 (1 bytes) // isr: int8 = 0x10 (1 bytes) // padd: int8 = 0x5 (1 bytes) // irqbase: int8 = 0x6 (1 bytes) // readreg: int8 = 0x6 (1 bytes) // poll: int8 = 0x7 (1 bytes) // special: int8 = 0x3 (1 bytes) // initst: int8 = 0x9 (1 bytes) // autoeoi: int8 = 0xff (1 bytes) // rotate: int8 = 0x7 (1 bytes) // nestedm: int8 = 0x64 (1 bytes) // init4: int8 = 0xf6 (1 bytes) // elcr: int8 = 0x3 (1 bytes) // elcrmas: int8 = 0x9 (1 bytes) // } // } // } // } // ] *(uint32_t*)0x200000000600 = 0; *(uint32_t*)0x200000000604 = 0; *(uint8_t*)0x200000000608 = 0; *(uint8_t*)0x200000000609 = 3; *(uint8_t*)0x20000000060a = 6; *(uint8_t*)0x20000000060b = 0x10; *(uint8_t*)0x20000000060c = 5; *(uint8_t*)0x20000000060d = 6; *(uint8_t*)0x20000000060e = 6; *(uint8_t*)0x20000000060f = 7; *(uint8_t*)0x200000000610 = 3; *(uint8_t*)0x200000000611 = 9; *(uint8_t*)0x200000000612 = -1; *(uint8_t*)0x200000000613 = 7; *(uint8_t*)0x200000000614 = 0x64; *(uint8_t*)0x200000000615 = 0xf6; *(uint8_t*)0x200000000616 = 3; *(uint8_t*)0x200000000617 = 9; syscall(__NR_ioctl, /*fd=*/r[2], /*cmd=*/0x8208ae63, /*arg=*/0x200000000600ul); // ioctl$KVM_SET_REGS arguments: [ // fd: fd_kvmcpu (resource) // cmd: const = 0x4090ae82 (4 bytes) // arg: ptr[in, kvm_regs] { // kvm_regs { // gp: array[int64] { // int64 = 0xcb (8 bytes) // int64 = 0xd (8 bytes) // int64 = 0x6 (8 bytes) // int64 = 0x6d (8 bytes) // int64 = 0x2 (8 bytes) // int64 = 0x1002 (8 bytes) // int64 = 0xf1 (8 bytes) // int64 = 0x200 (8 bytes) // int64 = 0x7fffffffffffb (8 bytes) // int64 = 0x8d (8 bytes) // int64 = 0xfffffffffffffffe (8 bytes) // int64 = 0x1 (8 bytes) // int64 = 0xfffffffffffffffe (8 bytes) // int64 = 0x5 (8 bytes) // int64 = 0x3 (8 bytes) // int64 = 0xbde (8 bytes) // } // rip: kvm_guest_addrs = 0x1000 (8 bytes) // rflags: kvm_x86_rflags = 0x67a64fa265d09613 (8 bytes) // } // } // ] *(uint64_t*)0x2000000003c0 = 0xcb; *(uint64_t*)0x2000000003c8 = 0xd; *(uint64_t*)0x2000000003d0 = 6; *(uint64_t*)0x2000000003d8 = 0x6d; *(uint64_t*)0x2000000003e0 = 2; *(uint64_t*)0x2000000003e8 = 0x1002; *(uint64_t*)0x2000000003f0 = 0xf1; *(uint64_t*)0x2000000003f8 = 0x200; *(uint64_t*)0x200000000400 = 0x7fffffffffffb; *(uint64_t*)0x200000000408 = 0x8d; *(uint64_t*)0x200000000410 = 0xfffffffffffffffe; *(uint64_t*)0x200000000418 = 1; *(uint64_t*)0x200000000420 = 0xfffffffffffffffe; *(uint64_t*)0x200000000428 = 5; *(uint64_t*)0x200000000430 = 3; *(uint64_t*)0x200000000438 = 0xbde; *(uint64_t*)0x200000000440 = 0x1000; *(uint64_t*)0x200000000448 = 0x67a64fa265d09613; syscall(__NR_ioctl, /*fd=*/r[3], /*cmd=*/0x4090ae82, /*arg=*/0x2000000003c0ul); // ioctl$KVM_RUN arguments: [ // fd: fd_kvmcpu (resource) // cmd: const = 0xae80 (4 bytes) // arg: const = 0x0 (8 bytes) // ] syscall(__NR_ioctl, /*fd=*/r[3], /*cmd=*/0xae80, /*arg=*/0ul); } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000, /*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=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; for (procid = 0; procid < 5; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }