linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Takashi Iwai <tiwai@suse.de>
Cc: linux-acpi@vger.kernel.org, Zhang Rui <rui.zhang@intel.com>,
	Len Brown <lenb@kernel.org>
Subject: Re: [PATCH] ACPI: fan: Use scnprintf() for avoiding potential buffer overflow
Date: Sat, 14 Mar 2020 11:13:55 +0100	[thread overview]
Message-ID: <6805885.HkWLXbPDYh@kreacher> (raw)
In-Reply-To: <20200311070851.3731-1-tiwai@suse.de>

On Wednesday, March 11, 2020 8:08:51 AM CET 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().
> 
> Also adjust the argument to really match with the actually remaining
> buffer size.
> 
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
>  drivers/acpi/fan.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
> index aaf4e8f348cf..873e039ad4b7 100644
> --- a/drivers/acpi/fan.c
> +++ b/drivers/acpi/fan.c
> @@ -276,29 +276,29 @@ static ssize_t show_state(struct device *dev, struct device_attribute *attr, cha
>  	int count;
>  
>  	if (fps->control == 0xFFFFFFFF || fps->control > 100)
> -		count = snprintf(buf, PAGE_SIZE, "not-defined:");
> +		count = scnprintf(buf, PAGE_SIZE, "not-defined:");
>  	else
> -		count = snprintf(buf, PAGE_SIZE, "%lld:", fps->control);
> +		count = scnprintf(buf, PAGE_SIZE, "%lld:", fps->control);
>  
>  	if (fps->trip_point == 0xFFFFFFFF || fps->trip_point > 9)
> -		count += snprintf(&buf[count], PAGE_SIZE, "not-defined:");
> +		count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
>  	else
> -		count += snprintf(&buf[count], PAGE_SIZE, "%lld:", fps->trip_point);
> +		count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->trip_point);
>  
>  	if (fps->speed == 0xFFFFFFFF)
> -		count += snprintf(&buf[count], PAGE_SIZE, "not-defined:");
> +		count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
>  	else
> -		count += snprintf(&buf[count], PAGE_SIZE, "%lld:", fps->speed);
> +		count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->speed);
>  
>  	if (fps->noise_level == 0xFFFFFFFF)
> -		count += snprintf(&buf[count], PAGE_SIZE, "not-defined:");
> +		count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
>  	else
> -		count += snprintf(&buf[count], PAGE_SIZE, "%lld:", fps->noise_level * 100);
> +		count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->noise_level * 100);
>  
>  	if (fps->power == 0xFFFFFFFF)
> -		count += snprintf(&buf[count], PAGE_SIZE, "not-defined\n");
> +		count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined\n");
>  	else
> -		count += snprintf(&buf[count], PAGE_SIZE, "%lld\n", fps->power);
> +		count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld\n", fps->power);
>  
>  	return count;
>  }
> 

Applied as 5.7 material, thanks!





      reply	other threads:[~2020-03-15  2:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-11  7:08 [PATCH] ACPI: fan: Use scnprintf() for avoiding potential buffer overflow Takashi Iwai
2020-03-14 10:13 ` Rafael J. Wysocki [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=6805885.HkWLXbPDYh@kreacher \
    --to=rjw@rjwysocki.net \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    --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).