[PATCH 3.16 061/202] ipmi: msghandler: Fix potential Spectre v1 vulnerabilities

From: Ben Hutchings
Date: Sat Apr 27 2019 - 11:19:15 EST


3.16.66-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "Gustavo A. R. Silva" <gustavo@xxxxxxxxxxxxxx>

commit a7102c7461794a5bb31af24b08e9e0f50038897a upstream.

channel and addr->channel are indirectly controlled by user-space,
hence leading to a potential exploitation of the Spectre variant 1
vulnerability.

These issues were detected with the help of Smatch:

drivers/char/ipmi/ipmi_msghandler.c:1381 ipmi_set_my_address() warn: potential spectre issue 'user->intf->addrinfo' [w] (local cap)
drivers/char/ipmi/ipmi_msghandler.c:1401 ipmi_get_my_address() warn: potential spectre issue 'user->intf->addrinfo' [r] (local cap)
drivers/char/ipmi/ipmi_msghandler.c:1421 ipmi_set_my_LUN() warn: potential spectre issue 'user->intf->addrinfo' [w] (local cap)
drivers/char/ipmi/ipmi_msghandler.c:1441 ipmi_get_my_LUN() warn: potential spectre issue 'user->intf->addrinfo' [r] (local cap)
drivers/char/ipmi/ipmi_msghandler.c:2260 check_addr() warn: potential spectre issue 'intf->addrinfo' [r] (local cap)

Fix this by sanitizing channel and addr->channel before using them to
index user->intf->addrinfo and intf->addrinfo, correspondingly.

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://lore.kernel.org/lkml/20180423164740.GY17484@xxxxxxxxxxxxxx/

Signed-off-by: Gustavo A. R. Silva <gustavo@xxxxxxxxxxxxxx>
Signed-off-by: Corey Minyard <cminyard@xxxxxxxxxx>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@xxxxxxxxxxxxxxx>
---
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -46,6 +46,7 @@
#include <linux/proc_fs.h>
#include <linux/rcupdate.h>
#include <linux/interrupt.h>
+#include <linux/nospec.h>

#define PFX "IPMI message handler: "

@@ -1116,6 +1117,7 @@ int ipmi_set_my_address(ipmi_user_t us
{
if (channel >= IPMI_MAX_CHANNELS)
return -EINVAL;
+ channel = array_index_nospec(channel, IPMI_MAX_CHANNELS);
user->intf->channels[channel].address = address;
return 0;
}
@@ -1127,6 +1129,7 @@ int ipmi_get_my_address(ipmi_user_t us
{
if (channel >= IPMI_MAX_CHANNELS)
return -EINVAL;
+ channel = array_index_nospec(channel, IPMI_MAX_CHANNELS);
*address = user->intf->channels[channel].address;
return 0;
}
@@ -1138,6 +1141,7 @@ int ipmi_set_my_LUN(ipmi_user_t user,
{
if (channel >= IPMI_MAX_CHANNELS)
return -EINVAL;
+ channel = array_index_nospec(channel, IPMI_MAX_CHANNELS);
user->intf->channels[channel].lun = LUN & 0x3;
return 0;
}
@@ -1149,6 +1153,7 @@ int ipmi_get_my_LUN(ipmi_user_t user,
{
if (channel >= IPMI_MAX_CHANNELS)
return -EINVAL;
+ channel = array_index_nospec(channel, IPMI_MAX_CHANNELS);
*address = user->intf->channels[channel].lun;
return 0;
}
@@ -1875,6 +1880,7 @@ static int check_addr(ipmi_smi_t i
{
if (addr->channel >= IPMI_MAX_CHANNELS)
return -EINVAL;
+ addr->channel = array_index_nospec(addr->channel, IPMI_MAX_CHANNELS);
*lun = intf->channels[addr->channel].lun;
*saddr = intf->channels[addr->channel].address;
return 0;