Skip to content

Commit bb8e52e

Browse files
robertosassumimizohar
authored andcommitted
ima: Allow template selection with ima_template[_fmt]= after ima_hash=
Commit c2426d2 ("ima: added support for new kernel cmdline parameter ima_template_fmt") introduced an additional check on the ima_template variable to avoid multiple template selection. Unfortunately, ima_template could be also set by the setup function of the ima_hash= parameter, when it calls ima_template_desc_current(). This causes attempts to choose a new template with ima_template= or with ima_template_fmt=, after ima_hash=, to be ignored. Achieve the goal of the commit mentioned with the new static variable template_setup_done, so that template selection requests after ima_hash= are not ignored. Finally, call ima_init_template_list(), if not already done, to initialize the list of templates before lookup_template_desc() is called. Reported-by: Guo Zihua <guozihua@huawei.com> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Cc: stable@vger.kernel.org Fixes: c2426d2 ("ima: added support for new kernel cmdline parameter ima_template_fmt") Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent f7333b9 commit bb8e52e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

security/integrity/ima/ima_template.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static struct ima_template_desc builtin_templates[] = {
2929

3030
static LIST_HEAD(defined_templates);
3131
static DEFINE_SPINLOCK(template_list);
32+
static int template_setup_done;
3233

3334
static const struct ima_template_field supported_fields[] = {
3435
{.field_id = "d", .field_init = ima_eventdigest_init,
@@ -101,10 +102,11 @@ static int __init ima_template_setup(char *str)
101102
struct ima_template_desc *template_desc;
102103
int template_len = strlen(str);
103104

104-
if (ima_template)
105+
if (template_setup_done)
105106
return 1;
106107

107-
ima_init_template_list();
108+
if (!ima_template)
109+
ima_init_template_list();
108110

109111
/*
110112
* Verify that a template with the supplied name exists.
@@ -128,6 +130,7 @@ static int __init ima_template_setup(char *str)
128130
}
129131

130132
ima_template = template_desc;
133+
template_setup_done = 1;
131134
return 1;
132135
}
133136
__setup("ima_template=", ima_template_setup);
@@ -136,7 +139,7 @@ static int __init ima_template_fmt_setup(char *str)
136139
{
137140
int num_templates = ARRAY_SIZE(builtin_templates);
138141

139-
if (ima_template)
142+
if (template_setup_done)
140143
return 1;
141144

142145
if (template_desc_init_fields(str, NULL, NULL) < 0) {
@@ -147,6 +150,7 @@ static int __init ima_template_fmt_setup(char *str)
147150

148151
builtin_templates[num_templates - 1].fmt = str;
149152
ima_template = builtin_templates + num_templates - 1;
153+
template_setup_done = 1;
150154

151155
return 1;
152156
}

0 commit comments

Comments
 (0)