[REBASE & FF] [feature/supv] Fix Ring 3 stack indexing, sizing, and user mapping - #1768
Open
vineelko wants to merge 3 commits into
Open
Conversation
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.
Contributor
✅ QEMU Validation PassedAll QEMU validation jobs completed successfully.
Workflow run: https://github.com/OpenDevicePartnership/patina/actions/runs/33941375991 Boot Time to EFI Shell
Dependencies
This comment was automatically generated by the Patina QEMU PR Validation Post workflow. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
enter_runtimereceived the APIC ID and forwarded it to
bsp_request_loopas 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_pointis now used for the request path,while the APIC ID is still used for the
CpuManagerAPIs keyed by it.SyscallInterface::initwas given theMAX_CPUSconst generic capacity (32)rather than the number of CPUs the IPL provisioned stacks for (16), so
get_cpl3_stackreturned pointers past the end of that array, intosupervisor 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.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.
How This Was Tested
Integration Instructions
N/A