Skip to content

Commit 145832f

Browse files
matt-auldrodrigovivi
authored andcommitted
drm/xe/migrate: prevent potential UAF
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: 270172f ("drm/xe: Update xe_ttm_access_memory to use GPU for non-visible access") Signed-off-by: Matthew Auld <[email protected]> Cc: Maciej Patelczyk <[email protected]> Cc: Matthew Brost <[email protected]> Reviewed-by: Stuart Summers <[email protected]> Link: https://lore.kernel.org/r/[email protected] (cherry picked from commit 9b7ca35) Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent 4126cb3 commit 145832f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/gpu/drm/xe/xe_migrate.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,21 +1893,22 @@ int xe_migrate_access_memory(struct xe_migrate *m, struct xe_bo *bo,
18931893
current_bytes = min_t(int, current_bytes, S16_MAX * pitch);
18941894
}
18951895

1896-
if (fence)
1897-
dma_fence_put(fence);
1898-
18991896
__fence = xe_migrate_vram(m, current_bytes,
19001897
(unsigned long)buf & ~PAGE_MASK,
19011898
dma_addr + current_page,
19021899
vram_addr, write ?
19031900
XE_MIGRATE_COPY_TO_VRAM :
19041901
XE_MIGRATE_COPY_TO_SRAM);
19051902
if (IS_ERR(__fence)) {
1906-
if (fence)
1903+
if (fence) {
19071904
dma_fence_wait(fence, false);
1905+
dma_fence_put(fence);
1906+
}
19081907
fence = __fence;
19091908
goto out_err;
19101909
}
1910+
1911+
dma_fence_put(fence);
19111912
fence = __fence;
19121913

19131914
buf += current_bytes;

0 commit comments

Comments
 (0)