From: Mimi Zohar <zohar@linux.ibm.com>
To: linux-integrity@vger.kernel.org
Cc: Roberto Sassu <roberto.sassu@huawei.com>,
Vitaly Chikunov <vt@altlinux.org>,
Patrick Uiterwijk <puiterwi@redhat.com>,
Mimi Zohar <zohar@linux.ibm.com>
Subject: [PATCH] ima-evm-utils: calculate the per TPM bank boot_aggregate
Date: Wed, 25 Mar 2020 17:35:01 -0400 [thread overview]
Message-ID: <1585172101-19501-1-git-send-email-zohar@linux.ibm.com> (raw)
The IMA measurement list boot_aggregate is the link between the preboot
event log and the IMA measurement list. Read and calculate all the
possible per TPM bank boot_aggregate digests based on PCRs 0 - 7.
Reading the TPM PCRs requires root permission, unless access to the
device (/dev/tpm0 or /dev/tpmrm0) has been granted.
Prior to calculating the boot_aggregate, the TPM PCRs themselves should
be validated by walking the TPM event log and re-calculating the PCRs.
(Such a test should be included as part of the TSS regression testsuites.)
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
---
src/evmctl.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/src/evmctl.c b/src/evmctl.c
index 50258dd158fc..675980823636 100644
--- a/src/evmctl.c
+++ b/src/evmctl.c
@@ -1900,6 +1900,77 @@ static int cmd_ima_measurement(struct command *cmd)
return ima_measurement(file);
}
+static void calc_bootaggr(struct tpm_bank_info *bank)
+{
+ EVP_MD_CTX *pctx;
+ unsigned int mdlen;
+ const EVP_MD *md;
+#if OPENSSL_VERSION_NUMBER < 0x10100000
+ EVP_MD_CTX ctx;
+ pctx = &ctx;
+#else
+ pctx = EVP_MD_CTX_new();
+#endif
+ int err = 0;
+ int i;
+
+ md = EVP_get_digestbyname(bank->algo_name);
+
+ err = EVP_DigestInit(pctx, md);
+ if (!err) {
+ printf("EVP_DigestInit() failed\n");
+ goto out;
+ }
+
+ for (i = 0; i < 8; i++) {
+ err = EVP_DigestUpdate(pctx, bank->pcr[i], bank->digest_size);
+ if (!err) {
+ log_err("EVP_DigestUpdate() failed\n");
+ return;
+ }
+ }
+
+ err = EVP_DigestFinal(pctx, bank->digest, &mdlen);
+ if (!err) {
+ log_err("EVP_DigestFinal() failed\n");
+ goto out;
+ }
+
+out:
+ printf("%s:", bank->algo_name);
+ imaevm_hexdump(bank->digest, bank->digest_size);
+#if OPENSSL_VERSION_NUMBER >= 0x10100000
+ EVP_MD_CTX_free(pctx);
+#endif
+}
+
+/*
+ * The IMA measurement list boot_aggregate is the link between the preboot
+ * event log and the IMA measurement list. Read and calculate all the
+ * possible per TPM bank boot_aggregate digests based on the existing
+ * PCRs 0 - 7 to validate against the IMA boot_aggregate record.
+ */
+static int cmd_ima_bootaggr(struct command *cmd)
+{
+ struct tpm_bank_info *tpm_banks;
+ int num_banks = 0;
+ int i;
+
+ tpm_banks = init_tpm_banks(&num_banks);
+
+ if (read_tpm_banks(num_banks, tpm_banks) != 0) {
+ log_info("Failed to read any TPM PCRs\n");
+ return -1;
+ }
+
+ for (i = 0; i < num_banks; i++) {
+ if (!tpm_banks[i].supported)
+ continue;
+ calc_bootaggr(&tpm_banks[i]);
+ }
+ return 0;
+}
+
static void print_usage(struct command *cmd)
{
printf("usage: %s %s\n", cmd->name, cmd->arg ? cmd->arg : "");
@@ -2015,6 +2086,7 @@ struct command cmds[] = {
{"ima_setxattr", cmd_setxattr_ima, 0, "[--sigfile file]", "Set IMA signature from sigfile\n"},
{"ima_hash", cmd_hash_ima, 0, "file", "Make file content hash.\n"},
{"ima_measurement", cmd_ima_measurement, 0, "file", "Verify measurement list (experimental).\n"},
+ {"ima_boot_aggregate", cmd_ima_bootaggr, 0, "", "Calculate per TPM bank boot_aggregate digests\n"},
{"ima_fix", cmd_ima_fix, 0, "[-t fdsxm] path", "Recursively fix IMA/EVM xattrs in fix mode.\n"},
{"ima_clear", cmd_ima_clear, 0, "[-t fdsxm] path", "Recursively remove IMA/EVM xattrs.\n"},
{"sign_hash", cmd_sign_hash, 0, "[--key key] [--pass [password]", "Sign hashes from shaXsum output.\n"},
--
2.7.5
reply other threads:[~2020-03-25 21:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1585172101-19501-1-git-send-email-zohar@linux.ibm.com \
--to=zohar@linux.ibm.com \
--cc=linux-integrity@vger.kernel.org \
--cc=puiterwi@redhat.com \
--cc=roberto.sassu@huawei.com \
--cc=vt@altlinux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).