// https://syzkaller.appspot.com/bug?id=a1d74e82a88d285ec1ba0999fc4b898c84f0fc92 // 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 clone_ongoing; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { if (__atomic_load_n(&clone_ongoing, __ATOMIC_RELAXED) != 0) { exit(sig); } 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); if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) exit(1); return fd; } static const char* setup_fault() { int fd = open("/proc/self/make-it-fail", O_WRONLY); if (fd == -1) return "CONFIG_FAULT_INJECTION is not enabled"; close(fd); fd = open("/proc/thread-self/fail-nth", O_WRONLY); if (fd == -1) return "kernel does not have systematic fault injection support"; close(fd); 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) return "failed to write fault injection file"; } } return NULL; } uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); const char* reason; (void)reason; if ((reason = setup_fault())) printf("the reproducer may not work as expected: fault injection setup " "failed: %s\n", reason); install_segv_handler(); intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } res = syscall(__NR_socket, /*domain=*/0x10ul, /*type=*/3ul, /*proto=*/0); if (res != -1) r[0] = res; NONFAILING(*(uint64_t*)0x20000100 = 0); NONFAILING(*(uint32_t*)0x20000108 = 0); NONFAILING(*(uint64_t*)0x20000110 = 0x200000c0); NONFAILING(*(uint64_t*)0x200000c0 = 0x20000140); NONFAILING(*(uint32_t*)0x20000140 = 0x1c); NONFAILING(*(uint16_t*)0x20000144 = 0x68); NONFAILING(*(uint16_t*)0x20000146 = 0x78e9); NONFAILING(*(uint32_t*)0x20000148 = 0); NONFAILING(*(uint32_t*)0x2000014c = 0); NONFAILING(*(uint8_t*)0x20000150 = 0xa); NONFAILING(*(uint8_t*)0x20000151 = 0); NONFAILING(*(uint8_t*)0x20000152 = 0); NONFAILING(*(uint8_t*)0x20000153 = 0); NONFAILING(*(uint32_t*)0x20000154 = 0); NONFAILING(*(uint16_t*)0x20000158 = 4); NONFAILING(*(uint16_t*)0x2000015a = 4); NONFAILING(*(uint64_t*)0x200000c8 = 0x1c); NONFAILING(*(uint64_t*)0x20000118 = 1); NONFAILING(*(uint64_t*)0x20000120 = 0); NONFAILING(*(uint64_t*)0x20000128 = 0); NONFAILING(*(uint32_t*)0x20000130 = 0); syscall(__NR_sendmsg, /*fd=*/r[0], /*msg=*/0x20000100ul, /*f=*/0ul); res = syscall(__NR_socket, /*domain=*/0x10ul, /*type=*/3ul, /*proto=*/0); if (res != -1) r[1] = res; NONFAILING(*(uint64_t*)0x20000000 = 0); NONFAILING(*(uint32_t*)0x20000008 = 0); NONFAILING(*(uint64_t*)0x20000010 = 0x200001c0); NONFAILING(*(uint64_t*)0x200001c0 = 0x20000300); NONFAILING(*(uint32_t*)0x20000300 = 0x24); NONFAILING(*(uint16_t*)0x20000304 = 0x68); NONFAILING(*(uint16_t*)0x20000306 = 1); NONFAILING(*(uint32_t*)0x20000308 = 2); NONFAILING(*(uint32_t*)0x2000030c = 0x7ffffffc); NONFAILING(*(uint8_t*)0x20000310 = 0); NONFAILING(*(uint8_t*)0x20000311 = 0); NONFAILING(*(uint8_t*)0x20000312 = 0); NONFAILING(*(uint8_t*)0x20000313 = 0); NONFAILING(*(uint32_t*)0x20000314 = 0); NONFAILING(*(uint16_t*)0x20000318 = 0xc); NONFAILING(*(uint16_t*)0x2000031a = 2); NONFAILING(*(uint32_t*)0x2000031c = 1); NONFAILING(*(uint8_t*)0x20000320 = 4); NONFAILING(*(uint8_t*)0x20000321 = 0); NONFAILING(*(uint16_t*)0x20000322 = 0); NONFAILING(*(uint64_t*)0x200001c8 = 0x24); NONFAILING(*(uint64_t*)0x20000018 = 1); NONFAILING(*(uint64_t*)0x20000020 = 0); NONFAILING(*(uint64_t*)0x20000028 = 0); NONFAILING(*(uint32_t*)0x20000030 = 0x24008000); inject_fault(5); syscall(__NR_sendmsg, /*fd=*/r[1], /*msg=*/0x20000000ul, /*f=MSG_NOSIGNAL*/ 0x4000ul); return 0; }