io_uring: protect fixed file indexing with array_index_nospec()

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>
This commit is contained in:
Jens Axboe 2019-10-26 07:22:55 -06:00
Родитель 17f2fe35d0
Коммит b7620121dc
1 изменённых файлов: 1 добавлений и 0 удалений

Просмотреть файл

@ -2321,6 +2321,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];