Skip to contentSkip to conversation

drm/amdgpu: fix a possible null pointer dereference

PATCH Superseded Ma Ke 4 participants 5 messages Jun 22, 2024 – Jun 24, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ma Ke

author
#0 lore raw

PATCH 1/1 drm/amdgpu: fix a possible null pointer dereference

In amdgpu_connector_add_common_modes(), the return value of drm_cvt_mode() is assigned to mode, which will lead to a NULL pointer dereference on failure of drm_cvt_mode(). Add a check to avoid npd.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c +2 -0
index 9caba10315a8..6cf946adb6fe 100644
@@ -458,6 +458,8 @@ static void amdgpu_connector_add_common_modes(struct drm_encoder *encoder,
 			continue;
 
 		mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
+		if (!mode)
+			continue;
 		drm_mode_probed_add(connector, mode);
 	}
 }
Signature · 1 line
2.25.1
#1 lore raw
Quoted 3 lines

In amdgpu_connector_add_common_modes(), the return value of drm_cvt_mode() is assigned to mode, which will lead to a NULL pointer dereference on failure of drm_cvt_mode(). Add a check to avoid npd.

Can a wording approach (like the following) be a better change description?

A null pointer is stored in the local variable “mode” after a call of the function “drm_cvt_mode” failed. This pointer was passed to a subsequent call of the function “drm_mode_probed_add” where an undesirable dereference will be performed then.
Thus add a corresponding return value check.

Would you like to add any tags (like “Fixes”) accordingly?

How do you think about to use a summary phrase like “Avoid null pointer dereference in amdgpu_connector_add_common_modes()”?

Regards,
Markus

#2 lore raw
In reply to Ma Ke

Are you planning on submitting a bogus CVE for this patch too?

- Joshie 🐸✨

Quoted 22 lines · Ma Ke

In amdgpu_connector_add_common_modes(), the return value of drm_cvt_mode() is assigned to mode, which will lead to a NULL pointer dereference on failure of drm_cvt_mode(). Add a check to avoid npd.

---
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 2 ++

1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c +2 -0
index 9caba10315a8..6cf946adb6fe 100644
@@ -458,6 +458,8 @@ static void amdgpu_connector_add_common_modes(struct drm_encoder *encoder,
 			continue;
 
 		mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
+		if (!mode)
+			continue;
 		drm_mode_probed_add(connector, mode);
 	}
 }
#3 lore raw

Maybe that wasn't you or whatever, but your last patch that did this got some CVE assigned to it that didn't really make any sense, given this is just a null deref that'd end up as an oops?

It can only happen if the kzalloc in drm_mode_create fails.

I imagine that the continue is not the best cause of action anyway, it's probably not worth adding some broken connector with a bunch of missing modes. It's just going to make things appear more broken and be unexpected to userspace.

Maybe this is some new thing that we do now I am out of the loop on...

- Joshie 🐸✨

Quoted 27 lines · Joshua Ashton

Are you planning on submitting a bogus CVE for this patch too?

- Joshie 🐸✨

Quoted 22 lines · Ma Ke

In amdgpu_connector_add_common_modes(), the return value of drm_cvt_mode() is assigned to mode, which will lead to a NULL pointer dereference on failure of drm_cvt_mode(). Add a check to avoid npd.

---
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 2 ++

1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c +2 -0
index 9caba10315a8..6cf946adb6fe 100644
@@ -458,6 +458,8 @@ static void amdgpu_connector_add_common_modes(struct drm_encoder *encoder,
 			continue;
 
 		mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
+		if (!mode)
+			continue;
 		drm_mode_probed_add(connector, mode);
 	}
 }
#4 lore raw
Quoted 6 lines · Joshua Ashton

Maybe that wasn't you or whatever, but your last patch that did this got some CVE assigned to it that didn't really make any sense, given this is just a null deref that'd end up as an oops?

It can only happen if the kzalloc in drm_mode_create fails.

Quoted 8 lines

I imagine that the continue is not the best cause of action anyway, it's probably not worth adding some broken connector with a bunch of missing modes.
It's just going to make things appear more broken and be unexpected to userspace.

Maybe this is some new thing that we do now I am out of the loop on...

Kernel CVE handling changed a lot, for background:

https://lwn.net/Articles/978711/

No one needs to ask for CVEs, you'll all get them pretty much automatically for everything now.

Cheers, Sima

Quoted 36 lines

- Joshie 🐸✨

Quoted 6 lines · Joshua Ashton

Are you planning on submitting a bogus CVE for this patch too?

- Joshie 🐸✨

Quoted 1 line · Ma Ke

In amdgpu_connector_add_common_modes(), the return value of

drm_cvt_mode()

Quoted 9 lines

Review

Quoted 9 lines

is assigned to mode, which will lead to a NULL pointer dereference on failure of drm_cvt_mode(). Add a check to avoid npd.

---
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 2 ++

1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c

Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c static void

Quoted 4 lines

index 9caba10315a8..6cf946adb6fe 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c +0 -0
@@ -458,6 +458,8 @@ static void

amdgpu_connector_add_common_modes(struct drm_encoder *encoder,

Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c static void amdgpu_connector_add_common_modes(struct drm_encoder *encoder,

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c +0 -0
                     continue;
 
             mode = drm_cvt_mode(dev, common_modes[i].w,

common_modes[i].h, 60, false, false, false);

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c +2 -0
+            if (!mode)
+                    continue;
             drm_mode_probed_add(connector, mode);
     }
 }
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch