[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d35ca52c81e7408ba94210c6dbc30368@AcuMS.aculab.com>
Date: Sat, 11 Dec 2021 17:01:07 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Jann Horn' <jannh@...gle.com>, Marco Elver <elver@...gle.com>,
"Peter Zijlstra" <peterz@...radead.org>,
Alexander Potapenko <glider@...gle.com>
CC: Kees Cook <keescook@...omium.org>,
Thomas Gleixner <tglx@...utronix.de>,
Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Elena Reshetova <elena.reshetova@...el.com>,
"Mark Rutland" <mark.rutland@....com>,
Peter Collingbourne <pcc@...gle.com>,
"kasan-dev@...glegroups.com" <kasan-dev@...glegroups.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"llvm@...ts.linux.dev" <llvm@...ts.linux.dev>,
"linux-toolchains@...r.kernel.org" <linux-toolchains@...r.kernel.org>
Subject: RE: randomize_kstack: To init or not to init?
From: Jann Horn
> Sent: 09 December 2021 21:16
...
> This doesn't just affect alloca(), right? According to godbolt.org
> (https://godbolt.org/z/jYrWEx7o8):
>
> void bar(char *p);
> void foo() {
> char arr[512];
> bar(arr);
> }
>
> when compiled with "-ftrivial-auto-var-init=pattern -O2 -mno-sse"
> gives this result:
>
> foo: # @foo
> push rbx
> sub rsp, 512
> mov rbx, rsp
> mov edx, 512
> mov rdi, rbx
> mov esi, 170
> call memset@PLT
> mov rdi, rbx
> call bar
> add rsp, 512
> pop rbx
> ret
Jeepers - I don't ever want that to happen not ever...
There is plenty of userspace code that allocates large arrays on stack
(I bet some get into MB sizes) that are correctly bound-checked but
the expense of initialising them will be horrid.
So you end up with horrid, complex, more likely to be buggy, code
that tries to allocate things that are 'just big enough' rather
than just a sanity check on a large buffer.
Typical examples are char path[MAXPATH].
You know the path will almost certainly be < 100 bytes.
MAXPATH is overkill - but can be tested for.
But you don't want path[] initialised.
So you cane to pick a shorter length - and then it all goes 'TITSUP'
when the actual path is a bit longer than you allowed for.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists