public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] dma-buf: don't hold the mutex around map/unmap calls
@ 2012-03-18 23:34 Daniel Vetter
  2012-03-18 23:34 ` [PATCH 2/4] dma-buf: add support for kernel cpu access Daniel Vetter
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Daniel Vetter @ 2012-03-18 23:34 UTC (permalink / raw)
  To: linaro-mm-sig, LKML, DRI Development, linux-media; +Cc: Daniel Vetter

The mutex protects the attachment list and hence needs to be held
around the callbakc to the exporters (optional) attach/detach
functions.

Holding the mutex around the map/unmap calls doesn't protect any
dma_buf state. Exporters need to properly protect any of their own
state anyway (to protect against calls from their own interfaces).
So this only makes the locking messier (and lockdep easier to anger).

Therefore let's just drop this.

v2: Rebased on top of latest dma-buf-next git.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Rob Clark <rob.clark@linaro.org>
---
 drivers/base/dma-buf.c  |    5 -----
 include/linux/dma-buf.h |    2 +-
 2 files changed, 1 insertions(+), 6 deletions(-)

diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c
index 3c8c023..5641b9c 100644
--- a/drivers/base/dma-buf.c
+++ b/drivers/base/dma-buf.c
@@ -258,9 +258,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
 	if (WARN_ON(!attach || !attach->dmabuf))
 		return ERR_PTR(-EINVAL);
 
-	mutex_lock(&attach->dmabuf->lock);
 	sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction);
-	mutex_unlock(&attach->dmabuf->lock);
 
 	return sg_table;
 }
@@ -282,10 +280,7 @@ void dma_buf_unmap_attachment(struct dma_buf_attachment *attach,
 	if (WARN_ON(!attach || !attach->dmabuf || !sg_table))
 		return;
 
-	mutex_lock(&attach->dmabuf->lock);
 	attach->dmabuf->ops->unmap_dma_buf(attach, sg_table,
 						direction);
-	mutex_unlock(&attach->dmabuf->lock);
-
 }
 EXPORT_SYMBOL_GPL(dma_buf_unmap_attachment);
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index bc4203dc..24e0f48 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -88,7 +88,7 @@ struct dma_buf {
 	struct file *file;
 	struct list_head attachments;
 	const struct dma_buf_ops *ops;
-	/* mutex to serialize list manipulation and other ops */
+	/* mutex to serialize list manipulation and attach/detach */
 	struct mutex lock;
 	void *priv;
 };
-- 
1.7.7.5


^ permalink raw reply related	[flat|nested] 15+ messages in thread
* [PATCH] dma-buf: document fd flags and O_CLOEXEC requirement
@ 2012-03-19 21:42 Rob Clark
  2012-03-22  6:05 ` Sumit Semwal
  0 siblings, 1 reply; 15+ messages in thread
From: Rob Clark @ 2012-03-19 21:42 UTC (permalink / raw)
  To: linaro-mm-sig, linux-kernel, dri-devel, linux-media
  Cc: patches, daniel.vetter, sumit.semwal, Rob Clark

From: Rob Clark <rob@ti.com>

Otherwise subsystems will get this wrong and end up with a second
export ioctl with the flag and O_CLOEXEC support added.

Signed-off-by: Rob Clark <rob@ti.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
Updated version of Daniel's original documentation patch with (hopefully)
improved wording, and a better description of the motivation.

 Documentation/dma-buf-sharing.txt |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/Documentation/dma-buf-sharing.txt b/Documentation/dma-buf-sharing.txt
index 225f96d..3b51134 100644
--- a/Documentation/dma-buf-sharing.txt
+++ b/Documentation/dma-buf-sharing.txt
@@ -223,6 +223,24 @@ Miscellaneous notes:
 - Any exporters or users of the dma-buf buffer sharing framework must have
   a 'select DMA_SHARED_BUFFER' in their respective Kconfigs.
 
+- In order to avoid fd leaks on exec, the FD_CLOEXEC flag must be set
+  on the file descriptor.  This is not just a resource leak, but a
+  potential security hole.  It could give the newly exec'd application
+  access to buffers, via the leaked fd, to which it should otherwise
+  not be permitted access.
+
+  The problem with doing this via a separate fcntl() call, versus doing it
+  atomically when the fd is created, is that this is inherently racy in a
+  multi-threaded app[3].  The issue is made worse when it is library code
+  opening/creating the file descriptor, as the application may not even be
+  aware of the fd's.
+
+  To avoid this problem, userspace must have a way to request O_CLOEXEC
+  flag be set when the dma-buf fd is created.  So any API provided by
+  the exporting driver to create a dmabuf fd must provide a way to let
+  userspace control setting of O_CLOEXEC flag passed in to dma_buf_fd().
+
 References:
 [1] struct dma_buf_ops in include/linux/dma-buf.h
 [2] All interfaces mentioned above defined in include/linux/dma-buf.h
+[3] https://lwn.net/Articles/236486/
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2012-03-22  6:05 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-18 23:34 [PATCH 1/4] dma-buf: don't hold the mutex around map/unmap calls Daniel Vetter
2012-03-18 23:34 ` [PATCH 2/4] dma-buf: add support for kernel cpu access Daniel Vetter
2012-03-19  2:00   ` Rob Clark
2012-03-19 23:02     ` [PATCH] " Daniel Vetter
2012-03-22  6:03       ` [Linaro-mm-sig] " Sumit Semwal
2012-03-18 23:34 ` [PATCH 3/4] dma_buf: Add documentation for the new cpu access support Daniel Vetter
2012-03-19  1:54   ` Rob Clark
2012-03-22  6:04     ` [Linaro-mm-sig] " Sumit Semwal
2012-03-18 23:34 ` [PATCH 4/4] dma-buf: document fd flags and O_CLOEXEC requirement Daniel Vetter
2012-03-19 10:51   ` [Linaro-mm-sig] " Dave Airlie
2012-03-19 15:41     ` [PATCH] " Daniel Vetter
2012-03-19 15:44       ` Ville Syrjälä
2012-03-22  6:03 ` [Linaro-mm-sig] [PATCH 1/4] dma-buf: don't hold the mutex around map/unmap calls Sumit Semwal
  -- strict thread matches above, loose matches on Subject: below --
2012-03-19 21:42 [PATCH] dma-buf: document fd flags and O_CLOEXEC requirement Rob Clark
2012-03-22  6:05 ` Sumit Semwal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox