]> xenbits.xensource.com Git - linux-pvops.git/commitdiff
ima: free duplicate measurement memory
authorRoberto Sassu <roberto.sassu@polito.it>
Mon, 19 Dec 2011 14:57:27 +0000 (15:57 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 25 Jan 2012 21:53:20 +0000 (13:53 -0800)
commit 45fae7493970d7c45626ccd96d4a74f5f1eea5a9 upstream.

Info about new measurements are cached in the iint for performance.  When
the inode is flushed from cache, the associated iint is flushed as well.
Subsequent access to the inode will cause the inode to be re-measured and
will attempt to add a duplicate entry to the measurement list.

This patch frees the duplicate measurement memory, fixing a memory leak.

Signed-off-by: Roberto Sassu <roberto.sassu@polito.it>
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
security/integrity/ima/ima_api.c
security/integrity/ima/ima_queue.c

index 3cd58b60afd26d20c2aa546707ab8f37a1498ee0..852bf8537ea7a572f2ef01b222725c265e7a04fa 100644 (file)
@@ -183,8 +183,8 @@ void ima_store_measurement(struct ima_iint_cache *iint, struct file *file,
        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);
 }
index a0880e9c8e054695c757818b7991b2c37daf38ab..e19316d321119ee8951e15a1ae1a68caa087108a 100644 (file)
@@ -113,6 +113,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;
                }
        }