Skip to content

Commit 5ef4e41

Browse files
committed
LSM: Prepare for reorganizing "security=" logic
This moves the string handling for "security=" boot parameter into a stored pointer instead of a string duplicate. This will allow easier handling of the string when switching logic to use the coming enable/disable infrastructure. Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Casey Schaufler <casey@schaufler-ca.com> Reviewed-by: John Johansen <john.johansen@canonical.com>
1 parent a8027fb commit 5ef4e41

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

‎security/security.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434

3535
#define MAX_LSM_EVM_XATTR 2
3636

37-
/* Maximum number of letters for an LSM name string */
38-
#define SECURITY_NAME_MAX 10
39-
4037
/* How many LSMs were built into the kernel? */
4138
#define LSM_COUNT (__end_lsm_info - __start_lsm_info)
4239

@@ -45,9 +42,8 @@ static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain);
4542

4643
char *lsm_names;
4744
/* Boot-time LSM user choice */
48-
static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
49-
CONFIG_DEFAULT_SECURITY;
5045
static __initdata const char *chosen_lsm_order;
46+
static __initdata const char *chosen_major_lsm;
5147

5248
static __initconst const char * const builtin_lsm_order = CONFIG_LSM;
5349

@@ -138,7 +134,7 @@ static bool __init lsm_allowed(struct lsm_info *lsm)
138134
return true;
139135

140136
/* Disabled if this LSM isn't the chosen one. */
141-
if (strcmp(lsm->name, chosen_lsm) != 0)
137+
if (strcmp(lsm->name, chosen_major_lsm) != 0)
142138
return false;
143139

144140
return true;
@@ -168,6 +164,9 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
168164
struct lsm_info *lsm;
169165
char *sep, *name, *next;
170166

167+
if (!chosen_major_lsm)
168+
chosen_major_lsm = CONFIG_DEFAULT_SECURITY;
169+
171170
sep = kstrdup(order, GFP_KERNEL);
172171
next = sep;
173172
/* Walk the list, looking for matching LSMs. */
@@ -257,12 +256,12 @@ int __init security_init(void)
257256
}
258257

259258
/* Save user chosen LSM */
260-
static int __init choose_lsm(char *str)
259+
static int __init choose_major_lsm(char *str)
261260
{
262-
strncpy(chosen_lsm, str, SECURITY_NAME_MAX);
261+
chosen_major_lsm = str;
263262
return 1;
264263
}
265-
__setup("security=", choose_lsm);
264+
__setup("security=", choose_major_lsm);
266265

267266
/* Explicitly choose LSM initialization order. */
268267
static int __init choose_lsm_order(char *str)

0 commit comments

Comments
 (0)