diff --git a/docs/re.md b/docs/re.md index 1fae61c466fa8f7e8de08bd7367cf0d1beb267c0..0ef0a6ecfb5c6d1a2d14e895f311c6ef51843fe8 100644 --- a/docs/re.md +++ b/docs/re.md @@ -135,6 +135,26 @@ able to write to this MSR using __wrmsr. What's interesting about this is that the tutorial tries to modify this MSR but if we assume that the **lock bit is set** that branch **will be a no-op**. +```c +static bool ia32_feature_control_flags(void) { + int msr_value = __rdmsr(IA32_FEATURE_CONTROL_MSR); + + if (!(msr_value & IA32_FEATURE_CONTROL_LOCK_BIT)) { + printk(KERN_INFO "Writing to the IA32_FEATURE_CONTROL MSR\n"); + __wrmsr(IA32_FEATURE_CONTROL_MSR, + IA32_FEATURE_CONTROL_LOCK_BIT | + IA32_FEATURE_CONTROL_VMXON_OUTSIDE_SMX, + 0); + } + + if (!(msr_value & IA32_FEATURE_CONTROL_VMXON_OUTSIDE_SMX)) { + printk(KERN_INFO "Virtualization isn't available\n"); + return false; + } + + return true; +} +``` ## References