lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-id: <1344504982-30415-2-git-send-email-t.stanislaws@samsung.com>
Date:	Thu, 09 Aug 2012 11:36:21 +0200
From:	Tomasz Stanislawski <t.stanislaws@...sung.com>
To:	linux-media@...r.kernel.org, dri-devel@...ts.freedesktop.org
Cc:	airlied@...hat.com, m.szyprowski@...sung.com,
	t.stanislaws@...sung.com, kyungmin.park@...sung.com,
	laurent.pinchart@...asonboard.com, sumit.semwal@...aro.org,
	inki.dae@...sung.com, daniel.vetter@...ll.ch, rob@...com,
	pawel@...iak.com, linaro-mm-sig@...ts.linaro.org,
	linux-kernel@...r.kernel.org, gregkh@...uxfoundation.org,
	jy0922.shim@...sung.com, sw0312.kim@...sung.com,
	dan.j.williams@...el.com, linux-doc@...r.kernel.org
Subject: [PATCH v2 1/2] dma-buf: add reference counting for exporter module

This patch adds reference counting on a module that exported dma-buf and
implements its operations. This prevents the module from being unloaded while
DMABUF file is in use.

Signed-off-by: Tomasz Stanislawski <t.stanislaws@...sung.com>
Acked-by: Sumit Semwal <sumit.semwal@...aro.org>
Acked-by: Daniel Vetter <daniel.vetter@...ll.ch>
CC: linux-doc@...r.kernel.org
---
 Documentation/dma-buf-sharing.txt |    3 ++-
 drivers/base/dma-buf.c            |    9 ++++++++-
 include/linux/dma-buf.h           |    2 ++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/Documentation/dma-buf-sharing.txt b/Documentation/dma-buf-sharing.txt
index ad86fb8..2613057 100644
--- a/Documentation/dma-buf-sharing.txt
+++ b/Documentation/dma-buf-sharing.txt
@@ -49,7 +49,8 @@ The dma_buf buffer sharing API usage contains the following steps:
    The buffer exporter announces its wish to export a buffer. In this, it
    connects its own private buffer data, provides implementation for operations
    that can be performed on the exported dma_buf, and flags for the file
-   associated with this buffer.
+   associated with this buffer. The operations structure has owner field.
+   You should initialize this to THIS_MODULE in most cases.
 
    Interface:
       struct dma_buf *dma_buf_export(void *priv, struct dma_buf_ops *ops,
diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c
index c30f3e1..a1d9cab 100644
--- a/drivers/base/dma-buf.c
+++ b/drivers/base/dma-buf.c
@@ -27,6 +27,7 @@
 #include <linux/dma-buf.h>
 #include <linux/anon_inodes.h>
 #include <linux/export.h>
+#include <linux/module.h>
 
 static inline int is_dma_buf_file(struct file *);
 
@@ -40,6 +41,7 @@ static int dma_buf_release(struct inode *inode, struct file *file)
 	dmabuf = file->private_data;
 
 	dmabuf->ops->release(dmabuf);
+	module_put(dmabuf->ops->owner);
 	kfree(dmabuf);
 	return 0;
 }
@@ -105,9 +107,14 @@ struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops,
 		return ERR_PTR(-EINVAL);
 	}
 
+	if (!try_module_get(ops->owner))
+		return ERR_PTR(-ENOENT);
+
 	dmabuf = kzalloc(sizeof(struct dma_buf), GFP_KERNEL);
-	if (dmabuf == NULL)
+	if (dmabuf == NULL) {
+		module_put(ops->owner);
 		return ERR_PTR(-ENOMEM);
+	}
 
 	dmabuf->priv = priv;
 	dmabuf->ops = ops;
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index eb48f38..22953de 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -37,6 +37,7 @@ struct dma_buf_attachment;
 
 /**
  * struct dma_buf_ops - operations possible on struct dma_buf
+ * @owner: the module that implements dma_buf operations
  * @attach: [optional] allows different devices to 'attach' themselves to the
  *	    given buffer. It might return -EBUSY to signal that backing storage
  *	    is already allocated and incompatible with the requirements
@@ -70,6 +71,7 @@ struct dma_buf_attachment;
  * @vunmap: [optional] unmaps a vmap from the buffer
  */
 struct dma_buf_ops {
+	struct module *owner;
 	int (*attach)(struct dma_buf *, struct device *,
 			struct dma_buf_attachment *);
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ