]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
ima: display template format in meas. list if template name length is zero
authorRoberto Sassu <roberto.sassu@polito.it>
Mon, 13 Oct 2014 12:08:39 +0000 (14:08 +0200)
committerMimi Zohar <zohar@linux.vnet.ibm.com>
Mon, 13 Oct 2014 12:39:01 +0000 (08:39 -0400)
With the introduction of the 'ima_template_fmt' kernel cmdline parameter,
a user can define a new template descriptor with custom format. However,
in this case, userspace tools will be unable to parse the measurements
list because the new template is unknown. For this reason, this patch
modifies the current IMA behavior to display in the list the template
format instead of the name (only if the length of the latter is zero)
so that a tool can extract needed information if it can handle listed
fields.

This patch also correctly displays the error log message in
ima_init_template() if the selected template cannot be initialized.

Changelog:
 - v3:
   - check the first byte of 'e->template_desc->name' instead of using
     strlen() in ima_fs.c (suggested by Mimi Zohar)

 - v2:
   - print the template format in ima_init_template(), if the selected
     template is custom (Roberto Sassu)

 - v1:
   - fixed patch description (Roberto Sassu, suggested by Mimi Zohar)
   - set 'template_name' variable in ima_fs.c only once
     (Roberto Sassu, suggested by Mimi Zohar)

Signed-off-by: Roberto Sassu <roberto.sassu@polito.it>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
security/integrity/ima/ima_fs.c
security/integrity/ima/ima_template.c

index 973b5683a92ef6a487632701f6ee3ddf5b85a7b4..461215e5fd31d11be9f68c97fac1de09e057b368 100644 (file)
@@ -118,6 +118,7 @@ static int ima_measurements_show(struct seq_file *m, void *v)
        /* the list never shrinks, so we don't need a lock here */
        struct ima_queue_entry *qe = v;
        struct ima_template_entry *e;
+       char *template_name;
        int namelen;
        u32 pcr = CONFIG_IMA_MEASURE_PCR_IDX;
        bool is_ima_template = false;
@@ -128,6 +129,9 @@ static int ima_measurements_show(struct seq_file *m, void *v)
        if (e == NULL)
                return -1;
 
+       template_name = (e->template_desc->name[0] != '\0') ?
+           e->template_desc->name : e->template_desc->fmt;
+
        /*
         * 1st: PCRIndex
         * PCR used is always the same (config option) in
@@ -139,14 +143,14 @@ static int ima_measurements_show(struct seq_file *m, void *v)
        ima_putc(m, e->digest, TPM_DIGEST_SIZE);
 
        /* 3rd: template name size */
-       namelen = strlen(e->template_desc->name);
+       namelen = strlen(template_name);
        ima_putc(m, &namelen, sizeof(namelen));
 
        /* 4th:  template name */
-       ima_putc(m, e->template_desc->name, namelen);
+       ima_putc(m, template_name, namelen);
 
        /* 5th:  template length (except for 'ima' template) */
-       if (strcmp(e->template_desc->name, IMA_TEMPLATE_IMA_NAME) == 0)
+       if (strcmp(template_name, IMA_TEMPLATE_IMA_NAME) == 0)
                is_ima_template = true;
 
        if (!is_ima_template)
@@ -200,6 +204,7 @@ static int ima_ascii_measurements_show(struct seq_file *m, void *v)
        /* the list never shrinks, so we don't need a lock here */
        struct ima_queue_entry *qe = v;
        struct ima_template_entry *e;
+       char *template_name;
        int i;
 
        /* get entry */
@@ -207,6 +212,9 @@ static int ima_ascii_measurements_show(struct seq_file *m, void *v)
        if (e == NULL)
                return -1;
 
+       template_name = (e->template_desc->name[0] != '\0') ?
+           e->template_desc->name : e->template_desc->fmt;
+
        /* 1st: PCR used (config option) */
        seq_printf(m, "%2d ", CONFIG_IMA_MEASURE_PCR_IDX);
 
@@ -214,7 +222,7 @@ static int ima_ascii_measurements_show(struct seq_file *m, void *v)
        ima_print_digest(m, e->digest, TPM_DIGEST_SIZE);
 
        /* 3th:  template name */
-       seq_printf(m, " %s", e->template_desc->name);
+       seq_printf(m, " %s", template_name);
 
        /* 4th:  template specific data */
        for (i = 0; i < e->template_desc->num_fields; i++) {
index 1310afc587f31f8c4b230f8b2bdba5b7027a3c92..b7b359ca39ee12017a0721f011558314c84c9153 100644 (file)
@@ -176,7 +176,9 @@ int __init ima_init_template(void)
                                           &(template->fields),
                                           &(template->num_fields));
        if (result < 0)
-               pr_err("template %s init failed, result: %d\n", template->name);
+               pr_err("template %s init failed, result: %d\n",
+                      (strlen(template->name) ?
+                      template->name : template->fmt), result);
 
        return result;
 }