From: David Laight <David.Laight@ACULAB.COM>
To: 'Jann Horn' <jannh@google.com>, Marco Elver <elver@google.com>,
"Peter Zijlstra" <peterz@infradead.org>,
Alexander Potapenko <glider@google.com>
Cc: Kees Cook <keescook@chromium.org>,
Thomas Gleixner <tglx@linutronix.de>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Elena Reshetova <elena.reshetova@intel.com>,
"Mark Rutland" <mark.rutland@arm.com>,
Peter Collingbourne <pcc@google.com>,
"kasan-dev@googlegroups.com" <kasan-dev@googlegroups.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"llvm@lists.linux.dev" <llvm@lists.linux.dev>,
"linux-toolchains@vger.kernel.org"
<linux-toolchains@vger.kernel.org>
Subject: RE: randomize_kstack: To init or not to init?
Date: Sat, 11 Dec 2021 17:01:07 +0000 [thread overview]
Message-ID: <d35ca52c81e7408ba94210c6dbc30368@AcuMS.aculab.com> (raw)
In-Reply-To: <CAG48ez0dZwigkLHVWvNS6Cg-7bL4GoCMULyQzWteUv4zZ=OnWQ@mail.gmail.com>
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)
next prev parent reply other threads:[~2021-12-11 17:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-09 9:58 randomize_kstack: To init or not to init? Marco Elver
2021-12-09 10:27 ` Peter Zijlstra
2021-12-09 12:58 ` Marco Elver
2021-12-09 20:16 ` Segher Boessenkool
2021-12-09 20:33 ` Marco Elver
2021-12-20 7:00 ` Marco Elver
2021-12-09 20:48 ` Kees Cook
2021-12-09 20:54 ` Marco Elver
2021-12-09 21:11 ` Alexander Potapenko
2021-12-10 0:01 ` Segher Boessenkool
2021-12-09 21:14 ` Kees Cook
2021-12-09 21:16 ` Jann Horn
2021-12-09 21:40 ` Marco Elver
2021-12-11 17:01 ` David Laight [this message]
2021-12-11 20:20 ` Segher Boessenkool
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d35ca52c81e7408ba94210c6dbc30368@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=elena.reshetova@intel.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=jannh@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-toolchains@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=pcc@google.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).