// 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 #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 6d 79 63 6f 6e 66 69 67 00} (length 0xb) // } // mode: open_mode = 0x13c (4 bytes) // ] memcpy((void*)0x80000280, "./myconfig\000", 11); syscall(__NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x80000280, /*mode=S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IRUSR*/ 0x13c); // mount arguments: [ // src: nil // dst: ptr[in, buffer] { // buffer: {2e 2f 6d 79 63 6f 6e 66 69 67 00} (length 0xb) // } // type: ptr[in, buffer] { // buffer: {63 6f 6e 66 69 67 66 73 00} (length 0x9) // } // flags: mount_flags = 0x0 (4 bytes) // data: nil // ] memcpy((void*)0x800001c0, "./myconfig\000", 11); memcpy((void*)0x80000200, "configfs\000", 9); syscall(__NR_mount, /*src=*/0, /*dst=*/0x800001c0, /*type=*/0x80000200, /*flags=*/0, /*data=*/0); // mkdirat arguments: [ // fd: fd_dir (resource) // path: ptr[in, buffer] { // buffer: {2e 2f 6d 79 63 6f 6e 66 69 67 2f 75 73 62 5f 67 61 64 67 65 // 74 2f 67 31 00} (length 0x19) // } // mode: open_mode = 0x1ff (4 bytes) // ] memcpy((void*)0x80000240, "./myconfig/usb_gadget/g1\000", 25); syscall( __NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x80000240, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/ 0x1ff); // mkdirat arguments: [ // fd: fd_dir (resource) // path: ptr[in, buffer] { // buffer: {2e 2f 6d 79 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 0x2d) // } // mode: open_mode = 0x1ff (4 bytes) // ] memcpy((void*)0x800003c0, "./myconfig/usb_gadget/g1/functions/uac2.usb0\000", 45); syscall( __NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x800003c0, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/ 0x1ff); // openat arguments: [ // fd: fd_dir (resource) // file: ptr[in, buffer] { // buffer: {2e 2f 6d 79 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 0x35) // } // flags: open_flags = 0xe8202 (4 bytes) // mode: open_mode = 0x1c3 (2 bytes) // ] // returns fd memcpy((void*)0x80000480, "./myconfig/usb_gadget/g1/functions/uac2.usb0/c_srate\000", 53); res = syscall( __NR_openat, /*fd=*/0xffffff9c, /*file=*/0x80000480, /*flags=O_TRUNC|O_NOFOLLOW|O_NOATIME|O_LARGEFILE|O_CLOEXEC|0x2*/ 0xe8202, /*mode=S_IXOTH|S_IWOTH|S_IXUSR|S_IWUSR|S_IRUSR*/ 0x1c3); if (res != -1) r[0] = res; // write arguments: [ // fd: fd (resource) // buf: ptr[in, buffer] { // buffer: {34 74 99 ac ee 44 6f 81 aa 92 30 2c 38 38 32 30 30 2c a6 45 // 26 92 46 9d 66 e0} (length 0x1a) // } // count: len = 0x1a (4 bytes) // ] memcpy((void*)0x800004c0, "\x34\x74\x99\xac\xee\x44\x6f\x81\xaa\x92\x30\x2c\x38\x38\x32\x30\x30" "\x2c\xa6\x45\x26\x92\x46\x9d\x66\xe0", 26); syscall(__NR_write, /*fd=*/(intptr_t)r[0], /*buf=*/0x800004c0, /*count=*/0x1a); } 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; }