Patch "kconfig: fix memory leak from range properties" has been added to the 4.19-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

    kconfig: fix memory leak from range properties

to the 4.19-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:
     kconfig-fix-memory-leak-from-range-properties.patch
and it can be found in the queue-4.19 subdirectory.

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



commit 379bc3ff94894e35c07c93c50c1b75be94ef69e1
Author: Masahiro Yamada <masahiroy@xxxxxxxxxx>
Date:   Wed Nov 15 13:16:53 2023 +0900

    kconfig: fix memory leak from range properties
    
    [ Upstream commit ae1eff0349f2e908fc083630e8441ea6dc434dc0 ]
    
    Currently, sym_validate_range() duplicates the range string using
    xstrdup(), which is overwritten by a subsequent sym_calc_value() call.
    It results in a memory leak.
    
    Instead, only the pointer should be copied.
    
    Below is a test case, with a summary from Valgrind.
    
    [Test Kconfig]
    
      config FOO
              int "foo"
              range 10 20
    
    [Test .config]
    
      CONFIG_FOO=0
    
    [Before]
    
      LEAK SUMMARY:
         definitely lost: 3 bytes in 1 blocks
         indirectly lost: 0 bytes in 0 blocks
           possibly lost: 0 bytes in 0 blocks
         still reachable: 17,465 bytes in 21 blocks
              suppressed: 0 bytes in 0 blocks
    
    [After]
    
      LEAK SUMMARY:
         definitely lost: 0 bytes in 0 blocks
         indirectly lost: 0 bytes in 0 blocks
           possibly lost: 0 bytes in 0 blocks
         still reachable: 17,462 bytes in 20 blocks
              suppressed: 0 bytes in 0 blocks
    
    Signed-off-by: Masahiro Yamada <masahiroy@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 703b9b899ee9c..5adb60b7e12f3 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -119,9 +119,9 @@ static long long sym_get_range_val(struct symbol *sym, int base)
 static void sym_validate_range(struct symbol *sym)
 {
 	struct property *prop;
+	struct symbol *range_sym;
 	int base;
 	long long val, val2;
-	char str[64];
 
 	switch (sym->type) {
 	case S_INT:
@@ -137,17 +137,15 @@ static void sym_validate_range(struct symbol *sym)
 	if (!prop)
 		return;
 	val = strtoll(sym->curr.val, NULL, base);
-	val2 = sym_get_range_val(prop->expr->left.sym, base);
+	range_sym = prop->expr->left.sym;
+	val2 = sym_get_range_val(range_sym, base);
 	if (val >= val2) {
-		val2 = sym_get_range_val(prop->expr->right.sym, base);
+		range_sym = prop->expr->right.sym;
+		val2 = sym_get_range_val(range_sym, base);
 		if (val <= val2)
 			return;
 	}
-	if (sym->type == S_INT)
-		sprintf(str, "%lld", val2);
-	else
-		sprintf(str, "0x%llx", val2);
-	sym->curr.val = xstrdup(str);
+	sym->curr.val = range_sym->curr.val;
 }
 
 static void sym_set_changed(struct symbol *sym)



[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