Skip to contentSkip to conversation

gpu: drm: radeon: Fix a possible null-pointer dereference in radeon_connector_set_property()

PATCH In review Jia-Ju Bai 2 participants 2 messages Jul 29, 2019 – Aug 1, 2019

Subsystems (2)
lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 gpu: drm: radeon: Fix a possible null-pointer dereference in radeon_connector_set_property()

In radeon_connector_set_property(), there is an if statement on line 743 to check whether connector->encoder is NULL:

    if (connector->encoder)

When connector->encoder is NULL, it is used on line 755:

    if (connector->encoder->crtc)

Thus, a possible null-pointer dereference may occur.

To fix this bug, connector->encoder is checked before being used.

This bug is found by a static analysis tool STCheck written by us.

---
 drivers/gpu/drm/radeon/radeon_connectors.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_connectors.c +1 -1
index c60d1a44d22a..b684cd719612 100644
@@ -752,7 +752,7 @@ static int radeon_connector_set_property(struct drm_connector *connector, struct
 
 		radeon_encoder->output_csc = val;
 
-		if (connector->encoder->crtc) {
+		if (connector->encoder && connector->encoder->crtc) {
 			struct drm_crtc *crtc  = connector->encoder->crtc;
 			struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
 
Signature · 1 line
2.17.0
#1 lore raw
Quoted 5 lines · Jia-Ju Bai

In radeon_connector_set_property(), there is an if statement on line 743 to check whether connector->encoder is NULL:

    if (connector->encoder)
Quoted 8 lines

When connector->encoder is NULL, it is used on line 755:

    if (connector->encoder->crtc)

Thus, a possible null-pointer dereference may occur.

To fix this bug, connector->encoder is checked before being used.

This bug is found by a static analysis tool STCheck written by us.

I believe we always have an encoder for every connector, but never hurts to be safe. Thanks. Applied.

Alex

Quoted 26 lines
---
 drivers/gpu/drm/radeon/radeon_connectors.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_connectors.c +1 -2
index c60d1a44d22a..b684cd719612 100644
@@ -752,7 +752,7 @@ static int radeon_connector_set_property(struct drm_connector *connector, struct
 
                radeon_encoder->output_csc = val;
 
-               if (connector->encoder->crtc) {
+               if (connector->encoder && connector->encoder->crtc) {
                        struct drm_crtc *crtc  = connector->encoder->crtc;
                        struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
 
--

2.17.0

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