Unverified Commit f5780555 authored by Palmer Dabbelt's avatar Palmer Dabbelt
Browse files

Merge patch series "riscv: Introduce KASLR"

Alexandre Ghiti <alexghiti@rivosinc.com> says:

The following KASLR implementation allows to randomize the kernel mapping:

- virtually: we expect the bootloader to provide a seed in the device-tree
- physically: only implemented in the EFI stub, it relies on the firmware to
  provide a seed using EFI_RNG_PROTOCOL. arm64 has a similar implementation
  hence the patch 3 factorizes KASLR related functions for riscv to take
  advantage.

The new virtual kernel location is limited by the early page table that only
has one PUD and with the PMD alignment constraint, the kernel can only take
< 512 positions.

* b4-shazam-merge:
  riscv: libstub: Implement KASLR by using generic functions
  libstub: Fix compilation warning for rv32
  arm64: libstub: Move KASLR handling functions to kaslr.c
  riscv: Dump out kernel offset information on panic
  riscv: Introduce virtual kernel mapping KASLR

Link: https://lore.kernel.org/r/20230722123850.634544-1-alexghiti@rivosinc.com


Signed-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
parents f0936363 b7ac4b8e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -156,4 +156,6 @@ static inline void efi_capsule_flush_cache_range(void *addr, int size)

efi_status_t efi_handle_corrupted_x18(efi_status_t s, const char *f);

void efi_icache_sync(unsigned long start, unsigned long end);

#endif /* _ASM_EFI_H */
+19 −0
Original line number Diff line number Diff line
@@ -720,6 +720,25 @@ config RELOCATABLE

          If unsure, say N.

config RANDOMIZE_BASE
        bool "Randomize the address of the kernel image"
        select RELOCATABLE
        depends on MMU && 64BIT && !XIP_KERNEL
        help
          Randomizes the virtual address at which the kernel image is
          loaded, as a security feature that deters exploit attempts
          relying on knowledge of the location of kernel internals.

          It is the bootloader's job to provide entropy, by passing a
          random u64 value in /chosen/kaslr-seed at kernel entry.

          When booting via the UEFI stub, it will invoke the firmware's
          EFI_RNG_PROTOCOL implementation (if available) to supply entropy
          to the kernel proper. In addition, it will randomise the physical
          location of the kernel Image as well.

          If unsure, say N.

endmenu # "Kernel features"

menu "Boot options"
+2 −0
Original line number Diff line number Diff line
@@ -45,4 +45,6 @@ void arch_efi_call_virt_teardown(void);

unsigned long stext_offset(void);

void efi_icache_sync(unsigned long start, unsigned long end);

#endif /* _ASM_EFI_H */
+3 −0
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ typedef struct page *pgtable_t;
struct kernel_mapping {
	unsigned long page_offset;
	unsigned long virt_addr;
	unsigned long virt_offset;
	uintptr_t phys_addr;
	uintptr_t size;
	/* Offset between linear mapping virtual address and kernel load address */
@@ -185,6 +186,8 @@ extern phys_addr_t __phys_addr_symbol(unsigned long x);

#define sym_to_pfn(x)           __phys_to_pfn(__pa_symbol(x))

unsigned long kaslr_offset(void);

#endif /* __ASSEMBLY__ */

#define virt_addr_valid(vaddr)	({						\
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ __efistub__start = _start;
__efistub__start_kernel		= _start_kernel;
__efistub__end			= _end;
__efistub__edata		= _edata;
__efistub___init_text_end	= __init_text_end;
__efistub_screen_info		= screen_info;

#endif
Loading