Skip to content

Commit 7e61148

Browse files
committed
LSM: Refactor "security=" in terms of enable/disable
For what are marked as the Legacy Major LSMs, make them effectively exclusive when selected on the "security=" boot parameter, to handle the future case of when a previously major LSMs become non-exclusive (e.g. when TOMOYO starts blob-sharing). Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
1 parent 5ef4e41 commit 7e61148

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

‎security/security.c‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,6 @@ static bool __init lsm_allowed(struct lsm_info *lsm)
129129
if (!is_enabled(lsm))
130130
return false;
131131

132-
/* Skip major-specific checks if not a major LSM. */
133-
if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0)
134-
return true;
135-
136-
/* Disabled if this LSM isn't the chosen one. */
137-
if (strcmp(lsm->name, chosen_major_lsm) != 0)
138-
return false;
139-
140132
return true;
141133
}
142134

@@ -164,8 +156,28 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
164156
struct lsm_info *lsm;
165157
char *sep, *name, *next;
166158

159+
/* Process "security=", if given. */
167160
if (!chosen_major_lsm)
168161
chosen_major_lsm = CONFIG_DEFAULT_SECURITY;
162+
if (chosen_major_lsm) {
163+
struct lsm_info *major;
164+
165+
/*
166+
* To match the original "security=" behavior, this
167+
* explicitly does NOT fallback to another Legacy Major
168+
* if the selected one was separately disabled: disable
169+
* all non-matching Legacy Major LSMs.
170+
*/
171+
for (major = __start_lsm_info; major < __end_lsm_info;
172+
major++) {
173+
if ((major->flags & LSM_FLAG_LEGACY_MAJOR) &&
174+
strcmp(major->name, chosen_major_lsm) != 0) {
175+
set_enabled(major, false);
176+
init_debug("security=%s disabled: %s\n",
177+
chosen_major_lsm, major->name);
178+
}
179+
}
180+
}
169181

170182
sep = kstrdup(order, GFP_KERNEL);
171183
next = sep;

0 commit comments

Comments
 (0)