io_uring: only allow submit from owning task
authorJens Axboe <axboe@kernel.dk>
Fri, 17 Jan 2020 02:00:24 +0000 (19:00 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Jan 2020 07:22:32 +0000 (08:22 +0100)
commit 44d282796f81eb1debc1d7cb53245b4cb3214cb5 upstream.

If the credentials or the mm doesn't match, don't allow the task to
submit anything on behalf of this ring. The task that owns the ring can
pass the file descriptor to another task, but we don't want to allow
that task to submit an SQE that then assumes the ring mm and creds if
it needs to go async.

Cc: stable@vger.kernel.org
Suggested-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/io_uring.c

index 709671f..b1c9ad1 100644 (file)
@@ -3716,6 +3716,12 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
                        wake_up(&ctx->sqo_wait);
                submitted = to_submit;
        } else if (to_submit) {
+               if (current->mm != ctx->sqo_mm ||
+                   current_cred() != ctx->creds) {
+                       ret = -EPERM;
+                       goto out;
+               }
+
                to_submit = min(to_submit, ctx->sq_entries);
 
                mutex_lock(&ctx->uring_lock);