Limit comparing the calculated PCR value to just a single bank
Mimi Zohar
maintainerPATCH 1/1 Limit comparing the calculated PCR value to just a single bank
TPM 2.0 banks may be extended either with a padded SHA1 hash or more recently with a per TPM bank calculated hash. If the measurement list is carried across kexec, the original kernel might extend the TPM differently than the new kernel.
Support for verifying a mixed IMA measurement list is not supported. To permit verifying just the SHA1 bank, specify "--verify-bank=sha1" on the command line.
--- src/evmctl.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
src/evmctl.c +16 -1
@@ -125,6 +125,7 @@ static char *caps_str;static char *ima_str;static char *selinux_str;static char *search_type; +static char *verify_bank;static int verify_list_sig;static int recursive;static int msize;
@@ -2011,6 +2012,16 @@ static int ima_measurement(const char *file) pseudo_banks_mask = (1 << num_banks) -1 ; pseudo_padded_banks_mask = pseudo_banks_mask; +/* Instead of verifying all the banks, only verify a single bank */ +for (c =0 ; c < num_banks; c++) { +if (verify_bank + &&strcmp (pseudo_padded_banks[c].algo_name, verify_bank)) { + pseudo_banks_mask ^= (1 << c); + pseudo_padded_banks_mask ^= (1 << c); +break ; + } + } +while (fread (&entry.header,sizeof (entry.header),1 , fp)) { entry_num++;if (entry.header.name_len >TCG_EVENT_NAME_LEN_MAX ) {
@@ -2537,7 +2548,7 @@ struct command cmds[] = { {"ima_verify", cmd_verify_ima, 0, "file", "Verify IMA signature (for debugging).\n"}, {"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, "[--ignore-violations] [--verify-sig [--key key1, key2, ...]] [--pcrs [hash-algorithm,]file [--pcrs hash-algorithm,file] ...] file", "Verify measurement list (experimental).\n"}, + {"ima_measurement", cmd_ima_measurement, 0, "[--ignore-violations] [--verify-sig [--key key1, key2, ...]] [--pcrs [hash-algorithm,]file [--pcrs hash-algorithm,file] ...] [--verify-bank hash-algorithm] file", "Verify measurement list (experimental).\n"}, {"ima_boot_aggregate", cmd_ima_bootaggr, 0, "[--pcrs hash-algorithm,file] [TPM 1.2 BIOS event log]", "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"},
@@ -2578,6 +2589,7 @@ static struct option opts[] = { {"xattr-user", 0, 0, 140}, {"ignore-violations", 0, 0, 141}, {"pcrs", 1, 0, 142}, + {"verify-bank", 2, 0, 143}, {} };
@@ -2766,6 +2778,9 @@ int main(int argc, char *argv[]) } pcrfile[npcrfile++] = optarg;break ; +case 143 : + verify_bank = optarg; +break ;case '?' :exit (1 );break ;
Signature · 1 line
2.27.0
Quoted 61 lines · Mimi Zohar
TPM 2.0 banks may be extended either with a padded SHA1 hash or more recently with a per TPM bank calculated hash. If the measurement list is carried across kexec, the original kernel might extend the TPM differently than the new kernel.
Support for verifying a mixed IMA measurement list is not supported. To permit verifying just the SHA1 bank, specify "--verify-bank=sha1" on the command line.
Signed-off-by Mimi Zohar <[email protected]>--- src/evmctl.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)src/evmctl.c +13
-1@@ -125,6 +125,7 @@ static char *caps_str;static char *ima_str;static char *selinux_str;static char *search_type; +static char *verify_bank;static int verify_list_sig;static int recursive;static int msize;@@ -2011,6 +2012,16 @@ static int ima_measurement(const char *file) pseudo_banks_mask = (1 << num_banks) -1 ; pseudo_padded_banks_mask = pseudo_banks_mask; +/* Instead of verifying all the banks, only verify a single bank */ +for (c =0 ; c < num_banks; c++) { +if (verify_bank + &&strcmp (pseudo_padded_banks[c].algo_name, verify_bank)) { + pseudo_banks_mask ^= (1 << c); + pseudo_padded_banks_mask ^= (1 << c); +break ; + } + } +while (fread (&entry.header,sizeof (entry.header),1 , fp)) { entry_num++;if (entry.header.name_len >TCG_EVENT_NAME_LEN_MAX ) {@@ -2537,7 +2548,7 @@ struct command cmds[] = { {"ima_verify", cmd_verify_ima, 0, "file", "Verify IMA signature (for debugging).\n"}, {"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, "[--ignore-violations] [--verify-sig [--key key1, key2, ...]] [--pcrs [hash-algorithm,]file [--pcrs hash-algorithm,file] ...] file", "Verify measurement list (experimental).\n"}, + {"ima_measurement", cmd_ima_measurement, 0, "[--ignore-violations] [--verify-sig [--key key1, key2, ...]] [--pcrs [hash-algorithm,]file [--pcrs hash-algorithm,file] ...] [--verify-bank hash-algorithm] file", "Verify measurement list (experimental).\n"}, {"ima_boot_aggregate", cmd_ima_bootaggr, 0, "[--pcrs hash-algorithm,file] [TPM 1.2 BIOS event log]", "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"},@@ -2578,6 +2589,7 @@ static struct option opts[] = { {"xattr-user", 0, 0, 140}, {"ignore-violations", 0, 0, 141}, {"pcrs", 1, 0, 142}, + {"verify-bank", 2, 0, 143}, {} };
src/evmctl.c int main(int argc, char *argv[]) · line 2786
Quoted 9 lines
src/evmctl.c +3
-0@@ -2766,6 +2778,9 @@ int main(int argc, char *argv[]) } pcrfile[npcrfile++] = optarg;break ; +case 143 : + verify_bank = optarg; +break ;case '?' :exit (1 );break ;