Fri Mar 6 14:02:39 2015 UTC ()
Synchronize permission checks with upstream drm_ioctl_permit.


(riastradh)
diff -r1.13 -r1.14 src/sys/external/bsd/drm2/drm/drm_drv.c

cvs diff -r1.13 -r1.14 src/sys/external/bsd/drm2/drm/Attic/drm_drv.c (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/drm/Attic/drm_drv.c 2015/01/01 01:15:42 1.13
+++ src/sys/external/bsd/drm2/drm/Attic/drm_drv.c 2015/03/06 14:02:39 1.14
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: drm_drv.c,v 1.13 2015/01/01 01:15:42 mrg Exp $ */ 1/* $NetBSD: drm_drv.c,v 1.14 2015/03/06 14:02:39 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell. 8 * by Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: drm_drv.c,v 1.13 2015/01/01 01:15:42 mrg Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: drm_drv.c,v 1.14 2015/03/06 14:02:39 riastradh Exp $");
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/types.h> 36#include <sys/types.h>
37#include <sys/conf.h> 37#include <sys/conf.h>
38#include <sys/device.h> 38#include <sys/device.h>
39#include <sys/file.h> 39#include <sys/file.h>
40#include <sys/filedesc.h> 40#include <sys/filedesc.h>
41#include <sys/ioccom.h> 41#include <sys/ioccom.h>
42#include <sys/kauth.h> 42#include <sys/kauth.h>
43#ifndef _MODULE 43#ifndef _MODULE
44/* XXX Mega-kludge because modules are broken. */ 44/* XXX Mega-kludge because modules are broken. */
45#include <sys/once.h> 45#include <sys/once.h>
46#endif 46#endif
@@ -632,39 +632,48 @@ drm_ioctl(struct file *fp, unsigned long @@ -632,39 +632,48 @@ drm_ioctl(struct file *fp, unsigned long
632 const unsigned int driver_nr = nr - DRM_COMMAND_BASE; 632 const unsigned int driver_nr = nr - DRM_COMMAND_BASE;
633 if (driver_nr >= dev->driver->num_ioctls) 633 if (driver_nr >= dev->driver->num_ioctls)
634 return EINVAL; 634 return EINVAL;
635 ioctl = &dev->driver->ioctls[driver_nr]; 635 ioctl = &dev->driver->ioctls[driver_nr];
636 } else if (nr < __arraycount(drm_ioctls)) { 636 } else if (nr < __arraycount(drm_ioctls)) {
637 ioctl = &drm_ioctls[nr]; 637 ioctl = &drm_ioctls[nr];
638 } else { 638 } else {
639 ioctl = NULL; 639 ioctl = NULL;
640 } 640 }
641 641
642 if ((ioctl == NULL) || (ioctl->func == NULL)) 642 if ((ioctl == NULL) || (ioctl->func == NULL))
643 return EINVAL; 643 return EINVAL;
644 644
 645 /* XXX Synchronize with drm_ioctl_permit in upstream drm_drv.c. */
645 if (ISSET(ioctl->flags, DRM_ROOT_ONLY) && !DRM_SUSER()) 646 if (ISSET(ioctl->flags, DRM_ROOT_ONLY) && !DRM_SUSER())
646 return EACCES; 647 return EACCES;
647 648
648 if (ISSET(ioctl->flags, DRM_AUTH) && !file->authenticated) 649 if (ISSET(ioctl->flags, DRM_AUTH) &&
 650 (file->minor->type != DRM_MINOR_RENDER) &&
 651 !file->authenticated)
649 return EACCES; 652 return EACCES;
650 653
651 if (ISSET(ioctl->flags, DRM_MASTER) && (file->master == NULL)) 654 if (ISSET(ioctl->flags, DRM_MASTER) &&
 655 (file->master == NULL) &&
 656 (file->minor->type != DRM_MINOR_CONTROL))
652 return EACCES; 657 return EACCES;
653 658
654 if (!ISSET(ioctl->flags, DRM_CONTROL_ALLOW) && 659 if (!ISSET(ioctl->flags, DRM_CONTROL_ALLOW) &&
655 (file->minor->type == DRM_MINOR_CONTROL)) 660 (file->minor->type == DRM_MINOR_CONTROL))
656 return EACCES; 661 return EACCES;
657 662
 663 if (!ISSET(ioctl->flags, DRM_RENDER_ALLOW) &&
 664 (file->minor->type == DRM_MINOR_RENDER))
 665 return EACCES;
 666
658 if (!ISSET(ioctl->flags, DRM_UNLOCKED)) 667 if (!ISSET(ioctl->flags, DRM_UNLOCKED))
659 mutex_lock(&drm_global_mutex); 668 mutex_lock(&drm_global_mutex);
660 669
661 /* XXX errno Linux->NetBSD */ 670 /* XXX errno Linux->NetBSD */
662 error = -(*ioctl->func)(dev, data, file); 671 error = -(*ioctl->func)(dev, data, file);
663 672
664 if (!ISSET(ioctl->flags, DRM_UNLOCKED)) 673 if (!ISSET(ioctl->flags, DRM_UNLOCKED))
665 mutex_unlock(&drm_global_mutex); 674 mutex_unlock(&drm_global_mutex);
666 675
667 return error; 676 return error;
668} 677}
669 678
670static int 679static int