summaryrefslogtreecommitdiff
path: root/drivers/md
diff options
context:
space:
mode:
authorJordy Zomer <jordy@jordyzomer.github.io>2022-01-29 17:58:39 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-04-20 10:06:42 +0300
commit76c94651005f58885facf9c973007f5ea01ab01f (patch)
tree5e6200a41ac1001740d3ae66911cdce25dbee256 /drivers/md
parentffa0495a506d5edbd1b4ad45a2759bc080856695 (diff)
downloadlinux-76c94651005f58885facf9c973007f5ea01ab01f.tar.xz
dm ioctl: prevent potential spectre v1 gadget
[ 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>
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/dm-ioctl.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index eb2659a12310..70245782e7f6 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -16,6 +16,7 @@
#include <linux/dm-ioctl.h>
#include <linux/hdreg.h>
#include <linux/compat.h>
+#include <linux/nospec.h>
#include <asm/uaccess.h>
@@ -1642,6 +1643,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;
}