[PATCH v39 29/42] LSM: secctx provider check on release
Casey Schaufler
casey at schaufler-ca.com
Fri Dec 15 22:16:23 UTC 2023
Verify that the LSM releasing the secctx is the LSM that
allocated it. This was not necessary when only one LSM could
create a secctx, but once there can be more than one it is.
Signed-off-by: Casey Schaufler <casey at schaufler-ca.com>
---
security/apparmor/secid.c | 10 ++--------
security/selinux/hooks.c | 10 ++--------
2 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c
index c9b9a8d90afa..1df08372bf1b 100644
--- a/security/apparmor/secid.c
+++ b/security/apparmor/secid.c
@@ -146,14 +146,8 @@ int apparmor_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
void apparmor_release_secctx(struct lsmcontext *cp)
{
- /*
- * stacking scaffolding:
- * When it is possible for more than one LSM to provide a
- * release hook, do this check:
- * if (cp->id == LSM_ID_APPARMOR || cp->id == LSM_ID_UNDEF)
- */
-
- kfree(cp->context);
+ if (cp->id == LSM_ID_APPARMOR)
+ kfree(cp->context);
}
/**
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 656f25337334..a6deccbbcc40 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -6616,14 +6616,8 @@ static int selinux_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
static void selinux_release_secctx(struct lsmcontext *cp)
{
- /*
- * stacking scaffolding:
- * When it is possible for more than one LSM to provide a
- * release hook, do this check:
- * if (cp->id == LSM_ID_SELINUX || cp->id == LSM_ID_UNDEF)
- */
-
- kfree(cp->context);
+ if (cp->id == LSM_ID_SELINUX)
+ kfree(cp->context);
}
static void selinux_inode_invalidate_secctx(struct inode *inode)
--
2.41.0
More information about the Linux-security-module-archive
mailing list