1. 08 6月, 2018 13 次提交
  2. 07 6月, 2018 17 次提交
  3. 06 6月, 2018 10 次提交
    • S
    • S
      conf: Use resrc=tpm in case of TPM passthrough following docs · ac23367c
      Stefan Berger 提交于
      Fix the resrc field for the TPM passthrough case to show tpm.
      This fixes the code to follow the documentation.
      Signed-off-by: NStefan Berger <stefanb@linux.vnet.ibm.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      ac23367c
    • S
      conf: Audit TPM emulator device at domain startup · 6f06a6c1
      Stefan Berger 提交于
      Extend the existing auditing with auditing for the TPM emulator.
      Signed-off-by: NStefan Berger <stefanb@linux.vnet.ibm.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      6f06a6c1
    • S
      qemu: Run swtpm_setup in unprivileged mode for a TPM 2.0 · ff907a46
      Stefan Berger 提交于
      swtpm_setup can be run for a TPM 2 in unprivileged mode assuming
      XDG_CONFIG_HOME has been set and the necessary configuration files
      have been put into that directory.
      
      For current reference also see this link:
      
      https://github.com/stefanberger/swtpm/pull/63Signed-off-by: NStefan Berger <stefanb@linux.vnet.ibm.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      ff907a46
    • S
      a55414f6
    • S
      qemu: Add swtpm to emulator cgroup · 3f1a7070
      Stefan Berger 提交于
      Add the external swtpm to the emulator cgroup so that upper limits of CPU
      usage can be enforced on the emulated TPM.
      
      To enable this we need to have the swtpm write its process id (pid) into a
      file. We then read it from the file to configure the emulator cgroup.
      
      The PID file is created in /var/run/libvirt/qemu/swtpm:
      
      [root@localhost swtpm]# ls -lZ /var/run/libvirt/qemu/swtpm/
      total 4
      -rw-r--r--. 1 tss  tss  system_u:object_r:qemu_var_run_t:s0          5 Apr 10 12:26 1-testvm-swtpm.pid
      srw-rw----. 1 qemu qemu system_u:object_r:svirt_image_t:s0:c597,c632 0 Apr 10 12:26 1-testvm-swtpm.sock
      
      The swtpm command line now looks as follows:
      
      root@localhost testvm]# ps auxZ | grep swtpm | grep socket | grep -v grep
      system_u:system_r:virtd_t:s0:c597,c632 tss 18697 0.0  0.0 28172 3892 ?       Ss   16:46   0:00 /usr/bin/swtpm socket --daemon --ctrl type=unixio,path=/var/run/libvirt/qemu/swtpm/1-testvm-swtpm.sock,mode=0600 --tpmstate dir=/var/lib/libvirt/swtpm/485d0004-a48f-436a-8457-8a3b73e28568/tpm1.2/ --log file=/var/log/swtpm/libvirt/qemu/testvm-swtpm.log --pid file=/var/run/libvirt/qemu/swtpm/1-testvm-swtpm.pid
      Signed-off-by: NStefan Berger <stefanb@linux.vnet.ibm.com>
      Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      3f1a7070
    • S
      conf: Add support for choosing emulation of a TPM 2.0 · 8737578d
      Stefan Berger 提交于
      This patch extends the TPM's device XML with TPM 2.0 support. This only works
      for the emulator type backend and looks as follows:
      
          <tpm model='tpm-tis'>
            <backend type='emulator' version='2.0'/>
          </tpm>
      
      The swtpm process now has --tpm2 as an additional parameter:
      
      system_u:system_r:svirt_t:s0:c597,c632 tss 18477 11.8  0.0 28364  3868 ?        Rs   11:13  13:50 /usr/bin/swtpm socket --daemon --ctrl type=unixio,path=/var/run/libvirt/qemu/swtpm/testvm-swtpm.sock,mode=0660 --tpmstate dir=/var/lib/libvirt/swtpm/testvm/tpm2,mode=0640 --log file=/var/log/swtpm/libvirt/qemu/testvm-swtpm.log --tpm2 --pid file=/var/run/libvirt/qemu/swtpm/testvm-swtpm.pid
      
      The version of the TPM can be changed and the state of the TPM is preserved.
      Signed-off-by: NStefan Berger <stefanb@linux.vnet.ibm.com>
      Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      8737578d
    • S
      security: Label the external swtpm with SELinux labels · 2fc665bb
      Stefan Berger 提交于
      In this patch we label the swtpm process with SELinux labels. We give it the
      same label as the QEMU process has. We label its state directory and files
      as well. We restore the old security labels once the swtpm has terminated.
      
      The file and process labels now look as follows:
      
      Directory: /var/lib/libvirt/swtpm
      
      [root@localhost swtpm]# ls -lZ
      total 4
      rwx------. 2 tss  tss  system_u:object_r:svirt_image_t:s0:c254,c932 4096 Apr  5 16:46 testvm
      
      [root@localhost testvm]# ls -lZ
      total 8
      -rw-r--r--. 1 tss tss system_u:object_r:svirt_image_t:s0:c254,c932 3648 Apr  5 16:46 tpm-00.permall
      
      The log in /var/log/swtpm/libvirt/qemu is labeled as follows:
      
      -rw-r--r--. 1 tss tss system_u:object_r:svirt_image_t:s0:c254,c932 2237 Apr  5 16:46 vtpm.log
      
      [root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep swtpm | grep ctrl | grep -v grep
      system_u:system_r:svirt_t:s0:c254,c932 tss 25664 0.0  0.0 28172  3892 ?        Ss   16:57   0:00 /usr/bin/swtpm socket --daemon --ctrl type=unixio,path=/var/run/libvirt/qemu/swtpm/testvm-swtpm.sock,mode=0660 --tpmstate dir=/var/lib/libvirt/swtpm/testvm/tpm1.2 --log file=/var/log/swtpm/libvirt/qemu/testvm-swtpm.log
      
      [root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep qemu | grep tpm | grep -v grep
      system_u:system_r:svirt_t:s0:c254,c932 qemu 25669 99.0  0.0 3096704 48500 ?    Sl   16:57   3:28 /bin/qemu-system-x86_64 [..]
      Signed-off-by: NStefan Berger <stefanb@linux.vnet.ibm.com>
      Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      2fc665bb
    • S
      tests: Add test cases for external swtpm TPM emulator · f264df2d
      Stefan Berger 提交于
      This patch adds extensions to existing test cases and specific test cases
      for the tpm-emulator.
      Signed-off-by: NStefan Berger <stefanb@linux.vnet.ibm.com>
      Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      f264df2d
    • S
      qemu: Add support for external swtpm TPM emulator · 69122bc2
      Stefan Berger 提交于
      This patch adds support for an external swtpm TPM emulator. The XML for
      this type of TPM looks as follows:
      
       <tpm model='tpm-tis'>
         <backend type='emulator'/>
       </tpm>
      
      The XML will currently only start a TPM 1.2.
      
      Upon first start, libvirt will run `swtpm_setup`, which will simulate the
      manufacturing of a TPM and create certificates for it and write them into
      NVRAM locations of the emulated TPM.
      
      After that libvirt starts the swtpm TPM emulator using the `swtpm` executable.
      
      Once the VM terminates, libvirt uses the swtpm_ioctl executable to gracefully
      shut down the `swtpm` in case it is still running (QEMU did not send shutdown)
      or clean up the socket file.
      
      The above mentioned executables must be found in the PATH.
      
      The executables can either be run as root or started as root and switch to
      the tss user. The requirement for the tss user comes through 'tcsd', which
      is used for the simulation of the manufacturing. Which user is used can be
      configured through qemu.conf. By default 'tss' is used.
      
      The swtpm writes out state into files. The state is kept in /var/lib/libvirt/swtpm:
      
      [root@localhost libvirt]# ls -lZ | grep swtpm
      
      drwx--x--x. 7 root root unconfined_u:object_r:virt_var_lib_t:s0 4096 Apr  5 16:22 swtpm
      
      The directory /var/lib/libvirt/swtpm maintains per-TPM state directories.
      (Using the uuid of the VM for that since the name can change per VM renaming but
       we need a stable directory name.)
      
      [root@localhost swtpm]# ls -lZ
      total 4
      drwx------. 2 tss  tss  system_u:object_r:virt_var_lib_t:s0          4096 Apr  5 16:46 485d0004-a48f-436a-8457-8a3b73e28568
      
      [root@localhost 485d0004-a48f-436a-8457-8a3b73e28568]# ls -lZ
      total 4
      drwx------. 2 tss tss system_u:object_r:virt_var_lib_t:s0 4096 Apr 10 21:34 tpm1.2
      
      [root@localhost tpm1.2]# ls -lZ
      total 8
      -rw-r--r--. 1 tss tss system_u:object_r:virt_var_lib_t:s0 3648 Apr  5 16:46 tpm-00.permall
      
      The directory /var/run/libvirt/qemu/swtpm/ hosts the swtpm.sock that
      QEMU uses to communicate with the swtpm:
      
      root@localhost domain-1-testvm]# ls -lZ
      total 0
      srw-------. 1 qemu qemu system_u:object_r:svirt_image_t:s0:c597,c632  0 Apr  6 10:24 1-testvm-swtpm.sock
      
      The logfile for the swtpm is in /var/log/swtpm/libvirt/qemu:
      
      [root@localhost-3 qemu]# ls -lZ
      total 4
      -rw-------. 1 tss tss unconfined_u:object_r:var_log_t:s0 2199 Apr  6 14:01 testvm-swtpm.log
      
      The processes are labeled as follows:
      
      [root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep swtpm | grep socket | grep -v grep
      system_u:system_r:virtd_t:s0-s0:c0.c1023 tss 18697 0.0  0.0 28172 3892 ?       Ss   16:46   0:00 /usr/bin/swtpm socket --daemon --ctrl type=unixio,path=/var/run/libvirt/qemu/swtpm/1-testvm-swtpm.sock,mode=0600 --tpmstate dir=/var/lib/libvirt/swtpm/485d0004-a48f-436a-8457-8a3b73e28568/tpm1.2 --log file=/var/log/swtpm/libvirt/qemu/testvm-swtpm.log
      
      [root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep qemu | grep tpm | grep -v grep
      system_u:system_r:svirt_t:s0:c413,c430 qemu 18702 2.5  0.0 3036052 48676 ?     Sl   16:46   0:08 /bin/qemu-system-x86_64 [...]
      Signed-off-by: NStefan Berger <stefanb@linux.vnet.ibm.com>
      Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      69122bc2