Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3682370pxv; Mon, 26 Jul 2021 09:17:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNDNxe2wldJ7jEBM1e87+uH5OWfjFUWJ/Tx43RA8gUkglkZAjzv1sJLfLwNuxC1ollv1h4 X-Received: by 2002:a92:dc4a:: with SMTP id x10mr13442500ilq.166.1627316257770; Mon, 26 Jul 2021 09:17:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627316257; cv=none; d=google.com; s=arc-20160816; b=CK37Are14YuxzusCZf4OjAYrIc6GZntlV6AhfgSMiU7ls5AlROmkY4yjmePdD9WtyJ k/EcffCGRwD+SKIlYuNNEB3IKgTyLQdHGNHit5QpPvsp0wFKQM4zKYF+VtBRNNAL/XXO Ysmte6JxUIP3ZM3mMhIwFwPQVWmKdYE0dCyXOiEnmz3GAa3vszDhf+6hqsvvEcbMkUNT Emu9d3k13CM3csIar1NIKDFFbx4rFXC1Fk18ma5u1TVV7mUt6vNoQbEcTx3KJ0qWcl83 2AHu2IyCZQ6rnq2HufwF0hmTzmvnCGU4pBXqW22XSE3/7M77eizCrxzF9PjwgSYNu2jX SdXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=I00l3Q4vopegxPvosGW012nmNakwhZfWc5ROHgEuiVs=; b=ZOXAFaC9KIBHR6Jj4i/x4X/62V+Oonx12FOsDO+EyW8Mv2733UI9yADm1kL4YMuXBH TGMI2w6Zwd51zLz9iQPFb0EGmHhyQqnl5eW9A58VbDUvYxbxM64uqiDRj4fezkSLco8I BkPuVQR6ks7Ag/m2/CvbIhaGt4vvX80i/PiA2jONb5KGiJL1lwVw8xl7Rdi3GcHkv3C4 S8bGLwvjhZ7aDkAo8D8Vc5CqY04V/IcRUZpEEjr/Xh+UFHZ81COEI/S+IZtW1Q7i6sPJ Sals7awHA6YrR7hrW1eNsUxlFlsmnyMHCjsRIqLiOlPQ8r2d+7AblYT2xS7lcKsfHBes eVvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q0vSnO4r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t15si262644ilg.47.2021.07.26.09.17.26; Mon, 26 Jul 2021 09:17:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q0vSnO4r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236347AbhGZPeS (ORCPT + 99 others); Mon, 26 Jul 2021 11:34:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:60532 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236110AbhGZPT0 (ORCPT ); Mon, 26 Jul 2021 11:19:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6B07C60F38; Mon, 26 Jul 2021 15:59:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315193; bh=6O/R5/EgTsRzWUbbEhc/kjHA1H6B4O4IbMck1UQPpaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q0vSnO4rnBjyQbejbUGmkbr+6PUzWFgtfK2Caa8EnRhHBflhg9EMsBDnJCcq4cWbe EUsxOGYUBt/pGTFE0wtpQlnH2wp+oShWj96aDurXuDNM2E3OCqhbhRtvUtUHztWWQM 1SDMxjtTcREHqGyQCfAaw2z/6QtJYFOMuzNza5Cg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Charles Baylis , Daniel Vetter Subject: [PATCH 5.4 100/108] drm: Return -ENOTTY for non-drm ioctls Date: Mon, 26 Jul 2021 17:39:41 +0200 Message-Id: <20210726153834.885830076@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153831.696295003@linuxfoundation.org> References: <20210726153831.696295003@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Charles Baylis commit 3abab27c322e0f2acf981595aa8040c9164dc9fb upstream. drm: Return -ENOTTY for non-drm ioctls Return -ENOTTY from drm_ioctl() when userspace passes in a cmd number which doesn't relate to the drm subsystem. Glibc uses the TCGETS ioctl to implement isatty(), and without this change isatty() returns it incorrectly returns true for drm devices. To test run this command: $ if [ -t 0 ]; then echo is a tty; fi < /dev/dri/card0 which shows "is a tty" without this patch. This may also modify memory which the userspace application is not expecting. Signed-off-by: Charles Baylis Cc: stable@vger.kernel.org Signed-off-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/YPG3IBlzaMhfPqCr@stando.fishzet.co.uk Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/drm_ioctl.c | 3 +++ include/drm/drm_ioctl.h | 1 + 2 files changed, 4 insertions(+) --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -826,6 +826,9 @@ long drm_ioctl(struct file *filp, if (drm_dev_is_unplugged(dev)) return -ENODEV; + if (DRM_IOCTL_TYPE(cmd) != DRM_IOCTL_BASE) + return -ENOTTY; + is_driver_ioctl = nr >= DRM_COMMAND_BASE && nr < DRM_COMMAND_END; if (is_driver_ioctl) { --- a/include/drm/drm_ioctl.h +++ b/include/drm/drm_ioctl.h @@ -68,6 +68,7 @@ typedef int drm_ioctl_compat_t(struct fi unsigned long arg); #define DRM_IOCTL_NR(n) _IOC_NR(n) +#define DRM_IOCTL_TYPE(n) _IOC_TYPE(n) #define DRM_MAJOR 226 /**