// https://syzkaller.appspot.com/bug?id=840ec78a9ded8997e0d64722122b36dbc35f7870 // 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 #include #include #include #include #ifndef __NR_mmap #define __NR_mmap 222 #endif #ifndef __NR_sendmsg #define __NR_sendmsg 211 #endif #ifndef __NR_socket #define __NR_socket 198 #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 sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } 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 void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); for (int i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); write_file("/proc/self/oom_score_adj", "1000"); } 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[] = { {"/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"}, {"/sys/kernel/debug/failslab/task-filter", "Y"}, {"/sys/kernel/debug/fail_page_alloc/task-filter", "Y"}, {"/sys/kernel/debug/fail_futex/task-filter", "Y"}, {"/sys/kernel/debug/fail_usercopy/task-filter", "Y"}, {"/sys/kernel/debug/fail_make_request/task-filter", "Y"}, {"/sys/kernel/debug/fail_io_timeout/task-filter", "Y"}, {"/sys/kernel/debug/fail_iommufd/task-filter", "Y"}, {"/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) ; } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter = 0; for (;; iter++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { setup_test(); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { sleep_ms(10); if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } } } uint64_t r[1] = {0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // socket$nl_route arguments: [ // domain: const = 0x10 (8 bytes) // type: const = 0x3 (8 bytes) // proto: const = 0x0 (4 bytes) // ] // returns sock_nl_route res = syscall(__NR_socket, /*domain=*/0x10ul, /*type=*/3ul, /*proto=*/0); if (res != -1) r[0] = res; // sendmsg$nl_route arguments: [ // fd: sock_nl_route (resource) // msg: ptr[in, msghdr_netlink[netlink_msg_route]] { // msghdr_netlink[netlink_msg_route] { // addr: nil // addrlen: len = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // vec: ptr[in, iovec[in, netlink_msg_route]] { // iovec[in, netlink_msg_route] { // addr: ptr[inout, array[ANYUNION]] { // array[ANYUNION] { // union ANYUNION { // ANYBLOB: buffer: {50 00 00 00 10 00 01 06 01 00 00 00 00 // 00 00 00 00 00 00 00 64 00 00 00 00 00 00 00 00 00 00 00 // 0c 00 03 00 76 78 6c 61 6e 30 00 00 24 00 12 80 0c 00 01 // 00 76 78 6c 61 6e 00 00 00 14 00 02 80 05 00 19 00 01 00 // 00 00 05 00 1e 00 01} (length 0x4d) // } // } // } // len: len = 0x50 (8 bytes) // } // } // vlen: const = 0x1 (8 bytes) // ctrl: const = 0x0 (8 bytes) // ctrllen: const = 0x0 (8 bytes) // f: send_flags = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // } // } // f: send_flags = 0x0 (8 bytes) // ] NONFAILING(*(uint64_t*)0x20000000 = 0); NONFAILING(*(uint32_t*)0x20000008 = 0); NONFAILING(*(uint64_t*)0x20000010 = 0x20000080); NONFAILING(*(uint64_t*)0x20000080 = 0x20000100); NONFAILING( memcpy((void*)0x20000100, "\x50\x00\x00\x00\x10\x00\x01\x06\x01\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x64\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x0c\x00\x03\x00\x76\x78\x6c\x61\x6e\x30\x00\x00\x24\x00\x12\x80" "\x0c\x00\x01\x00\x76\x78\x6c\x61\x6e\x00\x00\x00\x14\x00\x02\x80" "\x05\x00\x19\x00\x01\x00\x00\x00\x05\x00\x1e\x00\x01", 77)); NONFAILING(*(uint64_t*)0x20000088 = 0x50); NONFAILING(*(uint64_t*)0x20000018 = 1); NONFAILING(*(uint64_t*)0x20000020 = 0); NONFAILING(*(uint64_t*)0x20000028 = 0); NONFAILING(*(uint32_t*)0x20000030 = 0); syscall(__NR_sendmsg, /*fd=*/r[0], /*msg=*/0x20000000ul, /*f=*/0ul); // sendmsg$nl_route arguments: [ // fd: sock_nl_route (resource) // msg: ptr[in, msghdr_netlink[netlink_msg_route]] { // msghdr_netlink[netlink_msg_route] { // addr: nil // addrlen: len = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // vec: ptr[in, iovec[in, netlink_msg_route]] { // iovec[in, netlink_msg_route] { // addr: ptr[inout, array[ANYUNION]] { // array[ANYUNION] { // union ANYUNION { // ANYBLOB: buffer: {2c 00 00 00 78 00 01 04 02 00 00 00 03 // 00 00 00 07 00 00 00 64 00 00 00 14 00 01 80 08 00 01 00 // 64 00 00 00 08 00 02 00 c8 58 df 50 6a 74 04 af 69 1a ab // f4 a0 a9 c2 ad 94 6b e5 15 c1 38 04 77 d4 a5 12 0a 9b bc // d4 ad 3c a1 9f 06 13 ef 68 43 6c 9e 70 47 e2 b5 7d ee 46 // c7 e6 9d 6b 75 99 f2 91 9b 8c 90 13 8e e8 e4 79 04 5d 09 // 39 93 dd df a6 20 c8 aa e3 35 96 72 73 dd b1 0d fa c0 6d // 3d 2d 44 80 b9 2c b1 e0 72 44 08 b7 67 3e 0f 4b b7 42 1d // b4 26 ea 25 f4 5f 63 0c 68 6f 25 bd a5 5d 23 41 36 98 42} // (length 0xa5) // } // } // } // len: len = 0x2c (8 bytes) // } // } // vlen: const = 0x1 (8 bytes) // ctrl: const = 0x0 (8 bytes) // ctrllen: const = 0x0 (8 bytes) // f: send_flags = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // } // } // f: send_flags = 0x0 (8 bytes) // ] NONFAILING(*(uint64_t*)0x20000200 = 0); NONFAILING(*(uint32_t*)0x20000208 = 0); NONFAILING(*(uint64_t*)0x20000210 = 0x20000280); NONFAILING(*(uint64_t*)0x20000280 = 0x20000340); NONFAILING(memcpy( (void*)0x20000340, "\x2c\x00\x00\x00\x78\x00\x01\x04\x02\x00\x00\x00\x03\x00\x00\x00\x07\x00" "\x00\x00\x64\x00\x00\x00\x14\x00\x01\x80\x08\x00\x01\x00\x64\x00\x00\x00" "\x08\x00\x02\x00\xc8\x58\xdf\x50\x6a\x74\x04\xaf\x69\x1a\xab\xf4\xa0\xa9" "\xc2\xad\x94\x6b\xe5\x15\xc1\x38\x04\x77\xd4\xa5\x12\x0a\x9b\xbc\xd4\xad" "\x3c\xa1\x9f\x06\x13\xef\x68\x43\x6c\x9e\x70\x47\xe2\xb5\x7d\xee\x46\xc7" "\xe6\x9d\x6b\x75\x99\xf2\x91\x9b\x8c\x90\x13\x8e\xe8\xe4\x79\x04\x5d\x09" "\x39\x93\xdd\xdf\xa6\x20\xc8\xaa\xe3\x35\x96\x72\x73\xdd\xb1\x0d\xfa\xc0" "\x6d\x3d\x2d\x44\x80\xb9\x2c\xb1\xe0\x72\x44\x08\xb7\x67\x3e\x0f\x4b\xb7" "\x42\x1d\xb4\x26\xea\x25\xf4\x5f\x63\x0c\x68\x6f\x25\xbd\xa5\x5d\x23\x41" "\x36\x98\x42", 165)); NONFAILING(*(uint64_t*)0x20000288 = 0x2c); NONFAILING(*(uint64_t*)0x20000218 = 1); NONFAILING(*(uint64_t*)0x20000220 = 0); NONFAILING(*(uint64_t*)0x20000228 = 0); NONFAILING(*(uint32_t*)0x20000230 = 0); syscall(__NR_sendmsg, /*fd=*/r[0], /*msg=*/0x20000200ul, /*f=*/0ul); } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); setup_sysctl(); const char* reason; (void)reason; install_segv_handler(); loop(); return 0; }