mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 14:53:58 -04:00
ima: Define and use a digest_size field in the ima_algo_desc structure
Add the digest_size field to the ima_algo_desc structure to determine the digest size from the correct source. If the hash algorithm is among allocated PCR banks, take the value from the TPM bank info (equal to the value from the crypto subsystem if the TPM algorithm is supported by it; otherwise, not exceding the size of the digest buffer in the tpm_digest structure, used by IMA). If the hash algorithm is SHA1, use the predefined value. Lastly, if the hash algorithm is the default one but not among the PCR banks, take the digest size from the crypto subsystem (the default hash algorithm is checked when parsing the ima_hash= command line option). Finally, use the new information to correctly show the template digest in ima_measurements_show() and ima_ascii_measurements_show(). Link: https://github.com/linux-integrity/linux/issues/14 Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
This commit is contained in:
committed by
Mimi Zohar
parent
1984dc2c2f
commit
a74d7197eb
@@ -109,6 +109,7 @@ static struct crypto_shash *ima_alloc_tfm(enum hash_algo algo)
|
||||
|
||||
int __init ima_init_crypto(void)
|
||||
{
|
||||
unsigned int digest_size;
|
||||
enum hash_algo algo;
|
||||
long rc;
|
||||
int i;
|
||||
@@ -147,7 +148,9 @@ int __init ima_init_crypto(void)
|
||||
|
||||
for (i = 0; i < NR_BANKS(ima_tpm_chip); i++) {
|
||||
algo = ima_tpm_chip->allocated_banks[i].crypto_id;
|
||||
digest_size = ima_tpm_chip->allocated_banks[i].digest_size;
|
||||
ima_algo_array[i].algo = algo;
|
||||
ima_algo_array[i].digest_size = digest_size;
|
||||
|
||||
/* unknown TPM algorithm */
|
||||
if (algo == HASH_ALGO__LAST)
|
||||
@@ -183,12 +186,15 @@ int __init ima_init_crypto(void)
|
||||
}
|
||||
|
||||
ima_algo_array[ima_sha1_idx].algo = HASH_ALGO_SHA1;
|
||||
ima_algo_array[ima_sha1_idx].digest_size = SHA1_DIGEST_SIZE;
|
||||
}
|
||||
|
||||
if (ima_hash_algo_idx >= NR_BANKS(ima_tpm_chip) &&
|
||||
ima_hash_algo_idx != ima_sha1_idx) {
|
||||
digest_size = hash_digest_size[ima_hash_algo];
|
||||
ima_algo_array[ima_hash_algo_idx].tfm = ima_shash_tfm;
|
||||
ima_algo_array[ima_hash_algo_idx].algo = ima_hash_algo;
|
||||
ima_algo_array[ima_hash_algo_idx].digest_size = digest_size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user