Skip to content

(Possible) panic from BootServices->AllocatePages() returning the zero address #1557

Closed
@kukrimate

Description

@kukrimate

The out parameter of BootServices->AllocatePages() is an EFI_PHYSICAL_ADDRESS, not a pointer.

The uefi-rs wrapper boot::allocate_pages() converts this into a NonNull<u8> and panics if that fails.

However there is nothing in the standard that says physical address 0 is not a valid result, and X86 has a tendency of mapping physical memory at address 0. This can cause valid programs to panic on allocation.

Most UEFI implementations allocate from top-down, so this only really happens in practice just before running out memory, but there is nothing in the spec that says they need to. Code assuming AllocatePages() always returns non-0 addresses can panic on random allocations.

Some other UEFI apps (e.g. GRUB) do have checks to retry allocation if address 0 was yielded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions