Thread (5 messages) flat view 5 messages, 1 author, 3d ago
DORMANTno replies

[PATCH v1 4/4] powerpc/iommu: fix debugfs name buffer for 64-bit it_index

From: Xixin Liu <hidden>
Date: 2026-08-07 03:31:44
Also in: lkml
Subsystem: linux for powerpc (32-bit and 64-bit), the rest · Maintainers: Madhavan Srinivasan, Linus Torvalds

iommu debugfs names sprintf() "%08lx" into char name[10]. The "8" in
%08lx is a minimum width, so a 64-bit it_index can need up to 16 hex
digits plus NUL.

Size the buffer for an unsigned long and use snprintf.

Signed-off-by: Xixin Liu <redacted>
---
 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index ee1b5cb557c9..e8f48aef7832 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -53,10 +53,11 @@
 
 static void iommu_debugfs_add(struct iommu_table *tbl)
 {
-	char name[10];
+	/* unsigned long hex + NUL; %08lx is a minimum width only */
+	char name[2 * sizeof(unsigned long) + 1];
 	struct dentry *liobn_entry;
 
-	sprintf(name, "%08lx", tbl->it_index);
+	snprintf(name, sizeof(name), "%08lx", tbl->it_index);
 	liobn_entry = debugfs_create_dir(name, iommu_debugfs_dir);
 
 	debugfs_create_file_unsafe("weight", 0400, liobn_entry, tbl, &iommu_debugfs_fops_weight);
@@ -70,9 +71,9 @@
 
 static void iommu_debugfs_del(struct iommu_table *tbl)
 {
-	char name[10];
+	char name[2 * sizeof(unsigned long) + 1];
 
-	sprintf(name, "%08lx", tbl->it_index);
+	snprintf(name, sizeof(name), "%08lx", tbl->it_index);
 	debugfs_lookup_and_remove(name, iommu_debugfs_dir);
 }
 #else
-- 
2.43.0

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help