Commit 1d6d8e6a authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Kleber Sacilotto de Souza

misc: hmc6352: fix potential Spectre v1

BugLink: https://bugs.launchpad.net/bugs/1798587

commit de916736 upstream.

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: stable@vger.kernel.org
Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 98135552
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/err.h> #include <linux/err.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include <linux/nospec.h>
static DEFINE_MUTEX(compass_mutex); static DEFINE_MUTEX(compass_mutex);
...@@ -50,6 +51,7 @@ static int compass_store(struct device *dev, const char *buf, size_t count, ...@@ -50,6 +51,7 @@ static int compass_store(struct device *dev, const char *buf, size_t count,
return ret; return ret;
if (val >= strlen(map)) if (val >= strlen(map))
return -EINVAL; return -EINVAL;
val = array_index_nospec(val, strlen(map));
mutex_lock(&compass_mutex); mutex_lock(&compass_mutex);
ret = compass_command(c, map[val]); ret = compass_command(c, map[val]);
mutex_unlock(&compass_mutex); mutex_unlock(&compass_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment