Skip to content

uefi: Improve handling of null-address allocations in allocate_pages #1558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

nicholasbishop
Copy link
Member

The firmware is allowed to return an allocation at address zero. This is not compatible with Rust, since it's UB to write through a null pointer. If a null address is returned, retry the allocation. If that second allocation still fails, return an error rather than panicking.

Fixes #1557

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

The firmware is allowed to return an allocation at address zero. This is not
compatible with Rust, since it's UB to write through a null pointer. If a null
address is returned, retry the allocation. If that second allocation still
fails, return an error rather than panicking.
@kukrimate
Copy link

kukrimate commented Mar 2, 2025

This seem to match the logic used by GRUB2's AllocatePages wrapper, which has been deployed since the inception of UEFI, so it is probably correct.

Copy link
Member

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice!

@phip1611 phip1611 added this pull request to the merge queue Mar 2, 2025
Merged via the queue into rust-osdev:main with commit f4673cf Mar 2, 2025
16 checks passed
@nicholasbishop nicholasbishop deleted the bishop-handle-null-page-alloc branch March 2, 2025 21:59
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.

(Possible) panic from BootServices->AllocatePages() returning the zero address
3 participants