Skip to content

Commit 94dbb87

Browse files
isilencegregkh
authored andcommitted
io_uring: drop file refs after task cancel
[ 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 <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 501e187 commit 94dbb87

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

‎fs/io_uring.c‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8821,6 +8821,15 @@ static void io_uring_attempt_task_drop(struct file *file)
88218821
io_uring_del_task_file(file);
88228822
}
88238823

8824+
static void io_uring_remove_task_files(struct io_uring_task *tctx)
8825+
{
8826+
struct file *file;
8827+
unsigned long index;
8828+
8829+
xa_for_each(&tctx->xa, index, file)
8830+
io_uring_del_task_file(file);
8831+
}
8832+
88248833
void __io_uring_files_cancel(struct files_struct *files)
88258834
{
88268835
struct io_uring_task *tctx = current->io_uring;
@@ -8829,16 +8838,12 @@ void __io_uring_files_cancel(struct files_struct *files)
88298838

88308839
/* make sure overflow events are dropped */
88318840
atomic_inc(&tctx->in_idle);
8832-
8833-
xa_for_each(&tctx->xa, index, file) {
8834-
struct io_ring_ctx *ctx = file->private_data;
8835-
8836-
io_uring_cancel_task_requests(ctx, files);
8837-
if (files)
8838-
io_uring_del_task_file(file);
8839-
}
8840-
8841+
xa_for_each(&tctx->xa, index, file)
8842+
io_uring_cancel_task_requests(file->private_data, files);
88418843
atomic_dec(&tctx->in_idle);
8844+
8845+
if (files)
8846+
io_uring_remove_task_files(tctx);
88428847
}
88438848

88448849
static s64 tctx_inflight(struct io_uring_task *tctx)
@@ -8901,6 +8906,8 @@ void __io_uring_task_cancel(void)
89018906

89028907
finish_wait(&tctx->wait, &wait);
89038908
atomic_dec(&tctx->in_idle);
8909+
8910+
io_uring_remove_task_files(tctx);
89048911
}
89058912

89068913
static int io_uring_flush(struct file *file, void *data)

0 commit comments

Comments
 (0)