Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs on Win10 1903! #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 22 additions & 37 deletions HyperBone.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,45 +104,45 @@
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8.1 Debug|x64'">
<OutDir>$(SolutionDir)\bin\$(Platform)\$(ConfigurationName)\</OutDir>
<OutDir>$(SolutionDir)bin\$(Platform)\$(ConfigurationName)\</OutDir>
<TimeStampServer>http://timestamp.verisign.com/scripts/timstamp.dll</TimeStampServer>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(ConfigurationName)\</IntDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(ConfigurationName)\</IntDir>
<TargetName>$(TargetName)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win10Debug|x64'">
<OutDir>$(SolutionDir)\bin\$(Platform)\$(ConfigurationName)\</OutDir>
<OutDir>$(SolutionDir)bin\$(Platform)\$(ConfigurationName)\</OutDir>
<TimeStampServer>http://timestamp.verisign.com/scripts/timstamp.dll</TimeStampServer>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(ConfigurationName)\</IntDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(ConfigurationName)\</IntDir>
<TargetName>$(TargetName)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">
<OutDir>$(SolutionDir)\bin\$(Platform)\$(ConfigurationName)\</OutDir>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(ConfigurationName)\</IntDir>
<OutDir>$(SolutionDir)bin\$(Platform)\$(ConfigurationName)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(ConfigurationName)\</IntDir>
<TargetName>$(TargetName)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|x64'">
<OutDir>$(SolutionDir)\bin\$(Platform)\$(ConfigurationName)\</OutDir>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(ConfigurationName)\</IntDir>
<OutDir>$(SolutionDir)bin\$(Platform)\$(ConfigurationName)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(ConfigurationName)\</IntDir>
<TargetName>$(TargetName)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win7 Release|x64'">
<OutDir>$(SolutionDir)\bin\$(Platform)\$(ConfigurationName)\</OutDir>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(ConfigurationName)\</IntDir>
<OutDir>$(SolutionDir)bin\$(Platform)\$(ConfigurationName)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(ConfigurationName)\</IntDir>
<TargetName>$(TargetName)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8.1 Release|x64'">
<OutDir>$(SolutionDir)\bin\$(Platform)\$(ConfigurationName)\</OutDir>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(ConfigurationName)\</IntDir>
<OutDir>$(SolutionDir)bin\$(Platform)\$(ConfigurationName)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(ConfigurationName)\</IntDir>
<TargetName>$(TargetName)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win10Release|x64'">
<OutDir>$(SolutionDir)\bin\$(Platform)\$(ConfigurationName)\</OutDir>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(ConfigurationName)\</IntDir>
<OutDir>$(SolutionDir)bin\$(Platform)\$(ConfigurationName)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(ConfigurationName)\</IntDir>
<TargetName>$(TargetName)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">
<OutDir>$(SolutionDir)\bin\$(Platform)\$(ConfigurationName)\</OutDir>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(ConfigurationName)\</IntDir>
<OutDir>$(SolutionDir)bin\$(Platform)\$(ConfigurationName)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(ConfigurationName)\</IntDir>
<TargetName>$(TargetName)</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Vista Debug|Win32'">
Expand Down Expand Up @@ -176,9 +176,7 @@
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<AdditionalDependencies>FltMgr.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>copy /y "$(TargetPath)" \\Win81_x64\c$\$(TargetFileName)</Command>
</PostBuildEvent>
<PostBuildEvent />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Win10Debug|x64'">
<ClCompile>
Expand All @@ -193,9 +191,7 @@
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<AdditionalDependencies>FltMgr.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>copy /y "$(TargetPath)" \\Win10_x64\c$\$(TargetFileName)</Command>
</PostBuildEvent>
<PostBuildEvent />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">
<ClCompile>
Expand All @@ -204,10 +200,7 @@
<PreprocessorDefinitions>_WIN8_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4054;4055;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
<PostBuildEvent />
<Link>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<AdditionalDependencies>FltMgr.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand All @@ -227,9 +220,7 @@
<PreprocessorDefinitions>_WIN7_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4054;4055;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<PostBuildEvent>
<Command>copy /y "$(TargetPath)" \\Win7_x64\c$\$(TargetFileName)</Command>
</PostBuildEvent>
<PostBuildEvent />
<Link>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<AdditionalDependencies>FltMgr.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand All @@ -242,10 +233,7 @@
<PreprocessorDefinitions>_WIN7_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4054;4055;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
<PostBuildEvent />
<Link>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<AdditionalDependencies>FltMgr.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down Expand Up @@ -284,10 +272,7 @@
<PreprocessorDefinitions>_WIN8_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4054;4055;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
<PostBuildEvent />
<Link>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<AdditionalDependencies>FltMgr.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down
5 changes: 4 additions & 1 deletion src/Arch/Intel/VMX.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,11 @@ VOID VmxSetupVMCS( IN PVCPU VpData )
// makes use of both of these instructions if the CPU supports it. By using
// VmxpAdjustMsr, these options will be ignored if this processor does
// not actually support the instructions to begin with.

vmCpuCtl2Requested.Fields.EnableRDTSCP = TRUE;
vmCpuCtl2Requested.Fields.EnableINVPCID = TRUE;
vmCpuCtl2Requested.Fields.EnableXSAVESXSTORS = TRUE;


// Begin by setting the link pointer to the required value for 4KB VMCS.
__vmx_vmwrite( VMCS_LINK_POINTER, MAXULONG64 );
Expand Down Expand Up @@ -532,7 +535,7 @@ VOID VmxSetupVMCS( IN PVCPU VpData )
// Exception bitmap
ULONG ExceptionBitmap = 0;
//ExceptionBitmap |= 1 << VECTOR_DEBUG_EXCEPTION;
ExceptionBitmap |= 1 << VECTOR_BREAKPOINT_EXCEPTION;
//ExceptionBitmap |= 1 << VECTOR_BREAKPOINT_EXCEPTION;

__vmx_vmwrite( EXCEPTION_BITMAP, ExceptionBitmap );

Expand Down
31 changes: 24 additions & 7 deletions src/Arch/Intel/VmxExitHandlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ DECLSPEC_NORETURN EXTERN_C VOID VmxpExitHandler( IN PCONTEXT Context )
guestContext.GpRegs = Context;
guestContext.ExitPending = FALSE;

//Context->Rsp = guestContext.GuestRsp;

(g_ExitHandler[guestContext.ExitReason])(&guestContext);

if (guestContext.ExitPending)
Expand Down Expand Up @@ -212,6 +214,7 @@ VOID VmExitINVD( IN PGUEST_STATE GuestState )
/// <param name="GuestState">Guest VM state</param>
VOID VmExitCPUID( IN PGUEST_STATE GuestState )
{
KdBreakPoint();
CPUID cpu_info = { 0 };
__cpuidex( (int*)&cpu_info, (int)GuestState->GpRegs->Rax, (int)GuestState->GpRegs->Rcx );

Expand Down Expand Up @@ -338,26 +341,34 @@ VOID VmExitCR( IN PGUEST_STATE GuestState )
{
PMOV_CR_QUALIFICATION data = (PMOV_CR_QUALIFICATION)&GuestState->ExitQualification;
PULONG64 regPtr = (PULONG64)&GuestState->GpRegs->Rax + data->Fields.Register;
ULONG64 regValue = *((PULONG64)&GuestState->GpRegs->Rax + data->Fields.Register);
VPID_CTX ctx = { 0 };

switch (data->Fields.AccessType)
{
case TYPE_MOV_TO_CR:
{
if (data->Fields.Register == 4)
{
regValue = GuestState->GuestRsp;
}

switch (data->Fields.ControlRegister)
{
case 0:
__vmx_vmwrite( GUEST_CR0, *regPtr );
__vmx_vmwrite( CR0_READ_SHADOW, *regPtr );
__vmx_vmwrite( GUEST_CR0, regValue);
__vmx_vmwrite( CR0_READ_SHADOW, regValue);
break;
case 3:
__vmx_vmwrite( GUEST_CR3, *regPtr );

regValue &= ~(1ULL << 63);
__vmx_vmwrite( GUEST_CR3, regValue);
if (g_Data->Features.VPID)
__invvpid( INV_ALL_CONTEXTS, &ctx );
break;
case 4:
__vmx_vmwrite( GUEST_CR4, *regPtr );
__vmx_vmwrite( CR4_READ_SHADOW, *regPtr );
__vmx_vmwrite( GUEST_CR4, regValue);
__vmx_vmwrite( CR4_READ_SHADOW, regValue);
break;
default:
DPRINT( "HyperBone: CPU %d: %s: Unsupported register %d\n", CPU_IDX, __FUNCTION__, data->Fields.ControlRegister );
Expand Down Expand Up @@ -385,6 +396,12 @@ VOID VmExitCR( IN PGUEST_STATE GuestState )
ASSERT( FALSE );
break;
}

if (data->Fields.Register == 4)
{
__vmx_vmwrite(GUEST_RSP, *regPtr);
}

}
break;

Expand Down Expand Up @@ -614,9 +631,9 @@ VOID VmExitMTF( IN PGUEST_STATE GuestState )
VOID VmExitStartFailed( IN PGUEST_STATE GuestState )
{
DPRINT(
"HyperBone: CPU %d: %s: Failed to enter VM, reason %d, code %d\n",
"HyperBone: CPU %d: %s: Failed to enter VM, reason %d, code %d, guest RIP %p\n",
CPU_IDX, __FUNCTION__,
GuestState->ExitReason, GuestState->ExitQualification
GuestState->ExitReason, GuestState->ExitQualification,GuestState->GuestRip
);

KeBugCheckEx( HYPERVISOR_ERROR, BUG_CHECK_INVALID_VM, GuestState->ExitReason, GuestState->ExitQualification, 0 );
Expand Down