vmcs_intel_x64_check_host.cpp
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 // Author: Connor Davis <davisc@ainfosec.com>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 
23 #include <vmcs/vmcs_intel_x64.h>
29 
30 using namespace intel_x64;
31 using namespace vmcs;
32 
33 void
35 {
39 }
40 
41 void
43 {
52 }
53 
54 void
56 {
57  auto cr0 = vmcs::host_cr0::get();
58  auto ia32_vmx_cr0_fixed0 = msrs::ia32_vmx_cr0_fixed0::get();
59  auto ia32_vmx_cr0_fixed1 = msrs::ia32_vmx_cr0_fixed1::get();
60 
61  if (0 != ((~cr0 & ia32_vmx_cr0_fixed0) | (cr0 & ~ia32_vmx_cr0_fixed1)))
62  {
63  bferror << " failed: check_host_cr0_for_unsupported_bits" << bfendl;
64  bferror << " - ia32_vmx_cr0_fixed0: " << view_as_pointer(ia32_vmx_cr0_fixed0) << bfendl;
65  bferror << " - ia32_vmx_cr0_fixed1: " << view_as_pointer(ia32_vmx_cr0_fixed1) << bfendl;
66  bferror << " - cr0: " << view_as_pointer(cr0) << bfendl;
67 
68  throw std::logic_error("invalid cr0");
69  }
70 }
71 
72 void
74 {
75  auto cr4 = vmcs::host_cr4::get();
76  auto ia32_vmx_cr4_fixed0 = msrs::ia32_vmx_cr4_fixed0::get();
77  auto ia32_vmx_cr4_fixed1 = msrs::ia32_vmx_cr4_fixed1::get();
78 
79  if (0 != ((~cr4 & ia32_vmx_cr4_fixed0) | (cr4 & ~ia32_vmx_cr4_fixed1)))
80  {
81  bferror << " failed: check_host_cr4_for_unsupported_bits" << bfendl;
82  bferror << " - ia32_vmx_cr4_fixed0: " << view_as_pointer(ia32_vmx_cr4_fixed0) << bfendl;
83  bferror << " - ia32_vmx_cr4_fixed1: " << view_as_pointer(ia32_vmx_cr4_fixed1) << bfendl;
84  bferror << " - cr4: " << view_as_pointer(cr4) << bfendl;
85 
86  throw std::logic_error("invalid cr4");
87  }
88 }
89 
90 void
92 {
94  throw std::logic_error("host cr3 too large");
95 }
96 
97 void
99 {
101  throw std::logic_error("host sysenter esp must be canonical");
102 }
103 
104 void
106 {
108  throw std::logic_error("host sysenter eip must be canonical");
109 }
110 
111 void
113 {
115  return;
116 
118  throw std::logic_error("host perf global ctrl msr reserved bits must be 0");
119 }
120 
121 void
123 {
125  return;
126 
128  throw std::logic_error("pat0 has a reserved memory type");
129 
131  throw std::logic_error("pat1 has a reserved memory type");
132 
134  throw std::logic_error("pat2 has a reserved memory type");
135 
137  throw std::logic_error("pat3 has a reserved memory type");
138 
140  throw std::logic_error("pat4 has a reserved memory type");
141 
143  throw std::logic_error("pat5 has a reserved memory type");
144 
146  throw std::logic_error("pat6 has a reserved memory type");
147 
149  throw std::logic_error("pat7 has a reserved memory type");
150 }
151 
152 void
154 {
156  return;
157 
159  throw std::logic_error("host_ia32_efer reserved bits must be 0 if "
160  "load_ia32_efer exit control is enabled");
161 
164 
166  throw std::logic_error("host addr space is 0, but efer.lma is 1");
167 
169  throw std::logic_error("host addr space is 1, but efer.lma is 0");
170 
172  return;
173 
174  if (!lme && lma)
175  throw std::logic_error("efer.lme is 0, but efer.lma is 1");
176 
177  if (lme && !lma)
178  throw std::logic_error("efer.lme is 1, but efer.lma is 0");
179 }
180 
181 void
183 {
199 }
200 
201 void
203 {
205  throw std::logic_error("host es ti flag must be 0");
206 
208  throw std::logic_error("host es rpl flag must be 0");
209 }
210 
211 void
213 {
215  throw std::logic_error("host cs ti flag must be 0");
216 
218  throw std::logic_error("host cs rpl flag must be 0");
219 }
220 
221 void
223 {
225  throw std::logic_error("host ss ti flag must be 0");
226 
228  throw std::logic_error("host ss rpl flag must be 0");
229 }
230 
231 void
233 {
235  throw std::logic_error("host ds ti flag must be 0");
236 
238  throw std::logic_error("host ds rpl flag must be 0");
239 }
240 
241 void
243 {
245  throw std::logic_error("host fs ti flag must be 0");
246 
248  throw std::logic_error("host fs rpl flag must be 0");
249 }
250 
251 void
253 {
255  throw std::logic_error("host gs ti flag must be 0");
256 
258  throw std::logic_error("host gs rpl flag must be 0");
259 }
260 
261 void
263 {
265  throw std::logic_error("host tr ti flag must be 0");
266 
268  throw std::logic_error("host tr rpl flag must be 0");
269 }
270 
271 void
273 {
274  if (vmcs::host_cs_selector::get() == 0)
275  throw std::logic_error("host cs cannot equal 0");
276 }
277 
278 void
280 {
281  if (vmcs::host_tr_selector::get() == 0)
282  throw std::logic_error("host tr cannot equal 0");
283 }
284 
285 void
287 {
289  return;
290 
291  if (vmcs::host_ss_selector::get() == 0)
292  throw std::logic_error("host ss cannot equal 0");
293 }
294 
295 void
297 {
299  throw std::logic_error("host fs base must be canonical");
300 }
301 
302 void
304 {
306  throw std::logic_error("host gs base must be canonical");
307 }
308 
309 void
311 {
313  throw std::logic_error("host gdtr base must be canonical");
314 }
315 
316 void
318 {
320  throw std::logic_error("host idtr base must be canonical");
321 }
322 
323 void
325 {
327  throw std::logic_error("host tr base must be canonical");
328 }
329 
330 void
332 {
337 }
338 
339 void
341 {
343  return;
344 
346  throw std::logic_error("ia 32e mode must be 0 if efer.lma == 0");
347 
349  throw std::logic_error("host addr space must be 0 if efer.lma == 0");
350 }
351 
352 void
354 {
356  return;
357 
359  throw std::logic_error("host addr space must be 1 if efer.lma == 1");
360 }
361 
362 void
364 {
366  return;
367 
369  throw std::logic_error("ia 32e mode must be disabled if host addr space is disabled");
370 
372  throw std::logic_error("cr4 pcide must be disabled if host addr space is disabled");
373 
374  if ((vmcs::host_rip::get() & 0xFFFFFFFF00000000) != 0)
375  throw std::logic_error("rip bits 63:32 must be 0 if host addr space is disabled");
376 }
377 
378 void
380 {
382  return;
383 
385  throw std::logic_error("cr4 pae must be enabled if host addr space is enabled");
386 
388  throw std::logic_error("host rip must be canonical");
389 }
auto is_physical_address_valid(T addr)
Definition: x64.h:126
auto memory_type_reserved(T memory_type)
const void * view_as_pointer(const T val)
auto is_address_canonical(T addr)
Definition: x64.h:118
auto is_enabled()