Permalink
Browse files

umip impl

  • Loading branch information...
daveti committed Dec 9, 2016
1 parent baa6f49 commit 0da5abf7e41b7fd9750a1a559db8b2f427745f88
Showing with 50 additions and 1 deletion.
  1. +38 −1 chipsec/hal/cpu.py
  2. +12 −0 chipsec/utilcmd/cpu_cmd.py
View
@@ -57,6 +57,8 @@ class CPU(hal_base.HALBase):
def __init__(self, cs):
super(CPU, self).__init__(cs)
self.helper = cs.helper
# daveti: internal debug flag
self.debug = True
def read_cr(self, cpu_thread_id, cr_number ):
value = self.helper.read_cr( cpu_thread_id, cr_number )
@@ -196,4 +198,39 @@ def dump_page_tables_all( self ):
if logger().HAL: logger().log( '[cpu%d] found paging hierarchy base (CR3): 0x%08X' % (tid,cr3) )
self.dump_page_tables( cr3 )
#
# Check for UMIP (User-Mode Instruction Prevention, bit 11 of CR4)
# Dec 8, 2016
# daveti
#
def is_umip_enabled_all(self):
umip_bit_mask = 0x0800
for tid in range(self.cs.msr.get_cpu_thread_count()):
cr4 = self.read_cr(tid, 4)
if self.debug:
print('[cpu%d] dumping CR4: 0x%08X' % (tid, cr4))
if not (cr4 & umip_bit_mask):
if logger().HAL:
logger().log('[cpu%d] found UMIP disabled (CR4): 0x%08X' % (tid, cr4))
return False
return True
#
# Enable UMIP for all CPUs
# Dec 9, 2016
# daveti
#
def enable_umip_all(self):
umip_bit_mask = 0x0800
for tid in range(self.cs.msr.get_cpu_thread_count()):
cr4 = self.read_cr(tid, 4)
if self.debug:
print('[cpud%d] dumping current CR4: 0x%08X' % (tid, cr4))
cr4 |= umip_bit_mask
self.write_cr(tid, 4, cr4)
cr4 = self.read_cr(tid, 4)
if self.debug:
print('[cpu%d] dumping new CR4: 0x%08X' % (tid, cr4))
if logger().HAL:
logger().log('[cpu%d] had UMIP enabled (CR4): 0x%08X' % (tid, cr4))
View
@@ -40,6 +40,7 @@ class CPUCommand(BaseCommand):
>>> chipsec_util cpu cr <cpu_id> <cr_number> [value]
>>> chipsec_util cpu cpuid <eax> [ecx]
>>> chipsec_util cpu pt [paging_base_cr3]
>>> chipsec_util cpu umip <check|enable>
Examples:
@@ -48,6 +49,8 @@ class CPUCommand(BaseCommand):
>>> chipsec_util cpu cr 0 4 0x0
>>> chipsec_util cpu cpuid 40000000
>>> chipsec_util cpu pt
>>> chipsec_util cpu umip check
>>> chipsec_util cpu umip enable
"""
def requires_driver(self):
@@ -144,6 +147,15 @@ def run(self):
self.logger.log( "[CHIPSEC][cpu%d] dumping paging hierarchy to '%s'..." % (tid,pt_fname) )
self.cs.cpu.dump_page_tables( cr3, pt_fname )
# daveti: umip handling
elif op == "umip":
if len(self.argv) == 4:
if self.argv[3] == "check":
self.logger.log( "[CHIPSEC] UMIP enabled for all: %r" % self.cs.cpu.is_umip_enabled_all())
elif self.argv[3] == "enable":
self.cs.cpu.enable_umip_all()
self.logger.log( "[CHIPSEC] UMIP enabled for all" )
else:
print CPUCommand.__doc__
return

0 comments on commit 0da5abf

Please sign in to comment.