mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V1] dma-buf: Reject attaching a zero-sized dma-buf
@ 2026-11-23 17:11 Lizhi Hou
  0 siblings, 0 replies; only message in thread
From: Lizhi Hou @ 2026-11-23 17:11 UTC (permalink / raw)
  To: christian.koenig, sumit.semwal, phasta, linaro-mm-sig, linux-media
  Cc: Lizhi Hou, dri-devel, linux-kernel, max.zhen, sonal.santan

Attaching to a zero-sized dma-buf does not make sense at all: there is
nothing for an importer to map.

So reject the attach, using WARN_ON() because a zero-sized dma-buf is
an exporter bug that userspace cannot trigger on its own.

Adding the check to dma_buf_export() instead was considered, which
would prevent zero-sized DMA-bufs from being created in the first
place.  It is not done here because drivers may be using zero-sized
DMA-bufs for driver internal buffers, and refusing them at creation
time risks regressing those users.

Fixes: d15bd7ee445d ("dma-buf: Introduce dma buffer sharing mechanism")
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
 drivers/dma-buf/dma-buf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 5c6957f8839a..8be7b6023e4a 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -1050,6 +1050,9 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 	if (WARN_ON(!dmabuf || !dev))
 		return ERR_PTR(-EINVAL);
 
+	if (WARN_ON(!dmabuf->size))
+		return ERR_PTR(-EINVAL);
+
 	attach = kzalloc_obj(*attach);
 	if (!attach)
 		return ERR_PTR(-ENOMEM);
-- 
2.34.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-23 17:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 17:11 [PATCH V1] dma-buf: Reject attaching a zero-sized dma-buf Lizhi Hou

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

all inboxes | Powered by JetHome®