All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felix Kuehling <felix.kuehling@amd.com>
To: Daniil Dulov <d.dulov@aladdin.ru>
Cc: lvc-project@linuxtesting.org, "David Airlie" <airlied@linux.ie>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	amd-gfx@lists.freedesktop.org, "Oak Zeng" <oak.zeng@intel.com>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"# v5 . 3+" <stable@vger.kernel.org>,
	"Christian König" <christian.koenig@amd.com>
Subject: Re: [PATCH v2] drm/amdkfd: Fix potential deallocation of previously deallocated memory.
Date: Thu, 11 May 2023 17:12:43 -0400	[thread overview]
Message-ID: <1435aa84-c45c-43ca-eac9-d9f85ebcf224@amd.com> (raw)
In-Reply-To: <20230511112314.29322-1-d.dulov@aladdin.ru>

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@aladdin.ru>

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

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


> ---
> v2: Move if (retval) inside previous if as Andi Shyti <andi.shyti@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,

WARNING: multiple messages have this Message-ID (diff)
From: Felix Kuehling <felix.kuehling@amd.com>
To: Daniil Dulov <d.dulov@aladdin.ru>
Cc: "Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"David Airlie" <airlied@linux.ie>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Oak Zeng" <oak.zeng@intel.com>,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org,
	"# v5 . 3+" <stable@vger.kernel.org>,
	lvc-project@linuxtesting.org
Subject: Re: [PATCH v2] drm/amdkfd: Fix potential deallocation of previously deallocated memory.
Date: Thu, 11 May 2023 17:12:43 -0400	[thread overview]
Message-ID: <1435aa84-c45c-43ca-eac9-d9f85ebcf224@amd.com> (raw)
In-Reply-To: <20230511112314.29322-1-d.dulov@aladdin.ru>

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@aladdin.ru>

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

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


> ---
> v2: Move if (retval) inside previous if as Andi Shyti <andi.shyti@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,

WARNING: multiple messages have this Message-ID (diff)
From: Felix Kuehling <felix.kuehling@amd.com>
To: Daniil Dulov <d.dulov@aladdin.ru>
Cc: lvc-project@linuxtesting.org, "David Airlie" <airlied@linux.ie>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	amd-gfx@lists.freedesktop.org, "Oak Zeng" <oak.zeng@intel.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"# v5 . 3+" <stable@vger.kernel.org>,
	"Christian König" <christian.koenig@amd.com>
Subject: Re: [PATCH v2] drm/amdkfd: Fix potential deallocation of previously deallocated memory.
Date: Thu, 11 May 2023 17:12:43 -0400	[thread overview]
Message-ID: <1435aa84-c45c-43ca-eac9-d9f85ebcf224@amd.com> (raw)
In-Reply-To: <20230511112314.29322-1-d.dulov@aladdin.ru>

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@aladdin.ru>

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

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


> ---
> v2: Move if (retval) inside previous if as Andi Shyti <andi.shyti@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,

  parent reply	other threads:[~2023-05-11 21:12 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18  6:55 [PATCH] drm/amdkfd: Fix potential deallocation of previously deallocated memory Daniil Dulov
2023-04-18  6:55 ` Daniil Dulov
2023-04-18  6:55 ` Daniil Dulov
2023-04-18  8:47 ` Andi Shyti
2023-04-18  8:47   ` Andi Shyti
2023-04-18 10:07   ` Krzysztof Kozlowski
2023-04-18 10:07     ` Krzysztof Kozlowski
2023-04-18 16:59     ` Andi Shyti
2023-04-18 16:59       ` Andi Shyti
2023-04-18 17:44       ` Andi Shyti
2023-04-18 17:44         ` Andi Shyti
2023-04-18 18:12         ` Daniil Dulov
2023-04-18 18:12           ` Daniil Dulov
2023-05-11 11:23         ` [PATCH v2] " Daniil Dulov
2023-05-11 11:23           ` Daniil Dulov
2023-05-11 11:23           ` Daniil Dulov
2023-05-11 11:28           ` kernel test robot
2023-05-11 21:12           ` Felix Kuehling [this message]
2023-05-11 21:12             ` Felix Kuehling
2023-05-11 21:12             ` Felix Kuehling

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435aa84-c45c-43ca-eac9-d9f85ebcf224@amd.com \
    --to=felix.kuehling@amd.com \
    --cc=airlied@linux.ie \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=d.dulov@aladdin.ru \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=oak.zeng@intel.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.