]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drm/amdgpu: Fix potential fence use-after-free v2
authorshanzhulig <shanzhulig@gmail.com>
Wed, 28 Jun 2023 01:10:47 +0000 (18:10 -0700)
committerStefan Bader <stefan.bader@canonical.com>
Mon, 30 Oct 2023 11:00:14 +0000 (12:00 +0100)
BugLink: https://bugs.launchpad.net/bugs/2039110
[ Upstream commit 2e54154b9f27262efd0cb4f903cc7d5ad1fe9628 ]

fence Decrements the reference count before exiting.
Avoid Race Vulnerabilities for fence use-after-free.

v2 (chk): actually fix the use after free and not just move it.

Signed-off-by: shanzhulig <shanzhulig@gmail.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c

index df40db96d667fb22da37492cbf2977412eec5107..5a253d5a66dd17c7be7c5692e09c3d689d5dcdd6 100644 (file)
@@ -1623,15 +1623,15 @@ static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev,
                        continue;
 
                r = dma_fence_wait_timeout(fence, true, timeout);
+               if (r > 0 && fence->error)
+                       r = fence->error;
+
                dma_fence_put(fence);
                if (r < 0)
                        return r;
 
                if (r == 0)
                        break;
-
-               if (fence->error)
-                       return fence->error;
        }
 
        memset(wait, 0, sizeof(*wait));