2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-19 02:34:01 +08:00
linux-next/arch/x86/tools
Junjie Mao e6023367d7 x86, kaslr: Prevent .bss from overlaping initrd
When choosing a random address, the current implementation does not take into
account the reversed space for .bss and .brk sections. Thus the relocated kernel
may overlap other components in memory. Here is an example of the overlap from a
x86_64 kernel in qemu (the ranges of physical addresses are presented):

 Physical Address

    0x0fe00000                  --+--------------------+  <-- randomized base
                               /  |  relocated kernel  |
                   vmlinux.bin    | (from vmlinux.bin) |
    0x1336d000    (an ELF file)   +--------------------+--
                               \  |                    |  \
    0x1376d870                  --+--------------------+   |
                                  |    relocs table    |   |
    0x13c1c2a8                    +--------------------+   .bss and .brk
                                  |                    |   |
    0x13ce6000                    +--------------------+   |
                                  |                    |  /
    0x13f77000                    |       initrd       |--
                                  |                    |
    0x13fef374                    +--------------------+

The initrd image will then be overwritten by the memset during early
initialization:

[    1.655204] Unpacking initramfs...
[    1.662831] Initramfs unpacking failed: junk in compressed archive

This patch prevents the above situation by requiring a larger space when looking
for a random kernel base, so that existing logic can effectively avoids the
overlap.

[kees: switched to perl to avoid hex translation pain in mawk vs gawk]
[kees: calculated overlap without relocs table]

Fixes: 82fa9637a2 ("x86, kaslr: Select random position from e820 maps")
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Junjie Mao <eternal.n08@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Matt Fleming <matt.fleming@intel.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1414762838-13067-1-git-send-email-eternal.n08@gmail.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2014-11-01 22:20:50 +01:00
..
.gitignore x86, relocs: Refactor the relocs tool to merge 32- and 64-bit ELF 2013-04-16 16:02:58 -07:00
calc_run_size.pl x86, kaslr: Prevent .bss from overlaping initrd 2014-11-01 22:20:50 +01:00
chkobjdump.awk x86: Fix objdump version check in chkobjdump.awk for different formats. 2009-12-18 09:26:56 -08:00
distill.awk x86: Show symbol name if insn decoder test failed 2009-11-17 07:16:50 +01:00
gen-insn-attr-x86.awk x86, insn: Add new opcodes as of June, 2013 2013-08-06 08:08:47 -07:00
insn_sanity.c arch/x86/tools/insn_sanity.c: Identify source of messages 2013-01-24 15:57:53 +01:00
Makefile x86/build: Supress "Nothing to be done for ..." messages 2014-04-14 11:44:36 +02:00
relocs_32.c x86, relocs: Refactor the relocs tool to merge 32- and 64-bit ELF 2013-04-16 16:02:58 -07:00
relocs_64.c x86, relocs: Refactor the relocs tool to merge 32- and 64-bit ELF 2013-04-16 16:02:58 -07:00
relocs_common.c x86, relocs: Add manual debug mode 2014-01-22 04:21:45 -08:00
relocs.c x86/relocs: Make per_cpu_load_addr static 2014-09-24 15:17:47 +02:00
relocs.h x86, relocs: Add manual debug mode 2014-01-22 04:21:45 -08:00
test_get_len.c x86: Remove trailing spaces in messages 2010-02-07 17:47:51 +01:00