Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Enhanced Functionality with Optimized EPT, Boot-time Hooks, and Preliminary Hyper-V Support (Experimental) #19

Merged
merged 172 commits into from
May 2, 2024

Conversation

memN0ps
Copy link
Owner

@memN0ps memN0ps commented May 2, 2024

This pull request introduces a series of enhancements and refinements to the UEFI Rust hypervisor, aimed at improving functionality and stability across various components:

  • EPT Management: Transitioned from using separate primary and secondary EPTs (Extended Page Tables) for all threads to a single primary EPT per thread, optimizing memory management.
  • Runtime CPUID Hooks: Implemented hooks in the CPUID instruction at runtime, currently marked as unstable. These hooks are managed through EPT violations and are installed on a shadow copy page via vmcall. While CPUID, INT3, and other instructions could potentially employ similar hooks with minor modifications, MTF (Monitor Trap Flag) is utilized to restore hooks and execute the overwritten bytes. Future updates aim to enhance support for runtime hooks via a CPUID backdoor. Initial attempts to utilize a guest agent for executing kernel code upon EPT violations were set aside in favor of maintaining obfuscation through EPT, minimizing guest exposure.
  • Hook Stability and Overhead: Currently, hooks are unstable and subject to extensive testing before they can be deemed stable for public release. The implementation involves hooks during system boot and includes SSDT hooks, but is anticipated to cause multiple VM exits, though the overhead should not significantly impact performance.
  • Memory Management for Hooks: Accessing the Guest Physical Address (PA) now requires traversing the page tables, a crucial step for effective hook implementation.
  • Build System and Continuous Integration:
    • Adopted cargo-make for project builds, utilizing a Makefile.toml configuration.
    • Updated GitHub workflow YAML files to integrate cargo make.
  • Documentation and Configuration Updates:
    • Revised README.md to reflect the latest changes.
    • Updated workspace settings in config.toml.
  • Debugging Features: Introduced features to selectively enable or disable support for Hyper-V Type 2, primarily for debugging purposes. This update continues to inject #GP faults for invalid or reserved MSR accesses.
  • MSR Hooks: Added functionality to hook the LSTAR register at runtime, allowing for dynamic retrieval and restoration of the ntoskrnl base address.
  • Code Formatting: Updated the project to conform to a modified cargo fmt style.
  • Structural Changes: Implemented various structural changes and refactorings to enhance code organization and maintainability.
  • Dependency Updates: Updated the UEFI crate and other dependent crates to newer versions.
  • Boot Loader Addition: Integrated a new loader to facilitate system startup.

Note: This is partial support for #10 and #18.

These changes lay the groundwork for more robust and flexible hypervisor capabilities, aiming for increased stability and performance in virtualized environments. Further testing and validation are required to ensure that these enhancements meet the necessary standards for reliability and security.

Acknowledgments: Special thanks to Daax's, Satoshi Tanda, Jessiep, and Drew for their contributions and support in this update.

memN0ps added 30 commits March 20, 2024 16:17
At this point `original_lstar` should not be 0 at all because `MsrAccessType::Write` on msr::IA32_LSTAR stores it in there.
Will edit this to go somewhere else later and do a refactor. vmread is called each time, only need to do once. Need to make more memory safe is possible.
The ntoskrnl.exe base address is retrieved via vmexit so it requires hooks to be called from there.
- Might have to use vmcalls/hypercalls to perform these hooks using an interface as doing at run-time is dirty.
@memN0ps memN0ps merged commit af3928f into main May 2, 2024
1 check passed
@memN0ps memN0ps deleted the development branch May 3, 2024 23:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant