All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx+linux-hardening@kernel.org>
To: Anggara Putra <anggaraputra87.ap@gmail.com>
Cc: linux-pm@vger.kernel.org, rafael@kernel.org,
	viresh.kumar@linaro.org,  linux-hardening@vger.kernel.org
Subject: Re: [PATCH] cpufreq: Allow a terminator after a full-length driver name
Date: Fri, 4 Dec 2026 13:19:53 +0100	[thread overview]
Message-ID: <axKvq9eRSB865SmT@devuan> (raw)
In-Reply-To: <CALo22m0A=hEDO3uopK3-gn9LOpJweOPVvPLOFqv=h0G5PkMQPw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2587 bytes --]

Hi Anggara,

> Date: 2026-12-04 10:38:08+0700
> From: Anggara Putra <anggaraputra87.ap@gmail.com>
>
> "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);

How does this know the buffer size?  Won't this overflow the buffer
given a too-long string?


Have a lovely day!
Alex

>  }
> 
>  /*
> 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;
> 

-- 
<https://www.alejandro-colomar.es>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2026-12-04 12:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=axKvq9eRSB865SmT@devuan \
    --to=alx+linux-hardening@kernel.org \
    --cc=anggaraputra87.ap@gmail.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=viresh.kumar@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.