// https://syzkaller.appspot.com/bug?id=e5ec25c5282aa2341e7429e1db5725a773782635 // 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[1] = {0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // mkdir arguments: [ // path: ptr[in, buffer] { // buffer: {63 6f 6e 66 69 67 00} (length 0x7) // } // mode: open_mode = 0x1ff (8 bytes) // ] memcpy((void*)0x200000000000, "config\000", 7); syscall( __NR_mkdir, /*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: {63 6f 6e 66 69 67 00} (length 0x7) // } // type: ptr[in, buffer] { // buffer: {63 6f 6e 66 69 67 66 73 00} (length 0x9) // } // flags: mount_flags = 0x0 (8 bytes) // data: nil // ] memcpy((void*)0x200000000100, "config\000", 7); memcpy((void*)0x200000000200, "configfs\000", 9); syscall(__NR_mount, /*src=*/0ul, /*dst=*/0x200000000100ul, /*type=*/0x200000000200ul, /*flags=*/0ul, /*data=*/0ul); // mkdir arguments: [ // path: ptr[in, buffer] { // buffer: {63 6f 6e 66 69 67 2f 75 73 62 5f 67 61 64 67 65 74 2f 67 31 // 00} (length 0x15) // } // mode: open_mode = 0x1ff (8 bytes) // ] memcpy((void*)0x200000000300, "config/usb_gadget/g1\000", 21); syscall( __NR_mkdir, /*path=*/0x200000000300ul, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/ 0x1fful); // mkdir arguments: [ // path: ptr[in, buffer] { // buffer: {63 6f 6e 66 69 67 2f 75 73 62 5f 67 61 64 67 65 74 2f 67 31 // 2f 66 75 6e 63 74 69 6f 6e 73 2f 75 61 63 32 2e 75 73 62 30 00} // (length 0x29) // } // mode: open_mode = 0x1ff (8 bytes) // ] memcpy((void*)0x200000000500, "config/usb_gadget/g1/functions/uac2.usb0\000", 41); syscall( __NR_mkdir, /*path=*/0x200000000500ul, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/ 0x1fful); // openat arguments: [ // fd: fd_dir (resource) // file: ptr[in, buffer] { // buffer: {63 6f 6e 66 69 67 2f 75 73 62 5f 67 61 64 67 65 74 2f 67 31 // 2f 66 75 6e 63 74 69 6f 6e 73 2f 75 61 63 32 2e 75 73 62 30 2f 63 5f // 73 72 61 74 65 00} (length 0x31) // } // flags: open_flags = 0x1 (4 bytes) // mode: open_mode = 0x0 (2 bytes) // ] // returns fd memcpy((void*)0x200000000600, "config/usb_gadget/g1/functions/uac2.usb0/c_srate\000", 49); res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000600ul, /*flags=O_WRONLY*/ 1, /*mode=*/0); if (res != -1) r[0] = res; // write arguments: [ // fd: fd (resource) // buf: ptr[in, buffer] { // buffer: {34 34 31 46 30 2c 34 ca 26 34 83 85 ce 08 a6 47 bd 92 67 1b // f5 8e bf 98 5e 2d 6c 66 c4 0d 80 e9 ed 03 5e 90 90 94 61 6c ac 97 1c // 79 38 92 53 a7 9e fa e2 74 fe d6 a6 e8 6a 55 71 65 df 7b 12 09 76 54 // 0a 63 74 e0 bd 54 51 54 d5 e4 91 3a 5a ab 9c 7c 5e 69 18 2f 88 46 90 // b7 be f3 58 0c ca 69 33 6f 21 df 01 6d bb 7b 33 3c be 95 a4 fb} // (length 0x6e) // } // count: len = 0x6e (8 bytes) // ] memcpy((void*)0x200000000280, "\x34\x34\x31\x46\x30\x2c\x34\xca\x26\x34\x83\x85\xce\x08\xa6\x47\xbd" "\x92\x67\x1b\xf5\x8e\xbf\x98\x5e\x2d\x6c\x66\xc4\x0d\x80\xe9\xed\x03" "\x5e\x90\x90\x94\x61\x6c\xac\x97\x1c\x79\x38\x92\x53\xa7\x9e\xfa\xe2" "\x74\xfe\xd6\xa6\xe8\x6a\x55\x71\x65\xdf\x7b\x12\x09\x76\x54\x0a\x63" "\x74\xe0\xbd\x54\x51\x54\xd5\xe4\x91\x3a\x5a\xab\x9c\x7c\x5e\x69\x18" "\x2f\x88\x46\x90\xb7\xbe\xf3\x58\x0c\xca\x69\x33\x6f\x21\xdf\x01\x6d" "\xbb\x7b\x33\x3c\xbe\x95\xa4\xfb", 110); syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x200000000280ul, /*count=*/0x6eul); } 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; }