heads icon indicating copy to clipboard operation
heads copied to clipboard

cbmem -L broken under coreboot 4.21+

Open tlaurion opened this issue 1 year ago • 9 comments

@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 https://github.com/linuxboot/heads/issues/1604#issuecomment-1942087004

tlaurion avatar Feb 13 '24 22:02 tlaurion

Issued a PR that should address the issue: https://github.com/linuxboot/heads/pull/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).

miczyg1 avatar Feb 14 '24 08:02 miczyg1

@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 https://github.com/coreboot/coreboot/commit/a88dd4b6fbac8748a6f4580ad6363da47f5b3bc2, 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 avatar Feb 14 '24 15:02 tlaurion

Logs provided and analysis at https://github.com/linuxboot/heads/pull/1609#issuecomment-1944461330 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 avatar Feb 15 '24 15:02 tlaurion

Discussion under thread at https://matrix.to/#/!pAlHOfxQNPXOgFGTmo:matrix.org/$CQDLxAckANKmXAu8ZDtcDIHUn1dgvgfzyifZidHr7SA?via=matrix.org&via=nitro.chat&via=fairydust.space leading to traces requests by @krystian-hebel and @miczyg1

tlaurion avatar Feb 19 '24 17:02 tlaurion

Ok, so to trace this better

Coreboot custom event log format:

  • https://github.com/tlaurion/heads/tree/422_fhd at commit https://github.com/tlaurion/heads/commit/4bb831720e323cb75c29a400d005561d4016e3ca used here to test on x230 (coreboot custom event log format)

tlaurion avatar Feb 19 '24 18:02 tlaurion

TCG event log format

  • https://github.com/tlaurion/heads/tree/422_fhd at commit https://github.com/tlaurion/heads/commit/6b61f61e6e209192ebf0b9a413744f7daaab06e8 used here to test on x230 (TCG event log format)

tlaurion avatar Feb 19 '24 19:02 tlaurion

Issued a PR that should address the issue: #1609

@miczyg1 #1609 closed as explained under https://github.com/linuxboot/heads/issues/1608#issuecomment-1952968828 : 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 https://github.com/linuxboot/heads/issues/1608#issuecomment-1952939422

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

tlaurion avatar Feb 19 '24 20:02 tlaurion

Blocker for #1568

tlaurion avatar Feb 22 '24 17:02 tlaurion

@miczyg1 ping?

tlaurion avatar Apr 22 '24 02:04 tlaurion

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 avatar Aug 15 '24 14:08 tlaurion

Opened https://github.com/Dasharo/dasharo-issues/issues/1004

Closing here

tlaurion avatar Aug 15 '24 14:08 tlaurion