From: Pengpeng Hou <pengpeng@iscas.ac.cn>
To: Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
Kees Cook <kees@kernel.org>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
Pengpeng Hou <pengpeng@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] powerpc/powernv: allocate sensor group names to fit the OF node name
Date: Fri, 17 Apr 2026 15:45:05 +0800 [thread overview]
Message-ID: <20260417074505.16178-1-pengpeng@iscas.ac.cn> (raw)
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)
reply other threads:[~2026-04-17 7:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260417074505.16178-1-pengpeng@iscas.ac.cn \
--to=pengpeng@iscas.ac.cn \
--cc=chleroy@kernel.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox