Skip to content

Commit ff6f8f4

Browse files
committed
don't BSOD when KVA shadowing is enabled
1 parent 206d245 commit ff6f8f4

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/include/util.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@ typedef struct _STAGE2_LOADER_DATA {
1515
DWORD loader_pid;
1616
} STAGE2_LOADER_DATA, *PSTAGE2_LOADER_DATA;
1717

18+
typedef struct _SYSTEM_KERNEL_VA_SHADOW_INFORMATION {
19+
union {
20+
ULONG KvaShadowFlags;
21+
struct {
22+
ULONG KvaShadowEnabled : 1;
23+
ULONG KvaShadowUserGlobal : 1;
24+
ULONG KvaShadowPcid : 1;
25+
ULONG KvaShadowInvpcid : 1;
26+
ULONG KvaShadowRequired : 1; // REDSTONE4
27+
ULONG KvaShadowRequiredAvailable : 1;
28+
ULONG InvalidPteBit : 6;
29+
ULONG L1DataCacheFlushSupported : 1;
30+
ULONG L1TerminalFaultMitigationPresent : 1;
31+
ULONG Reserved : 18;
32+
};
33+
};
34+
} SYSTEM_KERNEL_VA_SHADOW_INFORMATION, *PSYSTEM_KERNEL_VA_SHADOW_INFORMATION;
35+
36+
constexpr SYSTEM_INFORMATION_CLASS SystemKernelVaShadowInformation = (SYSTEM_INFORMATION_CLASS)196;
37+
1838
extern "C" NTSYSAPI NTSTATUS NTAPI RtlGetVersion(
1939
_Out_ PRTL_OSVERSIONINFOW lpVersionInformation
2040
);
@@ -43,6 +63,14 @@ inline bool isHvciEnabled() {
4363
return false;
4464
}
4565

66+
inline bool isKVAShadowEnabled() {
67+
SYSTEM_KERNEL_VA_SHADOW_INFORMATION kvs = { 0 };
68+
if (NT_SUCCESS(NtQuerySystemInformation(SystemKernelVaShadowInformation, &kvs, sizeof(kvs), NULL))) {
69+
return kvs.KvaShadowEnabled;
70+
}
71+
return false;
72+
}
73+
4674
inline std::wstring get_proces_name(HANDLE process) {
4775
std::wstring process_name;
4876
process_name.resize(MAX_PATH);

src/stage1/fumo_preloader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define ERR_STAGE1_FAILED_TO_GET_DEBUG_PRIVILEGES 3
1010
#define ERR_STAGE1_UNSUPPORTED_OS 50
1111
#define ERR_STAGE1_HVCI_ENABLED 51
12+
#define ERR_STAGE1_KVA_SHADOW_ENABLED 52
1213
#define ERR_STAGE1_FAILED_TO_MAP_DRIVER 100
1314
#define ERR_STAGE1_FAILED_TO_OPEN_DRIVER 101
1415
#define ERR_STAGE1_FAILED_TO_GET_DRIVER_VERSION 102

src/stage1/stage1.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ int main(PFUMO_EMBEDDED_DATA embedded_data) {
8181
if (isHvciEnabled())
8282
return fumo::error(ERR_STAGE1_HVCI_ENABLED, L"HyperVisor Code Integrity (HVCI) is enabled, please disable it and try again");
8383

84+
if (isKVAShadowEnabled())
85+
return fumo::error(ERR_STAGE1_KVA_SHADOW_ENABLED, L"Kernel Virtual Address Shadow (KVAS) is enabled, please disable it and try again");
86+
8487
if(!get_debug_privileges())
8588
return fumo::error(ERR_STAGE1_FAILED_TO_GET_DEBUG_PRIVILEGES, L"Failed to get debug privileges");
8689

0 commit comments

Comments
 (0)