drm/amd/display: fix possible buffer overflow relating to secure display
Subsystems (3)
PATCH 1/1 drm/amd/display: fix possible buffer overflow relating to secure display
It is possible that adev->dm.dc->caps.max_links is greater than AMDGPU_MAX_CRTCS. So, to not potentially access unallocated memory use adev->mode_info.num_crtc to do the bounds check instead of adev->dm.dc->caps.max_links.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -1
@@ -1742,7 +1742,7 @@ static void amdgpu_dm_fini(struct amdgpu_device *adev)#if defined(CONFIG_DRM_AMD_SECURE_DISPLAY )if (adev->dm.secure_display_ctxs) { -for (i =0 ; i < adev->dm.dc->caps.max_links; i++) { +for (i =0 ; i < adev->mode_info.num_crtc; i++) {if (adev->dm.secure_display_ctxs[i].crtc) {flush_work (&adev->dm.secure_display_ctxs[i].notify_ta_work);flush_work (&adev->dm.secure_display_ctxs[i].forward_roi_work);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c +5 -3
@@ -223,7 +223,7 @@ int amdgpu_dm_crtc_configure_crc_source(struct drm_crtc *crtc,#if defined(CONFIG_DRM_AMD_SECURE_DISPLAY )/* Disable secure_display if it was enabled */ if (!enable) { -for (i =0 ; i < adev->dm.dc->caps.max_links; i++) { +for (i =0 ; i < adev->mode_info.num_crtc; i++) {if (adev->dm.secure_display_ctxs[i].crtc == crtc) {/* stop ROI update on this crtc */ flush_work (&adev->dm.secure_display_ctxs[i].notify_ta_work);
@@ -544,12 +544,14 @@ amdgpu_dm_crtc_secure_display_create_contexts(struct amdgpu_device *adev)struct secure_display_context *secure_display_ctxs =NULL ;int i; - secure_display_ctxs =kcalloc (AMDGPU_MAX_CRTCS ,sizeof (struct secure_display_context ),GFP_KERNEL ); + secure_display_ctxs =kcalloc (adev->mode_info.num_crtc, +sizeof (struct secure_display_context ), +GFP_KERNEL );if (!secure_display_ctxs)return NULL ; -for (i =0 ; i < adev->dm.dc->caps.max_links; i++) { +for (i =0 ; i < adev->mode_info.num_crtc; i++) {INIT_WORK (&secure_display_ctxs[i].forward_roi_work, amdgpu_dm_forward_crc_window);INIT_WORK (&secure_display_ctxs[i].notify_ta_work, amdgpu_dm_crtc_notify_ta_to_read); secure_display_ctxs[i].crtc = &adev->mode_info.crtcs[i]->base;
Signature · 1 line
2.38.1
[AMD Official Use Only - General]
Thanks,
Alan
-----Original Message-----
From: Mahfooz, Hamza <[email protected]>
Sent: Thursday, January 12, 2023 2:17 AM
To: [email protected]
Cc: Mahfooz, Hamza <[email protected]>; Wentland, Harry <[email protected]>; Li, Sun peng (Leo) <[email protected]>; Siqueira, Rodrigo <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Lin, Wayne <[email protected]>; Pillai, Aurabindo <[email protected]>; Li, Roman <[email protected]>; Wu, Hersen <[email protected]>; Zuo, Jerry <[email protected]>; Liu, HaoPing (Alan) <[email protected]>; Dhillon, Jasdeep <[email protected]>; Liu, Aaron <[email protected]>; [email protected]; [email protected]
Subject: [PATCH] drm/amd/display: fix possible buffer overflow relating to secure display
It is possible that adev->dm.dc->caps.max_links is greater than AMDGPU_MAX_CRTCS. So, to not potentially access unallocated memory use adev->mode_info.num_crtc to do the bounds check instead ofadev->dm.dc->caps.max_links.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -1
@@ -1742,7 +1742,7 @@ static void amdgpu_dm_fini(struct amdgpu_device *adev)#if defined(CONFIG_DRM_AMD_SECURE_DISPLAY )if (adev->dm.secure_display_ctxs) { -for (i =0 ; i < adev->dm.dc->caps.max_links; i++) { +for (i =0 ; i < adev->mode_info.num_crtc; i++) {if (adev->dm.secure_display_ctxs[i].crtc) {flush_work (&adev->dm.secure_display_ctxs[i].notify_ta_work);flush_work (&adev->dm.secure_display_ctxs[i].forward_roi_work);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c +5 -3
@@ -223,7 +223,7 @@ int amdgpu_dm_crtc_configure_crc_source(struct drm_crtc *crtc, #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)/* Disable secure_display if it was enabled */ if (!enable) { -for (i =0 ; i < adev->dm.dc->caps.max_links; i++) { +for (i =0 ; i < adev->mode_info.num_crtc; i++) {if (adev->dm.secure_display_ctxs[i].crtc == crtc) {/* stop ROI update on this crtc */ flush_work (&adev->dm.secure_display_ctxs[i].notify_ta_work);
@@ -544,12 +544,14 @@ amdgpu_dm_crtc_secure_display_create_contexts(struct amdgpu_device *adev)struct secure_display_context *secure_display_ctxs =NULL ;int i; - secure_display_ctxs =kcalloc (AMDGPU_MAX_CRTCS ,sizeof (struct secure_display_context ),GFP_KERNEL ); + secure_display_ctxs =kcalloc (adev->mode_info.num_crtc, +sizeof (struct secure_display_context ), +GFP_KERNEL );if (!secure_display_ctxs)return NULL ; -for (i =0 ; i < adev->dm.dc->caps.max_links; i++) { +for (i =0 ; i < adev->mode_info.num_crtc; i++) {INIT_WORK (&secure_display_ctxs[i].forward_roi_work, amdgpu_dm_forward_crc_window);INIT_WORK (&secure_display_ctxs[i].notify_ta_work, amdgpu_dm_crtc_notify_ta_to_read); secure_display_ctxs[i].crtc = &adev->mode_info.crtcs[i]->base;
--
2.38.1