• Jason Yan's avatar
    powerpc/fsl_booke/32: randomize the kernel image offset · 6a38ea1d
    Jason Yan authored
    After we have the basic support of relocate the kernel in some
    appropriate place, we can start to randomize the offset now.
    
    Entropy is derived from the banner and timer, which will change every
    build and boot. This not so much safe so additionally the bootloader may
    pass entropy via the /chosen/kaslr-seed node in device tree.
    
    We will use the first 512M of the low memory to randomize the kernel
    image. The memory will be split in 64M zones. We will use the lower 8
    bit of the entropy to decide the index of the 64M zone. Then we chose a
    16K aligned offset inside the 64M zone to put the kernel in.
    
    We also check if we will overlap with some areas like the dtb area, the
    initrd area or the crashkernel area. If we cannot find a proper area,
    kaslr will be disabled and boot from the original kernel.
    
    Some pieces of code are derived from arch/x86/boot/compressed/kaslr.c or
    arch/arm64/kernel/kaslr.c such as rotate_xor(). Credit goes to Kees and
    Ard.
    Signed-off-by: default avatarJason Yan <yanaijie@huawei.com>
    Reviewed-by: default avatarDiana Craciun <diana.craciun@nxp.com>
    Tested-by: default avatarDiana Craciun <diana.craciun@nxp.com>
    Reviewed-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
    Signed-off-by: default avatarScott Wood <oss@buserror.net>
    Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
    6a38ea1d
kaslr_booke.c 9.35 KB