Bitdefender Hypervisor Memory Introspection
memtables.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Bitdefender
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #ifndef _MEM_TABLES_H_
6 #define _MEM_TABLES_H_
7 
8 #include "thread_safeness.h"
9 
10 
11 #define MAX_MEM_TABLE_SIZE 256
12 // PUSHF (opcode = 1)
13 // PUSH dst (rex + opcode = 1 + 1 = 2)
14 // PUSH idx (rex + opcode = 1 + 1 = 2)
15 // MOV [rsp + 8], slack_addr low (opcode + modrm + sub + disp + imm = 1 + 1 + 1 + 1 + 4 = 8)
16 // MOV [rsp + C], slack_addr high (opcode + modrm + sub + disp + imm = 1 + 1 + 1 + 1 + 4 = 8)
17 // IMUL idx, idx, 11 (rex + opcode + modrm + imm = 1 + 1 + 1 + 1 = 4)
18 // ADD [rsp + 8], idx (rex + opcode + modrm + sib + disp = 1 + 1 + 1 + 1 + 1 = 5)
19 // POP idx (rex + opcode = 1 + 1 = 2)
20 // POP dst (rex + opcode = 1 + 1 = 2)
21 // MOV [rsp - 8], 0 (rex + opcode + modrm + sib + disp + imm4 = 9 bytes)
22 // POPF (opcode = 1)
23 // JMP dst (rex + opcode + modrm = 1 + 1 + 1 = 3)
24 // 11 * number of entries
25 #define MEM_TABLE_HEADER_SIZE 47
26 #define MEM_TABLE_ENTRY_SIZE 11u
27 #define MAX_MEM_TABLE_SLACK_SIZE ((MEM_TABLE_HEADER_SIZE) + (MEM_TABLE_ENTRY_SIZE) * (MAX_MEM_TABLE_SIZE))
28 
29 
33 typedef struct _MEM_TABLE_RELOC
34 {
36 
40 
43  void *InsCloak;
44  void *SlackCloak;
45 
51 
52 
53 //
54 // API
55 //
56 BOOLEAN
58  _In_ QWORD Ptr,
59  _In_ THS_PTR_TYPE Type,
60  _Out_opt_ QWORD *Table
61  );
62 
65  void
66  );
67 
68 void
70  void
71  );
72 
75  void
76  );
77 
78 BOOLEAN
80  _In_ QWORD Rip
81  );
82 
85  void
86  );
87 
88 #endif // _MEM_TABLES_H_
_Bool BOOLEAN
Definition: intro_types.h:58
void * SlackCloak
Slack handler cloak handle.
Definition: memtables.h:44
INTSTATUS IntMtblCheckAccess(void)
Check if the current instruction is like a switch-case table access instruction.
Definition: memtables.c:401
#define _In_
Definition: intro_sal.h:21
BOOLEAN IntMtblIsPtrInReloc(QWORD Ptr, THS_PTR_TYPE Type, QWORD *Table)
Check if the given pointer is inside a mem-table relocation handler.
Definition: memtables.c:596
BOOLEAN InAgent
True if we relocated the instruction inside the PT filter agent.
Definition: memtables.h:48
int INTSTATUS
The status data type.
Definition: introstatus.h:24
struct _MEM_TABLE_RELOC * PMEM_TABLE_RELOC
struct _MEM_TABLE_RELOC MEM_TABLE_RELOC
BOOLEAN IntMtblInsRelocated(QWORD Rip)
Check if the instruction at the provided RIP is instrumented.
Definition: memtables.c:677
void IntMtblDisable(void)
Disables mem-table instructions instrumentation.
Definition: memtables.c:644
BOOLEAN Patched
True if the instruction has been instrumented.
Definition: memtables.h:46
QWORD SlackAddress
Slack address where the handler was allocated.
Definition: memtables.h:41
void * InsCloak
Instrumented instruction cloak handle.
Definition: memtables.h:43
BOOLEAN Ignored
True if we didn't manage to hook it.
Definition: memtables.h:47
#define _Out_opt_
Definition: intro_sal.h:30
QWORD TableGva
Guest virtual address of the switch-case table accessed by the instruction.
Definition: memtables.h:38
unsigned long long QWORD
Definition: intro_types.h:53
QWORD Rip
RIP of the instrumented instruction.
Definition: memtables.h:37
BOOLEAN Dumped
TRUE if it's a problematic table and we dumped it's content in an error.
Definition: memtables.h:49
INTSTATUS IntMtblRemoveAgentEntries(void)
Removes only the mem-table entries that were relocated inside the PT filter.
Definition: memtables.c:707
uint32_t DWORD
Definition: intro_types.h:49
THS_PTR_TYPE
The type of pointer to be checked.
DWORD SlackSize
Size of the allocated slack buffer.
Definition: memtables.h:42
QWORD Hits
Number of times this instruction generated a read EPT violation.
Definition: memtables.h:39
INTSTATUS IntMtblUninit(void)
Completely uninit the mem-tables, removing all the handlers from the NT slack space.
Definition: memtables.c:745
LIST_ENTRY Link
List element link.
Definition: memtables.h:35