Skip to content

Commit 8171c8a

Browse files
robertosassugregkh
authored andcommitted
ima: Allow template selection with ima_template[_fmt]= after ima_hash=
commit bb8e52e upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0795b71 commit 8171c8a

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎security/integrity/ima/ima_template.c‎

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

2828
static LIST_HEAD(defined_templates);
2929
static DEFINE_SPINLOCK(template_list);
30+
static int template_setup_done;
3031

3132
static const struct ima_template_field supported_fields[] = {
3233
{.field_id = "d", .field_init = ima_eventdigest_init,
@@ -80,10 +81,11 @@ static int __init ima_template_setup(char *str)
8081
struct ima_template_desc *template_desc;
8182
int template_len = strlen(str);
8283

83-
if (ima_template)
84+
if (template_setup_done)
8485
return 1;
8586

86-
ima_init_template_list();
87+
if (!ima_template)
88+
ima_init_template_list();
8789

8890
/*
8991
* Verify that a template with the supplied name exists.
@@ -107,6 +109,7 @@ static int __init ima_template_setup(char *str)
107109
}
108110

109111
ima_template = template_desc;
112+
template_setup_done = 1;
110113
return 1;
111114
}
112115
__setup("ima_template=", ima_template_setup);
@@ -115,7 +118,7 @@ static int __init ima_template_fmt_setup(char *str)
115118
{
116119
int num_templates = ARRAY_SIZE(builtin_templates);
117120

118-
if (ima_template)
121+
if (template_setup_done)
119122
return 1;
120123

121124
if (template_desc_init_fields(str, NULL, NULL) < 0) {
@@ -126,6 +129,7 @@ static int __init ima_template_fmt_setup(char *str)
126129

127130
builtin_templates[num_templates - 1].fmt = str;
128131
ima_template = builtin_templates + num_templates - 1;
132+
template_setup_done = 1;
129133

130134
return 1;
131135
}

0 commit comments

Comments
 (0)