All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Michal Hocko <mhocko@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Rik van Riel <riel@redhat.com>,
	Daniel Micay <danielmicay@gmail.com>,
	Qualys Security Advisory <qsa@qualys.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	"x86@kernel.org" <x86@kernel.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Dmitry Safonov <dsafonov@virtuozzo.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Grzegorz Andrejczuk <grzegorz.andrejczuk@intel.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	LKML <linux-kernel@vger.kernel.org>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"kernel-hardening@lists.openwall.com" 
	<kernel-hardening@lists.openwall.com>
Subject: Re: [PATCH v2] binfmt_elf: Use ELF_ET_DYN_BASE only for PIE
Date: Tue, 27 Jun 2017 13:08:39 -0700	[thread overview]
Message-ID: <CAGXu5jKaGjuq6s8XF+mctaL1Ckr2HtKgCnty2p6rUFQSmc-xHQ@mail.gmail.com> (raw)
In-Reply-To: <20170627144948.GD28078@dhcp22.suse.cz>

On Tue, Jun 27, 2017 at 7:49 AM, Michal Hocko <mhocko@kernel.org> wrote:
> On Wed 21-06-17 10:32:01, Kees Cook wrote:
>> The ELF_ET_DYN_BASE position was originally intended to keep loaders
>> away from ET_EXEC binaries. (For example, running "/lib/ld-linux.so.2
>> /bin/cat" might cause the subsequent load of /bin/cat into where the
>> loader had been loaded.) With the advent of PIE (ET_DYN binaries with
>> an INTERP Program Header), ELF_ET_DYN_BASE continued to be used since
>> the kernel was only looking at ET_DYN. However, since ELF_ET_DYN_BASE
>> is traditionally set at the top 1/3rd of the TASK_SIZE, a substantial
>> portion of the address space is unused.
>>
>> For 32-bit tasks when RLIMIT_STACK is set to RLIM_INFINITY, programs
>> are loaded below the mmap region. This means they can be made to collide
>> (CVE-2017-1000370) or nearly collide (CVE-2017-1000371) with pathological
>> stack regions. Lowering ELF_ET_DYN_BASE solves both by moving programs
>> above the mmap region in all cases, and will now additionally avoid
>> programs falling back to the mmap region by enforcing MAP_FIXED for
>> program loads (i.e. if it would have collided with the stack, now it
>> will fail to load instead of falling back to the mmap region).
>
> I do not understand this part. MAP_FIXED will simply unmap whatever
> was under the requested range, how it could help failing anything? So
> what would happen if something was mapped in that region, or is this
> impossible? Moreover MAP_FIXED close to stack will inhibit the stack gap
> protection.

Hmm, well, that's my misunderstanding. Regardless, it should still use
MAP_FIXED otherwise we end up with potentially unpredictable results.
(Note that MAP_FIXED is already used all all remaining allocations, it
was just missing on the first one.)

-Kees

-- 
Kees Cook
Pixel Security

WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@chromium.org>
To: Michal Hocko <mhocko@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Rik van Riel <riel@redhat.com>,
	Daniel Micay <danielmicay@gmail.com>,
	Qualys Security Advisory <qsa@qualys.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	"x86@kernel.org" <x86@kernel.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Dmitry Safonov <dsafonov@virtuozzo.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Grzegorz Andrejczuk <grzegorz.andrejczuk@intel.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	LKML <linux-kernel@vger.kernel.org>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"kernel-hardening@lists.openwall.com"
	<kernel-hardening@lists.openwall.com>
Subject: [kernel-hardening] Re: [PATCH v2] binfmt_elf: Use ELF_ET_DYN_BASE only for PIE
Date: Tue, 27 Jun 2017 13:08:39 -0700	[thread overview]
Message-ID: <CAGXu5jKaGjuq6s8XF+mctaL1Ckr2HtKgCnty2p6rUFQSmc-xHQ@mail.gmail.com> (raw)
In-Reply-To: <20170627144948.GD28078@dhcp22.suse.cz>

On Tue, Jun 27, 2017 at 7:49 AM, Michal Hocko <mhocko@kernel.org> wrote:
> On Wed 21-06-17 10:32:01, Kees Cook wrote:
>> The ELF_ET_DYN_BASE position was originally intended to keep loaders
>> away from ET_EXEC binaries. (For example, running "/lib/ld-linux.so.2
>> /bin/cat" might cause the subsequent load of /bin/cat into where the
>> loader had been loaded.) With the advent of PIE (ET_DYN binaries with
>> an INTERP Program Header), ELF_ET_DYN_BASE continued to be used since
>> the kernel was only looking at ET_DYN. However, since ELF_ET_DYN_BASE
>> is traditionally set at the top 1/3rd of the TASK_SIZE, a substantial
>> portion of the address space is unused.
>>
>> For 32-bit tasks when RLIMIT_STACK is set to RLIM_INFINITY, programs
>> are loaded below the mmap region. This means they can be made to collide
>> (CVE-2017-1000370) or nearly collide (CVE-2017-1000371) with pathological
>> stack regions. Lowering ELF_ET_DYN_BASE solves both by moving programs
>> above the mmap region in all cases, and will now additionally avoid
>> programs falling back to the mmap region by enforcing MAP_FIXED for
>> program loads (i.e. if it would have collided with the stack, now it
>> will fail to load instead of falling back to the mmap region).
>
> I do not understand this part. MAP_FIXED will simply unmap whatever
> was under the requested range, how it could help failing anything? So
> what would happen if something was mapped in that region, or is this
> impossible? Moreover MAP_FIXED close to stack will inhibit the stack gap
> protection.

Hmm, well, that's my misunderstanding. Regardless, it should still use
MAP_FIXED otherwise we end up with potentially unpredictable results.
(Note that MAP_FIXED is already used all all remaining allocations, it
was just missing on the first one.)

-Kees

-- 
Kees Cook
Pixel Security

  parent reply	other threads:[~2017-06-27 20:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-21 17:32 [PATCH v2] binfmt_elf: Use ELF_ET_DYN_BASE only for PIE Kees Cook
2017-06-21 17:32 ` [kernel-hardening] " Kees Cook
2017-06-21 18:24 ` Rik van Riel
2017-06-21 18:24   ` [kernel-hardening] " Rik van Riel
2017-06-27 14:49 ` Michal Hocko
2017-06-27 14:49   ` [kernel-hardening] " Michal Hocko
2017-06-27 14:54   ` Daniel Micay
2017-06-27 14:54     ` [kernel-hardening] " Daniel Micay
2017-06-27 20:08   ` Kees Cook [this message]
2017-06-27 20:08     ` Kees Cook
2017-06-27 20:08     ` Kees Cook
2017-07-04 13:12     ` Michal Hocko
2017-07-04 13:12       ` [kernel-hardening] " Michal Hocko
2017-07-04 13:12       ` Michal Hocko

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=CAGXu5jKaGjuq6s8XF+mctaL1Ckr2HtKgCnty2p6rUFQSmc-xHQ@mail.gmail.com \
    --to=keescook@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=danielmicay@gmail.com \
    --cc=dsafonov@virtuozzo.com \
    --cc=grzegorz.andrejczuk@intel.com \
    --cc=hpa@zytor.com \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mhocko@kernel.org \
    --cc=mingo@redhat.com \
    --cc=qsa@qualys.com \
    --cc=riel@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=viro@zeniv.linux.org.uk \
    --cc=x86@kernel.org \
    --cc=yamada.masahiro@socionext.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.