]> www.infradead.org Git - users/hch/misc.git/commitdiff
drm/xe/migrate: prevent potential UAF
authorMatthew Auld <matthew.auld@intel.com>
Thu, 31 Jul 2025 09:38:11 +0000 (10:38 +0100)
committerMatthew Auld <matthew.auld@intel.com>
Thu, 7 Aug 2025 15:59:22 +0000 (16:59 +0100)
If we hit the error path, the previous fence (if there is one) has
already been put() prior to this, so doing a fence_wait could lead to
UAF. Tweak the flow to do to the put() until after we do the wait.

Fixes: 270172f64b11 ("drm/xe: Update xe_ttm_access_memory to use GPU for non-visible access")
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Maciej Patelczyk <maciej.patelczyk@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Stuart Summers <stuart.summers@intel.com>
Link: https://lore.kernel.org/r/20250731093807.207572-8-matthew.auld@intel.com
drivers/gpu/drm/xe/xe_migrate.c

index b36f5997706cb19a9c54ee0703eddfc3b2bcc04e..4effe10d815bd3d704d05b7d132d7c74b8561092 100644 (file)
@@ -2090,9 +2090,6 @@ int xe_migrate_access_memory(struct xe_migrate *m, struct xe_bo *bo,
                        current_bytes = min_t(int, current_bytes, S16_MAX * pitch);
                }
 
-               if (fence)
-                       dma_fence_put(fence);
-
                __fence = xe_migrate_vram(m, current_bytes,
                                          (unsigned long)buf & ~PAGE_MASK,
                                          &pagemap_addr[current_page],
@@ -2100,11 +2097,15 @@ int xe_migrate_access_memory(struct xe_migrate *m, struct xe_bo *bo,
                                          XE_MIGRATE_COPY_TO_VRAM :
                                          XE_MIGRATE_COPY_TO_SRAM);
                if (IS_ERR(__fence)) {
-                       if (fence)
+                       if (fence) {
                                dma_fence_wait(fence, false);
+                               dma_fence_put(fence);
+                       }
                        fence = __fence;
                        goto out_err;
                }
+
+               dma_fence_put(fence);
                fence = __fence;
 
                buf += current_bytes;