Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76c94651 authored by Jordy Zomer's avatar Jordy Zomer Committed by Greg Kroah-Hartman
Browse files

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: default avatarJordy Zomer <jordy@pwning.systems>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent ffa0495a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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;
}