[PATCH] drm/display: fix possible null-pointer dereference in dcn10_set_clock()
Tuo Li
islituo at gmail.com
Tue Aug 10 13:55:39 UTC 2021
Thanks for your feedback. We will prepare a V2 patch according to your advice.
Best wishes,
Tuo Li
On 2021/8/10 21:38, Chen, Guchun wrote:
> [Public]
>
> Thanks for your patch.
>
> I suggest moving the check of function pointer dc->clk_mgr->funcs->get_clock earlier, and return early if it's NULL, as if it's NULL, it's meaningless to continue the clock setting.
>
> ....
> if (!dc->clk_mgr || !dc->clk_mgr->funcs->get_clock)
> return DC_FAIL_UNSUPPORTED_1;
>
> dc->clk_mgr->funcs->get_clock(dc->clk_mgr,
> context, clock_type, &clock_cfg);
> ....
>
> Regards,
> Guchun
>
> -----Original Message-----
> From: amd-gfx <amd-gfx-bounces at lists.freedesktop.org> On Behalf Of Tuo Li
> Sent: Tuesday, August 10, 2021 5:20 PM
> To: Wentland, Harry <Harry.Wentland at amd.com>; Li, Sun peng (Leo) <Sunpeng.Li at amd.com>; Deucher, Alexander <Alexander.Deucher at amd.com>; Koenig, Christian <Christian.Koenig at amd.com>; Pan, Xinhui <Xinhui.Pan at amd.com>; airlied at linux.ie; daniel at ffwll.ch; Cyr, Aric <Aric.Cyr at amd.com>; Lei, Jun <Jun.Lei at amd.com>; Zhuo, Qingqing <Qingqing.Zhuo at amd.com>; Siqueira, Rodrigo <Rodrigo.Siqueira at amd.com>; Lee, Alvin <Alvin.Lee2 at amd.com>; Stempen, Vladimir <Vladimir.Stempen at amd.com>; isabel.zhang at amd.com; Lee, Sung <Sung.Lee at amd.com>; Po-Yu Hsieh Paul <Paul.Hsieh at amd.com>; Wood, Wyatt <Wyatt.Wood at amd.com>
> Cc: amd-gfx at lists.freedesktop.org; dri-devel at lists.freedesktop.org; linux-kernel at vger.kernel.org; baijiaju1990 at gmail.com; Tuo Li <islituo at gmail.com>; TOTE Robot <oslab at tsinghua.edu.cn>
> Subject: [PATCH] drm/display: fix possible null-pointer dereference in dcn10_set_clock()
>
> The variable dc->clk_mgr is checked in:
> if (dc->clk_mgr && dc->clk_mgr->funcs->get_clock)
>
> This indicates dc->clk_mgr can be NULL.
> However, it is dereferenced in:
> if (!dc->clk_mgr->funcs->get_clock)
>
> To fix this possible null-pointer dereference, check dc->clk_mgr before dereferencing it.
>
> Reported-by: TOTE Robot <oslab at tsinghua.edu.cn>
> Signed-off-by: Tuo Li <islituo at gmail.com>
> ---
> drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c
> index c545eddabdcc..3a7c7c7efa68 100644
> --- a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c
> +++ b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c
> @@ -3635,7 +3635,7 @@ enum dc_status dcn10_set_clock(struct dc *dc,
> dc->clk_mgr->funcs->get_clock(dc->clk_mgr,
> context, clock_type, &clock_cfg);
>
> - if (!dc->clk_mgr->funcs->get_clock)
> + if (dc->clk_mgr && !dc->clk_mgr->funcs->get_clock)
> return DC_FAIL_UNSUPPORTED_1;
>
> if (clk_khz > clock_cfg.max_clock_khz)
> --
> 2.25.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/amd-gfx/attachments/20210810/65d0e928/attachment-0001.htm>
More information about the amd-gfx
mailing list