From: Borislav Petkov <bp@alien8.de>
To: Kees Cook <keescook@chromium.org>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
"Thomas Gleixner" <tglx@linutronix.de>,
"Ingo Molnar" <mingo@redhat.com>,
"H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, "Alexander Viro" <viro@zeniv.linux.org.uk>,
"Ismael Ripoll" <iripoll@upv.es>,
"Hector Marco-Gisbert" <hecmargi@upv.es>,
"Jan-Simon Möller" <dl9pf@gmx.de>,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] ASLR: fix stack randomization on 64-bit systems
Date: Wed, 18 Feb 2015 10:15:43 +0100 [thread overview]
Message-ID: <20150218091543.GF3211@pd.tnic> (raw)
In-Reply-To: <20150214173350.GA18393@www.outflux.net>
On Sat, Feb 14, 2015 at 09:33:50AM -0800, Kees Cook wrote:
> From: Hector Marco-Gisbert <hecmargi@upv.es>
>
> The issue is that the stack for processes is not properly randomized on 64 bit
> architectures due to an integer overflow.
>
> The affected function is randomize_stack_top() in file "fs/binfmt_elf.c":
>
> static unsigned long randomize_stack_top(unsigned long stack_top)
> {
> unsigned int random_variable = 0;
>
> if ((current->flags & PF_RANDOMIZE) &&
> !(current->personality & ADDR_NO_RANDOMIZE)) {
> random_variable = get_random_int() & STACK_RND_MASK;
> random_variable <<= PAGE_SHIFT;
> }
> return PAGE_ALIGN(stack_top) + random_variable;
> return PAGE_ALIGN(stack_top) - random_variable;
> }
>
> Note that, it declares the "random_variable" variable as "unsigned int". Since
> the result of the shifting operation between STACK_RND_MASK (which is
> 0x3fffff on x86_64, 22 bits) and PAGE_SHIFT (which is 12 on x86_64):
>
> random_variable <<= PAGE_SHIFT;
>
> then the two leftmost bits are dropped when storing the result in the
> "random_variable". This variable shall be at least 34 bits long to hold the
> (22+12) result.
>
> These two dropped bits have an impact on the entropy of process stack.
> Concretely, the total stack entropy is reduced by four: from 2^28 to 2^30 (One
> fourth of expected entropy).
>
> This patch restores back the entropy by correcting the types involved in the
> operations in the functions randomize_stack_top() and stack_maxrandom_size().
>
> The successful fix can be tested with:
> $ for i in `seq 1 10`; do cat /proc/self/maps | grep stack; done
> 7ffeda566000-7ffeda587000 rw-p 00000000 00:00 0 [stack]
> 7fff5a332000-7fff5a353000 rw-p 00000000 00:00 0 [stack]
> 7ffcdb7a1000-7ffcdb7c2000 rw-p 00000000 00:00 0 [stack]
> 7ffd5e2c4000-7ffd5e2e5000 rw-p 00000000 00:00 0 [stack]
> ...
>
> Once corrected, the leading bytes should be between 7ffc and 7fff, rather
> than always being 7fff.
>
> CVE-2015-1593
>
> Signed-off-by: Hector Marco-Gisbert <hecmargi@upv.es>
> Signed-off-by: Ismael Ripoll <iripoll@upv.es>
> [kees: rebase, fix 80 char, clean up commit message, add test example, cve]
> Signed-off-by: Kees Cook <keescook@chromium.org>
> Cc: stable@vger.kernel.org
Ok, I'm picking this up. Do scream if someone else wants to do that,
otherwise it is going to tip next week, after the merge window is over.
Thanks.
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--
next prev parent reply other threads:[~2015-02-18 9:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-14 17:33 [PATCH] ASLR: fix stack randomization on 64-bit systems Kees Cook
2015-02-16 20:49 ` Andy Lutomirski
2015-02-18 3:27 ` Kees Cook
2015-02-18 9:15 ` Borislav Petkov [this message]
2015-02-18 20:11 ` Andrew Morton
2015-02-18 20:19 ` Ingo Molnar
2015-02-18 20:25 ` Borislav Petkov
2015-02-18 20:26 ` Ingo Molnar
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=20150218091543.GF3211@pd.tnic \
--to=bp@alien8.de \
--cc=akpm@linux-foundation.org \
--cc=dl9pf@gmx.de \
--cc=hecmargi@upv.es \
--cc=hpa@zytor.com \
--cc=iripoll@upv.es \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=viro@zeniv.linux.org.uk \
--cc=x86@kernel.org \
/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).