linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ima: Allow template selection with ima_template[_fmt]= after ima_hash=
@ 2022-01-31 17:11 Roberto Sassu
  2022-01-31 19:20 ` Mimi Zohar
  0 siblings, 1 reply; 2+ messages in thread
From: Roberto Sassu @ 2022-01-31 17:11 UTC (permalink / raw)
  To: zohar
  Cc: linux-integrity, linux-security-module, linux-kernel, guozihua,
	Roberto Sassu, stable

Commit c2426d2ad5027 ("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.

Cc: stable@vger.kernel.org
Fixes: c2426d2ad5027 ("ima: added support for new kernel cmdline parameter ima_template_fmt")
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---
 security/integrity/ima/ima_template.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c
index 694560396be0..db1ad6d7a57f 100644
--- a/security/integrity/ima/ima_template.c
+++ b/security/integrity/ima/ima_template.c
@@ -29,6 +29,7 @@ static struct ima_template_desc builtin_templates[] = {
 
 static LIST_HEAD(defined_templates);
 static DEFINE_SPINLOCK(template_list);
+static int template_setup_done;
 
 static const struct ima_template_field supported_fields[] = {
 	{.field_id = "d", .field_init = ima_eventdigest_init,
@@ -101,10 +102,11 @@ static int __init ima_template_setup(char *str)
 	struct ima_template_desc *template_desc;
 	int template_len = strlen(str);
 
-	if (ima_template)
+	if (template_setup_done)
 		return 1;
 
-	ima_init_template_list();
+	if (!ima_template)
+		ima_init_template_list();
 
 	/*
 	 * Verify that a template with the supplied name exists.
@@ -128,6 +130,7 @@ static int __init ima_template_setup(char *str)
 	}
 
 	ima_template = template_desc;
+	template_setup_done = 1;
 	return 1;
 }
 __setup("ima_template=", ima_template_setup);
@@ -136,7 +139,7 @@ static int __init ima_template_fmt_setup(char *str)
 {
 	int num_templates = ARRAY_SIZE(builtin_templates);
 
-	if (ima_template)
+	if (template_setup_done)
 		return 1;
 
 	if (template_desc_init_fields(str, NULL, NULL) < 0) {
@@ -147,6 +150,7 @@ static int __init ima_template_fmt_setup(char *str)
 
 	builtin_templates[num_templates - 1].fmt = str;
 	ima_template = builtin_templates + num_templates - 1;
+	template_setup_done = 1;
 
 	return 1;
 }
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ima: Allow template selection with ima_template[_fmt]= after ima_hash=
  2022-01-31 17:11 [PATCH] ima: Allow template selection with ima_template[_fmt]= after ima_hash= Roberto Sassu
@ 2022-01-31 19:20 ` Mimi Zohar
  0 siblings, 0 replies; 2+ messages in thread
From: Mimi Zohar @ 2022-01-31 19:20 UTC (permalink / raw)
  To: Roberto Sassu
  Cc: linux-integrity, linux-security-module, linux-kernel, guozihua, stable

On Mon, 2022-01-31 at 18:11 +0100, Roberto Sassu wrote:
> Commit c2426d2ad5027 ("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.
> 
> Cc: stable@vger.kernel.org
> Fixes: c2426d2ad5027 ("ima: added support for new kernel cmdline parameter ima_template_fmt")
> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>

Thanks, Roberto.

Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>

Mimi


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-31 19:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-31 17:11 [PATCH] ima: Allow template selection with ima_template[_fmt]= after ima_hash= Roberto Sassu
2022-01-31 19:20 ` Mimi Zohar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).