// https://syzkaller.appspot.com/bug?id=4f3a544c4a1f113216b11517018d36d2007c85d6 // 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 #include #include static unsigned long long procid; 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 void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } 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: 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); 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); } } 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) { 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"); } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 4; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } 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[1] = {0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: syscall(__NR_unshare, 0x40000000ul); break; case 1: syscall(__NR_getpid); break; case 2: res = syscall(__NR_socket, 0x10ul, 3ul, 0x14); if (res != -1) r[0] = res; break; case 3: NONFAILING(*(uint64_t*)0x20000200 = 0); NONFAILING(*(uint32_t*)0x20000208 = 0); NONFAILING(*(uint64_t*)0x20000210 = 0x20000100); NONFAILING(*(uint64_t*)0x20000100 = 0x20001740); NONFAILING(memcpy( (void*)0x20001740, "\x38\x00\x00\x00\x03\x14\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x09" "\x00\x02\x00\x73\x79\x7a\x30\x00\x00\x00\x00\x08\x00\x41\x00\x72\x78" "\x65\x00\x14\x00\x33\x00\x76\x69\x72\x74\x5f\x77\x69\x66\x69\x30\x00" "\x00\x00\x00\x00\x00\x3b\x23\x8c\x78\x53\x09\xd2\x68\xb6\x9a\xd9\x6e" "\x84\x09\x00\x00\x00\x00\x00\x00\x00\x63\x45\xef\x53\xb8\x7f\xe2\x70" "\x94\x34\x14\xa9\x1d\x5c\xc4\xb8\x33\x0f\xc8\xcd\xd3\x5f\xc9\x51\x1d" "\x41\x10\x73\x97\x58\x02\xb3\x65\xd8\x08\x71\xde\xe4\x8b\x4c\xea\x93" "\x4e\x97\x8f\x10\x81\x8e\xa2\x01\x4a\x18\xb3\x1b\x5c\xb2\xa4\x4c\x82" "\xdb\x9f\x8e\xa9\xa6\xd1\x06\xa1\xed\x19\x1e\x1c\x99\x89\xbd\x3d\xa7" "\x5a\x2c\x98\xfb\x24\xee\x46\xbd\x04\xcf\xf2\x9e\xb9\x08\xa0\xd3\x0a" "\x66\xbf\x11\x6c\xa3\x42\x15\xbb\x36\x69\xd3\x0e\x55\xc8\xaf\xf8\xbd" "\x83\x4b\x8d\x65\x40\xa4\xb9\xe8\xce\x79\xd3\xd7\x0b\x83\x8b\xe0\x93" "\x7e\xd9\x80\x28\x95\x44\x80\xc2\x05\xfe\x2b\x35\xf0\xbd\xfb\xaf\x78" "\x29\xe4\xab\x09\xa4\xe4\xef\x4d\xbc\x5c\x82\xa3\xd0\x19\xd0\xac\x8d" "\xee\xc5\x12\x4f\x4b\x1a\x0f\xbb\x7c\xf6\x41\xe2\x87\xfd\xa1\x76\x69" "\xa2\x1d\x4d\x0a\x78\x26\x07\xc3\xf2\x87\xc5\xd4\x6a\xfc\xe7\x93\xdd" "\xd6\x55\xf4\xfa\x60\x72\xef\xa0\xfa\xde\xf3\xca\xb4\x75\xd3\xe5\x1d" "\x0c\xa6\xcc\x7e\x37\x37\x38\x4f\x21\x71\x93\xb2\x63\x7d\xea\xe2\x4e" "\x5e\x74\x17\xc0\xd0\x0b\x01\x15\x22\x02\x36\xe5\xd7\xc9\x6b\x30\x27" "\x1d\x19\x5a\x37\xc1\xa3\xa1\x2e\x0e\x60\x87\x61\x65\x03\xaa\xb7\xa6" "\x6c\x13\x1e\xa8\x68\x8d\x4b\x47\xd3\xf4\xf9\xfd\x58\xee\x06\x99\x8f" "\xbf\x48\x4b\x2d\xae\x0b\x38\xf2\xe5\xb8\xed\xf9\x85\xca\xf8\xef\xa8" "\xe0\xd4\xca\x07\x91\xd0\x83\xa4\xbc\xfa\x6f\xf8\x1d\xc0\xcb\x9a\x4d" "\xc9\x66\x71\x4c\xff\x75\x85\xca\x2c\xa3\x43\x36\x68\x54\x98\xf2\x30" "\x23\x51\x35\x8e\x2a\xf5\xd4\x73\x4c\x2e\xfd\xec\x55\x1a\x2e\xdc\x18" "\x51\x11\x0e\xdf\x77\xec\xc1\x70\xe5\x85\xac\xfa\xcd\xc1\x25\xd0\x76" "\x96\x6f\x4c\x1b\xcd\x00\x4b\x24\x54\x3f\xab\x41\x91\x7b\x07\x22\x56" "\x34\x6b\x36\x20\x7c\xb9\xd3\xf0\x32\x8f\x44\xe4\xdd\x86\x84\x3f\x8c" "\x2e\x8d\xb7\x43\xde\x70\x8c\xfd\xe9\x87\xd2\xb4\x51\x7d\x9f\x46\xcb" "\x6f\x56\x46\x01\x07\x66\xd1\x97\x65\xd7\x2b\xaf\x9d\x78\xf9\xb9\xde" "\x16\x83\x07\x9a\xd4\x0a\x61\xaa\xab\xe5\xe3\x13\x5f\x64\x0c\xc0\x25" "\x38\x42\x3b\x3a\x25\x05\x83\xaf\x80\xb7\xe0\xf7\xd0\x44\x53\xcc\x25" "\x8d\x8b\x87\x1f\x64\x5c\xc8\x1d\x66\x7f\xb3\x9e\x02\x83\xfd\xe2\xee" "\x88\xd9\x74\x03\x4e\x4d\xb6\x8f\x2f\xac\x5f\xe9\x70\xb5\x7a\x7f\x2d" "\x82\xf7\x07\x65\x66\xf5\xe6\xf4\x5c\x76\x4d\xa5\xb6\x88\x63\x55\x9a" "\x02\x67\x33\xbe\x81\xc4\x66\x6e\x86\x32\x72\x50\x45\xc8\xb5\x61\xcd" "\x16\xf9\x21\x3d\x8d\x0b\xa9\x6d\x21\x6a\x50\x24\x86\x18\xd6\x93\xb5" "\xa7\x08\xaf\x82\x33\x15\xa7\xe6\x29\x4f\xbe\x53\x59\x3d\x10\xbd\xd4" "\x81\x36\xf9\x50\xe0\x6b\x98\xb7\xfe\xc9\x07\xfc\xee\x26\xc5\x1c\x6f" "\x43\xb4\xb5\x10\x5e\x38\xb1\xb7\xa7\xef\xd3\x26\x3f\x07\x45\x86\x97" "\x24\xe2\xe3\x74\xb7\xe4\xe1\x62\x12\x95\x73\x76", 692)); NONFAILING(*(uint64_t*)0x20000108 = 0x38); NONFAILING(*(uint64_t*)0x20000218 = 1); NONFAILING(*(uint64_t*)0x20000220 = 0); NONFAILING(*(uint64_t*)0x20000228 = 0); NONFAILING(*(uint32_t*)0x20000230 = 0); syscall(__NR_sendmsg, r[0], 0x20000200ul, 0ul); break; } } 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(); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { use_temporary_dir(); loop(); } } sleep(1000000); return 0; }