All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] io_uring: protect fixed file indexing with array_index_nospec()
@ 2019-10-26 13:51 Jens Axboe
  0 siblings, 0 replies; only message in thread
From: Jens Axboe @ 2019-10-26 13:51 UTC (permalink / raw)
  To: linux-block@vger.kernel.org; +Cc: Jann Horn


We index the file tables with a user given value. After we check
it's within our limits, use array_index_nospec() to prevent any
spectre attacks here.

Suggested-by: Jann Horn <jannh@google.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 4402485f0879..769a8c7eee37 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2320,6 +2320,7 @@ static int io_req_set_file(struct io_ring_ctx *ctx, const struct sqe_submit *s,
 		if (unlikely(!ctx->user_files ||
 		    (unsigned) fd >= ctx->nr_user_files))
 			return -EBADF;
+		fd = array_index_nospec(fd, ctx->nr_user_files);
 		if (!ctx->user_files[fd])
 			return -EBADF;
 		req->file = ctx->user_files[fd];

-- 
Jens Axboe

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-10-26 13:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-26 13:51 [PATCH] io_uring: protect fixed file indexing with array_index_nospec() Jens Axboe

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.