// https://syzkaller.appspot.com/bug?id=93389742321a26855072ae4c7c97d10f6853e6ba // 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 #ifndef __NR_fsconfig #define __NR_fsconfig 431 #endif #ifndef __NR_fsopen #define __NR_fsopen 430 #endif 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"); } #define KMEMLEAK_FILE "/sys/kernel/debug/kmemleak" static const char* setup_leak() { if (!write_file(KMEMLEAK_FILE, "scan=off")) { if (errno == EBUSY) return "KMEMLEAK disabled: increase CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE" " or unset CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF"; return "failed to write(kmemleak, \"scan=off\")"; } if (!write_file(KMEMLEAK_FILE, "scan")) return "failed to write(kmemleak, \"scan\")"; sleep(5); if (!write_file(KMEMLEAK_FILE, "scan")) return "failed to write(kmemleak, \"scan\")"; if (!write_file(KMEMLEAK_FILE, "clear")) return "failed to write(kmemleak, \"clear\")"; return NULL; } static void check_leaks(void) { int fd = open(KMEMLEAK_FILE, O_RDWR); if (fd == -1) exit(1); uint64_t start = current_time_ms(); if (write(fd, "scan", 4) != 4) exit(1); sleep(1); while (current_time_ms() - start < 4 * 1000) sleep(1); if (write(fd, "scan", 4) != 4) exit(1); static char buf[128 << 10]; ssize_t n = read(fd, buf, sizeof(buf) - 1); if (n < 0) exit(1); int nleaks = 0; if (n != 0) { sleep(1); if (write(fd, "scan", 4) != 4) exit(1); if (lseek(fd, 0, SEEK_SET) < 0) exit(1); n = read(fd, buf, sizeof(buf) - 1); if (n < 0) exit(1); buf[n] = 0; char* pos = buf; char* end = buf + n; while (pos < end) { char* next = strstr(pos + 1, "unreferenced object"); if (!next) next = end; char prev = *next; *next = 0; fprintf(stderr, "BUG: memory leak\n%s\n", pos); *next = prev; pos = next; nleaks++; } } if (write(fd, "clear", 5) != 5) exit(1); close(fd); if (nleaks) exit(1); } 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; } check_leaks(); } } uint64_t r[1] = {0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // fsopen arguments: [ // type: ptr[in, buffer] { // buffer: {63 69 66 73 00} (length 0x5) // } // flags: fsopen_flags = 0x0 (8 bytes) // ] // returns fd_fscontext memcpy((void*)0x200000000000, "cifs\000", 5); res = syscall(__NR_fsopen, /*type=*/0x200000000000ul, /*flags=*/0ul); if (res != -1) r[0] = res; // fsconfig$FSCONFIG_SET_STRING arguments: [ // fd: fd_fscontext (resource) // cmd: const = 0x1 (8 bytes) // key: ptr[in, buffer] { // buffer: {73 6f 75 72 63 65} (length 0x6) // } // value: ptr[in, buffer] { // buffer: {2f 2f f2 2f 06 08 2f df 2f 6f dc ea 95 9a 82 10 97 57 8f 37 // 98 9b 5c 2f 5c f9 0d 6d 44 94 29 55 db 15 58 2e 49 0a 7d f3 9d e4 5f // 05 9c 71 66 34 49 5e 23 62 3f 39 de af 75 27 83 4c e0 97 e1 6e 5f a4 // 25 b1 97 93 af 76 ce 2f 5c b4 4c f2 5f a7 fb f4 84 1f 41 ea 73 5e ef // a2 85 a3 21 fb 93 d7 52 ab 32 1e 57 e9 68 9b f7 75 6c f9 44 d4 82 58 // 35 13 aa 87 f9 ba a9 6d 14 14 52 5f 9a 5c 3e 34 ce 8e 5f 23 f8 44 b1 // de 70 01 cc 3a a6 c5 6e eb ab f7 30 99 ef 8b 3c 4d 0a c0 60 5b 82 f6 // 24 a4 be 1e d3 e4 d9 4c 14 ed cf cb 92 f1 83 1a 31 a6 f3 65 c2 46 c3 // 00 aa d5 fc 1b 52 a9 8c b4 26 9f a2 24 06 1a b0 57 23 f4 de 36 04 63 // c0 ee 63 a0 6c d5 64 e5 cd b2 c1 30 97 77 87 e5 06 91 57 0d 72 f5 97 // 25 e8 70 4f eb 5d c2 98 43 ff 4b a0 b3 5c 99 7b cd 52 92 94 f7 1d 01 // 51 1a bd 15 62 15 68 e2 21 00 b9 7a 29 19 00 ee d2 29 5b 70 60 b3 03 // a7 70 27 58 ec cd 6f 58 05 ff ff 2f 6f b2 ad b8 89 69 40 0c ff 53 26 // 8a c9 fe 7a c2 90 e7 46 a6 db 0d 03 6a 2c 4e e1 6c 77 0a ad e8 f0 bd // a1 98 ce f9 1e 52 9c 63 c5 6b 65 5f a7 11 22 04 d8 2e a0 15 83 f1 92 // db 79 e9 dc 40 2e c1 67 c6 0c 63 a2 36 d8 df ef f7 9c 1a cc 8a 6d 8b // 37 cf c5 a6 f4 0c ab 6a 25 59 a9 dd 0e 39 65 b5 ec 99 40 d2 09 0a b1 // 6f} (length 0x185) // } // aux: const = 0x0 (8 bytes) // ] memcpy((void*)0x200000000040, "source", 6); memcpy((void*)0x200000005fc0, "//\362/\006\b/\337/o\334\352\225\232\202\020\227W\2177\230\233\\/" "\\\371\rmD\224)U\333\025X.I\n}\363\235\344_\005\234qf4I^#b?" "9\336\257u\'\203L\340\227\341n_\244%\261\227\223\257v\316/" "\\\264L\362_\247\373\364\204\037A\352s^\357\242\205\243!" "\373\223\327R\2532\036W\351h\233\367ul\371D\324\202X5\023\252\207\371" "\272\251m\024\024R_\232\\>4\316\216_#\370D\261\336p\001\314:" "\246\305n\353\253\3670\231\357\2134\316\216_#\370D\261\336p\001\314:" "\246\305n\353\253\3670\231\357\213