linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] security: Introduce LSM_ORDER_LAST and set it for the integrity LSM
@ 2023-03-08 17:11 Roberto Sassu
  2023-03-08 17:11 ` [PATCH] Revert "integrity: double check iint_cache was initialized" Roberto Sassu
  2023-03-09  0:23 ` [PATCH v2] security: Introduce LSM_ORDER_LAST and set it for the integrity LSM Mimi Zohar
  0 siblings, 2 replies; 4+ messages in thread
From: Roberto Sassu @ 2023-03-08 17:11 UTC (permalink / raw)
  To: zohar, dmitry.kasatkin, paul, jmorris, serge
  Cc: linux-integrity, linux-security-module, linux-kernel, keescook,
	Roberto Sassu

From: Roberto Sassu <roberto.sassu@huawei.com>

Introduce LSM_ORDER_LAST, to satisfy the requirement of LSMs willing to be
the last, e.g. the 'integrity' LSM, without changing the kernel command
line or configuration.

Also, set this order for the 'integrity' LSM. While not enforced, this is
the only LSM expected to use it.

Similarly to LSM_ORDER_FIRST, LSMs with LSM_ORDER_LAST are always enabled
and put at the end of the LSM list.

Finally, for LSM_ORDER_MUTABLE LSMs, set the found variable to true if an
LSM is found, regardless of its order. In this way, the kernel would not
wrongly report that the LSM is not built-in in the kernel if its order is
LSM_ORDER_LAST.

Fixes: 79f7865d844c ("LSM: Introduce "lsm=" for boottime LSM selection")
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---

Changelog

v1:
- Add comment for LSM_ORDER_LAST definition (suggested by Mimi)
- Add Fixes tag (suggested by Mimi)
- Do minor corrections in the commit messages (suggested by Mimi and Stefan)

 include/linux/lsm_hooks.h |  1 +
 security/integrity/iint.c |  1 +
 security/security.c       | 12 +++++++++---
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index 6e156d2acff..c55761d93a2 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -1716,6 +1716,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count,
 enum lsm_order {
 	LSM_ORDER_FIRST = -1,	/* This is only for capabilities. */
 	LSM_ORDER_MUTABLE = 0,
+	LSM_ORDER_LAST = 1,	/* This is only for integrity. */
 };
 
 struct lsm_info {
diff --git a/security/integrity/iint.c b/security/integrity/iint.c
index 8638976f799..b97eb59e0e3 100644
--- a/security/integrity/iint.c
+++ b/security/integrity/iint.c
@@ -182,6 +182,7 @@ static int __init integrity_iintcache_init(void)
 DEFINE_LSM(integrity) = {
 	.name = "integrity",
 	.init = integrity_iintcache_init,
+	.order = LSM_ORDER_LAST,
 };
 
 
diff --git a/security/security.c b/security/security.c
index cf6cc576736..2f36229d5b6 100644
--- a/security/security.c
+++ b/security/security.c
@@ -284,9 +284,9 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
 		bool found = false;
 
 		for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
-			if (lsm->order == LSM_ORDER_MUTABLE &&
-			    strcmp(lsm->name, name) == 0) {
-				append_ordered_lsm(lsm, origin);
+			if (strcmp(lsm->name, name) == 0) {
+				if (lsm->order == LSM_ORDER_MUTABLE)
+					append_ordered_lsm(lsm, origin);
 				found = true;
 			}
 		}
@@ -306,6 +306,12 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
 		}
 	}
 
+	/* LSM_ORDER_LAST is always last. */
+	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+		if (lsm->order == LSM_ORDER_LAST)
+			append_ordered_lsm(lsm, "   last");
+	}
+
 	/* Disable all LSMs not in the ordered list. */
 	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
 		if (exists_ordered_lsm(lsm))
-- 
2.25.1


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

* [PATCH] Revert "integrity: double check iint_cache was initialized"
  2023-03-08 17:11 [PATCH v2] security: Introduce LSM_ORDER_LAST and set it for the integrity LSM Roberto Sassu
@ 2023-03-08 17:11 ` Roberto Sassu
  2023-03-09  0:23 ` [PATCH v2] security: Introduce LSM_ORDER_LAST and set it for the integrity LSM Mimi Zohar
  1 sibling, 0 replies; 4+ messages in thread
From: Roberto Sassu @ 2023-03-08 17:11 UTC (permalink / raw)
  To: zohar, dmitry.kasatkin, paul, jmorris, serge
  Cc: linux-integrity, linux-security-module, linux-kernel, keescook,
	Roberto Sassu

From: Roberto Sassu <roberto.sassu@huawei.com>

With the recent introduction of LSM_ORDER_LAST, the 'integrity' LSM is
always initialized and the iint_cache is always created (the kernel panics
on error). Thus, the additional check of iint_cache in
integrity_inode_get() is no longer necessary.

This reverts commit 92063f3ca73aab794bd5408d3361fd5b5ea33079.

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---
 security/integrity/iint.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/security/integrity/iint.c b/security/integrity/iint.c
index b97eb59e0e3..c73858e8c6d 100644
--- a/security/integrity/iint.c
+++ b/security/integrity/iint.c
@@ -98,14 +98,6 @@ struct integrity_iint_cache *integrity_inode_get(struct inode *inode)
 	struct rb_node *node, *parent = NULL;
 	struct integrity_iint_cache *iint, *test_iint;
 
-	/*
-	 * The integrity's "iint_cache" is initialized at security_init(),
-	 * unless it is not included in the ordered list of LSMs enabled
-	 * on the boot command line.
-	 */
-	if (!iint_cache)
-		panic("%s: lsm=integrity required.\n", __func__);
-
 	iint = integrity_iint_find(inode);
 	if (iint)
 		return iint;
-- 
2.25.1


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

* Re: [PATCH v2] security: Introduce LSM_ORDER_LAST and set it for the integrity LSM
  2023-03-08 17:11 [PATCH v2] security: Introduce LSM_ORDER_LAST and set it for the integrity LSM Roberto Sassu
  2023-03-08 17:11 ` [PATCH] Revert "integrity: double check iint_cache was initialized" Roberto Sassu
@ 2023-03-09  0:23 ` Mimi Zohar
  2023-03-09  7:55   ` Roberto Sassu
  1 sibling, 1 reply; 4+ messages in thread
From: Mimi Zohar @ 2023-03-09  0:23 UTC (permalink / raw)
  To: Roberto Sassu, dmitry.kasatkin, paul, jmorris, serge
  Cc: linux-integrity, linux-security-module, linux-kernel, keescook,
	Roberto Sassu

On Wed, 2023-03-08 at 18:11 +0100, Roberto Sassu wrote:
> From: Roberto Sassu <roberto.sassu@huawei.com>
> 
> Introduce LSM_ORDER_LAST, to satisfy the requirement of LSMs willing to be
> the last, e.g. the 'integrity' LSM, without changing the kernel command
> line or configuration.

^needing to be last

> 
> Also, set this order for the 'integrity' LSM. While not enforced, this is
> the only LSM expected to use it.
> 
> Similarly to LSM_ORDER_FIRST, LSMs with LSM_ORDER_LAST are always enabled
> and put at the end of the LSM list.
> 
> Finally, for LSM_ORDER_MUTABLE LSMs, set the found variable to true if an
> LSM is found, regardless of its order. In this way, the kernel would not
> wrongly report that the LSM is not built-in in the kernel if its order is
> LSM_ORDER_LAST.
> 
> Fixes: 79f7865d844c ("LSM: Introduce "lsm=" for boottime LSM selection")
> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>

Thanks, Roberto.  With this patch, 'integrity' can be safely removed
from CONFIG_LSM definitions.

-- 
thanks,

Mimi



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

* Re: [PATCH v2] security: Introduce LSM_ORDER_LAST and set it for the integrity LSM
  2023-03-09  0:23 ` [PATCH v2] security: Introduce LSM_ORDER_LAST and set it for the integrity LSM Mimi Zohar
@ 2023-03-09  7:55   ` Roberto Sassu
  0 siblings, 0 replies; 4+ messages in thread
From: Roberto Sassu @ 2023-03-09  7:55 UTC (permalink / raw)
  To: Mimi Zohar, dmitry.kasatkin, paul, jmorris, serge
  Cc: linux-integrity, linux-security-module, linux-kernel, keescook,
	Roberto Sassu

On Wed, 2023-03-08 at 19:23 -0500, Mimi Zohar wrote:
> On Wed, 2023-03-08 at 18:11 +0100, Roberto Sassu wrote:
> > From: Roberto Sassu <roberto.sassu@huawei.com>
> > 
> > Introduce LSM_ORDER_LAST, to satisfy the requirement of LSMs willing to be
> > the last, e.g. the 'integrity' LSM, without changing the kernel command
> > line or configuration.
> 
> ^needing to be last

Ok.

> > Also, set this order for the 'integrity' LSM. While not enforced, this is
> > the only LSM expected to use it.
> > 
> > Similarly to LSM_ORDER_FIRST, LSMs with LSM_ORDER_LAST are always enabled
> > and put at the end of the LSM list.
> > 
> > Finally, for LSM_ORDER_MUTABLE LSMs, set the found variable to true if an
> > LSM is found, regardless of its order. In this way, the kernel would not
> > wrongly report that the LSM is not built-in in the kernel if its order is
> > LSM_ORDER_LAST.
> > 
> > Fixes: 79f7865d844c ("LSM: Introduce "lsm=" for boottime LSM selection")
> > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> 
> Thanks, Roberto.  With this patch, 'integrity' can be safely removed
> from CONFIG_LSM definitions.

Perfect, will add the new patch.

Thanks

Roberto


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

end of thread, other threads:[~2023-03-09  7:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-08 17:11 [PATCH v2] security: Introduce LSM_ORDER_LAST and set it for the integrity LSM Roberto Sassu
2023-03-08 17:11 ` [PATCH] Revert "integrity: double check iint_cache was initialized" Roberto Sassu
2023-03-09  0:23 ` [PATCH v2] security: Introduce LSM_ORDER_LAST and set it for the integrity LSM Mimi Zohar
2023-03-09  7:55   ` Roberto Sassu

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).