vmcs_intel_x64_check.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_CHECK_H
23 #define VMCS_INTEL_X64_CHECK_H
24 
25 #include <type_traits>
26 #include <intrinsics/x64.h>
28 
34 
35 // *INDENT-OFF*
36 
37 namespace intel_x64
38 {
39 namespace vmcs
40 {
41 namespace check
42 {
43 
44 void all();
60 void control_vpid_checks();
67 
73 
82 
83 void host_state_all();
93 
110 
116 
117 void guest_state_all();
133 
152 void guest_cs_limit();
153 void guest_ss_limit();
154 void guest_ds_limit();
155 void guest_es_limit();
156 void guest_gs_limit();
157 void guest_fs_limit();
180 void guest_ds_dpl();
181 void guest_es_dpl();
182 void guest_fs_dpl();
183 void guest_gs_dpl();
197 void guest_cs_granularity();
198 void guest_ss_granularity();
199 void guest_ds_granularity();
200 void guest_es_granularity();
201 void guest_fs_granularity();
202 void guest_gs_granularity();
213 void guest_tr_granularity();
222 
228 
230 void guest_rip_upper_bits();
231 void guest_rip_valid_addr();
233 void guest_rflags_vm_bit();
235 
262 
263 void guest_pdptes_all();
266 
267 template<class MA, class C,
268  class = typename std::enable_if<std::is_integral<MA>::value>::type,
269  class = typename std::enable_if<std::is_integral<C>::value>::type>
270 auto control_reserved_properly_set(MA msr_addr, C ctls, const char *ctls_name)
271 {
272  using namespace vmcs::primary_processor_based_vm_execution_controls;
273 
274  auto allowed0 = (msrs::get(msr_addr) & 0x00000000FFFFFFFFUL);
275  auto allowed1 = ((msrs::get(msr_addr) >> 32) & 0x00000000FFFFFFFFUL);
276  auto allowed1_failed = false;
277 
278  ctls &= 0x00000000FFFFFFFFUL;
279 
280  if ((allowed0 & ctls) != allowed0)
281  {
282  bferror << " failed: controls_reserved_properly_set" << '\n';
283  bferror << " - allowed0: " << view_as_pointer(allowed0) << '\n';
284  bferror << " - bad ctls: " << view_as_pointer(ctls) << '\n';
285 
286  throw std::logic_error("invalid "_s + ctls_name);
287  }
288 
289  allowed1_failed = (ctls & ~allowed1) != 0UL;
290 
292  allowed1_failed = allowed1_failed && activate_secondary_controls::is_enabled();
293 
294  if (allowed1_failed)
295  {
296  bferror << " failed: check_control_ctls_reserved_properly_set" << '\n';
297  bferror << " - allowed1: " << view_as_pointer(allowed1) << '\n';
298  bferror << " - bad ctls: " << view_as_pointer(ctls) << '\n';
299 
300  throw std::logic_error("invalid "_s + ctls_name);
301  }
302 }
303 
304 template<class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
305 auto memory_type_reserved(T memory_type)
306 {
307  switch (memory_type)
308  {
315  return false;
316 
317  default:
318  return true;
319  }
320 }
321 
322 }
323 }
324 }
325 
326 // *INDENT-ON*
327 
328 #endif
auto memory_type_reserved(T memory_type)
constexpr const auto write_back
Definition: x64.h:46
constexpr const auto uncacheable_minus
Definition: x64.h:47
auto get(A addr) noexcept
const void * view_as_pointer(const T val)
constexpr const auto write_protected
Definition: x64.h:45
constexpr const auto uncacheable
Definition: x64.h:42
auto control_reserved_properly_set(MA msr_addr, C ctls, const char *ctls_name)
constexpr const auto write_through
Definition: x64.h:44
constexpr const auto write_combining
Definition: x64.h:43