-
Notifications
You must be signed in to change notification settings - Fork 17
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
tpm2: Update the policy for the PCR policy counter index #370
tpm2: Update the policy for the PCR policy counter index #370
Conversation
This adds a new branch which permits using the TPM2_PolicyNV command against the index without any authorization, much like there is already a branch that permits TPM2_NV_Read. This will make it compatible with automatic branch selection when the tpm2 package starts to make use of Policy.Execute from the github.com/canonical/go-tpm2/policyutil packagevin the future, without having to retrospectively modify the policy of NV indexes on existing devices.
8114797
to
b7a7bd3
Compare
Note that most of the new code in this PR is a clone of the code in |
tpm2/policy_v3.go
Outdated
// pcrPolicyData_v3 represents version 3 of the PCR policy metadata for | ||
// executing a policy session, and can be updated. It has the same format | ||
// as version 2. | ||
type pcrPolicyData_v3 = pcrPolicyData_v2 | ||
type pcrPolicyData_v3 struct { | ||
Selection tpm2.PCRSelectionList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldn't this just embed pcrPolicyData_v2 and replace below only the methods that have changes? it's very hard to spot what are difference between the methods are atm, are they mostly in executeRevocationCheck ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the changes are only in executeRevocationCheck
. I'll try what you suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've done this now, although it did require a bit more work in the unit tests.
Rather than fully reimplement pcrPolicyData_v3, which only has minor differences to pcrPolicyData_v2, instead, just embed pcrPolicyData_v2 as an anonymous member of the new pcrPolicyData_v3 and add an override for the method that is different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the change, one comment
// XXX(chrisccoulson): This is the 3rd session we open here, with all 3 loaded | ||
// on the TPM. PC Client TPMs are only guaranteed to support 3 loaded sessions, | ||
// so we're pushing things a bit close to the wire here. This code does execute | ||
// during early boot, but it might be better to make the HMAC session associated | ||
// with the TPM connection unloaded by default (context saved), and only context | ||
// load it when needed. | ||
revocationCheckSession, err := tpm.StartAuthSession(nil, nil, tpm2.SessionTypePolicy, nil, counter.Name().Algorithm()) | ||
if err != nil { | ||
return fmt.Errorf("cannot create policy session for revocation check: %w", err) | ||
} | ||
defer tpm.FlushContext(revocationCheckSession) | ||
|
||
authPolicies, err := computeV3PcrPolicyCounterAuthPolicies(counter.Name().Algorithm(), updateKey) | ||
if err != nil { | ||
return policyDataError{fmt.Errorf("cannot compute auth policies for PCR policy counter: %w", err)} | ||
} | ||
if err := tpm.PolicyCommandCode(revocationCheckSession, tpm2.CommandPolicyNV); err != nil { | ||
return err | ||
} | ||
if err := tpm.PolicyOR(revocationCheckSession, authPolicies); err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be good to have a comment here that explain why we create a new session and what we do with it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a comment now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
This adds a new branch which permits using the
TPM2_PolicyNV
commandagainst the index without any authorization, much like there is already
a branch that permits
TPM2_NV_Read
.This will make it compatible with automatic branch selection when the
tpm2
package starts to make use ofPolicy.Execute
from thegithub.com/canonical/go-tpm2/policyutil
package in the future, withouthaving to retrospectively modify the policy of NV indexes on existing
devices.