Skip to content

Commit

Permalink
io_uring: don't rely on weak ->files references
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
axboe authored and gregkh committed Nov 1, 2020
1 parent eeb3eb7 commit adb6bf5
Show file tree
Hide file tree
Showing 7 changed files with 344 additions and 37 deletions.
6 changes: 6 additions & 0 deletions fs/exec.c
Expand Up @@ -62,6 +62,7 @@
#include <linux/oom.h>
#include <linux/compat.h>
#include <linux/vmalloc.h>
#include <linux/io_uring.h>

#include <linux/uaccess.h>
#include <asm/mmu_context.h>
Expand Down Expand Up @@ -1895,6 +1896,11 @@ static int bprm_execve(struct linux_binprm *bprm,
struct files_struct *displaced;
int retval;

/*
* Cancel any io_uring activity across execve
*/
io_uring_task_cancel();

retval = unshare_files(&displaced);
if (retval)
return retval;
Expand Down
2 changes: 2 additions & 0 deletions fs/file.c
Expand Up @@ -21,6 +21,7 @@
#include <linux/rcupdate.h>
#include <linux/close_range.h>
#include <net/sock.h>
#include <linux/io_uring.h>

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

if (files) {
io_uring_files_cancel(files);
task_lock(tsk);
tsk->files = NULL;
task_unlock(tsk);
Expand Down

0 comments on commit adb6bf5

Please sign in to comment.