// https://syzkaller.appspot.com/bug?id=3e96783cf717ed2f5dc98bbf2b77613671d76ce3 // 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 #ifndef __NR_mkdirat #define __NR_mkdirat 296 #endif #ifndef __NR_mmap #define __NR_mmap 192 #endif #ifndef __NR_mount #define __NR_mount 21 #endif #ifndef __NR_openat #define __NR_openat 295 #endif #ifndef __NR_write #define __NR_write 4 #endif #undef __NR_mmap #define __NR_mmap __NR_mmap2 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[1] = {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 (4 bytes) // ] memcpy((void*)0x80000180, "./proc\000", 7); syscall( __NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x80000180, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/ 0x1ff); // 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 (4 bytes) // data: nil // ] memcpy((void*)0x800001c0, "./proc\000", 7); memcpy((void*)0x80000200, "proc\000", 5); syscall(__NR_mount, /*src=*/0, /*dst=*/0x800001c0, /*type=*/0x80000200, /*flags=*/0, /*data=*/0); // openat arguments: [ // fd: fd_dir (resource) // file: ptr[in, buffer] { // buffer: {2e 2f 70 72 6f 63 2f 62 75 73 2f 70 63 69 2f 30 30 2f 30 30 // 2e 30 00} (length 0x17) // } // flags: open_flags = 0x2 (4 bytes) // mode: open_mode = 0x181 (2 bytes) // ] // returns fd memcpy((void*)0x80000240, "./proc/bus/pci/00/00.0\000", 23); res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x80000240, /*flags=O_RDWR*/ 2, /*mode=S_IXOTH|S_IWUSR|S_IRUSR*/ 0x181); if (res != -1) r[0] = res; // write$P9_RREADDIR arguments: [ // fd: wfd9p (resource) // data: ptr[in, p9_msg[P9_RREADDIR, p9_rreaddir]] { // p9_msg[P9_RREADDIR, p9_rreaddir] { // size: bytesize = 0x10f (4 bytes) // type: const = 0x29 (1 bytes) // tag: int16 = 0x2 (2 bytes) // payload: p9_rreaddir { // count: int32 = 0x8000 (4 bytes) // entries: array[p9_dir] { // p9_dir { // qid: p9_qid { // type: p9_qid_types = 0x80 (1 bytes) // version: int32 = 0x1 (4 bytes) // path: int64 = 0x1 (8 bytes) // } // offset: int64 = 0xffffffff (8 bytes) // type: int8 = 0x9 (1 bytes) // name_len: len = 0x1c (2 bytes) // name: buffer: {2e 2f 70 72 6f 63 2f 62 75 73 2f 70 63 69 2f 30 // 30 2f 30 30 2e 30 2f 66 69 6c 65 30} (length 0x1c) // } // p9_dir { // qid: p9_qid { // type: p9_qid_types = 0x20 (1 bytes) // version: int32 = 0x4 (4 bytes) // path: int64 = 0x8 (8 bytes) // } // offset: int64 = 0x8 (8 bytes) // type: int8 = 0x9 (1 bytes) // name_len: len = 0x1c (2 bytes) // name: buffer: {2e 2f 70 72 6f 63 2f 62 75 73 2f 70 63 69 2f 30 // 30 2f 30 30 2e 30 2f 66 69 6c 65 30} (length 0x1c) // } // p9_dir { // qid: p9_qid { // type: p9_qid_types = 0x40 (1 bytes) // version: int32 = 0x3 (4 bytes) // path: int64 = 0x4 (8 bytes) // } // offset: int64 = 0x5 (8 bytes) // type: int8 = 0x8 (1 bytes) // name_len: len = 0x1c (2 bytes) // name: buffer: {2e 2f 70 72 6f 63 2f 62 75 73 2f 70 63 69 2f 30 // 30 2f 30 30 2e 30 2f 66 69 6c 65 30} (length 0x1c) // } // p9_dir { // qid: p9_qid { // type: p9_qid_types = 0x84 (1 bytes) // version: int32 = 0x0 (4 bytes) // path: int64 = 0x3 (8 bytes) // } // offset: int64 = 0x8 (8 bytes) // type: int8 = 0xf8 (1 bytes) // name_len: len = 0x16 (2 bytes) // name: buffer: {2e 2f 70 72 6f 63 2f 62 75 73 2f 70 63 69 2f 30 // 30 2f 30 30 2e 30} (length 0x16) // } // p9_dir { // qid: p9_qid { // type: p9_qid_types = 0x0 (1 bytes) // version: int32 = 0x1 (4 bytes) // path: int64 = 0x6 (8 bytes) // } // offset: int64 = 0xe50 (8 bytes) // type: int8 = 0x7 (1 bytes) // name_len: len = 0x22 (2 bytes) // name: buffer: {2e 2f 70 72 6f 63 2f 62 75 73 2f 70 63 69 2f 30 // 30 2f 30 30 2e 30 2f 66 69 6c 65 30 2f 66 69 6c 65 30} (length // 0x22) // } // } // } // } // } // size: bytesize = 0x10f (4 bytes) // ] *(uint32_t*)0x80000300 = 0x10f; *(uint8_t*)0x80000304 = 0x29; *(uint16_t*)0x80000305 = 2; *(uint32_t*)0x80000307 = 0x8000; *(uint8_t*)0x8000030b = 0x80; *(uint32_t*)0x8000030c = 1; *(uint64_t*)0x80000310 = 1; *(uint64_t*)0x80000318 = 0xffffffff; *(uint8_t*)0x80000320 = 9; *(uint16_t*)0x80000321 = 0x1c; memcpy((void*)0x80000323, "./proc/bus/pci/00/00.0/file0", 28); *(uint8_t*)0x8000033f = 0x20; *(uint32_t*)0x80000340 = 4; *(uint64_t*)0x80000344 = 8; *(uint64_t*)0x8000034c = 8; *(uint8_t*)0x80000354 = 9; *(uint16_t*)0x80000355 = 0x1c; memcpy((void*)0x80000357, "./proc/bus/pci/00/00.0/file0", 28); *(uint8_t*)0x80000373 = 0x40; *(uint32_t*)0x80000374 = 3; *(uint64_t*)0x80000378 = 4; *(uint64_t*)0x80000380 = 5; *(uint8_t*)0x80000388 = 8; *(uint16_t*)0x80000389 = 0x1c; memcpy((void*)0x8000038b, "./proc/bus/pci/00/00.0/file0", 28); *(uint8_t*)0x800003a7 = 0x84; *(uint32_t*)0x800003a8 = 0; *(uint64_t*)0x800003ac = 3; *(uint64_t*)0x800003b4 = 8; *(uint8_t*)0x800003bc = 0xf8; *(uint16_t*)0x800003bd = 0x16; memcpy((void*)0x800003bf, "./proc/bus/pci/00/00.0", 22); *(uint8_t*)0x800003d5 = 0; *(uint32_t*)0x800003d6 = 1; *(uint64_t*)0x800003da = 6; *(uint64_t*)0x800003e2 = 0xe50; *(uint8_t*)0x800003ea = 7; *(uint16_t*)0x800003eb = 0x22; memcpy((void*)0x800003ed, "./proc/bus/pci/00/00.0/file0/file0", 34); syscall(__NR_write, /*fd=*/(intptr_t)r[0], /*data=*/0x80000300, /*size=*/0x10f); } int main(void) { syscall(__NR_mmap, /*addr=*/0x7ffff000, /*len=*/0x1000, /*prot=*/0, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32, /*fd=*/(intptr_t)-1, /*offset=*/0); syscall(__NR_mmap, /*addr=*/0x80000000, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32, /*fd=*/(intptr_t)-1, /*offset=*/0); syscall(__NR_mmap, /*addr=*/0x81000000, /*len=*/0x1000, /*prot=*/0, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32, /*fd=*/(intptr_t)-1, /*offset=*/0); const char* reason; (void)reason; loop(); return 0; }