Skip to content

Commit a4626e9

Browse files
cschauflerpcmoore
authored andcommitted
lsm: secctx provider check on release
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 <[email protected]> [PM: subject tweak] Signed-off-by: Paul Moore <[email protected]>
1 parent b530104 commit a4626e9

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

security/apparmor/secid.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,11 @@ int apparmor_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
108108

109109
void apparmor_release_secctx(struct lsm_context *cp)
110110
{
111-
/*
112-
* stacking scaffolding:
113-
* When it is possible for more than one LSM to provide a
114-
* release hook, do this check:
115-
* if (cp->id == LSM_ID_APPARMOR || cp->id == LSM_ID_UNDEF)
116-
*/
117-
118-
kfree(cp->context);
111+
if (cp->id == LSM_ID_APPARMOR) {
112+
kfree(cp->context);
113+
cp->context = NULL;
114+
cp->id = LSM_ID_UNDEF;
115+
}
119116
}
120117

121118
/**

security/selinux/hooks.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6672,14 +6672,11 @@ static int selinux_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
66726672

66736673
static void selinux_release_secctx(struct lsm_context *cp)
66746674
{
6675-
/*
6676-
* stacking scaffolding:
6677-
* When it is possible for more than one LSM to provide a
6678-
* release hook, do this check:
6679-
* if (cp->id == LSM_ID_SELINUX || cp->id == LSM_ID_UNDEF)
6680-
*/
6681-
6682-
kfree(cp->context);
6675+
if (cp->id == LSM_ID_SELINUX) {
6676+
kfree(cp->context);
6677+
cp->context = NULL;
6678+
cp->id = LSM_ID_UNDEF;
6679+
}
66836680
}
66846681

66856682
static void selinux_inode_invalidate_secctx(struct inode *inode)

0 commit comments

Comments
 (0)