From: "Christian König" <christian.koenig@amd.com>
To: Wentao_Liang <Wentao_Liang_g@163.com>,
alexander.deucher@amd.com, Xinhui.Pan@amd.com
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drivers:gpu:drm:amd:amdgpu:amdgpu_cs.c:fix a potential use-after-free
Date: Tue, 9 Aug 2022 15:28:08 +0200 [thread overview]
Message-ID: <7cf898fd-f3fe-061d-19ec-68d74627bd7d@amd.com> (raw)
In-Reply-To: <20220728121237.9201-1-Wentao_Liang_g@163.com>
Am 28.07.22 um 14:12 schrieb Wentao_Liang:
> in line 1535, "dma_fence_put(fence);" drop the reference to fence and may
> cause fence to be released. However, fence is used subsequently in line
> 1542 "fence->error". This may result in an use-after-free bug.
>
> It can be fixed by recording fence->error in a variable before dropping
> the reference to fence and referencing it after dropping.
>
> The bug has been confirmed by Christian König on 2021-08-16. Now, I
> resend this patch with my real name. I hope the patch can be updated
> in a near future.
The subject line should be something like "drm/amdgpu: fix potential use
after free".
>
> Signed-off-by: Wentao_Liang <Wentao_Liang_g@163.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index b28af04b0c3e..1d675a5838f2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -1518,7 +1518,7 @@ static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev,
> struct drm_amdgpu_fence *fences)
> {
> uint32_t fence_count = wait->in.fence_count;
> - unsigned int i;
> + unsigned int i, error;
> long r = 1;
>
> for (i = 0; i < fence_count; i++) {
> @@ -1533,14 +1533,15 @@ static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev,
>
> r = dma_fence_wait_timeout(fence, true, timeout);
> dma_fence_put(fence);
> + error = fence->error;
That's still the wrong order, you need to get the fence error before
dropping the reference.
Christian.
> if (r < 0)
> return r;
>
> if (r == 0)
> break;
>
> - if (fence->error)
> - return fence->error;
> + if (error)
> + return error;
> }
>
> memset(wait, 0, sizeof(*wait));
prev parent reply other threads:[~2022-08-09 13:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-28 12:12 Wentao_Liang
2022-08-09 13:28 ` Christian König [this message]
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=7cf898fd-f3fe-061d-19ec-68d74627bd7d@amd.com \
--to=christian.koenig@amd.com \
--cc=Wentao_Liang_g@163.com \
--cc=Xinhui.Pan@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®