Skip to content

Commit f4d0668

Browse files
committed
io_uring/openclose: fix io_pipe_fixed() slot tracking for specific slots
__io_fixed_fd_install() returns 0 on success for non-alloc mode (specific slot), not the slot index. io_pipe_fixed() used this return value directly as the slot index in fds[], which can cause the reported values returned via copy_to_user() to be incorrect, or the error path operating on the incorrect direct descriptor. Fix by computing the actual 0-based slot index (slot - 1) for specific slot mode, while preserving the existing behavior for auto-alloc mode where __io_fixed_fd_install() already returns the allocated index. Cc: stable@vger.kernel.org Fixes: 53db8a7 ("io_uring: add support for IORING_OP_PIPE") Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent a6bded9 commit f4d0668

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

io_uring/openclose.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,31 +345,34 @@ static int io_pipe_fixed(struct io_kiocb *req, struct file **files,
345345
{
346346
struct io_pipe *p = io_kiocb_to_cmd(req, struct io_pipe);
347347
struct io_ring_ctx *ctx = req->ctx;
348+
bool alloc_slot;
348349
int ret, fds[2] = { -1, -1 };
349350
int slot = p->file_slot;
350351

351352
if (p->flags & O_CLOEXEC)
352353
return -EINVAL;
353354

355+
alloc_slot = slot == IORING_FILE_INDEX_ALLOC;
356+
354357
io_ring_submit_lock(ctx, issue_flags);
355358

356359
ret = __io_fixed_fd_install(ctx, files[0], slot);
357360
if (ret < 0)
358361
goto err;
359-
fds[0] = ret;
362+
fds[0] = alloc_slot ? ret : slot - 1;
360363
files[0] = NULL;
361364

362365
/*
363366
* If a specific slot is given, next one will be used for
364367
* the write side.
365368
*/
366-
if (slot != IORING_FILE_INDEX_ALLOC)
369+
if (!alloc_slot)
367370
slot++;
368371

369372
ret = __io_fixed_fd_install(ctx, files[1], slot);
370373
if (ret < 0)
371374
goto err;
372-
fds[1] = ret;
375+
fds[1] = alloc_slot ? ret : slot - 1;
373376
files[1] = NULL;
374377

375378
io_ring_submit_unlock(ctx, issue_flags);

0 commit comments

Comments
 (0)