// https://syzkaller.appspot.com/bug?id=a1954eed3adfde914df9a0a2d0b7d1ecb876072f // 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 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 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[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // mkdirat arguments: [ // fd: fd_dir (resource) // path: ptr[in, buffer] { // buffer: {2e 2f 70 72 6f 63 00} (length 0x7) // } // mode: open_mode = 0x1ff (8 bytes) // ] memcpy((void*)0x200000000000, "./proc\000", 7); syscall( __NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x200000000000ul, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/ 0x1fful); // mount arguments: [ // src: nil // dst: ptr[in, buffer] { // buffer: {2e 2f 70 72 6f 63 00} (length 0x7) // } // type: ptr[in, buffer] { // buffer: {70 72 6f 63 00} (length 0x5) // } // flags: mount_flags = 0x0 (8 bytes) // data: nil // ] memcpy((void*)0x200000000040, "./proc\000", 7); memcpy((void*)0x2000000001c0, "proc\000", 5); syscall(__NR_mount, /*src=*/0ul, /*dst=*/0x200000000040ul, /*type=*/0x2000000001c0ul, /*flags=*/0ul, /*data=*/0ul); // openat arguments: [ // fd: fd_dir (resource) // file: ptr[in, buffer] { // buffer: {2e 2f 70 72 6f 63 2f 73 79 73 2f 6b 65 72 6e 65 6c 2f 63 74 // 72 6c 2d 61 6c 74 2d 64 65 6c 00} (length 0x1f) // } // flags: open_flags = 0x1 (4 bytes) // mode: open_mode = 0x0 (2 bytes) // ] // returns fd memcpy((void*)0x200000000200, "./proc/sys/kernel/ctrl-alt-del\000", 31); res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000200ul, /*flags=O_WRONLY*/ 1, /*mode=*/0); if (res != -1) r[0] = res; // write arguments: [ // fd: fd (resource) // buf: ptr[in, buffer] { // buffer: {31} (length 0x1) // } // count: len = 0x1 (8 bytes) // ] memset((void*)0x200000000280, 49, 1); syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x200000000280ul, /*count=*/1ul); // openat$uinput arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 75 69 6e 70 75 74 00} (length 0xc) // } // flags: uinput_open_flags = 0x802 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_uinput memcpy((void*)0x200000000580, "/dev/uinput\000", 12); res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000580ul, /*flags=O_RDWR_NONBLOCK*/ 0x802, /*mode=*/0); if (res != -1) r[1] = res; // ioctl$UI_SET_EVBIT arguments: [ // fd: fd_uinput (resource) // cmd: const = 0x40045564 (4 bytes) // arg: intptr = 0x1 (8 bytes) // ] syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x40045564, /*arg=*/1ul); // ioctl$UI_SET_KEYBIT arguments: [ // fd: fd_uinput (resource) // cmd: const = 0x40045565 (4 bytes) // arg: intptr = 0x1d (8 bytes) // ] syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x40045565, /*arg=*/0x1dul); // ioctl$UI_SET_KEYBIT arguments: [ // fd: fd_uinput (resource) // cmd: const = 0x40045565 (4 bytes) // arg: intptr = 0x38 (8 bytes) // ] syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x40045565, /*arg=*/0x38ul); // ioctl$UI_SET_KEYBIT arguments: [ // fd: fd_uinput (resource) // cmd: const = 0x40045565 (4 bytes) // arg: intptr = 0x6f (8 bytes) // ] syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x40045565, /*arg=*/0x6ful); // ioctl$UI_DEV_SETUP arguments: [ // fd: fd_uinput (resource) // cmd: const = 0x405c5503 (4 bytes) // arg: ptr[in, uinput_setup] { // uinput_setup { // id: input_id { // bustype: int16 = 0x3 (2 bytes) // vendor: int16 = 0x1 (2 bytes) // product: int16 = 0x1 (2 bytes) // version: int16 = 0x1 (2 bytes) // } // name: buffer: {73 79 7a 30 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 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} (length 0x50) // ff_effects_max: int32 = 0x0 (4 bytes) // } // } // ] *(uint16_t*)0x2000000005c0 = 3; *(uint16_t*)0x2000000005c2 = 1; *(uint16_t*)0x2000000005c4 = 1; *(uint16_t*)0x2000000005c6 = 1; memcpy((void*)0x2000000005c8, "syz0\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000", 80); *(uint32_t*)0x200000000618 = 0; syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x405c5503, /*arg=*/0x2000000005c0ul); // ioctl$UI_DEV_CREATE arguments: [ // fd: fd_uinput (resource) // cmd: const = 0x5501 (4 bytes) // ] syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x5501, 0); // write$input_event arguments: [ // fd: fd_uinput (resource) // data: ptr[in, input_event] { // input_event { // time: timeval { // sec: time_sec (resource) // usec: time_usec (resource) // } // type: input_codes = 0x1 (2 bytes) // code: int16 = 0x1d (2 bytes) // val: int32 = 0x1 (4 bytes) // } // } // len: len = 0x18 (8 bytes) // ] *(uint64_t*)0x200000000640 = 0; *(uint64_t*)0x200000000648 = 0; *(uint16_t*)0x200000000650 = 1; *(uint16_t*)0x200000000652 = 0x1d; *(uint32_t*)0x200000000654 = 1; syscall(__NR_write, /*fd=*/r[1], /*data=*/0x200000000640ul, /*len=*/0x18ul); // write$input_event arguments: [ // fd: fd_uinput (resource) // data: ptr[in, input_event] { // input_event { // time: timeval { // sec: time_sec (resource) // usec: time_usec (resource) // } // type: input_codes = 0x1 (2 bytes) // code: int16 = 0x38 (2 bytes) // val: int32 = 0x1 (4 bytes) // } // } // len: len = 0x18 (8 bytes) // ] *(uint64_t*)0x200000000680 = 0; *(uint64_t*)0x200000000688 = 0; *(uint16_t*)0x200000000690 = 1; *(uint16_t*)0x200000000692 = 0x38; *(uint32_t*)0x200000000694 = 1; syscall(__NR_write, /*fd=*/r[1], /*data=*/0x200000000680ul, /*len=*/0x18ul); // write$input_event arguments: [ // fd: fd_uinput (resource) // data: ptr[in, input_event] { // input_event { // time: timeval { // sec: time_sec (resource) // usec: time_usec (resource) // } // type: input_codes = 0x1 (2 bytes) // code: int16 = 0x6f (2 bytes) // val: int32 = 0x1 (4 bytes) // } // } // len: len = 0x18 (8 bytes) // ] *(uint64_t*)0x2000000006c0 = 0; *(uint64_t*)0x2000000006c8 = 0; *(uint16_t*)0x2000000006d0 = 1; *(uint16_t*)0x2000000006d2 = 0x6f; *(uint32_t*)0x2000000006d4 = 1; syscall(__NR_write, /*fd=*/r[1], /*data=*/0x2000000006c0ul, /*len=*/0x18ul); // write$input_event arguments: [ // fd: fd_uinput (resource) // data: ptr[in, input_event] { // input_event { // time: timeval { // sec: time_sec (resource) // usec: time_usec (resource) // } // type: input_codes = 0x0 (2 bytes) // code: int16 = 0x0 (2 bytes) // val: int32 = 0x0 (4 bytes) // } // } // len: len = 0x18 (8 bytes) // ] *(uint64_t*)0x200000000700 = 0; *(uint64_t*)0x200000000708 = 0; *(uint16_t*)0x200000000710 = 0; *(uint16_t*)0x200000000712 = 0; *(uint32_t*)0x200000000714 = 0; syscall(__NR_write, /*fd=*/r[1], /*data=*/0x200000000700ul, /*len=*/0x18ul); } 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; loop(); return 0; }