// https://syzkaller.appspot.com/bug?id=5daea027b13b9760e6786ec63e04110eede069f3 // 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_mmap #define __NR_mmap 222 #endif #ifndef __NR_mprotect #define __NR_mprotect 226 #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$MAP_CREATE_CONST_STR arguments: [ // cmd: const = 0x0 (8 bytes) // arg: ptr[in, bpf_map_create_arg_t[const[BPF_MAP_TYPE_ARRAY, int32], // const[4, int32], const[8, int32], const[1, int32], // const[BPF_F_RDONLY_PROG, int32], const[0, int64]]] { // bpf_map_create_arg_t[const[BPF_MAP_TYPE_ARRAY, int32], const[4, // int32], const[8, int32], const[1, int32], const[BPF_F_RDONLY_PROG, // int32], const[0, int64]] { // type: const = 0x2 (4 bytes) // ksize: const = 0x4 (4 bytes) // vsize: const = 0x8 (4 bytes) // max: const = 0x1 (4 bytes) // flags: const = 0x80 (4 bytes) // inner: fd_bpf_map (resource) // node: int32 = 0x0 (4 bytes) // map_name: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} // (length 0x10) map_ifindex: ifindex (resource) btf_fd: fd_btf // (resource) btf_key_type_id: int32 = 0x0 (4 bytes) btf_value_type_id: // int32 = 0x0 (4 bytes) btf_vmlinux_type_id: int32 = 0x0 (4 bytes) // map_extra: const = 0x0 (8 bytes) // value_type_btf_obj_fd: union // _bpf_map_create_arg_t[const[BPF_MAP_TYPE_ARRAY, int32], const[4, // int32], const[8, int32], const[1, int32], const[BPF_F_RDONLY_PROG, // int32], const[0, int64]]_value_type_btf_obj_fd_wrapper { // void: buffer: {} (length 0x0) // } // pad1: union _bpf_map_create_arg_t[const[BPF_MAP_TYPE_ARRAY, int32], // const[4, int32], const[8, int32], const[1, int32], // const[BPF_F_RDONLY_PROG, int32], const[0, int64]]_pad1_wrapper { // value: const = 0x0 (4 bytes) // } // map_token_fd: union _bpf_map_create_arg_t[const[BPF_MAP_TYPE_ARRAY, // int32], const[4, int32], const[8, int32], const[1, int32], // const[BPF_F_RDONLY_PROG, int32], const[0, // int64]]_map_token_fd_wrapper { // void: buffer: {} (length 0x0) // } // pad2: union _bpf_map_create_arg_t[const[BPF_MAP_TYPE_ARRAY, int32], // const[4, int32], const[8, int32], const[1, int32], // const[BPF_F_RDONLY_PROG, int32], const[0, int64]]_pad2_wrapper { // value: const = 0x0 (4 bytes) // } // } // } // size: len = 0x50 (8 bytes) // ] // returns fd_bpf_const_str_map NONFAILING(*(uint32_t*)0x200003c0 = 2); NONFAILING(*(uint32_t*)0x200003c4 = 4); NONFAILING(*(uint32_t*)0x200003c8 = 8); NONFAILING(*(uint32_t*)0x200003cc = 1); NONFAILING(*(uint32_t*)0x200003d0 = 0x80); NONFAILING(*(uint32_t*)0x200003d4 = -1); NONFAILING(*(uint32_t*)0x200003d8 = 0); NONFAILING(memset((void*)0x200003dc, 0, 16)); NONFAILING(*(uint32_t*)0x200003ec = 0); NONFAILING(*(uint32_t*)0x200003f0 = -1); NONFAILING(*(uint32_t*)0x200003f4 = 0); NONFAILING(*(uint32_t*)0x200003f8 = 0); NONFAILING(*(uint32_t*)0x200003fc = 0); NONFAILING(*(uint64_t*)0x20000400 = 0); NONFAILING(*(uint32_t*)0x20000408 = 0); NONFAILING(*(uint32_t*)0x2000040c = 0); res = syscall(__NR_bpf, /*cmd=*/0ul, /*arg=*/0x200003c0ul, /*size=*/0x50ul); if (res != -1) r[0] = res; // 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 = 0x19 (4 bytes) // ninsn: bytesize8 = 0x11 (4 bytes) // insns: ptr[inout, array[ANYUNION]] { // array[ANYUNION] { // union ANYUNION { // ANYBLOB: buffer: {18 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 // 00 85 00 00 00 a8 00 00 00 b7 08 00 00 00 00 00 00 7b 8a f8 ff // 00 00 00 00 b7 08 00 00 00 00 00 00 7b 8a f0 ff 00 00 00 00 bf // a1 00 00 00 00 00 00 07 01 00 00 f8 ff ff ff bf a4 00 00 00 00 // 00 00 07 04 00 00 f0 ff ff ff b7 02 00 00 08 00 00 00 18 23 00 // 00} (length 0x64) // } // union ANYUNION { // ANYRES32: ANYRES32 (resource) // } // } // } // license: nil // loglev: int32 = 0x0 (4 bytes) // logsize: len = 0x0 (4 bytes) // log: nil // kern_version: bpf_kern_version = 0x0 (4 bytes) // flags: bpf_prog_load_flags = 0x1a (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 = 0x0 (4 bytes) // } // btf_fd: fd_btf (resource) // func_info_rec_size: const = 0x0 (4 bytes) // func_info: nil // func_info_cnt: len = 0x0 (4 bytes) // line_info_rec_size: const = 0x0 (4 bytes) // line_info: nil // line_info_cnt: len = 0x0 (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*)0x20000100 = 0x19); NONFAILING(*(uint32_t*)0x20000104 = 0x11); NONFAILING(*(uint64_t*)0x20000108 = 0x20000200); NONFAILING(memcpy( (void*)0x20000200, "\x18\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x85\x00" "\x00\x00\xa8\x00\x00\x00\xb7\x08\x00\x00\x00\x00\x00\x00\x7b\x8a\xf8\xff" "\x00\x00\x00\x00\xb7\x08\x00\x00\x00\x00\x00\x00\x7b\x8a\xf0\xff\x00\x00" "\x00\x00\xbf\xa1\x00\x00\x00\x00\x00\x00\x07\x01\x00\x00\xf8\xff\xff\xff" "\xbf\xa4\x00\x00\x00\x00\x00\x00\x07\x04\x00\x00\xf0\xff\xff\xff\xb7\x02" "\x00\x00\x08\x00\x00\x00\x18\x23\x00\x00", 100)); NONFAILING(*(uint32_t*)0x20000264 = r[0]); NONFAILING(*(uint64_t*)0x20000110 = 0); NONFAILING(*(uint32_t*)0x20000118 = 0); NONFAILING(*(uint32_t*)0x2000011c = 0); NONFAILING(*(uint64_t*)0x20000120 = 0); NONFAILING(*(uint32_t*)0x20000128 = 0); NONFAILING(*(uint32_t*)0x2000012c = 0x1a); NONFAILING(memset((void*)0x20000130, 0, 16)); NONFAILING(*(uint32_t*)0x20000140 = 0); NONFAILING(*(uint32_t*)0x20000144 = 0); NONFAILING(*(uint32_t*)0x20000148 = -1); NONFAILING(*(uint32_t*)0x2000014c = 0); NONFAILING(*(uint64_t*)0x20000150 = 0); NONFAILING(*(uint32_t*)0x20000158 = 0); NONFAILING(*(uint32_t*)0x2000015c = 0); NONFAILING(*(uint64_t*)0x20000160 = 0); NONFAILING(*(uint32_t*)0x20000168 = 0); NONFAILING(*(uint32_t*)0x2000016c = 0); NONFAILING(*(uint32_t*)0x20000170 = 0); NONFAILING(*(uint32_t*)0x20000174 = 0); NONFAILING(*(uint64_t*)0x20000178 = 0); NONFAILING(*(uint64_t*)0x20000180 = 0); NONFAILING(*(uint32_t*)0x20000188 = 0x10); NONFAILING(*(uint32_t*)0x2000018c = 0); NONFAILING(*(uint32_t*)0x20000190 = 0); syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x20000100ul, /*size=*/0x94ul); // mprotect arguments: [ // addr: VMA[0x800000] // len: len = 0x800000 (8 bytes) // prot: mmap_prot = 0x1 (8 bytes) // ] syscall(__NR_mprotect, /*addr=*/0x20000000ul, /*len=*/0x800000ul, /*prot=PROT_READ*/ 1ul); // bpf$MAP_LOOKUP_BATCH arguments: [ // cmd: const = 0x18 (8 bytes) // arg: ptr[in, bpf_map_batch_arg] { // bpf_map_batch_arg { // in_batch: nil // out_batch: nil // key: nil // val: nil // count: int32 = 0x2 (4 bytes) // map_fd: fd_bpf_map (resource) // elem_flags: bpf_batch_flags = 0x0 (8 bytes) // flags: const = 0x0 (8 bytes) // } // } // size: len = 0x38 (8 bytes) // ] NONFAILING(*(uint64_t*)0x20000240 = 0); NONFAILING(*(uint64_t*)0x20000248 = 0); NONFAILING(*(uint64_t*)0x20000250 = 0); NONFAILING(*(uint64_t*)0x20000258 = 0); NONFAILING(*(uint32_t*)0x20000260 = 2); NONFAILING(*(uint32_t*)0x20000264 = -1); NONFAILING(*(uint64_t*)0x20000268 = 0); NONFAILING(*(uint64_t*)0x20000270 = 0); syscall(__NR_bpf, /*cmd=*/0x18ul, /*arg=*/0x20000240ul, /*size=*/0x38ul); return 0; }