Skip to contentSkip to conversation

drm/amd/display: Add sanity checks for drm_edid_raw()

PATCH RESEND Applied Takashi Iwai 2 participants 2 messages Jun 16, 2025 – Jun 23, 2025

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

PATCH RESEND 1/1 drm/amd/display: Add sanity checks for drm_edid_raw()

When EDID is retrieved via drm_edid_raw(), it doesn't guarantee to return proper EDID bytes the caller wants: it may be either NULL (that leads to an Oops) or with too long bytes over the fixed size raw_edid array (that may lead to memory corruption). The latter was reported actually when connected with a bad adapter.

Add sanity checks for drm_edid_raw() to address the above corner cases, and return EDID_BAD_INPUT accordingly.

Fixes 48edb2a4256e ("drm/amd/display: switch amdgpu_dm_connector to use struct drm_edid")

---

Just resent, as the previous submission seems overlooked

 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +4 -0
index d4395b92fb85..9e3e51a2dc49 100644
@@ -1029,6 +1029,10 @@ enum dc_edid_status dm_helpers_read_local_edid(
 			return EDID_NO_RESPONSE;
 
 		edid = drm_edid_raw(drm_edid); // FIXME: Get rid of drm_edid_raw()
+		if (!edid ||
+		    edid->extensions >= sizeof(sink->dc_edid.raw_edid) / EDID_LENGTH)
+			return EDID_BAD_INPUT;
+
 		sink->dc_edid.length = EDID_LENGTH * (edid->extensions + 1);
 		memmove(sink->dc_edid.raw_edid, (uint8_t *)edid, sink->dc_edid.length);
 
Signature · 1 line
2.49.0
Applied
#1 lore raw

Applied. Thanks!

Alex

Quoted 38 lines · Takashi Iwai

When EDID is retrieved via drm_edid_raw(), it doesn't guarantee to return proper EDID bytes the caller wants: it may be either NULL (that leads to an Oops) or with too long bytes over the fixed size raw_edid array (that may lead to memory corruption). The latter was reported actually when connected with a bad adapter.

Add sanity checks for drm_edid_raw() to address the above corner cases, and return EDID_BAD_INPUT accordingly.

Fixes 48edb2a4256e ("drm/amd/display: switch amdgpu_dm_connector to use struct drm_edid")

---

Just resent, as the previous submission seems overlooked

 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +4 -1
index d4395b92fb85..9e3e51a2dc49 100644
@@ -1029,6 +1029,10 @@ enum dc_edid_status dm_helpers_read_local_edid(
                        return EDID_NO_RESPONSE;
 
                edid = drm_edid_raw(drm_edid); // FIXME: Get rid of drm_edid_raw()
+               if (!edid ||
+                   edid->extensions >= sizeof(sink->dc_edid.raw_edid) / EDID_LENGTH)
+                       return EDID_BAD_INPUT;
+
                sink->dc_edid.length = EDID_LENGTH * (edid->extensions + 1);
                memmove(sink->dc_edid.raw_edid, (uint8_t *)edid, sink->dc_edid.length);
 
--

2.49.0