public inbox for linuxppc-dev@ozlabs.org
 help / color / mirror / Atom feed
* [PATCH] powerpc/powernv: allocate sensor group names to fit the OF node name
@ 2026-04-17  7:45 Pengpeng Hou
  0 siblings, 0 replies; only message in thread
From: Pengpeng Hou @ 2026-04-17  7:45 UTC (permalink / raw)
  To: Madhavan Srinivasan, Michael Ellerman
  Cc: Nicholas Piggin, Christophe Leroy (CS GROUP), Kees Cook,
	linuxppc-dev, linux-kernel, Pengpeng Hou, stable

opal_sensor_groups_init() stores each sensor-group name in a fixed
char[20] field and formats it with "%pOFn" or "%pOFn%d".

The node name comes from firmware and is not bounded to fit in 20 bytes,
so formatting the fully qualified group name can write past the end of
the embedded buffer.

Allocate the group name string to fit the formatted result instead of
storing it in a fixed-size array.

Fixes: bf9571550f52 ("powerpc/powernv: Add support to clear sensor groups data")
Cc: stable@vger.kernel.org

Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
 arch/powerpc/platforms/powernv/opal-sensor-groups.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/opal-sensor-groups.c b/arch/powerpc/platforms/powernv/opal-sensor-groups.c
index 87fd6d7769e9..f940c223f1b5 100644
--- a/arch/powerpc/platforms/powernv/opal-sensor-groups.c
+++ b/arch/powerpc/platforms/powernv/opal-sensor-groups.c
@@ -23,7 +23,7 @@ struct sg_attr {
 };
 
 static struct sensor_group {
-	char name[20];
+	char *name;
 	struct attribute_group sg;
 	struct sg_attr *sgattrs;
 } *sgs;
@@ -207,9 +207,12 @@ void __init opal_sensor_groups_init(void)
 		}
 
 		if (!of_property_read_u32(node, "ibm,chip-id", &chipid))
-			sprintf(sgs[i].name, "%pOFn%d", node, chipid);
+			sgs[i].name = kasprintf(GFP_KERNEL, "%pOFn%d",
+						node, chipid);
 		else
-			sprintf(sgs[i].name, "%pOFn", node);
+			sgs[i].name = kasprintf(GFP_KERNEL, "%pOFn", node);
+		if (!sgs[i].name)
+			goto out_sgs_sgattrs;
 
 		sgs[i].sg.name = sgs[i].name;
 		if (add_attr_group(ops, len, &sgs[i], sgid)) {
@@ -225,6 +228,7 @@ void __init opal_sensor_groups_init(void)
 
 out_sgs_sgattrs:
 	while (--i >= 0) {
+		kfree(sgs[i].name);
 		kfree(sgs[i].sgattrs);
 		kfree(sgs[i].sg.attrs);
 	}
-- 
2.50.1 (Apple Git-155)



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-04-17  7:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-17  7:45 [PATCH] powerpc/powernv: allocate sensor group names to fit the OF node name Pengpeng Hou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox