Skip to content

underhill_mem: reject oversized page numbers and test memory access - #5235

Open
Sunil Muthuswamy (sunilmut) wants to merge 1 commit into
microsoft:mainfrom
sunilmut:user/sunilmut/malformed-gpn-repro
Open

Sunil Muthuswamy (sunilmut) wants to merge 1 commit into
microsoft:mainfrom
sunilmut:user/sunilmut/malformed-gpn-repro

Conversation

@sunilmut

@sunilmut Sunil Muthuswamy (sunilmut) commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

The guest-RAM check converted a guest page number to an address with
gpn << 12, which discards high bits. An oversized GPN such as
(1 << 52) | 4 was accepted as page 4, while later bitmap indexing used the
original GPN, leading to a panic in the visibility bitmap.

This change converts with checked_mul(HV_PAGE_SIZE) and rejects GPNs whose
address does not fit. Valid GPNs behave as before. The private RAM check now
takes the MemoryLayout instead of &self so it can be unit tested; its five
callers pass their existing layout.

Test changes:

  • Oversized GPNs are rejected (failed before the fix).
  • Memory-access behavior tests: read/write permission enforcement,
    kernel/user instruction-read views, shared/private mapping errors that leave
    data unchanged, registration-failure isolation, and concurrent overlapping
    registration without duplicate work.

@sunilmut
Sunil Muthuswamy (sunilmut) requested a review from a team as a code owner November 23, 2026 00:34
Copilot AI balanced review requested due to automatic review settings November 23, 2026 00:34
@github-actions github-actions Bot added the unsafe Related to unsafe code label Nov 23, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Guest-controlled GPN validation affects OpenHCL’s VTL0 memory-isolation boundary, warranting human security review because end-to-end hypercall rejection was not runtime-validated.

No open issues 🎉

What changed in this PR

This PR hardens OpenHCL’s guest-memory validation by rejecting page numbers whose byte addresses overflow, preventing them from aliasing valid RAM and causing visibility-bitmap panics.

Changes:

  • Use checked page-to-address conversion and make the RAM check independently testable.
  • Add regression and behavior tests for overflow, memory permissions, execute views, and shared/private visibility.
  • Test registration-failure isolation and concurrent overlapping registration; enable tracing in unit tests.
File Description
openhcl/​underhill_mem/​src/​registrar.rs Adds failure-isolation and concurrent-registration tests.
openhcl/​underhill_mem/​src/​mapping.rs Adds permission, execute-view, and visibility tests.
openhcl/​underhill_mem/​src/​lib.rs Rejects overflowing page numbers, updates callers, and adds regression coverage.
openhcl/​underhill_mem/​Cargo.toml Adds the tracing-enabled test dependency.
Cargo.lock Records the added test dependency.

Review effort: Balanced

Reject oversized guest page numbers before checking guest RAM.

Test changes:
- Verify oversized page numbers are rejected.
- Check read/write permissions and kernel/user instruction-read access.
- Verify shared/private mapping errors leave memory unchanged.
- Ensure registration failures do not block unrelated RAM.
- Check overlapping registration requests succeed without duplicates.
@sunilmut
Sunil Muthuswamy (sunilmut) force-pushed the user/sunilmut/malformed-gpn-repro branch from 374749c to d0f073f Compare November 26, 2026 22:33
Copilot AI balanced review requested due to automatic review settings November 26, 2026 22:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the guest-memory validation hardening change.

No open issues 🎉

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants