Skip to contentSkip to conversation

drm/msm/dpu: reorder pointer operations after sanity checks to avoid NULL deref

PATCH Superseded Qasim Ijaz 3 participants 3 messages Mar 8, 2025 – Mar 9, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Qasim Ijaz

author
#0 lore raw

PATCH 1/1 drm/msm/dpu: reorder pointer operations after sanity checks to avoid NULL deref

_dpu_encoder_trigger_start dereferences "struct dpu_encoder_phys *phys" before the sanity checks which can lead to a NULL pointer dereference if phys is NULL.

Fix this by reordering the dereference after the sanity checks.

Fixes 8144d17a81d9 ("drm/msm/dpu: Skip trigger flush and start for CWB")
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +2 -2
index 0eed93a4d056..ba8b2a163232 100644
@@ -1667,8 +1667,6 @@ static void _dpu_encoder_trigger_flush(struct drm_encoder *drm_enc,
  */
 static void _dpu_encoder_trigger_start(struct dpu_encoder_phys *phys)
 {
-	struct dpu_encoder_virt *dpu_enc = to_dpu_encoder_virt(phys->parent);
-
 	if (!phys) {
 		DPU_ERROR("invalid argument(s)\n");
 		return;
@@ -1679,6 +1677,8 @@ static void _dpu_encoder_trigger_start(struct dpu_encoder_phys *phys)
 		return;
 	}
 
+	struct dpu_encoder_virt *dpu_enc = to_dpu_encoder_virt(phys->parent);
+
 	if (phys->parent->encoder_type == DRM_MODE_ENCODER_VIRTUAL &&
 	    dpu_enc->cwb_mask) {
 		DPU_DEBUG("encoder %d CWB enabled, skipping\n", DRMID(phys->parent));
Signature · 1 line
2.39.5
#1 lore raw
Quoted 8 lines · Qasim Ijaz

_dpu_encoder_trigger_start dereferences "struct dpu_encoder_phys *phys" before the sanity checks which can lead to a NULL pointer dereference if phys is NULL.

Fix this by reordering the dereference after the sanity checks.

Fixes 8144d17a81d9 ("drm/msm/dpu: Skip trigger flush and start for CWB")

Your SoB should be the last tag. Fixes comes before it.

Quoted 18 lines
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +0 -2
index 0eed93a4d056..ba8b2a163232 100644
@@ -1667,8 +1667,6 @@ static void _dpu_encoder_trigger_flush(struct drm_encoder *drm_enc,
  */
 static void _dpu_encoder_trigger_start(struct dpu_encoder_phys *phys)
 {
-	struct dpu_encoder_virt *dpu_enc = to_dpu_encoder_virt(phys->parent);
-
 	if (!phys) {
 		DPU_ERROR("invalid argument(s)\n");
 		return;

drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c static void _dpu_encoder_trigger_start(struct dpu_encoder_phys *phys) · line 1681

Quoted 5 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +2 -0
@@ -1679,6 +1677,8 @@ static void _dpu_encoder_trigger_start(struct dpu_encoder_phys *phys)
 		return;
 	}
 
+	struct dpu_encoder_virt *dpu_enc = to_dpu_encoder_virt(phys->parent);
+

I'm not a fan of having variable defs in the middle of the code. Please keep the def at the top and assign it here.

Quoted 6 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +0 -0
 	if (phys->parent->encoder_type == DRM_MODE_ENCODER_VIRTUAL &&
 	    dpu_enc->cwb_mask) {
 		DPU_DEBUG("encoder %d CWB enabled, skipping\n", DRMID(phys->parent));
Signature · 1 line
2.39.5
Signature · 2 lines
With best wishes
Dmitry
#2 lore raw
In reply to Qasim Ijaz

…

Quoted 1 line

Fix this by reordering the dereference after the sanity checks.

Another wording suggestion:
Thus move the assignment of the variable “dpu_enc” behind a null pointer check.

Would an other summary phrase be nicer?

Regards,
Markus