Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The event data of EV_EFI_VARIABLE_AUTHORITY may not cover the whole EFI variable #9

Closed
lcp opened this issue Nov 1, 2022 · 7 comments

Comments

@lcp
Copy link
Contributor

lcp commented Nov 1, 2022

Per TCG Trusted Boot Chain in EDK II:

When UEFI secure boot is enabled, the DxeImageVerificationLib verifies the PE image signature based upon the EFI_SIGNATURE_DATA in the EFI_SIGNATURE_LIST of an image signature database. If an EFI_SIGNATURE_DATA is used to verify the image, then this EFI_SIGNATURE_DATA will be measured with EV_EFI_VARIABLE_AUTHORITY in DxeImageVerificationLib Measurement.c MeasureVariable().

So the EV_EFI_VARIABLE_AUTHORITY events for db or MokList only cover EFI_SIGNATURE_DATA, i.e. the x509 certificate used to verify the EFI image, not the whole variable. In such case, we have to check if the event data is really in the EFI variable and rehash the event data.

lcp added a commit to lcp/pcr-oracle that referenced this issue Nov 1, 2022
When verifying the TPM2_EFI_VARIABLE_AUTHORITY event, the event data may
not cover the whole EFI variable. For example, edk2 only measures the
x509 certificate in "db" that verifies the EFI image, not the whole "db"
variable. Instead of rehashing the EFI variable, just check if the raw
event data is from the given EFI variable.

(_GNU_SOURCE is introduced to support memem().)

Fixes: okirch#9

Signed-off-by: Gary Lin <glin@suse.com>
lcp added a commit to lcp/pcr-oracle that referenced this issue Nov 1, 2022
When verifying the TPM2_EFI_VARIABLE_AUTHORITY event, the event data may
not cover the whole EFI variable. For example, edk2 only measures the
x509 certificate in "db" that verifies the EFI image, not the whole "db"
variable. Instead of rehashing the EFI variable, just check if the raw
event data is from the given EFI variable.

(_GNU_SOURCE is introduced to support memem().)

Fixes: okirch#9

Signed-off-by: Gary Lin <glin@suse.com>
lcp added a commit to lcp/pcr-oracle that referenced this issue Nov 1, 2022
When verifying the TPM2_EFI_VARIABLE_AUTHORITY event, the event data may
not cover the whole EFI variable. For example, edk2 only measures the
x509 certificate in "db" that verifies the EFI image, not the whole "db"
variable. Instead of rehashing the EFI variable, just check if the raw
event data is from the given EFI variable.

(_GNU_SOURCE is introduced to support memem().)

Fixes: okirch#9

Signed-off-by: Gary Lin <glin@suse.com>
@okirch
Copy link
Owner

okirch commented Nov 1, 2022

Can you attach the -ddd output for one such example event here, please? I'd like to understand what exactly is in this hash.

The problem with just re-hashing the existing data we find in the event log is that it will fail when a new shim is installed with a new signer's certificate, or a new grub with a new SUSE certificate.

I think we could address this case very much like the "Shim" variable event. We can inspect the shim to extract the x509 certificate of the signer, and build the EFI_SIGNATURE_DATA for it. We would have to consult the db to find the signature owner.

@lcp
Copy link
Contributor Author

lcp commented Nov 2, 2022

pcr-oracle.log

There are 3 affected EFI_VARIABLE_AUTHORITY events.

  • db-d719b2cb-3d3a-4596-a3bc-dad00e67656f: This one is from the firmware when verifying shim.efi.
  • Shim-605dab50-e046-4300-abb6-3dd810dd8b23: This happened when shim verified grub.efi.
  • MokListRT-605dab50-e046-4300-abb6-3dd810dd8b23: I'm using the kernel package from kernel:Stable so the project cert was measured.

@okirch
Copy link
Owner

okirch commented Nov 2, 2022

Thank you. I have some code, but it's not fully working yet.

I pushed some new code to the main branch that should help me with lifting data from users' systems as test cases. Can you please give this a spin:

./pcr-oracle --from eventlog all --verify current -d --create-testcase /tmp/pcr-oracle.test

Then please create a tarball from /tmp/pcr-oracle.test and send it to me. Thank you!

@okirch
Copy link
Owner

okirch commented Nov 7, 2022

Hi!
I've extended the code to attempt the following:

  • extract the signer's certificate from the next boot service application
  • when we encounter a VARIABLE_AUTHORITY event for Shim, we load the shim's vendor certificate and perform a quick check to ensure that the BSA was indeed signed. If that is the case, we generate the synthetic event using the raw DER encoded vendor cert
  • for VARIABLE_AUTHORITY events for "db" and "MokListRT", we take a similar approach: loop through the respective certificate DB, and if we find the CA cert that was used to issue the certificate that was used to sign the next BSA, we return the authority record from the DB (which is a SignatureData type per UEFI spec).

None of this is tested properly, because I'm currently not testing on openSUSE. Please give it a spin (and don't forget to send me a testcase as described above).

@lcp
Copy link
Contributor Author

lcp commented Nov 8, 2022

It's clever to read the CA file directly so that we don't have to fiddle with the shim binary. So far, the "db" and "Shim" events are handled properly in my laptop. The "MokList" event for my kernel is tricky since the kernel file is not in ESP, so there is no BSA event for the kernel path :-\

@okirch
Copy link
Owner

okirch commented Nov 8, 2022

Who generates the MokList event for the kernel? It looks like it's not the shim, because shim loads grub in your log file.
If it's grub, maybe we can make it add an EFI device path that tells us where to look. Partition uuid and path would be sufficient.

Anyway, this issue is getting rather longish. I'll open another one and close this one.

@okirch
Copy link
Owner

okirch commented Nov 8, 2022

Let's continue this investigation in issue #14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants