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

Felix Kuehling felix.kuehling at amd.com
Thu May 11 21:12:43 UTC 2023


On 2023-05-11 07:23, 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>

Thanks. I am applying this patch to amd-staging-drm-next.

Reviewed-by: Felix Kuehling <Felix.Kuehling at amd.com>


> ---
> v2: Move if (retval) inside previous if as Andi Shyti <andi.shyti at linux.intel.com> suggested.
>   drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 13 +++++++------
>   1 file changed, 7 insertions(+), 6 deletions(-)
>
> 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..dadeb2013fd9 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
> @@ -113,18 +113,19 @@ static struct kfd_mem_obj *allocate_mqd(struct kfd_dev *kfd,
>   			&(mqd_mem_obj->gtt_mem),
>   			&(mqd_mem_obj->gpu_addr),
>   			(void *)&(mqd_mem_obj->cpu_ptr), true);
> +
> +		if (retval) {
> +			kfree(mqd_mem_obj);
> +			return NULL;
> +		}
>   	} else {
>   		retval = kfd_gtt_sa_allocate(kfd, sizeof(struct v9_mqd),
>   				&mqd_mem_obj);
> -	}
> -
> -	if (retval) {
> -		kfree(mqd_mem_obj);
> -		return NULL;
> +		if (retval)
> +			return NULL;
>   	}
>   
>   	return mqd_mem_obj;
> -
>   }
>   
>   static void init_mqd(struct mqd_manager *mm, void **mqd,


More information about the dri-devel mailing list