drm/amdgpu: Fix out-of-bounds write warning
Subsystems (2)
PATCH 1/1 drm/amdgpu: Fix out-of-bounds write warning
Check the ring type value to fix the out-of-bounds write warning
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +5 -0
@@ -353,6 +353,11 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, ring->hw_prio = hw_prio;if (!ring->no_scheduler) { +if (ring->funcs->type >=AMDGPU_HW_IP_NUM ) { +dev_warn (adev->dev,"ring type %d has no scheduler\n" , ring->funcs->type); +return 0 ; + } + hw_ip = ring->funcs->type; num_sched = &adev->gpu_sched[hw_ip][hw_prio].num_scheds; adev->gpu_sched[hw_ip][hw_prio].sched[(*num_sched)++] =
Signature · 1 line
2.34.1
PATCH v2 1/2 drm/amdgpu: Fix uninitialized variable warning in amdgpu_afmt_acr
Assign value to clock to fix the warning below:
"Using uninitialized value res. Field res.clock is uninitialized"
--- drivers/gpu/drm/amd/amdgpu/amdgpu_afmt.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_afmt.c +1 -0
@@ -100,6 +100,7 @@ struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock)amdgpu_afmt_calc_cts (clock, &res.cts_32khz, &res.n_32khz,32000 );amdgpu_afmt_calc_cts (clock, &res.cts_44_1khz, &res.n_44_1khz,44100 );amdgpu_afmt_calc_cts (clock, &res.cts_48khz, &res.n_48khz,48000 ); + res.clock = clock;return res; }
Signature · 1 line
2.34.1
Re: [PATCH v2 1/2] drm/amdgpu: Fix uninitialized variable warning in amdgpu_afmt_acr
Quoted 5 lines · Ma Jun
Assign value to clock to fix the warning below:
"Using uninitialized value res. Field res.clock is uninitialized"Signed-off-by Ma Jun <[email protected]>
Quoted 19 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_afmt.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/amd/amdgpu/amdgpu_afmt.c +1
-1@@ -100,6 +100,7 @@ struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock)amdgpu_afmt_calc_cts (clock, &res.cts_32khz, &res.n_32khz,32000 );amdgpu_afmt_calc_cts (clock, &res.cts_44_1khz, &res.n_44_1khz,44100 );amdgpu_afmt_calc_cts (clock, &res.cts_48khz, &res.n_48khz,48000 ); + res.clock = clock;return res; } --2.34.1
PATCH v2 2/2 drm/amdgpu: Fix the uninitialized variable warning
In reply to Ma JunInitialize the phy_id to 0 to fix the warning of
"Using uninitialized value phy_id"
--- drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +5 -1
@@ -95,7 +95,7 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __ustruct psp_context *psp = &adev->psp;struct ta_securedisplay_cmd *securedisplay_cmd;struct drm_device *dev =adev_to_drm (adev); -uint32_t phy_id; +uint32_t phy_id =0 ;uint32_t op;char str[64 ];int ret;
@@ -135,6 +135,10 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __umutex_unlock (&psp->securedisplay_context.mutex);break ;case 2 : +if (size <3 ) { +dev_err (adev->dev,"Invalid input: %s\n" , str); +return -EINVAL ; + }mutex_lock (&psp->securedisplay_context.mutex);psp_prep_securedisplay_cmd_buf (psp, &securedisplay_cmd,TA_SECUREDISPLAY_COMMAND__SEND_ROI_CRC );
Signature · 1 line
2.34.1
Re: [PATCH v2 2/2] drm/amdgpu: Fix the uninitialized variable warning
Quoted 22 lines · Ma Jun
Initialize the
phy_idto 0 to fix the warning of
"Using uninitialized valuephy_id"Signed-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +1
-1@@ -95,7 +95,7 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __ustruct psp_context *psp = &adev->psp;struct ta_securedisplay_cmd *securedisplay_cmd;struct drm_device *dev =adev_to_drm (adev); -uint32_t phy_id; +uint32_t phy_id =0 ;uint32_t op;char str[64 ];int ret;
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __u · line 141
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +4
-0@@ -135,6 +135,10 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __umutex_unlock (&psp->securedisplay_context.mutex);break ;case 2 : +if (size <3 ) { +dev_err (adev->dev,"Invalid input: %s\n" , str); +return -EINVAL ; + }
Better is to check the return of sscanf to see if phy_id value is successfully scanned. Otherwise, return error.
Thanks,
Lijo
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +0
-0mutex_lock (&psp->securedisplay_context.mutex);psp_prep_securedisplay_cmd_buf (psp, &securedisplay_cmd,TA_SECUREDISPLAY_COMMAND__SEND_ROI_CRC );
Re: [PATCH v2 2/2] drm/amdgpu: Fix the uninitialized variable warning
Quoted 27 lines · Lijo
Quoted 24 lines · Ma Jun
Initialize the
phy_idto 0 to fix the warning of
"Using uninitialized valuephy_id"Signed-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +1
-1@@ -95,7 +95,7 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __ustruct psp_context *psp = &adev->psp;struct ta_securedisplay_cmd *securedisplay_cmd;struct drm_device *dev =adev_to_drm (adev); -uint32_t phy_id; +uint32_t phy_id =0 ;uint32_t op;char str[64 ];int ret;@@ -135,6 +135,10 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __umutex_unlock (&psp->securedisplay_context.mutex);break ;
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __u · line 141
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +4
-0case 2 : +if (size <3 ) { +dev_err (adev->dev,"Invalid input: %s\n" , str); +return -EINVAL ; + }Better is to check the return of sscanf to see if
phy_idvalue is successfully scanned. Otherwise, return error.
Thanks, will fix in v3
Regards,
Ma Jun
Quoted 7 lines
Thanks,
LijoQuoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +0
-0mutex_lock (&psp->securedisplay_context.mutex);psp_prep_securedisplay_cmd_buf (psp, &securedisplay_cmd,TA_SECUREDISPLAY_COMMAND__SEND_ROI_CRC );
Re: [PATCH v2 2/2] drm/amdgpu: Fix the uninitialized variable warning
In reply to Ma JunQuoted 14 lines · Ma Jun
Initialize the
phy_idto 0 to fix the warning of
"Using uninitialized valuephy_id"Signed-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __u · line 98
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +1
-1@@ -95,7 +95,7 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __ustruct psp_context *psp = &adev->psp;struct ta_securedisplay_cmd *securedisplay_cmd;struct drm_device *dev =adev_to_drm (adev); -uint32_t phy_id; +uint32_t phy_id =0 ;
You can drop this hunk now that you added the check below.
Alex
Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +4
-1uint32_t op;char str[64 ];int ret;@@ -135,6 +135,10 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __umutex_unlock (&psp->securedisplay_context.mutex);break ;case 2 : +if (size <3 ) { +dev_err (adev->dev,"Invalid input: %s\n" , str); +return -EINVAL ; + }mutex_lock (&psp->securedisplay_context.mutex);psp_prep_securedisplay_cmd_buf (psp, &securedisplay_cmd,TA_SECUREDISPLAY_COMMAND__SEND_ROI_CRC ); --2.34.1
Christian König
maintainerAm 25.04.24 um 12:00 schrieb Ma Jun:
Quoted 13 lines
Check the ring type value to fix the out-of-bounds write warning
Signed-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, · line 360
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +5
-0@@ -353,6 +353,11 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, ring->hw_prio = hw_prio;if (!ring->no_scheduler) { +if (ring->funcs->type >=AMDGPU_HW_IP_NUM ) { +dev_warn (adev->dev,"ring type %d has no scheduler\n" , ring->funcs->type); +return 0 ; + } +
That check should probably be at the beginning of the function since trying to initialize a ring with an invalid type should be rejected immediately.
Regards,
Christian.
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0hw_ip = ring->funcs->type; num_sched = &adev->gpu_sched[hw_ip][hw_prio].num_scheds; adev->gpu_sched[hw_ip][hw_prio].sched[(*num_sched)++] =
Quoted 18 lines · Christian König
Am 25.04.24 um 12:00 schrieb Ma Jun:
Quoted 15 lines
Check the ring type value to fix the out-of-bounds write warning
Signed-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -353,6 +353,11 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, ring->hw_prio = hw_prio;
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, · line 360
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +5
-0if (!ring->no_scheduler) { +if (ring->funcs->type >=AMDGPU_HW_IP_NUM ) { +dev_warn (adev->dev,"ring type %d has no scheduler\n" , ring->funcs->type); +return 0 ; + } +That check should probably be at the beginning of the function since trying to initialize a ring with an invalid type should be rejected immediately.
This check is used to skip the gpu_sched setting for the rings which don't have scheduler, such as KIQ, MES, UMSCH_MM. Without this check, there could be an potential out-of-bounds writing when ring->no__scheduler is not set correctly.
Regards,
Ma Jun
Quoted 7 lines
Regards,
Christian.Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0hw_ip = ring->funcs->type; num_sched = &adev->gpu_sched[hw_ip][hw_prio].num_scheds; adev->gpu_sched[hw_ip][hw_prio].sched[(*num_sched)++] =
Christian König
maintainerAm 26.04.24 um 05:24 schrieb Ma, Jun:
Quoted 27 lines · Christian König
Quoted 16 lines
Am 25.04.24 um 12:00 schrieb Ma Jun:
Quoted 15 lines
Check the ring type value to fix the out-of-bounds write warning
Signed-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -353,6 +353,11 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, ring->hw_prio = hw_prio;Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, · line 360
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +5
-0if (!ring->no_scheduler) { +if (ring->funcs->type >=AMDGPU_HW_IP_NUM ) { +dev_warn (adev->dev,"ring type %d has no scheduler\n" , ring->funcs->type); +return 0 ; + } +That check should probably be at the beginning of the function since trying to initialize a ring with an invalid type should be rejected immediately.
Quoted 4 lines
This check is used to skip the
gpu_schedsetting for the rings which don't have scheduler, such as KIQ, MES,UMSCH_MM. Without this check, there could be an potential out-of-bounds writing whenring->no__scheduleris not set correctly.
Ah! In this case that that is not really clean.
Probably best approach is to change the "if (!ring->no_scheduler)" instead.
Maybe even move this code here into amdgpu_ctx.c:
hw_ip = ring->funcs->type;
num_sched = &adev->gpu_sched[hw_ip][hw_prio].num_scheds; adev->gpu_sched[hw_ip][hw_prio].sched[(*num_sched)++] = &ring->sched;
And then add something like hw_ip <= AMDGPU_HW_IP_NUM.
Background is that it is perfectly valid to have a scheduler for the MES for example.
Regards,
Christian.
Quoted 10 lines
Regards,
Ma JunQuoted 6 lines
Regards,
Christian.Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0hw_ip = ring->funcs->type; num_sched = &adev->gpu_sched[hw_ip][hw_prio].num_scheds; adev->gpu_sched[hw_ip][hw_prio].sched[(*num_sched)++] =