[PATCH] EDAC/xilinx: Fix stack off-by-one in debugfs UE injection handlers
Shengzhuo Wei
me at cherr.cc
Fri Apr 24 11:49:05 PDT 2026
Two EDAC debugfs write handlers copy up to sizeof(buf) bytes into a
fixed-size stack buffer and then unconditionally NUL-terminate it via
buf[len] = '\0'. When userspace writes >= sizeof(buf) bytes, len
becomes sizeof(buf) and the NUL write lands 1 byte past the end of the
stack buffer.
Fix by clamping the copy length to sizeof(buf) - 1 so that the NUL
terminator is always in-bounds.
Fixes: 3bd2706c910f ("EDAC/zynqmp: Add EDAC support for Xilinx ZynqMP OCM")
Fixes: 83bf24051a60 ("EDAC/versal: Make the bit position of injected errors configurable")
Signed-off-by: Shengzhuo Wei <me at cherr.cc>
---
drivers/edac/versal_edac.c | 2 +-
drivers/edac/zynqmp_edac.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/edac/versal_edac.c b/drivers/edac/versal_edac.c
index 5a43b5d43ca28027c829f53aea50588297484c5c..917d7d1762aa9ec9f752e8419c24fd265048ff28 100644
--- a/drivers/edac/versal_edac.c
+++ b/drivers/edac/versal_edac.c
@@ -856,7 +856,7 @@ static ssize_t inject_data_ue_store(struct file *file, const char __user *data,
u8 len, ue0, ue1;
int i, ret;
- len = min_t(size_t, count, sizeof(buf));
+ len = min_t(size_t, count, sizeof(buf) - 1);
if (copy_from_user(buf, data, len))
return -EFAULT;
diff --git a/drivers/edac/zynqmp_edac.c b/drivers/edac/zynqmp_edac.c
index cdffc9e4194d42d4d11c5218c9f341ac46301a94..048a7b9becd622a5eeebf9c893ffdf9e163f5e9b 100644
--- a/drivers/edac/zynqmp_edac.c
+++ b/drivers/edac/zynqmp_edac.c
@@ -304,7 +304,7 @@ static ssize_t inject_ue_write(struct file *file, const char __user *data,
if (!data)
return -EFAULT;
- len = min_t(size_t, count, sizeof(buf));
+ len = min_t(size_t, count, sizeof(buf) - 1);
if (copy_from_user(buf, data, len))
return -EFAULT;
---
base-commit: dd6c438c3e64a5ff0b5d7e78f7f9be547803ef1b
change-id: 20260425-edac-stack-off-by-one-f6703cfe8213
Best regards,
--
Shengzhuo Wei <me at cherr.cc>
More information about the linux-arm-kernel
mailing list