Date: Thu, 25 Jul 2019 19:46:53 -0700 From: Joe Perches <joe@...ches.com> To: Kees Cook <keescook@...omium.org>, Linus Torvalds <torvalds@...ux-foundation.org> Cc: Rasmus Villemoes <linux@...musvillemoes.dk>, Yann Droneaud <ydroneaud@...eya.com>, David Laight <David.Laight@...lab.com>, "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>, Jonathan Corbet <corbet@....net>, Stephen Kitt <steve@....org>, Nitin Gote <nitin.r.gote@...el.com>, "jannh@...gle.com" <jannh@...gle.com>, "kernel-hardening@...ts.openwall.com" <kernel-hardening@...ts.openwall.com>, Andrew Morton <akpm@...ux-foundation.org> Subject: Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms On Thu, 2019-07-25 at 13:03 -0700, Kees Cook wrote: > On Wed, Jul 24, 2019 at 10:08:57AM -0700, Linus Torvalds wrote: > > On Wed, Jul 24, 2019 at 6:09 AM Rasmus Villemoes > > <linux@...musvillemoes.dk> wrote: > > > The kernel's snprintf() does not behave in a non-standard way, at least > > > not with respect to its return value. > > > > Note that the kernels snprintf() *does* very much protect against the > > overflow case - not by changing the return value, but simply by having > > > > /* Reject out-of-range values early. Large positive sizes are > > used for unknown buffer sizes. */ > > if (WARN_ON_ONCE(size > INT_MAX)) > > return 0; > > > > at the very top. > > > > So you can't actually overflow in the kernel by using the repeated > > > > offset += vsnprintf( .. size - offset ..); > > > > model. > > > > Yes, it's the wrong thing to do, but it is still _safe_. > > Actually, perhaps we should add this test to strscpy() too? Doesn't seem to have a reason not to be added but maybe it's better to add another WARN_ON_ONCE. > diff --git a/lib/string.c b/lib/string.c  > @@ -182,7 +182,7 @@ ssize_t strscpy(char *dest, const char *src, size_t count) > size_t max = count; > long res = 0; > > - if (count == 0) > + if (count == 0 || count > INT_MAX) > return -E2BIG; > > #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS >
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.