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

Commit

Permalink
Using x86_64 crate's Cr4 from x86_64 instead of buggy x86 crate's cr4
Browse files Browse the repository at this point in the history
Using x86_64 crate's cr4 fixes the CRITICAL_PROCESS_DIED bug instead of buggy x86 crate's cr4. Thanks to Matthias :)
  • Loading branch information
memN0ps committed Jan 12, 2024
1 parent a1e3e9b commit a7be8da
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ A lightweight, memory-safe, and blazingly fast Rust-based type-2 research hyperv

- **Robust Isolation Mechanisms**: Custom Global Descriptor Table (GDT), Interrupt Descriptor Table (IDT), and Page Tables will be used for enhanced security. This design decision will prevent potential vulnerabilities from using the host's `ntoskrnl.exe` `CR3` or a usermode process's `CR3`, fortifying the hypervisor against sophisticated attacks. [Further reading on the importance of these structures](https://www.unknowncheats.me/forum/2779560-post4.html).

- **Stability Enhancements**: Addressing the `CRITICAL_PROCESS_DIED (ef)` BSOD issue is a top priority.

## Installation

1. Install Rust from [here](https://www.rust-lang.org/tools/install).
Expand Down
8 changes: 4 additions & 4 deletions hypervisor/src/intel/vmcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! is vital for VMX operations on the CPU. It also offers utility functions for
//! adjusting VMCS entries and displaying VMCS state for debugging purposes.
use x86_64::registers::control::Cr4;
use {
// Internal crate usages
crate::{
Expand Down Expand Up @@ -41,6 +40,7 @@ use {
task,
vmx::vmcs::{self},
},
x86_64::registers::control::Cr4,
};

/// Represents the VMCS region in memory.
Expand Down Expand Up @@ -110,7 +110,7 @@ impl Vmcs {
pub fn setup_guest_registers_state(context: &CONTEXT, guest_descriptor_table: &Box<DescriptorTables, KernelAlloc>, guest_registers: &mut GuestRegisters) {
unsafe { vmwrite(vmcs::guest::CR0, controlregs::cr0().bits() as u64) };
unsafe { vmwrite(vmcs::guest::CR3, controlregs::cr3()) };
unsafe { vmwrite(vmcs::guest::CR4, Cr4::read_raw()) };
vmwrite(vmcs::guest::CR4, Cr4::read_raw());

vmwrite(vmcs::guest::DR7, context.Dr7);

Expand Down Expand Up @@ -222,7 +222,7 @@ impl Vmcs {
let _pml4_pa = host_paging.get_pml4_pa()?;
unsafe { vmwrite(vmcs::host::CR3, crate::utils::nt::NTOSKRNL_CR3) };

unsafe { vmwrite(vmcs::host::CR4, controlregs::cr4().bits() as u64) };
vmwrite(vmcs::host::CR4, Cr4::read_raw());

// The RIP/RSP registers are set within `launch_vm`.

Expand Down Expand Up @@ -280,7 +280,7 @@ impl Vmcs {

unsafe {
vmwrite(vmcs::control::CR0_READ_SHADOW, controlregs::cr0().bits() as u64);
vmwrite(vmcs::control::CR4_READ_SHADOW, controlregs::cr4().bits() as u64);
vmwrite(vmcs::control::CR4_READ_SHADOW, Cr4::read_raw());
};

vmwrite(vmcs::control::MSR_BITMAPS_ADDR_FULL, PhysicalAddress::pa_from_va(msr_bitmap.as_ref() as *const _ as _));
Expand Down

0 comments on commit a7be8da

Please sign in to comment.