From: Viresh Kumar <viresh.kumar@linaro.org>
To: Takashi Iwai <tiwai@suse.de>
Cc: "Rafael J . Wysocki" <rjw@rjwysocki.net>, linux-pm@vger.kernel.org
Subject: Re: [PATCH] cpufreq: Use scnprintf() for avoiding potential buffer overflow
Date: Wed, 11 Mar 2020 12:44:44 +0530 [thread overview]
Message-ID: <20200311071444.ihuzc6n5x6pbmhbx@vireshk-i7> (raw)
In-Reply-To: <20200311071341.4339-1-tiwai@suse.de>
On 11-03-20, 08:13, Takashi Iwai wrote:
> Since snprintf() returns the would-be-output size instead of the
> actual output size, the succeeding calls may go beyond the given
> buffer limit. Fix it by replacing with scnprintf().
>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
> drivers/cpufreq/cpufreq_stats.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
> index f9bcf0f3ea30..94d959a8e954 100644
> --- a/drivers/cpufreq/cpufreq_stats.c
> +++ b/drivers/cpufreq/cpufreq_stats.c
> @@ -90,35 +90,35 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
> if (policy->fast_switch_enabled)
> return 0;
>
> - len += snprintf(buf + len, PAGE_SIZE - len, " From : To\n");
> - len += snprintf(buf + len, PAGE_SIZE - len, " : ");
> + len += scnprintf(buf + len, PAGE_SIZE - len, " From : To\n");
> + len += scnprintf(buf + len, PAGE_SIZE - len, " : ");
> for (i = 0; i < stats->state_num; i++) {
> if (len >= PAGE_SIZE)
> break;
> - len += snprintf(buf + len, PAGE_SIZE - len, "%9u ",
> + len += scnprintf(buf + len, PAGE_SIZE - len, "%9u ",
> stats->freq_table[i]);
> }
> if (len >= PAGE_SIZE)
> return PAGE_SIZE;
>
> - len += snprintf(buf + len, PAGE_SIZE - len, "\n");
> + len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
>
> for (i = 0; i < stats->state_num; i++) {
> if (len >= PAGE_SIZE)
> break;
>
> - len += snprintf(buf + len, PAGE_SIZE - len, "%9u: ",
> + len += scnprintf(buf + len, PAGE_SIZE - len, "%9u: ",
> stats->freq_table[i]);
>
> for (j = 0; j < stats->state_num; j++) {
> if (len >= PAGE_SIZE)
> break;
> - len += snprintf(buf + len, PAGE_SIZE - len, "%9u ",
> + len += scnprintf(buf + len, PAGE_SIZE - len, "%9u ",
> stats->trans_table[i*stats->max_state+j]);
> }
> if (len >= PAGE_SIZE)
> break;
> - len += snprintf(buf + len, PAGE_SIZE - len, "\n");
> + len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
> }
>
> if (len >= PAGE_SIZE) {
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
prev parent reply other threads:[~2020-03-11 7:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-11 7:13 [PATCH] cpufreq: Use scnprintf() for avoiding potential buffer overflow Takashi Iwai
2020-03-11 7:14 ` Viresh Kumar [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=20200311071444.ihuzc6n5x6pbmhbx@vireshk-i7 \
--to=viresh.kumar@linaro.org \
--cc=linux-pm@vger.kernel.org \
--cc=rjw@rjwysocki.net \
--cc=tiwai@suse.de \
/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;
as well as URLs for NNTP newsgroup(s).