Skip to content

Commit

Permalink
don't BSOD when KVA shadowing is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbasPL committed Feb 4, 2024
1 parent 206d245 commit ff6f8f4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ typedef struct _STAGE2_LOADER_DATA {
DWORD loader_pid;
} STAGE2_LOADER_DATA, *PSTAGE2_LOADER_DATA;

typedef struct _SYSTEM_KERNEL_VA_SHADOW_INFORMATION {
union {
ULONG KvaShadowFlags;
struct {
ULONG KvaShadowEnabled : 1;
ULONG KvaShadowUserGlobal : 1;
ULONG KvaShadowPcid : 1;
ULONG KvaShadowInvpcid : 1;
ULONG KvaShadowRequired : 1; // REDSTONE4
ULONG KvaShadowRequiredAvailable : 1;
ULONG InvalidPteBit : 6;
ULONG L1DataCacheFlushSupported : 1;
ULONG L1TerminalFaultMitigationPresent : 1;
ULONG Reserved : 18;
};
};
} SYSTEM_KERNEL_VA_SHADOW_INFORMATION, *PSYSTEM_KERNEL_VA_SHADOW_INFORMATION;

constexpr SYSTEM_INFORMATION_CLASS SystemKernelVaShadowInformation = (SYSTEM_INFORMATION_CLASS)196;

extern "C" NTSYSAPI NTSTATUS NTAPI RtlGetVersion(
_Out_ PRTL_OSVERSIONINFOW lpVersionInformation
);
Expand Down Expand Up @@ -43,6 +63,14 @@ inline bool isHvciEnabled() {
return false;
}

inline bool isKVAShadowEnabled() {
SYSTEM_KERNEL_VA_SHADOW_INFORMATION kvs = { 0 };
if (NT_SUCCESS(NtQuerySystemInformation(SystemKernelVaShadowInformation, &kvs, sizeof(kvs), NULL))) {
return kvs.KvaShadowEnabled;
}
return false;
}

inline std::wstring get_proces_name(HANDLE process) {
std::wstring process_name;
process_name.resize(MAX_PATH);
Expand Down
1 change: 1 addition & 0 deletions src/stage1/fumo_preloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define ERR_STAGE1_FAILED_TO_GET_DEBUG_PRIVILEGES 3
#define ERR_STAGE1_UNSUPPORTED_OS 50
#define ERR_STAGE1_HVCI_ENABLED 51
#define ERR_STAGE1_KVA_SHADOW_ENABLED 52
#define ERR_STAGE1_FAILED_TO_MAP_DRIVER 100
#define ERR_STAGE1_FAILED_TO_OPEN_DRIVER 101
#define ERR_STAGE1_FAILED_TO_GET_DRIVER_VERSION 102
Expand Down
3 changes: 3 additions & 0 deletions src/stage1/stage1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ int main(PFUMO_EMBEDDED_DATA embedded_data) {
if (isHvciEnabled())
return fumo::error(ERR_STAGE1_HVCI_ENABLED, L"HyperVisor Code Integrity (HVCI) is enabled, please disable it and try again");

if (isKVAShadowEnabled())
return fumo::error(ERR_STAGE1_KVA_SHADOW_ENABLED, L"Kernel Virtual Address Shadow (KVAS) is enabled, please disable it and try again");

if(!get_debug_privileges())
return fumo::error(ERR_STAGE1_FAILED_TO_GET_DEBUG_PRIVILEGES, L"Failed to get debug privileges");

Expand Down

0 comments on commit ff6f8f4

Please sign in to comment.