[PATCH 09/25] plugins/amdgpu: Check images were opened successfully
Tvrtko Ursulin <[email protected]> Wed, 11 Mar 2026 09:58:58 +0000
| Newsgroups | dev.linux.lists.criu |
|---|---|
| Message-ID | <[email protected]> |
Avoid potentially passing a NULL file pointer to fread/fwrite inside sdma_copy_bo() and therefore invoking undefined behaviour. Signed-off-by: Tvrtko Ursulin <[email protected]> Reviewed-By: David Francis <[email protected]> --- plugins/amdgpu/amdgpu_plugin_drm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/amdgpu/amdgpu_plugin_drm.c b/plugins/amdgpu/amdgpu_plugin_drm.c index 34014783c2d4..06976a81ce1a 100644 --- a/plugins/amdgpu/amdgpu_plugin_drm.c +++ b/plugins/amdgpu/amdgpu_plugin_drm.c @@ -210,6 +210,11 @@ static int restore_bo_contents_drm(int drm_render_minor, CriuRenderNode *rd, int snprintf(img_path, sizeof(img_path), IMG_DRM_PAGES_FILE, rd->id, drm_render_minor, i); bo_contents_fp = open_img_file(img_path, false, &image_size); + if (!bo_contents_fp) { + ret = -EIO; + pr_err("Failed to open BO image file %s\n", img_path); + break; + } ret = sdma_copy_bo(dmabufs[i], rd->bo_entries[i]->size, bo_contents_fp, buffer, buffer_size, h_dev, max_copy_size, SDMA_OP_VRAM_WRITE, true); @@ -380,6 +385,10 @@ int amdgpu_plugin_drm_dump_file(int fd, int id, struct stat *drm) snprintf(img_path, sizeof(img_path), IMG_DRM_PAGES_FILE, rd->id, rd->drm_render_minor, i); image_size = handle_entry.size; bo_contents_fp = open_img_file(img_path, true, &image_size); + if (!bo_contents_fp) { + ret = -EIO; + goto exit; + } posix_memalign(&buffer, sysconf(_SC_PAGE_SIZE), handle_entry.size); -- 2.52.0