// https://syzkaller.appspot.com/bug?id=baff5bfd0c148e6a6552e815fba942c1ac5e61b0 // 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 #include #include #include #include #include #ifndef __NR_bpf #define __NR_bpf 321 #endif static unsigned long long procid; 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 void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } #define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \ *(type*)(addr) = \ htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \ (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } 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 IORING_SETUP_SQE128 (1U << 10) #define IORING_SETUP_CQE32 (1U << 11) 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 user_addr; }; struct io_cqring_offsets { uint32_t head; uint32_t tail; uint32_t ring_mask; uint32_t ring_entries; uint32_t overflow; uint32_t cqes; uint32_t flags; uint32_t resv1; uint64_t user_addr; }; 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; }; static long io_uring_sqe_size(struct io_uring_params* params) { return SIZEOF_IO_URING_SQE << !!(params->flags & IORING_SETUP_SQE128); } static long io_uring_cqe_size(struct io_uring_params* params) { return SIZEOF_IO_URING_CQE << !!(params->flags & IORING_SETUP_CQE32); } #define IORING_OFF_SQ_RING 0ULL #define IORING_OFF_SQES 0x10000000ULL static long syz_io_uring_setup(volatile long a0, volatile long a1, volatile long a2, volatile long a3, volatile long a4) { uint32_t entries = (uint32_t)a0; struct io_uring_params* setup_params = (struct io_uring_params*)a1; void** ring_params_ptr_out = (void**)a2; void** ring_ptr_out = (void**)a3; void** sqes_ptr_out = (void**)a4; uint32_t fd_io_uring = syscall(__NR_io_uring_setup, entries, setup_params); *ring_params_ptr_out = (void*)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 * io_uring_cqe_size(setup_params); 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 * io_uring_sqe_size(setup_params); *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 < setup_params->sq_entries; index++) array[index] = index; return fd_io_uring; } static long syz_io_uring_submit(volatile long a0, volatile long a1, volatile long a2, volatile long a3) { struct io_uring_params* params = (struct io_uring_params*)a0; char* ring_ptr = (char*)a1; char* sqes_ptr = (char*)a2; char* sqe = (char*)a3; uint32_t sq_ring_mask = *(uint32_t*)(ring_ptr + params->sq_off.ring_mask); uint32_t* sq_tail_ptr = (uint32_t*)(ring_ptr + params->sq_off.tail); uint32_t sq_tail = *sq_tail_ptr & sq_ring_mask; uint32_t sqe_size = io_uring_sqe_size(params); char* sqe_dest = sqes_ptr + sq_tail * sqe_size; memcpy(sqe_dest, sqe, sqe_size); uint32_t sq_tail_next = *sq_tail_ptr + 1; __atomic_store_n(sq_tail_ptr, sq_tail_next, __ATOMIC_RELEASE); return 0; } static long syz_ublk_setup_io_uring(volatile long a0, volatile long a1, volatile long a2, volatile long a3, volatile long a4) { struct io_uring_params* params = (struct io_uring_params*)a1; params->flags |= IORING_SETUP_SQE128 | IORING_SETUP_CQE32; return syz_io_uring_setup(a0, (long)params, a2, a3, a4); } #define UBLK_F_USER_COPY (1UL << 7) #define UBLK_IO_RES_OK 0 #define UBLK_IO_RES_NEED_GET_DATA 1 #define UBLK_IO_COMMIT_AND_FETCH_REQ 0x21 #define UBLK_IO_NEED_GET_DATA 0x22 #define UBLK_U_IO_COMMIT_AND_FETCH_REQ \ _IOWR('u', UBLK_IO_COMMIT_AND_FETCH_REQ, struct ublksrv_io_cmd) #define UBLK_U_IO_NEED_GET_DATA \ _IOWR('u', UBLK_IO_NEED_GET_DATA, struct ublksrv_io_cmd) struct ublksrv_ctrl_cmd { __u32 dev_id; __u16 queue_id; __u16 len; __u64 addr; __u64 data[1]; __u16 dev_path_len; __u16 pad; __u32 reserved; }; struct ublksrv_ctrl_dev_info { __u16 nr_hw_queues; __u16 queue_depth; __u16 state; __u16 pad0; __u32 max_io_buf_bytes; __u32 dev_id; __s32 ublksrv_pid; __u32 pad1; __u64 flags; __u64 ublksrv_flags; __u32 owner_uid; __u32 owner_gid; __u64 reserved1; __u64 reserved2; }; struct ublksrv_io_desc { __u32 op_flags; union { __u32 nr_sectors; __u32 nr_zones; }; __u64 start_sector; __u64 addr; }; struct ublksrv_io_cmd { __u16 q_id; __u16 tag; __s32 result; union { __u64 addr; __u64 zone_append_lba; }; }; struct io_uring_sqe { __u8 opcode; __u8 flags; __u16 ioprio; __s32 fd; union { __u64 off; __u64 addr2; struct { __u32 cmd_op; __u32 __pad1; }; }; union { __u64 addr; __u64 splice_off_in; struct { __u32 level; __u32 optname; }; }; __u32 len; union { __kernel_rwf_t rw_flags; __u32 fsync_flags; __u16 poll_events; __u32 poll32_events; __u32 sync_range_flags; __u32 msg_flags; __u32 timeout_flags; __u32 accept_flags; __u32 cancel_flags; __u32 open_flags; __u32 statx_flags; __u32 fadvise_advice; __u32 splice_flags; __u32 rename_flags; __u32 unlink_flags; __u32 hardlink_flags; __u32 xattr_flags; __u32 msg_ring_flags; __u32 uring_cmd_flags; __u32 waitid_flags; __u32 futex_flags; __u32 install_fd_flags; __u32 nop_flags; __u32 pipe_flags; }; __u64 user_data; union { __u16 buf_index; __u16 buf_group; } __attribute__((packed)); __u16 personality; union { __s32 splice_fd_in; __u32 file_index; __u32 zcrx_ifq_idx; __u32 optlen; struct { __u16 addr_len; __u16 __pad3[1]; }; }; union { struct { __u64 addr3; __u64 __pad2[1]; }; struct { __u64 attr_ptr; __u64 attr_type_mask; }; __u64 optval; __u8 cmd[0]; }; }; static long syz_ublk_add_dev(volatile long a0, volatile long a1, volatile long a2, volatile long a3, volatile long a4, volatile long a5) { __u32 ring_fd = (__u32)a0; struct io_uring_params* params = (struct io_uring_params*)a1; char* ring_ptr = (char*)a2; char* sqes_ptr = (char*)a3; struct io_uring_sqe* sqe = (struct io_uring_sqe*)a4; void** dev_info_ptr_out = (void**)a5; struct ublksrv_ctrl_cmd* cmd = (struct ublksrv_ctrl_cmd*)(sqe->cmd); struct ublksrv_ctrl_dev_info* dev_info = (struct ublksrv_ctrl_dev_info*)(unsigned long)(cmd->addr); dev_info->flags |= UBLK_F_USER_COPY; int ret = syz_io_uring_submit((long)params, (long)ring_ptr, (long)sqes_ptr, (long)sqe); if (ret < 0) return (long)ret; syscall(__NR_io_uring_enter, ring_fd, 1, 1, 1, NULL, _NSIG / 8); *dev_info_ptr_out = (void*)dev_info; return dev_info->dev_id; } struct ublk_queue { __u16 q_id; __u32 char_dev_fd; struct io_uring_params params; __u32 ring_fd; char* ring_ptr; char* sqes_ptr; char* io_cmd_buf; }; #define UBLK_MAX_QUEUE_DEPTH 4096 #define UBLK_QUEUES_OFFSET 0 #define round_up(x, y) (((x) + (y) - 1) / (y) * (y)) static long syz_ublk_setup_queues(volatile long a0, volatile long a1, volatile long a2, volatile long a3, volatile long a4, volatile long a5, volatile long a6) { int char_dev_fd = (int)a0; struct ublksrv_ctrl_dev_info* dev_info = (struct ublksrv_ctrl_dev_info*)a1; struct io_uring_params* params = (struct io_uring_params*)a2; struct ublk_queue* queues = (struct ublk_queue*)a3; int queues_len = (int)a4; struct io_uring_sqe* sqe = (struct io_uring_sqe*)a5; void** queues_ptr_out = (void**)a6; if (char_dev_fd < 0 || !dev_info) return -1; memset(queues, 0, sizeof(struct ublk_queue) * queues_len); int queue_depth = dev_info->queue_depth; for (int q_id = 0; q_id < dev_info->nr_hw_queues; q_id++) { struct ublk_queue* queue = &queues[q_id]; queue->q_id = q_id; queue->char_dev_fd = char_dev_fd; queue->params = *params; struct io_uring_params* temp = NULL; queue->ring_fd = syz_ublk_setup_io_uring( (long)queue_depth, (long)&queue->params, (long)&temp, (long)&queue->ring_ptr, (long)&queue->sqes_ptr); if (queue->ring_fd < 0) { return queue->ring_fd; } unsigned long cmd_buf_size = round_up(queue_depth * sizeof(struct ublksrv_io_desc), getpagesize()); unsigned long off = UBLK_QUEUES_OFFSET + q_id * round_up(UBLK_MAX_QUEUE_DEPTH * sizeof(struct ublksrv_io_desc), getpagesize()); queue->io_cmd_buf = (char*)mmap(0, cmd_buf_size, PROT_READ, MAP_SHARED | MAP_POPULATE, char_dev_fd, off); if (queue->io_cmd_buf == MAP_FAILED) { return -1; } for (int j = 0; j < queue_depth; j++) { struct ublksrv_io_cmd* cmd = (struct ublksrv_io_cmd*)(&sqe->cmd); cmd->q_id = q_id; cmd->tag = j; cmd->addr = 0; sqe->user_data = j | (sqe->cmd_op << 16); if (syz_io_uring_submit((long)&queue->params, (long)queue->ring_ptr, (long)queue->sqes_ptr, (long)sqe) < 0) { return -1; } syscall(__NR_io_uring_enter, queue->ring_fd, 1, 0, 0, NULL, _NSIG / 8); } } *queues_ptr_out = (void*)queues; 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"); } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } int i, call, thread; for (call = 0; call < 8; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } 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[8] = {0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0, 0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: // openat$ttynull arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 74 74 79 6e 75 6c 6c 00} (length 0xd) // } // flags: open_flags = 0x103902 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_tty memcpy((void*)0x200000000000, "/dev/ttynull\000", 13); res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000000ul, /*flags=O_SYNC|O_NONBLOCK|O_NOCTTY|FASYNC|O_RDWR*/ 0x103902, /*mode=*/0); if (res != -1) r[0] = res; break; case 1: // dup arguments: [ // oldfd: fd (resource) // ] // returns fd syscall(__NR_dup, /*oldfd=*/r[0]); break; case 2: // syz_ublk_setup_io_uring arguments: [ // entries: int32 = 0x1d (4 bytes) // params: ptr[inout, io_uring_params] { // io_uring_params { // sq_entries: int32 = 0x0 (4 bytes) // cq_entries: int32 = 0x30b5 (4 bytes) // flags: io_uring_setup_flags = 0x0 (4 bytes) // sq_thread_cpu: int32 = 0x2 (4 bytes) // sq_thread_idle: int32 = 0x95 (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: io_sqring_offsets { // head: int32 = 0x0 (4 bytes) // tail: int32 = 0x0 (4 bytes) // ring_mask: int32 = 0x0 (4 bytes) // ring_entries: int32 = 0x0 (4 bytes) // flags: int32 = 0x0 (4 bytes) // dropped: int32 = 0x0 (4 bytes) // array: int32 = 0x0 (4 bytes) // resv1: int32 = 0x0 (4 bytes) // user_addr: int64 = 0x0 (8 bytes) // } // cq_off: io_cqring_offsets { // head: int32 = 0x0 (4 bytes) // tail: int32 = 0x0 (4 bytes) // ring_mask: int32 = 0x0 (4 bytes) // ring_entries: int32 = 0x0 (4 bytes) // overflow: int32 = 0x0 (4 bytes) // cqes: int32 = 0x0 (4 bytes) // flags: int32 = 0x0 (4 bytes) // resv1: int32 = 0x0 (4 bytes) // user_addr: int64 = 0x0 (8 bytes) // } // } // } // ring_params_ptr: ptr[out, ring_params_ptr] { // ring_params_ptr (resource) // } // ring_ptr: ptr[out, ring_ptr] { // ring_ptr (resource) // } // sqes_ptr: ptr[out, sqes_ptr] { // sqes_ptr (resource) // } // ] // returns fd_io_uring *(uint32_t*)0x200000000044 = 0x30b5; *(uint32_t*)0x200000000048 = 0; *(uint32_t*)0x20000000004c = 2; *(uint32_t*)0x200000000050 = 0x95; *(uint32_t*)0x200000000058 = -1; memset((void*)0x20000000005c, 0, 12); res = -1; res = syz_ublk_setup_io_uring(/*entries=*/0x1d, /*params=*/0x200000000040, /*ring_params_ptr=*/0x200000000100, /*ring_ptr=*/0x200000000280, /*sqes_ptr=*/0x200000000140); if (res != -1) { r[1] = res; r[2] = *(uint64_t*)0x200000000100; r[3] = *(uint64_t*)0x200000000280; r[4] = *(uint64_t*)0x200000000140; } break; case 3: // syz_ublk_add_dev arguments: [ // fd_io_uring: fd_io_uring (resource) // ring_params_ptr: ring_params_ptr (resource) // ring_ptr: ring_ptr (resource) // sqes_ptr: sqes_ptr (resource) // sqe: ptr[inout, io_uring_sqe_uring[fd_ublk_ctrl, // const[UBLK_U_CMD_ADD_DEV, int32], ublk_ctrl_cmd$add_dev, int64]] { // io_uring_sqe_uring[fd_ublk_ctrl, const[UBLK_U_CMD_ADD_DEV, int32], // ublk_ctrl_cmd$add_dev, int64] { // opcode: const = 0x2e (1 bytes) // flags: iosqe_flags = 0x14 (1 bytes) // ioprio: const = 0x0 (2 bytes) // fd: fd_ublk_ctrl (resource) // cmd_op: const = 0xc0207504 (4 bytes) // pad1: const = 0x0 (4 bytes) // addr: const = 0x0 (8 bytes) // len: const = 0x0 (4 bytes) // uring_flags: uring_cmd_flags = 0x0 (4 bytes) // user_data: int64 = 0x4 (8 bytes) // buf_index_unused: const = 0x0 (2 bytes) // ioring_personality_id: ioring_personality_id (resource) // pad_unused: buffer: {00 00 00 00} (length 0x4) // cmd: ublk_ctrl_cmd[const[-1, int32], len[addr, int16], ptr64[in, // ublk_ctrl_dev_info_new], const[0, int64]] { // dev_id: const = 0xffffffff (4 bytes) // queue_id: const = 0xffff (2 bytes) // len: len = 0x40 (2 bytes) // addr: ptr[in, ublk_ctrl_dev_info_new] { // union ublk_ctrl_dev_info_new { // any_dev: ublk_ctrl_dev_info[int32] { // nr_hw_queues: int16 = 0x3 (2 bytes) // queue_depth: int16 = 0xe26 (2 bytes) // state: const = 0x0 (2 bytes) // pad0: const = 0x0 (2 bytes) // max_io_buf_bytes: const = 0x1000 (4 bytes) // dev_id: int32 = 0x10010001 (4 bytes) // ublk_pid: pid (resource) // pad1: const = 0x0 (4 bytes) // flags: ublk_f_flags = 0xcd (8 bytes) // ublk_flags: const = 0x0 (8 bytes) // owner_uid: const = 0x0 (4 bytes) // owner_gid: const = 0x0 (4 bytes) // reserved1: const = 0x0 (8 bytes) // reserved2: const = 0x0 (8 bytes) // } // } // } // data: const = 0x0 (8 bytes) // dev_path_len: const = 0x0 (2 bytes) // pad: const = 0x0 (2 bytes) // reserved: const = 0x0 (4 bytes) // pad2_unused: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00} (length 0x30) // } // } // } // dev_info_ptr: ptr[out, dev_info_ptr] { // dev_info_ptr (resource) // } // ] // returns ublk_dev_id *(uint8_t*)0x2000000003c0 = 0x2e; *(uint8_t*)0x2000000003c1 = 0x14; *(uint16_t*)0x2000000003c2 = 0; *(uint32_t*)0x2000000003c4 = -1; *(uint32_t*)0x2000000003c8 = 0xc0207504; *(uint32_t*)0x2000000003cc = 0; *(uint64_t*)0x2000000003d0 = 0; *(uint32_t*)0x2000000003d8 = 0; *(uint32_t*)0x2000000003dc = 0; *(uint64_t*)0x2000000003e0 = 4; *(uint16_t*)0x2000000003e8 = 0; *(uint16_t*)0x2000000003ea = 0; memset((void*)0x2000000003ec, 0, 4); *(uint32_t*)0x2000000003f0 = -1; *(uint16_t*)0x2000000003f4 = -1; *(uint16_t*)0x2000000003f6 = 0x40; *(uint64_t*)0x2000000003f8 = 0x2000000004c0; *(uint16_t*)0x2000000004c0 = 3; *(uint16_t*)0x2000000004c2 = 0xe26; *(uint16_t*)0x2000000004c4 = 0; *(uint16_t*)0x2000000004c6 = 0; *(uint32_t*)0x2000000004c8 = 0x1000; *(uint32_t*)0x2000000004cc = 0x10010001; *(uint32_t*)0x2000000004d0 = -1; *(uint32_t*)0x2000000004d4 = 0; *(uint64_t*)0x2000000004d8 = 0xcd; *(uint64_t*)0x2000000004e0 = 0; *(uint32_t*)0x2000000004e8 = 0; *(uint32_t*)0x2000000004ec = 0; *(uint64_t*)0x2000000004f0 = 0; *(uint64_t*)0x2000000004f8 = 0; *(uint64_t*)0x200000000400 = 0; *(uint16_t*)0x200000000408 = 0; *(uint16_t*)0x20000000040a = 0; *(uint32_t*)0x20000000040c = 0; memset((void*)0x200000000410, 0, 48); res = -1; res = syz_ublk_add_dev(/*fd_io_uring=*/r[1], /*ring_params_ptr=*/r[2], /*ring_ptr=*/r[3], /*sqes_ptr=*/r[4], /*sqe=*/0x2000000003c0, /*dev_info_ptr=*/0x200000000480); if (res != -1) r[5] = *(uint64_t*)0x200000000480; break; case 4: // socket$inet6_tcp arguments: [ // domain: const = 0xa (8 bytes) // type: const = 0x1 (8 bytes) // proto: const = 0x0 (4 bytes) // ] // returns sock_tcp6 res = syscall(__NR_socket, /*domain=*/0xaul, /*type=*/1ul, /*proto=*/0); if (res != -1) r[6] = res; break; case 5: // dup arguments: [ // oldfd: fd (resource) // ] // returns fd res = syscall(__NR_dup, /*oldfd=*/r[6]); if (res != -1) r[7] = res; break; case 6: // syz_ublk_setup_queues arguments: [ // fd_ublk_ch: fd_ublk_ch (resource) // dev_info_ptr: dev_info_ptr (resource) // params: ptr[in, io_uring_params] { // io_uring_params { // sq_entries: int32 = 0x0 (4 bytes) // cq_entries: int32 = 0x1 (4 bytes) // flags: io_uring_setup_flags = 0x0 (4 bytes) // sq_thread_cpu: int32 = 0x3 (4 bytes) // sq_thread_idle: int32 = 0x257 (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: io_sqring_offsets { // head: int32 = 0x0 (4 bytes) // tail: int32 = 0x0 (4 bytes) // ring_mask: int32 = 0x0 (4 bytes) // ring_entries: int32 = 0x0 (4 bytes) // flags: int32 = 0x0 (4 bytes) // dropped: int32 = 0x0 (4 bytes) // array: int32 = 0x0 (4 bytes) // resv1: int32 = 0x0 (4 bytes) // user_addr: int64 = 0x0 (8 bytes) // } // cq_off: io_cqring_offsets { // head: int32 = 0x0 (4 bytes) // tail: int32 = 0x0 (4 bytes) // ring_mask: int32 = 0x0 (4 bytes) // ring_entries: int32 = 0x0 (4 bytes) // overflow: int32 = 0x0 (4 bytes) // cqes: int32 = 0x0 (4 bytes) // flags: int32 = 0x0 (4 bytes) // resv1: int32 = 0x0 (4 bytes) // user_addr: int64 = 0x0 (8 bytes) // } // } // } // queues: ptr[out, array[ublk_queue]] { // array[ublk_queue] { // ublk_queue { // queue_id: int16 = 0x0 (2 bytes) // pad1: const = 0x0 (2 bytes) // fd_ublk_ch: fd_ublk_ch (resource) // params: io_uring_params { // sq_entries: int32 = 0x0 (4 bytes) // cq_entries: int32 = 0x7ffffe (4 bytes) // flags: io_uring_setup_flags = 0x8 (4 bytes) // sq_thread_cpu: int32 = 0x2000 (4 bytes) // sq_thread_idle: int32 = 0x10000004 (4 bytes) // features: int32 = 0x0 (4 bytes) // wq_fd: fd_io_uring (resource) // resv: buffer: (DirOut) // sq_off: io_sqring_offsets { // head: int32 = 0x0 (4 bytes) // tail: int32 = 0x0 (4 bytes) // ring_mask: int32 = 0x0 (4 bytes) // ring_entries: int32 = 0x0 (4 bytes) // flags: int32 = 0x0 (4 bytes) // dropped: int32 = 0x0 (4 bytes) // array: int32 = 0x0 (4 bytes) // resv1: int32 = 0x0 (4 bytes) // user_addr: int64 = 0x0 (8 bytes) // } // cq_off: io_cqring_offsets { // head: int32 = 0x0 (4 bytes) // tail: int32 = 0x0 (4 bytes) // ring_mask: int32 = 0x0 (4 bytes) // ring_entries: int32 = 0x0 (4 bytes) // overflow: int32 = 0x0 (4 bytes) // cqes: int32 = 0x0 (4 bytes) // flags: int32 = 0x0 (4 bytes) // resv1: int32 = 0x0 (4 bytes) // user_addr: int64 = 0x0 (8 bytes) // } // } // ring_fd: fd_io_uring (resource) // pad2: const = 0x0 (4 bytes) // ring_ptr: ring_ptr (resource) // sqes_ptr: sqes_ptr (resource) // io_cmd_buf: intptr = 0x0 (8 bytes) // } // ublk_queue { // queue_id: int16 = 0x0 (2 bytes) // pad1: const = 0x0 (2 bytes) // fd_ublk_ch: fd_ublk_ch (resource) // params: io_uring_params { // sq_entries: int32 = 0x0 (4 bytes) // cq_entries: int32 = 0x35bc (4 bytes) // flags: io_uring_setup_flags = 0x1 (4 bytes) // sq_thread_cpu: int32 = 0xfffffffd (4 bytes) // sq_thread_idle: int32 = 0x30b (4 bytes) // features: int32 = 0x0 (4 bytes) // wq_fd: fd_io_uring (resource) // resv: buffer: (DirOut) // sq_off: io_sqring_offsets { // head: int32 = 0x0 (4 bytes) // tail: int32 = 0x0 (4 bytes) // ring_mask: int32 = 0x0 (4 bytes) // ring_entries: int32 = 0x0 (4 bytes) // flags: int32 = 0x0 (4 bytes) // dropped: int32 = 0x0 (4 bytes) // array: int32 = 0x0 (4 bytes) // resv1: int32 = 0x0 (4 bytes) // user_addr: int64 = 0x0 (8 bytes) // } // cq_off: io_cqring_offsets { // head: int32 = 0x0 (4 bytes) // tail: int32 = 0x0 (4 bytes) // ring_mask: int32 = 0x0 (4 bytes) // ring_entries: int32 = 0x0 (4 bytes) // overflow: int32 = 0x0 (4 bytes) // cqes: int32 = 0x0 (4 bytes) // flags: int32 = 0x0 (4 bytes) // resv1: int32 = 0x0 (4 bytes) // user_addr: int64 = 0x0 (8 bytes) // } // } // ring_fd: fd_io_uring (resource) // pad2: const = 0x0 (4 bytes) // ring_ptr: ring_ptr (resource) // sqes_ptr: sqes_ptr (resource) // io_cmd_buf: intptr = 0x0 (8 bytes) // } // ublk_queue { // queue_id: int16 = 0x0 (2 bytes) // pad1: const = 0x0 (2 bytes) // fd_ublk_ch: fd_ublk_ch (resource) // params: io_uring_params { // sq_entries: int32 = 0x0 (4 bytes) // cq_entries: int32 = 0xc1cf (4 bytes) // flags: io_uring_setup_flags = 0x0 (4 bytes) // sq_thread_cpu: int32 = 0x0 (4 bytes) // sq_thread_idle: int32 = 0x1f0 (4 bytes) // features: int32 = 0x0 (4 bytes) // wq_fd: fd_io_uring (resource) // resv: buffer: (DirOut) // sq_off: io_sqring_offsets { // head: int32 = 0x0 (4 bytes) // tail: int32 = 0x0 (4 bytes) // ring_mask: int32 = 0x0 (4 bytes) // ring_entries: int32 = 0x0 (4 bytes) // flags: int32 = 0x0 (4 bytes) // dropped: int32 = 0x0 (4 bytes) // array: int32 = 0x0 (4 bytes) // resv1: int32 = 0x0 (4 bytes) // user_addr: int64 = 0x0 (8 bytes) // } // cq_off: io_cqring_offsets { // head: int32 = 0x0 (4 bytes) // tail: int32 = 0x0 (4 bytes) // ring_mask: int32 = 0x0 (4 bytes) // ring_entries: int32 = 0x0 (4 bytes) // overflow: int32 = 0x0 (4 bytes) // cqes: int32 = 0x0 (4 bytes) // flags: int32 = 0x0 (4 bytes) // resv1: int32 = 0x0 (4 bytes) // user_addr: int64 = 0x0 (8 bytes) // } // } // ring_fd: fd_io_uring (resource) // pad2: const = 0x0 (4 bytes) // ring_ptr: ring_ptr (resource) // sqes_ptr: sqes_ptr (resource) // io_cmd_buf: intptr = 0x0 (8 bytes) // } // ublk_queue { // queue_id: int16 = 0x0 (2 bytes) // pad1: const = 0x0 (2 bytes) // fd_ublk_ch: fd_ublk_ch (resource) // params: io_uring_params { // sq_entries: int32 = 0x0 (4 bytes) // cq_entries: int32 = 0x0 (4 bytes) // flags: io_uring_setup_flags = 0x8200 (4 bytes) // sq_thread_cpu: int32 = 0x2 (4 bytes) // sq_thread_idle: int32 = 0x367 (4 bytes) // features: int32 = 0x0 (4 bytes) // wq_fd: fd_io_uring (resource) // resv: buffer: (DirOut) // sq_off: io_sqring_offsets { // head: int32 = 0x0 (4 bytes) // tail: int32 = 0x0 (4 bytes) // ring_mask: int32 = 0x0 (4 bytes) // ring_entries: int32 = 0x0 (4 bytes) // flags: int32 = 0x0 (4 bytes) // dropped: int32 = 0x0 (4 bytes) // array: int32 = 0x0 (4 bytes) // resv1: int32 = 0x0 (4 bytes) // user_addr: int64 = 0x0 (8 bytes) // } // cq_off: io_cqring_offsets { // head: int32 = 0x0 (4 bytes) // tail: int32 = 0x0 (4 bytes) // ring_mask: int32 = 0x0 (4 bytes) // ring_entries: int32 = 0x0 (4 bytes) // overflow: int32 = 0x0 (4 bytes) // cqes: int32 = 0x0 (4 bytes) // flags: int32 = 0x0 (4 bytes) // resv1: int32 = 0x0 (4 bytes) // user_addr: int64 = 0x0 (8 bytes) // } // } // ring_fd: fd_io_uring (resource) // pad2: const = 0x0 (4 bytes) // ring_ptr: ring_ptr (resource) // sqes_ptr: sqes_ptr (resource) // io_cmd_buf: intptr = 0x0 (8 bytes) // } // } // } // nr_queues: const = 0x1 (8 bytes) // sqe: ptr[inout, io_uring_sqe_uring[fd_ublk_ch, // const[UBLK_U_IO_FETCH_REQ, int32], ublk_io_cmd$fetch_req, // user_data[UBLK_U_IO_FETCH_REQ]]] { // io_uring_sqe_uring[fd_ublk_ch, const[UBLK_U_IO_FETCH_REQ, int32], // ublk_io_cmd$fetch_req, user_data[UBLK_U_IO_FETCH_REQ]] { // opcode: const = 0x2e (1 bytes) // flags: iosqe_flags = 0x44 (1 bytes) // ioprio: const = 0x0 (2 bytes) // fd: fd_ublk_ch (resource) // cmd_op: const = 0xc0107520 (4 bytes) // pad1: const = 0x0 (4 bytes) // addr: const = 0x0 (8 bytes) // len: const = 0x0 (4 bytes) // uring_flags: uring_cmd_flags = 0x0 (4 bytes) // user_data: user_data[UBLK_U_IO_FETCH_REQ] { // tag: int64 = 0x0 (0 bytes) // cmd: const = 0xc0107520 (0 bytes) // pad: const = 0x0 (8 bytes) // } // buf_index_unused: const = 0x1f (2 bytes) // ioring_personality_id: ioring_personality_id (resource) // pad_unused: buffer: {00 00 00 00} (length 0x4) // cmd: ublk_io_cmd[int16[0:UBLK_MAX_HW_QUEUES], // int16[0:UBLK_MAX_QUEUE_DEPTH], const[0, int32], ptr64[inout, // ublk_io_buf_u]] { // q_id: int16 = 0xfff9 (2 bytes) // tag: int16 = 0x4 (2 bytes) // result: const = 0x0 (4 bytes) // addr: nil // pad: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00} (length 0x40) // } // } // } // ublk_queues_ptr: nil // ] *(uint32_t*)0x200000000184 = 1; *(uint32_t*)0x200000000188 = 0; *(uint32_t*)0x20000000018c = 3; *(uint32_t*)0x200000000190 = 0x257; *(uint32_t*)0x200000000198 = -1; memset((void*)0x20000000019c, 0, 12); *(uint32_t*)0x20000000080c = 0x7ffffe; *(uint32_t*)0x200000000810 = 8; *(uint32_t*)0x200000000814 = 0x2000; *(uint32_t*)0x200000000818 = 0x10000004; *(uint32_t*)0x200000000820 = -1; *(uint32_t*)0x2000000008ac = 0x35bc; *(uint32_t*)0x2000000008b0 = 1; *(uint32_t*)0x2000000008b4 = 0xfffffffd; *(uint32_t*)0x2000000008b8 = 0x30b; *(uint32_t*)0x2000000008c0 = -1; *(uint32_t*)0x20000000094c = 0xc1cf; *(uint32_t*)0x200000000950 = 0; *(uint32_t*)0x200000000954 = 0; *(uint32_t*)0x200000000958 = 0x1f0; *(uint32_t*)0x200000000960 = r[7]; *(uint32_t*)0x2000000009ec = 0; *(uint32_t*)0x2000000009f0 = 0x8200; *(uint32_t*)0x2000000009f4 = 2; *(uint32_t*)0x2000000009f8 = 0x367; *(uint32_t*)0x200000000a00 = -1; *(uint8_t*)0x200000000340 = 0x2e; *(uint8_t*)0x200000000341 = 0x44; *(uint16_t*)0x200000000342 = 0; *(uint32_t*)0x200000000344 = -1; *(uint32_t*)0x200000000348 = 0xc0107520; *(uint32_t*)0x20000000034c = 0; *(uint64_t*)0x200000000350 = 0; *(uint32_t*)0x200000000358 = 0; *(uint32_t*)0x20000000035c = 0; STORE_BY_BITMASK(uint64_t, , 0x200000000360, 0, 0, 16); STORE_BY_BITMASK(uint64_t, , 0x200000000360, 0xc0107520, 16, 32); STORE_BY_BITMASK(uint64_t, , 0x200000000360, 0, 48, 16); *(uint16_t*)0x200000000368 = 0x1f; *(uint16_t*)0x20000000036a = 0; memset((void*)0x20000000036c, 0, 4); *(uint16_t*)0x200000000370 = 0xfff9; *(uint16_t*)0x200000000372 = 4; *(uint32_t*)0x200000000374 = 0; *(uint64_t*)0x200000000378 = 0; memset((void*)0x200000000380, 0, 64); syz_ublk_setup_queues(/*fd_ublk_ch=*/r[7], /*dev_info_ptr=*/r[5], /*params=*/0x200000000180, /*queues=*/0x200000000800, /*nr_queues=*/1, /*sqe=*/0x200000000340, /*ublk_queues_ptr=*/0); break; case 7: // bpf$MAP_CREATE_CONST_STR arguments: [ // cmd: const = 0x0 (8 bytes) // arg: ptr[inout, array[ANYUNION]] { // array[ANYUNION] { // union ANYUNION { // ANYBLOB: buffer: {02 00 00 00 04} (length 0x5) // } // union ANYUNION { // ANYRES32: ANYRES32 (resource) // } // } // } // size: len = 0x48 (8 bytes) // ] // returns fd_bpf_const_str_map memcpy((void*)0x200000000340, "\x02\x00\x00\x00\x04", 5); *(uint32_t*)0x200000000345 = 0; syscall(__NR_bpf, /*cmd=*/0ul, /*arg=*/0x200000000340ul, /*size=*/0x48ul); break; } } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*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=*/0x200001000000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; for (procid = 0; procid < 5; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }