drm: Don't leak phys_wc "handles" to userspace
authorAndy Lutomirski <luto@amacapital.net>
Mon, 13 May 2013 23:58:48 +0000 (23:58 +0000)
committerDave Airlie <airlied@redhat.com>
Fri, 31 May 2013 03:37:39 +0000 (13:37 +1000)
I didn't fix this in the earlier patch -- it would have broken the
build due to the now-deleted garbage in drm_os_linux.h.

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_bufs.c
drivers/gpu/drm/drm_ioctl.c

index 0190fce2007821c7f81ead1fc693e7ca5ffde8ca..5a4dbb410b71591f6f7b61a7d89f6f7609438578 100644 (file)
@@ -414,6 +414,15 @@ int drm_addmap_ioctl(struct drm_device *dev, void *data,
 
        /* avoid a warning on 64-bit, this casting isn't very nice, but the API is set so too late */
        map->handle = (void *)(unsigned long)maplist->user_token;
+
+       /*
+        * It appears that there are no users of this value whatsoever --
+        * drmAddMap just discards it.  Let's not encourage its use.
+        * (Keeping drm_addmap_core's returned mtrr value would be wrong --
+        *  it's not a real mtrr index anymore.)
+        */
+       map->mtrr = -1;
+
        return 0;
 }
 
index e77bd8b57df2acd666a2c3dc8d7cacf1540c5c74..ffd7a7ba70d496212c149bfd2a11798f5e01665f 100644 (file)
@@ -38,6 +38,9 @@
 
 #include <linux/pci.h>
 #include <linux/export.h>
+#ifdef CONFIG_X86
+#include <asm/mtrr.h>
+#endif
 
 /**
  * Get the bus id.
@@ -181,7 +184,17 @@ int drm_getmap(struct drm_device *dev, void *data,
        map->type = r_list->map->type;
        map->flags = r_list->map->flags;
        map->handle = (void *)(unsigned long) r_list->user_token;
-       map->mtrr = r_list->map->mtrr;
+
+#ifdef CONFIG_X86
+       /*
+        * There appears to be exactly one user of the mtrr index: dritest.
+        * It's easy enough to keep it working on non-PAT systems.
+        */
+       map->mtrr = phys_wc_to_mtrr_index(r_list->map->mtrr);
+#else
+       map->mtrr = -1;
+#endif
+
        mutex_unlock(&dev->struct_mutex);
 
        return 0;