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 */