vmcs_intel_x64_host_vm_state.h
Go to the documentation of this file.
1 //
2 // Bareflank Hypervisor
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #ifndef VMCS_INTEL_X64_HOST_VM_STATE_H
23 #define VMCS_INTEL_X64_HOST_VM_STATE_H
24 
25 #include <memory>
26 
27 #include <debug.h>
29 
38 {
39 public:
40 
42  ~vmcs_intel_x64_host_vm_state() override = default;
43 
45  { return m_es; }
47  { return m_cs; }
49  { return m_ss; }
51  { return m_ds; }
53  { return m_fs; }
55  { return m_gs; }
57  { return m_ldtr; }
59  { return m_tr; }
60 
62  { return m_cr0; }
64  { return m_cr3; }
66  { return m_cr4; }
67  x64::dr7::value_type dr7() const override
68  { return m_dr7; }
69 
71  { return m_rflags; }
72 
74  { return m_gdt.base(); }
76  { return m_idt.base(); }
77 
78  gdt_x64::size_type gdt_limit() const override
79  { return m_gdt.limit(); }
80  idt_x64::size_type idt_limit() const override
81  { return m_idt.limit(); }
82 
83  gdt_x64::limit_type es_limit() const override
84  { return m_es_index != 0 ? m_gdt.limit(m_es_index) : 0; }
85  gdt_x64::limit_type cs_limit() const override
86  { return m_cs_index != 0 ? m_gdt.limit(m_cs_index) : 0; }
87  gdt_x64::limit_type ss_limit() const override
88  { return m_ss_index != 0 ? m_gdt.limit(m_ss_index) : 0; }
89  gdt_x64::limit_type ds_limit() const override
90  { return m_ds_index != 0 ? m_gdt.limit(m_ds_index) : 0; }
91  gdt_x64::limit_type fs_limit() const override
92  { return m_fs_index != 0 ? m_gdt.limit(m_fs_index) : 0; }
93  gdt_x64::limit_type gs_limit() const override
94  { return m_gs_index != 0 ? m_gdt.limit(m_gs_index) : 0; }
96  { return m_ldtr_index != 0 ? m_gdt.limit(m_ldtr_index) : 0; }
97  gdt_x64::limit_type tr_limit() const override
98  { return m_tr_index != 0 ? m_gdt.limit(m_tr_index) : 0; }
99 
101  { return m_es_index != 0 ? m_gdt.access_rights(m_es_index) : x64::access_rights::unusable; }
103  { return m_cs_index != 0 ? m_gdt.access_rights(m_cs_index) : x64::access_rights::unusable; }
105  { return m_ss_index != 0 ? m_gdt.access_rights(m_ss_index) : x64::access_rights::unusable; }
107  { return m_ds_index != 0 ? m_gdt.access_rights(m_ds_index) : x64::access_rights::unusable; }
109  { return m_fs_index != 0 ? m_gdt.access_rights(m_fs_index) : x64::access_rights::unusable; }
111  { return m_gs_index != 0 ? m_gdt.access_rights(m_gs_index) : x64::access_rights::unusable; }
113  { return m_ldtr_index != 0 ? m_gdt.access_rights(m_ldtr_index) : x64::access_rights::unusable; }
115  { return m_tr_index != 0 ? m_gdt.access_rights(m_tr_index) : x64::access_rights::unusable; }
116 
117  gdt_x64::base_type es_base() const override
118  { return m_es_index != 0 ? m_gdt.base(m_es_index) : 0; }
119  gdt_x64::base_type cs_base() const override
120  { return m_cs_index != 0 ? m_gdt.base(m_cs_index) : 0; }
121  gdt_x64::base_type ss_base() const override
122  { return m_ss_index != 0 ? m_gdt.base(m_ss_index) : 0; }
123  gdt_x64::base_type ds_base() const override
124  { return m_ds_index != 0 ? m_gdt.base(m_ds_index) : 0; }
125  gdt_x64::base_type fs_base() const override
126  { return m_fs_index != 0 ? m_gdt.base(m_fs_index) : 0; }
127  gdt_x64::base_type gs_base() const override
128  { return m_gs_index != 0 ? m_gdt.base(m_gs_index) : 0; }
129  gdt_x64::base_type ldtr_base() const override
130  { return m_ldtr_index != 0 ? m_gdt.base(m_ldtr_index) : 0; }
131  gdt_x64::base_type tr_base() const override
132  { return m_tr_index != 0 ? m_gdt.base(m_tr_index) : 0; }
133 
135  { return m_ia32_debugctl_msr; }
137  { return m_ia32_pat_msr; }
139  { return m_ia32_efer_msr; }
141  { return m_ia32_perf_global_ctrl_msr; }
143  { return m_ia32_sysenter_cs_msr; }
145  { return m_ia32_sysenter_esp_msr; }
147  { return m_ia32_sysenter_eip_msr; }
149  { return m_ia32_fs_base_msr; }
151  { return m_ia32_gs_base_msr; }
152 
153  void dump() const override
154  {
155  bfdebug << "----------------------------------------" << bfendl;
156  bfdebug << "- vmcs_intel_x64_host_vm_state dump -" << bfendl;
157  bfdebug << "----------------------------------------" << bfendl;
158 
159  bfdebug << bfendl;
160  bfdebug << "segment selectors:" << bfendl;
161  bfdebug << " - m_es: " << view_as_pointer(m_es) << bfendl;
162  bfdebug << " - m_cs: " << view_as_pointer(m_cs) << bfendl;
163  bfdebug << " - m_ss: " << view_as_pointer(m_ss) << bfendl;
164  bfdebug << " - m_ds: " << view_as_pointer(m_ds) << bfendl;
165  bfdebug << " - m_fs: " << view_as_pointer(m_fs) << bfendl;
166  bfdebug << " - m_gs: " << view_as_pointer(m_gs) << bfendl;
167  bfdebug << " - m_ldtr: " << view_as_pointer(m_ldtr) << bfendl;
168  bfdebug << " - m_tr: " << view_as_pointer(m_tr) << bfendl;
169 
170  bfdebug << bfendl;
171  bfdebug << "segment base:" << bfendl;
172  bfdebug << " - es_base(): " << view_as_pointer(es_base()) << bfendl;
173  bfdebug << " - cs_base(): " << view_as_pointer(cs_base()) << bfendl;
174  bfdebug << " - ss_base(): " << view_as_pointer(ss_base()) << bfendl;
175  bfdebug << " - ds_base(): " << view_as_pointer(ds_base()) << bfendl;
176  bfdebug << " - fs_base(): " << view_as_pointer(fs_base()) << bfendl;
177  bfdebug << " - gs_base(): " << view_as_pointer(gs_base()) << bfendl;
178  bfdebug << " - ldtr_base(): " << view_as_pointer(ldtr_base()) << bfendl;
179  bfdebug << " - tr_base(): " << view_as_pointer(tr_base()) << bfendl;
180 
181  bfdebug << bfendl;
182  bfdebug << "segment limit:" << bfendl;
183  bfdebug << " - es_limit(): " << view_as_pointer(es_limit()) << bfendl;
184  bfdebug << " - cs_limit(): " << view_as_pointer(cs_limit()) << bfendl;
185  bfdebug << " - ss_limit(): " << view_as_pointer(ss_limit()) << bfendl;
186  bfdebug << " - ds_limit(): " << view_as_pointer(ds_limit()) << bfendl;
187  bfdebug << " - fs_limit(): " << view_as_pointer(fs_limit()) << bfendl;
188  bfdebug << " - gs_limit(): " << view_as_pointer(gs_limit()) << bfendl;
189  bfdebug << " - ldtr_limit(): " << view_as_pointer(ldtr_limit()) << bfendl;
190  bfdebug << " - tr_limit(): " << view_as_pointer(tr_limit()) << bfendl;
191 
192  bfdebug << bfendl;
193  bfdebug << "segment acess rights:" << bfendl;
194  bfdebug << " - es_access_rights(): " << view_as_pointer(es_access_rights()) << bfendl;
195  bfdebug << " - cs_access_rights(): " << view_as_pointer(cs_access_rights()) << bfendl;
196  bfdebug << " - ss_access_rights(): " << view_as_pointer(ss_access_rights()) << bfendl;
197  bfdebug << " - ds_access_rights(): " << view_as_pointer(ds_access_rights()) << bfendl;
198  bfdebug << " - fs_access_rights(): " << view_as_pointer(fs_access_rights()) << bfendl;
199  bfdebug << " - gs_access_rights(): " << view_as_pointer(gs_access_rights()) << bfendl;
200  bfdebug << " - ldtr_access_rights(): " << view_as_pointer(ldtr_access_rights()) << bfendl;
201  bfdebug << " - tr_access_rights(): " << view_as_pointer(tr_access_rights()) << bfendl;
202 
203  bfdebug << bfendl;
204  bfdebug << "registers:" << bfendl;
205  bfdebug << " - m_cr0: " << view_as_pointer(m_cr0) << bfendl;
206  bfdebug << " - m_cr3: " << view_as_pointer(m_cr3) << bfendl;
207  bfdebug << " - m_cr4: " << view_as_pointer(m_cr4) << bfendl;
208  bfdebug << " - m_dr7: " << view_as_pointer(m_dr7) << bfendl;
209 
210  bfdebug << bfendl;
211  bfdebug << "flags:" << bfendl;
212  bfdebug << " - m_rflags: " << view_as_pointer(m_rflags) << bfendl;
213 
214  bfdebug << bfendl;
215  bfdebug << "gdt/idt:" << bfendl;
216  bfdebug << " - m_gdt.base(): " << view_as_pointer(m_gdt.base()) << bfendl;
217  bfdebug << " - m_gdt.limit(): " << view_as_pointer(m_gdt.limit()) << bfendl;
218  bfdebug << " - m_idt.base(): " << view_as_pointer(m_idt.base()) << bfendl;
219  bfdebug << " - m_idt.limit(): " << view_as_pointer(m_idt.limit()) << bfendl;
220 
221  bfdebug << bfendl;
222  bfdebug << "model specific registers:" << bfendl;
223  bfdebug << " - m_ia32_debugctl_msr: " << view_as_pointer(m_ia32_debugctl_msr) << bfendl;
224  bfdebug << " - m_ia32_pat_msr: " << view_as_pointer(m_ia32_pat_msr) << bfendl;
225  bfdebug << " - m_ia32_efer_msr: " << view_as_pointer(m_ia32_efer_msr) << bfendl;
226  bfdebug << " - m_ia32_perf_global_ctrl_msr: " << view_as_pointer(m_ia32_perf_global_ctrl_msr) << bfendl;
227  bfdebug << " - m_ia32_sysenter_cs_msr: " << view_as_pointer(m_ia32_sysenter_cs_msr) << bfendl;
228  bfdebug << " - m_ia32_sysenter_esp_msr: " << view_as_pointer(m_ia32_sysenter_esp_msr) << bfendl;
229  bfdebug << " - m_ia32_sysenter_eip_msr: " << view_as_pointer(m_ia32_sysenter_eip_msr) << bfendl;
230  bfdebug << " - m_ia32_fs_base_msr: " << view_as_pointer(m_ia32_fs_base_msr) << bfendl;
231  bfdebug << " - m_ia32_gs_base_msr: " << view_as_pointer(m_ia32_gs_base_msr) << bfendl;
232 
233  bfdebug << bfendl;
234  }
235 
236 private:
237 
246 
247  x64::segment_register::type m_es_index;
248  x64::segment_register::type m_cs_index;
249  x64::segment_register::type m_ss_index;
250  x64::segment_register::type m_ds_index;
251  x64::segment_register::type m_fs_index;
252  x64::segment_register::type m_gs_index;
253  x64::segment_register::type m_ldtr_index;
254  x64::segment_register::type m_tr_index;
255 
259  x64::dr7::value_type m_dr7;
260 
261  x64::rflags::value_type m_rflags;
262 
263  gdt_x64 m_gdt;
264  idt_x64 m_idt;
265 
266  intel_x64::msrs::value_type m_ia32_debugctl_msr;
267  intel_x64::msrs::value_type m_ia32_pat_msr;
268  intel_x64::msrs::value_type m_ia32_efer_msr;
269  intel_x64::msrs::value_type m_ia32_perf_global_ctrl_msr;
270  intel_x64::msrs::value_type m_ia32_sysenter_cs_msr;
271  intel_x64::msrs::value_type m_ia32_sysenter_esp_msr;
272  intel_x64::msrs::value_type m_ia32_sysenter_eip_msr;
273  intel_x64::msrs::value_type m_ia32_fs_base_msr;
274  intel_x64::msrs::value_type m_ia32_gs_base_msr;
275 };
276 
277 #endif
gdt_x64::integer_pointer gdt_base() const override
gdt_x64::access_rights_type cs_access_rights() const override
x64::rflags::value_type rflags() const override
intel_x64::cr4::value_type cr4() const override
x64::segment_register::type fs() const override
intel_x64::msrs::value_type ia32_sysenter_esp_msr() const override
gdt_x64::base_type tr_base() const override
auto base() const
Definition: idt_x64.h:212
access_rights_type access_rights(index_type index) const
Definition: gdt_x64.h:534
gdt_x64::limit_type tr_limit() const override
intel_x64::msrs::value_type ia32_sysenter_cs_msr() const override
gdt_x64::limit_type ldtr_limit() const override
x64::segment_register::type tr() const override
gdt_x64::access_rights_type ss_access_rights() const override
gdt_x64::limit_type es_limit() const override
x64::segment_register::type ldtr() const override
gdt_x64::size_type gdt_limit() const override
intel_x64::msrs::value_type ia32_gs_base_msr() const override
gdt_x64::base_type ldtr_base() const override
uint64_t value_type
Definition: debug_x64.h:34
gdt_x64::access_rights_type fs_access_rights() const override
constexpr const auto unusable
Definition: x64.h:90
idt_x64::size_type idt_limit() const override
gdt_x64::access_rights_type es_access_rights() const override
gdt_x64::access_rights_type tr_access_rights() const override
uint64_t value_type
Definition: crs_intel_x64.h:46
gdt_x64::base_type es_base() const override
x64::segment_register::type ds() const override
intel_x64::msrs::value_type ia32_sysenter_eip_msr() const override
uintptr_t integer_pointer
Definition: idt_x64.h:159
intel_x64::msrs::value_type ia32_efer_msr() const override
gdt_x64::base_type fs_base() const override
intel_x64::msrs::value_type ia32_pat_msr() const override
uint32_t access_rights_type
Definition: gdt_x64.h:199
intel_x64::cr3::value_type cr3() const override
gdt_x64::base_type ds_base() const override
x64::segment_register::type es() const override
uint16_t size_type
Definition: idt_x64.h:158
gdt_x64::access_rights_type gs_access_rights() const override
const void * view_as_pointer(const T val)
gdt_x64::base_type gs_base() const override
uint64_t base_type
Definition: gdt_x64.h:197
uint64_t value_type
Definition: rflags_x64.h:39
intel_x64::cr0::value_type cr0() const override
gdt_x64::limit_type fs_limit() const override
gdt_x64::base_type cs_base() const override
gdt_x64::access_rights_type ds_access_rights() const override
gdt_x64::access_rights_type ldtr_access_rights() const override
integer_pointer base() const
Definition: gdt_x64.h:260
~vmcs_intel_x64_host_vm_state() override=default
size_type limit() const
Definition: gdt_x64.h:270
gdt_x64::base_type ss_base() const override
intel_x64::msrs::value_type ia32_fs_base_msr() const override
uint64_t value_type
idt_x64::integer_pointer idt_base() const override
intel_x64::msrs::value_type ia32_debugctl_msr() const override
x64::segment_register::type gs() const override
intel_x64::msrs::value_type ia32_perf_global_ctrl_msr() const override
uintptr_t integer_pointer
Definition: gdt_x64.h:196
uint32_t limit_type
Definition: gdt_x64.h:198
uint64_t value_type
x64::segment_register::type cs() const override
x64::segment_register::type ss() const override
x64::dr7::value_type dr7() const override
uint16_t size_type
Definition: gdt_x64.h:194
gdt_x64::limit_type ss_limit() const override
auto limit() const
Definition: idt_x64.h:222
gdt_x64::limit_type ds_limit() const override
gdt_x64::limit_type gs_limit() const override
uint64_t value_type
gdt_x64::limit_type cs_limit() const override