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

cbmem -L broken under coreboot 4.21+ #1608

Closed
tlaurion opened this issue Feb 13, 2024 · 13 comments · Fixed by #1824
Closed

cbmem -L broken under coreboot 4.21+ #1608

tlaurion opened this issue Feb 13, 2024 · 13 comments · Fixed by #1824

Comments

@tlaurion
Copy link
Collaborator

tlaurion commented Feb 13, 2024

@JonathonHall-Purism

Well, TBH I'm not sure a lot of other use so much measured boot outside of Heads @JonathonHall-Purism ?
This shows its not tested a lot, or as you said, since cbmem is built by musl-cross-make related doubts, which is compiler buillding everything tools.cpio related under Heads, including cbmem here), that might as well be an undesired artifact of those? (modified quote)

I took the time to use rom produced here (4.22.01 tag release codebase built with measured boot and coreboot custom event log format) and test cbmem built on top of ubuntu 23.10/debian trixie OS (to remove musl-cross-make doubts).

Interestingly enough:

  • sudo ~/Downloada/coreboot-4.22.01/util/cbmem/cbmem -L : Unknown TPM log specification: : FAIL
  • sudo ~/Downloada/coreboot-4.19/util/cbmem/cbmem -L : coreboot TPM log: [...] : OK

So now, let's test cbmem behavior in between those release versions:

  • sudo ~/Downloada/coreboot-4.21/util/cbmem/cbmem -L : Unknown TPM log specification: : FAIL
  • sudo ~/Downloada/coreboot-4.20.1/util/cbmem/cbmem -L : coreboot TPM log: [...] : OK

So cbmem -L broke somewhere between 4.20.1 and 4.21.


Raised awareness under #coreboot channel at https://matrix.to/#/!EhaGFZyYcbyhdSgStq:matrix.org/$DJW_mF5d1PfhJIvoM-_HvX8s3BpzNvtNu77auhvKBo0?via=matrix.org&via=sibnsk.net&via=datanauten.de. @miczyg1 said he would take a look at https://matrix.to/#/!EhaGFZyYcbyhdSgStq:matrix.org/$34SHe96Ef5Qrv2pIXtmi2lqpSwnh1GsKXlZCR9I7PpY?via=matrix.org&via=sibnsk.net&via=datanauten.de

Originally posted by @tlaurion in #1604 (comment)

@tlaurion tlaurion changed the title cbmem broken under coreboot 4.21+ cbmem -L broken under coreboot 4.21+ Feb 13, 2024
@miczyg1
Copy link
Contributor

miczyg1 commented Feb 14, 2024

Issued a PR that should address the issue: #1609

As far as heads is concerned, it doesn't matter which event log format is used right? Or rather coreboot's custom format is preferred @tlaurion ?

Why cbmem -L does not work with the standard TPM log per specifications is a separate matter (I suspect the first event in the event log is not SpecID event, but why? not sure yet).

@tlaurion
Copy link
Collaborator Author

tlaurion commented Feb 14, 2024

@miczyg1 @JonathonHall-Purism theoritically, tpm1.2 vs coreboot log format should not matter since from my understanding, they use PCR2 for operations.

For our interest here and where the bug was discovered (all ivy/sandy/haswell boards were based on 4.19 since edp/fhd patch was not merged upstream), boards stayed on 4.19. But since https://review.coreboot.org/c/coreboot/+/28950 got merged yesterday as coreboot/coreboot@a88dd4b, I'll prepare a PR switching all boards to that commit and be able to give traces, switching boards to TCG TPM1.2 TPM Event log format and go from there.

@tlaurion
Copy link
Collaborator Author

tlaurion commented Feb 15, 2024

Logs provided and analysis at #1609 (comment) and further comments

TCPA log entry 10:
	PCR: -967035966
	Event type: Unknown (0xace82028 >= 19)
	Digest: d97f7b94ead60f73575cdf71010ef9fd99ed6b28
	Event data: 

Looks like coreboot didn't terminate the event log... cbmem checks for a zero_block of one TCPA entry length, if it isn;t found, then it goes further... We could add more safety checks to cbmem to avoid that but also make sure coreboot properly terminates the eventlog (or at least clear the cbmem entry with the log while creating it...)

@SergiiDmytruk cc

EDIT:

coreboot is clearing the cbmem areas with TCG logs in src/security/tpm/tspi/log-tpm1.c and src/security/tpm/tspi/log-tpm2.c: memset(tclt, 0, tpm_log_len);, so a memory corruption?

@tlaurion
Copy link
Collaborator Author

tlaurion commented Feb 19, 2024

@tlaurion
Copy link
Collaborator Author

tlaurion commented Feb 19, 2024

Ok, so to trace this better

Coreboot custom event log format:

@tlaurion
Copy link
Collaborator Author

tlaurion commented Feb 19, 2024

TCG event log format

@tlaurion
Copy link
Collaborator Author

tlaurion commented Feb 19, 2024

Issued a PR that should address the issue: #1609

@miczyg1 #1609 closed as explained under #1608 (comment) : switching to coreboot custom format doesn't fix anything at all.
The recap of the discussion leading to log dropped today above happened in the thread pointed by #1608 (comment)

Let me know here if anything else is needed to troubleshoot coreboot upstream issue from Heads side.

@tlaurion
Copy link
Collaborator Author

Blocker for #1568

@tlaurion
Copy link
Collaborator Author

@miczyg1 ping?

@tlaurion
Copy link
Collaborator Author

tlaurion commented Aug 15, 2024

This is related to coreboot changes from TCPA->TPM event log and is still present under coreboot master (24.05) and affects all forks since coreboot 4.21 where that change occurred

@tlaurion
Copy link
Collaborator Author

Opened Dasharo/dasharo-issues#1004

Closing here

@tlaurion tlaurion closed this as not planned Won't fix, can't repro, duplicate, stale Aug 15, 2024
@tlaurion tlaurion reopened this Oct 25, 2024
miczyg1 added a commit to Dasharo/coreboot that referenced this issue Oct 30, 2024
The utilit yassumed that TCG TPM log area is zeroed and then filled
with events but it does not have to be true. If there is garbage
after the last valid event entry, the utility will most likely
access data outside of the cbmem area containing the logs. Relevant
issue: linuxboot/heads#1608

TEST=Dump TCG TPM1.2 event log on Dell OptiPlex 7010 and see
"Invalid TPM1.2 log entry overflowing cbmem area" error is printed.

Signed-off-by: Michał Żygowski <[email protected]>
@miczyg1
Copy link
Contributor

miczyg1 commented Oct 30, 2024

https://review.coreboot.org/c/coreboot/+/84926

Fixed the cbmem utility side, but it would also be good to clear that log area on creation.

miczyg1 added a commit to Dasharo/coreboot that referenced this issue Oct 30, 2024
The utilit yassumed that TCG TPM log area is zeroed and then filled
with events but it does not have to be true. If there is garbage
after the last valid event entry, the utility will most likely
access data outside of the cbmem area containing the logs. Relevant
issue: linuxboot/heads#1608

TEST=Dump TCG TPM1.2 event log on Dell OptiPlex 7010 and see
"Invalid TPM1.2 log entry overflowing cbmem area" error is printed.

Signed-off-by: Michał Żygowski <[email protected]>
miczyg1 added a commit to Dasharo/coreboot that referenced this issue Oct 30, 2024
The utilit yassumed that TCG TPM log area is zeroed and then filled
with events but it does not have to be true. If there is garbage
after the last valid event entry, the utility will most likely
access data outside of the cbmem area containing the logs. Relevant
issue: linuxboot/heads#1608

TEST=Dump TCG TPM1.2 event log on Dell OptiPlex 7010 and see
"Invalid TPM1.2 log entry overflowing cbmem area" error is printed.

Signed-off-by: Michał Żygowski <[email protected]>
@miczyg1
Copy link
Contributor

miczyg1 commented Oct 30, 2024

https://review.coreboot.org/c/coreboot/+/84927

Fixed the log area creation for TPM1.2. Not sure why but the TPM2.0 log area was completely cleared, thus the issue did not appear when parsing TPM2.0 logs...

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

Successfully merging a pull request may close this issue.

2 participants