Skip to contentSkip to conversation

drm: Test for PCI root bus to avoid NULL pointer dereference

PATCH In review Alex Williamson 3 participants 3 messages Aug 27, 2014 – Oct 3, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: Test for PCI root bus to avoid NULL pointer dereference

If we have a GPU on the PCI root bus that calls drm_pcie_get_speed_cap_mask() we end up with a NULL pointer dereference since pdev->bus->self is NULL. We already protect against callers passing non-PCI devices, so let's also catch this case and return -EINVAL.

Root complex graphics are not terribly likely outside of IGD, but when we assign a standard plugin GPU to a virtual machine, our assumption that we have a parent device quickly becomes invalid.

---

 drivers/gpu/drm/drm_pci.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_pci.c +1 -1
index 020cfd9..411e806 100644
@@ -390,7 +390,7 @@ int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *mask)
 	u32 lnkcap, lnkcap2;
 
 	*mask = 0;
-	if (!dev->pdev)
+	if (!dev->pdev || pci_is_root_bus(dev->pdev->bus))
 		return -EINVAL;
 
 	root = dev->pdev->bus->self;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Alex Williamson

If we have a GPU on the PCI root bus that calls drm_pcie_get_speed_cap_mask() we end up with a NULL pointer dereference since pdev->bus->self is NULL. We already protect against callers passing non-PCI devices, so let's also catch this case and return -EINVAL.

Root complex graphics are not terribly likely outside of IGD, but when we assign a standard plugin GPU to a virtual machine, our assumption that we have a parent device quickly becomes invalid.

Quoted 23 lines

---

 drivers/gpu/drm/drm_pci.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_pci.c +1 -1
index 020cfd9..411e806 100644
@@ -390,7 +390,7 @@ int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *mask)
        u32 lnkcap, lnkcap2;
 
        *mask = 0;
-       if (!dev->pdev)
+       if (!dev->pdev || pci_is_root_bus(dev->pdev->bus))
                return -EINVAL;
 
        root = dev->pdev->bus->self;

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
In reply to Alex Williamson
Quoted 9 lines · Alex Williamson

If we have a GPU on the PCI root bus that calls drm_pcie_get_speed_cap_mask() we end up with a NULL pointer dereference since pdev->bus->self is NULL. We already protect against callers passing non-PCI devices, so let's also catch this case and return -EINVAL.

Root complex graphics are not terribly likely outside of IGD, but when we assign a standard plugin GPU to a virtual machine, our assumption that we have a parent device quickly becomes invalid.

What happend to this patch? I don't see it applied on https://github.com/torvalds/linux/tree/master/drivers/gpu/drm

B.