diff mbox series

[v2,2/2] io_uring: Potential Oops in io_sq_offload_start()

Message ID 20190408081513.GB15239@kadam (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] cpumask: Introduce possible_cpu_safe() | expand

Commit Message

Dan Carpenter April 8, 2019, 8:15 a.m. UTC
The "p->sq_thread_cpu" variable is an integer which comes from the user.
We can't pass values greater than NR_CPUS to cpu_possible() or it could
lead to an out of bound read and possibly an Oops.

The recently added cpu_possible_safe() function can handle unfiltered
input so lets use that instead.  This patch also removes the call to
array_index_nospec() since that is handled in cpu_possible_safe().

Fixes: 6c271ce2f1d5 ("io_uring: add submission polling")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
No change.

 fs/io_uring.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Dan Carpenter April 30, 2019, 9:26 a.m. UTC | #1
The io_uring patches are slated for v5.7 so we should figure out a
solution for this bug.

regrds,
dan carpenter
Dan Carpenter May 3, 2019, 11:43 a.m. UTC | #2
On Tue, Apr 30, 2019 at 12:26:19PM +0300, Dan Carpenter wrote:
> The io_uring patches are slated for v5.7 so we should figure out a
> solution for this bug.
> 

Never mind.  We merged a different fix.  975554b03edd
("io_uring: fix SQPOLL cpu validation").

regards,
dan carpenter
diff mbox series

Patch

diff --git a/fs/io_uring.c b/fs/io_uring.c
index c0fecb9d889f..9789887b0d36 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2240,16 +2240,13 @@  static int io_sq_offload_start(struct io_ring_ctx *ctx,
 		ctx->sq_thread_idle = HZ;
 
 	ret = -EINVAL;
-	if (!cpu_possible(p->sq_thread_cpu))
+	if (!cpu_possible_safe(p->sq_thread_cpu))
 		goto err;
 
 	if (ctx->flags & IORING_SETUP_SQPOLL) {
 		if (p->flags & IORING_SETUP_SQ_AFF) {
-			int cpu;
-
-			cpu = array_index_nospec(p->sq_thread_cpu, NR_CPUS);
 			ctx->sqo_thread = kthread_create_on_cpu(io_sq_thread,
-							ctx, cpu,
+							ctx, p->sq_thread_cpu,
 							"io_uring-sq");
 		} else {
 			ctx->sqo_thread = kthread_create(io_sq_thread, ctx,