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

Save EFI BootX variables when (un)sealing storage key #4612

Merged
merged 1 commit into from
Feb 14, 2025

Conversation

rucoder
Copy link
Contributor

@rucoder rucoder commented Feb 12, 2025

To do a proper analysis in a monitor TUI we need values of BootXXXX and BootOrder EFI variables. Variable data for them is present in the TPM log however neither TCG spec nor UEFI spec mandate what part of EFI_LOAD_OPTION structure is serialized and measured in the TPM log so the reliable extraction is not possible. For example UEFI on NUC13 device avoids first two fields of this structure.

  • save variables to /persist/status/boot_vars/{success,fail} directories Export paths by introducing GetBootVariablesDirNames()
  • export paths to saved TPM logs by introducing GetTpmLogFileNames() and GetTpmLogBackupFileNames()

@rucoder rucoder force-pushed the rucoder/monitor-tpm-log branch from 2318db4 to 72baaeb Compare February 12, 2025 15:37
@rucoder rucoder force-pushed the rucoder/monitor-tpm-log branch 2 times, most recently from 8f3ed02 to 6d0478e Compare February 12, 2025 15:46
Copy link
Member

@OhmSpectator OhmSpectator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that we only copy BootOrder and BootXXXX variables, but not any other EFI variables (e.g., keys like PK-, db-, dbx-, etc.). In some scenarios, these other EFI variables may be measured into PCRs as well (particularly on platforms with certain secure-boot flows), so it might be worth considering whether we want to save those, too. If someone’s unsealing fails because of changes in another EFI variable that we currently don’t copy, the debugging data will still be incomplete. Could that be an issue for certain platforms?

Also, I notice that we do not yet provide an automated way to compare the “fail” vs. “success” snapshots. This is presumably meant for a manual, ad-hoc diff to investigate unseal failures. It would be helpful to document this workflow so that others know.

Something like...

If unsealing fails, check the snapshot in /persist/status/boot_vars/fail,
Compare against /persist/status/boot_vars/success,
Check the relevant measurement logs in /persist/status/tpm_measurement_{unseal_fail,seal_success},
Identify which bytes changed.

Nevertheless, for this particular case, it may be enough, so approving.

@shjala
Copy link
Member

shjala commented Feb 13, 2025

LGTM.

@rucoder
Copy link
Contributor Author

rucoder commented Feb 13, 2025

I see that we only copy BootOrder and BootXXXX variables, but not any other EFI variables (e.g., keys like PK-, db-, dbx-, etc.). In some scenarios, these other EFI variables may be measured into PCRs as well (particularly on platforms with certain secure-boot flows), so it might be worth considering whether we want to save those, too. If someone’s unsealing fails because of changes in another EFI variable that we currently don’t copy, the debugging data will still be incomplete. Could that be an issue for certain platforms?

Also, I notice that we do not yet provide an automated way to compare the “fail” vs. “success” snapshots. This is presumably meant for a manual, ad-hoc diff to investigate unseal failures. It would be helpful to document this workflow so that others know.

Something like...

If unsealing fails, check the snapshot in /persist/status/boot_vars/fail,
Compare against /persist/status/boot_vars/success,
Check the relevant measurement logs in /persist/status/tpm_measurement_{unseal_fail,seal_success},
Identify which bytes changed.

Nevertheless, for this particular case, it may be enough, so approving.

@OhmSpectator other variables are more like "yes/no" flags for analysis. For example "SecureBoot" -- we only care whether this variable is present or not and do not care about attached data. And the data attached to event log is good enough for human analysis but I need to extract data automatically and unfortunately the format is not well defined in specs and manufactures do what they want.

@OhmSpectator

Also, I notice that we do not yet provide an automated way to compare the “fail” vs. “success” snapshots.

TUI does that

@OhmSpectator
Copy link
Member

OhmSpectator commented Feb 13, 2025

TUI does that

Ah, got it! Maybe add it as a comment: the produced files are later consumed by another component.

@rucoder
Copy link
Contributor Author

rucoder commented Feb 13, 2025

TUI does that

Ah, got it! Maybe add it as a comment: the produced files are later consumed by another component.

To do a proper analysis in a monitor TUI we need values of BootXXXX and BootOrder EFI variables.

isn't it enough :) ?

@OhmSpectator
Copy link
Member

TUI does that

Ah, got it! Maybe add it as a comment: the produced files are later consumed by another component.

To do a proper analysis in a monitor TUI we need values of BootXXXX and BootOrder EFI variables.

isn't it enough :) ?

Enough indeed. Sorry, missed it.

bootVarRegex := regexp.MustCompile(fmt.Sprintf(`^Boot[0-9a-fA-F]{4}-%s$`, efiGlobalVariableGUID))

for _, file := range files {
if bootOrderRegex.MatchString(file.Name()) || bootVarRegex.MatchString(file.Name()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if bootOrderRegex.MatchString(file.Name()) || bootVarRegex.MatchString(file.Name()) {
if file.Name() == fmt.Sprintf(`BootOrder-%s`, efiGlobalVariableGUID) || bootVarRegex.MatchString(file.Name()) {

@christoph-zededa
Copy link
Contributor

Tests?

To do a proper analysis a monitor TUI we need values of BootXXXX and
BootOrder EFI variables. Variable data for them is present in the TPM
log however neither TCG spec nor UEFI spec mandate what part of
EFI_LOAD_OPTION structure is serialized and measured in the TPM log so
the reliable extraction is not possible. For example UEFI on NUC13
device avoids first two fields of this structure.

- save variables to /persist/status/boot_vars/{success,fail} directories
  Export paths by introducing GetBootVariablesDirNames()
- export paths to saved TPM logs by introducing GetTpmLogFileNames()
  and GetTpmLogBackupFileNames()

Signed-off-by: Mikhail Malyshev <[email protected]>
@rucoder rucoder force-pushed the rucoder/monitor-tpm-log branch from 6d0478e to 81db9bf Compare February 13, 2025 13:17
@github-actions github-actions bot requested a review from shjala February 13, 2025 13:17
@eriknordmark
Copy link
Contributor

Also, I notice that we do not yet provide an automated way to compare the “fail” vs. “success” snapshots.

TUI does that

I think we have users which use the meta-data server to retrieve the output from diag and then present that using their app instance screen. Is there a way we can make this comparison common so that both the TUI and diag can present it and as a result it will also appear in the meta-data server output?

@rucoder
Copy link
Contributor Author

rucoder commented Feb 13, 2025

Also, I notice that we do not yet provide an automated way to compare the “fail” vs. “success” snapshots.

TUI does that

I think we have users which use the meta-data server to retrieve the output from diag and then present that using their app instance screen. Is there a way we can make this comparison common so that both the TUI and diag can present it and as a result it will also appear in the meta-data server output?

@eriknordmark I'll think of it but not in this iteration. I already have libs for parsing logs and EFI structures and re-implementing it would take too much time. Porting it back to EVE will take much less time when it is ready and tested

@OhmSpectator OhmSpectator merged commit a084843 into lf-edge:master Feb 14, 2025
44 checks passed
@rucoder rucoder deleted the rucoder/monitor-tpm-log branch February 14, 2025 12:44
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 this pull request may close these issues.

5 participants