···240240 /* fixed must be grabbed every time since we drop the uring_lock */241241 if ((cd->flags & IORING_ASYNC_CANCEL_FD) &&242242 (cd->flags & IORING_ASYNC_CANCEL_FD_FIXED)) {243243- if (unlikely(fd >= ctx->file_table.data.nr))243243+ struct io_rsrc_node *node;244244+245245+ node = io_rsrc_node_lookup(&ctx->file_table.data, fd);246246+ if (unlikely(!node))244247 return -EBADF;245245- fd = array_index_nospec(fd, ctx->file_table.data.nr);246246- cd->file = io_file_from_index(&ctx->file_table, fd);248248+ cd->file = io_slot_file(node);247249 if (!cd->file)248250 return -EBADF;249251 }
+9-7
io_uring/filetable.c
···5858 u32 slot_index)5959 __must_hold(&req->ctx->uring_lock)6060{6161- struct io_rsrc_node *node;6161+ struct io_rsrc_node *node, *old_node;62626363 if (io_is_uring_fops(file))6464 return -EBADF;···7171 if (!node)7272 return -ENOMEM;73737474- slot_index = array_index_nospec(slot_index, ctx->file_table.data.nr);7575- if (ctx->file_table.data.nodes[slot_index])7676- io_put_rsrc_node(ctx->file_table.data.nodes[slot_index]);7474+ old_node = io_rsrc_node_lookup(&ctx->file_table.data, slot_index);7575+ if (old_node)7676+ io_put_rsrc_node(old_node);7777 else7878 io_file_bitmap_set(&ctx->file_table, slot_index);7979···123123124124int io_fixed_fd_remove(struct io_ring_ctx *ctx, unsigned int offset)125125{126126+ struct io_rsrc_node *node;127127+126128 if (unlikely(!ctx->file_table.data.nr))127129 return -ENXIO;128130 if (offset >= ctx->file_table.data.nr)129131 return -EINVAL;130132131131- offset = array_index_nospec(offset, ctx->file_table.data.nr);132132- if (!ctx->file_table.data.nodes[offset])133133+ node = io_rsrc_node_lookup(&ctx->file_table.data, offset);134134+ if (!node)133135 return -EBADF;134134- io_put_rsrc_node(ctx->file_table.data.nodes[offset]);136136+ io_put_rsrc_node(node);135137 ctx->file_table.data.nodes[offset] = NULL;136138 io_file_bitmap_clear(&ctx->file_table, offset);137139 return 0;