From patchwork Wed Nov 27 16:25:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 11264423 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 80ACA14ED for ; Wed, 27 Nov 2019 16:26:47 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 68873206E0 for ; Wed, 27 Nov 2019 16:26:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68873206E0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 425836E321; Wed, 27 Nov 2019 16:26:45 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by gabe.freedesktop.org (Postfix) with ESMTPS id B04656E321; Wed, 27 Nov 2019 16:26:44 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id a131so3435416wme.5; Wed, 27 Nov 2019 08:26:44 -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=qOVtybo7usSbjoqRS9lVUZgze/kCb5tgAd7kGTrcnVo=; b=aR1e1AcZTEz7vi2Kl+NGD+CiNVX/wYdV5bon8xuGzj9e7BYlxJEkJtW5d5w2OmDAwE /WfPAUYCpYdqqm0ilYHVd1CEOeP1SapCS31KgMqMbVDJLRlXh9IRy+FjzMUQsvi4Cyua S8BSrGfjjLkqYjRps9A6CImBiCLzcMaPBHejKYL64/DDhC8634Xa/fE7DBHtgUCKFpQR QMz60UK+dOf+KanzVpZ7BI4uwfxzI/C1grZS6CRnfSiZAZt34L/T4kYWEZlWefC/6C8P i3ojE02+91CZm6S+5xHWity5uPfgz4xoBHV0WO2ijmtHm2RhNcXqCeSpZzm+LFxWU9DN jaCA== X-Gm-Message-State: APjAAAV7j3gBVKnUf6SWX59Xqdnpxcqc593BJa+M/GRIrMSXnlc0dkuf muvnw8ek9i7zt5XOH4pMJFMiyuO8 X-Google-Smtp-Source: APXvYqyKREFCINTGZPzKlf23UoZFoaitJAwZDVukVF/q7qrvkzypIGaAuSCnKgOo7m0pUYXt787d3Q== X-Received: by 2002:a1c:9cce:: with SMTP id f197mr768632wme.133.1574872002926; Wed, 27 Nov 2019 08:26:42 -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 b1sm19680794wrs.74.2019.11.27.08.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 08:26:42 -0800 (PST) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH v2] drm: drop DRM_AUTH from PRIME_TO/FROM_HANDLE ioctls Date: Wed, 27 Nov 2019 16:25:54 +0000 Message-Id: <20191127162554.2494-1-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191101130313.8862-5-emil.l.velikov@gmail.com> References: <20191101130313.8862-5-emil.l.velikov@gmail.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qOVtybo7usSbjoqRS9lVUZgze/kCb5tgAd7kGTrcnVo=; b=VCFQFxd8bsRIJkYZEvCLkZLgV+/gP0jP41iyKSALeWJFBfl94LPndBwPOjuCoiVqFy GnO8aN1d4vHncXdkKi6nHlEYMakMk/71qX7xQOGITu70zEZZKrWKhlhkC9nRWvD2At06 u9vGNW0+Xwc6AfcPR+lDNurt3XrHv/3sB3lHEj3TmJA/3+EewJFcZR1nfV+3zvVgav0e 1syBVVp/8Xlvlhjw8Kz540nRWQnjeMZI03QLHYBG7n0wRd2SWNYrDcZDuz/9pwsjMC3v VuPaeLwNHPdhZJrEO9aIMY+D79TgYztrG4plJI70wNFEuAsHOjx+bRSXBrnw5PNn3313 FLvw== 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, amd-gfx@lists.freedesktop.org, Boris Brezillon , Alex Deucher , Sean Paul Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Emil Velikov Current validation requires that we're authenticated, even though we can bypass (by design) the authentication when using a render node. Let's address the former by following the design decision. v2: Add simpler validation in the ioctls themselves (Boris) Cc: Alex Deucher Cc: amd-gfx@lists.freedesktop.org Cc: Boris Brezillon Cc: Daniel Vetter Cc: Sean Paul Acked-by: Christian König Signed-off-by: Emil Velikov --- drivers/gpu/drm/drm_ioctl.c | 4 ++-- drivers/gpu/drm/drm_prime.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c index fcd728d7cf72..5afb39688b55 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -652,8 +652,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = { DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETRESOURCES, drm_mode_getresources, 0), - DRM_IOCTL_DEF(DRM_IOCTL_PRIME_HANDLE_TO_FD, drm_prime_handle_to_fd_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), - DRM_IOCTL_DEF(DRM_IOCTL_PRIME_FD_TO_HANDLE, drm_prime_fd_to_handle_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), + DRM_IOCTL_DEF(DRM_IOCTL_PRIME_HANDLE_TO_FD, drm_prime_handle_to_fd_ioctl, DRM_RENDER_ALLOW), + DRM_IOCTL_DEF(DRM_IOCTL_PRIME_FD_TO_HANDLE, drm_prime_fd_to_handle_ioctl, DRM_RENDER_ALLOW), DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPLANERESOURCES, drm_mode_getplane_res, 0), DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCRTC, drm_mode_getcrtc, 0), diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 0a2316e0e812..dab166c860ec 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -358,11 +358,27 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, } EXPORT_SYMBOL(drm_gem_prime_fd_to_handle); +static inline bool +allowed_ioctl(struct drm_device *dev, struct drm_file *file_priv) +{ + /* Unauthenticated master is allowed, for render capable devices */ + if (drm_is_primary_client(file_priv)) { + if (!file_priv->authenticated && + !drm_core_check_feature(dev, DRIVER_RENDER)) + return false; + } + + return true; +} + int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_prime_handle *args = data; + if (!allowed_ioctl(dev, file_priv)) + return -EACCES; + if (!dev->driver->prime_fd_to_handle) return -ENOSYS; @@ -511,6 +527,9 @@ int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data, { struct drm_prime_handle *args = data; + if (!allowed_ioctl(dev, file_priv)) + return -EACCES; + if (!dev->driver->prime_handle_to_fd) return -ENOSYS;