linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: srinivas pandruvada <srinivas.pandruvada@linux.intel.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	Daniil Dulov <d.dulov@aladdin.ru>,
	Zhang Rui <rui.zhang@intel.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>,
	Amit Kucheria <amitk@kernel.org>, Chen Yu <yu.c.chen@intel.com>,
	Jacob Pan <jacob.jun.pan@linux.intel.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	lvc-project@linuxtesting.org
Subject: Re: [PATCH] thermal: intel_powerclamp: Check for a possible array out of bounds access.
Date: Mon, 05 Jun 2023 09:36:54 -0700	[thread overview]
Message-ID: <9a4660438e0466c04880fad4450215707921521e.camel@linux.intel.com> (raw)
In-Reply-To: <CAJZ5v0iyDvApQVjY=BopVSXZSg3tqmcYBnDQN2HORp3Oy8atEQ@mail.gmail.com>

On Sun, 2023-06-04 at 18:13 +0200, Rafael J. Wysocki wrote:
> Cc list trimmed.
> 
> On Fri, Jun 2, 2023 at 11:12 AM Daniil Dulov <d.dulov@aladdin.ru>
> wrote:
> > 
> > ratio may be equal to MAX_TARGET_RATIO - 1 that will result in
> > out of bound access.
> > 
The description was not clear to me.

May be something like this:

"
The max value of "ratio" parameter passed to the function
get_compensation() is MAX_TARGET_RATIO - 1. The size of cal_data array
is MAX_TARGET_RATIO. Hence, accessing cal_data[ratio + 1], will result
in out of bound access.

Add a condition to check ratio < MAX_TARGET_RATIO - 1, before accsssing
cal_data[ratio + 1].
"

The change is correct. But for actual code change,
the ratio < MAX_TARGET_RATIO - 1 is also checked in else if() before,
which can be merged to check only once for this condition.

Thanks,
Srinivas






> > Found by Linux Verification Center (linuxtesting.org) with SVACE.
> > 
> > Fixes: d6d71ee4a14a ("PM: Introduce Intel PowerClamp Driver")
> > Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
> > ---
> >  drivers/thermal/intel/intel_powerclamp.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/thermal/intel/intel_powerclamp.c
> > b/drivers/thermal/intel/intel_powerclamp.c
> > index fb04470d7d4b..9deaf2b8ccf6 100644
> > --- a/drivers/thermal/intel/intel_powerclamp.c
> > +++ b/drivers/thermal/intel/intel_powerclamp.c
> > @@ -277,7 +277,8 @@ static unsigned int get_compensation(int ratio)
> >                 comp = (cal_data[ratio].steady_comp +
> >                         cal_data[ratio - 1].steady_comp +
> >                         cal_data[ratio - 2].steady_comp) / 3;
> > -       } else if (cal_data[ratio].confidence >= CONFIDENCE_OK &&

I think the concern is that cal_data[ratio + 1] is going out of bound
for the "ratio" passed to this function, when ratio ==
ARRAY_SIZE(cal_data) - 1;

Here size of cal_data array is 50. The max possible "ratio" passed can
be 49.




> > +       } else if (ratio < MAX_TARGET_RATIO - 1 &&
> > +               cal_data[ratio].confidence >= CONFIDENCE_OK &&
> >                 cal_data[ratio - 1].confidence >= CONFIDENCE_OK &&
> >                 cal_data[ratio + 1].confidence >= CONFIDENCE_OK) {
> >                 comp = (cal_data[ratio].steady_comp +
> > --
> 
> Rui, Srinivas, can you have a look at this, please?


      reply	other threads:[~2023-06-05 16:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-02  8:55 [PATCH] thermal: intel_powerclamp: Check for a possible array out of bounds access Daniil Dulov
2023-06-04 16:13 ` Rafael J. Wysocki
2023-06-05 16:36   ` srinivas pandruvada [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=9a4660438e0466c04880fad4450215707921521e.camel@linux.intel.com \
    --to=srinivas.pandruvada@linux.intel.com \
    --cc=amitk@kernel.org \
    --cc=d.dulov@aladdin.ru \
    --cc=daniel.lezcano@linaro.org \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=yu.c.chen@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).