Skip to content

Commit a6bded9

Browse files
committed
io_uring/filetable: clamp alloc_hint to the configured alloc range
Explicit fixed file install/remove operations on slots outside the configured alloc range can corrupt alloc_hint via io_file_bitmap_set() and io_file_bitmap_clear(), which unconditionally update alloc_hint to the bit position. This causes subsequent auto-allocations to fall outside the configured range. For example, if the alloc range is [10, 20) and a file is removed at slot 2, alloc_hint gets set to 2. The next auto-alloc then starts searching from slot 2, potentially returning a slot below the range. Fix this by clamping alloc_hint to [file_alloc_start, file_alloc_end) at the top of io_file_bitmap_get() before starting the search. Cc: stable@vger.kernel.org Fixes: 6e73dff ("io_uring: let to set a range for file slot allocation") Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 0efc331 commit a6bded9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

io_uring/filetable.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ static int io_file_bitmap_get(struct io_ring_ctx *ctx)
2222
if (!table->bitmap)
2323
return -ENFILE;
2424

25+
if (table->alloc_hint < ctx->file_alloc_start ||
26+
table->alloc_hint >= ctx->file_alloc_end)
27+
table->alloc_hint = ctx->file_alloc_start;
28+
2529
do {
2630
ret = find_next_zero_bit(table->bitmap, nr, table->alloc_hint);
2731
if (ret != nr)

0 commit comments

Comments
 (0)