* [PATCH 0/3] debugfs: Reserve space for string terminators
@ 2026-09-26 12:12 Jiale Yao
2026-09-26 12:12 ` [PATCH 1/3] platform/olpc: Reserve space for a string terminator Jiale Yao
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Jiale Yao @ 2026-09-26 12:12 UTC (permalink / raw)
To: Laurent Pinchart, Vinod Koul, Frank Li, Michal Simek,
Jeff Johnson, Hans de Goede, Ilpo Järvinen, Andres Salomon,
Thomas Gleixner, Paul Fox, Dan Carpenter,
Vasanthakumar Thiagarajan, Hyun Kwon, dmaengine,
linux-arm-kernel, linux-kernel, linux-wireless, ath12k,
platform-driver-x86
Cc: Jiale Yao
The same boundary mistake appears in three debugfs write handlers. Each
handler has a zero-initialized buffer and allows a user write to fill the
entire buffer. That overwrites the only NUL terminator before the input
is parsed with sscanf(), strsep(), or strcasecmp(), which can then read
beyond the end of the buffer.
The write paths are independent, so the fixes are split by file and can
be applied separately. Each patch reserves one byte for the terminating
NUL while preserving the normal input size for that handler.
Jiale Yao (3):
platform/olpc: Reserve space for a string terminator
wifi: ath12k: Reserve space for a string terminator
dmaengine: xilinx: dpdma: Reserve space for a string terminator
drivers/dma/xilinx/xilinx_dpdma.c | 2 +-
drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c | 2 +-
drivers/platform/olpc/olpc-ec.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] platform/olpc: Reserve space for a string terminator
2026-09-26 12:12 [PATCH 0/3] debugfs: Reserve space for string terminators Jiale Yao
@ 2026-09-26 12:12 ` Jiale Yao
2026-09-26 12:12 ` [PATCH 2/3] wifi: ath12k: " Jiale Yao
2026-09-26 12:12 ` [PATCH 3/3] dmaengine: xilinx: dpdma: " Jiale Yao
2 siblings, 0 replies; 6+ messages in thread
From: Jiale Yao @ 2026-09-26 12:12 UTC (permalink / raw)
To: Hans de Goede, Ilpo Järvinen, Andres Salomon,
Thomas Gleixner, Paul Fox, platform-driver-x86, linux-kernel
Cc: Jiale Yao
ec_dbgfs_cmd_write() copies user input into a zero-initialized stack
buffer and passes it to sscanf(). A write that fills the entire buffer
overwrites its only terminator, so the subsequent parsing can read beyond
the buffer.
Limit the copy to leave room for the trailing NUL.
Fixes: 6cca83d498bd ("Platform: OLPC: move debugfs support from x86 EC driver")
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
drivers/platform/olpc/olpc-ec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c
index 4a2d36f7331e..063f7e55c421 100644
--- a/drivers/platform/olpc/olpc-ec.c
+++ b/drivers/platform/olpc/olpc-ec.c
@@ -269,7 +269,7 @@ static ssize_t ec_dbgfs_cmd_write(struct file *file, const char __user *buf,
mutex_lock(&ec_dbgfs_lock);
- size = simple_write_to_buffer(cmdbuf, sizeof(cmdbuf), ppos, buf, size);
+ size = simple_write_to_buffer(cmdbuf, sizeof(cmdbuf) - 1, ppos, buf, size);
m = sscanf(cmdbuf, "%x:%u %x %x %x %x %x", &ec_cmd_int[0],
&ec_dbgfs_resp_bytes, &ec_cmd_int[1], &ec_cmd_int[2],
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/3] wifi: ath12k: Reserve space for a string terminator
2026-09-26 12:12 [PATCH 0/3] debugfs: Reserve space for string terminators Jiale Yao
2026-09-26 12:12 ` [PATCH 1/3] platform/olpc: Reserve space for a string terminator Jiale Yao
@ 2026-09-26 12:12 ` Jiale Yao
2026-09-26 12:33 ` Dan Carpenter
2026-09-26 12:12 ` [PATCH 3/3] dmaengine: xilinx: dpdma: " Jiale Yao
2 siblings, 1 reply; 6+ messages in thread
From: Jiale Yao @ 2026-09-26 12:12 UTC (permalink / raw)
To: Jeff Johnson, Vasanthakumar Thiagarajan, Dan Carpenter,
linux-wireless, ath12k, linux-kernel
Cc: Jiale Yao
ath12k_write_htt_stats_type() accepts count == size, which fills the
zero-initialized buffer without a terminating NUL. sscanf() then reads
beyond the buffer.
Reject input that leaves no room for the trailing NUL.
Fixes: 8c7a5031a6b0 ("wifi: ath12k: Fix buffer overflow in debugfs")
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c b/drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c
index b772181a496e..f84f1828275a 100644
--- a/drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c
+++ b/drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c
@@ -6190,7 +6190,7 @@ static ssize_t ath12k_write_htt_stats_type(struct file *file,
const int size = 32;
int num_args;
- if (count > size)
+ if (count >= size)
return -EINVAL;
char *buf __free(kfree) = kzalloc(size, GFP_KERNEL);
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] dmaengine: xilinx: dpdma: Reserve space for a string terminator
2026-09-26 12:12 [PATCH 0/3] debugfs: Reserve space for string terminators Jiale Yao
2026-09-26 12:12 ` [PATCH 1/3] platform/olpc: Reserve space for a string terminator Jiale Yao
2026-09-26 12:12 ` [PATCH 2/3] wifi: ath12k: " Jiale Yao
@ 2026-09-26 12:12 ` Jiale Yao
2026-09-26 14:34 ` Laurent Pinchart
2 siblings, 1 reply; 6+ messages in thread
From: Jiale Yao @ 2026-09-26 12:12 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() allocates a buffer of size bytes, and
strncpy_from_user() can fill it without a terminating NUL when the input
has no NUL in the copied range. strsep() and strcasecmp() then read
beyond the buffer.
Allocate an extra byte and keep that byte zero-initialized, so the input
copied remains unchanged and the buffer is always terminated.
Fixes: 1d220435cab3 ("dmaengine: xilinx: dpdma: Add debugfs support")
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
drivers/dma/xilinx/xilinx_dpdma.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/dma/xilinx/xilinx_dpdma.c b/drivers/dma/xilinx/xilinx_dpdma.c
index d9a3542c4531..b61ef3062d84 100644
--- a/drivers/dma/xilinx/xilinx_dpdma.c
+++ b/drivers/dma/xilinx/xilinx_dpdma.c
@@ -410,7 +410,7 @@ 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);
+ kern_buff = kzalloc(size + 1, GFP_KERNEL);
if (!kern_buff)
return -ENOMEM;
kern_buff_start = kern_buff;
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] wifi: ath12k: Reserve space for a string terminator
2026-09-26 12:12 ` [PATCH 2/3] wifi: ath12k: " Jiale Yao
@ 2026-09-26 12:33 ` Dan Carpenter
0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2026-09-26 12:33 UTC (permalink / raw)
To: Jiale Yao
Cc: Jeff Johnson, Vasanthakumar Thiagarajan, linux-wireless, ath12k,
linux-kernel
On Sat, Sep 26, 2026 at 08:12:49PM +0800, Jiale Yao wrote:
> ath12k_write_htt_stats_type() accepts count == size, which fills the
> zero-initialized buffer without a terminating NUL. sscanf() then reads
> beyond the buffer.
>
> Reject input that leaves no room for the trailing NUL.
>
> Fixes: 8c7a5031a6b0 ("wifi: ath12k: Fix buffer overflow in debugfs")
> Signed-off-by: Jiale Yao <yaojiale02@163.com>
> ---
Reviewed-by: Dan Carpenter <error27@gmail.com>
regards,
dan carpenter
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] dmaengine: xilinx: dpdma: Reserve space for a string terminator
2026-09-26 12:12 ` [PATCH 3/3] dmaengine: xilinx: dpdma: " Jiale Yao
@ 2026-09-26 14:34 ` Laurent Pinchart
0 siblings, 0 replies; 6+ messages in thread
From: Laurent Pinchart @ 2026-09-26 14:34 UTC (permalink / raw)
To: Jiale Yao
Cc: Vinod Koul, Frank Li, Michal Simek, Hyun Kwon, dmaengine,
linux-arm-kernel, linux-kernel
On Sat, Sep 26, 2026 at 08:12:50PM +0800, Jiale Yao wrote:
> xilinx_dpdma_debugfs_write() allocates a buffer of size bytes, and
> strncpy_from_user() can fill it without a terminating NUL when the input
> has no NUL in the copied range. strsep() and strcasecmp() then read
> beyond the buffer.
strncpy() has long been considered unsafe, and has finally been removed
from the kernel in v7.2. A better fix would be to similarly replace
strncpy_from_user() with a safe equivalent.
> Allocate an extra byte and keep that byte zero-initialized, so the input
> copied remains unchanged and the buffer is always terminated.
>
> Fixes: 1d220435cab3 ("dmaengine: xilinx: dpdma: Add debugfs support")
> Signed-off-by: Jiale Yao <yaojiale02@163.com>
> ---
> drivers/dma/xilinx/xilinx_dpdma.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/dma/xilinx/xilinx_dpdma.c b/drivers/dma/xilinx/xilinx_dpdma.c
> index d9a3542c4531..b61ef3062d84 100644
> --- a/drivers/dma/xilinx/xilinx_dpdma.c
> +++ b/drivers/dma/xilinx/xilinx_dpdma.c
> @@ -410,7 +410,7 @@ 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);
> + kern_buff = kzalloc(size + 1, GFP_KERNEL);
> if (!kern_buff)
> return -ENOMEM;
> kern_buff_start = kern_buff;
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-09-26 14:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-26 12:12 [PATCH 0/3] debugfs: Reserve space for string terminators Jiale Yao
2026-09-26 12:12 ` [PATCH 1/3] platform/olpc: Reserve space for a string terminator Jiale Yao
2026-09-26 12:12 ` [PATCH 2/3] wifi: ath12k: " Jiale Yao
2026-09-26 12:33 ` Dan Carpenter
2026-09-26 12:12 ` [PATCH 3/3] dmaengine: xilinx: dpdma: " Jiale Yao
2026-09-26 14:34 ` Laurent Pinchart
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®