Skip to content

Commit db8b2c0

Browse files
vivekkreddydigetx
authored andcommitted
drm/virtio: Fix UAF in virtgpu_dma_buf_free_obj()
Fix the following issues identified by Smatch static checker: - The call to dma_buf_put(attach->dmabuf) after dma_buf_detach() leads to a UAF bug as dma_buf_detach() frees the attach object. Fix this by extracting the dmabuf object from attach and using that in the call to dma_buf_put(). - The resv object is extracted from attach before checking to see if attach is valid (that is !NULL) or not. Although, attach would very likely be valid, fix this by making sure that the resv object is used only after ensuring that attach is valid. Fixes: 2885e57 ("drm/virtio: Add helpers to initialize and free the imported object") Fixes: ca77f27 ("drm/virtio: Import prime buffers from other devices as guest blobs") Cc: Gerd Hoffmann <[email protected]> Cc: Dmitry Osipenko <[email protected]> Cc: Gurchetan Singh <[email protected]> Cc: Chia-I Wu <[email protected]> Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Vivek Kasireddy <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Reviewed-by: Dmitry Osipenko <[email protected]> Tested-by: Dmitry Osipenko <[email protected]> Signed-off-by: Dmitry Osipenko <[email protected]> [[email protected]: Edited commit title]
1 parent bea6afc commit db8b2c0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/gpu/drm/virtio/virtgpu_prime.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,22 @@ static void virtgpu_dma_buf_free_obj(struct drm_gem_object *obj)
189189
struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj);
190190
struct virtio_gpu_device *vgdev = obj->dev->dev_private;
191191
struct dma_buf_attachment *attach = obj->import_attach;
192-
struct dma_resv *resv = attach->dmabuf->resv;
193192

194193
if (attach) {
195-
dma_resv_lock(resv, NULL);
194+
struct dma_buf *dmabuf = attach->dmabuf;
195+
196+
dma_resv_lock(dmabuf->resv, NULL);
196197

197198
virtio_gpu_detach_object_fenced(bo);
198199

199200
if (bo->sgt)
200201
dma_buf_unmap_attachment(attach, bo->sgt,
201202
DMA_BIDIRECTIONAL);
202203

203-
dma_resv_unlock(resv);
204+
dma_resv_unlock(dmabuf->resv);
204205

205-
dma_buf_detach(attach->dmabuf, attach);
206-
dma_buf_put(attach->dmabuf);
206+
dma_buf_detach(dmabuf, attach);
207+
dma_buf_put(dmabuf);
207208
}
208209

209210
if (bo->created) {

0 commit comments

Comments
 (0)