Skip to content

Commit cd9c88d

Browse files
Jordy Zomersnitm
authored andcommitted
dm ioctl: prevent potential spectre v1 gadget
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 <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent a8b9d11 commit cd9c88d

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/md/dm-ioctl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/dm-ioctl.h>
1919
#include <linux/hdreg.h>
2020
#include <linux/compat.h>
21+
#include <linux/nospec.h>
2122

2223
#include <linux/uaccess.h>
2324
#include <linux/ima.h>
@@ -1788,6 +1789,7 @@ static ioctl_fn lookup_ioctl(unsigned int cmd, int *ioctl_flags)
17881789
if (unlikely(cmd >= ARRAY_SIZE(_ioctls)))
17891790
return NULL;
17901791

1792+
cmd = array_index_nospec(cmd, ARRAY_SIZE(_ioctls));
17911793
*ioctl_flags = _ioctls[cmd].flags;
17921794
return _ioctls[cmd].fn;
17931795
}

0 commit comments

Comments
 (0)