Skip to content
/ linux Public

Commit cc54e0e

Browse files
axboeSasha Levin
authored andcommitted
io_uring/openclose: fix io_pipe_fixed() slot tracking for specific slots
[ Upstream commit f4d0668 ] __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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 749b5e6 commit cc54e0e

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
@@ -336,31 +336,34 @@ static int io_pipe_fixed(struct io_kiocb *req, struct file **files,
336336
{
337337
struct io_pipe *p = io_kiocb_to_cmd(req, struct io_pipe);
338338
struct io_ring_ctx *ctx = req->ctx;
339+
bool alloc_slot;
339340
int ret, fds[2] = { -1, -1 };
340341
int slot = p->file_slot;
341342

342343
if (p->flags & O_CLOEXEC)
343344
return -EINVAL;
344345

346+
alloc_slot = slot == IORING_FILE_INDEX_ALLOC;
347+
345348
io_ring_submit_lock(ctx, issue_flags);
346349

347350
ret = __io_fixed_fd_install(ctx, files[0], slot);
348351
if (ret < 0)
349352
goto err;
350-
fds[0] = ret;
353+
fds[0] = alloc_slot ? ret : slot - 1;
351354
files[0] = NULL;
352355

353356
/*
354357
* If a specific slot is given, next one will be used for
355358
* the write side.
356359
*/
357-
if (slot != IORING_FILE_INDEX_ALLOC)
360+
if (!alloc_slot)
358361
slot++;
359362

360363
ret = __io_fixed_fd_install(ctx, files[1], slot);
361364
if (ret < 0)
362365
goto err;
363-
fds[1] = ret;
366+
fds[1] = alloc_slot ? ret : slot - 1;
364367
files[1] = NULL;
365368

366369
io_ring_submit_unlock(ctx, issue_flags);

0 commit comments

Comments
 (0)