dm ioctl: prevent potential spectre v1 gadget
authorJordy Zomer <jordy@jordyzomer.github.io>
Sat, 29 Jan 2022 14:58:39 +0000 (15:58 +0100)
committerMike Snitzer <snitzer@redhat.com>
Tue, 22 Feb 2022 16:04:41 +0000 (11:04 -0500)
It appears like cmd could be a Spectre v1 gadget as it's supplied by a
user and used as an array index. Prevent the contents of kernel memory
from being leaked to userspace via speculative execution by using
array_index_nospec.

Signed-off-by: Jordy Zomer <jordy@pwning.systems>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-ioctl.c

index 21fe8652b095bd1f517aa43c31ce50bd5a572b67..901abd6dea41972a2eb9079e9a353268d0c0ee1c 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/dm-ioctl.h>
 #include <linux/hdreg.h>
 #include <linux/compat.h>
+#include <linux/nospec.h>
 
 #include <linux/uaccess.h>
 #include <linux/ima.h>
@@ -1788,6 +1789,7 @@ static ioctl_fn lookup_ioctl(unsigned int cmd, int *ioctl_flags)
        if (unlikely(cmd >= ARRAY_SIZE(_ioctls)))
                return NULL;
 
+       cmd = array_index_nospec(cmd, ARRAY_SIZE(_ioctls));
        *ioctl_flags = _ioctls[cmd].flags;
        return _ioctls[cmd].fn;
 }