Cleanup ELF loading and handle non page-aligned section ends corretly#1155
Draft
joergroedel wants to merge 14 commits into
Draft
Cleanup ELF loading and handle non page-aligned section ends corretly#1155joergroedel wants to merge 14 commits into
joergroedel wants to merge 14 commits into
Conversation
Initialize the kernel-stack of a new user-mode task using one structure and initialize it in one place. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Initialize the stack of a new kernel task from a single structure to make it more similar to user-task stack initialization. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Check at compile time whether the stack-frame after ret_addr is 16b-aligned. Also consolidate the check for kernel and user tasks. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
The initialization routines for user- and kernel-tasks basically do the same thing, except that they use different context structures for each case. Consolidate the common parts in allocate_stack_common() and make that function generic. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
User-tasks use a different launch path than kernel-tasks. Kernel-tasks go directly to a Rust function on the `ret` in `switch_context` while for user-tasks the `ret`-target is an assembly function which calls the `setup_user_task()` helper and then goes into the `iret` path. This causes some fraction in how the initial stack layouts of both task types are set up, so consolidate this to be more similar in both cases. Kernel- and User thread now use a common thread entry in assembly code, which unifies the initial thread setup. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
When loading a user ELF binary for execution the COCONUT kernel created a new Task object and mapped the ELF sections into the new tasks user-VMR. This all happened from the context of the old task. This behavior is problematic as it creates unnecessary complexity for cases when the kernel needs to write values into the user address space. Fix this behavior by moving the actual ELF loading into the context of the new task. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Make the shadow stack initialization more readable by introducing an initializer struct with push semantics. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
The label must point at the potentially faulting RIP in order for the exception to be handled correctly. Fix the label in copy_bytes(). Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
The page-fault handler did not handle faults to the user memory region correctly when they were coming from kernel code. Rewrite the handler to implement the right behavior. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Some structs in the ELF parser code miss the Copy + Clone annotations, so add them. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Provide a function to safely zero user-space memory from kernel mode. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Re-work the ELF loader code and make it more spec compliant. Also make sure to zero any remaining page-memory when a writable segment does not end at a page boundary. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Now that the kernel ELF loader can handle unaligned segments correctly there is no need anymore for a custom linker script for user-mode binaries. Fixes: coconut-svsm#483 Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
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.
This cleans up the ELF loading code for user-mode binaries and adds handling for non page-aligned section-ends. When a writable section does not end at a page boundary, the rest of the page is zeroed out.
With these changes the user-mode binaries do no longer need a custom linker script which enforces the alignment. So this is removed as well.
These changes depend on #1152 and #1153.
Fixes: #483