using TPM2 NVRAM for storing LUKS password
A message that is not in the archive (sent off-list or not yet received): [email protected]
Patrick Ohly
Quoted 6 lines · Stefan Berger
Quoted 5 lines · Patrick Ohly
I'm unsure whether this is an issue in tpm2.0-tools, in swtpm2, or my
usage of both. Let me describe in more details what commands are used.
Quoted 8 lines
Quoted 2 lines
The virtual TPM gets initialized with:
swtpm_setup_oe.sh --tpm2 --tpm-state ... --createe
swtpm_setup.sh, which this one seems to be derived from, should only be
run once to simulate the TPM manufacturing. It's destructive to existing
TPM 2 state. Are you running this every time?
It's run once before the test, with a clean --tpm-state test. Then follow the install part, the reboot, and then booting into the installed image.
Quoted 26 lines
Quoted 26 lines
The commands that run as part of installation are:
tpm2_takeownership -o ownerpass -e endorsepass -l lockpasstpm2_nvdefine-x0x1500001-s 40 -a0x40000001-t0x80020002-P ownerpass
tpm2_nvwrite -x0x1500001-a0x40000001-f/dev/shm/keydir.sVrmLQ/keyfile-P ownerpass
52 45 46 4b 49 54 5f 30 70 e6 2b b9 ca 0c 1c 00 1d 6d eb 58 a1 7a cf 0d 1d 71 46 bc fd 7a 80 a0 8f 8b 0a 30 fc 89 9b dbtpm2_nvlist
1 NV indexes defined.0. NV Index:
0x1500001
{
Hash algorithm(nameAlg):11
The Index attributes(attributes):0xa0020002 The size of the data area(dataSize):40 }tpm2_nvreadlock -x
0x1500001-a0x40000001-P ownerpassThen the initramfs does:
tpm2_nvlist
0 NV indexes defined.
Quoted 6 lines
Quoted 3 lines
tpm2_nvread -x
0x1500001-a0x40000001-s 40 -o 0 -P ownerpass
ERROR: Failed to read NVRAM area at index0x1500001(22020097). Error:0x28bI did all of this with the latest versions of libtpms and swtpm and it works fine for me.
Which TPM tools (project and revision?) did you use?
Signature · 6 lines
Best Regards, Patrick Ohly The content of this message is my personal opinion only and although I am an employee of Intel, the statements I make here in no way represent Intel's position on the issue, nor am I authorized to speak on behalf of Intel on this matter.
Stefan Berger
Quoted 9 lines · Patrick Ohly
Quoted 8 lines · Stefan Berger
Quoted 7 lines · Patrick Ohly
I'm unsure whether this is an issue in tpm2.0-tools, in swtpm2, or my
usage of both. Let me describe in more details what commands are used.The virtual TPM gets initialized with:
swtpm_setup_oe.sh --tpm2 --tpm-state ... --createe
Quoted 8 lines
Quoted 5 lines
swtpm_setup.sh, which this one seems to be derived from, should only be
run once to simulate the TPM manufacturing. It's destructive to existing
TPM 2 state. Are you running this every time?It's run once before the test, with a clean --tpm-state test. Then follow the install part, the reboot, and then booting into the installed image.
Nevertheless I'll extend swtpm_setup with --overwrite and --not-overwrite options to allow overwriting of existing state or to not allow it, and error out if state is found but the options are omitted.
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
The commands that run as part of installation are:
tpm2_takeownership-o ownerpass -e endorsepass -l lockpasstpm2_nvdefine-x0x1500001-s 40 -a0x40000001-t0x80020002
-P ownerpasstpm2_nvwrite -x 0x1500001 -a 0x40000001 -f /dev/shm/keydir.sVrmLQ/keyfile -P ownerpass 52 45 46 4b 49 54 5f 30 70 e6 2b b9 ca 0c 1c 00 1d 6d eb 58 a17a cf 0d 1d 71 46 bc fd 7a 80 a0 8f 8b 0a 30 fc 89 9b db
tpm2_nvlist 1 NV indexes defined. 0. NV Index: 0x1500001 { Hash algorithm(nameAlg):11 The Index attributes(attributes):0xa0020002 The size of the data area(dataSize):40 } tpm2_nvreadlock -x 0x1500001 -a 0x40000001 -P ownerpassThen the initramfs does:
tpm2_nvlist
0 NV indexes defined.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
tpm2_nvread -x 0x1500001 -a 0x40000001 -s 40 -o 0 -P ownerpass ERROR: Failed to read NVRAM area at index 0x1500001(22020097). Error:0x28b
I did all of this with the latest versions of libtpms and swtpm and it works fine for me.
Which TPM tools (project and revision?) did you use?
I used the tpm2-tools and tpm2-tss available from Fedora 26.
Stefan
Patrick Ohly
Quoted 10 lines · Stefan Berger
Quoted 7 lines · Patrick Ohly
Quoted 3 lines · Stefan Berger
I did all of this with the latest versions of libtpms and swtpm and
it works fine for me.Which TPM tools (project and revision?) did you use?
I used the tpm2-tools and tpm2-tss available from Fedora 26.
That's 2.1.1, which is a bit more recent than the 2.1.0 that I am currently building with meta-measured. But that difference is minor.
How did you connect to swtpm from inside QEMU? Did your test involve restarting swtpm?
When I reboot the virtual machine without restarting QEMU and swtpm, then NVRAM survives the reboot.
But when I stop QEMU and swtpm and then boot up again, swtpm modifies the tpm2-00.permall data file when QEMU connects and the previously defined NVRAM entry is gone. This can already be reproduced with just "tpm2_nvdefine".
Here's roughly what I ran:
swtpm socket --ctrl type=unixio,path=/tmp/swtpm.sock --tpmstate dir=tpm --log file=swtpm.log --tpm2 &
qemu ... -chardev 'socket,id=chrtpm0,path=/tmp/swtpm.sock' -tpmdev emulator,id=tpm0,chardev=chrtpm0 -device tpm-tis,tpmdev=tpm0 ...
# export TPM2TOOLS_TCTI_NAME=device
# tpm2_nvdefine -x 0x1500001 -s 40 -a 0x40000001 -t 0x80020002
^ac
(qemu) qswtpm terminates now and one can take a copy of the current state:
cp tpm/tpm2-00.permall /tmp
Then start both swtpm and qemu again as above, without any TPM operations from userspace, and check:
cmp tpm/tpm2-00.permall /tmp/tpm2-00.permall
tpm/tpm2-00.permall /tmp/tpm2-00.permall differ: byte 313, line 1BTW, should the swtpm instance above really terminate when qemu disconnects? It currently does, although -terminate is not given.
How can I enable more debug logging inside swtpm? Increasing the level does not really provide much useful information.
Signature · 6 lines
Best Regards, Patrick Ohly The content of this message is my personal opinion only and although I am an employee of Intel, the statements I make here in no way represent Intel's position on the issue, nor am I authorized to speak on behalf of Intel on this matter.
Stefan Berger
Quoted 6 lines · Patrick Ohly
Quoted 5 lines · Stefan Berger
Quoted 4 lines · Patrick Ohly
Quoted 3 lines · Stefan Berger
I did all of this with the latest versions of libtpms and swtpm and
it works fine for me.
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Which TPM tools (project and revision?) did you use?
I used the tpm2-tools and tpm2-tss available from Fedora 26.
That's 2.1.1, which is a bit more recent than the 2.1.0 that I am currently building with meta-measured. But that difference is minor.
How did you connect to swtpm from inside QEMU? Did your test involve restarting swtpm?
Yes.
My swtpm command line looks like this:
#> ls -l /tmp/mytpm1
total 16
-rw-rw-r--. 1 stefanb stefanb 16384 Nov 10 06:26 tpm2-00.permall #> swtpm socket --tpmstate dir=/tmp/mytpm1 --ctrl type=unixio,path=/tmp/mytpm1/ctrl.sock --tpm2
The QEMU command line looks like this:
# sudo ./x86_64-softmmu/qemu-system-x86_64 -vnc :10 -enable-kvm -m 1024 -boot d -L /usr/share/seabios -bios bios-256k.bin -boot menu=on --chardev socket,id=chrtpm,path=/tmp/mytpm1/ctrl.sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0 -monitor stdio -chardev file,id=pts2,path=/tmp/seabios.log -device isa-serial,chardev=pts2 /var/lib/libvirt/images/FC26
Quoted 3 lines
When I reboot the virtual machine without restarting QEMU and swtpm, then NVRAM survives the reboot.
A possibility could be that the TPM 2's state file was not written. If I was to try to use a tpm2-00.permall file that swtpm doesn't have access to, because it's being owned by another user, then that could happen. But I see errors being logged that the file cannot be written to. There isn't anything that would issue a TPM2_Clear(), right?
Other possibilities, you have an old libtpms library that's being picked up that may have had a bug? 'ldconfig -v' only shows one libtpms, right?And it's the one you compiled from recent code...
I have test cases in the swtpm test suite that create NVRAM areas (with counters) and shut the TPM 2 down and resume it and also resume from previously stored state. So, there is coverage for NVRAM to a certain extent. 'make check' on swtpm succeeds for you, right?
Quoted 21 lines
But when I stop QEMU and swtpm and then boot up again, swtpm modifies the tpm2-00.permall data file when QEMU connects and the previously defined NVRAM entry is gone. This can already be reproduced with just "
tpm2_nvdefine".Here's roughly what I ran:
swtpm socket --ctrl type=unixio,path=/tmp/swtpm.sock --tpmstate dir=tpm --log file=swtpm.log --tpm2 & qemu ... -chardev 'socket,id=chrtpm0,path=/tmp/swtpm.sock' -tpmdev emulator,id=tpm0,chardev=chrtpm0 -device tpm-tis,tpmdev=tpm0 ... # export TPM2TOOLS_TCTI_NAME=device # tpm2_nvdefine -x 0x1500001 -s 40 -a 0x40000001 -t 0x80020002 ^ac (qemu) qswtpm terminates now and one can take a copy of the current state:
cp tpm/tpm2-00.permall /tmp
Quoted 8 lines
Then start both swtpm and qemu again as above, without any TPM operations from userspace, and check:
cmp tpm/tpm2-00.permall /tmp/tpm2-00.permall tpm/tpm2-00.permall /tmp/tpm2-00.permall differ: byte 313, line 1BTW, should the swtpm instance above really terminate when qemu disconnects? It currently does, although -terminate is not given.
It is terminated by QEMU issuing a shutdown on it. I think it's better than leaving stale swtpm processes running.
Quoted 4 lines
How can I enable more debug logging inside swtpm? Increasing the level does not really provide much useful information.
There's not much debugging output inside the TPM 2 code. Some fatal errors, such as not swtpm not being able to write the TPM2 state file should show up, though.
Stefan
Patrick Ohly
Quoted 2 lines · Stefan Berger
Other possibilities, you have an old libtpms library that's being picked up that may have had a bug?
I indeed didn't have the latest code, but for other reasons - see my other email. It's working now :-)
Quoted 5 lines
Quoted 2 lines
BTW, should the swtpm instance above really terminate when qemu disconnects? It currently does, although -terminate is not given.
It is terminated by QEMU issuing a shutdown on it. I think it's better than leaving stale swtpm processes running.
That it explains it. I was just wondering.
Having swtpm spawned by QEMU avoids exactly this issue with lingering processes, even when QEMU itself gets killed and doesn't get around to shut down the TPM properly. Unfortunately the QEMU developers didn't buy that argument :-/
Quoted 8 lines
Quoted 4 lines
How can I enable more debug logging inside swtpm? Increasing the level
does not really provide much useful information.There's not much debugging output inside the TPM 2 code. Some fatal errors, such as not swtpm not being able to write the TPM2 state file should show up, though.
Just to close on this, --enable-debug also enables additional output, doesn't it? I haven't actually used it, though, because it leads to an assertion in swtpm when using TPM2 (https://github.com/stefanberger/swt
pm/issues/54).
Signature · 6 lines
Best Regards, Patrick Ohly The content of this message is my personal opinion only and although I am an employee of Intel, the statements I make here in no way represent Intel's position on the issue, nor am I authorized to speak on behalf of Intel on this matter.