Skip to content

Commit 1bb30b2

Browse files
Dan Carpenterdlezcano
authored andcommitted
thermal/core: Potential buffer overflow in thermal_build_list_of_policies()
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: 1b4f484 ("thermal: core: group functions related to governor handling") Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/20210916131342.GB25094@kili
1 parent 8b4bd25 commit 1bb30b2

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/thermal/thermal_core.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,14 @@ int thermal_build_list_of_policies(char *buf)
222222
{
223223
struct thermal_governor *pos;
224224
ssize_t count = 0;
225-
ssize_t size = PAGE_SIZE;
226225

227226
mutex_lock(&thermal_governor_lock);
228227

229228
list_for_each_entry(pos, &thermal_governor_list, governor_list) {
230-
size = PAGE_SIZE - count;
231-
count += scnprintf(buf + count, size, "%s ", pos->name);
229+
count += scnprintf(buf + count, PAGE_SIZE - count, "%s ",
230+
pos->name);
232231
}
233-
count += scnprintf(buf + count, size, "\n");
232+
count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
234233

235234
mutex_unlock(&thermal_governor_lock);
236235

0 commit comments

Comments
 (0)