lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Tue, 7 Feb 2023 15:28:23 -0800
From:   Kees Cook <keescook@...omium.org>
To:     Yann Droneaud <ydroneaud@...aton.org>
Cc:     Geert Uytterhoeven <geert@...ux-m68k.org>,
        Arnd Bergmann <arnd@...db.de>,
        Aleksa Sarai <cyphar@...har.com>,
        Christian Brauner <christian.brauner@...ntu.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        Dinh Nguyen <dinguyen@...nel.org>,
        Catalin Marinas <catalin.marinas@....com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Alexander Potapenko <glider@...gle.com>,
        Christian Brauner <brauner@...nel.org>,
        Stafford Horne <shorne@...il.com>,
        Alexander Viro <viro@...iv.linux.org.uk>,
        Christophe Leroy <christophe.leroy@...roup.eu>,
        linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH] uaccess: Add minimum bounds check on kernel buffer size

On Tue, Feb 07, 2023 at 10:06:14AM +0100, Yann Droneaud wrote:
> Hi,
> 
> Le 06/02/2023 à 21:03, Geert Uytterhoeven a écrit :
> 
> > Hi Arnd,
> > 
> > On Fri, Feb 3, 2023 at 10:23 PM Arnd Bergmann <arnd@...db.de> wrote:
> > > On Fri, Feb 3, 2023, at 20:35, Kees Cook wrote:
> > > > --- a/include/linux/uaccess.h
> > > > +++ b/include/linux/uaccess.h
> > > > @@ -329,6 +329,10 @@ copy_struct_from_user(void *dst, size_t ksize,
> > > > const void __user *src,
> > > >        size_t size = min(ksize, usize);
> > > >        size_t rest = max(ksize, usize) - size;
> > > > 
> > > > +     /* Double check if ksize is larger than a known object size. */
> > > > +     if (WARN_ON_ONCE(ksize > __builtin_object_size(dst, 1)))
> > > > +             return -E2BIG;
> > > > +
> > > WARN_ON_ONCE() may be a little expensive since that adds two
> > > comparisons and a static variable to each copy, but it's probably
> > > fine.
> > When seeing this, I was a bit worried about the size increase.
> > Hence I gave it a try on atari_defconfig and ran bloat-o-meter.
> > Surprisingly, there was no size increase at all, as all checks
> > were optimized away.
> > 
> > Hence perhaps this can become a compile-time check?
> 
> It should be a compile-time check, because one would not want __builtin_object_size(dst, 1) to return -1 if dst' size is not known at compile-time.

Note that it's size_t, so it's actually SIZE_MAX, which is why these
tests will vanish most of the time. i.e. it cannot ever be possible for
the SIZE_MAX case so the entire test is elided.

And when ksize is known at compile time and __bos is not SIZE_MAX, the
result is also known to be either always true or always false, etc.

What's nice here is that when ksize is only run-time known and the buffer
size is compile-time known, we'll keep the test.

-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ