Skip to content

Commit a538e3f

Browse files
JeffMoyeraxboe
authored andcommitted
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>
1 parent f55adad commit a538e3f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/aio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
#include <asm/kmap_types.h>
4747
#include <linux/uaccess.h>
48+
#include <linux/nospec.h>
4849

4950
#include "internal.h"
5051

@@ -1038,6 +1039,7 @@ static struct kioctx *lookup_ioctx(unsigned long ctx_id)
10381039
if (!table || id >= table->nr)
10391040
goto out;
10401041

1042+
id = array_index_nospec(id, table->nr);
10411043
ctx = rcu_dereference(table->table[id]);
10421044
if (ctx && ctx->user_id == ctx_id) {
10431045
if (percpu_ref_tryget_live(&ctx->users))

0 commit comments

Comments
 (0)