summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordy Zomer <jordy@jordyzomer.github.io>2022-01-29 15:58:39 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-04-15 14:15:02 +0200
commit7ae2c5b89da3cfaf856df880af27d3bb32a74b3d (patch)
tree44c1a67aa5df39bdc621975c4cc51ede35281911
parent75517bd7e4afad5a800b4d14f80aa7e6f73a9681 (diff)
downloadlinux-stable-7ae2c5b89da3cfaf856df880af27d3bb32a74b3d.tar.gz
linux-stable-7ae2c5b89da3cfaf856df880af27d3bb32a74b3d.tar.bz2
linux-stable-7ae2c5b89da3cfaf856df880af27d3bb32a74b3d.zip
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>
-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 17cbad58834f..0aae4a46db66 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -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>
@@ -1670,6 +1671,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;
}