From owner-freebsd-bugs@freebsd.org Thu Sep 20 13:17:03 2018 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AA1AE109C742 for ; Thu, 20 Sep 2018 13:17:03 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 308958C9E0 for ; Thu, 20 Sep 2018 13:17:03 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.ysv.freebsd.org (Postfix) id E8A00109C741; Thu, 20 Sep 2018 13:17:02 +0000 (UTC) Delivered-To: bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ACD1A109C740 for ; Thu, 20 Sep 2018 13:17:02 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.ysv.freebsd.org (mxrelay.ysv.freebsd.org [IPv6:2001:1900:2254:206a::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.ysv.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ACB28C9DF for ; Thu, 20 Sep 2018 13:17:02 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.ysv.freebsd.org (Postfix) with ESMTPS id A894B14F8B for ; Thu, 20 Sep 2018 13:17:01 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id w8KDH1JM046092 for ; Thu, 20 Sep 2018 13:17:01 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id w8KDH1TO046091 for bugs@FreeBSD.org; Thu, 20 Sep 2018 13:17:01 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 231513] off-by-one overflow in drm_ioctl (sys/dev/drm/drm_drv.c) Date: Thu, 20 Sep 2018 13:17:01 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: yangx92@hotmail.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Sep 2018 13:17:03 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D231513 Bug ID: 231513 Summary: off-by-one overflow in drm_ioctl (sys/dev/drm/drm_drv.c) Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: yangx92@hotmail.com Created attachment 197277 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D197277&action= =3Dedit patch_for_drm_out-of-bouns_access There is a off-by-one overflow in drm_ioctl (sys/dev/drm/drm_drv.c). 701 int drm_ioctl(struct cdev *kdev, u_long cmd, caddr_t data, int flags, 702 DRM_STRUCTPROC *p) 703 { 704 struct drm_device *dev =3D drm_get_device_from_kdev(kdev); 705 int retcode =3D 0; 706 drm_ioctl_desc_t *ioctl; 707 int (*func)(struct drm_device *dev, void *data, struct drm_file *file_priv); 708 int nr =3D DRM_IOCTL_NR(cmd); 709 int is_driver_ioctl =3D 0; 710 struct drm_file *file_priv; 711=20 ...=20 743 ioctl =3D &drm_ioctls[nr]; 744 /* It's not a core DRM ioctl, try driver-specific. */ 745 if (ioctl->func =3D=3D NULL && nr >=3D DRM_COMMAND_BASE) { 746 /* The array entries begin at DRM_COMMAND_BASE ioctl nr= */ 747 nr -=3D DRM_COMMAND_BASE; 748 if (nr > dev->driver->max_ioctl) { 749 DRM_DEBUG("Bad driver ioctl number, 0x%x (of 0x%x)\n", 750 nr, dev->driver->max_ioctl); 751 return EINVAL; 752 } 753 ioctl =3D &dev->driver->ioctls[nr]; 754 is_driver_ioctl =3D 1; 755 } 756 func =3D ioctl->func; 757=20 758 if (func =3D=3D NULL) { 759 DRM_DEBUG("no function\n"); 760 return EINVAL; 761 } 762=20 763 if (((ioctl->flags & DRM_ROOT_ONLY) && !DRM_SUSER(p)) || 764 ((ioctl->flags & DRM_AUTH) && !file_priv->authenticated) || 765 ((ioctl->flags & DRM_MASTER) && !file_priv->master)) 766 return EACCES; 767=20 768 if (is_driver_ioctl) { 769 DRM_LOCK(); 770 /* shared code returns -errno */ 771 retcode =3D -func(dev, data, file_priv); 772 DRM_UNLOCK(); 773 } else { 774 retcode =3D func(dev, data, file_priv); 775 } 776=20 777 if (retcode !=3D 0) 778 DRM_DEBUG(" returning %d\n", retcode); 779=20 780 return retcode; 781 } The correct logic for line 748 is nr >=3D dev->driver->max_ioctl. Otherwise, there would be out-of-bounds access in line 753. Then, ioctl is used in line 756. The attachment is the proposal patch. --=20 You are receiving this mail because: You are the assignee for the bug.=