Skip to content

[Feature Request] ELF loader support for physical/virtual KASLR #5661

@bysui

Description

@bysui

Feature Request

Currently, the x86 kernel is loaded into a fixed physical address and runs at a fixed virtual address. Physical/Virtual KASLR is not available, as it is only handled for bzImage during decompression, missing out on an additional layer of defense against code reuse attacks. KASLR is easily broken by information leaks, but since Firecracker uses short-lived VMs, KASLR might be a desirable feature because the VMs will be frequently re-randomized.

Describe the desired solution

  • Physical KASLR
    kernel_offset argument to loader::elf::Elf::load() effectively does physical KASLR by allowing the kernel to be loaded at an offset from the default at CONFIG_PHYSICAL_START. So we only need to provide a kernel_offset that is aligned to CONFIG_PHYSICAL_ALIGNED.
    For PVH entry, the current code in linux_loader doesn't support physical KASLR. If we provide a kernel_offset, it will choose to use the Linux 64-bit boot protocol. However, in the Linux kernel, physical KASLR for PVH entry has been allowed since commit 47ffe0578aee45fed3a06d5dcff76cdebb303163 which introduced a new PVH ELF note that imposes the relocation range. I can change the handling in linux_loader to adapt to this.

  • Virtual KASLR
    There is no available function in linux_loader for now. However, it is easily to implemented, all we need is the relocation information for kernel. In x86 kernel, there is a vmlinux.relocs file which contains all relocation information needed, so what we need is to read it and perform relocation like handle_relocations() in arch/x86/boot/compressed/misc.c. The only discussion is where to implement it: in Firecracker or linux_loader.

Describe possible alternatives

As for virtual KASLR, I have another possible implementation approach: to do it directly in the kernel when booting from vmlinux, see this patchset, then it doesn't need any changes in VMM, however, I'm not sure if it would be acceptable by the x86 folks.

Additional context

Checks

  • [*] Have you searched the Firecracker Issues database for similar requests?
  • [*] Have you read all the existing relevant Firecracker documentation?
  • [*] Have you read and understood Firecracker's core tenets?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Awaiting authorIndicates that an issue or pull request requires author action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions