Skip to content

Commit 511abce

Browse files
axboegregkh
authored andcommitted
io_uring: don't rely on weak ->files references
commit 0f21220 upstream. Grab actual references to the files_struct. To avoid circular references issues due to this, we add a per-task note that keeps track of what io_uring contexts a task has used. When the tasks execs or exits its assigned files, we cancel requests based on this tracking. With that, we can grab proper references to the files table, and no longer need to rely on stashing away ring_fd and ring_file to check if the ring_fd may have been closed. Cc: stable@vger.kernel.org # v5.5+ Reviewed-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fdc84c9 commit 511abce

7 files changed

Lines changed: 340 additions & 36 deletions

File tree

‎fs/exec.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include <linux/oom.h>
6363
#include <linux/compat.h>
6464
#include <linux/vmalloc.h>
65+
#include <linux/io_uring.h>
6566

6667
#include <linux/uaccess.h>
6768
#include <asm/mmu_context.h>
@@ -1847,6 +1848,11 @@ static int __do_execve_file(int fd, struct filename *filename,
18471848
* further execve() calls fail. */
18481849
current->flags &= ~PF_NPROC_EXCEEDED;
18491850

1851+
/*
1852+
* Cancel any io_uring activity across execve
1853+
*/
1854+
io_uring_task_cancel();
1855+
18501856
retval = unshare_files(&displaced);
18511857
if (retval)
18521858
goto out_ret;

‎fs/file.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/bitops.h>
1919
#include <linux/spinlock.h>
2020
#include <linux/rcupdate.h>
21+
#include <linux/io_uring.h>
2122

2223
unsigned int sysctl_nr_open __read_mostly = 1024*1024;
2324
unsigned int sysctl_nr_open_min = BITS_PER_LONG;
@@ -439,6 +440,7 @@ void exit_files(struct task_struct *tsk)
439440
struct files_struct * files = tsk->files;
440441

441442
if (files) {
443+
io_uring_files_cancel(files);
442444
task_lock(tsk);
443445
tsk->files = NULL;
444446
task_unlock(tsk);

0 commit comments

Comments
 (0)