// https://syzkaller.appspot.com/bug?id=3a0130f6b0d9eadf2a211d84fdc2f69c9741afc2 // 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_clone #define __NR_clone 220 #endif #ifndef __NR_exit #define __NR_exit 93 #endif #ifndef __NR_mmap #define __NR_mmap 222 #endif #ifndef __NR_mprotect #define __NR_mprotect 226 #endif #ifndef __NR_ptrace #define __NR_ptrace 117 #endif #ifndef __NR_sendmsg #define __NR_sendmsg 211 #endif #ifndef __NR_setsockopt #define __NR_setsockopt 208 #endif #ifndef __NR_wait4 #define __NR_wait4 260 #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"); } #define USLEEP_FORKED_CHILD (3 * 50 * 1000) static long handle_clone_ret(long ret) { if (ret != 0) { __atomic_store_n(&clone_ongoing, 0, __ATOMIC_RELAXED); return ret; } usleep(USLEEP_FORKED_CHILD); syscall(__NR_exit, 0); while (1) { } } static long syz_clone(volatile long flags, volatile long stack, volatile long stack_len, volatile long ptid, volatile long ctid, volatile long tls) { long sp = (stack + stack_len) & ~15; __atomic_store_n(&clone_ongoing, 1, __ATOMIC_RELAXED); long ret = (long)syscall(__NR_clone, flags & ~CLONE_VM, sp, ptid, ctid, tls); return handle_clone_ret(ret); } 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] = {0x0}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // setsockopt$inet6_tcp_TCP_REPAIR_WINDOW arguments: [ // fd: sock_tcp6 (resource) // level: const = 0x6 (4 bytes) // optname: const = 0x1d (4 bytes) // optval: ptr[in, tcp_repair_window] { // tcp_repair_window { // snd_wl1: int32 = 0xffff8006 (4 bytes) // snd_wnd: int32 = 0x9 (4 bytes) // max_window: int32 = 0x800 (4 bytes) // rcv_wnd: int32 = 0x5 (4 bytes) // rcv_wup: int32 = 0x4 (4 bytes) // } // } // optlen: len = 0x14 (8 bytes) // ] NONFAILING(*(uint32_t*)0x20000040 = 0xffff8006); NONFAILING(*(uint32_t*)0x20000044 = 9); NONFAILING(*(uint32_t*)0x20000048 = 0x800); NONFAILING(*(uint32_t*)0x2000004c = 5); NONFAILING(*(uint32_t*)0x20000050 = 4); syscall(__NR_setsockopt, /*fd=*/(intptr_t)-1, /*level=*/6, /*optname=*/0x1d, /*optval=*/0x20000040ul, /*optlen=*/0x14ul); // sendmsg$inet_sctp arguments: [ // fd: sock_sctp (resource) // msg: ptr[in, msghdr_sctp] { // msghdr_sctp { // addr: ptr[in, sockaddr_sctp] { // union sockaddr_sctp { // in: sockaddr_in { // family: const = 0x2 (2 bytes) // port: int16be = 0x4e24 (2 bytes) // addr: union ipv4_addr { // dev: ipv4_addr_t[netdev_addr_id] { // a0: const = 0xac (1 bytes) // a1: const = 0x14 (1 bytes) // a2: const = 0x14 (1 bytes) // a3: int8 = 0x2c (1 bytes) // } // } // pad = 0x0 (8 bytes) // } // } // } // addrlen: len = 0x10 (4 bytes) // pad = 0x0 (4 bytes) // vec: nil // vlen: len = 0x0 (8 bytes) // ctrl: nil // ctrllen: bytesize = 0x0 (8 bytes) // f: send_flags = 0x40084 (4 bytes) // pad = 0x0 (4 bytes) // } // } // f: send_flags = 0x1 (8 bytes) // ] NONFAILING(*(uint64_t*)0x20000000 = 0x20000040); NONFAILING(*(uint16_t*)0x20000040 = 2); NONFAILING(*(uint16_t*)0x20000042 = htobe16(0x4e24)); NONFAILING(*(uint8_t*)0x20000044 = 0xac); NONFAILING(*(uint8_t*)0x20000045 = 0x14); NONFAILING(*(uint8_t*)0x20000046 = 0x14); NONFAILING(*(uint8_t*)0x20000047 = 0x2c); NONFAILING(*(uint32_t*)0x20000008 = 0x10); NONFAILING(*(uint64_t*)0x20000010 = 0); NONFAILING(*(uint64_t*)0x20000018 = 0); NONFAILING(*(uint64_t*)0x20000020 = 0); NONFAILING(*(uint64_t*)0x20000028 = 0); NONFAILING(*(uint32_t*)0x20000030 = 0x40084); syscall(__NR_sendmsg, /*fd=*/(intptr_t)-1, /*msg=*/0x20000000ul, /*f=MSG_OOB*/ 1ul); // mprotect arguments: [ // addr: VMA[0xf000] // len: len = 0xf000 (8 bytes) // prot: mmap_prot = 0x1 (8 bytes) // ] syscall(__NR_mprotect, /*addr=*/0x20000000ul, /*len=*/0xf000ul, /*prot=PROT_READ*/ 1ul); // syz_clone arguments: [ // flags: clone_flags = 0x11 (8 bytes) // stack: nil // stack_len: bytesize = 0x0 (8 bytes) // parentid: nil // childtid: nil // tls: nil // ] // returns pid res = -1; NONFAILING(res = syz_clone(/*flags=*/0x11, /*stack=*/0, /*stack_len=*/0, /*parentid=*/0, /*childtid=*/0, /*tls=*/0)); if (res != -1) r[0] = res; // ptrace arguments: [ // req: ptrace_req = 0x10 (8 bytes) // pid: pid (resource) // ] syscall(__NR_ptrace, /*req=PTRACE_ATTACH*/ 0x10ul, /*pid=*/r[0], 0, 0); // wait4 arguments: [ // pid: pid (resource) // status: nil // options: wait_options = 0x40000000 (8 bytes) // ru: nil // ] syscall(__NR_wait4, /*pid=*/r[0], /*status=*/0ul, /*options=__WALL*/ 0x40000000ul, /*ru=*/0ul); // ptrace$setregset arguments: [ // req: const = 0x4205 (8 bytes) // pid: pid (resource) // what: pthread_regset = 0x405 (8 bytes) // data: ptr[in, iovec[in, array[int8]]] { // iovec[in, array[int8]] { // addr: nil // len: len = 0x300 (8 bytes) // } // } // ] NONFAILING(*(uint64_t*)0x20000000 = 0); NONFAILING(*(uint64_t*)0x20000008 = 0x300); syscall(__NR_ptrace, /*req=*/0x4205ul, /*pid=*/r[0], /*what=NT_TASKSTRUCT|NT_PRSTATUS|0x400*/ 0x405ul, /*data=*/0x20000000ul); } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-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=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; install_segv_handler(); loop(); return 0; }