mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] riscv: Introduce KASLR
@ 2023-02-15 14:51 Alexandre Ghiti
  2023-02-15 14:51 ` [PATCH 1/4] riscv: Introduce virtual kernel mapping KASLR Alexandre Ghiti
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Alexandre Ghiti @ 2023-02-15 14:51 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Ard Biesheuvel,
	linux-riscv, linux-kernel, linux-efi
  Cc: Alexandre Ghiti

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.

Note that the patch "riscv: Use PUD/P4D/PGD pages for the linear
mapping" is necessary to retrieve the memory below the physical kernel
address, so that the EFI stub does not have to try to relocate the kernel
as close as possible to the start of dram.

This patchset is rebased on top of:

Introduce 64b relocatable kernel (https://lore.kernel.org/lkml/20230215143626.453491-1-alexghiti@rivosinc.com/)
RISC-V kasan rework (https://lore.kernel.org/lkml/Y6TTvku%2FyuSjm42j@spud/T/)
riscv: Use PUD/P4D/PGD pages for the linear mapping (https://lore.kernel.org/lkml/20230125114229.hrhsyw4aegrnmoau@orel/T/)
riscv: Allow to downgrade paging mode from the command line (https://lore.kernel.org/lkml/CAHVXubjeSMvfTPnvrnYRupOGx6+vUvUGfRS3piTeo=TH2cHKNg@mail.gmail.com/)
base-commit-tag: v6.2-rc7

This patchset was tested with u-boot boottime service for the seed on:
- ubuntu defconfig + kasan outline (sv39, sv48, sv57): OK
- ubuntu defconfig + kasan inline (sv39, sv48, sv57): OK
- ubuntu defconfg (sv39, sv48, sv57): OK

Alexandre Ghiti (4):
  riscv: Introduce virtual kernel mapping KASLR
  riscv: Dump out kernel offset information on panic
  arm64: libstub: Move KASLR handling functions to efi-stub-helper.c
  riscv: libstub: Implement KASLR by using generic functions

 arch/riscv/Kconfig                            |  18 +++
 arch/riscv/include/asm/page.h                 |   1 +
 arch/riscv/kernel/pi/Makefile                 |   2 +-
 arch/riscv/kernel/pi/cmdline_early.c          |  12 ++
 arch/riscv/kernel/pi/fdt_early.c              |  23 +++
 arch/riscv/kernel/setup.c                     |  25 +++
 arch/riscv/mm/init.c                          |  31 +++-
 drivers/firmware/efi/libstub/arm64-stub.c     | 110 +------------
 .../firmware/efi/libstub/efi-stub-helper.c    | 147 ++++++++++++++++++
 drivers/firmware/efi/libstub/efistub.h        |   8 +
 drivers/firmware/efi/libstub/riscv-stub.c     |  27 ++--
 11 files changed, 281 insertions(+), 123 deletions(-)
 create mode 100644 arch/riscv/kernel/pi/fdt_early.c

--
2.37.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-02-21 15:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-15 14:51 [PATCH 0/4] riscv: Introduce KASLR Alexandre Ghiti
2023-02-15 14:51 ` [PATCH 1/4] riscv: Introduce virtual kernel mapping KASLR Alexandre Ghiti
2023-02-15 14:51 ` [PATCH 2/4] riscv: Dump out kernel offset information on panic Alexandre Ghiti
2023-02-15 14:51 ` [PATCH 3/4] arm64: libstub: Move KASLR handling functions to efi-stub-helper.c Alexandre Ghiti
2023-02-15 14:51 ` [PATCH 4/4] riscv: libstub: Implement KASLR by using generic functions Alexandre Ghiti
2023-02-21 15:50 ` [PATCH 0/4] riscv: Introduce KASLR Björn Töpel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®