Skip to content

Instantly share code, notes, and snippets.

@drinkcat
Last active May 14, 2018 07:48
Show Gist options
  • Save drinkcat/8456381 to your computer and use it in GitHub Desktop.
Save drinkcat/8456381 to your computer and use it in GitHub Desktop.
DRM fix
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 4177780..bbfc071 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -170,6 +170,9 @@ static struct drm_ioctl_desc drm_ioctls[] = {
#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
+/* Allow set/drop master ioctls as normal user */
+static u32 drm_master_relax = 0;
+
/**
* Take down the DRM device.
*
@@ -276,6 +279,11 @@ static int __init drm_core_init(void)
goto err_p3;
}
+ if (!debugfs_create_bool("drm_master_relax", S_IRUSR | S_IWUSR,
+ drm_debugfs_root, &drm_master_relax)) {
+ DRM_ERROR("Cannot create /sys/kernel/debug/dri/drm_master_relax\n");
+ }
+
DRM_INFO("Initialized %s %d.%d.%d %s\n",
CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
return 0;
@@ -292,7 +300,7 @@ err_p1:
static void __exit drm_core_exit(void)
{
remove_proc_entry("dri", NULL);
- debugfs_remove(drm_debugfs_root);
+ debugfs_remove_recursive(drm_debugfs_root);
drm_sysfs_destroy();
unregister_chrdev(DRM_MAJOR, "drm");
@@ -383,6 +391,7 @@ long drm_ioctl(struct file *filp,
char stack_kdata[128];
char *kdata = NULL;
unsigned int usize, asize;
+ int flags;
dev = file_priv->minor->dev;
@@ -424,6 +433,15 @@ long drm_ioctl(struct file *filp,
} else
goto err_i1;
+ flags = ioctl->flags;
+ if (drm_master_relax) {
+ if (nr == DRM_IOCTL_NR(DRM_IOCTL_SET_MASTER)) {
+ flags = DRM_AUTH;
+ } else if (nr == DRM_IOCTL_NR(DRM_IOCTL_DROP_MASTER)) {
+ flags = DRM_MASTER;
+ }
+ }
+
/* Do not trust userspace, use our own definition */
func = ioctl->func;
/* is there a local override? */
@@ -433,10 +451,10 @@ long drm_ioctl(struct file *filp,
if (!func) {
DRM_DEBUG("no function\n");
retcode = -EINVAL;
- } else if (((ioctl->flags & DRM_ROOT_ONLY) && !capable(CAP_SYS_ADMIN)) ||
- ((ioctl->flags & DRM_AUTH) && !file_priv->authenticated) ||
- ((ioctl->flags & DRM_MASTER) && !file_priv->is_master) ||
- (!(ioctl->flags & DRM_CONTROL_ALLOW) && (file_priv->minor->type == DRM_MINOR_CONTROL))) {
+ } else if (((flags & DRM_ROOT_ONLY) && !capable(CAP_SYS_ADMIN)) ||
+ ((flags & DRM_AUTH) && !file_priv->authenticated) ||
+ ((flags & DRM_MASTER) && !file_priv->is_master) ||
+ (!(flags & DRM_CONTROL_ALLOW) && (file_priv->minor->type == DRM_MINOR_CONTROL))) {
retcode = -EACCES;
} else {
if (cmd & (IOC_IN | IOC_OUT)) {
@@ -462,7 +480,7 @@ long drm_ioctl(struct file *filp,
} else
memset(kdata, 0, usize);
- if (ioctl->flags & DRM_UNLOCKED)
+ if (flags & DRM_UNLOCKED)
retcode = func(dev, kdata, file_priv);
else {
mutex_lock(&drm_global_mutex);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment