// https://syzkaller.appspot.com/bug?id=b2c26e9e60a70de5dc7d929fd1e991ccbdefa9bc // 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 #ifndef __NR_bpf #define __NR_bpf 321 #endif #ifndef __NR_io_uring_enter #define __NR_io_uring_enter 426 #endif #ifndef __NR_io_uring_setup #define __NR_io_uring_setup 425 #endif 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; } #define SIZEOF_IO_URING_SQE 64 #define SIZEOF_IO_URING_CQE 16 #define SQ_HEAD_OFFSET 0 #define SQ_TAIL_OFFSET 64 #define SQ_RING_MASK_OFFSET 256 #define SQ_RING_ENTRIES_OFFSET 264 #define SQ_FLAGS_OFFSET 276 #define SQ_DROPPED_OFFSET 272 #define CQ_HEAD_OFFSET 128 #define CQ_TAIL_OFFSET 192 #define CQ_RING_MASK_OFFSET 260 #define CQ_RING_ENTRIES_OFFSET 268 #define CQ_RING_OVERFLOW_OFFSET 284 #define CQ_FLAGS_OFFSET 280 #define CQ_CQES_OFFSET 320 struct io_sqring_offsets { uint32_t head; uint32_t tail; uint32_t ring_mask; uint32_t ring_entries; uint32_t flags; uint32_t dropped; uint32_t array; uint32_t resv1; uint64_t resv2; }; struct io_cqring_offsets { uint32_t head; uint32_t tail; uint32_t ring_mask; uint32_t ring_entries; uint32_t overflow; uint32_t cqes; uint64_t resv[2]; }; struct io_uring_params { uint32_t sq_entries; uint32_t cq_entries; uint32_t flags; uint32_t sq_thread_cpu; uint32_t sq_thread_idle; uint32_t features; uint32_t resv[4]; struct io_sqring_offsets sq_off; struct io_cqring_offsets cq_off; }; #define IORING_OFF_SQ_RING 0 #define IORING_OFF_SQES 0x10000000ULL #define IORING_SETUP_SQE128 (1U << 10) #define IORING_SETUP_CQE32 (1U << 11) static long syz_io_uring_setup(volatile long a0, volatile long a1, volatile long a2, volatile long a3) { uint32_t entries = (uint32_t)a0; struct io_uring_params* setup_params = (struct io_uring_params*)a1; void** ring_ptr_out = (void**)a2; void** sqes_ptr_out = (void**)a3; setup_params->flags &= ~(IORING_SETUP_CQE32 | IORING_SETUP_SQE128); uint32_t fd_io_uring = syscall(__NR_io_uring_setup, entries, setup_params); uint32_t sq_ring_sz = setup_params->sq_off.array + setup_params->sq_entries * sizeof(uint32_t); uint32_t cq_ring_sz = setup_params->cq_off.cqes + setup_params->cq_entries * SIZEOF_IO_URING_CQE; uint32_t ring_sz = sq_ring_sz > cq_ring_sz ? sq_ring_sz : cq_ring_sz; *ring_ptr_out = mmap(0, ring_sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd_io_uring, IORING_OFF_SQ_RING); uint32_t sqes_sz = setup_params->sq_entries * SIZEOF_IO_URING_SQE; *sqes_ptr_out = mmap(0, sqes_sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd_io_uring, IORING_OFF_SQES); uint32_t* array = (uint32_t*)((uintptr_t)*ring_ptr_out + setup_params->sq_off.array); for (uint32_t index = 0; index < entries; index++) array[index] = index; return fd_io_uring; } static long syz_io_uring_submit(volatile long a0, volatile long a1, volatile long a2) { char* ring_ptr = (char*)a0; char* sqes_ptr = (char*)a1; char* sqe = (char*)a2; uint32_t sq_ring_mask = *(uint32_t*)(ring_ptr + SQ_RING_MASK_OFFSET); uint32_t* sq_tail_ptr = (uint32_t*)(ring_ptr + SQ_TAIL_OFFSET); uint32_t sq_tail = *sq_tail_ptr & sq_ring_mask; char* sqe_dest = sqes_ptr + sq_tail * SIZEOF_IO_URING_SQE; memcpy(sqe_dest, sqe, SIZEOF_IO_URING_SQE); uint32_t sq_tail_next = *sq_tail_ptr + 1; __atomic_store_n(sq_tail_ptr, sq_tail_next, __ATOMIC_RELEASE); return 0; } 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 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[6] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // socket$nl_netfilter arguments: [ // domain: const = 0x10 (8 bytes) // type: const = 0x3 (8 bytes) // proto: const = 0xc (4 bytes) // ] // returns sock_nl_netfilter syscall(__NR_socket, /*domain=*/0x10ul, /*type=*/3ul, /*proto=*/0xc); // 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 = 0x10 (4 bytes) // ninsn: bytesize8 = 0x4 (4 bytes) // insns: ptr[inout, array[ANYUNION]] { // array[ANYUNION] { // union ANYUNION { // ANYBLOB: buffer: {b4 00 00 00 00 00 00 00 79 10 48 00 00 00 00 // 00 61 04 00 00 00 00 00 00 95 00 00 00} (length 0x1c) // } // } // } // license: ptr[in, buffer] { // buffer: {47 50 4c 00} (length 0x4) // } // loglev: int32 = 0x2 (4 bytes) // logsize: len = 0xfd90 (4 bytes) // log: ptr[out, buffer] { // buffer: (DirOut) // } // kern_version: bpf_kern_version = 0x0 (4 bytes) // flags: bpf_prog_load_flags = 0x0 (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 { // sk_msg: sk_msg_attach_types = 0x0 (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: 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 = 0x48 (8 bytes) // ] // returns fd_bpf_prog *(uint32_t*)0x20000000e000 = 0x10; *(uint32_t*)0x20000000e004 = 4; *(uint64_t*)0x20000000e008 = 0x200000000040; memcpy((void*)0x200000000040, "\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); *(uint64_t*)0x20000000e010 = 0x200000003ff6; memcpy((void*)0x200000003ff6, "GPL\000", 4); *(uint32_t*)0x20000000e018 = 2; *(uint32_t*)0x20000000e01c = 0xfd90; *(uint64_t*)0x20000000e020 = 0x20000000cf3d; *(uint32_t*)0x20000000e028 = 0; *(uint32_t*)0x20000000e02c = 0; memset((void*)0x20000000e030, 0, 16); *(uint32_t*)0x20000000e040 = 0; *(uint32_t*)0x20000000e044 = 0; *(uint32_t*)0x20000000e048 = -1; *(uint32_t*)0x20000000e04c = 8; *(uint64_t*)0x20000000e050 = 0; *(uint32_t*)0x20000000e058 = 0; *(uint32_t*)0x20000000e05c = 0x10; *(uint64_t*)0x20000000e060 = 0; *(uint32_t*)0x20000000e068 = 0; *(uint32_t*)0x20000000e06c = 0; *(uint32_t*)0x20000000e070 = -1; *(uint32_t*)0x20000000e074 = 0; *(uint64_t*)0x20000000e078 = 0; *(uint64_t*)0x20000000e080 = 0; *(uint32_t*)0x20000000e088 = 0x10; *(uint32_t*)0x20000000e08c = 0; *(uint32_t*)0x20000000e090 = 0; res = syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x20000000e000ul, /*size=*/0x48ul); if (res != -1) r[0] = res; // close arguments: [ // fd: fd (resource) // ] syscall(__NR_close, /*fd=*/r[0]); // socketpair$unix arguments: [ // domain: const = 0x1 (8 bytes) // type: unix_socket_type = 0x1 (8 bytes) // proto: const = 0x0 (4 bytes) // fds: ptr[out, unix_pair] { // unix_pair { // fd0: sock_unix (resource) // fd1: sock_unix (resource) // } // } // ] res = syscall(__NR_socketpair, /*domain=*/1ul, /*type=SOCK_STREAM*/ 1ul, /*proto=*/0, /*fds=*/0x200000001540ul); if (res != -1) r[1] = *(uint32_t*)0x200000001544; // bpf$MAP_CREATE arguments: [ // cmd: const = 0x0 (8 bytes) // arg: ptr[inout, array[ANYUNION]] { // array[ANYUNION] { // union ANYUNION { // ANYBLOB: buffer: {0f 00 00 00 04 00 00 00 04 00 00 00 12} (length // 0xd) // } // } // } // size: len = 0x48 (8 bytes) // ] // returns fd_bpf_map memcpy((void*)0x200000000700, "\x0f\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x12", 13); res = syscall(__NR_bpf, /*cmd=*/0ul, /*arg=*/0x200000000700ul, /*size=*/0x48ul); if (res != -1) r[2] = res; // sendmsg$inet arguments: [ // fd: sock (resource) // msg: ptr[in, msghdr_inet] { // msghdr_inet { // msg_name: nil // msg_namelen: len = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // msg_iov: ptr[in, array[iovec[in, array[int8]]]] { // array[iovec[in, array[int8]]] { // iovec[in, array[int8]] { // addr: ptr[in, buffer] { // buffer: {7d} (length 0x1) // } // len: len = 0x1 (8 bytes) // } // } // } // msg_iovlen: len = 0x1 (8 bytes) // msg_control: nil // msg_controllen: bytesize = 0x0 (8 bytes) // msg_flags: const = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // } // } // f: send_flags = 0x804c8d5 (8 bytes) // ] *(uint64_t*)0x200000000300 = 0; *(uint32_t*)0x200000000308 = 0; *(uint64_t*)0x200000000310 = 0x200000000bc0; *(uint64_t*)0x200000000bc0 = 0x200000000780; memset((void*)0x200000000780, 125, 1); *(uint64_t*)0x200000000bc8 = 1; *(uint64_t*)0x200000000318 = 1; *(uint64_t*)0x200000000320 = 0; *(uint64_t*)0x200000000328 = 0; *(uint32_t*)0x200000000330 = 0; syscall( __NR_sendmsg, /*fd=*/r[1], /*msg=*/0x200000000300ul, /*f=MSG_BATCH|MSG_PROBE|MSG_OOB|MSG_NOSIGNAL|MSG_MORE|MSG_EOR|0x8000844*/ 0x804c8d5ul); // bpf$MAP_UPDATE_ELEM_TAIL_CALL arguments: [ // cmd: const = 0x2 (8 bytes) // arg: ptr[inout, bpf_map_update_tail_call_arg] { // bpf_map_update_tail_call_arg { // map: tail_call_map_update { // in: tail_call_map_fd (resource) // out: tail_call_map (resource) // } // pad = 0x0 (4 bytes) // key: ptr[in, const[0, const]] { // const = 0x0 (4 bytes) // } // val: ptr[in, fd_bpf_prog] { // fd_bpf_prog (resource) // } // flags: const = 0x0 (8 bytes) // } // } // size: len = 0x20 (8 bytes) // ] *(uint32_t*)0x2000000000c0 = r[2]; *(uint64_t*)0x2000000000c8 = 0x200000000000; *(uint32_t*)0x200000000000 = 0; *(uint64_t*)0x2000000000d0 = 0x2000000002c0; *(uint32_t*)0x2000000002c0 = r[0]; *(uint64_t*)0x2000000000d8 = 0; syscall(__NR_bpf, /*cmd=*/2ul, /*arg=*/0x2000000000c0ul, /*size=*/0x20ul); // syz_io_uring_setup arguments: [ // entries: int32 = 0x9e (4 bytes) // params: ptr[inout, io_uring_params] { // io_uring_params { // sq_entries: int32 = 0x0 (4 bytes) // cq_entries: int32 = 0x5867 (4 bytes) // flags: io_uring_setup_flags = 0x800 (4 bytes) // sq_thread_cpu: int32 = 0xfffffffc (4 bytes) // sq_thread_idle: int32 = 0x1bd (4 bytes) // features: int32 = 0x0 (4 bytes) // wq_fd: fd_io_uring (resource) // resv: buffer: {00 00 00 00 00 00 00 00 00 00 00 00} (length 0xc) // sq_off: array[int32] { // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // } // cq_off: array[int32] { // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // } // } // } // ring_ptr: ptr[out, ring_ptr] { // ring_ptr (resource) // } // sqes_ptr: ptr[out, sqes_ptr] { // sqes_ptr (resource) // } // ] // returns fd_io_uring *(uint32_t*)0x200000000644 = 0x5867; *(uint32_t*)0x200000000648 = 0x800; *(uint32_t*)0x20000000064c = 0xfffffffc; *(uint32_t*)0x200000000650 = 0x1bd; *(uint32_t*)0x200000000658 = -1; memset((void*)0x20000000065c, 0, 12); res = -1; res = syz_io_uring_setup(/*entries=*/0x9e, /*params=*/0x200000000640, /*ring_ptr=*/0x200000000040, /*sqes_ptr=*/0x2000000001c0); if (res != -1) { r[3] = res; r[4] = *(uint64_t*)0x200000000040; r[5] = *(uint64_t*)0x2000000001c0; } // syz_io_uring_submit arguments: [ // ring_ptr: ring_ptr (resource) // sqes_ptr: sqes_ptr (resource) // sqe: ptr[in, io_uring_sqe_u] { // union io_uring_sqe_u { // IORING_OP_READV: union io_uring_sqe_readv { // pass_iovec: io_uring_sqe[IORING_OP_READV, flags[ioprio_priorities, // int16], fd_or_fixed_fd_index, fileoff[int64], ptr[in, // array[iovec_out]], len[addr, int32], flags[rwf_flags, int32], // sqe_user_data_not_openat, personality_only_misc] { // opcode: const = 0x1 (1 bytes) // flags: iosqe_flags = 0x0 (1 bytes) // ioprio: ioprio_priorities = 0x4007 (2 bytes) // fd: union fd_or_fixed_fd_index { // fd_index: int32 = 0x4 (4 bytes) // } // off: int64 = 0x0 (8 bytes) // addr: ptr[in, array[iovec[out, array[int8]]]] { // array[iovec[out, array[int8]]] { // iovec[out, array[int8]] { // addr: ptr[out, buffer] { // buffer: (DirOut) // } // len: len = 0xd8 (8 bytes) // } // } // } // len: len = 0x1 (4 bytes) // misc_flags: rwf_flags = 0x0 (4 bytes) // user_data: sqe_user_data_not_openat = 0x0 (8 bytes) // misc: personality_only_misc { // buf_index_unused: const = 0x0 (2 bytes) // ioring_personality_id: ioring_personality_id (resource) // pad_unused: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00} (length 0x14) // } // } // } // } // } // ] *(uint8_t*)0x200000000200 = 1; *(uint8_t*)0x200000000201 = 0; *(uint16_t*)0x200000000202 = 0x4007; *(uint32_t*)0x200000000204 = 4; *(uint64_t*)0x200000000208 = 0; *(uint64_t*)0x200000000210 = 0x200000000100; *(uint64_t*)0x200000000100 = 0x200000001800; *(uint64_t*)0x200000000108 = 0xd8; *(uint32_t*)0x200000000218 = 1; *(uint32_t*)0x20000000021c = 0; *(uint64_t*)0x200000000220 = 0; *(uint16_t*)0x200000000228 = 0; *(uint16_t*)0x20000000022a = 0; memset((void*)0x20000000022c, 0, 20); syz_io_uring_submit(/*ring_ptr=*/r[4], /*sqes_ptr=*/r[5], /*sqe=*/0x200000000200); // io_uring_enter arguments: [ // fd: fd_io_uring (resource) // to_submit: int32 = 0x100847c0 (4 bytes) // min_complete: int32 = 0x0 (4 bytes) // flags: io_uring_enter_flags = 0x1 (8 bytes) // sigmask: nil // size: len = 0x0 (8 bytes) // ] syscall(__NR_io_uring_enter, /*fd=*/r[3], /*to_submit=*/0x100847c0, /*min_complete=*/0, /*flags=IORING_ENTER_GETEVENTS*/ 1ul, /*sigmask=*/0ul, /*size=*/0ul); } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*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=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; loop(); return 0; }