microsoft / MSRSec

Security and Privacy Research at Microsoft
MIT License
37 stars 28 forks source link

Driver not loaded (qemu) #20

Closed vivinamartins16 closed 5 years ago

vivinamartins16 commented 5 years ago

Hey all!

I'm building fTPM with OP-TEE on Qemu. Following the instructions, I got to build the solution but the driver didn't load. I got the following on my Normal World shell:

Starting tee-supplicant: OK
Starting network: OK
Starting network (udhcpc): OK
Starting tpm2-abrmd: device driver not loaded, skipping.

What am I missing? also, how can I interect with the TA? how can i invoke it from normal world or how can I access it?

p.s: I see no evidence of the TA being loaded in the secure world.

Thanks in advance!

dmcilvaney commented 5 years ago

Hi @vivinamartins16, I work mostly on the Windows side, so I won't be much help directly (I've only run the fTPM in QEMU from a user mode program, never with the Linux driver). I'll try and find someone with some better background to help out.

vivinamartins16 commented 5 years ago

Thanks @dmcilvaney ! I'd be much appreciated! In case it helps, I also tried following the Linaro guide

https://github.com/jbech-linaro/manifest/tree/ftpm

But no sucess either. Everything builds without errors but the TPM doesn't seem to be loaded.

Thanks in advance!

dmcilvaney commented 5 years ago

Maybe have a read through here if you haven't yet: https://patchwork.kernel.org/comment/22741599/

vivinamartins16 commented 5 years ago

Thanks @dmcilvaney ! I have already read through that but no success either! I still don't see the TAs being loaded, even tought I don't get any error message during build.

dmcilvaney commented 5 years ago

Ok, few thoughts (I have focused on the Windows/early firmware side so these may not be particularly valuable but I'll give it a shot)

  1. Are you basing this entirely off Joakim's TPM work? If not, any instructions you can point me to?
  2. I think that most Linux work was done based on ms-tpm-20-ref/Samples/… I can't promise that this repo works flawlessly with Linux yet (but it should be fine)
  3. We moved to a new UUID for the TA a few months ago, but the Linux driver is using an old one. We just rolled it back in 6bb57db632c424f87cbaf7ec6f9c89be7682b3c0 so if you built from MSRSec, try updating to use the historic UUID.
  4. Are you running the fTPM as an early TA, or user mode TA? I think most of the Linux driver discussion was based around an early TA.
vivinamartins16 commented 5 years ago

First of all, thanks a lot for the time and effort to help me out :)

  1. Yes. I followed 100% Joakim's setup. No further steps taken.
  2. With Joakim's setup, I downloaded the optee_ta from ms-tpm-20-ref repo. I'll try to switch to the one in this repo and see what happens.
  3. I checked the UUID, and matches the historic UUID. I'll keep that in mind when using the TA from this repo!
  4. I was expecting it to behave as early TA.

-- other info:

None of which starts with bc5 or 53b.

Running grep, I get:

# grep -r "bc50d9" .
grep: ./run/dbus/system_bus_socket: No such device or address
./etc/profile.d/ftpm_alias.sh:alias setup_ftpm='mkdir -p /host && mount -t 9p -o trans=virtio host /host && cd /lib/optee_armtz && ln -sf /host/ms-tpm-20-ref/out/bc50d971-d4c9-42c4-82cb-123456789123.ta bc50d971-d4c9-42c4-82cb-123456789123.ta'

Which is the script I run previously, before make run-only. It seems to be making a symlink from the TA. I believe that this is whats going wrong. Is this "host" folder, the main one with optee or the one inside out-br? Maybe it should be inside out-br instead of the external folder?

I'll try switching repos, changing location of the ms-tpm-20-ref folder inside optee and see what I get.

Thanks once more!

DMattoon commented 5 years ago

On #4, this is something we plan to resolve. As of right now the TA has a hard requirement on the ability to light up storage on init. We understand that this is not the desired behavior and intend to provide the ability to defer (and not panic) when storage is not yet available on startup.

dmcilvaney commented 5 years ago

Ok, the lack of TA in the host folder is odd, but may be a red herring. An 'early TA' gets packaged as a part of the OP-TEE binary itself, and OP-TEE will unpackage it without requiring the rich OS to get involved.

That said, the mount 'should' work. When you launch QEMU you can give it a path to a directory on the host machine (-fsdev … path=/your/path/here/). Running the command mkdir -p /host && mount -t 9p -o trans=virtio host /host should create a /host folder inside QEMU, connect the "host" tag, and mount /your/path/here/ into that folder. This means anything you put in that folder on the host machine will be available inside QEMU. The ln command then makes the new TA binary you built available in the optee_armtz/ folder. OP-TEE knows how to read TAs out of there.

Piping out the secure console should give the absolute truth about calls to a TA. It looks like the fTPM might be loaded properly. You can crank the TA debug up with CFG_TEE_TA_LOG_LEVEL=4 and CFG_TA_DEBUG=y. It should be pretty obvious if the fTPM is running if you watch the secure console.

vivinamartins16 commented 5 years ago

Thank you @dmcilvaney ! I managed to run Joakim's setup it with a few flags turned on and the link with the host folder on qemu that you suggested worked just fine! thank you :)