Skip to content

Commit

Permalink
autofs: harden ioctl table
Browse files Browse the repository at this point in the history
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) <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Acked-by: Ian Kent <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Matthew Wilcox authored and torvalds committed Oct 16, 2020
1 parent 50b7d85 commit 589f6b5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fs/autofs/dev-ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <linux/compat.h>
#include <linux/syscalls.h>
#include <linux/magic.h>
#include <linux/nospec.h>

#include "autofs_i.h"

Expand Down Expand Up @@ -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 _ioctls[] = {
static const ioctl_fn _ioctls[] = {
autofs_dev_ioctl_version,
autofs_dev_ioctl_protover,
autofs_dev_ioctl_protosubver,
Expand All @@ -581,7 +582,10 @@ static ioctl_fn lookup_dev_ioctl(unsigned int 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 */
Expand Down

0 comments on commit 589f6b5

Please sign in to comment.