From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] arm64: kernel: Fix incorrect brk randomization
Date: Wed, 11 May 2016 16:29:38 +0100 [thread overview]
Message-ID: <20160511152938.GA24039@arm.com> (raw)
In-Reply-To: <CAGXu5jLy4e1d8oQMAm8JTgCjyCPb_i3QvMw+gT3_H6WeAatO1Q@mail.gmail.com>
On Wed, May 11, 2016 at 08:27:14AM -0700, Kees Cook wrote:
> On Wed, May 11, 2016 at 2:44 AM, Jon Medhurst (Tixy) <tixy@linaro.org> wrote:
> > On Tue, 2016-05-10 at 10:55 -0700, Kees Cook wrote:
> >> This fixes two issues with the arm64 brk randomziation. First, the
> >> STACK_RND_MASK was being used incorrectly. The original code was:
> >>
> >> unsigned long range_end = base + (STACK_RND_MASK << PAGE_SHIFT) + 1;
> >>
> >> STACK_RND_MASK is 0x7ff (32-bit) or 0x3ffff (64-bit), with 4K pages where
> >> PAGE_SHIFT is 12:
> >>
> >> #define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
> >> 0x7ff >> (PAGE_SHIFT - 12) : \
> >> 0x3ffff >> (PAGE_SHIFT - 12))
> >>
> >> This means the resulting offset from base would be 0x7ff0001 or 0x3ffff0001,
> >> which is wrong since it creates an unaligned end address. It was likely
> >> intended to be:
> >>
> >> unsigned long range_end = base + ((STACK_RND_MASK + 1) << PAGE_SHIFT)
> >>
> >> Which would result in offsets of 0x800000 (32-bit) and 0x40000000 (64-bit).
> >>
> >> However, even this corrected 32-bit compat offset (0x00800000) is much
> >> smaller than native ARM's brk randomization value (0x02000000):
> >>
> >> unsigned long arch_randomize_brk(struct mm_struct *mm)
> >> {
> >> unsigned long range_end = mm->brk + 0x02000000;
> >> return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
> >> }
> >>
> >> So, instead of basing arm64's brk randomization on mistaken STACK_RND_MASK
> >> calculations, just use specific corrected values for compat (0x2000000)
> >> and native arm64 (0x40000000).
> >>
> >> Signed-off-by: Kees Cook <keescook@chromium.org>
> >
> > There seems to be a helper 'is_compat_task()' that does
> > 'test_thread_flag(TIF_32BIT)' so could perhaps be used instead, but
> > that's too nit-picky. This change makes things more consistent with
>
> Oh, good call. Yeah, none of the other .c code does direct tests for
> the TIF_32BIT flag, so I'll use the helper and send a v2. Thanks!
I already applied it with that change and Tixy's reviewed-by. Thanks!
Will
next prev parent reply other threads:[~2016-05-11 15:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-10 17:55 [PATCH] arm64: kernel: Fix incorrect brk randomization Kees Cook
2016-05-11 9:44 ` Jon Medhurst (Tixy)
2016-05-11 15:27 ` Kees Cook
2016-05-11 15:29 ` Will Deacon [this message]
2016-05-11 15:30 ` Kees Cook
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=20160511152938.GA24039@arm.com \
--to=will.deacon@arm.com \
--cc=linux-arm-kernel@lists.infradead.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).