// https://syzkaller.appspot.com/bug?id=7eb5be5c14aad4813ccfec72fcbfe3ad54706260 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #ifndef __NR_bpf #define __NR_bpf 280 #endif #ifndef __NR_ioctl #define __NR_ioctl 29 #endif #ifndef __NR_mmap #define __NR_mmap 222 #endif #ifndef __NR_mprotect #define __NR_mprotect 226 #endif #ifndef __NR_userfaultfd #define __NR_userfaultfd 282 #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; \ }) uint64_t r[1] = {0xffffffffffffffff}; 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(); intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // bpf$PROG_LOAD arguments: [ // cmd: const = 0x5 (8 bytes) // arg: ptr[in, bpf_prog_t[flags[bpf_prog_type, int32], // bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]] { // bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, // bpf_btf_id[opt], fd_bpf_prog[opt]] { // type: bpf_prog_type = 0x4 (4 bytes) // ninsn: bytesize8 = 0x0 (4 bytes) // insns: nil // license: nil // loglev: int32 = 0x0 (4 bytes) // logsize: len = 0x0 (4 bytes) // log: nil // kern_version: bpf_kern_version = 0x41000 (4 bytes) // flags: bpf_prog_load_flags = 0x40 (4 bytes) // prog_name: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} // (length 0x10) prog_ifindex: ifindex (resource) expected_attach_type: // union bpf_prog_attach_types { // fallback: bpf_attach_types = 0x5 (4 bytes) // } // btf_fd: fd_btf (resource) // func_info_rec_size: const = 0x8 (4 bytes) // func_info: nil // func_info_cnt: len = 0x0 (4 bytes) // line_info_rec_size: const = 0x10 (4 bytes) // line_info: ptr[in, bpf_line_info] { // bpf_line_info { // insn_off: int32 = 0x0 (4 bytes) // file_name_off: int32 = 0xa (4 bytes) // line_off: int32 = 0x0 (4 bytes) // line_col: int32 = 0x10 (4 bytes) // } // } // line_info_cnt: len = 0x10 (4 bytes) // attach_btf_id: bpf_btf_id (resource) // attach_prog_fd: fd_bpf_prog (resource) // core_relo_cnt: len = 0x0 (4 bytes) // fd_array: nil // core_relos: nil // core_relo_rec_size: const = 0x10 (4 bytes) // log_true_size: int32 = 0x0 (4 bytes) // prog_token_fd: union _bpf_prog_t[flags[bpf_prog_type, int32], // bpf_prog_attach_types, bpf_btf_id[opt], // fd_bpf_prog[opt]]_prog_token_fd_wrapper { // void: buffer: {} (length 0x0) // } // pad: union _bpf_prog_t[flags[bpf_prog_type, int32], // bpf_prog_attach_types, bpf_btf_id[opt], // fd_bpf_prog[opt]]_pad_wrapper { // value: const = 0x0 (4 bytes) // } // } // } // size: len = 0x94 (8 bytes) // ] // returns fd_bpf_prog NONFAILING(*(uint32_t*)0x200002c0 = 4); NONFAILING(*(uint32_t*)0x200002c4 = 0); NONFAILING(*(uint64_t*)0x200002c8 = 0); NONFAILING(*(uint64_t*)0x200002d0 = 0); NONFAILING(*(uint32_t*)0x200002d8 = 0); NONFAILING(*(uint32_t*)0x200002dc = 0); NONFAILING(*(uint64_t*)0x200002e0 = 0); NONFAILING(*(uint32_t*)0x200002e8 = 0x41000); NONFAILING(*(uint32_t*)0x200002ec = 0x40); NONFAILING(memset((void*)0x200002f0, 0, 16)); NONFAILING(*(uint32_t*)0x20000300 = 0); NONFAILING(*(uint32_t*)0x20000304 = 5); NONFAILING(*(uint32_t*)0x20000308 = -1); NONFAILING(*(uint32_t*)0x2000030c = 8); NONFAILING(*(uint64_t*)0x20000310 = 0); NONFAILING(*(uint32_t*)0x20000318 = 0); NONFAILING(*(uint32_t*)0x2000031c = 0x10); NONFAILING(*(uint64_t*)0x20000320 = 0x20000000); NONFAILING(*(uint32_t*)0x20000000 = 0); NONFAILING(*(uint32_t*)0x20000004 = 0xa); NONFAILING(*(uint32_t*)0x20000008 = 0); NONFAILING(*(uint32_t*)0x2000000c = 0x10); NONFAILING(*(uint32_t*)0x20000328 = 0x10); NONFAILING(*(uint32_t*)0x2000032c = 0); NONFAILING(*(uint32_t*)0x20000330 = -1); NONFAILING(*(uint32_t*)0x20000334 = 0); NONFAILING(*(uint64_t*)0x20000338 = 0); NONFAILING(*(uint64_t*)0x20000340 = 0); NONFAILING(*(uint32_t*)0x20000348 = 0x10); NONFAILING(*(uint32_t*)0x2000034c = 0); NONFAILING(*(uint32_t*)0x20000350 = 0); syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x200002c0ul, /*size=*/0x94ul); // userfaultfd arguments: [ // flags: userfaultfd_flags = 0x80001 (8 bytes) // ] // returns fd_uffd res = syscall(__NR_userfaultfd, /*flags=UFFD_USER_MODE_ONLY|O_CLOEXEC*/ 0x80001ul); if (res != -1) r[0] = res; // ioctl$UFFDIO_API arguments: [ // fd: fd_uffd (resource) // cmd: const = 0xc018aa3f (4 bytes) // arg: ptr[in, uffdio_api] { // uffdio_api { // api: const = 0xaa (8 bytes) // featur: uffdio_features = 0x0 (8 bytes) // ioctls: const = 0x0 (8 bytes) // } // } // ] NONFAILING(*(uint64_t*)0x200000c0 = 0xaa); NONFAILING(*(uint64_t*)0x200000c8 = 0); NONFAILING(*(uint64_t*)0x200000d0 = 0); syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc018aa3f, /*arg=*/0x200000c0ul); // mprotect arguments: [ // addr: VMA[0x4000] // len: len = 0x4000 (8 bytes) // prot: mmap_prot = 0x1 (8 bytes) // ] syscall(__NR_mprotect, /*addr=*/0x20000000ul, /*len=*/0x4000ul, /*prot=PROT_READ*/ 1ul); // ioctl$UFFDIO_ZEROPAGE arguments: [ // fd: fd_uffd (resource) // cmd: const = 0xc020aa04 (4 bytes) // arg: ptr[in, uffdio_zeropage] { // uffdio_zeropage { // range: uffdio_range { // start: VMA[0x3000] // len: len = 0x3000 (8 bytes) // } // mode: uffdio_zero_mode = 0x0 (8 bytes) // zeropg: const = 0x0 (8 bytes) // } // } // ] NONFAILING(*(uint64_t*)0x20000000 = 0x204bd000); NONFAILING(*(uint64_t*)0x20000008 = 0x3000); NONFAILING(*(uint64_t*)0x20000010 = 0); NONFAILING(*(uint64_t*)0x20000018 = 0); syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc020aa04, /*arg=*/0x20000000ul); return 0; }