[PATCH] drm/amdkfd: Fix potential deallocation of previously deallocated memory.

Krzysztof Kozlowski krzk at kernel.org
Tue Apr 18 10:07:15 UTC 2023


On 18/04/2023 10:47, Andi Shyti wrote:
> Hi Daniil,
> 
> On Mon, Apr 17, 2023 at 11:55:21PM -0700, Daniil Dulov wrote:
>> Pointer mqd_mem_obj can be deallocated in kfd_gtt_sa_allocate().
>> The function then returns non-zero value, which causes the second deallocation.
>>
>> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>>
>> Fixes: d1f8f0d17d40 ("drm/amdkfd: Move non-sdma mqd allocation out of init_mqd")
>> Signed-off-by: Daniil Dulov <d.dulov at aladdin.ru>
>> ---
>>  drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
>> index 3b6f5963180d..bce11c5b07d6 100644
>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
>> @@ -119,7 +119,8 @@ static struct kfd_mem_obj *allocate_mqd(struct kfd_dev *kfd,
>>  	}
>>  
>>  	if (retval) {
>> -		kfree(mqd_mem_obj);
>> +		if (mqd_mem_obj)
>> +			kfree(mqd_mem_obj);
> 
> I think this is not needed. kfree() returns immediately if
> mqd_mem_obj is NULL.
> 

Yep, the tool has to be fixed because such patch is just misleading.
However different point - the commit description actually describes
entirely different case: double free. Maybe the issue is true, just the
fix is wrong?

Best regards,
Krzysztof



More information about the dri-devel mailing list