• Kees Cook's avatar
    x86, kaslr: randomize module base load address · e2b32e67
    Kees Cook authored
    Randomize the load address of modules in the kernel to make kASLR
    effective for modules.  Modules can only be loaded within a particular
    range of virtual address space.  This patch adds 10 bits of entropy to
    the load address by adding 1-1024 * PAGE_SIZE to the beginning range
    where modules are loaded.
    
    The single base offset was chosen because randomizing each module
    load ends up wasting/fragmenting memory too much. Prior approaches to
    minimizing fragmentation while doing randomization tend to result in
    worse entropy than just doing a single base address offset.
    
    Example kASLR boot without this change, with a single module loaded:
    ---[ Modules ]---
    0xffffffffc0000000-0xffffffffc0001000           4K     ro     GLB x  pte
    0xffffffffc0001000-0xffffffffc0002000           4K     ro     GLB NX pte
    0xffffffffc0002000-0xffffffffc0004000           8K     RW     GLB NX pte
    0xffffffffc0004000-0xffffffffc0200000        2032K                   pte
    0xffffffffc0200000-0xffffffffff000000        1006M                   pmd
    ---[ End Modules ]---
    
    Example kASLR boot after this change, same module loaded:
    ---[ Modules ]---
    0xffffffffc0000000-0xffffffffc0200000           2M                   pmd
    0xffffffffc0200000-0xffffffffc03bf000        1788K                   pte
    0xffffffffc03bf000-0xffffffffc03c0000           4K     ro     GLB x  pte
    0xffffffffc03c0000-0xffffffffc03c1000           4K     ro     GLB NX pte
    0xffffffffc03c1000-0xffffffffc03c3000           8K     RW     GLB NX pte
    0xffffffffc03c3000-0xffffffffc0400000         244K                   pte
    0xffffffffc0400000-0xffffffffff000000        1004M                   pmd
    ---[ End Modules ]---
    Signed-off-by: default avatarAndy Honig <ahonig@google.com>
    Link: http://lkml.kernel.org/r/20140226005916.GA27083@www.outflux.netSigned-off-by: default avatarKees Cook <keescook@chromium.org>
    Signed-off-by: default avatarH. Peter Anvin <hpa@linux.intel.com>
    e2b32e67
module.c 6.37 KB