50 #define LOCAL_BUF_SIZE 4 76 offset =
gGuest.
PaeEnabled ? (Address & 0xFFF) >> 3 : (Address & 0xFFF) >> 2;
91 ERROR(
"[ERROR] IntVeUpdateCacheEntry failed: 0x%08x\n", status);
97 goto _stop_stats_and_exit;
103 while (list != &pPt->
Entries[offset])
105 PINVOCATION_CONTEXT pIc = NULL;
133 list = localCallbacksList.
Flink;
134 while (list != &localCallbacksList)
144 ERROR(
"[ERROR] Callback failed: 0x%08x\n", status2);
165 TRACE(
"[PTM] Callback returned INT_STATUS_ACCESS_DENIED, will block the PT write.\n");
169 _stop_stats_and_exit:
232 if (pPtHook->
Gpa == Gpa)
246 goto cleanup_and_exit;
263 goto cleanup_and_exit;
274 pPtHook, Flags, &pPtHook->
GpaHook);
277 ERROR(
"[ERROR] IntHookGpaSetHook failed for gpa %llx: 0x%08x\n", Gpa, status);
278 goto cleanup_and_exit;
287 ERROR(
"[ERROR] IntFlushEPTPermissions failed: 0x%08x\n", status);
288 goto cleanup_and_exit;
329 _In_ void *ParentHook,
355 if (NULL == Callback)
369 ERROR(
"[ERROR] IntHookPtmAddTable failed: 0x%08x\n", status);
374 if (NULL == pPtmHook)
386 pPtmHook->
PtHook = pPtHook;
389 offset =
gGuest.
PaeEnabled ? ((Address & 0xFFF) >> 3) : ((Address & 0xFFF) >> 2);
397 ERROR(
"[ERROR] IntVeUpdateCacheEntry failed: 0x%08x\n", status);
431 if (Hook->GpaHookSet)
436 ERROR(
"[ERROR] IntHookGpaRemoveHook failed: 0x%08x\n", status);
439 Hook->GpaHookSet =
FALSE;
499 Hook->PtHook->RefCount--;
500 Hook->PtHook->DelCount++;
502 if (0 == Hook->PtHook->RefCount)
507 ERROR(
"[ERROR] IntHookPtmRemoveTableHook failed: 0x%08x\n", status);
554 ERROR(
"[ERROR] IntHookPtmRemoveHookInternal failed: 0x%08x\n", status);
589 ERROR(
"[ERROR] IntHookGpaDeleteHook failed: 0x%08x\n", status);
624 Hook->PtHook->DelCount--;
625 if ((0 == Hook->PtHook->DelCount) && (0 == Hook->PtHook->RefCount))
630 ERROR(
"[ERROR] IntHookPtmDeleteTableHook failed: 0x%08x\n", status);
678 ERROR(
"[ERROR] IntHookPtmDeleteHookInternal failed: 0x%08x\n", status);
726 ERROR(
"[ERROR] IntHookPtmDeleteHookInternal failed: 0x%08x\n", status);
754 ERROR(
"[ERROR] IntHookGpaDeleteHook failed: 0x%08x\n", status);
759 ERROR(
"[ERROR] Invalid hook state: %x for hook at GPA 0x%016llx\n", p->
Header.
Flags, p->
Gpa);
PHOOK_GPA GpaHook
The GPA hook set on this page-table.
static INTSTATUS IntHookPtmDeleteHookInternal(PHOOK_PTM Hook, DWORD Flags)
Permanently delete a page-table hook handle.
#define INT_STATUS_ACCESS_DENIED
LIST_ENTRY RemovedPtmHooks
List of removed page-table hooks (HOOK_PTM_TABLE).
#define CONTAINING_RECORD(List, Type, Member)
BOOLEAN Dirty
Set whenever hooks are added or removed.
void * Context
User-defined data that will be supplied to the callback.
struct _INVOCATION_CONTEXT INVOCATION_CONTEXT
static INTSTATUS IntHookPtmAddTable(QWORD Gpa, DWORD Flags, PHOOK_PTM_TABLE *PtHook)
Add a new page-table to the monitored list.
INTSTATUS IntHookGpaRemoveHook(HOOK_GPA **Hook, DWORD Flags)
Remove a GPA hook.
#define INT_STATUS_SUCCESS
#define PTM_PAE_ROOT_HOOK_ID(addr)
static INTSTATUS IntHookPtmRemoveHookInternal(PHOOK_PTM Hook, DWORD Flags)
Remove a page-table hook handle.
#define PTM_HOOK_TABLE_SIZE
#define IntEnterDebugger()
struct _LIST_ENTRY * Flink
Used by the internal page monitor (used by PTS).
#define INT_SUCCESS(Status)
#define HOOK_FLG_DISABLED
If flag is set, the hook is disabled, therefore ignored on EPT violations.
static BOOLEAN IsListEmpty(const LIST_ENTRY *ListHead)
PHOOK_PTS Hook
The PTS hook associated with the modified address.
struct _HOOK_PTM_TABLE * PHOOK_PTM_TABLE
BOOLEAN KernelBetaDetections
True if the kernel protection is in beta (log-only) mode.
Measures all the page table writes.
#define INT_STATUS_NOT_NEEDED_HINT
#define HpAllocWithTag(Len, Tag)
INTSTATUS IntHookPtmInit(void)
Initialize the page-table hook system.
int INTSTATUS
The status data type.
HOOK_STATE * gHooks
Global hooks state.
HOOK_HEADER Header
Hook header - used by all memory hooks.
INTSTATUS IntFlushEPTPermissions(void)
INTSTATUS IntHookPtmCommitHooks(void)
Commit the page-table hooks.
static INTSTATUS IntHookPtmDeleteTableHook(PHOOK_PTM_TABLE Hook, DWORD Flags)
Permanently delete a page-table hook.
INTSTATUS IntHookGpaSetHook(QWORD Gpa, DWORD Length, BYTE Type, PFUNC_EptViolationCallback Callback, void *Context, void *ParentHook, DWORD Flags, HOOK_GPA **Hook)
Places an EPT hook on the indicated memory range.
LIST_ENTRY PtmHooks[PTM_HOOK_TABLE_SIZE]
Hash of monitored address spaces.
INTSTATUS IntVeUpdateCacheEntry(QWORD Address, BOOLEAN Monitored)
Update an address inside the VE cache.
#define HOOK_FLG_PT_UM_ROOT
If flag is set, the hook is set on the root paging structure, and only the low, user-mode entires are...
BYTE HookType
The type of the hook structure (see _HOOK_TYPE)
#define HOOK_FLG_GLOBAL_MASK
Global flags must be defined here and must be handled by each hooks layer (even if it ignores them...
BOOLEAN PaeEnabled
True if Physical Address Extension is enabled.
static BOOLEAN RemoveEntryList(LIST_ENTRY *Entry)
QWORD Address
Guest physical address of the monitored page-table entry.
void * ParentHook
The parent hook. For a GPA hook, for example, a GVA hook or a PagedHook will be the parent hook...
#define HOOK_FLG_CHAIN_DELETE
If flag is set, then we won't remove the hook on commit phase; we'll let the parent hook handle the d...
HOOK_PTM_STATE PtmHooks
Page table monitoring (internal) state.
#define INT_STATUS_INVALID_PARAMETER_4
#define HpFreeAndNullWithTag(Add, Tag)
INTSTATUS IntHookGpaDeleteHook(HOOK_GPA **Hook, DWORD Flags)
Permanently delete a GPA hook.
INTSTATUS IntHookPtmDeleteHook(HOOK_PTM **Hook, DWORD Flags)
Permanently delete a page-table hook handle.
PFUNC_EptViolationCallback Callback
Modification callback, called whenever an entry inside this page-table is modified.
static void InsertTailList(LIST_ENTRY *ListHead, LIST_ENTRY *Entry)
static void InitializeListHead(LIST_ENTRY *ListHead)
INTSTATUS IntHookPtmSetHook(QWORD Address, PFUNC_EptViolationCallback Callback, void *Context, void *ParentHook, DWORD Flags, PHOOK_PTM *Hook)
Set a hook on a page-table.
#define UNREFERENCED_PARAMETER(P)
LIST_ENTRY * Entries
A list of hooked entries. When a HOOK_PTS_ENTRY is created for entry at offset X, Entries[x] will con...
enum _INTRO_ACTION INTRO_ACTION
Event actions.
DWORD DelCount
Number of delete requests. The entry will be deleted when this reaches 0.
MM Mm
Guest memory information, such as paging mode, system Cr3 value, etc.
INTSTATUS(* PFUNC_EptViolationCallback)(void *Context, void *Hook, QWORD Address, INTRO_ACTION *Action)
EPT callback handler.
GUEST_STATE gGuest
The current guest state.
LIST_ENTRY RemovedPtHooks
List of removed PTM hooks (HOOK_PTM).
PFUNC_EptViolationCallback Callback
Write callback to be called for the modification.
DWORD RefCount
Number of references - number of HOOK_PTM structures that point to this entry.
QWORD Gpa
The page-table guest physical address.
static INTSTATUS IntHookPtmWriteCallback(void *Context, void *Hook, QWORD Address, INTRO_ACTION *Action)
Called whenever a monitored page-table is written.
static INTSTATUS IntHookPtmRemoveTableHook(PHOOK_PTM_TABLE Hook, DWORD Flags)
Remove a page-table hook.
#define PTM_HOOK_ID(addr)
LIST_ENTRY Link
List element entry.
struct _INVOCATION_CONTEXT * PINVOCATION_CONTEXT
PAGING_MODE Mode
The paging mode used by the guest.
LIST_ENTRY Link
List entry link.
#define INT_STATUS_INVALID_PARAMETER_1
Used by an internal page monitored using PTM.
INTSTATUS IntHookPtmRemoveHook(HOOK_PTM **Hook, DWORD Flags)
Remove a page-table hook handle.
void * Context
Context to be passed to the Callback.
DWORD Flags
Generic flags. Check out EPT Hook flags.
HOOK_HEADER Header
Hook header - used by all memory hooks.
#define INT_STATUS_INVALID_PARAMETER_2
BOOLEAN HooksRemoved
True if hooks have been removed.
LIST_ENTRY Link
List entry link.
#define HOOK_FLG_REMOVE
If flag is set, the hook has been removed, and waits the next commit to be actually deleted...
#define HOOK_FLG_PAE_ROOT
#define INT_STATUS_INSUFFICIENT_RESOURCES
#define INT_STATUS_INVALID_PARAMETER_3