Skip to content

[REBASE & FF] [feature/supv] Fix Ring 3 stack indexing, sizing, and user mapping - #1768

Open
vineelko wants to merge 3 commits into
OpenDevicePartnership:feature/supvfrom
vineelko:users/vineelko/nvl_validation_fixes_0903
Open

[REBASE & FF] [feature/supv] Fix Ring 3 stack indexing, sizing, and user mapping#1768
vineelko wants to merge 3 commits into
OpenDevicePartnership:feature/supvfrom
vineelko:users/vineelko/nvl_validation_fixes_0903

Conversation

@vineelko

@vineelko vineelko commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Description

  • Pass the dense CPU index into the runtime request path: enter_runtime
    received the APIC ID and forwarded it to bsp_request_loop as a CPU index.
    On platforms whose APIC IDs are not 0..N-1 (observed: 0, 2, 4 … 46, BSP =
    16) this selected a Ring 3 stack outside the array the MM IPL provisioned, so
    the demoted routine faulted writing to a supervisor-owned page. The dense
    index the C core hands to entry_point is now used for the request path,
    while the APIC ID is still used for the CpuManager APIs keyed by it.

  • Size the syscall interface from the MP Information HOB CPU count:
    SyscallInterface::init was given the MAX_CPUS const generic capacity (32)
    rather than the number of CPUs the IPL provisioned stacks for (16), so
    get_cpl3_stack returned pointers past the end of that array, into
    supervisor memory, for any index in between. The MP Information HOB is now
    parsed before the PassDown HOB and its count is passed in, so out of range
    indices are rejected with InvalidCpuIndex.

  • Map the Ring 3 stacks user-accessible during BSP init: the supervisor
    relied on the MM IPL to leave the per-CPU CPL3 stacks user-accessible. The
    provisioned range is now mapped read/write, non-executable and
    user-accessible during BSP init, after confirming it lies inside MMRAM so
    nothing outside MMRAM is exposed to Ring 3, and every page is verified
    afterwards so a misconfiguration fails at init instead of at the first
    demotion.

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

  • Validated on internal hardware platform.

Integration Instructions

N/A

enter_runtime received the APIC ID and forwarded it to bsp_request_loop
as a CPU index. On platforms whose APIC IDs are not 0..N-1 (e.g. 16,
18, 24, ...) this selected a Ring 3 stack outside the array the MM IPL
provisioned, so the demoted routine faulted on its first push. Take the
dense index the C core hands to entry_point and use it for the request
path, keeping the APIC ID for the CpuManager APIs keyed by it.
… CPU count

SyscallInterface::init was given the MAX_CPUS const generic capacity
instead of the number of CPUs the MM IPL provisioned Ring 3 stacks for,
so get_cpl3_stack happily returned stack pointers past the end of that
array (supervisor memory) for any index between the real count and
MAX_CPUS. Parse the MP Information HOB before the PassDown HOB and pass
its CPU count in, so out-of-range indices are rejected.
The supervisor relied on the MM IPL to leave the per-CPU CPL3 stacks
user-accessible; where that does not hold, the first push made by a
demoted routine takes a page fault on a supervisor-owned page. Map the
provisioned range read/write, non-executable and user-accessible during
BSP init, after checking it lies inside MMRAM so nothing outside MMRAM
is exposed to Ring 3, and verify every page afterwards so a
misconfiguration fails at init rather than at the first demotion.
@vineelko
vineelko requested a review from kuqin12 September 5, 2026 03:03
@patina-automation

patina-automation Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

✅ QEMU Validation Passed

All QEMU validation jobs completed successfully.

Note: Q35 is only built on Windows hosts (QEMU boot is disabled due to a QEMU vfat issue).

Workflow run: https://github.com/OpenDevicePartnership/patina/actions/runs/33941375991

Boot Time to EFI Shell

Platform Elapsed
ArmVirt (Linux Host) 25.6s
Q35 (Linux Host) 29.0s

Dependencies

Repository Ref
patina 983f4dc
patina-dxe-core-qemu f636dd8
patina-fw-patcher c28ab7d
patina-qemu firmware v4.0.5
patina-qemu build script a8b6551

This comment was automatically generated by the Patina QEMU PR Validation Post workflow.

@github-actions github-actions Bot added impact:security Has a security impact impact:testing Affects testing labels Sep 5, 2026
@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 14.28571% with 36 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
patina_mm_supervisor/src/init.rs 0.00% 33 Missing ⚠️
patina_mm_supervisor/src/runtime.rs 0.00% 2 Missing ⚠️
patina_mm_supervisor/src/lib.rs 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

Labels

impact:security Has a security impact impact:testing Affects testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant