Commit 7ca79645 authored by Roberto Sassu's avatar Roberto Sassu Committed by Mimi Zohar

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: default avatarRoberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
parent e144d6b2
...@@ -138,8 +138,7 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash); ...@@ -138,8 +138,7 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash);
int ima_calc_buffer_hash(const void *buf, loff_t len, int ima_calc_buffer_hash(const void *buf, loff_t len,
struct ima_digest_data *hash); struct ima_digest_data *hash);
int ima_calc_field_array_hash(struct ima_field_data *field_data, int ima_calc_field_array_hash(struct ima_field_data *field_data,
struct ima_template_desc *desc, int num_fields, struct ima_template_entry *entry);
struct ima_digest_data *hash);
int __init ima_calc_boot_aggregate(struct ima_digest_data *hash); int __init ima_calc_boot_aggregate(struct ima_digest_data *hash);
void ima_add_violation(struct file *file, const unsigned char *filename, void ima_add_violation(struct file *file, const unsigned char *filename,
struct integrity_iint_cache *iint, struct integrity_iint_cache *iint,
......
...@@ -96,26 +96,16 @@ int ima_store_template(struct ima_template_entry *entry, ...@@ -96,26 +96,16 @@ int ima_store_template(struct ima_template_entry *entry,
static const char audit_cause[] = "hashing_error"; static const char audit_cause[] = "hashing_error";
char *template_name = entry->template_desc->name; char *template_name = entry->template_desc->name;
int result; int result;
struct {
struct ima_digest_data hdr;
char digest[TPM_DIGEST_SIZE];
} hash;
if (!violation) { if (!violation) {
int num_fields = entry->template_desc->num_fields;
/* this function uses default algo */
hash.hdr.algo = HASH_ALGO_SHA1;
result = ima_calc_field_array_hash(&entry->template_data[0], result = ima_calc_field_array_hash(&entry->template_data[0],
entry->template_desc, entry);
num_fields, &hash.hdr);
if (result < 0) { if (result < 0) {
integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode, integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode,
template_name, op, template_name, op,
audit_cause, result, 0); audit_cause, result, 0);
return result; return result;
} }
memcpy(entry->digest, hash.hdr.digest, hash.hdr.length);
} }
entry->pcr = pcr; entry->pcr = pcr;
result = ima_add_template_entry(entry, violation, op, inode, filename); result = ima_add_template_entry(entry, violation, op, inode, filename);
......
...@@ -464,18 +464,16 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash) ...@@ -464,18 +464,16 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash)
* Calculate the hash of template data * Calculate the hash of template data
*/ */
static int ima_calc_field_array_hash_tfm(struct ima_field_data *field_data, static int ima_calc_field_array_hash_tfm(struct ima_field_data *field_data,
struct ima_template_desc *td, struct ima_template_entry *entry,
int num_fields,
struct ima_digest_data *hash,
struct crypto_shash *tfm) struct crypto_shash *tfm)
{ {
SHASH_DESC_ON_STACK(shash, tfm); SHASH_DESC_ON_STACK(shash, tfm);
struct ima_template_desc *td = entry->template_desc;
int num_fields = entry->template_desc->num_fields;
int rc, i; int rc, i;
shash->tfm = tfm; shash->tfm = tfm;
hash->length = crypto_shash_digestsize(tfm);
rc = crypto_shash_init(shash); rc = crypto_shash_init(shash);
if (rc != 0) if (rc != 0)
return rc; return rc;
...@@ -504,24 +502,22 @@ static int ima_calc_field_array_hash_tfm(struct ima_field_data *field_data, ...@@ -504,24 +502,22 @@ static int ima_calc_field_array_hash_tfm(struct ima_field_data *field_data,
} }
if (!rc) if (!rc)
rc = crypto_shash_final(shash, hash->digest); rc = crypto_shash_final(shash, entry->digest);
return rc; return rc;
} }
int ima_calc_field_array_hash(struct ima_field_data *field_data, int ima_calc_field_array_hash(struct ima_field_data *field_data,
struct ima_template_desc *desc, int num_fields, struct ima_template_entry *entry)
struct ima_digest_data *hash)
{ {
struct crypto_shash *tfm; struct crypto_shash *tfm;
int rc; int rc;
tfm = ima_alloc_tfm(hash->algo); tfm = ima_alloc_tfm(HASH_ALGO_SHA1);
if (IS_ERR(tfm)) if (IS_ERR(tfm))
return PTR_ERR(tfm); return PTR_ERR(tfm);
rc = ima_calc_field_array_hash_tfm(field_data, desc, num_fields, rc = ima_calc_field_array_hash_tfm(field_data, entry, tfm);
hash, tfm);
ima_free_tfm(tfm); ima_free_tfm(tfm);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment