aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorRoberto Sassu <roberto.sassu@polito.it>2014-10-13 08:08:39 -0400
committerMimi Zohar <zohar@linux.vnet.ibm.com>2014-10-13 08:39:01 -0400
commit7dbdb4206bd69bf518fd76e01f4c5c64cda96455 (patch)
tree29e4d56591d813bfffaf7172ec98b760c9a9fc5a /security
parent71fed2eee0ea76b236f491006078c9d636323184 (diff)
ima: display template format in meas. list if template name length is zero
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>
Diffstat (limited to 'security')
-rw-r--r--security/integrity/ima/ima_fs.c16
-rw-r--r--security/integrity/ima/ima_template.c4
2 files changed, 15 insertions, 5 deletions
diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
index 973b5683a92e..461215e5fd31 100644
--- a/security/integrity/ima/ima_fs.c
+++ b/security/integrity/ima/ima_fs.c
@@ -118,6 +118,7 @@ static int ima_measurements_show(struct seq_file *m, void *v)
118 /* the list never shrinks, so we don't need a lock here */ 118 /* the list never shrinks, so we don't need a lock here */
119 struct ima_queue_entry *qe = v; 119 struct ima_queue_entry *qe = v;
120 struct ima_template_entry *e; 120 struct ima_template_entry *e;
121 char *template_name;
121 int namelen; 122 int namelen;
122 u32 pcr = CONFIG_IMA_MEASURE_PCR_IDX; 123 u32 pcr = CONFIG_IMA_MEASURE_PCR_IDX;
123 bool is_ima_template = false; 124 bool is_ima_template = false;
@@ -128,6 +129,9 @@ static int ima_measurements_show(struct seq_file *m, void *v)
128 if (e == NULL) 129 if (e == NULL)
129 return -1; 130 return -1;
130 131
132 template_name = (e->template_desc->name[0] != '\0') ?
133 e->template_desc->name : e->template_desc->fmt;
134
131 /* 135 /*
132 * 1st: PCRIndex 136 * 1st: PCRIndex
133 * PCR used is always the same (config option) in 137 * PCR used is always the same (config option) in
@@ -139,14 +143,14 @@ static int ima_measurements_show(struct seq_file *m, void *v)
139 ima_putc(m, e->digest, TPM_DIGEST_SIZE); 143 ima_putc(m, e->digest, TPM_DIGEST_SIZE);
140 144
141 /* 3rd: template name size */ 145 /* 3rd: template name size */
142 namelen = strlen(e->template_desc->name); 146 namelen = strlen(template_name);
143 ima_putc(m, &namelen, sizeof(namelen)); 147 ima_putc(m, &namelen, sizeof(namelen));
144 148
145 /* 4th: template name */ 149 /* 4th: template name */
146 ima_putc(m, e->template_desc->name, namelen); 150 ima_putc(m, template_name, namelen);
147 151
148 /* 5th: template length (except for 'ima' template) */ 152 /* 5th: template length (except for 'ima' template) */
149 if (strcmp(e->template_desc->name, IMA_TEMPLATE_IMA_NAME) == 0) 153 if (strcmp(template_name, IMA_TEMPLATE_IMA_NAME) == 0)
150 is_ima_template = true; 154 is_ima_template = true;
151 155
152 if (!is_ima_template) 156 if (!is_ima_template)
@@ -200,6 +204,7 @@ static int ima_ascii_measurements_show(struct seq_file *m, void *v)
200 /* the list never shrinks, so we don't need a lock here */ 204 /* the list never shrinks, so we don't need a lock here */
201 struct ima_queue_entry *qe = v; 205 struct ima_queue_entry *qe = v;
202 struct ima_template_entry *e; 206 struct ima_template_entry *e;
207 char *template_name;
203 int i; 208 int i;
204 209
205 /* get entry */ 210 /* get entry */
@@ -207,6 +212,9 @@ static int ima_ascii_measurements_show(struct seq_file *m, void *v)
207 if (e == NULL) 212 if (e == NULL)
208 return -1; 213 return -1;
209 214
215 template_name = (e->template_desc->name[0] != '\0') ?
216 e->template_desc->name : e->template_desc->fmt;
217
210 /* 1st: PCR used (config option) */ 218 /* 1st: PCR used (config option) */
211 seq_printf(m, "%2d ", CONFIG_IMA_MEASURE_PCR_IDX); 219 seq_printf(m, "%2d ", CONFIG_IMA_MEASURE_PCR_IDX);
212 220
@@ -214,7 +222,7 @@ static int ima_ascii_measurements_show(struct seq_file *m, void *v)
214 ima_print_digest(m, e->digest, TPM_DIGEST_SIZE); 222 ima_print_digest(m, e->digest, TPM_DIGEST_SIZE);
215 223
216 /* 3th: template name */ 224 /* 3th: template name */
217 seq_printf(m, " %s", e->template_desc->name); 225 seq_printf(m, " %s", template_name);
218 226
219 /* 4th: template specific data */ 227 /* 4th: template specific data */
220 for (i = 0; i < e->template_desc->num_fields; i++) { 228 for (i = 0; i < e->template_desc->num_fields; i++) {
diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c
index 1310afc587f3..b7b359ca39ee 100644
--- a/security/integrity/ima/ima_template.c
+++ b/security/integrity/ima/ima_template.c
@@ -176,7 +176,9 @@ int __init ima_init_template(void)
176 &(template->fields), 176 &(template->fields),
177 &(template->num_fields)); 177 &(template->num_fields));
178 if (result < 0) 178 if (result < 0)
179 pr_err("template %s init failed, result: %d\n", template->name); 179 pr_err("template %s init failed, result: %d\n",
180 (strlen(template->name) ?
181 template->name : template->fmt), result);
180 182
181 return result; 183 return result;
182} 184}