drm/amd/display: Fix possible buffer overflow in 'find_dcfclk_for_voltage()'
Subsystems (3)
PATCH 1/1 drm/amd/display: Fix possible buffer overflow in 'find_dcfclk_for_voltage()'
when 'find_dcfclk_for_voltage()' function is looping over VG_NUM_SOC_VOLTAGE_LEVELS (which is 8), but the size of the DcfClocks array is VG_NUM_DCFCLK_DPM_LEVELS (which is 7).
When the loop variable i reaches 7, the function tries to access clock_table->DcfClocks[7]. However, since the size of the DcfClocks array is 7, the valid indices are 0 to 6. Index 7 is beyond the size of the array, leading to a buffer overflow.
Fixes the below:drivers/gpu/drm/amd/amdgpu/../display/dc/clk_mgr/dcn301/vg_clk_mgr.c:550 find_dcfclk_for_voltage() error: buffer overflow 'clock_table->DcfClocks' 7 <= 7
--- drivers/gpu/drm/amd/display/dc/clk_mgr/dcn301/vg_clk_mgr.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/display/dc/clk_mgr/dcn301/vg_clk_mgr.c +2 -0
@@ -546,6 +546,8 @@ static unsigned int find_dcfclk_for_voltage(const struct vg_dpm_clocks *clock_taint i;for (i =0 ; i <VG_NUM_SOC_VOLTAGE_LEVELS ; i++) { +if (i >=VG_NUM_DCFCLK_DPM_LEVELS ) +break ;if (clock_table->SocVoltage[i] == voltage)return clock_table->DcfClocks[i]; }
Signature · 1 line
2.34.1
PATCH 1/1 drm/amd/display: Initialize 'wait_time_microsec' variable in link_dp_training_dpia.c
wait_time_microsec = max(wait_time_microsec, (uint32_t) DPIA_CLK_SYNC_DELAY);
Above line is trying to assign the maximum value between 'wait_time_microsec' and 'DPIA_CLK_SYNC_DELAY' to wait_time_microsec. However, 'wait_time_microsec' has not been assigned a value before this line, initialize 'wait_time_microsec' at the point of declaration.
Fixes the below:drivers/gpu/drm/amd/amdgpu/../display/dc/link/protocols/link_dp_training_dpia.c:697 dpia_training_eq_non_transparent() error: uninitialized symbol 'wait_time_microsec'.
--- .../drm/amd/display/dc/link/protocols/link_dp_training_dpia.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_dpia.c +1 -1
@@ -619,7 +619,7 @@ static enum link_training_result dpia_training_eq_non_transparent(uint32_t retries_eq =0 ;enum dc_status status;enum dc_dp_training_pattern tr_pattern; -uint32_t wait_time_microsec; +uint32_t wait_time_microsec =0 ;enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;union lane_align_status_updated dpcd_lane_status_updated = {0 };union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX ] = {0 };
Signature · 1 line
2.34.1
RE: [PATCH] drm/amd/display: Initialize 'wait_time_microsec' variable in link_dp_training_dpia.c
[Public]
Quoted 55 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Srinivasan Shanmugam
Sent: Tuesday, February 6, 2024 11:55 PM
To: Siqueira, Rodrigo <[email protected]>; Pillai, Aurabindo <[email protected]>
Cc: [email protected]; SHANMUGAM, SRINIVASAN <[email protected]>; Liu, Wenjing <[email protected]>
Subject: [PATCH] drm/amd/display: Initialize 'wait_time_microsec' variable inlink_dp_training_dpia.c
wait_time_microsec=max(wait_time_microsec, (uint32_t) DPIA_CLK_SYNC_DELAY);Above line is trying to assign the maximum value between '
wait_time_microsec' and 'DPIA_CLK_SYNC_DELAY' towait_time_microsec. However, 'wait_time_microsec' has not been assigned a value before this line, initialize 'wait_time_microsec' at the point of declaration.Fixes the below:
drivers/gpu/drm/amd/amdgpu/../display/dc/link/protocols/link_dp_training_dpia.c:697dpia_training_eq_non_transparent()error: uninitialized symbol 'wait_time_microsec'.Fixes 630168a97314 ("drm/amd/display: move dp link training logic to
link_dp_training")Cc Wenjing Liu <[email protected]>Cc Rodrigo Siqueira <[email protected]>Cc Aurabindo Pillai <[email protected]>Signed-off-by Srinivasan Shanmugam <[email protected]>--- .../drm/amd/display/dc/link/protocols/link_dp_training_dpia.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)diff --git
a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_dpia.cb/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_dpia.cindexe8dda44b23cb..5d36bab0029c100644drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_dpi renamed from drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_dpia.c +1
-0+++ a.c@@ -619,7 +619,7 @@ static enum link_training_resultdpia_training_eq_non_transparent(
uint32_t retries_eq = 0; enum dc_status status; enum dc_dp_training_pattern tr_pattern;drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_dpi renamed from drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_dpia.c +1
-1- uint32_t wait_time_microsec; + uint32_t wait_time_microsec = 0; enum dc_lane_count lane_count = lt_settings-Quoted 1 line
link_settings.lane_count;
union lane_align_status_updated dpcd_lane_status_updated = {0}; union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};--
2.34.1
PATCH 1/1 drm/amd/display: Fix possible use of uninitialized 'max_chunks_fbc_mode' in 'calculate_bandwidth()'
In reply to Srinivasan Shanmugam'max_chunks_fbc_mode' is only declared and assigned a value under a specific condition in the following lines:
if (data->fbc_en[i] == 1) {
max_chunks_fbc_mode = 128 - dmif_chunk_buff_margin;
}If 'data->fbc_en[i]' is not equal to 1 for any i, max_chunks_fbc_mode will not be initialized if it's used outside of this for loop.
Ensure that 'max_chunks_fbc_mode' is properly initialized before it's used. Initialize it to a default value right after its declaration to ensure that it gets a value assigned under all possible control flow paths.
Thus fixing the below:drivers/gpu/drm/amd/amdgpu/../display/dc/basics/dce_calcs.c:914 calculate_bandwidth() error: uninitialized symbol 'max_chunks_fbc_mode'. drivers/gpu/drm/amd/amdgpu/../display/dc/basics/dce_calcs.c:917 calculate_bandwidth() error: uninitialized symbol 'max_chunks_fbc_mode'.
--- drivers/gpu/drm/amd/display/dc/basics/dce_calcs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/basics/dce_calcs.c +1 -1
@@ -94,7 +94,7 @@ static void calculate_bandwidth(const uint32_t s_high =7 ;const uint32_t dmif_chunk_buff_margin =1 ; -uint32_t max_chunks_fbc_mode; +uint32_t max_chunks_fbc_mode =0 ;int32_t num_cursor_lines;int32_t i, j, k;
Signature · 1 line
2.34.1
RE: [PATCH] drm/amd/display: Fix possible use of uninitialized 'max_chunks_fbc_mode' in 'calculate_bandwidth()'
[Public]
Quoted 58 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Srinivasan Shanmugam
Sent: Tuesday, February 6, 2024 11:55 PM
To: Siqueira, Rodrigo <[email protected]>; Pillai, Aurabindo <[email protected]>
Cc: [email protected]; SHANMUGAM, SRINIVASAN <[email protected]>; Wentland, Harry <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH] drm/amd/display: Fix possible use of uninitialized 'max_chunks_fbc_mode' in 'calculate_bandwidth()''
max_chunks_fbc_mode' is only declared and assigned a value under a specific condition in the following lines:if (data->fbc_en[i] == 1) { max_chunks_fbc_mode = 128 - dmif_chunk_buff_margin; }If 'data->fbc_en[i]' is not equal to 1 for any i,
max_chunks_fbc_modewill not be initialized if it's used outside of this for loop.Ensure that '
max_chunks_fbc_mode' is properly initialized before it's used. Initialize it to a default value right after its declaration to ensure that it gets a value assigned under all possible control flow paths.Thus fixing the below:
drivers/gpu/drm/amd/amdgpu/../display/dc/basics/dce_calcs.c:914calculate_bandwidth()error: uninitialized symbol 'max_chunks_fbc_mode'.drivers/gpu/drm/amd/amdgpu/../display/dc/basics/dce_calcs.c:917calculate_bandwidth()error: uninitialized symbol 'max_chunks_fbc_mode'.Fixes 4562236b3bc0 ("drm/amd/dc: Add dc display driver (v2)")Cc Harry Wentland <[email protected]>Cc Alex Deucher <[email protected]>Cc Rodrigo Siqueira <[email protected]>Cc Aurabindo Pillai <[email protected]>Signed-off-by Srinivasan Shanmugam <[email protected]>--- drivers/gpu/drm/amd/display/dc/basics/dce_calcs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/display/dc/basics/dce_calcs.c +1
-2@@ -94,7 +94,7 @@ static void calculate_bandwidth(const uint32_t s_high =7 ;const uint32_t dmif_chunk_buff_margin =1 ; -uint32_t max_chunks_fbc_mode; +uint32_t max_chunks_fbc_mode =0 ;int32_t num_cursor_lines;int32_t i, j, k; --2.34.1
PATCH 1/1 drm/amd/display: Fix possible NULL dereference on device remove/driver unload
In reply to Srinivasan ShanmugamAs part of a cleanup amdgpu_dm_fini() function, which is typically called when a device is being shut down or a driver is being unloaded
The below error message suggests that there is a potential null pointer dereference issue with adev->dm.dc.
In the below, line of code where adev->dm.dc is used without a preceding null check:
for (i = 0; i < adev->dm.dc->caps.max_links; i++) {
To fix this issue, add a null check for adev->dm.dc before this line.
Reported by smatch:drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:1959 amdgpu_dm_fini() error: we previously assumed 'adev->dm.dc' could be null (see line 1943)
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -1
@@ -1956,7 +1956,7 @@ static void amdgpu_dm_fini(struct amdgpu_device *adev) &adev->dm.dmub_bo_gpu_addr, &adev->dm.dmub_bo_cpu_addr); -if (adev->dm.hpd_rx_offload_wq) { +if (adev->dm.hpd_rx_offload_wq && adev->dm.dc) {for (i =0 ; i < adev->dm.dc->caps.max_links; i++) {if (adev->dm.hpd_rx_offload_wq[i].wq) {destroy_workqueue (adev->dm.hpd_rx_offload_wq[i].wq);
Signature · 1 line
2.34.1
RE: [PATCH] drm/amd/display: Fix possible NULL dereference on device remove/driver unload
[AMD Official Use Only - General]
Quoted 60 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Srinivasan Shanmugam
Sent: Tuesday, February 6, 2024 11:55 PM
To: Siqueira, Rodrigo <[email protected]>; Pillai, Aurabindo <[email protected]>
Cc: [email protected]; SHANMUGAM, SRINIVASAN <[email protected]>; Andrey Grodzovsky <[email protected]>; Wentland, Harry <[email protected]>
Subject: [PATCH] drm/amd/display: Fix possible NULL dereference on device remove/driver unloadAs part of a cleanup
amdgpu_dm_fini()function, which is typically called when a device is being shut down or a driver is being unloadedThe below error message suggests that there is a potential null pointer dereference issue with
adev->dm.dc.In the below, line of code where
adev->dm.dcis used without a preceding null check:for (i = 0; i <
adev->dm.dc->caps.max_links; i++) {To fix this issue, add a null check for
adev->dm.dcbefore this line.Reported by smatch:
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:1959amdgpu_dm_fini()error: we previously assumed 'adev->dm.dc' could be null (see line 1943)Fixes 006c26a0f1c8 ("drm/amd/display: Fix crash on device remove/driverunload")
Cc Andrey Grodzovsky <[email protected]>Cc Harry Wentland <[email protected]>Cc Rodrigo Siqueira <[email protected]>Cc Aurabindo Pillai <[email protected]>Signed-off-by Srinivasan Shanmugam <[email protected]>--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1
-1@@ -1956,7 +1956,7 @@ static void amdgpu_dm_fini(struct amdgpu_device *adev) &adev->dm.dmub_bo_gpu_addr, &adev->dm.dmub_bo_cpu_addr); -if (adev->dm.hpd_rx_offload_wq) { +if (adev->dm.hpd_rx_offload_wq && adev->dm.dc) {for (i =0 ; i < adev->dm.dc->caps.max_links; i++) {if (adev->dm.hpd_rx_offload_wq[i].wq) {destroy_workqueue(adev-
Quoted 1 line
dm.hpd_rx_offload_wq[i].wq);
--
2.34.1
[Public]
Quoted 15 lines
-----Original Message-----
From: SHANMUGAM, SRINIVASAN <[email protected]>
Sent: Tuesday, February 6, 2024 11:55 PM
To: Siqueira, Rodrigo <[email protected]>; Pillai, Aurabindo <[email protected]>
Cc: [email protected]; SHANMUGAM, SRINIVASAN <[email protected]>; Li, Roman <[email protected]>
Subject: [PATCH] drm/amd/display: Fix possible buffer overflow in 'find_dcfclk_for_voltage()'when '
find_dcfclk_for_voltage()' function is looping overVG_NUM_SOC_VOLTAGE_LEVELS(which is 8), but the size of the DcfClocks array isVG_NUM_DCFCLK_DPM_LEVELS(which is 7).When the loop variable i reaches 7, the function tries to access clock_table-
Quoted 8 lines
Quoted 1 line
DcfClocks[7]. However, since the size of the DcfClocks array is 7, the valid
indices are 0 to 6. Index 7 is beyond the size of the array, leading to a buffer overflow.
Fixes the below:
drivers/gpu/drm/amd/amdgpu/../display/dc/clk_mgr/dcn301/vg_clk_mgr.c:
550find_dcfclk_for_voltage()error: buffer overflow 'clock_table->DcfClocks' 7 <= 7
I recommend mentioning that this is a static analysis tool error. With that:
Quoted 27 lines
Fixes 3a83e4e64bb1 ("drm/amd/display: Add dcn3.01 support to DC (v2)")Cc Roman Li <[email protected]>Cc Rodrigo Siqueira <[email protected]>Cc Aurabindo Pillai <[email protected]>Signed-off-by Srinivasan Shanmugam <[email protected]>--- drivers/gpu/drm/amd/display/dc/clk_mgr/dcn301/vg_clk_mgr.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/amd/display/dc/clk_mgr/dcn301/vg_clk_mgr.c +0
-0@@ -546,6 +546,8 @@ static unsigned int find_dcfclk_for_voltage(conststruct
vg_dpm_clocks*clock_taint i; for (i = 0; i < VG_NUM_SOC_VOLTAGE_LEVELS; i++) {drivers/gpu/drm/amd/display/dc/clk_mgr/dcn301/vg_clk_mgr.c +2
-1+if (i >=VG_NUM_DCFCLK_DPM_LEVELS ) +break ;if (clock_table->SocVoltage[i] == voltage)return clock_table->DcfClocks[i]; } --2.34.1