* [PATCH] drm/i915/gvt: fix dropping obj reference twice
@ 2019-11-06 7:31 Pan Bian
2019-11-06 8:43 ` Zhenyu Wang
0 siblings, 1 reply; 2+ messages in thread
From: Pan Bian @ 2019-11-06 7:31 UTC (permalink / raw)
To: Zhenyu Wang, Zhi Wang, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, David Airlie, Daniel Vetter
Cc: intel-gvt-dev, intel-gfx, dri-devel, linux-kernel, Pan Bian
The reference count of obj will be decremented twice if error occurs
in dma_buf_fd(). Additionally, attempting to read the reference count of
obj after dropping reference may lead to a use after free bug. Here, we
drop obj's reference until it is not used.
Signed-off-by: Pan Bian <bianpan2016@163.com>
---
drivers/gpu/drm/i915/gvt/dmabuf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/i915/gvt/dmabuf.c b/drivers/gpu/drm/i915/gvt/dmabuf.c
index 13044c027f27..4bfaefdf548d 100644
--- a/drivers/gpu/drm/i915/gvt/dmabuf.c
+++ b/drivers/gpu/drm/i915/gvt/dmabuf.c
@@ -498,8 +498,6 @@ int intel_vgpu_get_dmabuf(struct intel_vgpu *vgpu, unsigned int dmabuf_id)
goto out_free_gem;
}
- i915_gem_object_put(obj);
-
ret = dma_buf_fd(dmabuf, DRM_CLOEXEC | DRM_RDWR);
if (ret < 0) {
gvt_vgpu_err("create dma-buf fd failed ret:%d\n", ret);
@@ -524,6 +522,8 @@ int intel_vgpu_get_dmabuf(struct intel_vgpu *vgpu, unsigned int dmabuf_id)
file_count(dmabuf->file),
kref_read(&obj->base.refcount));
+ i915_gem_object_put(obj);
+
return dmabuf_fd;
out_free_dmabuf:
--
2.7.4
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] drm/i915/gvt: fix dropping obj reference twice
2019-11-06 7:31 [PATCH] drm/i915/gvt: fix dropping obj reference twice Pan Bian
@ 2019-11-06 8:43 ` Zhenyu Wang
0 siblings, 0 replies; 2+ messages in thread
From: Zhenyu Wang @ 2019-11-06 8:43 UTC (permalink / raw)
To: Pan Bian
Cc: Zhi Wang, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
David Airlie, Daniel Vetter, intel-gvt-dev, intel-gfx, dri-devel,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1459 bytes --]
On 2019.11.06 15:31:07 +0800, Pan Bian wrote:
> The reference count of obj will be decremented twice if error occurs
> in dma_buf_fd(). Additionally, attempting to read the reference count of
> obj after dropping reference may lead to a use after free bug. Here, we
> drop obj's reference until it is not used.
>
> Signed-off-by: Pan Bian <bianpan2016@163.com>
> ---
> drivers/gpu/drm/i915/gvt/dmabuf.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gvt/dmabuf.c b/drivers/gpu/drm/i915/gvt/dmabuf.c
> index 13044c027f27..4bfaefdf548d 100644
> --- a/drivers/gpu/drm/i915/gvt/dmabuf.c
> +++ b/drivers/gpu/drm/i915/gvt/dmabuf.c
> @@ -498,8 +498,6 @@ int intel_vgpu_get_dmabuf(struct intel_vgpu *vgpu, unsigned int dmabuf_id)
> goto out_free_gem;
> }
>
> - i915_gem_object_put(obj);
> -
> ret = dma_buf_fd(dmabuf, DRM_CLOEXEC | DRM_RDWR);
> if (ret < 0) {
> gvt_vgpu_err("create dma-buf fd failed ret:%d\n", ret);
> @@ -524,6 +522,8 @@ int intel_vgpu_get_dmabuf(struct intel_vgpu *vgpu, unsigned int dmabuf_id)
> file_count(dmabuf->file),
> kref_read(&obj->base.refcount));
>
> + i915_gem_object_put(obj);
> +
> return dmabuf_fd;
>
> out_free_dmabuf:
Looks fine to me. Thanks!
Reviewed-by: Zhenyu Wang <zhenyuw@linux.intel.com>
--
Open Source Technology Center, Intel ltd.
$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-06 8:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-06 7:31 [PATCH] drm/i915/gvt: fix dropping obj reference twice Pan Bian
2019-11-06 8:43 ` Zhenyu Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®