Skip to content

Commit 71fed2e

Browse files
Roberto SassuMimi Zohar
authored andcommitted
ima: added error messages to template-related functions
This patch adds some error messages to inform users about the following events: template descriptor not found, invalid template descriptor, template field not found and template initialization failed. Changelog: - v2: - display an error message if the format string contains too many fields (Roberto Sassu) Signed-off-by: Roberto Sassu <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent 0716abb commit 71fed2e

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

security/integrity/ima/ima_template.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ static int __init ima_template_setup(char *str)
5252
* If not, use CONFIG_IMA_DEFAULT_TEMPLATE.
5353
*/
5454
template_desc = lookup_template_desc(str);
55-
if (!template_desc)
55+
if (!template_desc) {
56+
pr_err("template %s not found, using %s\n",
57+
str, CONFIG_IMA_DEFAULT_TEMPLATE);
5658
return 1;
59+
}
5760

5861
/*
5962
* Verify whether the current hash algorithm is supported
@@ -117,8 +120,11 @@ static int template_desc_init_fields(const char *template_fmt,
117120
int template_num_fields = template_fmt_size(template_fmt);
118121
int i, result = 0;
119122

120-
if (template_num_fields > IMA_TEMPLATE_NUM_FIELDS_MAX)
123+
if (template_num_fields > IMA_TEMPLATE_NUM_FIELDS_MAX) {
124+
pr_err("format string '%s' contains too many fields\n",
125+
template_fmt);
121126
return -EINVAL;
127+
}
122128

123129
/* copying is needed as strsep() modifies the original buffer */
124130
template_fmt_copy = kstrdup(template_fmt, GFP_KERNEL);
@@ -137,6 +143,7 @@ static int template_desc_init_fields(const char *template_fmt,
137143
struct ima_template_field *f = lookup_template_field(c);
138144

139145
if (!f) {
146+
pr_err("field '%s' not found\n", c);
140147
result = -ENOENT;
141148
goto out;
142149
}
@@ -163,8 +170,13 @@ struct ima_template_desc *ima_template_desc_current(void)
163170
int __init ima_init_template(void)
164171
{
165172
struct ima_template_desc *template = ima_template_desc_current();
173+
int result;
166174

167-
return template_desc_init_fields(template->fmt,
168-
&(template->fields),
169-
&(template->num_fields));
175+
result = template_desc_init_fields(template->fmt,
176+
&(template->fields),
177+
&(template->num_fields));
178+
if (result < 0)
179+
pr_err("template %s init failed, result: %d\n", template->name);
180+
181+
return result;
170182
}

0 commit comments

Comments
 (0)