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: 40645 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8A930206A5 for ; Wed, 12 Nov 2014 11:38:42 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id f15sf6600856lbj.11 for ; Wed, 12 Nov 2014 03:38:41 -0800 (PST) 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=dB3hhBDPW9tk5j6LdhQ2tdc8RXfUrUfBE3/S0q+hq90=; b=HFAi7a4ALAXj4egEuq07m07gSpk6Z+3aFVdXvr9hGzwBuQKklfoAzRHsxksRoC3qYz hxoSdMzTb+n8fythuMT2ssRGh/DQM9H3tecrK/oXZ/+prrmwCWzJfCntUQyRqA4JMih/ DdgQt5xsisWSqopTOLFFqxmtiYmGvsYrUDDAAiARSHwtZIyz1xguN/6AcOnPbfr5G3S7 SuRf2HB0i9SjoAwOQ/pw9CNEMhhmxmgqNVUGbVTESsYNG3rTTe//2T9I+yjm8ONDu/2l suOyO/94nSU4zNIqCLxtT8u0Br03z5Gix65a7Q0/ODXsiei5A70J/aVProbyapeQ/Ksb WtMA== X-Gm-Message-State: ALoCoQm9vAQ0VMDFKnHgXn8OEvQGYl9G8O36kaks9c5IW1YE3Bg7guZCoWw9TxOnkeYLFwTtuCdv X-Received: by 10.112.48.98 with SMTP id k2mr304701lbn.15.1415792321285; Wed, 12 Nov 2014 03:38:41 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.3.5 with SMTP id 5ls675574lay.82.gmail; Wed, 12 Nov 2014 03:38:40 -0800 (PST) X-Received: by 10.112.133.138 with SMTP id pc10mr41945680lbb.48.1415792320950; Wed, 12 Nov 2014 03:38:40 -0800 (PST) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id b6si34442021lae.131.2014.11.12.03.38.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Nov 2014 03:38:40 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id gd6so10898744lab.20 for ; Wed, 12 Nov 2014 03:38:40 -0800 (PST) X-Received: by 10.112.235.196 with SMTP id uo4mr32167096lbc.66.1415792320865; Wed, 12 Nov 2014 03:38:40 -0800 (PST) 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.184.201 with SMTP id ew9csp407745lbc; Wed, 12 Nov 2014 03:38:40 -0800 (PST) X-Received: by 10.180.100.104 with SMTP id ex8mr44557656wib.80.1415792320226; Wed, 12 Nov 2014 03:38:40 -0800 (PST) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com. [209.85.212.181]) by mx.google.com with ESMTPS id ci4si27229673wib.83.2014.11.12.03.38.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Nov 2014 03:38:40 -0800 (PST) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.212.181 as permitted sender) client-ip=209.85.212.181; Received: by mail-wi0-f181.google.com with SMTP id n3so4546208wiv.8 for ; Wed, 12 Nov 2014 03:38:40 -0800 (PST) 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 Cc: Daniel Thompson , dri-devel@lists.freedesktop.org, Rob Clark , Benjamin Gaignard , linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org, John Stultz , Sumit Semwal 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> 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.47 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 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;