]> www.infradead.org Git - users/hch/misc.git/commit
drm/virtio: Fix UAF in virtgpu_dma_buf_free_obj()
authorVivek Kasireddy <vivek.kasireddy@intel.com>
Thu, 12 Dec 2024 05:54:21 +0000 (21:54 -0800)
committerDmitry Osipenko <dmitry.osipenko@collabora.com>
Sun, 19 Jan 2025 12:12:28 +0000 (15:12 +0300)
commitdb8b2c0e2abc90d1025fd7f6d4461b21b1d3248e
treec2c1f0a4795865479105b482919ac62eb8bfc807
parentbea6afc1bfad1d44f87ee73cfb631533b82aa3e2
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: 2885e575abc7 ("drm/virtio: Add helpers to initialize and free the imported object")
Fixes: ca77f27a2665 ("drm/virtio: Import prime buffers from other devices as guest blobs")
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Cc: Gurchetan Singh <gurchetansingh@chromium.org>
Cc: Chia-I Wu <olvaffe@gmail.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20241212055421.775759-1-vivek.kasireddy@intel.com
Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Tested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
[dmitry.osipenko@collabora.com: Edited commit title]
drivers/gpu/drm/virtio/virtgpu_prime.c