Skip to contentSkip to conversation

drm/radeon:avoid null pointer dereference when dev is not bound

PATCH In review Defang Bo 2 participants 3 messages Dec 27, 2020 – Jan 5, 2021

Subsystems (2)
lore
Share & tools
lore

Defang Bo

author
#0 lore raw

PATCH 1/1 drm/radeon:avoid null pointer dereference when dev is not bound

[Why]
Similar to commit<0fa375e6>. If the set_state/can_switch code access the drm_device when dev is not bound, a null pointer dereference can happen.

[How]
Add sanity checks to prevent it.

---
 drivers/gpu/drm/radeon/radeon_device.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/radeon/radeon_device.c +6 -0
index 266e3cb..50a1a60 100644
@@ -1224,6 +1224,9 @@ static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switchero
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
 
+	if (!dev)
+		return;
+
 	if (radeon_is_px(dev) && state == VGA_SWITCHEROO_OFF)
 		return;
 
@@ -1257,6 +1260,9 @@ static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switchero
 static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
+
+	if (!dev)
+		return false;
 
 	/*
 	 * FIXME: open_count is protected by drm_global_mutex but that would lead to
Signature · 1 line
2.7.4
#1 lore raw
Quoted 9 lines · Defang Bo

[Why]
Similar to commit<0fa375e6>. If the set_state/can_switch code access the drm_device when dev is not bound, a null pointer dereference can happen.

[How]
Add sanity checks to prevent it.

Are you actually hitting this or is this just defensive? I don't think we can actually get into a state where this would be a problem.

Alex

Quoted 31 lines
---
 drivers/gpu/drm/radeon/radeon_device.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/radeon/radeon_device.c +6 -1
index 266e3cb..50a1a60 100644
@@ -1224,6 +1224,9 @@ static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switchero
 {
        struct drm_device *dev = pci_get_drvdata(pdev);
 
+       if (!dev)
+               return;
+
        if (radeon_is_px(dev) && state == VGA_SWITCHEROO_OFF)
                return;
 
@@ -1257,6 +1260,9 @@ static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switchero
 static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
 {
        struct drm_device *dev = pci_get_drvdata(pdev);
+
+       if (!dev)
+               return false;
 
        /*
         * FIXME: open_count is protected by drm_global_mutex but that would lead to
--

2.7.4

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

author
#2 lore raw

I use static analysis tool to find these funcs are similar to the commit<0fa375e6bc90>(drm/rockchip: Fix suspend crash when drm is not bound),so it's just defensive, I haven't actually hitted this.

Quoted 47 lines · Alex Deucher
Quoted 9 lines · Defang Bo

[Why]
Similar to commit<0fa375e6>. If the set_state/can_switch code access the drm_device when dev is not bound, a null pointer dereference can happen.

[How]
Add sanity checks to prevent it.

Are you actually hitting this or is this just defensive? I don't think we can actually get into a state where this would be a problem.

Alex

Quoted 31 lines
---
 drivers/gpu/drm/radeon/radeon_device.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/radeon/radeon_device.c +6 -1
index 266e3cb..50a1a60 100644
@@ -1224,6 +1224,9 @@ static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switchero
 {
        struct drm_device *dev = pci_get_drvdata(pdev);
 
+       if (!dev)
+               return;
+
        if (radeon_is_px(dev) && state == VGA_SWITCHEROO_OFF)
                return;
 
@@ -1257,6 +1260,9 @@ static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switchero
 static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
 {
        struct drm_device *dev = pci_get_drvdata(pdev);
+
+       if (!dev)
+               return false;
 
        /*
         * FIXME: open_count is protected by drm_global_mutex but that would lead to
--

2.7.4

Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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