lkml.org 
[lkml]   [2022]   [Jun]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.18 095/879] drm/amd/pm: fix double free in si_parse_power_table()
    Date
    From: Keita Suzuki <keitasuzuki.park@sslab.ics.keio.ac.jp>

    [ Upstream commit f3fa2becf2fc25b6ac7cf8d8b1a2e4a86b3b72bd ]

    In function si_parse_power_table(), array adev->pm.dpm.ps and its member
    is allocated. If the allocation of each member fails, the array itself
    is freed and returned with an error code. However, the array is later
    freed again in si_dpm_fini() function which is called when the function
    returns an error.

    This leads to potential double free of the array adev->pm.dpm.ps, as
    well as leak of its array members, since the members are not freed in
    the allocation function and the array is not nulled when freed.
    In addition adev->pm.dpm.num_ps, which keeps track of the allocated
    array member, is not updated until the member allocation is
    successfully finished, this could also lead to either use after free,
    or uninitialized variable access in si_dpm_fini().

    Fix this by postponing the free of the array until si_dpm_fini() and
    increment adev->pm.dpm.num_ps everytime the array member is allocated.

    Signed-off-by: Keita Suzuki <keitasuzuki.park@sslab.ics.keio.ac.jp>
    Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c | 8 +++-----
    1 file changed, 3 insertions(+), 5 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 633dab14f51c..49c398ec0aaf 100644
    --- a/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
    +++ b/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
    @@ -7297,17 +7297,15 @@ static int si_parse_power_table(struct amdgpu_device *adev)
    if (!adev->pm.dpm.ps)
    return -ENOMEM;
    power_state_offset = (u8 *)state_array->states;
    - for (i = 0; i < state_array->ucNumEntries; i++) {
    + for (adev->pm.dpm.num_ps = 0, i = 0; i < state_array->ucNumEntries; i++) {
    u8 *idx;
    power_state = (union pplib_power_state *)power_state_offset;
    non_clock_array_index = power_state->v2.nonClockInfoIndex;
    non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
    &non_clock_info_array->nonClockInfo[non_clock_array_index];
    ps = kzalloc(sizeof(struct si_ps), GFP_KERNEL);
    - if (ps == NULL) {
    - kfree(adev->pm.dpm.ps);
    + if (ps == NULL)
    return -ENOMEM;
    - }
    adev->pm.dpm.ps[i].ps_priv = ps;
    si_parse_pplib_non_clock_info(adev, &adev->pm.dpm.ps[i],
    non_clock_info,
    @@ -7329,8 +7327,8 @@ static int si_parse_power_table(struct amdgpu_device *adev)
    k++;
    }
    power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
    + adev->pm.dpm.num_ps++;
    }
    - adev->pm.dpm.num_ps = state_array->ucNumEntries;

    /* fill in the vce power states */
    for (i = 0; i < adev->pm.dpm.num_of_vce_states; i++) {
    --
    2.35.1


    \
     
     \ /
      Last update: 2022-06-08 00:10    [W:3.557 / U:0.076 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site