Re: [PATCH v6 00/12] implement KASLR for powerpc/fsl_booke/32
From: Michael Ellerman
Date: Mon Aug 26 2019 - 21:33:59 EST
Jason Yan <yanaijie@xxxxxxxxxx> writes:
> A polite ping :)
>
> What else should I do now?
That's a good question.
Scott, are you still maintaining FSL bits, and if so any comments? Or
should I take this.
cheers
> On 2019/8/19 14:12, Jason Yan wrote:
>> Hi Michael,
>>
>> Is there anything more I should do to get this feature meeting the
>> requirements of the mainline?
>>
>> Thanks,
>> Jason
>>
>> On 2019/8/9 18:07, Jason Yan wrote:
>>> This series implements KASLR for powerpc/fsl_booke/32, as a security
>>> feature that deters exploit attempts relying on knowledge of the location
>>> of kernel internals.
>>>
>>> Since CONFIG_RELOCATABLE has already supported, what we need to do is
>>> map or copy kernel to a proper place and relocate. Freescale Book-E
>>> parts expect lowmem to be mapped by fixed TLB entries(TLB1). The TLB1
>>> entries are not suitable to map the kernel directly in a randomized
>>> region, so we chose to copy the kernel to a proper place and restart to
>>> relocate.
>>>
>>> Entropy is derived from the banner and timer base, 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.
>>>
>>> ÂÂÂÂ KERNELBASE
>>>
>>> ÂÂÂÂÂÂÂÂ |-->ÂÂ 64MÂÂ <--|
>>> ÂÂÂÂÂÂÂÂ |ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |
>>> ÂÂÂÂÂÂÂÂ +---------------+ÂÂÂ +----------------+---------------+
>>> ÂÂÂÂÂÂÂÂ |ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |....|ÂÂÂ |kernel|ÂÂÂ |ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |
>>> ÂÂÂÂÂÂÂÂ +---------------+ÂÂÂ +----------------+---------------+
>>> ÂÂÂÂÂÂÂÂ |ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |
>>> ÂÂÂÂÂÂÂÂ |----->ÂÂ offsetÂÂÂ <-----|
>>>
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ kernstart_virt_addr
>>>
>>> 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.
>>>
>>> Changes since v5:
>>> Â - Rename M_IF_NEEDED to MAS2_M_IF_NEEDED
>>> Â - Define some global variable as __ro_after_init
>>> Â - Replace kimage_vaddr with kernstart_virt_addr
>>> Â - Depend on RELOCATABLE, not select it
>>> Â - Modify the comment block below the SPDX tag
>>> Â - Remove some useless headers in kaslr_booke.c and move is_second_reloc
>>> ÂÂÂ declarationto mmu_decl.h
>>> Â - Remove DBG() and use pr_debug() and rewrite comment above
>>> get_boot_seed().
>>> Â - Add a patch to document the KASLR implementation.
>>> Â - Split a patch from patch #10 which exports kaslr offset in
>>> VMCOREINFO ELF notes.
>>> Â - Remove extra logic around finding nokaslr string in cmdline.
>>> Â - Make regions static global and __initdata
>>>
>>> Changes since v4:
>>> Â - Add Reviewed-by tag from Christophe
>>> Â - Remove an unnecessary cast
>>> Â - Remove unnecessary parenthesis
>>> Â - Fix checkpatch warning
>>>
>>> Changes since v3:
>>> Â - Add Reviewed-by and Tested-by tag from Diana
>>> Â - Change the comment in fsl_booke_entry_mapping.S to be consistent
>>> ÂÂÂ with the new code.
>>>
>>> Changes since v2:
>>> Â - Remove unnecessary #ifdef
>>> Â - Use SZ_64M instead of0x4000000
>>> Â - Call early_init_dt_scan_chosen() to init boot_command_line
>>> Â - Rename kaslr_second_init() to kaslr_late_init()
>>>
>>> Changes since v1:
>>> Â - Remove some useless 'extern' keyword.
>>> Â - Replace EXPORT_SYMBOL with EXPORT_SYMBOL_GPL
>>> Â - Improve some assembly code
>>> Â - Use memzero_explicit instead of memset
>>> Â - Use boot_command_line and remove early_command_line
>>> Â - Do not print kaslr offset if kaslr is disabled
>>>
>>> Jason Yan (12):
>>> ÂÂ powerpc: unify definition of M_IF_NEEDED
>>> ÂÂ powerpc: move memstart_addr and kernstart_addr to init-common.c
>>> ÂÂ powerpc: introduce kernstart_virt_addr to store the kernel base
>>> ÂÂ powerpc/fsl_booke/32: introduce create_tlb_entry() helper
>>> ÂÂ powerpc/fsl_booke/32: introduce reloc_kernel_entry() helper
>>> ÂÂ powerpc/fsl_booke/32: implement KASLR infrastructure
>>> ÂÂ powerpc/fsl_booke/32: randomize the kernel image offset
>>> ÂÂ powerpc/fsl_booke/kaslr: clear the original kernel if randomized
>>> ÂÂ powerpc/fsl_booke/kaslr: support nokaslr cmdline parameter
>>> ÂÂ powerpc/fsl_booke/kaslr: dump out kernel offset information on panic
>>> ÂÂ powerpc/fsl_booke/kaslr: export offset in VMCOREINFO ELF notes
>>> ÂÂ powerpc/fsl_booke/32: Document KASLR implementation
>>>
>>> Â Documentation/powerpc/kaslr-booke32.rstÂÂÂÂÂÂ |Â 42 ++
>>> Â arch/powerpc/KconfigÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |Â 11 +
>>>  arch/powerpc/include/asm/nohash/mmu-book3e.h | 10 +
>>> Â arch/powerpc/include/asm/page.hÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |ÂÂ 7 +
>>> Â arch/powerpc/kernel/MakefileÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |ÂÂ 1 +
>>> Â arch/powerpc/kernel/early_32.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |ÂÂ 2 +-
>>> Â arch/powerpc/kernel/exceptions-64e.SÂÂÂÂÂÂÂÂÂ |Â 12 +-
>>> Â arch/powerpc/kernel/fsl_booke_entry_mapping.S |Â 27 +-
>>> Â arch/powerpc/kernel/head_fsl_booke.SÂÂÂÂÂÂÂÂÂ |Â 55 ++-
>>> Â arch/powerpc/kernel/kaslr_booke.cÂÂÂÂÂÂÂÂÂÂÂÂ | 393 ++++++++++++++++++
>>> Â arch/powerpc/kernel/machine_kexec.cÂÂÂÂÂÂÂÂÂÂ |ÂÂ 1 +
>>> Â arch/powerpc/kernel/misc_64.SÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |ÂÂ 7 +-
>>> Â arch/powerpc/kernel/setup-common.cÂÂÂÂÂÂÂÂÂÂÂ |Â 20 +
>>> Â arch/powerpc/mm/init-common.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |ÂÂ 7 +
>>> Â arch/powerpc/mm/init_32.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |ÂÂ 5 -
>>> Â arch/powerpc/mm/init_64.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |ÂÂ 5 -
>>> Â arch/powerpc/mm/mmu_decl.hÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |Â 11 +
>>> Â arch/powerpc/mm/nohash/fsl_booke.cÂÂÂÂÂÂÂÂÂÂÂ |ÂÂ 8 +-
>>> Â 18 files changed, 572 insertions(+), 52 deletions(-)
>>> Â create mode 100644 Documentation/powerpc/kaslr-booke32.rst
>>> Â create mode 100644 arch/powerpc/kernel/kaslr_booke.c
>>>