Skip to content

Commit de91673

Browse files
GustavoARSilvagregkh
authored andcommitted
misc: hmc6352: fix potential Spectre v1
val is indirectly controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability. This issue was detected with the help of Smatch: drivers/misc/hmc6352.c:54 compass_store() warn: potential spectre issue 'map' [r] Fix this by sanitizing val before using it to index map Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1]. [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2 Cc: [email protected] Signed-off-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 86503bd commit de91673

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/misc/hmc6352.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/err.h>
2828
#include <linux/delay.h>
2929
#include <linux/sysfs.h>
30+
#include <linux/nospec.h>
3031

3132
static DEFINE_MUTEX(compass_mutex);
3233

@@ -50,6 +51,7 @@ static int compass_store(struct device *dev, const char *buf, size_t count,
5051
return ret;
5152
if (val >= strlen(map))
5253
return -EINVAL;
54+
val = array_index_nospec(val, strlen(map));
5355
mutex_lock(&compass_mutex);
5456
ret = compass_command(c, map[val]);
5557
mutex_unlock(&compass_mutex);

0 commit comments

Comments
 (0)