Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1673874 > unrolled thread
| Started by | Kees Cook <keescook@chromium.org> |
|---|---|
| First post | 2017-06-23 23:10 +0200 |
| Last post | 2017-06-24 16:00 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH v2 0/5] Use ELF_ET_DYN_BASE only for PIE Kees Cook <keescook@chromium.org> - 2017-06-23 23:10 +0200
[PATCH v2 3/5] arm64: Move ELF_ET_DYN_BASE to 4GB / 4MB Kees Cook <keescook@chromium.org> - 2017-06-23 23:10 +0200
Re: [PATCH v2 0/5] Use ELF_ET_DYN_BASE only for PIE Russell King - ARM Linux <linux@armlinux.org.uk> - 2017-06-24 11:20 +0200
Re: [PATCH v2 0/5] Use ELF_ET_DYN_BASE only for PIE Kees Cook <keescook@chromium.org> - 2017-06-24 16:00 +0200
| From | Kees Cook <keescook@chromium.org> |
|---|---|
| Date | 2017-06-23 23:10 +0200 |
| Subject | [PATCH v2 0/5] Use ELF_ET_DYN_BASE only for PIE |
| Message-ID | <tVE01-7gU-3@gated-at.bofh.it> |
This is v2 (to refresh the 5 patches in -mm) for moving ELF_ET_DYN_BASE
safely lower. Changes are clarifications in the commit logs (suggested
by mpe), a compat think-o fix for arm64 (thanks to Ard), and to add
Rik and mpe's Acks.
Quoting patch 1/5:
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).
To allow for a lower ELF_ET_DYN_BASE, loaders (ET_DYN without INTERP)
are loaded into the mmap region, leaving space available for either an
ET_EXEC binary with a fixed location or PIE being loaded into mmap by the
loader. Only PIE programs are loaded offset from ELF_ET_DYN_BASE, which
means architectures can now safely lower their values without risk of
loaders colliding with their subsequently loaded programs.
For 64-bit, ELF_ET_DYN_BASE is best set to 4GB to allow runtimes to
use the entire 32-bit address space for 32-bit pointers. For 32-bit,
4MB is used as the traditional minimum load location, likely to avoid
historically requiring a 4MB page table entry when only a portion of the
first 4MB would be used (since the NULL address is avoided).
Thanks to PaX Team, Daniel Micay, and Rik van Riel for inspiration and
suggestions on how to implement this solution.
-Kees
[toc] | [next] | [standalone]
| From | Kees Cook <keescook@chromium.org> |
|---|---|
| Date | 2017-06-23 23:10 +0200 |
| Subject | [PATCH v2 3/5] arm64: Move ELF_ET_DYN_BASE to 4GB / 4MB |
| Message-ID | <tVE02-7gU-19@gated-at.bofh.it> |
| In reply to | #1673874 |
Now that explicitly executed loaders are loaded in the mmap region, we have more freedom to decide where we position PIE binaries in the address space to avoid possible collisions with mmap or stack regions. For 64-bit, align to 4GB to allow runtimes to use the entire 32-bit address space for 32-bit pointers. On 32-bit use 4MB, to match ARM. This could be 0x8000, the standard ET_EXEC load address, but that is needlessly close to the NULL address, and anyone running arm compat PIE will have an MMU, so the tight mapping is not needed. Cc: stable@vger.kernel.org Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Kees Cook <keescook@chromium.org> --- arch/arm64/include/asm/elf.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h index 5d1700425efe..8790fb09f689 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -113,12 +113,11 @@ #define ELF_EXEC_PAGESIZE PAGE_SIZE /* - * This is the location that an ET_DYN program is loaded if exec'ed. Typical - * use of this is to invoke "./ld.so someprog" to test out a new version of - * the loader. We need to make sure that it is out of the way of the program - * that it will "exec", and that there is sufficient room for the brk. + * This is the base location for PIE (ET_DYN with INTERP) loads. On + * 64-bit, this is raised to 4GB to leave the entire 32-bit address + * space open for things that want to use the area for 32-bit pointers. */ -#define ELF_ET_DYN_BASE (2 * TASK_SIZE_64 / 3) +#define ELF_ET_DYN_BASE 0x100000000UL #ifndef __ASSEMBLY__ @@ -173,7 +172,8 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm, #ifdef CONFIG_COMPAT -#define COMPAT_ELF_ET_DYN_BASE (2 * TASK_SIZE_32 / 3) +/* PIE load location for compat arm. Must match ARM ELF_ET_DYN_BASE. */ +#define COMPAT_ELF_ET_DYN_BASE 0x000400000UL /* AArch32 registers. */ #define COMPAT_ELF_NGREG 18 -- 2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Russell King - ARM Linux <linux@armlinux.org.uk> |
|---|---|
| Date | 2017-06-24 11:20 +0200 |
| Message-ID | <tVPot-5YT-7@gated-at.bofh.it> |
| In reply to | #1673874 |
On Fri, Jun 23, 2017 at 01:59:55PM -0700, Kees Cook wrote: > This is v2 (to refresh the 5 patches in -mm) for moving ELF_ET_DYN_BASE > safely lower. Changes are clarifications in the commit logs (suggested > by mpe), a compat think-o fix for arm64 (thanks to Ard), and to add > Rik and mpe's Acks. > > Quoting patch 1/5: > > 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. With existing kernels on ARM: 00010000-00017000 r-xp 00000000 08:01 270810 /bin/cat 00026000-00027000 r--p 00006000 08:01 270810 /bin/cat 00027000-00028000 rw-p 00007000 08:01 270810 /bin/cat 7f661000-7f679000 r-xp 00000000 08:01 281659 /lib/arm-linux-gnueabihf/ld-2.23.so 7f688000-7f689000 r--p 00017000 08:01 281659 /lib/arm-linux-gnueabihf/ld-2.23.so 7f689000-7f68a000 rw-p 00018000 08:01 281659 /lib/arm-linux-gnueabihf/ld-2.23.so If the loader is loaded at 4MB, this means the size of an ET_EXEC program is limited to less than 4MB - and distros aren't yet building everything as PIE on ARM. -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@chromium.org> |
|---|---|
| Date | 2017-06-24 16:00 +0200 |
| Message-ID | <tVTLs-8uO-3@gated-at.bofh.it> |
| In reply to | #1674055 |
On Sat, Jun 24, 2017 at 2:11 AM, Russell King - ARM Linux <linux@armlinux.org.uk> wrote: > On Fri, Jun 23, 2017 at 01:59:55PM -0700, Kees Cook wrote: >> This is v2 (to refresh the 5 patches in -mm) for moving ELF_ET_DYN_BASE >> safely lower. Changes are clarifications in the commit logs (suggested >> by mpe), a compat think-o fix for arm64 (thanks to Ard), and to add >> Rik and mpe's Acks. >> >> Quoting patch 1/5: >> >> 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. > > With existing kernels on ARM: > > 00010000-00017000 r-xp 00000000 08:01 270810 /bin/cat > 00026000-00027000 r--p 00006000 08:01 270810 /bin/cat > 00027000-00028000 rw-p 00007000 08:01 270810 /bin/cat > 7f661000-7f679000 r-xp 00000000 08:01 281659 /lib/arm-linux-gnueabihf/ld-2.23.so > 7f688000-7f689000 r--p 00017000 08:01 281659 /lib/arm-linux-gnueabihf/ld-2.23.so > 7f689000-7f68a000 rw-p 00018000 08:01 281659 /lib/arm-linux-gnueabihf/ld-2.23.so > > If the loader is loaded at 4MB, this means the size of an ET_EXEC > program is limited to less than 4MB - and distros aren't yet > building everything as PIE on ARM. The loader isn't loaded at 4MB; that's what patch 1 changes: loaders are moved into the mmap region so they will not collide with either ET_EXEC nor PIE (ET_DYN-with-INTERP). (After this patch, the name "ELF_ET_DYN_BASE" becomes a bit misleading...) -Kees -- Kees Cook Pixel Security
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web