Commit 589f6b52 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Linus Torvalds

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: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarIan Kent <raven@themaw.net>
Link: https://lkml.kernel.org/r/20200818122203.GO17456@casper.infradead.orgSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 50b7d856
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <linux/compat.h> #include <linux/compat.h>
#include <linux/syscalls.h> #include <linux/syscalls.h>
#include <linux/magic.h> #include <linux/magic.h>
#include <linux/nospec.h>
#include "autofs_i.h" #include "autofs_i.h"
...@@ -563,7 +564,7 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp, ...@@ -563,7 +564,7 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,
static ioctl_fn lookup_dev_ioctl(unsigned int cmd) static ioctl_fn lookup_dev_ioctl(unsigned int cmd)
{ {
static ioctl_fn _ioctls[] = { static const ioctl_fn _ioctls[] = {
autofs_dev_ioctl_version, autofs_dev_ioctl_version,
autofs_dev_ioctl_protover, autofs_dev_ioctl_protover,
autofs_dev_ioctl_protosubver, autofs_dev_ioctl_protosubver,
...@@ -581,7 +582,10 @@ static ioctl_fn lookup_dev_ioctl(unsigned int cmd) ...@@ -581,7 +582,10 @@ static ioctl_fn lookup_dev_ioctl(unsigned int cmd)
}; };
unsigned int idx = cmd_idx(cmd); unsigned int idx = cmd_idx(cmd);
return (idx >= ARRAY_SIZE(_ioctls)) ? NULL : _ioctls[idx]; if (idx >= ARRAY_SIZE(_ioctls))
return NULL;
idx = array_index_nospec(idx, ARRAY_SIZE(_ioctls));
return _ioctls[idx];
} }
/* ioctl dispatcher */ /* ioctl dispatcher */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment