aio: fix spectre gadget in lookup_ioctx

Matthew pointed out that the ioctx_table is susceptible to spectre v1,
because the index can be controlled by an attacker. The below patch
should mitigate the attack for all of the aio system calls.

Cc: stable@vger.kernel.org
Reported-by: Matthew Wilcox <willy@infradead.org>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by Jeff Moyer and committed by Jens Axboe a538e3ff f55adad6

Changed files
+2
fs
+2
fs/aio.c
··· 45 45 46 46 #include <asm/kmap_types.h> 47 47 #include <linux/uaccess.h> 48 + #include <linux/nospec.h> 48 49 49 50 #include "internal.h" 50 51 ··· 1039 1038 if (!table || id >= table->nr) 1040 1039 goto out; 1041 1040 1041 + id = array_index_nospec(id, table->nr); 1042 1042 ctx = rcu_dereference(table->table[id]); 1043 1043 if (ctx && ctx->user_id == ctx_id) { 1044 1044 if (percpu_ref_tryget_live(&ctx->users))