dm ioctl: prevent potential spectre v1 gadget
authorJordy Zomer <jordy@jordyzomer.github.io>
Sat, 29 Jan 2022 14:58:39 +0000 (15:58 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Apr 2022 07:08:27 +0000 (09:08 +0200)
[ Upstream commit cd9c88da171a62c4b0f1c70e50c75845969fbc18 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/md/dm-ioctl.c

index 2f020401d5baa15543bae09bcccee5d10a046ac1..ddfea5324b58890da9fc520c7be25fd511b70fa4 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/dm-ioctl.h>
 #include <linux/hdreg.h>
 #include <linux/compat.h>
+#include <linux/nospec.h>
 
 #include <linux/uaccess.h>
 
@@ -1669,6 +1670,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;
 }