Home | History | Annotate | Download | only in security_SMMLocked
      1 #!/usr/bin/python
      2 #
      3 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 import logging, os
      8 from autotest_lib.client.bin import test, utils
      9 from autotest_lib.client.common_lib import error
     10 from autotest_lib.client.cros.power import power_utils
     11 
     12 class security_SMMLocked(test.test):
     13     """
     14     Verify SMM has SMRAM unmapped and that the SMM registers are locked.
     15     """
     16     version = 1
     17     executable = 'smm'
     18 
     19     def setup(self):
     20         os.chdir(self.srcdir)
     21         utils.make(self.executable)
     22 
     23     def run_once(self):
     24         errors = 0
     25         cpu_arch = utils.get_cpu_arch()
     26         if cpu_arch == "arm":
     27             logging.debug('ok: skipping SMM test for %s.', cpu_arch)
     28             return
     29 
     30         cpu_arch = power_utils.get_x86_cpu_arch()
     31         if cpu_arch == 'Stoney':
     32             # The SMM registers (MSRC001_0112 and MSRC001_0113) can be
     33             # locked from being altered by setting MSRC001_0015[SmmLock].
     34             # Bit 0 : 1=SMM code in the ASeg and TSeg range and the SMM
     35             #         registers are read-only and SMI interrupts are
     36             #         not intercepted in SVM for Stoney.
     37             Stoney_SMMLock = {'0xc0010015':  [('0', 1)]}
     38             self._registers = power_utils.Registers()
     39             errors = self._registers.verify_msr(Stoney_SMMLock)
     40         else:
     41             r = utils.run("%s/%s" % (self.srcdir, self.executable),
     42                           stdout_tee=utils.TEE_TO_LOGS,
     43                           stderr_tee=utils.TEE_TO_LOGS,
     44                           ignore_status=True)
     45             if r.exit_status != 0 or len(r.stderr) > 0:
     46                 raise error.TestFail(r.stderr)
     47             if 'skipping' in r.stdout:
     48                 logging.debug(r.stdout)
     49                 return
     50             if 'ok' not in r.stdout:
     51                 raise error.TestFail(r.stdout)
     52         if errors:
     53             logging.error('Test Failed for %s', cpu_arch)
     54             raise error.TestFail(r.stdout)
     55