Fix a buffer overflow in drm/amdgpu/smu
Subsystems (3)
PATCH 4/4 drm/amdgpu: minor code style enhancement for smu
In reply to Jiang LiuMinor code style enhancement for smu.
--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 2 +- drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
@@ -2153,7 +2153,7 @@ static int smu_resume(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;struct smu_context *smu = adev->powerplay.pp_handle; -if (amdgpu_sriov_vf (adev)&& !amdgpu_sriov_is_pp_one_vf (adev)) +if (amdgpu_sriov_vf (adev) && !amdgpu_sriov_is_pp_one_vf (adev))return 0 ;if (!smu->pm_enabled)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +1 -1
@@ -3524,8 +3524,8 @@ static const struct pptable_funcs smu_v13_0_6_ppt_funcs = { .init_power = smu_v13_0_init_power, .fini_power = smu_v13_0_fini_power, .check_fw_status = smu_v13_0_6_check_fw_status, -/* pptable related */ .check_fw_version = smu_v13_0_6_check_fw_version, +/* pptable related */ .set_driver_table_location = smu_v13_0_set_driver_table_location, .set_tool_table_location = smu_v13_0_set_tool_table_location, .notify_memory_pool_location = smu_v13_0_notify_memory_pool_location,
Signature · 1 line
2.43.5
cover Fix a buffer overflow in drm/amdgpu/smu
Fix several bugs in smu subsystem:
1) a buffer overflow bug in function smu_sys_set_pp_table()
2) tune logic of is_vcn_enabled()
3) enhance handling of gfx_off_entrycount in function smu_suspend()
Jiang Liu (4):
drm/amdgpu: avoid buffer overflow attach in smu_sys_set_pp_table() drm/amdgpu: accumulate gfx_off_entrycount in smu_suspend() drm/amdgpu: treat VCN as enabled if either VCN or JPEC is enabled drm/amdgpu: minor code style enhancement for smu
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 17 +++++++++-------- .../drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-)
Signature · 1 line
2.43.5
PATCH 2/4 drm/amdgpu: accumulate gfx_off_entrycount in smu_suspend()
As pwfw resets entrycount when device is suspended, so we should accmulate the gfx_off_entrycount value instead of save the last value of it.
--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -3
@@ -2134,12 +2134,12 @@ static int smu_suspend(struct amdgpu_ip_block *ip_block)smu_set_gfx_cgpg (smu, false);/* -* pwfw resets entrycount when device is suspended, so we save the -* last value to be used when we resume to keep it consistent +* pwfw resets entrycount when device is suspended, so we accumulate +* the `gfx_off_entrycount` value. */ ret =smu_get_entrycount_gfxoff (smu, &count);if (!ret) - adev->gfx.gfx_off_entrycount = count; + adev->gfx.gfx_off_entrycount += count;/* clear this on suspend so it will get reprogrammed on resume */ smu->workload_mask =0 ;
Signature · 1 line
2.43.5
PATCH 1/4 drm/amdgpu: avoid buffer overflow attach in smu_sys_set_pp_table()
In reply to Jiang LiuIt malicious user provides a small pptable through sysfs and then a bigger pptable, it may cause buffer overflow attack in function smu_sys_set_pp_table().
--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -1
@@ -612,7 +612,8 @@ static int smu_sys_set_pp_table(void *handle,return -EIO ; } -if (!smu_table->hardcode_pptable) { +if (!smu_table->hardcode_pptable || smu_table->power_play_table_size < size) { +kfree (smu_table->hardcode_pptable); smu_table->hardcode_pptable =kzalloc (size,GFP_KERNEL );if (!smu_table->hardcode_pptable)return -ENOMEM ;
Signature · 1 line
2.43.5
PATCH 3/4 drm/amdgpu: treat VCN as enabled if either VCN or JPEC is enabled
In reply to Jiang LiuFunction is_vcn_enabled() returns false if either the VCN or JPEG ip block is disabled, which sounds unreasonable. It should returns true when either VCN and JPEG is enabled.
--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -3
@@ -230,11 +230,11 @@ static bool is_vcn_enabled(struct amdgpu_device *adev)for (i =0 ; i < adev->num_ip_blocks; i++) {if ((adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_VCN || adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_JPEG ) && - !adev->ip_blocks[i].status.valid) -return false; + adev->ip_blocks[i].status.valid) +return true; } -return true; +return false; } static int smu_dpm_set_vcn_enable(struct smu_context *smu,
Signature · 1 line
2.43.5
Re: [v1 1/4] drm/amdgpu: avoid buffer overflow attach in smu_sys_set_pp_table()
In reply to Jiang LiuQuoted 5 lines · Jiang Liu
It malicious user provides a small pptable through sysfs and then a bigger pptable, it may cause buffer overflow attack in function
smu_sys_set_pp_table().Signed-off-by Jiang Liu <[email protected]>
Thanks,
Lijo
Quoted 18 lines
--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2
-1@@ -612,7 +612,8 @@ static int smu_sys_set_pp_table(void *handle,return -EIO ; } -if (!smu_table->hardcode_pptable) { +if (!smu_table->hardcode_pptable || smu_table->power_play_table_size < size) { +kfree (smu_table->hardcode_pptable); smu_table->hardcode_pptable =kzalloc (size,GFP_KERNEL );if (!smu_table->hardcode_pptable)return -ENOMEM ;
Re: [v1 2/4] drm/amdgpu: accumulate gfx_off_entrycount in smu_suspend()
In reply to Jiang LiuQuoted 16 lines · Jiang Liu
As pwfw resets entrycount when device is suspended, so we should accmulate the
gfx_off_entrycountvalue instead of save the last value of it.Signed-off-by Jiang Liu <[email protected]>--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0
-0@@ -2134,12 +2134,12 @@ static int smu_suspend(struct amdgpu_ip_block *ip_block)smu_set_gfx_cgpg (smu, false);
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_suspend(struct amdgpu_ip_block *ip_block) · line 2142
Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3
-3/* -* pwfw resets entrycount when device is suspended, so we save the -* last value to be used when we resume to keep it consistent +* pwfw resets entrycount when device is suspended, so we accumulate +* the `gfx_off_entrycount` value. */ ret =smu_get_entrycount_gfxoff (smu, &count);if (!ret) - adev->gfx.gfx_off_entrycount = count; + adev->gfx.gfx_off_entrycount += count;
This is slightly misleading - only Vangogh implements get_gfx_off_entrycount and its implementation, vangogh_get_gfxoff_entrycount, is already doing something like this -
*entrycount = value + adev->gfx.gfx_off_entrycount;
Thanks,
Lijo
Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0
-0/* clear this on suspend so it will get reprogrammed on resume */ smu->workload_mask =0 ;
Re: [v1 2/4] drm/amdgpu: accumulate gfx_off_entrycount in smu_suspend()
Quoted 38 lines
2025年2月7日 16:04,Lazar, Lijo <[email protected]> 写道:
Quoted 16 lines · Jiang Liu
As pwfw resets entrycount when device is suspended, so we should accmulate the
gfx_off_entrycountvalue instead of save the last value of it.Signed-off-by Jiang Liu <[email protected]>---
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0
-0@@ -2134,12 +2134,12 @@ static int smu_suspend(struct amdgpu_ip_block *ip_block)smu_set_gfx_cgpg (smu, false);drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_suspend(struct amdgpu_ip_block *ip_block) · line 2142
Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3
-3/* -* pwfw resets entrycount when device is suspended, so we save the -* last value to be used when we resume to keep it consistent +* pwfw resets entrycount when device is suspended, so we accumulate +* the `gfx_off_entrycount` value. */ ret =smu_get_entrycount_gfxoff (smu, &count);if (!ret) - adev->gfx.gfx_off_entrycount = count; + adev->gfx.gfx_off_entrycount += count;This is slightly misleading - only Vangogh implements
get_gfx_off_entrycountand its implementation,vangogh_get_gfxoff_entrycount, is already doing something like this -
Quoted 1 line
*entrycount = value +
adev->gfx.gfx_off_entrycount;
Because we have not restored the hardware counter by writing back the value on resume, adev->gfx.gfx_off_entrycount only remembers the latest value of latest suspend/resume cycle. And history information is lost, so changed it to accumulate all values.
Quoted 7 lines
Thanks,
LijoQuoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0
-0/* clear this on suspend so it will get reprogrammed on resume */ smu->workload_mask =0 ;
Re: [v1 2/4] drm/amdgpu: accumulate gfx_off_entrycount in smu_suspend()
Quoted 38 lines · Gerry Liu
Quoted 38 lines
2025年2月7日 16:04,Lazar, Lijo <[email protected]> 写道:
Quoted 16 lines · Jiang Liu
As pwfw resets entrycount when device is suspended, so we should accmulate the
gfx_off_entrycountvalue instead of save the last value of it.Signed-off-by Jiang Liu <[email protected]>---
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0
-0@@ -2134,12 +2134,12 @@ static int smu_suspend(struct amdgpu_ip_block *ip_block)smu_set_gfx_cgpg (smu, false);drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_suspend(struct amdgpu_ip_block *ip_block) · line 2142
Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3
-3/* -* pwfw resets entrycount when device is suspended, so we save the -* last value to be used when we resume to keep it consistent +* pwfw resets entrycount when device is suspended, so we accumulate +* the `gfx_off_entrycount` value. */ ret =smu_get_entrycount_gfxoff (smu, &count);if (!ret) - adev->gfx.gfx_off_entrycount = count; + adev->gfx.gfx_off_entrycount += count;This is slightly misleading - only Vangogh implements
get_gfx_off_entrycountand its implementation,vangogh_get_gfxoff_entrycount, is already doing something like this -
Quoted 3 lines
Quoted 1 line
*entrycount = value +
adev->gfx.gfx_off_entrycount;Because we have not restored the hardware counter by writing back the value on resume,
adev->gfx.gfx_off_entrycountonly remembers the latest value of latest suspend/resume cycle. And history information is lost, so changed it to accumulate all values.
What I meant is that accumulation is already done in the implementation side - check implementation of vangogh_get_gfxoff_entrycount.
Thanks,
Lijo
Quoted 9 lines
Quoted 8 lines
Thanks,
LijoQuoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0
-0/* clear this on suspend so it will get reprogrammed on resume */ smu->workload_mask =0 ;
Re: [v1 2/4] drm/amdgpu: accumulate gfx_off_entrycount in smu_suspend()
Quoted 45 lines
2025年2月7日 16:34,Lazar, Lijo <[email protected]> 写道:
Quoted 38 lines · Gerry Liu
Quoted 38 lines
2025年2月7日 16:04,Lazar, Lijo <[email protected]> 写道:
Quoted 16 lines · Jiang Liu
As pwfw resets entrycount when device is suspended, so we should accmulate the
gfx_off_entrycountvalue instead of save the last value of it.Signed-off-by Jiang Liu <[email protected]>---
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0
-0@@ -2134,12 +2134,12 @@ static int smu_suspend(struct amdgpu_ip_block *ip_block)smu_set_gfx_cgpg (smu, false);drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_suspend(struct amdgpu_ip_block *ip_block) · line 2142
Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3
-3/* -* pwfw resets entrycount when device is suspended, so we save the -* last value to be used when we resume to keep it consistent +* pwfw resets entrycount when device is suspended, so we accumulate +* the `gfx_off_entrycount` value. */ ret =smu_get_entrycount_gfxoff (smu, &count);if (!ret) - adev->gfx.gfx_off_entrycount = count; + adev->gfx.gfx_off_entrycount += count;This is slightly misleading - only Vangogh implements
get_gfx_off_entrycountand its implementation,vangogh_get_gfxoff_entrycount, is already doing something like this -
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
*entrycount = value +
adev->gfx.gfx_off_entrycount;Because we have not restored the hardware counter by writing back the value on resume,
adev->gfx.gfx_off_entrycountonly remembers the latest value of latest suspend/resume cycle. And history information is lost, so changed it to accumulate all values.What I meant is that accumulation is already done in the implementation side - check implementation of
vangogh_get_gfxoff_entrycount.
Aha, you are right, smu_suspend() calls smu_get_entrycount_gfxoff(), it already accumulates along the way. Will drop it.
Quoted 12 lines
Thanks,
LijoQuoted 8 lines
Quoted 8 lines
Thanks,
LijoQuoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0
-0/* clear this on suspend so it will get reprogrammed on resume */ smu->workload_mask =0 ;
Re: [v1 4/4] drm/amdgpu: minor code style enhancement for smu
In reply to Jiang LiuQuoted 13 lines · Jiang Liu
Minor code style enhancement for smu.
Signed-off-by Jiang Liu <[email protected]>--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 2 +- drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0
-0
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_resume(struct amdgpu_ip_block *ip_block) · line 2156
Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1
-1@@ -2153,7 +2153,7 @@ static int smu_resume(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;struct smu_context *smu = adev->powerplay.pp_handle; -if (amdgpu_sriov_vf (adev)&& !amdgpu_sriov_is_pp_one_vf (adev)) +if (amdgpu_sriov_vf (adev) && !amdgpu_sriov_is_pp_one_vf (adev))
This is already taken care in another patch. Rest of the patch is fine.
Thanks,
Lijo
Quoted 17 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0
-0return 0 ;if (!smu->pm_enabled)drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +1
-1@@ -3524,8 +3524,8 @@ static const struct pptable_funcs smu_v13_0_6_ppt_funcs = { .init_power = smu_v13_0_init_power, .fini_power = smu_v13_0_fini_power, .check_fw_status = smu_v13_0_6_check_fw_status, -/* pptable related */ .check_fw_version = smu_v13_0_6_check_fw_version, +/* pptable related */ .set_driver_table_location = smu_v13_0_set_driver_table_location, .set_tool_table_location = smu_v13_0_set_tool_table_location, .notify_memory_pool_location = smu_v13_0_notify_memory_pool_location,
Alex Deucher
AppliedRe: [v1 1/4] drm/amdgpu: avoid buffer overflow attach in smu_sys_set_pp_table()
In reply to Lazar, LijoApplied. Thanks!
Quoted 34 lines · Lijo
Quoted 5 lines · Jiang Liu
It malicious user provides a small pptable through sysfs and then a bigger pptable, it may cause buffer overflow attack in function
smu_sys_set_pp_table().Signed-off-by Jiang Liu <[email protected]>Reviewed-by Lijo Lazar <[email protected]>Thanks,
LijoQuoted 18 lines
--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2
-1@@ -612,7 +612,8 @@ static int smu_sys_set_pp_table(void *handle,return -EIO ; } -if (!smu_table->hardcode_pptable) { +if (!smu_table->hardcode_pptable || smu_table->power_play_table_size < size) { +kfree (smu_table->hardcode_pptable); smu_table->hardcode_pptable =kzalloc (size,GFP_KERNEL );if (!smu_table->hardcode_pptable)return -ENOMEM ;