Skip to contentSkip to conversation

Harden autofs ioctl table

PATCH Applied Matthew Wilcox 2 participants 2 messages Aug 18, 2020 – Aug 20, 2020 Kernel automounter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Harden autofs 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.

fs/autofs/dev-ioctl.c +6 -2
index 75105f45c51a..322b7dfb4ea0 100644
@@ -8,6 +8,7 @@
 #include <linux/compat.h>
 #include <linux/syscalls.h>
 #include <linux/magic.h>
+#include <linux/nospec.h>
 
 #include "autofs_i.h"
 
@@ -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,
@@ -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 */
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Matthew Wilcox

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.

Thanks Matthew, I certainly want to know about changes to autofs made by others so thanks for sending this to me.

At the same time I need to send my patches via someone else as Linus asked me to do ages ago now.

So, once again Andrew, if you would be so kind as to include this in your tree please.

Ian

Quoted 36 lines
fs/autofs/dev-ioctl.c +2 -1
index 75105f45c51a..322b7dfb4ea0 100644
@@ -8,6 +8,7 @@
 #include <linux/compat.h>
 #include <linux/syscalls.h>
 #include <linux/magic.h>
+#include <linux/nospec.h>
 
 #include "autofs_i.h"
 
@@ -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,
fs/autofs/dev-ioctl.c +4 -1
 		autofs_dev_ioctl_protosubver,
@@ -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 */