// https://syzkaller.appspot.com/bug?id=66d47f23f24ecf5536fd47d81defdb917c307bd2 // 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 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 (sig == SIGBUS) { valid = 1; } 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_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 kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } 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 __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } 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); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void execute_one(void); #define WAIT_FLAGS 0 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); 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[1] = {0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; res = syscall(SYS_socket, 0x1cul, 1ul, 0x84); if (res != -1) r[0] = res; NONFAILING(*(uint8_t*)0x20000000 = 0x1c); NONFAILING(*(uint8_t*)0x20000001 = 0x1c); NONFAILING(*(uint16_t*)0x20000002 = htobe16(0x4e22)); NONFAILING(*(uint32_t*)0x20000004 = 0x20); NONFAILING(memset((void*)0x20000008, 0, 16)); NONFAILING(*(uint32_t*)0x20000018 = 0x20); syscall(SYS_bind, r[0], 0x20000000ul, 0x1cul); NONFAILING(*(uint8_t*)0x20000180 = 0x1c); NONFAILING(*(uint8_t*)0x20000181 = 0x1c); NONFAILING(*(uint16_t*)0x20000182 = htobe16(0x4e22)); NONFAILING(*(uint32_t*)0x20000184 = 4); NONFAILING(*(uint64_t*)0x20000188 = htobe64(0)); NONFAILING(*(uint64_t*)0x20000190 = htobe64(1)); NONFAILING(*(uint32_t*)0x20000198 = 4); syscall(SYS_connect, r[0], 0x20000180ul, 0x1cul); NONFAILING(memcpy( (void*)0x20000480, "\xa3\x1b\xe1\x78\x8e\x58\x9b\x38\x59\xf3\xbb\xdd\x7e\xf7\x51\x23\x97\x31" "\xb2\x90\x4a\xd0\x4e\xb7\xdc\x37\xc6\x95\xf6\x05\x5c\xa8\x36\x54\x7e\x7b" "\x6c\xc3\x7d\xae\x2a\xe4\x77\x08\x94\x67\x3c\x89\x65\x93\x24\x1c\x56\x3e" "\x08\x69\x05\x35\xeb\x3b\x7f\x19\x7d\xda\x44\x54\xb4\x42\x4f\x34\xc8\x81" "\x69\x4e\xac\xef\xa6\xd4\xb1\x61\x9d\xf1\x0b\x97\x7c\xd9\x82\x16\xc9\x7b" "\x2e\xb3\x9f\x02\xde\x0f\xae\xe7\x0b\xec\xa3\x66\x3c\x2e\x6c\xd1\xca\x02" "\xae\x0f\xd5\x65\xb9\x7c\x5c\xa0\xea\xfc\xa4\xc9\x13\x73\x14\x16\xba\xcc" "\xae\x89\xe2\x68\x77\xfc\x2a\x8c\xa3\xee\xa8\x45\xf7\xc2\xcb\x48\x93\xe5" "\x83\x52\x45\x26\xe3\xeb\x73\xa2\xe4\xf1\x11\xcf\x40\x5f\xef\x99\xc2\xa1" "\xeb\x2c\x96\x70\x56\x88\xc8\xc7\x6b\xa1\x66\xd2\x23\x20\x07\x62\x69\xd2" "\x1c\x52\xbb\x5e\x86\x43\x7d\x6c\x65\x44\x42\xf6\xd8\x45\xe2\xff\x77\xf9" "\x24\xf0\x1d\x29\xf6\xd3\x74\x83\x25\x40\x56\x50\x17\x7f\xc3\x60\xd7\xed" "\xb1\xfb\x7a\x74\x38\x2b\x47\x34\x93\x9c\xee\xc9\xb0\xbf\x7d\xc4\x19\xe2" "\x77\x49\xbc\x71\x9c\x30\x8b\x57\x0f\x13\x4d\x93\x9d\x53\xa8\x03\xc1\x3b" "\x5d\xc3\xbc\x20\xc4\x9e\xc1\x62\x69\xca\x92\x0f\x04\xa1\x0b\xea\xe7\x61" "\x79\x99\x5a\x53\x1a\x27\x40\xf0\x0b\xc5\xe8\xb5\xf0\xd8\x1c\xd2\xca\x99" "\x16\x70\xa8\xc5\xac\x0a\x6b\x99\x31\x0c\x90\xe2\xa5\xe0\xe3\x7c\x99\x3c" "\xbd\xeb\x42\xcf\x74\xe0\xa8\xea\x4e\x64\xd8\x30\x46\x6d\x6e\x83\x7f\x21" "\x00\x5c\xcf\x79\xfe\x19\xdd\xd5\xaf\x69\x9e\x1b\x67\xd5\x3f\x18\x4d\xe5" "\x2a\xec\x02\x12\x92", 347)); syscall(SYS_sendto, r[0], 0x20000480ul, 0x15bul, 0x20108ul, 0ul, 0ul); syscall(SYS_listen, r[0], 0x1f); } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x1012ul, -1, 0ul); install_segv_handler(); use_temporary_dir(); loop(); return 0; }