Skip to content

xen/arch/x86/tpm.c: add CRB interface support + response validation fix#28

Open
accek-itl wants to merge 2 commits into
TrenchBoot:aem-staging-2026-03-13from
accek-itl:tpm-crb
Open

xen/arch/x86/tpm.c: add CRB interface support + response validation fix#28
accek-itl wants to merge 2 commits into
TrenchBoot:aem-staging-2026-03-13from
accek-itl:tpm-crb

Conversation

@accek-itl
Copy link
Copy Markdown

No description provided.

@macpijan macpijan requested a review from SergiiDmytruk April 23, 2026 13:27
Comment thread xen/arch/x86/tpm.c Outdated
* header (10) | parameterSize (4) | TPML_DIGEST_VALUES | authArea
* finish_r overlays: h (10) | paramSize (4) | hashCount (4) | hashes[]
*/
if ( o_size < sizeof(cmd_rsp.finish_r) + sizeof(uint32_t) )
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why sizeof(uint32_t)? That's first hash alg and 2 first bytes of the hash.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Rewrote these checks for o_size. Also changed the returned value to -1 to make it consistent with the other tmp2_hash_extend below.

Comment thread xen/arch/x86/tpm.c
uint32_t data_buf_pa = TPM_BASE + CRB_DATA_BUFFER_(loc);
unsigned expected;

crb_cmd_ready(loc);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure why, but coreboot's driver follows this with a wait for no error in CRB_CTRL_STS_ and then a wait for CRB_CTRL_START_ being zero.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hmm, doubt if transitioning to ready state could end up with a non-recoverable error, but why not check it. Better than an infinite loop waiting for successful start below, so added here too.

For wait for start being zero - it may be more coreboot-specific, as this is a wait for a previous operation to complete. Incomplete operation should not happen after successful SINIT. But added nevertheless, doesn't hurt.

Comment thread xen/arch/x86/tpm.c
tpm_write32(CRB_CTRL_RSP_ADDR_(loc), data_buf_pa);
tpm_write32(CRB_CTRL_RSP_ADDR_(loc) + 4, 0);

memcpy(__va(data_buf_pa), buf, i_size);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No check for i_size being too large.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed (added at the beginning of the function).

Comment thread xen/arch/x86/tpm.c
}

/* Read header to learn the response length. */
memcpy(buf, __va(data_buf_pa), sizeof(struct tpm_rsp_hdr));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

*o_size could be too small here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed (added at the beginning of the function).

Comment thread xen/arch/x86/tpm.c Outdated
static void crb_send_cmd(unsigned loc, uint8_t *buf, unsigned i_size,
unsigned *o_size)
{
uint32_t data_buf_pa = TPM_BASE + CRB_DATA_BUFFER_(loc);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should make no difference but upstream will likely prefer this version:

Suggested change
uint32_t data_buf_pa = TPM_BASE + CRB_DATA_BUFFER_(loc);
paddr_t data_buf_pa = TPM_BASE + CRB_DATA_BUFFER_(loc);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

accek added 2 commits May 15, 2026 15:30
Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Szymon Acedański <accek@invisiblethingslab.com>
Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Szymon Acedański <accek@invisiblethingslab.com>
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.

3 participants