From 6737067af0951e0f855f7b41834ecde29e47c1eb Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Sat, 26 Oct 2019 07:22:55 -0600 Subject: [PATCH 0691/2944] io_uring: protect fixed file indexing with array_index_nospec() commit b7620121dc04e44ce654297050f9eaf39d414a34 upstream. 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 Signed-off-by: Jens Axboe Signed-off-by: Joseph Qi Reviewed-by: Xiaoguang Wang --- fs/io_uring.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index 9df2689..7da320f 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]; -- 1.8.3.1