Linux Hardening
 help / color / mirror / Atom feed
* [PATCH] cpufreq: Allow a terminator after a full-length driver name
@ 2026-12-04  3:38 Anggara Putra
  2026-12-04 12:19 ` Alejandro Colomar
  0 siblings, 1 reply; 2+ messages in thread
From: Anggara Putra @ 2026-12-04  3:38 UTC (permalink / raw)
  To: linux-pm; +Cc: rafael, viresh.kumar, linux-hardening

"kirkwood-cpufreq" fills all 16 bytes of the driver name. The
scaling_driver attribute formats it with %s, and its 17-byte
output limit leaves room for only 16 characters and the NUL.

Reserve a byte for the driver's name terminator and use sysfs_emit()
to fit the complete name and newline. Governor names keep their
existing size.

OpenAI Codex assisted with the patch, commit message, and local tests
using the public KSPP compiler diagnostics.

Fixes: 2a4bd9f0db24 ("cpufreq: kirkwood: Add a cpufreq driver for
Marvell Kirkwood SoCs")
Link: https://github.com/KSPP/linux/issues/374
Signed-off-by: Anggara Putra <anggaraputra87.ap@gmail.com>
---
The Kirkwood driver and CPUfreq core built for ARM. In the rebuilt
driver object, the 17-byte name field contains "kirkwood-cpufreq"
followed by its terminating NUL.
The scaling_driver attribute was not read on Kirkwood hardware.

 drivers/cpufreq/cpufreq.c | 2 +-
 include/linux/cpufreq.h   | 4 +---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 4332cb1..a6885e1 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -841,7 +841,7 @@
  */
 static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf)
 {
-       return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name);
+       return sysfs_emit(buf, "%s\n", cpufreq_driver->name);
 }

 /*
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index be1eaa4..0f6c0f5 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -31,8 +31,6 @@
 #define CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS  NSEC_PER_MSEC

 #define CPUFREQ_NAME_LEN               16
-/* Print length for names. Extra 1 space for accommodating '\n' in prints */
-#define CPUFREQ_NAME_PLEN              (CPUFREQ_NAME_LEN + 1)

 struct cpufreq_governor;

@@ -353,7 +351,7 @@ __ATTR(_name, 0644, show_##_name, store_##_name)


 struct cpufreq_driver {
-       char            name[CPUFREQ_NAME_LEN];
+       char            name[CPUFREQ_NAME_LEN + 1];
        u16             flags;
        void            *driver_data;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04 12:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  3:38 [PATCH] cpufreq: Allow a terminator after a full-length driver name Anggara Putra
2026-12-04 12:19 ` Alejandro Colomar

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