From: Takashi Iwai <tiwai@suse.de>
To: Zhang Rui <rui.zhang@intel.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Amit Kucheria <amit.kucheria@verdurent.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] thermal: Add a sanity check for invalid state at stats update
Date: Mon, 30 Mar 2020 16:08:59 +0200 [thread overview]
Message-ID: <20200330140859.12535-1-tiwai@suse.de> (raw)
The thermal sysfs handler keeps the statistics table with the fixed
size that was determined from the initial max_states() call, and the
table entry is updated at each sysfs cur_state write call. And, when
the driver's set_cur_state() ops accepts the value given from
user-space, the thermal sysfs core blindly applies it to the
statistics table entry, which may overflow and cause an Oops.
Although it's rather a bug in the driver's ops implementations, we
shouldn't crash but rather give a proper warning instead.
This patch adds a sanity check for avoiding such an OOB access and
warns with a stack trace to show the suspicious device in question.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
We've hit some crash by stress tests, and this patch at least works
around the crash itself. While the actual bug fix of the buggy driver
is still being investigated, I submit the hardening in the core side
at first.
drivers/thermal/thermal_sysfs.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index aa99edb4dff7..a23c4e701d63 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -772,6 +772,11 @@ void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
spin_lock(&stats->lock);
+ if (dev_WARN_ONCE(&cdev->device, new_state >= stats->max_states,
+ "new state %ld exceeds max_state %ld",
+ new_state, stats->max_states))
+ goto unlock;
+
if (stats->state == new_state)
goto unlock;
--
2.16.4
next reply other threads:[~2020-03-30 14:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-30 14:08 Takashi Iwai [this message]
2020-04-07 13:30 ` [PATCH] thermal: Add a sanity check for invalid state at stats update Amit Kucheria
2020-04-07 14:12 ` Takashi Iwai
2020-04-07 14:17 ` Zhang, Rui
2020-04-07 15:37 ` Zhang, Rui
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=20200330140859.12535-1-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=amit.kucheria@verdurent.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rui.zhang@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).