Messages in this thread Patch in this message | | | From | Roberto Sassu <> | Subject | [PATCH 2/2] ima: free memory of unused template entries | Date | Wed, 16 Nov 2011 11:10:26 +0100 |
| |
This patch solves the following issues: - free the memory allocated for template entries that are already present in the measurements list; - since template entries are added to the measurements list after the PCR extend operation (with the previous patch), they can be now safely removed if the latter fails.
Signed-off-by: Roberto Sassu <roberto.sassu@polito.it> --- security/integrity/ima/ima_api.c | 4 ++-- security/integrity/ima/ima_queue.c | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c index 0d50df0..88a2788 100644 --- a/security/integrity/ima/ima_api.c +++ b/security/integrity/ima/ima_api.c @@ -178,8 +178,8 @@ void ima_store_measurement(struct integrity_iint_cache *iint, strncpy(entry->template.file_name, filename, IMA_EVENT_NAME_LEN_MAX); result = ima_store_template(entry, violation, inode); - if (!result) + if (!result || result == -EEXIST) iint->flags |= IMA_MEASURED; - else + if (result < 0) kfree(entry); } diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c index ddc7e18..7ae1e9a 100644 --- a/security/integrity/ima/ima_queue.c +++ b/security/integrity/ima/ima_queue.c @@ -105,7 +105,8 @@ static int ima_pcr_extend(const u8 *hash) result = tpm_pcr_extend(TPM_ANY_NUM, CONFIG_IMA_MEASURE_PCR_IDX, hash); if (result != 0) - pr_err("IMA: Error Communicating to TPM chip\n"); + pr_err("IMA: Error Communicating to TPM chip, result: %d\n", + result); return result; } @@ -126,6 +127,7 @@ int ima_add_template_entry(struct ima_template_entry *entry, int violation, memcpy(digest, entry->digest, sizeof digest); if (ima_lookup_digest_entry(digest)) { audit_cause = "hash_exists"; + result = -EEXIST; goto out; } } @@ -145,6 +147,7 @@ int ima_add_template_entry(struct ima_template_entry *entry, int violation, if (result != 0) { audit_cause = "TPM error"; audit_info = 0; + result = -ECOMM; kfree(qe); goto out; } -- 1.7.6.4 [unhandled content-type:application/x-pkcs7-signature] | |