// https://syzkaller.appspot.com/bug?id=d4aa3b37520a28ee882cb07bf3a22e59389f4e97 // 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 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 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; } static int inject_fault(int nth) { int fd; fd = open("/proc/thread-self/fail-nth", O_RDWR); if (fd == -1) exit(1); char buf[16]; sprintf(buf, "%d", nth + 1); if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) exit(1); return fd; } static void setup_fault() { static struct { const char* file; const char* val; bool fatal; } files[] = { {"/sys/kernel/debug/failslab/ignore-gfp-wait", "N", true}, {"/sys/kernel/debug/fail_futex/ignore-private", "N", false}, {"/sys/kernel/debug/fail_page_alloc/ignore-gfp-highmem", "N", false}, {"/sys/kernel/debug/fail_page_alloc/ignore-gfp-wait", "N", false}, {"/sys/kernel/debug/fail_page_alloc/min-order", "0", false}, }; unsigned i; for (i = 0; i < sizeof(files) / sizeof(files[0]); i++) { if (!write_file(files[i].file, files[i].val)) { if (files[i].fatal) exit(1); } } } uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; 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); setup_fault(); install_segv_handler(); intptr_t res = 0; res = syscall(__NR_socket, 0xaul, 1ul, 0); if (res != -1) r[0] = res; NONFAILING(*(uint32_t*)0x200000c0 = 1); syscall(__NR_setsockopt, r[0], 6, 0x13, 0x200000c0ul, 0x1d4ul); NONFAILING(*(uint16_t*)0x20000080 = 0xa); NONFAILING(*(uint16_t*)0x20000082 = htobe16(0)); NONFAILING(*(uint32_t*)0x20000084 = htobe32(0)); NONFAILING(memcpy( (void*)0x20000088, "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 16)); NONFAILING(*(uint32_t*)0x20000098 = 0); syscall(__NR_connect, r[0], 0x20000080ul, 0x1cul); NONFAILING(memcpy((void*)0x200001c0, "tls\000", 4)); syscall(__NR_setsockopt, r[0], 6, 0x1f, 0x200001c0ul, 4ul); syscall(__NR_shutdown, r[0], 1ul); NONFAILING(*(uint16_t*)0x20000040 = 0x303); NONFAILING(*(uint16_t*)0x20000042 = 0x33); NONFAILING(memcpy((void*)0x20000044, "\x44\xcd\x83\x8e\x7e\xb1\x03\x58", 8)); NONFAILING(memcpy( (void*)0x2000004c, "\xab\x5c\x29\x19\xe9\x9c\x1f\x8b\x1e\x48\xbc\x3e\x4f\xb1\x34\xb6", 16)); NONFAILING(memcpy((void*)0x2000005c, "\xd3\x10\x62\x4b", 4)); NONFAILING(memcpy((void*)0x20000060, "\x64\x44\xef\x86\x78\x48\x2c\xaf", 8)); syscall(__NR_setsockopt, r[0], 0x11a, 1, 0x20000040ul, 0x28ul); NONFAILING(memcpy((void*)0x200005c0, "/proc/self/exe\000", 15)); res = syscall(__NR_openat, 0xffffff9c, 0x200005c0ul, 0ul, 0ul); if (res != -1) r[1] = res; syscall(__NR_mmap, 0x20000000ul, 0x800000ul, 0x2800004ul, 0x12ul, r[1], 0ul); NONFAILING(memcpy((void*)0x20000180, "Y", 1)); inject_fault(3); syscall(__NR_sendto, r[0], 0x20000180ul, 1ul, 0x4000ul, 0ul, 0ul); return 0; }