Skip to contentSkip to conversation

sysctl: Check name array length in deprecated_sysctl_warning()

PATCH Applied Mateusz Jurczyk 2 participants 2 messages May 24, 2017 Proc sysctl

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sysctl: Check name array length in deprecated_sysctl_warning()

Prevent use of uninitialized memory (originating from the stack frame of do_sysctl()) by verifying that the name array is filled with sufficient input data before comparing its specific entries with integer constants.

Through timing measurement or analyzing the kernel debug logs, a user-mode program could potentially infer the results of comparisons against the uninitialized memory, and acquire some (very limited) information about the state of the kernel stack. The change also eliminates possible future warnings by tools such as KMSAN and other code checkers / instrumentations.

---
 kernel/sysctl_binary.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sysctl_binary.c +1 -1
index ece4b177052b..38d6ba22a209 100644
@@ -1346,7 +1346,7 @@ static void deprecated_sysctl_warning(const int *name, int nlen)
 	 * CTL_KERN/KERN_VERSION is used by older glibc and cannot
 	 * ever go away.
 	 */
-	if (name[0] == CTL_KERN && name[1] == KERN_VERSION)
+	if (nlen >= 2 && name[0] == CTL_KERN && name[1] == KERN_VERSION)
 		return;
 
 	if (printk_ratelimit()) {
Signature · 1 line
2.13.0.219.gdb65acc882-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Mateusz Jurczyk

Prevent use of uninitialized memory (originating from the stack frame of do_sysctl()) by verifying that the name array is filled with sufficient input data before comparing its specific entries with integer constants.

Quoted 8 lines

Through timing measurement or analyzing the kernel debug logs, a user-mode program could potentially infer the results of comparisons against the uninitialized memory, and acquire some (very limited) information about the state of the kernel stack. The change also eliminates possible future warnings by tools such as KMSAN and other code checkers / instrumentations.

-Kees

Quoted 20 lines
---
 kernel/sysctl_binary.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sysctl_binary.c +1 -2
index ece4b177052b..38d6ba22a209 100644
@@ -1346,7 +1346,7 @@ static void deprecated_sysctl_warning(const int *name, int nlen)
         * CTL_KERN/KERN_VERSION is used by older glibc and cannot
         * ever go away.
         */
-       if (name[0] == CTL_KERN && name[1] == KERN_VERSION)
+       if (nlen >= 2 && name[0] == CTL_KERN && name[1] == KERN_VERSION)
                return;
 
        if (printk_ratelimit()) {
--

2.13.0.219.gdb65acc882-goog

Signature · 2 lines
Kees Cook
Pixel Security