[PATCH] drm/amd/display: dce110: fix NULL deref in dce110_set_backlight_level()

Kery Qi posted 1 patch 1 month ago
drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH] drm/amd/display: dce110: fix NULL deref in dce110_set_backlight_level()
Posted by Kery Qi 1 month ago
dce110_set_backlight_level() computes controller_id from
pipe_ctx->stream_res.tg->inst before validating that tg is present.
pipe_ctx->stream_res.tg may be NULL on some paths, which can lead to a
NULL pointer dereference (oops/DoS) when setting backlight.

Fix this by requiring tg to be present before accessing tg->inst. Also
check abm->funcs before dereferencing function pointers.

Fixes: 4b0e95d1838f ("drm/amd/display: Add set backlight to hw sequencer.")
Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
---
 drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c b/drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c
index 0cdd8c74abdf..6177bc67ea9c 100644
--- a/drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c
+++ b/drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c
@@ -3263,10 +3263,15 @@ bool dce110_set_backlight_level(struct pipe_ctx *pipe_ctx,
 	struct panel_cntl *panel_cntl = link->panel_cntl;
 	struct dmcu *dmcu = dc->res_pool->dmcu;
 	bool fw_set_brightness = true;
+	struct timing_generator *tg = pipe_ctx->stream_res.tg;
+
+	if (!tg)
+		return false;
+
 	/* DMCU -1 for all controller id values,
 	 * therefore +1 here
 	 */
-	uint32_t controller_id = pipe_ctx->stream_res.tg->inst + 1;
+	uint32_t controller_id = tg->inst + 1;
 
 	if (abm == NULL || panel_cntl == NULL || (abm->funcs->set_backlight_level_pwm == NULL))
 		return false;
-- 
2.34.1