Skip to content

Commit 589f6b5

Browse files
Matthew Wilcoxtorvalds
authored andcommitted
autofs: harden ioctl table
The table of ioctl functions should be marked const in order to put them in read-only memory, and we should use array_index_nospec() to avoid speculation disclosing the contents of kernel memory to userspace. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Ian Kent <raven@themaw.net> Link: https://lkml.kernel.org/r/20200818122203.GO17456@casper.infradead.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 50b7d85 commit 589f6b5

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

fs/autofs/dev-ioctl.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/compat.h>
99
#include <linux/syscalls.h>
1010
#include <linux/magic.h>
11+
#include <linux/nospec.h>
1112

1213
#include "autofs_i.h"
1314

@@ -563,7 +564,7 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,
563564

564565
static ioctl_fn lookup_dev_ioctl(unsigned int cmd)
565566
{
566-
static ioctl_fn _ioctls[] = {
567+
static const ioctl_fn _ioctls[] = {
567568
autofs_dev_ioctl_version,
568569
autofs_dev_ioctl_protover,
569570
autofs_dev_ioctl_protosubver,
@@ -581,7 +582,10 @@ static ioctl_fn lookup_dev_ioctl(unsigned int cmd)
581582
};
582583
unsigned int idx = cmd_idx(cmd);
583584

584-
return (idx >= ARRAY_SIZE(_ioctls)) ? NULL : _ioctls[idx];
585+
if (idx >= ARRAY_SIZE(_ioctls))
586+
return NULL;
587+
idx = array_index_nospec(idx, ARRAY_SIZE(_ioctls));
588+
return _ioctls[idx];
585589
}
586590

587591
/* ioctl dispatcher */

0 commit comments

Comments
 (0)