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>hifive-unleashed-5.1
parent
7e611486d9
commit
14bd99c821
|
@ -2043,6 +2043,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count,
|
||||||
char *lsm);
|
char *lsm);
|
||||||
|
|
||||||
#define LSM_FLAG_LEGACY_MAJOR BIT(0)
|
#define LSM_FLAG_LEGACY_MAJOR BIT(0)
|
||||||
|
#define LSM_FLAG_EXCLUSIVE BIT(1)
|
||||||
|
|
||||||
struct lsm_info {
|
struct lsm_info {
|
||||||
const char *name; /* Required. */
|
const char *name; /* Required. */
|
||||||
|
|
|
@ -1723,7 +1723,7 @@ alloc_out:
|
||||||
|
|
||||||
DEFINE_LSM(apparmor) = {
|
DEFINE_LSM(apparmor) = {
|
||||||
.name = "apparmor",
|
.name = "apparmor",
|
||||||
.flags = LSM_FLAG_LEGACY_MAJOR,
|
.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
|
||||||
.enabled = &apparmor_enabled,
|
.enabled = &apparmor_enabled,
|
||||||
.init = apparmor_init,
|
.init = apparmor_init,
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,6 +49,7 @@ static __initconst const char * const builtin_lsm_order = CONFIG_LSM;
|
||||||
|
|
||||||
/* Ordered list of LSMs to initialize. */
|
/* Ordered list of LSMs to initialize. */
|
||||||
static __initdata struct lsm_info **ordered_lsms;
|
static __initdata struct lsm_info **ordered_lsms;
|
||||||
|
static __initdata struct lsm_info *exclusive;
|
||||||
|
|
||||||
static __initdata bool debug;
|
static __initdata bool debug;
|
||||||
#define init_debug(...) \
|
#define init_debug(...) \
|
||||||
|
@ -129,6 +130,12 @@ static bool __init lsm_allowed(struct lsm_info *lsm)
|
||||||
if (!is_enabled(lsm))
|
if (!is_enabled(lsm))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
/* Not allowed if another exclusive LSM already initialized. */
|
||||||
|
if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && exclusive) {
|
||||||
|
init_debug("exclusive disabled: %s\n", lsm->name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +151,11 @@ static void __init maybe_initialize_lsm(struct lsm_info *lsm)
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) {
|
||||||
|
exclusive = lsm;
|
||||||
|
init_debug("exclusive chosen: %s\n", lsm->name);
|
||||||
|
}
|
||||||
|
|
||||||
init_debug("initializing %s\n", lsm->name);
|
init_debug("initializing %s\n", lsm->name);
|
||||||
ret = lsm->init();
|
ret = lsm->init();
|
||||||
WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret);
|
WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret);
|
||||||
|
|
|
@ -6989,7 +6989,7 @@ void selinux_complete_init(void)
|
||||||
all processes and objects when they are created. */
|
all processes and objects when they are created. */
|
||||||
DEFINE_LSM(selinux) = {
|
DEFINE_LSM(selinux) = {
|
||||||
.name = "selinux",
|
.name = "selinux",
|
||||||
.flags = LSM_FLAG_LEGACY_MAJOR,
|
.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
|
||||||
.enabled = &selinux_enabled,
|
.enabled = &selinux_enabled,
|
||||||
.init = selinux_init,
|
.init = selinux_init,
|
||||||
};
|
};
|
||||||
|
|
|
@ -4809,6 +4809,6 @@ static __init int smack_init(void)
|
||||||
*/
|
*/
|
||||||
DEFINE_LSM(smack) = {
|
DEFINE_LSM(smack) = {
|
||||||
.name = "smack",
|
.name = "smack",
|
||||||
.flags = LSM_FLAG_LEGACY_MAJOR,
|
.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
|
||||||
.init = smack_init,
|
.init = smack_init,
|
||||||
};
|
};
|
||||||
|
|
|
@ -550,6 +550,6 @@ static int __init tomoyo_init(void)
|
||||||
|
|
||||||
DEFINE_LSM(tomoyo) = {
|
DEFINE_LSM(tomoyo) = {
|
||||||
.name = "tomoyo",
|
.name = "tomoyo",
|
||||||
.flags = LSM_FLAG_LEGACY_MAJOR,
|
.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
|
||||||
.init = tomoyo_init,
|
.init = tomoyo_init,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue