drm/amdgpu: Fix potential fence use-after-free v2
authorjsg <jsg@openbsd.org>
Thu, 24 Aug 2023 06:10:10 +0000 (06:10 +0000)
committerjsg <jsg@openbsd.org>
Thu, 24 Aug 2023 06:10:10 +0000 (06:10 +0000)
From shanzhulig
dd0b3b367c3839e439f36af908b39c98929a5e54 in linux-6.1.y/6.1.47
2e54154b9f27262efd0cb4f903cc7d5ad1fe9628 in mainline linux

sys/dev/pci/drm/amd/amdgpu/amdgpu_cs.c

index 22f8a5a..0508926 100644 (file)
@@ -1609,15 +1609,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));