Skip to content

Commit 7dbdb42

Browse files
Roberto SassuMimi Zohar
authored andcommitted
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 <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent 71fed2e commit 7dbdb42

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

security/integrity/ima/ima_fs.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static int ima_measurements_show(struct seq_file *m, void *v)
118118
/* the list never shrinks, so we don't need a lock here */
119119
struct ima_queue_entry *qe = v;
120120
struct ima_template_entry *e;
121+
char *template_name;
121122
int namelen;
122123
u32 pcr = CONFIG_IMA_MEASURE_PCR_IDX;
123124
bool is_ima_template = false;
@@ -128,6 +129,9 @@ static int ima_measurements_show(struct seq_file *m, void *v)
128129
if (e == NULL)
129130
return -1;
130131

132+
template_name = (e->template_desc->name[0] != '\0') ?
133+
e->template_desc->name : e->template_desc->fmt;
134+
131135
/*
132136
* 1st: PCRIndex
133137
* PCR used is always the same (config option) in
@@ -139,14 +143,14 @@ static int ima_measurements_show(struct seq_file *m, void *v)
139143
ima_putc(m, e->digest, TPM_DIGEST_SIZE);
140144

141145
/* 3rd: template name size */
142-
namelen = strlen(e->template_desc->name);
146+
namelen = strlen(template_name);
143147
ima_putc(m, &namelen, sizeof(namelen));
144148

145149
/* 4th: template name */
146-
ima_putc(m, e->template_desc->name, namelen);
150+
ima_putc(m, template_name, namelen);
147151

148152
/* 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)
150154
is_ima_template = true;
151155

152156
if (!is_ima_template)
@@ -200,21 +204,25 @@ static int ima_ascii_measurements_show(struct seq_file *m, void *v)
200204
/* the list never shrinks, so we don't need a lock here */
201205
struct ima_queue_entry *qe = v;
202206
struct ima_template_entry *e;
207+
char *template_name;
203208
int i;
204209

205210
/* get entry */
206211
e = qe->entry;
207212
if (e == NULL)
208213
return -1;
209214

215+
template_name = (e->template_desc->name[0] != '\0') ?
216+
e->template_desc->name : e->template_desc->fmt;
217+
210218
/* 1st: PCR used (config option) */
211219
seq_printf(m, "%2d ", CONFIG_IMA_MEASURE_PCR_IDX);
212220

213221
/* 2nd: SHA1 template hash */
214222
ima_print_digest(m, e->digest, TPM_DIGEST_SIZE);
215223

216224
/* 3th: template name */
217-
seq_printf(m, " %s", e->template_desc->name);
225+
seq_printf(m, " %s", template_name);
218226

219227
/* 4th: template specific data */
220228
for (i = 0; i < e->template_desc->num_fields; i++) {

security/integrity/ima/ima_template.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ int __init ima_init_template(void)
176176
&(template->fields),
177177
&(template->num_fields));
178178
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);
180182

181183
return result;
182184
}

0 commit comments

Comments
 (0)