mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sysctl: Check name array length in deprecated_sysctl_warning()
@ 2017-05-24 12:21 Mateusz Jurczyk
  2017-05-24 17:07 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Mateusz Jurczyk @ 2017-05-24 12:21 UTC (permalink / raw)
  To: David S. Miller, Matthew Whitehead, Eric W. Biederman,
	Tetsuo Handa, Andrew Morton
  Cc: linux-kernel

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.

Signed-off-by: Mateusz Jurczyk <mjurczyk@google.com>
---
 kernel/sysctl_binary.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
index ece4b177052b..38d6ba22a209 100644
--- a/kernel/sysctl_binary.c
+++ b/kernel/sysctl_binary.c
@@ -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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] sysctl: Check name array length in deprecated_sysctl_warning()
  2017-05-24 12:21 [PATCH] sysctl: Check name array length in deprecated_sysctl_warning() Mateusz Jurczyk
@ 2017-05-24 17:07 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2017-05-24 17:07 UTC (permalink / raw)
  To: Mateusz Jurczyk, Andrew Morton
  Cc: David S. Miller, Matthew Whitehead, Eric W. Biederman,
	Tetsuo Handa, LKML

On Wed, May 24, 2017 at 5:21 AM, Mateusz Jurczyk <mjurczyk@google.com> wrote:
> 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.
>
> Signed-off-by: Mateusz Jurczyk <mjurczyk@google.com>

Acked-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  kernel/sysctl_binary.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
> index ece4b177052b..38d6ba22a209 100644
> --- a/kernel/sysctl_binary.c
> +++ b/kernel/sysctl_binary.c
> @@ -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
>



-- 
Kees Cook
Pixel Security

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-24 17:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-24 12:21 [PATCH] sysctl: Check name array length in deprecated_sysctl_warning() Mateusz Jurczyk
2017-05-24 17:07 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®