From: Harsh Parmar <[email protected]>

A buffer object can legitimately have no backing store: a driver may
call ttm_bo_init_reserved() with zero placements, which leaves
bo->resource NULL. It can also become NULL after the backing store has
been released.

ttm_bo_vmap() passes bo->resource to ttm_mem_io_reserve() and then
dereferences it (mem->bus.*), causing a NULL pointer dereference when
called on such a buffer, e.g. via dma_buf_vmap() ->
drm_gem_dmabuf_vmap() -> drm_gem_ttm_vmap().

Bail out with -EINVAL if the buffer has no backing store.

Fixes: d3116756a710 ("drm/ttm: rename bo->mem and make it a pointer")
Signed-off-by: Harsh Parmar <[email protected]>
---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c 
b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 158f0df..01017e8 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -508,6 +508,9 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct 
iosys_map *map)
 
        dma_resv_assert_held(bo->base.resv);
 
+       if (!mem)
+               return -EINVAL;
+
        ret = ttm_mem_io_reserve(bo->bdev, mem);
        if (ret)
                return ret;
-- 
2.53.0

Reply via email to