From patchwork Wed Dec 19 19:22:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 10738031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D4E1514DE for ; Wed, 19 Dec 2018 19:25:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3D5127D29 for ; Wed, 19 Dec 2018 19:25:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7ED927E5A; Wed, 19 Dec 2018 19:25:41 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5B6FB27D29 for ; Wed, 19 Dec 2018 19:25:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5DA416F169; Wed, 19 Dec 2018 19:25:39 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by gabe.freedesktop.org (Postfix) with ESMTPS id 061816F169 for ; Wed, 19 Dec 2018 19:25:36 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id y185so10249089wmd.1 for ; Wed, 19 Dec 2018 11:25:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ng57qfuULVl+QfSEngJ+uYqLaNdZ5BkQdHPe0AS5zAs=; b=hhZYhKrI8zxI1byvZRvH+YTmRex8tsCuicHRRvVPETZxnthVy8QAT0w0vaWQPQ1rGu qLtZoY4+0dyfZkSo7leVaGVWCDK/JYTkGmTkSluRIjbAU+cKW53IK/B3aRWLEF0mmtQK 23wRdQ72otE18ddN8ZunJVfFI2iKNbrlsq4XTyBtSFuYwsjIpmRY6zVWHN4UwhHhdn4H TfolADAJmYsp80XToP4nU1G1AjhcgWPi/hnMNvhoD3nihVeiCx6SWGJ8/CqR9GGmWwn3 h7E22n66V0LgBLoI4j3HGGmaXHw9ISb69SrjZjtnko73F+KfLJ+AY4ccZaadGhfOH3E3 4xRg== X-Gm-Message-State: AA+aEWbvdevp1lqp0/AsrBI9fWRwxWADtky2GxdNj+06qwRChBah3C84 QxQaJqmhRvY+03ujIoRuEYkK+7Bwxkc= X-Google-Smtp-Source: AFSGD/W0oS6BA16y3FqBsLfaagYtTkEx452C6EPcqWXVgmyOgORjr+UcaMZU6v+D70Vnr4aUw5TK4Q== X-Received: by 2002:a1c:f8f:: with SMTP id 137mr8171004wmp.96.1545247534146; Wed, 19 Dec 2018 11:25:34 -0800 (PST) Received: from arch-x1c3.cbg.collabora.co.uk ([2a00:5f00:102:0:9665:9cff:feee:aa4d]) by smtp.gmail.com with ESMTPSA id c9sm7385483wmh.27.2018.12.19.11.25.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 11:25:33 -0800 (PST) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/3] drm: change DROP_MASTER permissions to allow DRM_MASTER Date: Wed, 19 Dec 2018 19:22:45 +0000 Message-Id: <20181219192247.29880-2-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181219192247.29880-1-emil.l.velikov@gmail.com> References: <20181219192247.29880-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emil.l.velikov@gmail.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Emil Velikov Currently only DRM_ROOT_ONLY is allowed to call the ioctl. Change that to DRM_MASTER, which means that only a process that is the current DRM master can drop it. Which makes sense, the process should be able to opt-out without any specific requirements. Signed-off-by: Emil Velikov --- drivers/gpu/drm/drm_ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c index 94bd872d56c4..2221c8857fb0 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -578,7 +578,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = { DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_legacy_getsareactx, DRM_AUTH), DRM_IOCTL_DEF(DRM_IOCTL_SET_MASTER, drm_setmaster_ioctl, DRM_UNLOCKED|DRM_ROOT_ONLY), - DRM_IOCTL_DEF(DRM_IOCTL_DROP_MASTER, drm_dropmaster_ioctl, DRM_UNLOCKED|DRM_ROOT_ONLY), + DRM_IOCTL_DEF(DRM_IOCTL_DROP_MASTER, drm_dropmaster_ioctl, DRM_UNLOCKED|DRM_MASTER), DRM_IOCTL_DEF(DRM_IOCTL_ADD_CTX, drm_legacy_addctx, DRM_AUTH|DRM_ROOT_ONLY), DRM_IOCTL_DEF(DRM_IOCTL_RM_CTX, drm_legacy_rmctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), From patchwork Wed Dec 19 19:22:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 10738035 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A49516C2 for ; Wed, 19 Dec 2018 19:25:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9437027D29 for ; Wed, 19 Dec 2018 19:25:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88CC927E5A; Wed, 19 Dec 2018 19:25:48 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 568CD27D29 for ; Wed, 19 Dec 2018 19:25:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6366B6F16B; Wed, 19 Dec 2018 19:25:47 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by gabe.freedesktop.org (Postfix) with ESMTPS id 29EF56F169 for ; Wed, 19 Dec 2018 19:25:37 +0000 (UTC) Received: by mail-wm1-x342.google.com with SMTP id y139so7144323wmc.5 for ; Wed, 19 Dec 2018 11:25:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g0ayEe9XWPHXZB+3M5JX2isJD4dEF8GcxOpp3w3z0FI=; b=ZKrKxHtPbrgo6x4XZU8TJgqgmDisY5LAuydi1YT+ganUB6E3TXb8z68bA1f1VWct1Y LIgZVENfyPsHuOkOqQow+5OkwUNcw7gKcXtDJ6Zc5Y6ECjHYbriK/fvEcfPyckXh8g+d ITL68C4a51S0USUjEsAVgMBi8n3Sb7UJMlaGoSFHC/Sc+YBTaDpybtoUzzUS4JI6Q2vj +ngqrZt0M0Bvmlir2Tzq4SkixQgkmDy8tuCSplfkC9FyAKhwE4cp2z2dIRZMBEG/jP0N ctl2xGo7IPFGH8ZKBPrM4kUtYsuWZucH4cFNAxve6+C9pS6oaEpgg+aXElU6+J2ioGzm pXdA== X-Gm-Message-State: AA+aEWaoUn1awbel2zTW86b5LUqk/UAQIR/rfPLSkvmePLvNWLARMS7H 9kpQYGj9aV3VQum/m2WRdqG3BFBCP0c= X-Google-Smtp-Source: AFSGD/Xv938bdS7of3xFJ7Yzj1+4sg5ACfgPqDrEtSTt0lHaOsN7iPQ1hexSp4ubXrwLBQTWyJ4X3w== X-Received: by 2002:a1c:2e43:: with SMTP id u64mr8594587wmu.52.1545247535523; Wed, 19 Dec 2018 11:25:35 -0800 (PST) Received: from arch-x1c3.cbg.collabora.co.uk ([2a00:5f00:102:0:9665:9cff:feee:aa4d]) by smtp.gmail.com with ESMTPSA id c9sm7385483wmh.27.2018.12.19.11.25.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 11:25:34 -0800 (PST) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/3] drm: annotate drm_core_check_feature() dev arg. as const Date: Wed, 19 Dec 2018 19:22:46 +0000 Message-Id: <20181219192247.29880-3-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181219192247.29880-1-emil.l.velikov@gmail.com> References: <20181219192247.29880-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emil.l.velikov@gmail.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Emil Velikov This static inline function doesn't modify any state. Signed-off-by: Emil Velikov Reviewed-by: Daniel Vetter --- include/drm/drm_drv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 35af23f5fa0d..eca73330ffaf 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -666,7 +666,7 @@ static inline bool drm_dev_is_unplugged(struct drm_device *dev) * * Returns true if the @feature is supported, false otherwise. */ -static inline bool drm_core_check_feature(struct drm_device *dev, u32 feature) +static inline bool drm_core_check_feature(const struct drm_device *dev, u32 feature) { return dev->driver->driver_features & dev->driver_features & feature; } From patchwork Wed Dec 19 19:22:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 10738033 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93F6514DE for ; Wed, 19 Dec 2018 19:25:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 849B027D29 for ; Wed, 19 Dec 2018 19:25:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78B1D27E5A; Wed, 19 Dec 2018 19:25:43 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3533027D29 for ; Wed, 19 Dec 2018 19:25:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 034AC6F16A; Wed, 19 Dec 2018 19:25:40 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by gabe.freedesktop.org (Postfix) with ESMTPS id AFEBF6F169 for ; Wed, 19 Dec 2018 19:25:38 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id v13so20675564wrw.5 for ; Wed, 19 Dec 2018 11:25:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XYNt1j4R4bZNTWrWWq51m7bsezB/67s8CiaBi6YpMS4=; b=iXYc7eEjjTg+b0XNK0Wnp37mpWadcWhyrCMI9j2eI9U0KGwyp0S2xa4hwUaeQMeWYW FayxmbJtWMM0dRVqQXRGfdVAQY4hTFeJab4pM/fe6XG54/g5OofsNU55uIUa+b1mmr/O gcLCgEQYzgBKAuPvaF18tY0Ce9rSXAZKKObdAZi9DY0uwCUtDNXaxHp1NWuQeyR4W4T5 k8NwziQHPFHY9ljrrZ6w1rxXIISd5R6Ztu7kZwD++VjLac79NEeT6WRNogup8UwIjQb5 HdK492kMhfp5NYCAGa65kEuXZZUwu5AFxX4h/88vxNxcb1r0B9516ScXXTIk7z8OoCC/ /u7w== X-Gm-Message-State: AA+aEWb1ThWCFLmD/tOpOaWA5cJvkhk1XWJWFX3znIf9d4VBtvj7eMAJ A4XxPOCVtimHIwqf5Tpo03nVSU+Vo8U= X-Google-Smtp-Source: AFSGD/UxydZ7C0+w1My+vMuXMU9GjvpZ2KZ1XV2+KgVfqSduZkLDtazUQkowQngilBd+rZ64bPuARg== X-Received: by 2002:a5d:4dc8:: with SMTP id f8mr20348507wru.45.1545247536914; Wed, 19 Dec 2018 11:25:36 -0800 (PST) Received: from arch-x1c3.cbg.collabora.co.uk ([2a00:5f00:102:0:9665:9cff:feee:aa4d]) by smtp.gmail.com with ESMTPSA id c9sm7385483wmh.27.2018.12.19.11.25.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 11:25:36 -0800 (PST) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/3] drm: allow render capable master with DRM_AUTH ioctls Date: Wed, 19 Dec 2018 19:22:47 +0000 Message-Id: <20181219192247.29880-4-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181219192247.29880-1-emil.l.velikov@gmail.com> References: <20181219192247.29880-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emil.l.velikov@gmail.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Emil Velikov There are cases (in mesa and applications) where one would open the primary node without properly authenticating the client. Sometimes we don't check if the authentication succeeds, but there's also cases we simply forget to do it. Mesa has been fixed recently although, there's the question of older drivers or other apps that exbibit this behaviour. To workaround this, some users resort to running their apps under sudo. Which admittedly isn't always a good idea. Since any DRIVER_RENDER driver has sufficient isolation between clients, we can use that, for unauthenticated [primary node] ioctls that require DRM_AUTH. But only if the respective ioctl is tagged as DRM_RENDER_ALLOW. As an added bonus this allows us to use vgem in userspace with zero change to some (but not all) existing programs. Signed-off-by: Emil Velikov Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_ioctl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c index 2221c8857fb0..4c775b775395 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -521,13 +521,17 @@ int drm_version(struct drm_device *dev, void *data, */ int drm_ioctl_permit(u32 flags, struct drm_file *file_priv) { + const struct drm_device *dev = file_priv->minor->dev; + /* ROOT_ONLY is only for CAP_SYS_ADMIN */ if (unlikely((flags & DRM_ROOT_ONLY) && !capable(CAP_SYS_ADMIN))) return -EACCES; - /* AUTH is only for authenticated or render client */ + /* AUTH is only for authenticated/render capable master or render client */ if (unlikely((flags & DRM_AUTH) && !drm_is_render_client(file_priv) && - !file_priv->authenticated)) + !file_priv->authenticated && + !(drm_core_check_feature(dev, DRIVER_RENDER) && + (flags & DRM_RENDER_ALLOW)))) return -EACCES; /* MASTER is only for master or control clients */