Skip to contentSkip to conversation

drm/msm/dpu: vid: guard hw_pp before accessing merge_3d

PATCH In review Kery Qi 2 participants 2 messages Jan 8 – Jan 9

Subsystems (3)
lore
Share & tools
lore

Kery Qi

author
#0 lore raw

PATCH 1/1 drm/msm/dpu: vid: guard hw_pp before accessing merge_3d

dpu_encoder_phys_vid_setup_timing_engine() dereferences phys_enc->hw_pp when checking/using the merge_3d block.

hw_pp is not guaranteed to be present for a video phys encoder until the virtual encoder atomic_mode_set path assigns it. If this function is reached on an error/unwind path (or after a partial setup) before hw_pp is assigned, the merge_3d checks can trigger a NULL pointer dereference and crash the kernel.

Guard merge_3d accesses with a hw_pp NULL check.

Fixes f87f3b80abaf ("drm/msm/dpu: don't always program merge_3d block")
Fixes dfa35bac9930 ("drm/msm/dpu: use struct dpu_hw_merge_3d in dpu_hw_pingpong")
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c +2 -2
index 0ba777bda253..5e5acbe9147f 100644
@@ -308,7 +308,7 @@ static void dpu_encoder_phys_vid_setup_timing_engine(
 	intf_cfg.stream_sel = 0; /* Don't care value for video mode */
 	intf_cfg.mode_3d = dpu_encoder_helper_get_3d_blend_mode(phys_enc);
 	intf_cfg.dsc = dpu_encoder_helper_get_dsc(phys_enc);
-	if (intf_cfg.mode_3d && phys_enc->hw_pp->merge_3d)
+	if (intf_cfg.mode_3d && phys_enc->hw_pp && phys_enc->hw_pp->merge_3d)
 		intf_cfg.merge_3d = phys_enc->hw_pp->merge_3d->idx;
 
 	spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
@@ -322,7 +322,7 @@ static void dpu_encoder_phys_vid_setup_timing_engine(
 				phys_enc->hw_intf,
 				phys_enc->hw_pp->idx);
 
-	if (phys_enc->hw_pp->merge_3d)
+	if (phys_enc->hw_pp && phys_enc->hw_pp->merge_3d)
 		phys_enc->hw_pp->merge_3d->ops.setup_3d_mode(phys_enc->hw_pp->merge_3d, intf_cfg.mode_3d);
 
 	spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 10 lines · Kery Qi

dpu_encoder_phys_vid_setup_timing_engine() dereferences phys_enc->hw_pp when checking/using the merge_3d block.

hw_pp is not guaranteed to be present for a video phys encoder until the virtual encoder atomic_mode_set path assigns it. If this function is reached on an error/unwind path (or after a partial setup) before hw_pp is assigned, the merge_3d checks can trigger a NULL pointer dereference and crash the kernel.

Guard merge_3d accesses with a hw_pp NULL check.

This function is only called from dpu_encoder_phys_vid_enable(), which is a part of atomic_enable() path. at this point all non-optional resources are already assigned.

Quoted 8 lines
Fixes f87f3b80abaf ("drm/msm/dpu: don't always program merge_3d block")
Fixes dfa35bac9930 ("drm/msm/dpu: use struct dpu_hw_merge_3d in dpu_hw_pingpong")
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 2 lines
With best wishes
Dmitry