kernel/sysctl_binary.c: 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.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Mateusz Jurczyk <[email protected]>
Acked-by: Kees Cook <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Matthew Whitehead <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Tetsuo Handa <[email protected]>
Cc: Alexander Potapenko <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
Mateusz Jurczyk authored and Linus Torvalds committed 2017-07-12 16:26:00 -07:00
1 parent 7c43a657a4
commit 9380fa60b1
1 file changed
+1 -1
+1 -1
View File
@@ -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()) {