From: Dan Carpenter <dan.carpenter@oracle.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: linux-pm@vger.kernel.org
Subject: Re: [bug report] thermal: Add cooling device's statistics in sysfs
Date: Mon, 17 Oct 2022 10:09:06 +0300 [thread overview]
Message-ID: <Y0z/knSyW1e6Dg3D@kadam> (raw)
In-Reply-To: <20221017055735.is4by26po2woxzet@vireshk-i7>
On Mon, Oct 17, 2022 at 11:27:35AM +0530, Viresh Kumar wrote:
> On 14-10-22, 17:08, Dan Carpenter wrote:
> > Hello Viresh Kumar,
> >
> > The patch 8ea229511e06: "thermal: Add cooling device's statistics in
> > sysfs" from Apr 2, 2018, leads to the following Smatch static checker
> > warning:
> >
> > drivers/thermal/thermal_sysfs.c:656 thermal_cooling_device_stats_update()
> > warn: potential integer overflow from user 'stats->state * stats->max_states + new_state'
> >
> > drivers/thermal/thermal_sysfs.c
> > 642 void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
> > 643 unsigned long new_state)
> > 644 {
> > 645 struct cooling_dev_stats *stats = cdev->stats;
> > 646
> > 647 if (!stats)
> > 648 return;
> > 649
> > 650 spin_lock(&stats->lock);
> > 651
> > 652 if (stats->state == new_state)
> > 653 goto unlock;
> > 654
> > 655 update_time_in_state(stats);
> > --> 656 stats->trans_table[stats->state * stats->max_states + new_state]++;
> > ^^^^^^^^^
> > The new state value comes from the user via sysfs. It is <= LONG_MAX
> > but otherwise there is no limit on its value.
>
> This routine gets called after cdev->ops->set_cur_state() has returned
> successfully. That callback does the verification of this value, based
> on what's the maximum value allowed and hence the size of the array
> here.
>
> I don't think we will have any issue here unless the cooling driver is
> buggy and isn't checking the state properly.
>
I only looked at the 1 example I posted, but so far as I can see from a
sample size of 1 they are all buggy. 100% buggy.
This strategy of relying on the drivers to do it correctly was doomed
from the get go.
regards,
dan carpenter
next prev parent reply other threads:[~2022-10-17 7:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-14 14:08 [bug report] thermal: Add cooling device's statistics in sysfs Dan Carpenter
2022-10-14 14:30 ` Dan Carpenter
2022-10-17 9:38 ` Viresh Kumar
2022-10-17 13:19 ` Dan Carpenter
2022-10-18 4:02 ` Viresh Kumar
2022-10-17 5:57 ` Viresh Kumar
2022-10-17 7:09 ` Dan Carpenter [this message]
2022-10-17 7:10 ` Viresh Kumar
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=Y0z/knSyW1e6Dg3D@kadam \
--to=dan.carpenter@oracle.com \
--cc=linux-pm@vger.kernel.org \
--cc=viresh.kumar@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox