Patch "thermal/core: Potential buffer overflow in thermal_build_list_of_policies()" has been added to the 5.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    thermal/core: Potential buffer overflow in thermal_build_list_of_policies()

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     thermal-core-potential-buffer-overflow-in-thermal_bu.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 185376edb9ac0b771f3a692e5f65ebf6739b71fa
Author: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
Date:   Thu Sep 16 16:13:42 2021 +0300

    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@xxxxxxxxxx>
    Signed-off-by: Daniel Lezcano <daniel.lezcano@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20210916131342.GB25094@kili
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index f526ce31f5a2..20eab56b02cb 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -228,15 +228,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);
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux