Skip to content

Commit

Permalink
io_uring: drop file refs after task cancel
Browse files Browse the repository at this point in the history
[ Upstream commit de7f1d9 ]

io_uring fds marked O_CLOEXEC and we explicitly cancel all requests
before going through exec, so we don't want to leave task's file
references to not our anymore io_uring instances.

Signed-off-by: Pavel Begunkov <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
isilence authored and gregkh committed Jan 19, 2021
1 parent 501e187 commit 94dbb87
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -8821,6 +8821,15 @@ static void io_uring_attempt_task_drop(struct file *file)
io_uring_del_task_file(file);
}

static void io_uring_remove_task_files(struct io_uring_task *tctx)
{
struct file *file;
unsigned long index;

xa_for_each(&tctx->xa, index, file)
io_uring_del_task_file(file);
}

void __io_uring_files_cancel(struct files_struct *files)
{
struct io_uring_task *tctx = current->io_uring;
Expand All @@ -8829,16 +8838,12 @@ void __io_uring_files_cancel(struct files_struct *files)

/* make sure overflow events are dropped */
atomic_inc(&tctx->in_idle);

xa_for_each(&tctx->xa, index, file) {
struct io_ring_ctx *ctx = file->private_data;

io_uring_cancel_task_requests(ctx, files);
if (files)
io_uring_del_task_file(file);
}

xa_for_each(&tctx->xa, index, file)
io_uring_cancel_task_requests(file->private_data, files);
atomic_dec(&tctx->in_idle);

if (files)
io_uring_remove_task_files(tctx);
}

static s64 tctx_inflight(struct io_uring_task *tctx)
Expand Down Expand Up @@ -8901,6 +8906,8 @@ void __io_uring_task_cancel(void)

finish_wait(&tctx->wait, &wait);
atomic_dec(&tctx->in_idle);

io_uring_remove_task_files(tctx);
}

static int io_uring_flush(struct file *file, void *data)
Expand Down

0 comments on commit 94dbb87

Please sign in to comment.