// https://syzkaller.appspot.com/bug?id=b23d95999136f86da560efe4adcfef2381a3b584 // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #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 __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 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 uintptr_t syz_open_procfs(uintptr_t a0, uintptr_t a1) { char buf[128]; memset(buf, 0, sizeof(buf)); if (a0 == 0) { NONFAILING(snprintf(buf, sizeof(buf), "/proc/self/%s", (char*)a1)); } else if (a0 == (uintptr_t)-1) { NONFAILING( snprintf(buf, sizeof(buf), "/proc/thread-self/%s", (char*)a1)); } else { NONFAILING(snprintf(buf, sizeof(buf), "/proc/self/task/%d/%s", (int)a0, (char*)a1)); } int fd = open(buf, O_RDWR); if (fd == -1) fd = open(buf, O_RDONLY); return fd; } long r[46]; 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, 0xaul, 0x1ul, 0x0ul); break; case 2: NONFAILING(*(uint16_t*)0x20191fa4 = (uint16_t)0xa); NONFAILING(*(uint16_t*)0x20191fa6 = (uint16_t)0x214e); NONFAILING(*(uint32_t*)0x20191fa8 = (uint32_t)0x7fff); NONFAILING(*(uint64_t*)0x20191fac = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x20191fb4 = (uint64_t)0x100000000000000); NONFAILING(*(uint32_t*)0x20191fbc = (uint32_t)0x7); NONFAILING(*(uint16_t*)0x20191fc0 = (uint16_t)0xa); NONFAILING(*(uint16_t*)0x20191fc2 = (uint16_t)0x234e); NONFAILING(*(uint32_t*)0x20191fc4 = (uint32_t)0x80); NONFAILING(*(uint8_t*)0x20191fc8 = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fc9 = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fca = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fcb = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fcc = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fcd = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fce = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fcf = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fd0 = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fd1 = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fd2 = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fd3 = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fd4 = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fd5 = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fd6 = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20191fd7 = (uint8_t)0x0); NONFAILING(*(uint32_t*)0x20191fd8 = (uint32_t)0xfffffffffffff5ff); NONFAILING(*(uint16_t*)0x20191fdc = (uint16_t)0x1); NONFAILING(*(uint32_t*)0x20191fe0 = (uint32_t)0x3ff); NONFAILING(*(uint32_t*)0x20191fe4 = (uint32_t)0x0); NONFAILING(*(uint32_t*)0x20191fe8 = (uint32_t)0x3); NONFAILING(*(uint32_t*)0x20191fec = (uint32_t)0x1fffe00); NONFAILING(*(uint32_t*)0x20191ff0 = (uint32_t)0x64); NONFAILING(*(uint32_t*)0x20191ff4 = (uint32_t)0x4); NONFAILING(*(uint32_t*)0x20191ff8 = (uint32_t)0x9); NONFAILING(*(uint32_t*)0x20191ffc = (uint32_t)0x101); r[37] = syscall(__NR_setsockopt, r[1], 0x29ul, 0xd2ul, 0x20191fa4ul, 0x5cul); break; case 3: NONFAILING(memcpy((void*)0x20bb8000, "\x6e\x65\x74\x2f\x69\x70\x36" "\x5f\x6d\x72\x5f\x63\x61\x63" "\x68\x65\x00", 17)); r[39] = syz_open_procfs(0x0ul, 0x20bb8000ul); break; case 4: r[40] = syscall(__NR_pread64, r[39], 0x20caef7bul, 0x0ul, 0x4cul); break; case 5: NONFAILING(*(uint64_t*)0x20917fb0 = (uint64_t)0x20131f47); NONFAILING(*(uint64_t*)0x20917fb8 = (uint64_t)0x6); NONFAILING(*(uint64_t*)0x20917fc0 = (uint64_t)0x20a87f2b); NONFAILING(*(uint64_t*)0x20917fc8 = (uint64_t)0x62); r[45] = syscall(__NR_readv, r[39], 0x20917fb0ul, 0x2ul); break; } return 0; } void loop() { long i; pthread_t th[12]; memset(r, -1, sizeof(r)); srand(getpid()); for (i = 0; i < 6; i++) { pthread_create(&th[i], 0, thr, (void*)i); usleep(rand() % 10000); } for (i = 0; i < 6; i++) { pthread_create(&th[6 + i], 0, thr, (void*)i); if (rand() % 2) usleep(rand() % 10000); } usleep(rand() % 100000); } int main() { install_segv_handler(); use_temporary_dir(); loop(); return 0; }