linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: chao.qin@intel.com
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Linux PM <linux-pm@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	paul.mei@intel.com, lili.li@intel.com
Subject: Re: [PATCH] powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue
Date: Wed, 21 Sep 2022 20:17:34 +0200	[thread overview]
Message-ID: <CAJZ5v0jmt7BTkmJZad9-7cC4xCc1W3iw1vb2CfOq1rUz-P6tOw@mail.gmail.com> (raw)
In-Reply-To: <20220920060826.3631210-1-chao.qin@intel.com>

On Tue, Sep 20, 2022 at 8:19 AM <chao.qin@intel.com> wrote:
>
> From: Chao Qin <chao.qin@intel.com>
>
> When value < time_unit, the parameter of ilog2() will be zero and
> the return value is -1. u64(-1) is too large for shift exponent
> and then will trigger shift-out-of-bounds:
>
> shift exponent 18446744073709551615 is too large for 32-bit type 'int'
> Call Trace:
>  rapl_compute_time_window_core
>  rapl_write_data_raw
>  set_time_window
>  store_constraint_time_window_us
>
> Signed-off-by: Chao Qin <chao.qin@intel.com>
> Acked-by: Zhang Rui <rui.zhang@intel.com>
> ---
>  drivers/powercap/intel_rapl_common.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
> index 21d624f9f5fb..bf91248630c3 100644
> --- a/drivers/powercap/intel_rapl_common.c
> +++ b/drivers/powercap/intel_rapl_common.c
> @@ -994,6 +994,9 @@ static u64 rapl_compute_time_window_core(struct rapl_package *rp, u64 value,
>                 y = value & 0x1f;
>                 value = (1 << y) * (4 + f) * rp->time_unit / 4;
>         } else {
> +               if (value < rp->time_unit)
> +                       return 0;
> +
>                 do_div(value, rp->time_unit);
>                 y = ilog2(value);
>                 f = div64_u64(4 * (value - (1 << y)), 1 << y);
> --

Applied as 6.1 material, thanks!

      reply	other threads:[~2022-09-21 18:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-20  6:08 [PATCH] powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue chao.qin
2022-09-21 18:17 ` 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=CAJZ5v0jmt7BTkmJZad9-7cC4xCc1W3iw1vb2CfOq1rUz-P6tOw@mail.gmail.com \
    --to=rafael@kernel.org \
    --cc=chao.qin@intel.com \
    --cc=lili.li@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=paul.mei@intel.com \
    /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).