-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Improve TPM extend ops output in normal and DEBUG mode #1758
Changes from 1 commit
5299266
7ca8d42
250a144
de7902f
77d4be1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ fi | |
# Unify lsmod output to use - instead of _ for comparison | ||
module_name=$(basename "$MODULE" | sed 's/_/-/g' | sed 's/\.ko$//') | ||
if lsmod | sed 's/_/-/g' | grep -q "^$module_name\\b"; then | ||
DEBUG "$MODULE: already loaded" | ||
DEBUG "$MODULE: already loaded, skipping" | ||
exit 0 | ||
fi | ||
|
||
|
@@ -39,17 +39,14 @@ if [ ! -r /sys/class/tpm/tpm0/pcrs -o ! -x /bin/tpm ]; then | |
fi | ||
|
||
if [ -z "$tpm_missing" ]; then | ||
DEBUG "Extending TPM PCR $MODULE_PCR with $MODULE prior of usage" | ||
echo "TPM: Extending PCR[$MODULE_PCR] with $MODULE prior of loading into kernel" | ||
tpmr extend -ix "$MODULE_PCR" -if "$MODULE" \ | ||
|| die "$MODULE: tpm extend failed" | ||
fi | ||
|
||
if [ ! -z "$*" -a -z "$tpm_missing" ]; then | ||
DEBUG "Extending TPM PCR $MODULE_PCR with $*" | ||
TMPFILE=/tmp/insmod.$$ | ||
echo "$@" > $TMPFILE | ||
DEBUG "Extending TPM PCR $MODULE_PCR with $MODULE prior of usage" | ||
tpmr extend -ix "$MODULE_PCR" -if $TMPFILE \ | ||
echo "TPM: Extending PCR[$MODULE_PCR] with $MODULE prior of loading into kernel" | ||
tpmr extend -ix "$MODULE_PCR" -if "$MODULE" \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was supposed to extend the PCR with the module arguments if any were given, but now it's extending a second time with the module itself. So inserting the module with different arguments won't yield a different PCR digest. I think you need to revert this change. If you don't want a temp file, maybe you could do something with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could use `tpmr extend -ix "$MODULE_PCR" -ic "$*"
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@JonathonHall-Purism : I'm not sure I follow. Traces better then words.
So basically, I only changed removal of tmp file altogether in pointed code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See also #1758 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, you changed what the PCR is extended with. It was not just extended with the module file content before, it was extended with the module parameters and the module file content. In the PR, changing the module parameters will no longer affect the resulting PCR measurement, but it does affect the module behavior. Granted, today we don't insert any modules with parameters. So I guess a change to actually include a module parameter would also necessarily change the initrd. But I think it's an unnecessary risk to introduce this possible vulnerability down the road, since it was there before, since it's easy to address. In other words - we currently do the following: You could instead insert it with a module parameter, like quirks: Prior to this PR, those resulted in different PCR values, which I think is important since this changes the behavior of the module in ways unknown to So IMO add |
||
|| die "$MODULE: tpm extend on arguments failed" | ||
fi | ||
|
||
|
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.
This used to also extend with the CBFS file name. I think we should continue to do that:
tpmr extend -ix "$CONFIG_PCR" -ic "$filename"
While it's hard to reason about whether an attack could be possible by moving the entire content of one file to another in some way that doesn't invalidate the PCRs, it's easy to just extend with the file name and be sure there's no such attack.
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.
@JonathonHall-Purism same comment #1758 (comment)
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.
@JonathonHall-Purism We do not to hash the filenames; we want to hash with file content.
Only occurrences in code of TPM PCR exttends
-ic
ops are to extend PCR[4] with hashes of literals: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 used to hash both. Now it only hashes the content.
This appears to open up an attack by pivoting file contents or renaming files.
For example, say there were only two such files:
echo CONFIG_RESTRICTED_BOOT=y....
some GPG key data
An attacker could manipulate CBFS to the following without affecting the measured PCR state.
echo CONFIG_RESTRICTED_BOOT=y...
some GPG key data
Heads would construct the same PCR measurements in this PR because it is only measuring the file content. But the restricted boot config and GPG keyring will be gone, since they've been renamed in such a way that they'll be ignored.
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.
(should spell this out 🙂 ) - So my point is you do need to hash both the filename and the content.
It used to do this by putting both the filename and content in a temp file, and hashing that.
A better strategy would be to extend once with the filename, then extend a second time with the file content. (That way the filename and content are clearly separated, you couldn't move the last few letters of the filename to the content, or something like that.)
So include
tpmr extend -ix "$CONFIG_PCR" -ic "$filename"
before hashing the file content.