// https://syzkaller.appspot.com/bug?id=7527ae92ab0b6495f037cfa703ac9dee9295c67c // 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; int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0; int valid = addr < prog_start || addr > prog_end; if (skip && valid) { _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(...) \ ({ \ int ok = 1; \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } else \ ok = 0; \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ ok; \ }) 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) { int iter = 0; DIR* dp = 0; retry: while (umount2(dir, MNT_DETACH) == 0) { } dp = opendir(dir); if (dp == NULL) { if (errno == EMFILE) { exit(1); } exit(1); } struct dirent* ep = 0; 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); for (int 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); 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++) { 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 < 5000) { continue; } kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[3] = {0xffffffffffffffff, 0x0, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; res = syscall(__NR_socket, 0x11ul, 0x800000003ul, 0); if (res != -1) r[0] = res; NONFAILING(*(uint16_t*)0x20000080 = 0x11); NONFAILING(memcpy((void*)0x20000082, "\x00\x00\x01\x00\x00\x00\x00\x00\x08\x00\x44\x94\x4e\xeb" "\xa7\x1a\x49\x76\xe2\x52\x92\x2c\xb1\x8f\x6e\x2e\x2a\xba" "\x00\x00\x00\x01\x2e\x0b\x38\x36\x00\x54\x04\xb0\xe0\x30" "\x1a\x4c\xe8\x75\xf2\xe3\xff\x5f\x16\x3e\xe3\x40\xb7\x67" "\x95\x00\x80\x00\x00\x00\x00\x00\x00\x01\x01\x01\x3c\x58" "\x11\x03\x9e\x15\x77\x50\x27\xec\xce\x66\xfd\x79\x2b\xbf" "\x0e\x5b\xf5\xff\x1b\x08\x16\xf3\xf6\xdb\x1c\x00\x01\x00" "\x00\x00\x00\x00\x00\x00\x49\x74\x00\x00\x00\x00\x00\x00" "\x00\x06\xad\x8e\x5e\xcc\x32\x6d\x3a\x09\xff\xc2\xc6\x54", 126)); syscall(__NR_bind, r[0], 0x20000080ul, 0x80ul); NONFAILING(*(uint32_t*)0x20000100 = 0x14); res = syscall(__NR_getsockname, r[0], 0x20000040ul, 0x20000100ul); if (res != -1) NONFAILING(r[1] = *(uint32_t*)0x20000044); res = syscall(__NR_socket, 0x10ul, 3ul, 0); if (res != -1) r[2] = res; NONFAILING(*(uint64_t*)0x200007c0 = 0); NONFAILING(*(uint32_t*)0x200007c8 = 0); NONFAILING(*(uint64_t*)0x200007d0 = 0x20000780); NONFAILING(*(uint64_t*)0x20000780 = 0x20001440); NONFAILING(*(uint32_t*)0x20001440 = 0x150); NONFAILING(*(uint16_t*)0x20001444 = 0x24); NONFAILING(*(uint16_t*)0x20001446 = 0xf0b); NONFAILING(*(uint32_t*)0x20001448 = 0); NONFAILING(*(uint32_t*)0x2000144c = 0); NONFAILING(*(uint8_t*)0x20001450 = 0); NONFAILING(*(uint8_t*)0x20001451 = 0); NONFAILING(*(uint16_t*)0x20001452 = 0); NONFAILING(*(uint32_t*)0x20001454 = r[1]); NONFAILING(*(uint16_t*)0x20001458 = 0); NONFAILING(*(uint16_t*)0x2000145a = 0); NONFAILING(*(uint16_t*)0x2000145c = -1); NONFAILING(*(uint16_t*)0x2000145e = -1); NONFAILING(*(uint16_t*)0x20001460 = 0); NONFAILING(*(uint16_t*)0x20001462 = 0); NONFAILING(*(uint16_t*)0x20001464 = 8); NONFAILING(*(uint16_t*)0x20001466 = 1); NONFAILING(memcpy((void*)0x20001468, "red\000", 4)); NONFAILING(*(uint16_t*)0x2000146c = 0x124); NONFAILING(*(uint16_t*)0x2000146e = 2); NONFAILING(*(uint16_t*)0x20001470 = 0x104); NONFAILING(*(uint16_t*)0x20001472 = 2); NONFAILING(memcpy( (void*)0x20001474, "\x12\xb5\x80\xbb\x51\x83\xd7\x4b\x7f\xbe\x9e\x72\x82\xab\x96\x45\x42\x9e" "\x67\x95\x91\x37\x35\x47\x06\x2b\x36\x11\x7a\xd1\xba\x67\x17\xe8\x7c\x01" "\xe3\x86\x96\x36\x92\xed\x76\x2d\xc5\xe0\x59\x8d\x04\x36\xb9\xcc\x30\x68" "\x74\xe1\x57\x43\x64\xbf\x17\xd6\xae\xe8\xda\xd4\x03\xcb\xa6\xc5\x12\xff" "\xa3\xfc\x97\x3a\x3c\xfd\x5d\x96\x15\xb1\x67\x74\xd5\xde\x66\x88\xb3\xbc" "\x38\x7b\xb7\xc1\x1e\x3b\x3b\x18\x84\x23\xf4\x91\x3e\xc3\x38\x17\x5b\xba" "\x14\xfa\x05\x26\x6d\xc4\x92\xa0\xc0\x3c\xbe\x95\xca\xe2\x7a\x9a\x21\xf5" "\x11\x56\x3a\x85\x88\x29\x6a\x1b\x33\xbb\xf9\x8b\xc0\x34\xb8\xad\x77\x7a" "\x90\xbb\x3d\x99\xe4\xa4\xf0\xf6\x9b\xa3\x73\xca\x2b\x19\xb5\xa2\xc2\xd0" "\xd5\x72\x3c\x5c\xfb\x02\x9e\x84\x1a\x79\xdd\xee\x27\x54\xd6\xa9\x8f\x51" "\x1e\xd3\xfd\x2a\xf3\xdf\xb0\x5d\x53\x0b\x67\x65\xa7\xfb\x3c\x7e\x60\xab" "\xb4\x2f\xa0\xac\xc4\x46\xb9\x9a\xfe\xeb\xcc\xf3\x4d\x87\xa6\x9d\xb2\x3c" "\x01\x96\x64\xb5\x60\xf6\x08\x3f\x24\x01\x2e\x6e\x88\x2c\x26\xc4\x42\x81" "\x5b\xfb\x52\x12\x88\xc8\x5a\xe4\xfd\xef\xcd\xee\x64\xfb\x94\xfe\xe2\xea" "\xd4\x6a\x2f\xc1", 256)); NONFAILING(*(uint16_t*)0x20001574 = 8); NONFAILING(*(uint16_t*)0x20001576 = 6); NONFAILING(*(uint32_t*)0x20001578 = -1); NONFAILING(*(uint16_t*)0x2000157c = 0x14); NONFAILING(*(uint16_t*)0x2000157e = 1); NONFAILING(*(uint32_t*)0x20001580 = 0); NONFAILING(*(uint32_t*)0x20001584 = 0); NONFAILING(*(uint32_t*)0x20001588 = 0); NONFAILING(*(uint8_t*)0x2000158c = 0); NONFAILING(*(uint8_t*)0x2000158d = 0); NONFAILING(*(uint8_t*)0x2000158e = 0); NONFAILING(*(uint8_t*)0x2000158f = 0); NONFAILING(*(uint64_t*)0x20000788 = 0x150); NONFAILING(*(uint64_t*)0x200007d8 = 1); NONFAILING(*(uint64_t*)0x200007e0 = 0); NONFAILING(*(uint64_t*)0x200007e8 = 0); NONFAILING(*(uint32_t*)0x200007f0 = 0); syscall(__NR_sendmsg, r[2], 0x200007c0ul, 0ul); } int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); install_segv_handler(); use_temporary_dir(); loop(); return 0; }