linux/arch
Junjie Mao 57c340a8ca x86, kaslr: Prevent .bss from overlaping initrd
commit e6023367d7 upstream.

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>
Link: http://lkml.kernel.org/r/1414762838-13067-1-git-send-email-eternal.n08@gmail.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-11-21 09:23:04 -08:00
..
alpha alpha: fix broken network checksum 2014-01-31 09:21:55 -08:00
arc ARC: Disable caches in early boot if so configured 2014-11-14 08:59:56 -08:00
arm ARM: 8191/1: decompressor: ensure I-side picks up relocated code 2014-11-21 09:23:02 -08:00
arm64 Correct the race condition in aarch64_insn_patch_text_sync() 2014-11-21 09:23:02 -08:00
avr32 avr32: add generic vga.h to Kbuild 2014-02-17 11:24:48 +01:00
blackfin Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media 2014-01-31 09:31:14 -08:00
c6x Build fix for c6x 2014-03-07 09:52:46 -08:00
cris cris: convert ffs from an object-like macro to a function-like macro 2014-03-10 17:26:21 -07:00
frv Merge branch 'kbuild' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild 2014-01-30 16:58:05 -08:00
hexagon Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2014-01-25 11:17:34 -08:00
ia64 hugetlb: restrict hugepage_migration_support() to x86_64 2014-06-30 20:11:53 -07:00
m32r Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2014-01-25 11:17:34 -08:00
m68k m68k: Disable/restore interrupts in hwreg_present()/hwreg_write() 2014-10-30 09:38:21 -07:00
metag parisc,metag: Do not hardcode maximum userspace stack size 2014-07-17 16:21:03 -07:00
microblaze microblaze: Fix a typo when disabling stack protection 2014-02-10 07:44:11 +01:00
mips MIPS: tlbex: Properly fix HUGE TLB Refill exception handler 2014-11-14 08:59:57 -08:00
mn10300 Merge branch 'kbuild' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild 2014-01-30 16:58:05 -08:00
openrisc OpenRISC updates for 3.14 2014-01-30 17:08:41 -08:00
parisc parisc: Use compat layer for msgctl, shmat, shmctl and semtimedop syscalls 2014-11-21 09:23:03 -08:00
powerpc powerpc: use device_online/offline() instead of cpu_up/down() 2014-11-14 09:00:13 -08:00
s390 KVM: s390: unintended fallthrough for external call 2014-10-30 09:38:19 -07:00
score Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media 2014-01-31 09:31:14 -08:00
sh sh: fix sh770x SCIF memory regions 2014-11-14 09:00:07 -08:00
sparc sparc32: Implement xchg and atomic_xchg using ATOMIC_HASH locks 2014-11-21 09:23:00 -08:00
tile hugetlb: restrict hugepage_migration_support() to x86_64 2014-06-30 20:11:53 -07:00
um um: ubd: Fix for processes stuck in D state forever 2014-11-14 08:59:49 -08:00
unicore32 mm: per-thread vma caching 2014-10-09 12:21:29 -07:00
x86 x86, kaslr: Prevent .bss from overlaping initrd 2014-11-21 09:23:04 -08:00
xtensa xtensa: re-wire umount syscall to sys_oldumount 2014-11-21 09:23:01 -08:00
.gitignore
Kconfig stackprotector: Introduce CONFIG_CC_STACKPROTECTOR_STRONG 2013-12-20 09:38:40 +01:00