Skip to content

Commit 14450ab

Browse files
GustavoARSilvagregkh
authored andcommitted
usbip: vhci_sysfs: fix potential Spectre v1
commit a0d6ec8 upstream. 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>
1 parent 8da07ee commit 14450ab

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

drivers/usb/usbip/vhci_sysfs.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include <linux/platform_device.h>
2525
#include <linux/slab.h>
2626

27+
/* Hardening for Spectre-v1 */
28+
#include <linux/nospec.h>
29+
2730
#include "usbip_common.h"
2831
#include "vhci.h"
2932

@@ -181,16 +184,20 @@ static int vhci_port_disconnect(struct vhci_hcd *vhci, __u32 rhport)
181184
return 0;
182185
}
183186

184-
static int valid_port(__u32 pdev_nr, __u32 rhport)
187+
static int valid_port(__u32 *pdev_nr, __u32 *rhport)
185188
{
186-
if (pdev_nr >= vhci_num_controllers) {
187-
pr_err("pdev %u\n", pdev_nr);
189+
if (*pdev_nr >= vhci_num_controllers) {
190+
pr_err("pdev %u\n", *pdev_nr);
188191
return 0;
189192
}
190-
if (rhport >= VHCI_HC_PORTS) {
191-
pr_err("rhport %u\n", rhport);
193+
*pdev_nr = array_index_nospec(*pdev_nr, vhci_num_controllers);
194+
195+
if (*rhport >= VHCI_HC_PORTS) {
196+
pr_err("rhport %u\n", *rhport);
192197
return 0;
193198
}
199+
*rhport = array_index_nospec(*rhport, VHCI_HC_PORTS);
200+
194201
return 1;
195202
}
196203

@@ -207,7 +214,7 @@ static ssize_t store_detach(struct device *dev, struct device_attribute *attr,
207214
pdev_nr = port_to_pdev_nr(port);
208215
rhport = port_to_rhport(port);
209216

210-
if (!valid_port(pdev_nr, rhport))
217+
if (!valid_port(&pdev_nr, &rhport))
211218
return -EINVAL;
212219

213220
hcd = platform_get_drvdata(*(vhci_pdevs + pdev_nr));
@@ -226,7 +233,8 @@ static ssize_t store_detach(struct device *dev, struct device_attribute *attr,
226233
}
227234
static DEVICE_ATTR(detach, S_IWUSR, NULL, store_detach);
228235

229-
static int valid_args(__u32 pdev_nr, __u32 rhport, enum usb_device_speed speed)
236+
static int valid_args(__u32 *pdev_nr, __u32 *rhport,
237+
enum usb_device_speed speed)
230238
{
231239
if (!valid_port(pdev_nr, rhport)) {
232240
return 0;
@@ -288,7 +296,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
288296
sockfd, devid, speed);
289297

290298
/* check received parameters */
291-
if (!valid_args(pdev_nr, rhport, speed))
299+
if (!valid_args(&pdev_nr, &rhport, speed))
292300
return -EINVAL;
293301

294302
hcd = platform_get_drvdata(*(vhci_pdevs + pdev_nr));

0 commit comments

Comments
 (0)