Skip to content

Commit 0f21220

Browse files
committed
io_uring: don't rely on weak ->files references
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: [email protected] # v5.5+ Reviewed-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent e6c8aa9 commit 0f21220

File tree

7 files changed

+344
-37
lines changed

7 files changed

+344
-37
lines changed

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>
@@ -1895,6 +1896,11 @@ static int bprm_execve(struct linux_binprm *bprm,
18951896
struct files_struct *displaced;
18961897
int retval;
18971898

1899+
/*
1900+
* Cancel any io_uring activity across execve
1901+
*/
1902+
io_uring_task_cancel();
1903+
18981904
retval = unshare_files(&displaced);
18991905
if (retval)
19001906
return retval;

fs/file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/rcupdate.h>
2222
#include <linux/close_range.h>
2323
#include <net/sock.h>
24+
#include <linux/io_uring.h>
2425

2526
unsigned int sysctl_nr_open __read_mostly = 1024*1024;
2627
unsigned int sysctl_nr_open_min = BITS_PER_LONG;
@@ -452,6 +453,7 @@ void exit_files(struct task_struct *tsk)
452453
struct files_struct * files = tsk->files;
453454

454455
if (files) {
456+
io_uring_files_cancel(files);
455457
task_lock(tsk);
456458
tsk->files = NULL;
457459
task_unlock(tsk);

0 commit comments

Comments
 (0)