[PATCH 6/6] firmware: xilinx: Bound debugfs clock name formatting

Michal Simek michal.simek at amd.com
Thu Nov 19 05:17:30 PST 2026


From: Jay Buddhabhatti <jay.buddhabhatti at amd.com>

PM_QID_CLOCK_GET_NAME returns up to 16 name bytes with no guaranteed NUL
terminator. Copy the response into a bounded local buffer before formatting
to prevent kernel stack data from leaking via debugfs.

Fixes: e60f02ddb4d2 ("firmware: xilinx: Add debugfs for query data API")
Signed-off-by: Jay Buddhabhatti <jay.buddhabhatti at amd.com>
Signed-off-by: Michal Simek <michal.simek at amd.com>
---

 drivers/firmware/xilinx/zynqmp-debug.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/xilinx/zynqmp-debug.c b/drivers/firmware/xilinx/zynqmp-debug.c
index f7751912d80a..77b35a525b96 100644
--- a/drivers/firmware/xilinx/zynqmp-debug.c
+++ b/drivers/firmware/xilinx/zynqmp-debug.c
@@ -21,6 +21,7 @@
 #include "zynqmp-debug.h"
 
 #define PM_API_NAME_LEN			50
+#define CLK_GET_NAME_RESP_LEN		16
 
 struct pm_api_info {
 	u32 api_id;
@@ -279,10 +280,14 @@ static int process_api_request(u32 pm_id, u64 *pm_api_arg, u32 *pm_api_ret)
 			break;
 
 		switch (qdata.qid) {
-		case PM_QID_CLOCK_GET_NAME:
-			sprintf(debugfs_buf, "Clock name = %s\n",
-				(char *)pm_api_ret);
+		case PM_QID_CLOCK_GET_NAME: {
+			char name[CLK_GET_NAME_RESP_LEN + 1];
+
+			memcpy(name, pm_api_ret, CLK_GET_NAME_RESP_LEN);
+			name[CLK_GET_NAME_RESP_LEN] = '\0';
+			sprintf(debugfs_buf, "Clock name = %s\n", name);
 			break;
+		}
 		case PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS:
 			sprintf(debugfs_buf, "Multiplier = %d, Divider = %d\n",
 				pm_api_ret[1], pm_api_ret[2]);
-- 
2.43.0




More information about the linux-arm-kernel mailing list