Skip to content

multiboot, elf: Support disjoint ELF segments on UEFI - #705

Merged
Mintsuki merged 1 commit into
Limine-Bootloader:trunkfrom
hotline1337:fix/multiboot-multirange-elf
Nov 14, 2026
Merged

Mintsuki merged 1 commit into
Limine-Bootloader:trunkfrom
hotline1337:fix/multiboot-multirange-elf

Conversation

@hotline1337

@hotline1337 hotline1337 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Replaced the single contiguous ELF staging buffer with one buffer per non-empty PT_LOAD segment in common/lib/elf.c.
  • Validated usable memory, 4 GiB limits, and entry point placement per segment in the Multiboot 1 and 2 loaders.
  • Preserved the full image span for Multiboot 2 relocation bounds while checking each segment independently.
  • Added tests for widely separated and overlapping ELF segments.

Background & Problem

Kernels with disjoint ELF segments, such as seL4 with bootstrap headers at 1 MiB and kernel code at 16 MiB, can fail to boot under UEFI via Multiboot 1 or 2 (#704):

  1. Synthetic single range: Limine represented the whole [min_paddr, max_paddr) span as one elsewhere_range, including gaps between loadable segments.
  2. Reserved memory in gaps: check_usable_memory() rejected the entire range if firmware reserved memory in a gap, even when every segment's target was usable.
  3. Staging buffer size: Sparse ELF images required a buffer covering the full span, increasing memory use with the size of the gaps.

Changes

  1. common/lib/elf.c, common/lib/elf.h: Return a staging range for each non-empty PT_LOAD segment. Sort ranges by target address, reject overlapping loadable targets, and check for overlaps between a target and another segment's staging buffer.
  2. common/protos/multiboot1.c: Check each kernel range against the 4 GiB limit and usable memory; validate the entry point and reserve each target range.
  3. common/protos/multiboot2.c: Apply the relocation slide to all kernel ranges. Keep the full image span for relocation bounds, but check usable and loader memory per segment. Validate the 4 GiB limit and entry point, and reserve each target range.
  4. checks/cases/multiboot_elf.py: Add Multiboot 1 and 2 boot cases with a distant header segment, plus hostile ELF cases with overlapping segments.

Verification & Testing

  1. Build:
    • Compiled the BIOS and x86-64 UEFI targets.
  2. Multiboot ELF checks:
    • Ran checks/run-checks -k 'multiboot_elf.*' on BIOS and x86-64 UEFI: 8/8 passed.
    • Covered disjoint-segment boots and hostile ELF inputs for Multiboot 1 and 2.

AI assistance disclosure

The fix was developed by a human, and verified with material AI help (gemini-4-carbon). The commit carries the corresponding Assisted-by: trailer.

Fixes #704

@hotline1337
hotline1337 force-pushed the fix/multiboot-multirange-elf branch 3 times, most recently from 2989078 to 8499a3f Compare November 7, 2026 18:24
@hotline1337 hotline1337 changed the title multiboot: Support disjoint ELF segments on UEFI multiboot, elf: Support disjoint ELF segments on UEFI Nov 7, 2026
@hotline1337
hotline1337 force-pushed the fix/multiboot-multirange-elf branch from 8499a3f to 1f39d86 Compare November 10, 2026 12:46
Assisted-by: Antigravity:gemini-4-carbon
Signed-off-by: hotline1337 <denuvo at tuta dot io>
@hotline1337
hotline1337 force-pushed the fix/multiboot-multirange-elf branch from 1f39d86 to 34011f8 Compare November 10, 2026 13:07
@Mintsuki
Mintsuki merged commit b8450a9 into Limine-Bootloader:trunk Nov 14, 2026
8 checks passed
@hotline1337
hotline1337 deleted the fix/multiboot-multirange-elf branch November 14, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants