Skip to contentSkip to conversation

drm/amd/display: Fix Null Pointer Dereference Issues

PATCH In review Zicheng Qu 3 participants 7 messages Nov 5, 2024 – Nov 18, 2024

Subsystems (3)
lore
Share & tools
lore

Zicheng Qu

author
#0 lore raw

cover drm/amd/display: Fix Null Pointer Dereference Issues

Hi all,

I am submitting two patches to fix null pointer dereference issues in the AMD display driver.

1. Patch 1/2 (Fixes: 8e4ed3cf1642): Add null checks in dcn20_program_pipe() to prevent potential crashes when accessing plane_state.

2. Patch 2/2 (Fixes: 0baae6246307): Ensures pipe_ctx->plane_state is checked in hwss_setup_dpp() to improve function stability.

Thanks for reviewing!

Zicheng Qu (2):
drm/amd/display: Fix null check for pipe_ctx->plane_state in
dcn20_program_pipe
drm/amd/display: Fix null check for pipe_ctx->plane_state in
hwss_setup_dpp

 drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c   | 3 +++
 drivers/gpu/drm/amd/display/dc/hwss/dcn20/dcn20_hwseq.c | 6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 drm/amd/display: Fix null check for pipe_ctx->plane_state in dcn20_program_pipe

This commit addresses a null pointer dereference issue in dcn20_program_pipe(). Previously, commit 8e4ed3cf1642 ("drm/amd/display:
Add null check for pipe_ctx->plane_state in dcn20_program_pipe") partially fixed the null pointer dereference issue. However, in dcn20_update_dchubp_dpp(), the variable pipe_ctx is passed in, and plane_state is accessed again through pipe_ctx. Multiple if statements directly call attributes of plane_state, leading to potential null pointer dereference issues. This patch adds necessary null checks to ensure stability.

Fixes 8e4ed3cf1642 ("drm/amd/display: Add null check for pipe_ctx->plane_state in dcn20_program_pipe")
---
 drivers/gpu/drm/amd/display/dc/hwss/dcn20/dcn20_hwseq.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dc/hwss/dcn20/dcn20_hwseq.c +3 -3
index a80c08582932..36d12db8d022 100644
@@ -1923,9 +1923,9 @@ static void dcn20_program_pipe(
 				dc->res_pool->hubbub, pipe_ctx->plane_res.hubp->inst, pipe_ctx->hubp_regs.det_size);
 	}
 
-	if (pipe_ctx->update_flags.raw ||
-	    (pipe_ctx->plane_state && pipe_ctx->plane_state->update_flags.raw) ||
-	    pipe_ctx->stream->update_flags.raw)
+	if (pipe_ctx->plane_state && (pipe_ctx->update_flags.raw ||
+	    pipe_ctx->plane_state->update_flags.raw ||
+	    pipe_ctx->stream->update_flags.raw))
 		dcn20_update_dchubp_dpp(dc, pipe_ctx, context);
 
 	if (pipe_ctx->plane_state && (pipe_ctx->update_flags.bits.enable ||
Signature · 1 line
2.34.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] drm/amd/display: Fix null check for pipe_ctx->plane_state in dcn20_program_pipe

Quoted 33 lines · Zicheng Qu

This commit addresses a null pointer dereference issue in dcn20_program_pipe(). Previously, commit 8e4ed3cf1642 ("drm/amd/display:
Add null check for pipe_ctx->plane_state in dcn20_program_pipe") partially fixed the null pointer dereference issue. However, in dcn20_update_dchubp_dpp(), the variable pipe_ctx is passed in, and plane_state is accessed again through pipe_ctx. Multiple if statements directly call attributes of plane_state, leading to potential null pointer dereference issues. This patch adds necessary null checks to ensure stability.

Fixes 8e4ed3cf1642 ("drm/amd/display: Add null check for pipe_ctx->plane_state in dcn20_program_pipe")
---
  drivers/gpu/drm/amd/display/dc/hwss/dcn20/dcn20_hwseq.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dc/hwss/dcn20/dcn20_hwseq.c +3 -3
index a80c08582932..36d12db8d022 100644
@@ -1923,9 +1923,9 @@ static void dcn20_program_pipe(
  				dc->res_pool->hubbub, pipe_ctx->plane_res.hubp->inst, pipe_ctx->hubp_regs.det_size);
  	}
 
-	if (pipe_ctx->update_flags.raw ||
-	    (pipe_ctx->plane_state && pipe_ctx->plane_state->update_flags.raw) ||
-	    pipe_ctx->stream->update_flags.raw)
+	if (pipe_ctx->plane_state && (pipe_ctx->update_flags.raw ||
+	    pipe_ctx->plane_state->update_flags.raw ||
+	    pipe_ctx->stream->update_flags.raw))
  		dcn20_update_dchubp_dpp(dc, pipe_ctx, context);
 
  	if (pipe_ctx->plane_state && (pipe_ctx->update_flags.bits.enable ||
author
#3 lore raw

PATCH 2/2 drm/amd/display: Fix null check for pipe_ctx->plane_state in hwss_setup_dpp

In reply to Zicheng Qu

This commit addresses a null pointer dereference issue in hwss_setup_dpp(). The issue could occur when pipe_ctx->plane_state is null. The fix adds a check to ensure pipe_ctx->plane_state is not null before accessing. This prevents a null pointer dereference.

Fixes 0baae6246307 ("drm/amd/display: Refactor fast update to use new HWSS build sequence")
---
 drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c +3 -0
index 7ee2be8f82c4..bb766c2a7417 100644
@@ -881,6 +881,9 @@ void hwss_setup_dpp(union block_sequence_params *params)
 	struct dpp *dpp = pipe_ctx->plane_res.dpp;
 	struct dc_plane_state *plane_state = pipe_ctx->plane_state;
 
+	if (!plane_state)
+		return;
+
 	if (dpp && dpp->funcs->dpp_setup) {
 		// program the input csc
 		dpp->funcs->dpp_setup(dpp,
Signature · 1 line
2.34.1
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] drm/amd/display: Fix null check for pipe_ctx->plane_state in hwss_setup_dpp

Quoted 25 lines · Zicheng Qu

This commit addresses a null pointer dereference issue in hwss_setup_dpp(). The issue could occur when pipe_ctx->plane_state is null. The fix adds a check to ensure pipe_ctx->plane_state is not null before accessing. This prevents a null pointer dereference.

Fixes 0baae6246307 ("drm/amd/display: Refactor fast update to use new HWSS build sequence")
---
  drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c +3 -0
index 7ee2be8f82c4..bb766c2a7417 100644
@@ -881,6 +881,9 @@ void hwss_setup_dpp(union block_sequence_params *params)
  	struct dpp *dpp = pipe_ctx->plane_res.dpp;
  	struct dc_plane_state *plane_state = pipe_ctx->plane_state;
 
+	if (!plane_state)
+		return;
+
  	if (dpp && dpp->funcs->dpp_setup) {
  		// program the input csc
  		dpp->funcs->dpp_setup(dpp,
#5 lore raw

Re: [PATCH 2/2] drm/amd/display: Fix null check for pipe_ctx->plane_state in hwss_setup_dpp

Applied both.

Thanks!

Alex

Quoted 29 lines · ChiaHsuan (Tom)
Quoted 25 lines · Zicheng Qu

This commit addresses a null pointer dereference issue in hwss_setup_dpp(). The issue could occur when pipe_ctx->plane_state is null. The fix adds a check to ensure pipe_ctx->plane_state is not null before accessing. This prevents a null pointer dereference.

Fixes 0baae6246307 ("drm/amd/display: Refactor fast update to use new HWSS build sequence")
---
  drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c +3 -0
index 7ee2be8f82c4..bb766c2a7417 100644
@@ -881,6 +881,9 @@ void hwss_setup_dpp(union block_sequence_params *params)
      struct dpp *dpp = pipe_ctx->plane_res.dpp;
      struct dc_plane_state *plane_state = pipe_ctx->plane_state;
 
+     if (!plane_state)
+             return;
+
      if (dpp && dpp->funcs->dpp_setup) {
              // program the input csc
              dpp->funcs->dpp_setup(dpp,
author
#6 lore raw
In reply to Zicheng Qu

Hi,

Gentle ping.

The patch link is: [PATCH 0/2] drm/amd/display: Fix Null Pointer Dereference Issues - Zicheng Qu (kernel.org) <https://lore.kernel.org/linux-kernel/[email protected]/>

Best regards,
Zicheng

Quoted 24 lines · Zicheng Qu

Hi all,

I am submitting two patches to fix null pointer dereference issues in the AMD display driver.

1. Patch 1/2 (Fixes: 8e4ed3cf1642): Add null checks in dcn20_program_pipe() to prevent potential crashes when accessing plane_state.

2. Patch 2/2 (Fixes: 0baae6246307): Ensures pipe_ctx->plane_state is checked in hwss_setup_dpp() to improve function stability.

Thanks for reviewing!

Zicheng Qu (2):
drm/amd/display: Fix null check for pipe_ctx->plane_state in
dcn20_program_pipe
drm/amd/display: Fix null check for pipe_ctx->plane_state in
hwss_setup_dpp

  drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c   | 3 +++
  drivers/gpu/drm/amd/display/dc/hwss/dcn20/dcn20_hwseq.c | 6 +++---
  2 files changed, 6 insertions(+), 3 deletions(-)