drm/amd/pm: fix a double-free in si_dpm_init

Message ID 20231214152413.3483199-1-alexious@zju.edu.cn
State New
Headers
Series drm/amd/pm: fix a double-free in si_dpm_init |

Commit Message

Zhipeng Lu Dec. 14, 2023, 3:24 p.m. UTC
  When the allocation of
adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries fails,
amdgpu_free_extended_power_table is called to free some fields of adev.
However, when the control flow returns to si_dpm_sw_init, it goes to
label dpm_failed and calls si_dpm_fini, which calls
amdgpu_free_extended_power_table again and free those fields again. Thus
a double-free is triggered.

Fixes: 841686df9f7d ("drm/amdgpu: add SI DPM support (v4)")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
---
 drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
  

Comments

Alex Deucher Dec. 14, 2023, 5:03 p.m. UTC | #1
Applied.  Thanks!

On Thu, Dec 14, 2023 at 10:59 AM Zhipeng Lu <alexious@zju.edu.cn> wrote:
>
> When the allocation of
> adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries fails,
> amdgpu_free_extended_power_table is called to free some fields of adev.
> However, when the control flow returns to si_dpm_sw_init, it goes to
> label dpm_failed and calls si_dpm_fini, which calls
> amdgpu_free_extended_power_table again and free those fields again. Thus
> a double-free is triggered.
>
> Fixes: 841686df9f7d ("drm/amdgpu: add SI DPM support (v4)")
> Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> ---
>  drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c b/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
> index fc8e4ac6c8e7..df4f20293c16 100644
> --- a/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
> +++ b/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
> @@ -7379,10 +7379,9 @@ static int si_dpm_init(struct amdgpu_device *adev)
>                 kcalloc(4,
>                         sizeof(struct amdgpu_clock_voltage_dependency_entry),
>                         GFP_KERNEL);
> -       if (!adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries) {
> -               amdgpu_free_extended_power_table(adev);
> +       if (!adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries)
>                 return -ENOMEM;
> -       }
> +
>         adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.count = 4;
>         adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].clk = 0;
>         adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].v = 0;
> --
> 2.34.1
>
  

Patch

diff --git a/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c b/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
index fc8e4ac6c8e7..df4f20293c16 100644
--- a/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
+++ b/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
@@ -7379,10 +7379,9 @@  static int si_dpm_init(struct amdgpu_device *adev)
 		kcalloc(4,
 			sizeof(struct amdgpu_clock_voltage_dependency_entry),
 			GFP_KERNEL);
-	if (!adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries) {
-		amdgpu_free_extended_power_table(adev);
+	if (!adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries)
 		return -ENOMEM;
-	}
+
 	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.count = 4;
 	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].clk = 0;
 	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].v = 0;