DMA Engine development
 help / color / mirror / Atom feed
* [PATCH v2] dmaengine: xilinx: dpdma: Reserve space for a string terminator
@ 2026-10-03  9:59 Jiale Yao
  2026-10-04  1:03 ` Frank Li
  0 siblings, 1 reply; 2+ messages in thread
From: Jiale Yao @ 2026-10-03  9:59 UTC (permalink / raw)
  To: Laurent Pinchart, Vinod Koul, Frank Li, Michal Simek, Hyun Kwon,
	dmaengine, linux-arm-kernel, linux-kernel
  Cc: Jiale Yao

xilinx_dpdma_debugfs_write() copies size bytes from userspace and parses
them with strsep() and strcasecmp(). If the input has no NUL within that
range, the parser can read beyond the allocation.

Use memdup_user_nul() to copy the complete input and append a terminating
NUL.

Fixes: 1d220435cab3 ("dmaengine: xilinx: dpdma: Add debugfs support")
Signed-off-by: Jiale Yao <yaojiale02@163.com>

---

Changes in v2:
- Replace kzalloc() and strncpy_from_user() with memdup_user_nul(), as
  suggested by Laurent.

diff --git a/drivers/dma/xilinx/xilinx_dpdma.c b/drivers/dma/xilinx/xilinx_dpdma.c
index d9a3542c4531..219d25be6c3a 100644
--- a/drivers/dma/xilinx/xilinx_dpdma.c
+++ b/drivers/dma/xilinx/xilinx_dpdma.c
@@ -410,15 +410,11 @@ static ssize_t xilinx_dpdma_debugfs_write(struct file *f,
 	if (dpdma_debugfs.testcase != DPDMA_TC_NONE)
 		return -EBUSY;
 
-	kern_buff = kzalloc(size, GFP_KERNEL);
-	if (!kern_buff)
-		return -ENOMEM;
+	kern_buff = memdup_user_nul(buf, size);
+	if (IS_ERR(kern_buff))
+		return PTR_ERR(kern_buff);
 	kern_buff_start = kern_buff;
 
-	ret = strncpy_from_user(kern_buff, buf, size);
-	if (ret < 0)
-		goto done;
-
 	/* Read the testcase name from a user request. */
 	testcase = strsep(&kern_buff, " ");
 
-- 
2.34.1


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

end of thread, other threads:[~2026-10-04  1:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-03  9:59 [PATCH v2] dmaengine: xilinx: dpdma: Reserve space for a string terminator Jiale Yao
2026-10-04  1:03 ` Frank Li

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