// https://syzkaller.appspot.com/bug?id=c4117efdec586bbccac5428cce624863690bd3b8 // 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; 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 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 long syz_open_dev(volatile long a0, volatile long a1, volatile long a2) { if (a0 == 0xc || a0 == 0xb) { char buf[128]; sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1, (uint8_t)a2); return open(buf, O_RDWR, 0); } else { char buf[1024]; char* hash; NONFAILING(strncpy(buf, (char*)a0, sizeof(buf) - 1)); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); a1 /= 10; } return open(buf, a2, 0); } } 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[5] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); setup_fault(); install_segv_handler(); intptr_t res = 0; syscall(__NR_perf_event_open, 0, 0, -1, -1, 0); res = syz_open_dev(0, 0, 0); if (res != -1) r[0] = res; syscall(__NR_sysinfo, 0); syscall(__NR_pipe2, 0, 0x4000); res = syscall(__NR_openat, 0xffffffffffffff9c, 0, 2, 0); if (res != -1) r[1] = res; syscall(__NR_write, r[1], 0, 0); syscall(__NR_ioctl, r[0], 0x1269, 0); syz_open_dev(0, 0xfffffffffffffff9, 0); res = syscall(__NR_socket, 2, 2, 0); if (res != -1) r[2] = res; syscall(__NR_setsockopt, r[2], 0, 0x12, 0, 0); syscall(__NR_sendto, r[2], 0, 0, 0, 0, 0); syscall(__NR_setsockopt, r[2], 0, 0x17, 0, 0); syscall(__NR_recvmmsg, r[2], 0, 0, 0x12001, 0); syscall(__NR_writev, r[2], 0, 0); NONFAILING(memcpy((void*)0x20000580, "/dev/infiniband/rdma_cm\000", 24)); res = syscall(__NR_openat, 0xffffffffffffff9c, 0x20000580, 2, 0); if (res != -1) r[3] = res; NONFAILING(*(uint32_t*)0x200001c0 = 0); NONFAILING(*(uint16_t*)0x200001c4 = 0x18); NONFAILING(*(uint16_t*)0x200001c6 = 0xfa00); NONFAILING(*(uint64_t*)0x200001c8 = 0); NONFAILING(*(uint64_t*)0x200001d0 = 0x20000140); NONFAILING(*(uint16_t*)0x200001d8 = 2); NONFAILING(*(uint8_t*)0x200001da = 0); NONFAILING(*(uint8_t*)0x200001db = 0); NONFAILING(*(uint8_t*)0x200001dc = 0); NONFAILING(*(uint8_t*)0x200001dd = 0); NONFAILING(*(uint8_t*)0x200001de = 0); NONFAILING(*(uint8_t*)0x200001df = 0); res = syscall(__NR_write, r[3], 0x200001c0, 0x20); if (res != -1) NONFAILING(r[4] = *(uint32_t*)0x20000140); NONFAILING(*(uint32_t*)0x20000200 = 3); NONFAILING(*(uint16_t*)0x20000204 = 0x40); NONFAILING(*(uint16_t*)0x20000206 = 0xfa00); NONFAILING(*(uint16_t*)0x20000208 = 0xa); NONFAILING(*(uint16_t*)0x2000020a = htobe16(2)); NONFAILING(*(uint32_t*)0x2000020c = htobe32(0)); NONFAILING(*(uint8_t*)0x20000210 = 0); NONFAILING(*(uint8_t*)0x20000211 = 0); NONFAILING(*(uint8_t*)0x20000212 = 0); NONFAILING(*(uint8_t*)0x20000213 = 0); NONFAILING(*(uint8_t*)0x20000214 = 0); NONFAILING(*(uint8_t*)0x20000215 = 0); NONFAILING(*(uint8_t*)0x20000216 = 0); NONFAILING(*(uint8_t*)0x20000217 = 0); NONFAILING(*(uint8_t*)0x20000218 = 0); NONFAILING(*(uint8_t*)0x20000219 = 0); NONFAILING(*(uint8_t*)0x2000021a = 0); NONFAILING(*(uint8_t*)0x2000021b = 0); NONFAILING(*(uint8_t*)0x2000021c = 0); NONFAILING(*(uint8_t*)0x2000021d = 0); NONFAILING(*(uint8_t*)0x2000021e = 0); NONFAILING(*(uint8_t*)0x2000021f = 0); NONFAILING(*(uint32_t*)0x20000220 = 0); NONFAILING(*(uint16_t*)0x20000224 = 0xa); NONFAILING(*(uint16_t*)0x20000226 = htobe16(0)); NONFAILING(*(uint32_t*)0x20000228 = htobe32(0)); NONFAILING(*(uint8_t*)0x2000022c = 0xfe); NONFAILING(*(uint8_t*)0x2000022d = 0x80); NONFAILING(*(uint8_t*)0x2000022e = 0); NONFAILING(*(uint8_t*)0x2000022f = 0); NONFAILING(*(uint8_t*)0x20000230 = 0); NONFAILING(*(uint8_t*)0x20000231 = 0); NONFAILING(*(uint8_t*)0x20000232 = 0); NONFAILING(*(uint8_t*)0x20000233 = 0); NONFAILING(*(uint8_t*)0x20000234 = 0); NONFAILING(*(uint8_t*)0x20000235 = 0); NONFAILING(*(uint8_t*)0x20000236 = 0); NONFAILING(*(uint8_t*)0x20000237 = 0); NONFAILING(*(uint8_t*)0x20000238 = 0); NONFAILING(*(uint8_t*)0x20000239 = 0); NONFAILING(*(uint8_t*)0x2000023a = 0); NONFAILING(*(uint8_t*)0x2000023b = 0xaa); NONFAILING(*(uint32_t*)0x2000023c = 0); NONFAILING(*(uint32_t*)0x20000240 = r[4]); NONFAILING(*(uint32_t*)0x20000244 = 0); inject_fault(0); syscall(__NR_write, r[3], 0x20000200, 0x48); return 0; }