// https://syzkaller.appspot.com/bug?id=451cabf93ff062700399d95a331e4eb2dfd66e4f // 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 #include #include static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } 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 void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } 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; } #define FS_IOC_SETFLAGS _IOW('f', 2, long) static void remove_dir(const char* dir) { DIR* dp; struct dirent* ep; int iter = 0; retry: while (umount2(dir, MNT_DETACH) == 0) { } dp = opendir(dir); if (dp == NULL) { if (errno == EMFILE) { exit(1); } exit(1); } while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); while (umount2(filename, MNT_DETACH) == 0) { } struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } int i; for (i = 0;; i++) { if (unlink(filename) == 0) break; if (errno == EPERM) { int fd = open(filename, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno != EBUSY || i > 100) exit(1); if (umount2(filename, MNT_DETACH)) exit(1); } } closedir(dp); int i; for (i = 0;; i++) { if (rmdir(dir) == 0) break; if (i < 100) { if (errno == EPERM) { int fd = open(dir, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno == EBUSY) { if (umount2(dir, MNT_DETACH)) exit(1); continue; } if (errno == ENOTEMPTY) { if (iter < 100) { iter++; goto retry; } } } exit(1); } } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); int i; for (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; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); setup_test(); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; res = syscall(__NR_socket, 0x10ul, 3ul, 0ul); if (res != -1) r[0] = res; NONFAILING(*(uint64_t*)0x20000280 = 0); NONFAILING(*(uint32_t*)0x20000288 = 0); NONFAILING(*(uint64_t*)0x20000290 = 0x20000000); NONFAILING(*(uint64_t*)0x20000000 = 0x200006c0); NONFAILING(memcpy((void*)0x200006c0, "\x28\x00\x00\x00\x10\x00\x5f\xba\x08" "\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00", 20)); NONFAILING(*(uint32_t*)0x200006d4 = 0); NONFAILING(memcpy( (void*)0x200006d8, "\x03\x00\x00\x80\x00\x00\x00\x00\x08\x00\x1b\x00\x00\x00\x00\x00\x07\x93" "\xae\x2d\xa5\xac\xc7\x99\xb5\x8c\xa6\x5a\x84\x14\xef\x73\x99\xa8\x7e\xca" "\x0d\xc2\x76\x29\x8b\xb0\xec\x93\x13\xae\x5d\x3b\x19\x92\x2f\x9a\x80\xac" "\xa8\x94\x1f\x62\x81\xf7\xcd\x8b\xbc\x2c\xd0\x18\xaa\x16\xdc\x1f\x8d\xed" "\xc3\x32\x6c\x89\xf6\x58\x04\x00\x00\x00\x78\x2b\x06\xaa\x3e\x87\x03\x7b" "\x9c\x80\x58\x30\x07\x9e\xd0\xf5\x88\x44\x93\x73\xbd\xbc\x44\x96\xa7\xa3" "\x06\x88\xd8\xff\xbd\x74\xb1\xdc\xa2\x45\xc0\x08\x81\xf9\x4d\x67\x25\x3b" "\x0a\x36\x9a\xa4\x97\x81\x6e\xc1\xf4\xa1\xd9\x12\xcf\x7c\x4c\xef\xf6\xd3" "\x61\xdc\x20\x48\x1b\xc5\xa4\x42\x64\x82\xd0\xb8\x05\xf0\x0a\xc5\xbd\x62" "\x65\x2e\x21\xfd\x03\x00\x4e\xa1\x23\xd3\xa2\xd5\x5b\xae\xff\xbb\x83\xdb" "\x1e\xa7\x2f\xea\x06\xa4\x45\x9d\xeb\xa2\x23\xf1\x8f\x21\xf2\x5b\x3e\x59" "\x2e\x13\xba\x69\x15\xd6\x91\xd7\x42\xc1\xe1\xd4\xf1\xde\x92\x66\xc8\xce" "\x87\x34\xd7\x2e\x75\xf9\xe0\xf6\xdd\xa5\x2b\xdb\x76\x2e\x05\x2e\xbd\x4a" "\xb2\xb6\x4e\x9f\x55\x58\x4e\xf1\x43\x7d\x09\xb4\xa3\x4c\x6b\x4b\x7e\xea" "\x9d\x84\xf3\xaf\x58\x6a\x22\x37\x27\x1b\xba\x94\x4e\xa8\x7e\xfd\xbf\x2e" "\x1f\x37\x86\xb5\x98\xd0\xa3\x03\x92\x61\xe3\xea\x8a\x2e\xbf\xc5\x46\x6d" "\x15\x27\xfb\xf9\x11\x0e\x14\xc9\x40\x05\xaa\x32\x2a\x05\xda\x7c\xb2\xcc" "\xd4\x3d\x43\x32\x8e\x50\x7e\x73\xcf\xe6\xf9\x56\x7b\x8e\x9f\xbf\xd2\x71" "\x5b\x2e\x4d\x9c\x5f\xf1\x0b\x67\x69\x15\x93\xd9\x32\x8a\xe0\xd4\x30\x99" "\xf6\x21\x9f\x23\xe2\x36\xe9\xc2\x73\xbd\x0d\x3b\x70\x60\xfd\xd6\x27\xb0" "\x37\x25\xb2\xaf\xc7\xb2\xb0\xb4\x24\x80\x35\x2a\x53\x50\xab\x01\x8b\xc8" "\x7f\xf2\x4e\x0e\x13\x54\xcf\x88\x31\x8f\x8d\xf5\x2d\xbd\x08\xf6\x02\x7e" "\x36\x51\x69\xc6\xff\x2a\x50\x0b\x7c\xee\xda\xd6\xc4\xed\x0a\x7c\xd0\x57" "\xad\xe8\x7b\xc2\x87\xb6\x6b\x4b\x82\xd2\xfb\x39\xc5\x82\xf2\xea\x3c\xd8" "\x01\x4f\xbe\x28\x0b\xa8\xca\x4c\x34\xb6\x5d\x8a\x8e\x3a\xbb\xfe\xa4", 449)); NONFAILING(*(uint64_t*)0x20000008 = 0x28); NONFAILING(*(uint64_t*)0x20000298 = 1); NONFAILING(*(uint64_t*)0x200002a0 = 0); NONFAILING(*(uint64_t*)0x200002a8 = 0); NONFAILING(*(uint32_t*)0x200002b0 = 0); syscall(__NR_sendmsg, r[0], 0x20000280ul, 0ul); res = syscall(__NR_socket, 0x10ul, 3ul, 0ul); if (res != -1) r[1] = res; NONFAILING(*(uint64_t*)0x20000040 = 0); NONFAILING(*(uint32_t*)0x20000048 = 0); NONFAILING(*(uint64_t*)0x20000050 = 0x20000240); NONFAILING(*(uint64_t*)0x20000240 = 0x20000340); NONFAILING(memcpy((void*)0x20000340, "\x40\x00\x00\x00\x10\x00\x05\x07\x03" "\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00", 20)); NONFAILING(*(uint32_t*)0x20000354 = 0); NONFAILING(memcpy((void*)0x20000358, "\x0f\xff\x00\x00\x08\x00\x00\x00\x18\x00\x12\x80\x08\x00" "\x01\x00\x73\x69\x74\x00\x0c\x00\x02\x80\x08\x00\x01\x00", 28)); NONFAILING(*(uint32_t*)0x20000374 = -1); NONFAILING(memcpy((void*)0x20000378, "\x08\x00\x04\x00", 4)); NONFAILING(*(uint32_t*)0x2000037c = -1); NONFAILING(memcpy((void*)0x20000380, "\x92\x8c\xa6\x53\xde\xfe\xda\x42\x00" "\x71\x3d\x97\xf6\xdd\x5f\x8e\x4f\x07" "\xee\x5f\xd0\xa3\xf6\x5e\x6e", 25)); NONFAILING(*(uint64_t*)0x20000248 = 0x40); NONFAILING(*(uint64_t*)0x20000058 = 1); NONFAILING(*(uint64_t*)0x20000060 = 0); NONFAILING(*(uint64_t*)0x20000068 = 0); NONFAILING(*(uint32_t*)0x20000070 = 0); syscall(__NR_sendmsg, r[1], 0x20000040ul, 0ul); } int main(void) { syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x32ul, -1, 0); install_segv_handler(); use_temporary_dir(); loop(); return 0; }