summaryrefslogtreecommitdiffstats
path: root/drivers/usb/usbip
diff options
context:
space:
mode:
authorGustavo A. R. Silva <gustavo@embeddedor.com>2018-05-18 21:13:42 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-05-24 12:14:28 -0400
commita0d6ec88090d7b1b008429c44532a388e29bb1bd (patch)
treec89de91b9859f2767d7be6ffd6aa89e6009d0c80 /drivers/usb/usbip
parent4a014a7339f441b0851ce012f469c0fadac61c81 (diff)
usbip: vhci_sysfs: fix potential Spectre v1
pdev_nr and rhport can be 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/usb/usbip/vhci_sysfs.c:238 detach_store() warn: potential spectre issue 'vhcis' drivers/usb/usbip/vhci_sysfs.c:328 attach_store() warn: potential spectre issue 'vhcis' drivers/usb/usbip/vhci_sysfs.c:338 attach_store() warn: potential spectre issue 'vhci->vhci_hcd_ss->vdev' drivers/usb/usbip/vhci_sysfs.c:340 attach_store() warn: potential spectre issue 'vhci->vhci_hcd_hs->vdev' Fix this by sanitizing pdev_nr and rhport before using them to index vhcis and vhci->vhci_hcd_ss->vdev respectively. 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: Gustavo A. R. Silva <gustavo@embeddedor.com> Acked-by: Shuah Khan (Samsung OSG) <shuah@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/usbip')
-rw-r--r--drivers/usb/usbip/vhci_sysfs.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/drivers/usb/usbip/vhci_sysfs.c b/drivers/usb/usbip/vhci_sysfs.c
index 48808388ec33..be37aec250c2 100644
--- a/drivers/usb/usbip/vhci_sysfs.c
+++ b/drivers/usb/usbip/vhci_sysfs.c
@@ -10,6 +10,9 @@
10#include <linux/platform_device.h> 10#include <linux/platform_device.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12 12
13/* Hardening for Spectre-v1 */
14#include <linux/nospec.h>
15
13#include "usbip_common.h" 16#include "usbip_common.h"
14#include "vhci.h" 17#include "vhci.h"
15 18
@@ -205,16 +208,20 @@ static int vhci_port_disconnect(struct vhci_hcd *vhci_hcd, __u32 rhport)
205 return 0; 208 return 0;
206} 209}
207 210
208static int valid_port(__u32 pdev_nr, __u32 rhport) 211static int valid_port(__u32 *pdev_nr, __u32 *rhport)
209{ 212{
210 if (pdev_nr >= vhci_num_controllers) { 213 if (*pdev_nr >= vhci_num_controllers) {
211 pr_err("pdev %u\n", pdev_nr); 214 pr_err("pdev %u\n", *pdev_nr);
212 return 0; 215 return 0;
213 } 216 }
214 if (rhport >= VHCI_HC_PORTS) { 217 *pdev_nr = array_index_nospec(*pdev_nr, vhci_num_controllers);
215 pr_err("rhport %u\n", rhport); 218
219 if (*rhport >= VHCI_HC_PORTS) {
220 pr_err("rhport %u\n", *rhport);
216 return 0; 221 return 0;
217 } 222 }
223 *rhport = array_index_nospec(*rhport, VHCI_HC_PORTS);
224
218 return 1; 225 return 1;
219} 226}
220 227
@@ -232,7 +239,7 @@ static ssize_t detach_store(struct device *dev, struct device_attribute *attr,
232 pdev_nr = port_to_pdev_nr(port); 239 pdev_nr = port_to_pdev_nr(port);
233 rhport = port_to_rhport(port); 240 rhport = port_to_rhport(port);
234 241
235 if (!valid_port(pdev_nr, rhport)) 242 if (!valid_port(&pdev_nr, &rhport))
236 return -EINVAL; 243 return -EINVAL;
237 244
238 hcd = platform_get_drvdata(vhcis[pdev_nr].pdev); 245 hcd = platform_get_drvdata(vhcis[pdev_nr].pdev);
@@ -258,7 +265,8 @@ static ssize_t detach_store(struct device *dev, struct device_attribute *attr,
258} 265}
259static DEVICE_ATTR_WO(detach); 266static DEVICE_ATTR_WO(detach);
260 267
261static int valid_args(__u32 pdev_nr, __u32 rhport, enum usb_device_speed speed) 268static int valid_args(__u32 *pdev_nr, __u32 *rhport,
269 enum usb_device_speed speed)
262{ 270{
263 if (!valid_port(pdev_nr, rhport)) { 271 if (!valid_port(pdev_nr, rhport)) {
264 return 0; 272 return 0;
@@ -322,7 +330,7 @@ static ssize_t attach_store(struct device *dev, struct device_attribute *attr,
322 sockfd, devid, speed); 330 sockfd, devid, speed);
323 331
324 /* check received parameters */ 332 /* check received parameters */
325 if (!valid_args(pdev_nr, rhport, speed)) 333 if (!valid_args(&pdev_nr, &rhport, speed))
326 return -EINVAL; 334 return -EINVAL;
327 335
328 hcd = platform_get_drvdata(vhcis[pdev_nr].pdev); 336 hcd = platform_get_drvdata(vhcis[pdev_nr].pdev);