// https://syzkaller.appspot.com/bug?id=27d313ef3e5b11d1d75cb07a6e79d8fe76904e89 // 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 #ifndef __NR_bpf #define __NR_bpf 321 #endif 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 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 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; } static void setup_sysctl() { int cad_pid = fork(); if (cad_pid < 0) exit(1); if (cad_pid == 0) { for (;;) sleep(100); } char tmppid[32]; snprintf(tmppid, sizeof(tmppid), "%d", cad_pid); struct { const char* name; const char* data; } files[] = { {"/sys/kernel/debug/x86/nmi_longest_ns", "10000000000"}, {"/proc/sys/kernel/hung_task_check_interval_secs", "20"}, {"/proc/sys/net/core/bpf_jit_kallsyms", "1"}, {"/proc/sys/net/core/bpf_jit_harden", "0"}, {"/proc/sys/kernel/kptr_restrict", "0"}, {"/proc/sys/kernel/softlockup_all_cpu_backtrace", "1"}, {"/proc/sys/fs/mount-max", "100"}, {"/proc/sys/vm/oom_dump_tasks", "0"}, {"/proc/sys/debug/exception-trace", "0"}, {"/proc/sys/kernel/printk", "7 4 1 3"}, {"/proc/sys/kernel/keys/gc_delay", "1"}, {"/proc/sys/vm/oom_kill_allocating_task", "1"}, {"/proc/sys/kernel/ctrl-alt-del", "0"}, {"/proc/sys/kernel/cad_pid", tmppid}, }; for (size_t i = 0; i < sizeof(files) / sizeof(files[0]); i++) { if (!write_file(files[i].name, files[i].data)) { } } kill(cad_pid, SIGKILL); while (waitpid(cad_pid, NULL, 0) != cad_pid) ; } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; int main(void) { syscall(__NR_mmap, /*addr=*/0x3ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x400000000000ul, /*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=*/0x400001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); setup_sysctl(); 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(); use_temporary_dir(); intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } NONFAILING(*(uint32_t*)0x40000000e000 = 0x10); NONFAILING(*(uint32_t*)0x40000000e004 = 4); NONFAILING(*(uint64_t*)0x40000000e008 = 0x400000000040); NONFAILING(memcpy((void*)0x400000000040, "\xb4\x00\x00\x00\x00\x00\x00\x00\x79\x10\x48\x00\x00\x00" "\x00\x00\x61\x04\x00\x00\x00\x00\x00\x00\x95\x00\x00\x00", 28)); NONFAILING(*(uint64_t*)0x40000000e010 = 0x400000003ff6); NONFAILING(memcpy((void*)0x400000003ff6, "GPL\000", 4)); NONFAILING(*(uint32_t*)0x40000000e018 = 2); NONFAILING(*(uint32_t*)0x40000000e01c = 0xfd90); NONFAILING(*(uint64_t*)0x40000000e020 = 0x40000000cf3d); NONFAILING(*(uint32_t*)0x40000000e028 = 0); NONFAILING(*(uint32_t*)0x40000000e02c = 0); NONFAILING(memset((void*)0x40000000e030, 0, 16)); NONFAILING(*(uint32_t*)0x40000000e040 = 0); NONFAILING(*(uint32_t*)0x40000000e044 = 0); NONFAILING(*(uint32_t*)0x40000000e048 = -1); NONFAILING(*(uint32_t*)0x40000000e04c = 8); NONFAILING(*(uint64_t*)0x40000000e050 = 0); NONFAILING(*(uint32_t*)0x40000000e058 = 0); NONFAILING(*(uint32_t*)0x40000000e05c = 0x10); NONFAILING(*(uint64_t*)0x40000000e060 = 0); NONFAILING(*(uint32_t*)0x40000000e068 = 0); NONFAILING(*(uint32_t*)0x40000000e06c = 0); NONFAILING(*(uint32_t*)0x40000000e070 = -1); NONFAILING(*(uint32_t*)0x40000000e074 = 0); NONFAILING(*(uint64_t*)0x40000000e078 = 0); NONFAILING(*(uint64_t*)0x40000000e080 = 0); NONFAILING(*(uint32_t*)0x40000000e088 = 0x10); NONFAILING(*(uint32_t*)0x40000000e08c = 0); NONFAILING(*(uint32_t*)0x40000000e090 = 0); res = syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x40000000e000ul, /*size=*/0x48ul); if (res != -1) r[0] = res; syscall(__NR_close, /*fd=*/r[0]); res = syscall(__NR_socketpair, /*domain=*/1ul, /*type=SOCK_DGRAM*/ 2ul, /*proto=*/0, /*fds=*/0x400000000140ul); if (res != -1) NONFAILING(r[1] = *(uint32_t*)0x400000000144); NONFAILING(*(uint32_t*)0x40000000e000 = 0xe); NONFAILING(*(uint32_t*)0x40000000e004 = 4); NONFAILING(*(uint64_t*)0x40000000e008 = 0x400000000540); NONFAILING(memcpy( (void*)0x400000000540, "\xb4\x05\x00\x00\xfd\xff\x7f\x00\x61\x10\x58\x00\x00\x00\x00\x00\xc6\x00" "\x00\x00\x00\x00\x00\x00\x95\x00\x00\x00\x00\x00\x00\x00\x9f\x33\xef\x60" "\x91\x6e\x6e\x71\x3f\x1e\xeb\x0b\x72\x5a\xd9\x9b\x81\x7f\xd9\x8c\xd8\x24" "\x49\x89\x49\x71\x4f\xfa\xac\x8a\x6f\x77\x06\x00\xdc\xca\x55\xf2\x1f\x3c" "\xa9\xe8\x22\xd1\x82\x05\x4d\x54\xd5\x3c\xd2\xb6\xdb\x71\x4e\x4b\xeb\x54" "\x47\x00\x00\x01\x00\x00\x00\x00\x8f\x2b\x90\x00\xf2\x24\x25\xe4\x09\x7e" "\xd6\x2c\xbc\x89\x10\x61\x01\x7c\xfa\x6f\xa2\x6f\xa7\x08\x8c\x60\x89\x7d" "\x4a\x61\x48\xa1\xc1\xe4\x3f\x00\x00\x1b\xde\x60\xbe\xac\x67\x1e\x8e\x8f" "\xde\xcb\x03\x58\x8a\xa6\x23\xfa\x71\xf3\x1b\xf0\xf8\x71\xab\x5c\x2f\xf8" "\x8a\xfc\x60\x02\x7f\x4e\x5b\x52\x71\xed\x58\xe8\x35\xcf\x0d\x00\x00\x00" "\x00\x98\xb5\x1f\xe6\xb1\xb8\xd9\xdb\xe8\x7d\xcf\xf4\x14\xed\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\xb3\x47\xab\xe6\x35\x2a\x08\x0f\x81\x40\xe5\xfd" "\x10\x74\x7b\x6e\xcd\xb3\x54\x05\x46\xbf\x63\x6e\x3d\x6e\x70\x0e\x5b\x05" "\x00\x00\x00\x00\x00\x00\x00\xeb\x9e\x14\x03\xe6\xc8\xf7\xa1\x87\xea\xf6" "\x0f\x3a\x17\xf0\xf0\x46\xa3\x07\xa4\x03\xc1\x9d\x98\x29\xc9\x0b\xd2\x11" "\x42\x52\x58\x15\x67\xac\xae\x71\x5c\xbe\x1b\x57\xd5\xcd\xa4\x32\xc5\xb9" "\x10\x40\x06\x23\xd2\x41\x95\x40\x5f\x2e\x76\xcc\xb7\xb3\x7b\x41\x21\x5c" "\x18\x4e\x73\x1f\xb1", 329)); NONFAILING(*(uint64_t*)0x40000000e010 = 0x400000003ff6); NONFAILING(memcpy((void*)0x400000003ff6, "GPL\000", 4)); NONFAILING(*(uint32_t*)0x40000000e018 = 4); NONFAILING(*(uint32_t*)0x40000000e01c = 0xfd90); NONFAILING(*(uint64_t*)0x40000000e020 = 0x40000000cf3d); NONFAILING(*(uint32_t*)0x40000000e028 = 0); NONFAILING(*(uint32_t*)0x40000000e02c = 0); NONFAILING(memset((void*)0x40000000e030, 0, 16)); NONFAILING(*(uint32_t*)0x40000000e040 = 0); NONFAILING(*(uint32_t*)0x40000000e044 = 0); NONFAILING(*(uint32_t*)0x40000000e048 = -1); NONFAILING(*(uint32_t*)0x40000000e04c = 8); NONFAILING(*(uint64_t*)0x40000000e050 = 0x400000000000); NONFAILING(*(uint32_t*)0x400000000000 = 0); NONFAILING(*(uint32_t*)0x400000000004 = 0); NONFAILING(*(uint32_t*)0x40000000e058 = 0x366); NONFAILING(*(uint32_t*)0x40000000e05c = 0x10); NONFAILING(*(uint64_t*)0x40000000e060 = 0x400000000000); NONFAILING(*(uint32_t*)0x400000000000 = 0); NONFAILING(*(uint32_t*)0x400000000004 = 0); NONFAILING(*(uint32_t*)0x400000000008 = 0); NONFAILING(*(uint32_t*)0x40000000000c = 0); NONFAILING(*(uint32_t*)0x40000000e068 = 0x1dd); NONFAILING(*(uint32_t*)0x40000000e06c = 0); NONFAILING(*(uint32_t*)0x40000000e070 = -1); NONFAILING(*(uint32_t*)0x40000000e074 = 0); NONFAILING(*(uint64_t*)0x40000000e078 = 0); NONFAILING(*(uint64_t*)0x40000000e080 = 0); NONFAILING(*(uint32_t*)0x40000000e088 = 0x10); NONFAILING(*(uint32_t*)0x40000000e08c = 0); NONFAILING(*(uint32_t*)0x40000000e090 = 0); res = syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x40000000e000ul, /*size=*/0x48ul); if (res != -1) r[2] = res; NONFAILING(*(uint32_t*)0x400000000200 = 0xf); NONFAILING(*(uint32_t*)0x400000000204 = 4); NONFAILING(*(uint32_t*)0x400000000208 = 4); NONFAILING(*(uint32_t*)0x40000000020c = 0x12); NONFAILING(*(uint32_t*)0x400000000210 = 0); NONFAILING(*(uint32_t*)0x400000000214 = -1); NONFAILING(*(uint32_t*)0x400000000218 = 0); NONFAILING(memset((void*)0x40000000021c, 0, 16)); NONFAILING(*(uint32_t*)0x40000000022c = 0); NONFAILING(*(uint32_t*)0x400000000230 = -1); NONFAILING(*(uint32_t*)0x400000000234 = 0); NONFAILING(*(uint32_t*)0x400000000238 = 0); NONFAILING(*(uint32_t*)0x40000000023c = 0); NONFAILING(*(uint64_t*)0x400000000240 = 0); NONFAILING(*(uint32_t*)0x400000000248 = 0); NONFAILING(*(uint32_t*)0x40000000024c = 0); res = syscall(__NR_bpf, /*cmd=*/0ul, /*arg=*/0x400000000200ul, /*size=*/0x48ul); if (res != -1) r[3] = res; NONFAILING(*(uint32_t*)0x400000000080 = r[3]); NONFAILING(*(uint32_t*)0x400000000084 = r[2]); NONFAILING(*(uint32_t*)0x400000000088 = 0x26); NONFAILING(*(uint32_t*)0x40000000008c = 0); NONFAILING(*(uint32_t*)0x400000000090 = 0); NONFAILING(*(uint32_t*)0x400000000094 = -1); NONFAILING(*(uint64_t*)0x400000000098 = 0); syscall(__NR_bpf, /*cmd=*/8ul, /*arg=*/0x400000000080ul, /*size=*/0x10ul); NONFAILING(*(uint32_t*)0x4000000000c0 = r[3]); NONFAILING(*(uint64_t*)0x4000000000c8 = 0x400000000000); NONFAILING(*(uint32_t*)0x400000000000 = 0); NONFAILING(*(uint64_t*)0x4000000000d0 = 0x400000000080); NONFAILING(*(uint32_t*)0x400000000080 = r[0]); NONFAILING(*(uint64_t*)0x4000000000d8 = 0); syscall(__NR_bpf, /*cmd=*/2ul, /*arg=*/0x4000000000c0ul, /*size=*/0x20ul); NONFAILING(*(uint64_t*)0x400000000080 = 0); NONFAILING(*(uint32_t*)0x400000000088 = 0); NONFAILING(*(uint64_t*)0x400000000090 = 0); NONFAILING(*(uint64_t*)0x400000000098 = 0); NONFAILING(*(uint64_t*)0x4000000000a0 = 0); NONFAILING(*(uint64_t*)0x4000000000a8 = 0); NONFAILING(*(uint32_t*)0x4000000000b0 = 0x1f00c00e); inject_fault(5); syscall(__NR_sendmsg, /*fd=*/r[1], /*msg=*/0x400000000080ul, /*f=MSG_BATCH|MSG_NOSIGNAL*/ 0x44000ul); return 0; }