From patchwork Wed Aug 3 18:04:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 9261691 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2B3A460754 for ; Wed, 3 Aug 2016 18:05:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 211DA28236 for ; Wed, 3 Aug 2016 18:05:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15F5A28306; Wed, 3 Aug 2016 18:05:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F03A28236 for ; Wed, 3 Aug 2016 18:05:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DA6006E896; Wed, 3 Aug 2016 18:05:07 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5D2B86E895 for ; Wed, 3 Aug 2016 18:04:59 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id q128so37536637wma.1 for ; Wed, 03 Aug 2016 11:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8ViTslsbZ9RHa4VfXhgiNhBISlC6FjxkxKTHS+NAuSc=; b=PFZDb9P3k5HQ03cmH+JLscl/Vpc4wU0f4TdkFd8smzmAiXwIg95e01oGUNxVnjzxqO 2vrmXMSJ28kv8Mz4xz94GcLPtII4NqE8yq1VJwPr9ZR6Abx8wIlwj9HVfpiFQvpfe+Ee R4qaJysPp7ZR2beV5HXx6pSJC67usHiYJX6PtEFvvSFcI+LLx2T0iEpgPm1gbu+PctNL ksQ84LZrga6GufLOwhoqrZaTkpQTHXMehxlYlwUJ5GJyzRX4TpaBErn50oLqJChiMsN9 d2I+zzxsIoiVSn+7qefbt5H8dLNPTNkkgzucvUrTLBfMeGaj+L6hPLaNleN6V9gTbibA gwNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8ViTslsbZ9RHa4VfXhgiNhBISlC6FjxkxKTHS+NAuSc=; b=SGpwwggcvr1w8OUG9qYCjx/gzPiAHiEJxZ/EI0hS/CIl5vZ4wpKXR5uTSlUd6hJ/fs dFon8+DcXK3ZVpQmmn9K7fEf6wzRqaj9c8T8G3LnU2L8A4v6/6oSgnMh8ZQS3jzu0bnX tFD5NCb5SE5ifs4p6siP2HcBrQNCcVlcJhPnlxizEI3kehmnhC+2M3Gl2KoQtSdavQOa 7JK4ZZhZ3E5Md+VYGeBOCJFZywJM86gAeByBFj+Okv7TNXrxST/YY0NnGCy8jw5kn1vH WBvFtRAdeTz4or9A9kYbPb7G/15p67mRFVqzdf9jZF8lZ1uRsn3KJpKKXqxkFAP6/Flo 02zg== X-Gm-Message-State: AEkoouvIhnjqDntv62C2oD7QlEp3Cn8fOkhcxs802sn3jJ3DJ2tO3qhfE3ntdJZzedVGCg== X-Received: by 10.28.104.137 with SMTP id d131mr25951236wmc.7.1470247496496; Wed, 03 Aug 2016 11:04:56 -0700 (PDT) Received: from localhost.localdomain ([37.120.18.65]) by smtp.gmail.com with ESMTPSA id va3sm8854296wjb.18.2016.08.03.11.04.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Aug 2016 11:04:55 -0700 (PDT) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/8] drm: remove redundant drm_file->uid Date: Wed, 3 Aug 2016 20:04:26 +0200 Message-Id: <20160803180432.1341-3-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.9.2 In-Reply-To: <20160803180432.1341-1-dh.herrmann@gmail.com> References: <20160803180432.1341-1-dh.herrmann@gmail.com> Cc: Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Each DRM file-context caches the EUID of the process that opened the file. It is used exclusively for debugging purposes in /proc/dri/ and friends. Note, however, that "struct file" already caches the credentials of a process at open-time. So lets just use drm_file->filp->f_cred->euid if available. The pointer-chasing will not hurt us, since it is only about debugging, anyway. Check priv->filp for NULL before deref, to prepare for in-kernel contexts (if they ever appear). We should not rely on "struct file" contexts to be around at all times, anyway. Signed-off-by: David Herrmann --- drivers/gpu/drm/drm_fops.c | 1 - drivers/gpu/drm/drm_info.c | 4 +++- drivers/gpu/drm/drm_ioctl.c | 4 +++- include/drm/drmP.h | 1 - 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c index 323c238..e9d66f5 100644 --- a/drivers/gpu/drm/drm_fops.c +++ b/drivers/gpu/drm/drm_fops.c @@ -199,7 +199,6 @@ static int drm_open_helper(struct file *filp, struct drm_minor *minor) filp->private_data = priv; priv->filp = filp; - priv->uid = current_euid(); priv->pid = get_pid(task_pid(current)); priv->minor = minor; diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c index 9ae353f..247ba2b 100644 --- a/drivers/gpu/drm/drm_info.c +++ b/drivers/gpu/drm/drm_info.c @@ -80,6 +80,7 @@ int drm_clients_info(struct seq_file *m, void *data) struct drm_info_node *node = (struct drm_info_node *) m->private; struct drm_device *dev = node->minor->dev; struct drm_file *priv; + kuid_t uid; seq_printf(m, "%20s %5s %3s master a %5s %10s\n", @@ -98,13 +99,14 @@ int drm_clients_info(struct seq_file *m, void *data) rcu_read_lock(); /* locks pid_task()->comm */ task = pid_task(priv->pid, PIDTYPE_PID); + uid = priv->filp ? priv->filp->f_cred->euid : GLOBAL_ROOT_UID; seq_printf(m, "%20s %5d %3d %c %c %5d %10u\n", task ? task->comm : "", pid_vnr(priv->pid), priv->minor->index, drm_is_current_master(priv) ? 'y' : 'n', priv->authenticated ? 'y' : 'n', - from_kuid_munged(seq_user_ns(m), priv->uid), + from_kuid_munged(seq_user_ns(m), uid), priv->magic); rcu_read_unlock(); } diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c index 33af4a5..49cd835 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -191,7 +191,9 @@ static int drm_getclient(struct drm_device *dev, void *data, client->auth = file_priv->authenticated; client->pid = pid_vnr(file_priv->pid); client->uid = from_kuid_munged(current_user_ns(), - file_priv->uid); + file_priv->filp ? + file_priv->filp->f_cred->euid : + GLOBAL_ROOT_UID); client->magic = 0; client->iocs = 0; diff --git a/include/drm/drmP.h b/include/drm/drmP.h index d488a72..0f69f56 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -320,7 +320,6 @@ struct drm_file { unsigned is_master:1; struct pid *pid; - kuid_t uid; drm_magic_t magic; struct list_head lhead; struct drm_minor *minor;