From patchwork Wed Nov 12 11:38:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 5287851 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9E4759F7DE for ; Wed, 12 Nov 2014 11:38:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B84DB20165 for ; Wed, 12 Nov 2014 11:38:49 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id DFE6120155 for ; Wed, 12 Nov 2014 11:38:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 64C3B6E26A; Wed, 12 Nov 2014 03:38:47 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by gabe.freedesktop.org (Postfix) with ESMTP id ABF7F6E206 for ; Wed, 12 Nov 2014 03:38:40 -0800 (PST) Received: by mail-wi0-f172.google.com with SMTP id bs8so4569237wib.11 for ; Wed, 12 Nov 2014 03:38:40 -0800 (PST) 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=dB3hhBDPW9tk5j6LdhQ2tdc8RXfUrUfBE3/S0q+hq90=; b=ecgiXYI+mZCNE5W4yMveutmm1Ul//VUkznJx/3Hpp/9jt0HmJMVH0MZ1b01syvuALX qJvlmFQIOknaSeiVK4jcjpUUp5nAOgJMuIOGOI7yAk2C6lFImMkdgyceOIOAYiZLqmot 02i50MNmGLl1aKtjLkzxdQ7PMhbYt76tk+xR7fRD1Gp0qG658Km8UeRK4iNMOssSDNNM ICNQiOo/uY2bnvnMOLgXz738VasOjdsVau5+ioZeo9/PmrKpyBUZ2NyvDOCZfjdST2dO xZa9/so949qY3hKRFI66EIOGX1XyM8s/9fY+YzQz6BJiN1dU/BiFQeY+HMLK+6RkpggG TFCw== X-Gm-Message-State: ALoCoQmE6bHbOHq+JHfSPioRY7gFS/MxcrmgrJ7Ap+lVwnSPqcbMMbKx/JiTkZnc0ZVW3Iu7xa14 X-Received: by 10.194.134.198 with SMTP id pm6mr3123903wjb.136.1415792319982; Wed, 12 Nov 2014 03:38:39 -0800 (PST) Received: from sundance.lan (cpc4-aztw19-0-0-cust157.18-1.cable.virginm.net. [82.33.25.158]) by mx.google.com with ESMTPSA id ji10sm21304728wid.7.2014.11.12.03.38.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Nov 2014 03:38:39 -0800 (PST) From: Daniel Thompson To: David Airlie Subject: [PATCH v2 v3.18-rc4 1/4] drm: prime: Honour O_RDWR during prime-handle-to-fd Date: Wed, 12 Nov 2014 11:38:12 +0000 Message-Id: <1415792295-2466-2-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1415792295-2466-1-git-send-email-daniel.thompson@linaro.org> References: <1415639805-17477-1-git-send-email-daniel.thompson@linaro.org> <1415792295-2466-1-git-send-email-daniel.thompson@linaro.org> Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Benjamin Gaignard 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=-2.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD,SUSPICIOUS_RECIPS,UNPARSEABLE_RELAY autolearn=ham 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 hard for the userspace to generate a file descriptor that can be used by mmap(). It is easy to relax the restriction and allow read/write permissions. This should be safe because the flags are seldom touched by drm; mostly they are passed verbatim to dma_buf calls. Signed-off-by: Daniel Thompson Reviewed-by: Rob Clark --- 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 78ca30808422..8467b17c8053 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 implemention 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. @@ -635,14 +635,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 b0b855613641..89c2b68ddc51 100644 --- a/include/uapi/drm/drm.h +++ b/include/uapi/drm/drm.h @@ -660,6 +660,7 @@ struct drm_set_client_cap { __u64 value; }; +#define DRM_RDWR O_RDWR #define DRM_CLOEXEC O_CLOEXEC struct drm_prime_handle { __u32 handle;