Skip to content

Commit 0dd99f1

Browse files
amlutoairlied
authored andcommitted
drm: Don't leak phys_wc "handles" to userspace
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>
1 parent 03dae7c commit 0dd99f1

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎drivers/gpu/drm/drm_bufs.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,15 @@ int drm_addmap_ioctl(struct drm_device *dev, void *data,
414414

415415
/* avoid a warning on 64-bit, this casting isn't very nice, but the API is set so too late */
416416
map->handle = (void *)(unsigned long)maplist->user_token;
417+
418+
/*
419+
* It appears that there are no users of this value whatsoever --
420+
* drmAddMap just discards it. Let's not encourage its use.
421+
* (Keeping drm_addmap_core's returned mtrr value would be wrong --
422+
* it's not a real mtrr index anymore.)
423+
*/
424+
map->mtrr = -1;
425+
417426
return 0;
418427
}
419428

‎drivers/gpu/drm/drm_ioctl.c‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838

3939
#include <linux/pci.h>
4040
#include <linux/export.h>
41+
#ifdef CONFIG_X86
42+
#include <asm/mtrr.h>
43+
#endif
4144

4245
/**
4346
* Get the bus id.
@@ -181,7 +184,17 @@ int drm_getmap(struct drm_device *dev, void *data,
181184
map->type = r_list->map->type;
182185
map->flags = r_list->map->flags;
183186
map->handle = (void *)(unsigned long) r_list->user_token;
184-
map->mtrr = r_list->map->mtrr;
187+
188+
#ifdef CONFIG_X86
189+
/*
190+
* There appears to be exactly one user of the mtrr index: dritest.
191+
* It's easy enough to keep it working on non-PAT systems.
192+
*/
193+
map->mtrr = phys_wc_to_mtrr_index(r_list->map->mtrr);
194+
#else
195+
map->mtrr = -1;
196+
#endif
197+
185198
mutex_unlock(&dev->struct_mutex);
186199

187200
return 0;

0 commit comments

Comments
 (0)