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: 50110 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1CD9222904 for ; Fri, 19 Jun 2015 13:52:49 +0000 (UTC) Received: by wizw5 with SMTP id w5sf5505224wiz.2 for ; Fri, 19 Jun 2015 06:52:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=pMQ/6w46aYMxfcofHIeXFPdwwaordYBW19tagiRAEV8=; b=YKL4snpx4tjnOA2V9RmEykbo/0VyZ8B2x99x53HC6FKdvtTS0cj9t3SAf5TQdVulBe Oe/eOyjNhOBnxFeDDx1+8xI2BG955X3a4WSUi7ByV74C5wJoMxhllzrwO1u3I+jof//b xFk9SWLJ4Oaf+7XXTwZBH76PoAInvrSoJBIy3GFRde5fX8jYOYrwoh2qXqAGUPo8JY1j 6/wv/QnMdcu2I7oTVWUX9rZaZjrKupUup9xU7zps45PRIIvVpRU8JtfbgXn3qNnCwPht gNY+R2+iPc3qqs8NceLZC6eyMTGRkXIOR6T/3tr5/lxltT7vzFphuu99YHjkJBh7tQ0W AESQ== X-Gm-Message-State: ALoCoQmYvXOFrZ3lgX8tsS6696cAz6DlE5lPU/KR56A+gDRDdyc+7tJEaZ53TQVlKp/KG523vsA7 X-Received: by 10.194.175.36 with SMTP id bx4mr12560152wjc.1.1434721967892; Fri, 19 Jun 2015 06:52:47 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.105 with SMTP id bf9ls586612lab.103.gmail; Fri, 19 Jun 2015 06:52:47 -0700 (PDT) X-Received: by 10.152.44.132 with SMTP id e4mr18258246lam.34.1434721967735; Fri, 19 Jun 2015 06:52:47 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id l5si9231399lbt.73.2015.06.19.06.52.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jun 2015 06:52:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by labbc20 with SMTP id bc20so74616558lab.1 for ; Fri, 19 Jun 2015 06:52:47 -0700 (PDT) X-Received: by 10.112.204.6 with SMTP id ku6mr17833805lbc.73.1434721967650; Fri, 19 Jun 2015 06:52:47 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp609769lbb; Fri, 19 Jun 2015 06:52:47 -0700 (PDT) X-Received: by 10.194.77.5 with SMTP id o5mr14006409wjw.140.1434721966055; Fri, 19 Jun 2015 06:52:46 -0700 (PDT) Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com. [209.85.212.172]) by mx.google.com with ESMTPS id bc8si19948856wjc.189.2015.06.19.06.52.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jun 2015 06:52:46 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.212.172 as permitted sender) client-ip=209.85.212.172; Received: by wicgi11 with SMTP id gi11so19399338wic.0 for ; Fri, 19 Jun 2015 06:52:45 -0700 (PDT) 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 Cc: Daniel Thompson , dri-devel@lists.freedesktop.org, Rob Clark , Benjamin Gaignard , Damien Hobson-Garcia , linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org, John Stultz , Sumit Semwal 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-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.thompson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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;