Skip to content

Commit 14bd99c

Browse files
committed
LSM: Separate idea of "major" LSM from "exclusive" LSM
In order to both support old "security=" Legacy Major LSM selection, and handling real exclusivity, this creates LSM_FLAG_EXCLUSIVE and updates the selection logic to handle them. Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
1 parent 7e61148 commit 14bd99c

6 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎include/linux/lsm_hooks.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count,
20432043
char *lsm);
20442044

20452045
#define LSM_FLAG_LEGACY_MAJOR BIT(0)
2046+
#define LSM_FLAG_EXCLUSIVE BIT(1)
20462047

20472048
struct lsm_info {
20482049
const char *name; /* Required. */

‎security/apparmor/lsm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ static int __init apparmor_init(void)
17231723

17241724
DEFINE_LSM(apparmor) = {
17251725
.name = "apparmor",
1726-
.flags = LSM_FLAG_LEGACY_MAJOR,
1726+
.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
17271727
.enabled = &apparmor_enabled,
17281728
.init = apparmor_init,
17291729
};

‎security/security.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static __initconst const char * const builtin_lsm_order = CONFIG_LSM;
4949

5050
/* Ordered list of LSMs to initialize. */
5151
static __initdata struct lsm_info **ordered_lsms;
52+
static __initdata struct lsm_info *exclusive;
5253

5354
static __initdata bool debug;
5455
#define init_debug(...) \
@@ -129,6 +130,12 @@ static bool __init lsm_allowed(struct lsm_info *lsm)
129130
if (!is_enabled(lsm))
130131
return false;
131132

133+
/* Not allowed if another exclusive LSM already initialized. */
134+
if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && exclusive) {
135+
init_debug("exclusive disabled: %s\n", lsm->name);
136+
return false;
137+
}
138+
132139
return true;
133140
}
134141

@@ -144,6 +151,11 @@ static void __init maybe_initialize_lsm(struct lsm_info *lsm)
144151
if (enabled) {
145152
int ret;
146153

154+
if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) {
155+
exclusive = lsm;
156+
init_debug("exclusive chosen: %s\n", lsm->name);
157+
}
158+
147159
init_debug("initializing %s\n", lsm->name);
148160
ret = lsm->init();
149161
WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret);

‎security/selinux/hooks.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6989,7 +6989,7 @@ void selinux_complete_init(void)
69896989
all processes and objects when they are created. */
69906990
DEFINE_LSM(selinux) = {
69916991
.name = "selinux",
6992-
.flags = LSM_FLAG_LEGACY_MAJOR,
6992+
.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
69936993
.enabled = &selinux_enabled,
69946994
.init = selinux_init,
69956995
};

‎security/smack/smack_lsm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4809,6 +4809,6 @@ static __init int smack_init(void)
48094809
*/
48104810
DEFINE_LSM(smack) = {
48114811
.name = "smack",
4812-
.flags = LSM_FLAG_LEGACY_MAJOR,
4812+
.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
48134813
.init = smack_init,
48144814
};

‎security/tomoyo/tomoyo.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,6 @@ static int __init tomoyo_init(void)
550550

551551
DEFINE_LSM(tomoyo) = {
552552
.name = "tomoyo",
553-
.flags = LSM_FLAG_LEGACY_MAJOR,
553+
.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
554554
.init = tomoyo_init,
555555
};

0 commit comments

Comments
 (0)