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]
Date: Wed, 15 May 2024 19:23:04 +0800
From: Yong Wu <yong.wu@...iatek.com>
To: Rob Herring <robh+dt@...nel.org>, Matthias Brugger
	<matthias.bgg@...il.com>, <christian.koenig@....com>, Sumit Semwal
	<sumit.semwal@...aro.org>, Andrew Morton <akpm@...ux-foundation.org>
CC: Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>, Conor Dooley
	<conor+dt@...nel.org>, Benjamin Gaignard <benjamin.gaignard@...labora.com>,
	Brian Starkey <Brian.Starkey@....com>, John Stultz <jstultz@...gle.com>,
	<tjmercier@...gle.com>, AngeloGioacchino Del Regno
	<angelogioacchino.delregno@...labora.com>, Yong Wu <yong.wu@...iatek.com>,
	<devicetree@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
	<linux-media@...r.kernel.org>, <dri-devel@...ts.freedesktop.org>,
	<linaro-mm-sig@...ts.linaro.org>, <linux-arm-kernel@...ts.infradead.org>,
	<linux-mediatek@...ts.infradead.org>, Robin Murphy <robin.murphy@....com>,
	Vijayanand Jitta <quic_vjitta@...cinc.com>, Joakim Bech
	<joakim.bech@...aro.org>, Jeffrey Kardatzke <jkardatzke@...gle.com>, "Pavel
 Machek" <pavel@....cz>, Simon Ser <contact@...rsion.fr>, Pekka Paalanen
	<ppaalanen@...il.com>, <willy@...radead.org>, Logan Gunthorpe
	<logang@...tatee.com>, Daniel Vetter <daniel@...ll.ch>,
	<jianjiao.zeng@...iatek.com>, <kuohong.wang@...iatek.com>,
	<youlin.pei@...iatek.com>
Subject: [PATCH v5 5/9] dma-buf: heaps: restricted_heap: Add private heap ops

Add "struct restricted_heap_ops". For the restricted memory, totally there
are two steps:
a) alloc: Allocate the buffer in kernel;
b) restrict_buf: Restrict/Protect/Secure that buffer.
The "alloc" is mandatory while "restrict_buf" is optional since it may
be part of "alloc".

Signed-off-by: Yong Wu <yong.wu@...iatek.com>
---
 drivers/dma-buf/heaps/restricted_heap.c | 41 ++++++++++++++++++++++++-
 drivers/dma-buf/heaps/restricted_heap.h | 12 ++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/drivers/dma-buf/heaps/restricted_heap.c b/drivers/dma-buf/heaps/restricted_heap.c
index c2ae19ba7d7e..8bb3c1876a69 100644
--- a/drivers/dma-buf/heaps/restricted_heap.c
+++ b/drivers/dma-buf/heaps/restricted_heap.c
@@ -12,10 +12,44 @@
 
 #include "restricted_heap.h"
 
+static int
+restricted_heap_memory_allocate(struct restricted_heap *rheap, struct restricted_buffer *buf)
+{
+	const struct restricted_heap_ops *ops = rheap->ops;
+	int ret;
+
+	ret = ops->alloc(rheap, buf);
+	if (ret)
+		return ret;
+
+	if (ops->restrict_buf) {
+		ret = ops->restrict_buf(rheap, buf);
+		if (ret)
+			goto buf_free;
+	}
+	return 0;
+
+buf_free:
+	ops->free(rheap, buf);
+	return ret;
+}
+
+static void
+restricted_heap_memory_free(struct restricted_heap *rheap, struct restricted_buffer *buf)
+{
+	const struct restricted_heap_ops *ops = rheap->ops;
+
+	if (ops->unrestrict_buf)
+		ops->unrestrict_buf(rheap, buf);
+
+	ops->free(rheap, buf);
+}
+
 static struct dma_buf *
 restricted_heap_allocate(struct dma_heap *heap, unsigned long size,
 			 unsigned long fd_flags, unsigned long heap_flags)
 {
+	struct restricted_heap *rheap = dma_heap_get_drvdata(heap);
 	struct restricted_buffer *restricted_buf;
 	DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
 	struct dma_buf *dmabuf;
@@ -28,6 +62,9 @@ restricted_heap_allocate(struct dma_heap *heap, unsigned long size,
 	restricted_buf->size = ALIGN(size, PAGE_SIZE);
 	restricted_buf->heap = heap;
 
+	ret = restricted_heap_memory_allocate(rheap, restricted_buf);
+	if (ret)
+		goto err_free_buf;
 	exp_info.exp_name = dma_heap_get_name(heap);
 	exp_info.size = restricted_buf->size;
 	exp_info.flags = fd_flags;
@@ -36,11 +73,13 @@ restricted_heap_allocate(struct dma_heap *heap, unsigned long size,
 	dmabuf = dma_buf_export(&exp_info);
 	if (IS_ERR(dmabuf)) {
 		ret = PTR_ERR(dmabuf);
-		goto err_free_buf;
+		goto err_free_rstrd_mem;
 	}
 
 	return dmabuf;
 
+err_free_rstrd_mem:
+	restricted_heap_memory_free(rheap, restricted_buf);
 err_free_buf:
 	kfree(restricted_buf);
 	return ERR_PTR(ret);
diff --git a/drivers/dma-buf/heaps/restricted_heap.h b/drivers/dma-buf/heaps/restricted_heap.h
index b448f77616ac..5783275d5714 100644
--- a/drivers/dma-buf/heaps/restricted_heap.h
+++ b/drivers/dma-buf/heaps/restricted_heap.h
@@ -15,6 +15,18 @@ struct restricted_buffer {
 
 struct restricted_heap {
 	const char		*name;
+
+	const struct restricted_heap_ops *ops;
+};
+
+struct restricted_heap_ops {
+	int	(*heap_init)(struct restricted_heap *rheap);
+
+	int	(*alloc)(struct restricted_heap *rheap, struct restricted_buffer *buf);
+	void	(*free)(struct restricted_heap *rheap, struct restricted_buffer *buf);
+
+	int	(*restrict_buf)(struct restricted_heap *rheap, struct restricted_buffer *buf);
+	void	(*unrestrict_buf)(struct restricted_heap *rheap, struct restricted_buffer *buf);
 };
 
 int restricted_heap_add(struct restricted_heap *rheap);
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ