// https://syzkaller.appspot.com/bug?id=f1834e1735946170a8a3a4c85edb978e94bada81 // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #include #include #include #include #include #include #include #include #include #include const int kFailStatus = 67; const int kRetryStatus = 69; static void fail(const char* msg, ...) { int e = errno; va_list args; va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); fprintf(stderr, " (errno %d)\n", e); doexit((e == ENOMEM || e == EAGAIN) ? kRetryStatus : kFailStatus); } static void exitf(const char* msg, ...) { int e = errno; va_list args; va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); fprintf(stderr, " (errno %d)\n", e); doexit(kRetryStatus); } static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* uctx) { 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); } doexit(sig); for (;;) { } } static void install_segv_handler() { 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 uint64_t current_time_ms() { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) fail("clock_gettime failed"); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir() { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) fail("failed to mkdtemp"); if (chmod(tmpdir, 0777)) fail("failed to chmod"); if (chdir(tmpdir)) fail("failed to chdir"); } 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) { exitf("opendir(%s) failed due to NOFILE, exiting"); } exitf("opendir(%s) failed", dir); } 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)) exitf("lstat(%s) failed", filename); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } int i; for (i = 0;; i++) { if (unlink(filename) == 0) break; if (errno == EROFS) { break; } if (errno != EBUSY || i > 100) exitf("unlink(%s) failed", filename); if (umount2(filename, MNT_DETACH)) exitf("umount(%s) failed", filename); } } closedir(dp); int i; for (i = 0;; i++) { if (rmdir(dir) == 0) break; if (i < 100) { if (errno == EROFS) { break; } if (errno == EBUSY) { if (umount2(dir, MNT_DETACH)) exitf("umount(%s) failed", dir); continue; } if (errno == ENOTEMPTY) { if (iter < 100) { iter++; goto retry; } } } exitf("rmdir(%s) failed", dir); } } static void test(); void loop() { int iter; for (iter = 0;; iter++) { char cwdbuf[256]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) fail("failed to mkdir"); int pid = fork(); if (pid < 0) fail("clone failed"); if (pid == 0) { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); if (chdir(cwdbuf)) fail("failed to chdir"); test(); doexit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { int res = waitpid(-1, &status, __WALL | WNOHANG); if (res == pid) break; usleep(1000); if (current_time_ms() - start > 5 * 1000) { kill(-pid, SIGKILL); kill(pid, SIGKILL); while (waitpid(-1, &status, __WALL) != pid) { } break; } } remove_dir(cwdbuf); } } long r[84]; void* thr(void* arg) { switch ((long)arg) { case 0: r[0] = syscall(__NR_mmap, 0x20000000ul, 0xfff000ul, 0x3ul, 0x32ul, 0xfffffffffffffffful, 0x0ul); break; case 1: r[1] = syscall(__NR_socket, 0x26ul, 0x5ul, 0x0ul); break; case 2: NONFAILING(*(uint16_t*)0x20e1e000 = (uint16_t)0x26); NONFAILING(memcpy( (void*)0x20e1e002, "\x68\x61\x73\x68\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 14)); NONFAILING(*(uint32_t*)0x20e1e010 = (uint32_t)0x0); NONFAILING(*(uint32_t*)0x20e1e014 = (uint32_t)0x0); NONFAILING(memcpy((void*)0x20e1e018, "\x63\x72\x63\x33\x32\x63\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00", 64)); r[7] = syscall(__NR_bind, r[1], 0x20e1e000ul, 0x58ul); break; case 3: NONFAILING(*(uint16_t*)0x20f3b000 = (uint16_t)0x26); NONFAILING(memcpy( (void*)0x20f3b002, "\x61\x65\x61\x64\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 14)); NONFAILING(*(uint32_t*)0x20f3b010 = (uint32_t)0x0); NONFAILING(*(uint32_t*)0x20f3b014 = (uint32_t)0x0); NONFAILING(memcpy((void*)0x20f3b018, "\x72\x66\x63\x34\x31\x30\x36\x28\x67\x63\x6d\x28" "\x61\x65\x73\x29\x29\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00", 64)); r[13] = syscall(__NR_bind, r[1], 0x20f3b000ul, 0x58ul); break; case 4: r[14] = syscall(__NR_setsockopt, r[1], 0x117ul, 0x5ul, 0x0ul, 0x789ul); break; case 5: NONFAILING(*(uint16_t*)0x20333fa8 = (uint16_t)0x26); NONFAILING(memcpy( (void*)0x20333faa, "\x72\x6e\x67\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 14)); NONFAILING(*(uint32_t*)0x20333fb8 = (uint32_t)0x0); NONFAILING(*(uint32_t*)0x20333fbc = (uint32_t)0xfffffffffffffffc); NONFAILING(memcpy((void*)0x20333fc0, "\x64\x72\x62\x67\x5f\x6e\x6f\x70\x72\x5f\x63\x74" "\x72\x5f\x61\x65\x73\x31\x32\x38\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00", 64)); r[20] = syscall(__NR_bind, r[1], 0x20333fa8ul, 0x10000004eul); break; case 6: NONFAILING(memcpy((void*)0x20890fec, "\x79\x73\x39\x76\xd8\xc3\x0a" "\x4a\xea\xd9\x60\xf2\xbd\x08" "\xcf\xe6\x27\x85\xce\x10", 20)); r[22] = syscall(__NR_setsockopt, r[1], 0x117ul, 0x1ul, 0x20890fecul, 0x14ul); break; case 7: NONFAILING(*(uint16_t*)0x20a65000 = (uint16_t)0x26); NONFAILING(memcpy( (void*)0x20a65002, "\x61\x65\x61\x64\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 14)); NONFAILING(*(uint32_t*)0x20a65010 = (uint32_t)0x0); NONFAILING(*(uint32_t*)0x20a65014 = (uint32_t)0x0); NONFAILING(memcpy((void*)0x20a65018, "\x67\x63\x6d\x28\x73\x65\x72\x70\x65\x6e\x74\x29" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00", 64)); r[28] = syscall(__NR_bind, 0xfffffffffffffffful, 0x20a65000ul, 0x58ul); break; case 8: r[29] = syscall(__NR_accept, r[1], 0x0ul, 0x0ul); break; case 9: NONFAILING(*(uint64_t*)0x202fefc8 = (uint64_t)0x0); NONFAILING(*(uint32_t*)0x202fefd0 = (uint32_t)0x0); NONFAILING(*(uint64_t*)0x202fefd8 = (uint64_t)0x20985000); NONFAILING(*(uint64_t*)0x202fefe0 = (uint64_t)0x1); NONFAILING(*(uint64_t*)0x202fefe8 = (uint64_t)0x20632f70); NONFAILING(*(uint64_t*)0x202feff0 = (uint64_t)0x78); NONFAILING(*(uint32_t*)0x202feff8 = (uint32_t)0x1); NONFAILING(*(uint64_t*)0x20985000 = (uint64_t)0x206fdf9d); NONFAILING(*(uint64_t*)0x20985008 = (uint64_t)0xe); NONFAILING(memcpy( (void*)0x206fdf9d, "\x95\x76\xfb\x56\x78\xf4\xd8\xbb\x1b\x8c\x63\xa2\x29\xd9", 14)); NONFAILING(*(uint64_t*)0x20632f70 = (uint64_t)0x18); NONFAILING(*(uint32_t*)0x20632f78 = (uint32_t)0x117); NONFAILING(*(uint32_t*)0x20632f7c = (uint32_t)0x3); NONFAILING(*(uint32_t*)0x20632f80 = (uint32_t)0x0); NONFAILING(*(uint64_t*)0x20632f88 = (uint64_t)0x18); NONFAILING(*(uint32_t*)0x20632f90 = (uint32_t)0x117); NONFAILING(*(uint32_t*)0x20632f94 = (uint32_t)0x3); NONFAILING(*(uint32_t*)0x20632f98 = (uint32_t)0x0); NONFAILING(*(uint64_t*)0x20632fa0 = (uint64_t)0x18); NONFAILING(*(uint32_t*)0x20632fa8 = (uint32_t)0x117); NONFAILING(*(uint32_t*)0x20632fac = (uint32_t)0x3); NONFAILING(*(uint32_t*)0x20632fb0 = (uint32_t)0x1); NONFAILING(*(uint64_t*)0x20632fb8 = (uint64_t)0x18); NONFAILING(*(uint32_t*)0x20632fc0 = (uint32_t)0x117); NONFAILING(*(uint32_t*)0x20632fc4 = (uint32_t)0x4); NONFAILING(*(uint32_t*)0x20632fc8 = (uint32_t)0x100000000); NONFAILING(*(uint64_t*)0x20632fd0 = (uint64_t)0x18); NONFAILING(*(uint32_t*)0x20632fd8 = (uint32_t)0x117); NONFAILING(*(uint32_t*)0x20632fdc = (uint32_t)0x4); NONFAILING(*(uint32_t*)0x20632fe0 = (uint32_t)0x3); r[60] = syscall(__NR_sendmsg, r[29], 0x202fefc8ul, 0x1ul); break; case 10: NONFAILING(*(uint64_t*)0x2094ffc8 = (uint64_t)0x20967000); NONFAILING(*(uint32_t*)0x2094ffd0 = (uint32_t)0x27); NONFAILING(*(uint64_t*)0x2094ffd8 = (uint64_t)0x20203000); NONFAILING(*(uint64_t*)0x2094ffe0 = (uint64_t)0x7); NONFAILING(*(uint64_t*)0x2094ffe8 = (uint64_t)0x207dafc6); NONFAILING(*(uint64_t*)0x2094fff0 = (uint64_t)0x0); NONFAILING(*(uint32_t*)0x2094fff8 = (uint32_t)0x8); NONFAILING(*(uint64_t*)0x20203000 = (uint64_t)0x20aa0f41); NONFAILING(*(uint64_t*)0x20203008 = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x20203010 = (uint64_t)0x20732000); NONFAILING(*(uint64_t*)0x20203018 = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x20203020 = (uint64_t)0x204c2f17); NONFAILING(*(uint64_t*)0x20203028 = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x20203030 = (uint64_t)0x205af000); NONFAILING(*(uint64_t*)0x20203038 = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x20203040 = (uint64_t)0x203d8000); NONFAILING(*(uint64_t*)0x20203048 = (uint64_t)0xf7); NONFAILING(*(uint64_t*)0x20203050 = (uint64_t)0x20823f4a); NONFAILING(*(uint64_t*)0x20203058 = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x20203060 = (uint64_t)0x20fa1000); NONFAILING(*(uint64_t*)0x20203068 = (uint64_t)0x0); r[82] = syscall(__NR_recvmsg, r[29], 0x2094ffc8ul, 0x3ul); break; case 11: r[83] = syscall(__NR_accept, r[1], 0x0ul, 0x0ul); break; } return 0; } void test() { long i; pthread_t th[24]; memset(r, -1, sizeof(r)); for (i = 0; i < 12; i++) { pthread_create(&th[i], 0, thr, (void*)i); usleep(rand() % 10000); } usleep(rand() % 100000); } int main() { int i; for (i = 0; i < 8; i++) { if (fork() == 0) { install_segv_handler(); use_temporary_dir(); loop(); return 0; } } sleep(1000000); return 0; }