All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Stephen  Bates" <sbates@raithlin.com>
To: "linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>,
	"mark.rutland@arm.com" <mark.rutland@arm.com>,
	"shhuiw@foxmail.com" <shhuiw@foxmail.com>,
	Logan Gunthorpe <logang@deltatee.com>,
	"viro@zeniv.linux.org.uk" <viro@zeniv.linux.org.uk>
Subject: [PATCH] io_uring: fix SQPOLL cpu check
Date: Tue, 11 Jun 2019 23:56:06 +0000	[thread overview]
Message-ID: <5D2859FE-DB39-48F5-BBB5-6EDD3791B6C3@raithlin.com> (raw)

The array_index_nospec() check in io_sq_offload_start() is performed
before any checks on p->sq_thread_cpu are done. This means cpu is
clamped and therefore no error occurs when out-of-range values are
passed in from userspace. This is in violation of the specification
for io_ring_setup() and causes the io_ring_setup unit test in liburing
to regress.

Add a new bounds check on sq_thread_cpu at the start of
io_sq_offload_start() so we can exit the function early when bad
values are passed in.

Fixes: 975554b03edd ("io_uring: fix SQPOLL cpu validation")
Signed-off-by: Stephen Bates <sbates@raithlin.com>
---
 fs/io_uring.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 30a5687..e458470 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2316,6 +2316,9 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx,
 {
 	int ret;
 
+	if (p->sq_thread_cpu >= nr_cpu_ids)
+		return -EINVAL;
+
 	init_waitqueue_head(&ctx->sqo_wait);
 	mmgrab(current->mm);
 	ctx->sqo_mm = current->mm;
-- 
2.7.4


             reply	other threads:[~2019-06-11 23:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-11 23:56 Stephen  Bates [this message]
2019-06-12  9:24 ` [PATCH] io_uring: fix SQPOLL cpu check Mark Rutland
2019-06-12  9:47   ` Stephen  Bates
2019-06-13  8:54     ` Jens Axboe
2019-06-13  9:14       ` Greg Kroah-Hartman
2019-06-13  9:15         ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5D2859FE-DB39-48F5-BBB5-6EDD3791B6C3@raithlin.com \
    --to=sbates@raithlin.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=logang@deltatee.com \
    --cc=mark.rutland@arm.com \
    --cc=shhuiw@foxmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.