HyperDbg Debugger
Loading...
Searching...
No Matches
CompatibilityChecks.c File Reference

Checks for processor compatibility with different features. More...

#include "pch.h"

Functions

BOOLEAN CompatibilityCheckCpuSupportForRtm ()
 Check whether the processor supports RTM or not.
UINT32 CompatibilityCheckGetX86VirtualAddressWidth ()
 Get virtual address width for x86 processors.
UINT32 CompatibilityCheckGetX86PhysicalAddressWidth ()
 Get physical address width for x86 processors.
BOOLEAN CompatibilityCheckCetShadowStackSupport ()
 Check if the processor supports CET IBT.
BOOLEAN CompatibilityCheckCetIbtSupport ()
 Check for Intel CET IBT support.
BOOLEAN CompatibilityCheckModeBasedExecution ()
 Check for mode-based execution.
BOOLEAN CompatibilityCheckPml ()
 Check for Page Modification Logging (PML) support.
VOID CompatibilityCheckPerformChecks ()
 Checks for the compatibility features based on current processor @detail NOTE: NOT ALL OF THE CHECKS ARE PERFORMED HERE.

Detailed Description

Checks for processor compatibility with different features.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.2
Date
2023-03-15

Function Documentation

◆ CompatibilityCheckCetIbtSupport()

BOOLEAN CompatibilityCheckCetIbtSupport ( )

Check for Intel CET IBT support.

Returns
BOOLEAN
108{
109 INT32 Regs[4];
110
111 CommonCpuidInstruction(7, 0, Regs);
112
113 return (BOOLEAN)((Regs[3] & (1 << 20)) != 0); // CpuInfo[3] is EDX
114}
signed int INT32
Definition BasicTypes.h:50
UCHAR BOOLEAN
Definition BasicTypes.h:35
VOID CommonCpuidInstruction(UINT32 Func, UINT32 SubFunc, INT *CpuInfo)
Get cpuid results.
Definition Common.c:85

◆ CompatibilityCheckCetShadowStackSupport()

BOOLEAN CompatibilityCheckCetShadowStackSupport ( )

Check if the processor supports CET IBT.

Returns
BOOLEAN
93{
94 INT32 Regs[4];
95
96 CommonCpuidInstruction(7, 0, Regs);
97
98 return (BOOLEAN)((Regs[2] & (1 << 7)) != 0); // // CpuInfo[3] is ECX
99}

◆ CompatibilityCheckCpuSupportForRtm()

BOOLEAN CompatibilityCheckCpuSupportForRtm ( )

Check whether the processor supports RTM or not.

Returns
BOOLEAN
22{
23 int Regs1[4];
24 int Regs2[4];
25 BOOLEAN Result;
26
27 //
28 // TSX is controlled via MSR_IA32_TSX_CTRL. However, support for this
29 // MSR is enumerated by ARCH_CAP_TSX_MSR bit in MSR_IA32_ARCH_CAPABILITIES.
30 //
31 // TSX control (aka MSR_IA32_TSX_CTRL) is only available after a
32 // microcode update on CPUs that have their MSR_IA32_ARCH_CAPABILITIES
33 // bit MDS_NO=1. CPUs with MDS_NO=0 are not planned to get
34 // MSR_IA32_TSX_CTRL support even after a microcode update. Thus,
35 // tsx= cmdline requests will do nothing on CPUs without
36 // MSR_IA32_TSX_CTRL support.
37 //
38
39 CommonCpuidInstruction(0, 0, Regs1);
40 CommonCpuidInstruction(7, 0, Regs2);
41
42 //
43 // Check RTM and MPX extensions in order to filter out TSX on Haswell CPUs
44 //
45 Result = Regs1[0] >= 0x7 && (Regs2[1] & 0x4800) == 0x4800;
46
47 return Result;
48}

◆ CompatibilityCheckGetX86PhysicalAddressWidth()

UINT32 CompatibilityCheckGetX86PhysicalAddressWidth ( )

Get physical address width for x86 processors.

Returns
UINT32
75{
76 INT32 Regs[4];
77
79
80 //
81 // Extracting bit 7:0 from eax register
82 //
83 return (Regs[0] & 0x0ff);
84}
#define CPUID_ADDR_WIDTH
Cpuid to get virtual address width.
Definition Constants.h:695

◆ CompatibilityCheckGetX86VirtualAddressWidth()

UINT32 CompatibilityCheckGetX86VirtualAddressWidth ( )

Get virtual address width for x86 processors.

Returns
UINT32
57{
58 int Regs[4];
59
61
62 //
63 // Extracting bit 15:8 from eax register
64 //
65 return ((Regs[0] >> 8) & 0x0ff);
66}

◆ CompatibilityCheckModeBasedExecution()

BOOLEAN CompatibilityCheckModeBasedExecution ( )

Check for mode-based execution.

Returns
BOOLEAN
123{
124 //
125 // The PML address and PML index fields exist only on processors that support the 1-setting of
126 // the "enable PML" VM - execution control
127 //
128 UINT32 SecondaryProcBasedVmExecControls = HvAdjustControls(IA32_VMX_PROCBASED_CTLS2_MODE_BASED_EXECUTE_CONTROL_FOR_EPT_FLAG,
129 IA32_VMX_PROCBASED_CTLS2);
130
131 if (SecondaryProcBasedVmExecControls & IA32_VMX_PROCBASED_CTLS2_MODE_BASED_EXECUTE_CONTROL_FOR_EPT_FLAG)
132 {
133 //
134 // The processor support PML
135 //
136 return TRUE;
137 }
138 else
139 {
140 //
141 // Not supported
142 //
143 return FALSE;
144 }
145}
UINT32 HvAdjustControls(UINT32 Ctl, UINT32 Msr)
Adjust controls for VMCS based on processor capability.
Definition Hv.c:23
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
unsigned int UINT32
Definition BasicTypes.h:54

◆ CompatibilityCheckPerformChecks()

VOID CompatibilityCheckPerformChecks ( )

Checks for the compatibility features based on current processor @detail NOTE: NOT ALL OF THE CHECKS ARE PERFORMED HERE.

Returns
VOID
184{
185 //
186 // Check if processor supports TSX (RTM)
187 //
189
190 //
191 // Get x86 processor width for virtual address
192 //
194
195 //
196 // Get x86 processor width for physical address
197 //
199
200 //
201 // Check Mode-based execution compatibility
202 //
204
205 //
206 // Check Intel CET IBT support
207 //
209
210 //
211 // Check Intel CET shadow stack support
212 //
214
215 //
216 // Check PML support
217 //
219
220 //
221 // Log for testing
222 //
223 LogDebugInfo("Mode based execution: %s | PML: %s",
224 g_CompatibilityCheck.ModeBasedExecutionSupport ? "true" : "false",
225 g_CompatibilityCheck.PmlSupport ? "true" : "false");
226}
BOOLEAN CompatibilityCheckModeBasedExecution()
Check for mode-based execution.
Definition CompatibilityChecks.c:122
BOOLEAN CompatibilityCheckPml()
Check for Page Modification Logging (PML) support.
Definition CompatibilityChecks.c:153
BOOLEAN CompatibilityCheckCetIbtSupport()
Check for Intel CET IBT support.
Definition CompatibilityChecks.c:107
BOOLEAN CompatibilityCheckCpuSupportForRtm()
Check whether the processor supports RTM or not.
Definition CompatibilityChecks.c:21
UINT32 CompatibilityCheckGetX86PhysicalAddressWidth()
Get physical address width for x86 processors.
Definition CompatibilityChecks.c:74
UINT32 CompatibilityCheckGetX86VirtualAddressWidth()
Get virtual address width for x86 processors.
Definition CompatibilityChecks.c:56
BOOLEAN CompatibilityCheckCetShadowStackSupport()
Check if the processor supports CET IBT.
Definition CompatibilityChecks.c:92
#define LogDebugInfo(format,...)
Log, initialize boot information and debug information.
Definition HyperDbgHyperLogIntrinsics.h:155
COMPATIBILITY_CHECKS_STATUS g_CompatibilityCheck
Different attributes and compatibility checks of the current processor.
Definition GlobalVariables.h:26

◆ CompatibilityCheckPml()

BOOLEAN CompatibilityCheckPml ( )

Check for Page Modification Logging (PML) support.

Returns
BOOLEAN
154{
155 //
156 // The PML address and PML index fields exist only on processors that support the 1-setting of
157 // the "enable PML" VM - execution control
158 //
159 UINT32 SecondaryProcBasedVmExecControls = HvAdjustControls(IA32_VMX_PROCBASED_CTLS2_ENABLE_PML_FLAG, IA32_VMX_PROCBASED_CTLS2);
160
161 if (SecondaryProcBasedVmExecControls & IA32_VMX_PROCBASED_CTLS2_ENABLE_PML_FLAG)
162 {
163 //
164 // The processor support MBEC
165 //
166 return TRUE;
167 }
168 else
169 {
170 //
171 // Not supported
172 //
173 return FALSE;
174 }
175}