From: Jiale Yao <yaojiale02@163.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
Michal Simek <michal.simek@amd.com>,
Hyun Kwon <hyun.kwon@xilinx.com>,
dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: Jiale Yao <yaojiale02@163.com>
Subject: [PATCH v2] dmaengine: xilinx: dpdma: Reserve space for a string terminator
Date: Sat, 3 Oct 2026 17:59:22 +0800 [thread overview]
Message-ID: <20261003095922.575350-1-yaojiale02@163.com> (raw)
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
next reply other threads:[~2026-10-03 9:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-03 9:59 Jiale Yao [this message]
2026-10-04 1:03 ` [PATCH v2] dmaengine: xilinx: dpdma: Reserve space for a string terminator Frank Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261003095922.575350-1-yaojiale02@163.com \
--to=yaojiale02@163.com \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=hyun.kwon@xilinx.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.simek@amd.com \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox