All of lore.kernel.org
 help / color / mirror / Atom feed
From: olof@lixom.net (Olof Johansson)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] firmware: arm_scmi: fix divide by zero when sustained_perf_level is zero
Date: Thu, 6 Sep 2018 09:59:32 -0700	[thread overview]
Message-ID: <20180906165932.csa5b4vlmaekv5y2@localhost> (raw)
In-Reply-To: <1536246639-7420-1-git-send-email-sudeep.holla@arm.com>

Hi,

On Thu, Sep 06, 2018 at 04:10:39PM +0100, Sudeep Holla wrote:
> Firmware can provide zero as values for sustained performance level and
> corresponding sustained frequency in kHz in order to hide the actual
> frequencies and provide only abstract values. It may endup with divide
> by zero scenario resulting in kernel panic.
> 
> Let's set the multiplication factor to one if either one or both of them
> (sustained_perf_level and sustained_freq) are set to zero.
> 
> Fixes: a9e3fbfaa0ff ("firmware: arm_scmi: add initial support for performance protocol")
> Reported-by: Ionela Voinescu <ionela.voinescu@arm.com>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>  drivers/firmware/arm_scmi/perf.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> Hi ARM SoC team,
> 
> Can you pick this patch directly ?

Applied, however:

> diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c
> index 721e6c57beae..64342944d917 100644
> --- a/drivers/firmware/arm_scmi/perf.c
> +++ b/drivers/firmware/arm_scmi/perf.c
> @@ -166,7 +166,13 @@ scmi_perf_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
>  					le32_to_cpu(attr->sustained_freq_khz);
>  		dom_info->sustained_perf_level =
>  					le32_to_cpu(attr->sustained_perf_level);
> -		dom_info->mult_factor =	(dom_info->sustained_freq_khz * 1000) /
> +		if (!dom_info->sustained_freq_khz ||
> +		    !dom_info->sustained_perf_level)
> +			/* CPUFreq converts to kHz, hence default 1000 */
> +			dom_info->mult_factor =	1000;
> +		else
> +			dom_info->mult_factor =
> +					(dom_info->sustained_freq_khz * 1000) /
>  					dom_info->sustained_perf_level;
>  		memcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);

I noticed you do memcpy of these name strings in a few places, and use
it as a string. Any firmware that would return a non-terminated string
would cause problems later on. strlcpy() might be a better approach.



-Olof

WARNING: multiple messages have this Message-ID (diff)
From: Olof Johansson <olof@lixom.net>
To: Sudeep Holla <sudeep.holla@arm.com>
Cc: arm@kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Ionela Voinescu <ionela.voinescu@arm.com>,
	Quentin Perret <quentin.perret@arm.com>,
	Kevin Hilman <khilman@linaro.org>, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH v2] firmware: arm_scmi: fix divide by zero when sustained_perf_level is zero
Date: Thu, 6 Sep 2018 09:59:32 -0700	[thread overview]
Message-ID: <20180906165932.csa5b4vlmaekv5y2@localhost> (raw)
In-Reply-To: <1536246639-7420-1-git-send-email-sudeep.holla@arm.com>

Hi,

On Thu, Sep 06, 2018 at 04:10:39PM +0100, Sudeep Holla wrote:
> Firmware can provide zero as values for sustained performance level and
> corresponding sustained frequency in kHz in order to hide the actual
> frequencies and provide only abstract values. It may endup with divide
> by zero scenario resulting in kernel panic.
> 
> Let's set the multiplication factor to one if either one or both of them
> (sustained_perf_level and sustained_freq) are set to zero.
> 
> Fixes: a9e3fbfaa0ff ("firmware: arm_scmi: add initial support for performance protocol")
> Reported-by: Ionela Voinescu <ionela.voinescu@arm.com>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>  drivers/firmware/arm_scmi/perf.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> Hi ARM SoC team,
> 
> Can you pick this patch directly ?

Applied, however:

> diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c
> index 721e6c57beae..64342944d917 100644
> --- a/drivers/firmware/arm_scmi/perf.c
> +++ b/drivers/firmware/arm_scmi/perf.c
> @@ -166,7 +166,13 @@ scmi_perf_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
>  					le32_to_cpu(attr->sustained_freq_khz);
>  		dom_info->sustained_perf_level =
>  					le32_to_cpu(attr->sustained_perf_level);
> -		dom_info->mult_factor =	(dom_info->sustained_freq_khz * 1000) /
> +		if (!dom_info->sustained_freq_khz ||
> +		    !dom_info->sustained_perf_level)
> +			/* CPUFreq converts to kHz, hence default 1000 */
> +			dom_info->mult_factor =	1000;
> +		else
> +			dom_info->mult_factor =
> +					(dom_info->sustained_freq_khz * 1000) /
>  					dom_info->sustained_perf_level;
>  		memcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);

I noticed you do memcpy of these name strings in a few places, and use
it as a string. Any firmware that would return a non-terminated string
would cause problems later on. strlcpy() might be a better approach.



-Olof

  reply	other threads:[~2018-09-06 16:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-05 16:38 [PATCH] firmware: arm_scmi: fix divide by zero when sustained_perf_level is zero Sudeep Holla
2018-09-05 16:38 ` Sudeep Holla
2018-09-06 13:17 ` Quentin Perret
2018-09-06 13:17   ` Quentin Perret
2018-09-06 14:38   ` Sudeep Holla
2018-09-06 14:38     ` Sudeep Holla
2018-09-06 15:10 ` [PATCH v2] " Sudeep Holla
2018-09-06 15:10   ` Sudeep Holla
2018-09-06 16:59   ` Olof Johansson [this message]
2018-09-06 16:59     ` Olof Johansson
2018-09-06 17:11     ` Sudeep Holla
2018-09-06 17:11       ` Sudeep Holla

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=20180906165932.csa5b4vlmaekv5y2@localhost \
    --to=olof@lixom.net \
    --cc=linux-arm-kernel@lists.infradead.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.