From patchwork Fri Jun 19 13:52:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 6645671 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id ED9619F358 for ; Fri, 19 Jun 2015 15:14:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6B9A220956 for ; Fri, 19 Jun 2015 15:14:06 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 83AF920561 for ; Fri, 19 Jun 2015 15:14:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 60C466E681; Fri, 19 Jun 2015 08:14:04 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by gabe.freedesktop.org (Postfix) with ESMTP id 6193D72045 for ; Fri, 19 Jun 2015 06:52:46 -0700 (PDT) Received: by wibee9 with SMTP id ee9so10373532wib.0 for ; Fri, 19 Jun 2015 06:52:45 -0700 (PDT) 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=pMQ/6w46aYMxfcofHIeXFPdwwaordYBW19tagiRAEV8=; b=H7i+qH/Sot0tQ/IxeO0O8+K499zBBjJKZjvQEN6quDTE1uOt6ZSv0/4okZMT03Eka9 AIu0w9xU+STya/HwQalxsYg9ueF9lzngzabqBGurQxNiiDtGOrBWGw7NOqcEoQ2n9nYM BWTn7xqWrTpn+PECyzujeroD8cFunoF3Tg1JQ8TdoI5C/vaiU6bbtcGxLk8E703nEKaR USPlbArlXj3dA8yu013HIaIFVTqPrRS3cAWag27+/0fu1vjRaTv+h1K1x/DloB2OUwSU WzI6c5y9EC/ATFIb5lIi1ztWmUj96uRKym0E9jS8kYEMnsssvdpS+3usI1NvSLDuSLB+ 5U6Q== X-Gm-Message-State: ALoCoQnYqPaMe1JeLTb8STaTdlzH4LmITjOpN/L4oYnNaMu1hkKJWR0upNJskQVpNhLZ+IYaupIf X-Received: by 10.194.76.237 with SMTP id n13mr25350399wjw.111.1434721965604; Fri, 19 Jun 2015 06:52:45 -0700 (PDT) Received: from wychelm.lan (cpc4-aztw19-0-0-cust71.18-1.cable.virginm.net. [82.33.25.72]) by mx.google.com with ESMTPSA id z9sm3855387wiv.9.2015.06.19.06.52.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jun 2015 06:52:44 -0700 (PDT) From: Daniel Thompson To: David Airlie Subject: [RESEND PATCH v2 v4.1-rc8 1/2] drm: prime: Honour O_RDWR during prime-handle-to-fd Date: Fri, 19 Jun 2015 14:52:28 +0100 Message-Id: <1434721949-25732-2-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1434721949-25732-1-git-send-email-daniel.thompson@linaro.org> References: <1434721949-25732-1-git-send-email-daniel.thompson@linaro.org> X-Mailman-Approved-At: Fri, 19 Jun 2015 08:14:03 -0700 Cc: Daniel Thompson , linaro-kernel@lists.linaro.org, patches@linaro.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Benjamin Gaignard , Damien Hobson-Garcia 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-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently DRM_IOCTL_PRIME_HANDLE_TO_FD rejects all flags except (DRM|O)_CLOEXEC making it difficult (maybe impossible) for userspace to mmap() the resulting dma-buf even when this is supported by the DRM driver. It is trivial to relax the restriction and permit read/write access. This is safe because the flags are seldom touched by drm; mostly they are passed verbatim to dma_buf calls. Signed-off-by: Daniel Thompson --- drivers/gpu/drm/drm_prime.c | 9 +++------ include/uapi/drm/drm.h | 1 + 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 7fec191b45f7..6d2cf4fb4038 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -331,7 +331,7 @@ static const struct dma_buf_ops drm_gem_prime_dmabuf_ops = { * drm_gem_prime_export - helper library implementation of the export callback * @dev: drm_device to export from * @obj: GEM object to export - * @flags: flags like DRM_CLOEXEC + * @flags: flags like DRM_CLOEXEC and DRM_RDWR * * This is the implementation of the gem_prime_export functions for GEM drivers * using the PRIME helpers. @@ -639,14 +639,11 @@ int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data, return -ENOSYS; /* check flags are valid */ - if (args->flags & ~DRM_CLOEXEC) + if (args->flags & ~(DRM_CLOEXEC | DRM_RDWR)) return -EINVAL; - /* we only want to pass DRM_CLOEXEC which is == O_CLOEXEC */ - flags = args->flags & DRM_CLOEXEC; - return dev->driver->prime_handle_to_fd(dev, file_priv, - args->handle, flags, &args->fd); + args->handle, args->flags, &args->fd); } int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data, diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h index ff6ef62d084b..092fe3fa8ec0 100644 --- a/include/uapi/drm/drm.h +++ b/include/uapi/drm/drm.h @@ -668,6 +668,7 @@ struct drm_set_client_cap { __u64 value; }; +#define DRM_RDWR O_RDWR #define DRM_CLOEXEC O_CLOEXEC struct drm_prime_handle { __u32 handle;