aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2021-09-16 16:13:42 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-09-30 10:11:04 +0200
commit8cba4c2698e282aa03948b74ebc259925c873402 (patch)
tree3adb7de6f2a4c1c94347100ce698b5db0478a451
parent215df4349916a62a03b1899ded08e7a9d2d40480 (diff)
downloadkernel_replicant_linux-8cba4c2698e282aa03948b74ebc259925c873402.tar.gz
kernel_replicant_linux-8cba4c2698e282aa03948b74ebc259925c873402.tar.bz2
kernel_replicant_linux-8cba4c2698e282aa03948b74ebc259925c873402.zip
thermal/core: Potential buffer overflow in thermal_build_list_of_policies()
[ Upstream commit 1bb30b20b49773369c299d4d6c65227201328663 ] After printing the list of thermal governors, then this function prints a newline character. The problem is that "size" has not been updated after printing the last governor. This means that it can write one character (the NUL terminator) beyond the end of the buffer. Get rid of the "size" variable and just use "PAGE_SIZE - count" directly. Fixes: 1b4f48494eb2 ("thermal: core: group functions related to governor handling") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20210916131342.GB25094@kili Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/thermal/thermal_core.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index e669f83faa3c..17de8a9b991e 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -224,15 +224,14 @@ int thermal_build_list_of_policies(char *buf)
{
struct thermal_governor *pos;
ssize_t count = 0;
- ssize_t size = PAGE_SIZE;
mutex_lock(&thermal_governor_lock);
list_for_each_entry(pos, &thermal_governor_list, governor_list) {
- size = PAGE_SIZE - count;
- count += scnprintf(buf + count, size, "%s ", pos->name);
+ count += scnprintf(buf + count, PAGE_SIZE - count, "%s ",
+ pos->name);
}
- count += scnprintf(buf + count, size, "\n");
+ count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
mutex_unlock(&thermal_governor_lock);