Skip to content

Commit 53262c9

Browse files
committed
io_uring/rsrc: unify nospec indexing for direct descriptors
For file updates, the node reset isn't capping the value via array_index_nospec() like the other paths do. Ensure it's all sane and have the update path do the proper capping as well. Reviewed-by: Gabriel Krisman Bertazi <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 8e1f412 commit 53262c9

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

io_uring/rsrc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
238238
continue;
239239

240240
i = up->offset + done;
241+
if (i >= ctx->file_table.data.nr)
242+
break;
243+
i = array_index_nospec(i, ctx->file_table.data.nr);
241244
if (io_reset_rsrc_node(ctx, &ctx->file_table.data, i))
242245
io_file_bitmap_clear(&ctx->file_table, i);
243246

io_uring/rsrc.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,15 @@ static inline void io_put_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node
109109
}
110110

111111
static inline bool io_reset_rsrc_node(struct io_ring_ctx *ctx,
112-
struct io_rsrc_data *data, int index)
112+
struct io_rsrc_data *data,
113+
unsigned int index)
113114
{
114-
struct io_rsrc_node *node = data->nodes[index];
115+
struct io_rsrc_node *node;
115116

117+
if (index >= data->nr)
118+
return false;
119+
index = array_index_nospec(index, data->nr);
120+
node = data->nodes[index];
116121
if (!node)
117122
return false;
118123
io_put_rsrc_node(ctx, node);

0 commit comments

Comments
 (0)