drm/vmwgfx: Tighten the security around buffer maps
authorThomas Hellstrom <thellstrom@vmware.com>
Wed, 21 Nov 2012 15:04:18 +0000 (16:04 +0100)
committerDave Airlie <airlied@redhat.com>
Wed, 28 Nov 2012 10:09:08 +0000 (20:09 +1000)
Make sure that other DRM clients can't map the contents of
non-shareable buffer objects.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c

index ef1109c8fec8f8b597cb4776da02183573b6f004..96dc84dc34d05122c877322b3415eff84d64af39 100644 (file)
@@ -248,13 +248,12 @@ void vmw_evict_flags(struct ttm_buffer_object *bo,
        *placement = vmw_sys_placement;
 }
 
-/**
- * FIXME: Proper access checks on buffers.
- */
-
 static int vmw_verify_access(struct ttm_buffer_object *bo, struct file *filp)
 {
-       return 0;
+       struct ttm_object_file *tfile =
+               vmw_fpriv((struct drm_file *)filp->private_data)->tfile;
+
+       return vmw_user_dmabuf_verify_access(bo, tfile);
 }
 
 static int vmw_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)
index 34dce9e2b6d205db1d3b44cb91e71cc41897516b..13aeda71280e396069c70352513149e5455e768c 100644 (file)
@@ -461,6 +461,8 @@ extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
                           size_t size, struct ttm_placement *placement,
                           bool interuptable,
                           void (*bo_free) (struct ttm_buffer_object *bo));
+extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo,
+                                 struct ttm_object_file *tfile);
 extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
                                  struct drm_file *file_priv);
 extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
index 88b6f921ee947fbe0ce2c2007f592e1acbcbaadd..0def4ff5b621b24fbf8d74d6e2f5b57988f295be 100644 (file)
@@ -458,6 +458,26 @@ out_no_base_object:
        return ret;
 }
 
+/**
+ * vmw_user_dmabuf_verify_access - verify access permissions on this
+ * buffer object.
+ *
+ * @bo: Pointer to the buffer object being accessed
+ * @tfile: Identifying the caller.
+ */
+int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo,
+                                 struct ttm_object_file *tfile)
+{
+       struct vmw_user_dma_buffer *vmw_user_bo;
+
+       if (unlikely(bo->destroy != vmw_user_dmabuf_destroy))
+               return -EPERM;
+
+       vmw_user_bo = vmw_user_dma_buffer(bo);
+       return (vmw_user_bo->base.tfile == tfile ||
+       vmw_user_bo->base.shareable) ? 0 : -EPERM;
+}
+
 int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
                           struct drm_file *file_priv)
 {