Skip to content

Commit 7ca7964

Browse files
robertosassumimizohar
authored andcommitted
ima: Store template digest directly in ima_template_entry
In preparation for the patch that calculates a digest for each allocated PCR bank, this patch passes to ima_calc_field_array_hash() the ima_template_entry structure, so that digests can be directly stored in that structure instead of ima_digest_data. Signed-off-by: Roberto Sassu <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent e144d6b commit 7ca7964

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

security/integrity/ima/ima.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash);
138138
int ima_calc_buffer_hash(const void *buf, loff_t len,
139139
struct ima_digest_data *hash);
140140
int ima_calc_field_array_hash(struct ima_field_data *field_data,
141-
struct ima_template_desc *desc, int num_fields,
142-
struct ima_digest_data *hash);
141+
struct ima_template_entry *entry);
143142
int __init ima_calc_boot_aggregate(struct ima_digest_data *hash);
144143
void ima_add_violation(struct file *file, const unsigned char *filename,
145144
struct integrity_iint_cache *iint,

security/integrity/ima/ima_api.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,16 @@ int ima_store_template(struct ima_template_entry *entry,
9696
static const char audit_cause[] = "hashing_error";
9797
char *template_name = entry->template_desc->name;
9898
int result;
99-
struct {
100-
struct ima_digest_data hdr;
101-
char digest[TPM_DIGEST_SIZE];
102-
} hash;
10399

104100
if (!violation) {
105-
int num_fields = entry->template_desc->num_fields;
106-
107-
/* this function uses default algo */
108-
hash.hdr.algo = HASH_ALGO_SHA1;
109101
result = ima_calc_field_array_hash(&entry->template_data[0],
110-
entry->template_desc,
111-
num_fields, &hash.hdr);
102+
entry);
112103
if (result < 0) {
113104
integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode,
114105
template_name, op,
115106
audit_cause, result, 0);
116107
return result;
117108
}
118-
memcpy(entry->digest, hash.hdr.digest, hash.hdr.length);
119109
}
120110
entry->pcr = pcr;
121111
result = ima_add_template_entry(entry, violation, op, inode, filename);

security/integrity/ima/ima_crypto.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -464,18 +464,16 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash)
464464
* Calculate the hash of template data
465465
*/
466466
static int ima_calc_field_array_hash_tfm(struct ima_field_data *field_data,
467-
struct ima_template_desc *td,
468-
int num_fields,
469-
struct ima_digest_data *hash,
467+
struct ima_template_entry *entry,
470468
struct crypto_shash *tfm)
471469
{
472470
SHASH_DESC_ON_STACK(shash, tfm);
471+
struct ima_template_desc *td = entry->template_desc;
472+
int num_fields = entry->template_desc->num_fields;
473473
int rc, i;
474474

475475
shash->tfm = tfm;
476476

477-
hash->length = crypto_shash_digestsize(tfm);
478-
479477
rc = crypto_shash_init(shash);
480478
if (rc != 0)
481479
return rc;
@@ -504,24 +502,22 @@ static int ima_calc_field_array_hash_tfm(struct ima_field_data *field_data,
504502
}
505503

506504
if (!rc)
507-
rc = crypto_shash_final(shash, hash->digest);
505+
rc = crypto_shash_final(shash, entry->digest);
508506

509507
return rc;
510508
}
511509

512510
int ima_calc_field_array_hash(struct ima_field_data *field_data,
513-
struct ima_template_desc *desc, int num_fields,
514-
struct ima_digest_data *hash)
511+
struct ima_template_entry *entry)
515512
{
516513
struct crypto_shash *tfm;
517514
int rc;
518515

519-
tfm = ima_alloc_tfm(hash->algo);
516+
tfm = ima_alloc_tfm(HASH_ALGO_SHA1);
520517
if (IS_ERR(tfm))
521518
return PTR_ERR(tfm);
522519

523-
rc = ima_calc_field_array_hash_tfm(field_data, desc, num_fields,
524-
hash, tfm);
520+
rc = ima_calc_field_array_hash_tfm(field_data, entry, tfm);
525521

526522
ima_free_tfm(tfm);
527523

0 commit comments

Comments
 (0)