Skip to content

Rust native TPML_TAGGED_PCR_PROPERTY type #308

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

Merged
merged 7 commits into from
Jan 17, 2022

Conversation

Superhepper
Copy link
Collaborator

@Superhepper Superhepper commented Jan 11, 2022

This PR fixes #305 by doing the following.

Fixes a bug in the types that parses octets containing bit fields representing pcr slots.

Adds necessary types needed in order to create the TaggedPcrPropertyList type which is a rust native version of the TPML_TAGGED_PCR_PROPERTY.

Changes CapabilityData to TaggedPcrPropertyList.

Copy link
Collaborator

@wiktor-k wiktor-k left a comment

Choose a reason for hiding this comment

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

Although I haven't worked with PCRs (yet) I've read the PR and it looks OK.

Fixed so that octets not indicated to be used by the
sizeOfSelect are ignored.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
@Superhepper Superhepper force-pushed the tpml_tagged_pcr_property branch 3 times, most recently from 9a6bbfb to 7e6e957 Compare January 13, 2022 13:23
Copy link
Member

@ionut-arm ionut-arm left a comment

Choose a reason for hiding this comment

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

Much like Wiktor, I don't have much experience working with PCRs, so just left a few generic questions/comments.

Comment on lines +74 to +63
impl From<PcrSlot> for [u8; TPM2_PCR_SELECT_MAX as usize] {
fn from(pcr_slot: PcrSlot) -> [u8; TPM2_PCR_SELECT_MAX as usize] {
u32::from(pcr_slot).to_le_bytes()
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This won't compile on a platform where TPM2_PCR_SELECT_MAX != 4, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ha! That is absolutely correct didn't even think about that.

Copy link
Collaborator Author

@Superhepper Superhepper Jan 15, 2022

Choose a reason for hiding this comment

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

This code have been there for a while and it is a little bit complicated to change. It will depend on what we want to support. I mean the Max value could be anything. It is, as I pointed out earlier, up to the platform specification to specify.

What I think we can do and I think we should do is the following. We should extend PcrSlot enum to support all slots up to 31. The reason for this is because PcrSelectSize already supports a size of four octets. Then we should change the From native to bindgen type conversions to be TryFrom and check if the selected value can fit in the bindgen buffer.

I think this should be done by doing one TryFrom for each size. So a buffer with size 4 will have type Error = Infallible;. But I have not thought about this to much yet.

But it is not something that should be done in this PR I think.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm happy with this approach - if it's just been moved from here to there and no one complained so far, I think we're good for now.

Copy link
Member

Choose a reason for hiding this comment

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

Do you want to raise an issue for that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I am going to raise an issue for that.

This commit moves the PcrSlot enum to its own source file
and simplifies the conversion from a u32.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
Moves the PcrSelectSize to its own file and adds
conversions to and from u8 and to usize.

Adds tests for PcrSelectSize.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
Adds the PcrPropertyTag enum. This corresponds to the TPM2_PT_PCR
constants.

Adds tests for PcrPropertyTag.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
Adds the TaggedPcrSelect type. This corresponds to the
TPMS_TAGGED_PCR_SELECT structure.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
Adds the TaggedPcrPropertyList type, this type corresponds to the
TPML_TAGGED_PCR_PROPERTY structure.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
@Superhepper Superhepper force-pushed the tpml_tagged_pcr_property branch from 7e6e957 to 66e6d86 Compare January 15, 2022 21:00
Copy link
Member

@ionut-arm ionut-arm left a comment

Choose a reason for hiding this comment

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

👍

@ionut-arm ionut-arm merged commit 392b170 into parallaxsecond:main Jan 17, 2022
@Superhepper Superhepper deleted the tpml_tagged_pcr_property branch July 3, 2022 09:47
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.

Implement native type for TPML_TAGGED_PCR_PROPERTY in CapabilityData.
3 participants