ima-evm-utils: similarly add sanity check for file parameter of TPM 1.2 PCRs
Mimi Zohar
maintainerPATCH 1/3 ima-evm-utils: similarly add sanity check for file parameter of TPM 1.2 PCRs
Parameter expects to be a copy of /sys/class/tpm/tpm0/device/pcrs (i.e. regular file, not a directory, block or character device, socket, ...)
--- src/evmctl.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
src/evmctl.c +13 -1
@@ -1379,14 +1379,26 @@ static char *misc_pcrs = "/sys/class/misc/tpm0/device/pcrs";/* Read all of the TPM 1.2 PCRs */ static int tpm_pcr_read (struct tpm_bank_info *tpm_banks,int len) { +struct stat s;FILE *fp =NULL ;char *p, pcr_str[8 ], buf[70 ];/* length of the TPM string */ int result =-1 ;int i =0 ;/* Use the provided TPM 1.2 pcrs file */ -if (pcrfile) +if (pcrfile) { +if (stat (pcrfile, &s) ==-1 ) { + errno =0 ; +return 1 ; + } + +if (!S_ISREG (s.st_mode)) { +log_info ("TPM 1.2 PCR file: not a regular file or link to regular file\n" ); +return 1 ; + } + fp =fopen (pcrfile,"r" ); + }if (!fp) fp =fopen (pcrs,"r" );
Signature · 1 line
2.7.5
Mimi Zohar
maintainerPATCH 2/3 ima-evm-utils: output specific "unknown keyid" file msg based on log level
When the IMA measurement list contains file signatures, the file signatures are verified either by calculating the local file data hash or based on the file hash contained in the measurement list. In either case a list of trusted public keys needs to be provided.
In addition to the list of known/unknown public keys needed to verify the measurement list being output, the specific files signed by an unknown public key are output as well.
Output the individual "unknown keyid" file messages based on log level.
Example 1: "ima_measurement" list of known/unknown public keys
Verify the provided IMA measurement list against the provided TPM 1.2 PCRs.
--validate: ignore measurement violations.
--verify: calculate and verify the template digest against the template data.
--verify-sig: verify the file signature against the file hash stored in the template data.
$ evmctl ima_measurement /tmp/local_binary_runtime_measurements --pcrs /tmp/local_pcrs_new --validate --verify --verify-sig key 1: 14c2d147 /etc/keys/x509_evm.der key 2: 6e6c1046 (unknown keyid) key 3: c4e2426e (unknown keyid) Matched per TPM bank calculated digest(s).
Example 2: verbose mode (-v) includes specific unknown files.
/usr/bin/evmctl: verification failed: unknown keyid 6e6c1046
--- src/libimaevm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
src/libimaevm.c +3 -2
@@ -512,8 +512,9 @@ static int verify_hash_v2(const char *file, const unsigned char *hash, int size,if (!pkey) {uint32_t keyid = hdr->keyid; -log_info ("%s: verification failed: unknown keyid %x\n" , - file,__be32_to_cpup (&keyid)); +if (imaevm_params.verbose >LOG_INFO ) +log_info ("%s: verification failed: unknown keyid %x\n" , + file,__be32_to_cpup (&keyid));return -1 ; }
Signature · 1 line
2.7.5
Re: [PATCH 2/3] ima-evm-utils: output specific "unknown keyid" file msg based on log level
Hi Mimi,
Quoted 5 lines
When the IMA measurement list contains file signatures, the file signatures are verified either by calculating the local file data hash or based on the file hash contained in the measurement list. In either case a list of trusted public keys needs to be provided.
Quoted 7 lines
In addition to the list of known/unknown public keys needed to verify the measurement list being output, the specific files signed by an unknown public key are output as well.
Output the individual "unknown keyid" file messages based on log level.
Example 1: "
ima_measurement" list of known/unknown public keys
Kind regards,
Petr
Re: [PATCH 2/3] ima-evm-utils: output specific "unknown keyid" file msg based on log level
In reply to Mimi ZoharHi Mimi,
src/libimaevm.c static int verify_hash_v2(const char *file, const unsigned char *hash, int size, · line 516
Quoted 4 lines
src/libimaevm.c +2
-2-log_info ("%s: verification failed: unknown keyid %x\n" , - file,__be32_to_cpup (&keyid)); +if (imaevm_params.verbose >LOG_INFO ) + log_info("%s: verification failed: unknown keyid %x\n",
BTW, I was thinking to add more macros which would handle if (imaevm_params.verbose > LOG_INFO), something like:
+#define log_dump_verbose(p, len) if (imaevm_params.verbose > LOG_INFO) do_dump(p, len, true)
+#define log_verbose(fmt, args...) if (imaevm_params.verbose > LOG_INFO) log_info(fmt, ##args)
But in the end I didn't post it, because:
1) imaevm_params.verbose is sometimes used for other purpose:src/evmctl.c:
if (sigdump || imaevm_params.verbose >= LOG_INFO)
imaevm_hexdump(sig, len);
...
if (imaevm_params.verbose > LOG_INFO) {
log_info("%d ", entry->header.pcr);
log_dump_n(entry->header.digest, sizeof(entry->header.digest));
log_info(" %s %s", entry->name, algo);
log_dump_n(digest, digest_len);
log_info(" %s", path);
if (fbuf) {
log_info(" ");
log_dump_n(fbuf, fbuf_len);
}
}...
if (imaevm_params.verbose <= LOG_INFO)
return;
2) code sometimes compares: imaevm_params.verbose >= LOG_INFO (i.e. >= vs >; is that intentional?)
Kind regards,
Petr
Mimi Zohar
maintainerPATCH 3/3 ima_evm_utils: indicate "--verify" template data digest failures
In reply to Mimi ZoharHelps to indicate when the template data digest verification fails. Indicate the problematic record in the measurement list based on log level and fail verification.
data digest")
--- src/evmctl.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
src/evmctl.c +20 -3
@@ -1444,14 +1444,21 @@ static int verify = 0;static int ima_verify_template_hash (struct template_entry *entry) {uint8_t digest[SHA_DIGEST_LENGTH ]; +static int line =0 ; + + line++;if (!memcmp (zero, entry->header.digest,sizeof (digest)))return 0 ;SHA1 (entry->template, entry->template_len, digest); -if (memcmp (digest, entry->header.digest,sizeof (digest))) +if (memcmp (digest, entry->header.digest,sizeof (digest))) { +if (imaevm_params.verbose >LOG_INFO ) +log_info ("Failed to verify template data digest(line %d).\n" , + line);return 1 ; + }return 0 ; }
@@ -1892,6 +1899,7 @@ static int ima_measurement(const char *file)struct template_entry entry = { .template =0 };FILE *fp; +int verified_template_digest =0 ;int err_padded =-1 ;int err =-1 ;
@@ -2020,8 +2028,12 @@ static int ima_measurement(const char *file)extend_tpm_banks (&entry, num_banks, pseudo_banks, pseudo_padded_banks); -if (verify) -ima_verify_template_hash (&entry); +/* Recalculate and verify template data digest */ +if (verify) { + err =ima_verify_template_hash (&entry); +if (err) + verified_template_digest =1 ; + }if (is_ima_template)ima_show (&entry);
@@ -2058,6 +2070,11 @@ static int ima_measurement(const char *file)log_info ("Failed to match per TPM bank or SHA1 padded TPM digest(s).\n" ); } +if (verified_template_digest) { +log_info ("Failed to verify template data digest.\n" ); + err =1 ; + } + out:fclose (fp);return err;
Signature · 1 line
2.7.5
Re: [PATCH 3/3] ima_evm_utils: indicate "--verify" template data digest failures
Hi Mimi,
Quoted 6 lines
Helps to indicate when the template data digest verification fails. Indicate the problematic record in the measurement list based on log level and fail verification.
Fixes ff26f9704ec4 ("ima-evm-utils: calculate and verify the templatedata digest")
Kind regards,
Petr
HI Mimi,
Quoted 4 lines
Parameter expects to be a copy of
/sys/class/tpm/tpm0/device/pcrs(i.e. regular file, not a directory, block or character device, socket, ...)Signed-off-by Mimi Zohar <[email protected]>
Kind regards,
Petr