Skip to content

Commit

Permalink
io_uring: reference ->nsproxy for file table commands
Browse files Browse the repository at this point in the history
commit 9b82849 upstream.

If we don't get and assign the namespace for the async work, then certain
paths just don't work properly (like /dev/stdin, /proc/mounts, etc).
Anything that references the current namespace of the given task should
be assigned for async work on behalf of that task.

Cc: stable@vger.kernel.org # v5.5+
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
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 adb6bf5 commit bfa36f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fs/io-wq.c
Expand Up @@ -60,6 +60,7 @@ struct io_worker {
const struct cred *cur_creds;
const struct cred *saved_creds;
struct files_struct *restore_files;
struct nsproxy *restore_nsproxy;
struct fs_struct *restore_fs;
};

Expand Down Expand Up @@ -153,6 +154,7 @@ static bool __io_worker_unuse(struct io_wqe *wqe, struct io_worker *worker)

task_lock(current);
current->files = worker->restore_files;
current->nsproxy = worker->restore_nsproxy;
task_unlock(current);
}

Expand Down Expand Up @@ -318,6 +320,7 @@ static void io_worker_start(struct io_wqe *wqe, struct io_worker *worker)

worker->flags |= (IO_WORKER_F_UP | IO_WORKER_F_RUNNING);
worker->restore_files = current->files;
worker->restore_nsproxy = current->nsproxy;
worker->restore_fs = current->fs;
io_wqe_inc_running(wqe, worker);
}
Expand Down Expand Up @@ -454,6 +457,7 @@ static void io_impersonate_work(struct io_worker *worker,
if (work->files && current->files != work->files) {
task_lock(current);
current->files = work->files;
current->nsproxy = work->nsproxy;
task_unlock(current);
}
if (work->fs && current->fs != work->fs)
Expand Down
1 change: 1 addition & 0 deletions fs/io-wq.h
Expand Up @@ -88,6 +88,7 @@ struct io_wq_work {
struct files_struct *files;
struct mm_struct *mm;
const struct cred *creds;
struct nsproxy *nsproxy;
struct fs_struct *fs;
unsigned long fsize;
unsigned flags;
Expand Down
3 changes: 3 additions & 0 deletions fs/io_uring.c
Expand Up @@ -5678,6 +5678,7 @@ static void io_req_drop_files(struct io_kiocb *req)
spin_unlock_irqrestore(&ctx->inflight_lock, flags);
req->flags &= ~REQ_F_INFLIGHT;
put_files_struct(req->work.files);
put_nsproxy(req->work.nsproxy);
req->work.files = NULL;
}

Expand Down Expand Up @@ -6086,6 +6087,8 @@ static int io_grab_files(struct io_kiocb *req)
return 0;

req->work.files = get_files_struct(current);
get_nsproxy(current->nsproxy);
req->work.nsproxy = current->nsproxy;
req->flags |= REQ_F_INFLIGHT;

spin_lock_irq(&ctx->inflight_lock);
Expand Down

0 comments on commit bfa36f7

Please sign in to comment.