Skip to content

Commit 592b104

Browse files
committed
lsm: rename the lsm order variables for consistency
Rename the builtin_lsm_order variable to lsm_order_builtin, chosen_lsm_order to lsm_order_cmdline, chosen_major_lsm to lsm_order_legacy, ordered_lsms[] to lsm_order[], and exclusive to lsm_exclusive. This patch also renames the associated kernel command line parsing functions and adds some basic function comment blocks. The parsing function choose_major_lsm() was renamed to lsm_choose_security(), choose_lsm_order() to lsm_choose_lsm(), and enable_debug() to lsm_debug_enable(). Reviewed-by: Kees Cook <kees@kernel.org> Reviewed-by: John Johansen <john.johansen@canonical.com> Reviewed-by: Casey Schaufler <casey@schaufler-ca.com> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 9f9dc69 commit 592b104

File tree

1 file changed

+48
-38
lines changed

1 file changed

+48
-38
lines changed

security/lsm_init.c

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ char *lsm_names;
1616
extern struct lsm_info __start_lsm_info[], __end_lsm_info[];
1717
extern struct lsm_info __start_early_lsm_info[], __end_early_lsm_info[];
1818

19-
/* Boot-time LSM user choice */
20-
static __initconst const char *const builtin_lsm_order = CONFIG_LSM;
21-
static __initdata const char *chosen_lsm_order;
22-
static __initdata const char *chosen_major_lsm;
19+
/* Build and boot-time LSM ordering. */
20+
static __initconst const char *const lsm_order_builtin = CONFIG_LSM;
21+
static __initdata const char *lsm_order_cmdline;
22+
static __initdata const char *lsm_order_legacy;
2323

2424
/* Ordered list of LSMs to initialize. */
25-
static __initdata struct lsm_info *ordered_lsms[MAX_LSM_COUNT + 1];
26-
static __initdata struct lsm_info *exclusive;
25+
static __initdata struct lsm_info *lsm_order[MAX_LSM_COUNT + 1];
26+
static __initdata struct lsm_info *lsm_exclusive;
2727

2828
static __initdata bool debug;
2929
#define init_debug(...) \
@@ -33,39 +33,49 @@ static __initdata bool debug;
3333
} while (0)
3434

3535
#define lsm_order_for_each(iter) \
36-
for ((iter) = ordered_lsms; *(iter); (iter)++)
36+
for ((iter) = lsm_order; *(iter); (iter)++)
3737
#define lsm_for_each_raw(iter) \
3838
for ((iter) = __start_lsm_info; \
3939
(iter) < __end_lsm_info; (iter)++)
4040
#define lsm_early_for_each_raw(iter) \
4141
for ((iter) = __start_early_lsm_info; \
4242
(iter) < __end_early_lsm_info; (iter)++)
4343

44-
static int lsm_append(const char *new, char **result);
45-
46-
/* Save user chosen LSM */
47-
static int __init choose_major_lsm(char *str)
44+
/**
45+
* lsm_choose_security - Legacy "major" LSM selection
46+
* @str: kernel command line parameter
47+
*/
48+
static int __init lsm_choose_security(char *str)
4849
{
49-
chosen_major_lsm = str;
50+
lsm_order_legacy = str;
5051
return 1;
5152
}
52-
__setup("security=", choose_major_lsm);
53+
__setup("security=", lsm_choose_security);
5354

54-
/* Explicitly choose LSM initialization order. */
55-
static int __init choose_lsm_order(char *str)
55+
/**
56+
* lsm_choose_lsm - Modern LSM selection
57+
* @str: kernel command line parameter
58+
*/
59+
static int __init lsm_choose_lsm(char *str)
5660
{
57-
chosen_lsm_order = str;
61+
lsm_order_cmdline = str;
5862
return 1;
5963
}
60-
__setup("lsm=", choose_lsm_order);
64+
__setup("lsm=", lsm_choose_lsm);
6165

62-
/* Enable LSM order debugging. */
63-
static int __init enable_debug(char *str)
66+
/**
67+
* lsm_debug_enable - Enable LSM framework debugging
68+
* @str: kernel command line parameter
69+
*
70+
* Currently we only provide debug info during LSM initialization, but we may
71+
* want to expand this in the future.
72+
*/
73+
static int __init lsm_debug_enable(char *str)
6474
{
6575
debug = true;
6676
return 1;
6777
}
68-
__setup("lsm.debug", enable_debug);
78+
__setup("lsm.debug", lsm_debug_enable);
6979

7080
/* Mark an LSM's enabled flag. */
7181
static int lsm_enabled_true __initdata = 1;
@@ -127,7 +137,7 @@ static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from)
127137
/* Enable this LSM, if it is not already set. */
128138
if (!lsm->enabled)
129139
lsm->enabled = &lsm_enabled_true;
130-
ordered_lsms[last_lsm] = lsm;
140+
lsm_order[last_lsm] = lsm;
131141
lsm_idlist[last_lsm++] = lsm->id;
132142

133143
init_debug("%s ordered: %s (%s)\n", from, lsm->id->name,
@@ -157,17 +167,17 @@ static void __init lsm_prepare(struct lsm_info *lsm)
157167
if (!is_enabled(lsm)) {
158168
set_enabled(lsm, false);
159169
return;
160-
} else if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && exclusive) {
170+
} else if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && lsm_exclusive) {
161171
init_debug("exclusive disabled: %s\n", lsm->id->name);
162172
set_enabled(lsm, false);
163173
return;
164174
}
165175

166176
/* Mark the LSM as enabled. */
167177
set_enabled(lsm, true);
168-
if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) {
178+
if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !lsm_exclusive) {
169179
init_debug("exclusive chosen: %s\n", lsm->id->name);
170-
exclusive = lsm;
180+
lsm_exclusive = lsm;
171181
}
172182

173183
/* Register the LSM blob sizes. */
@@ -226,7 +236,7 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
226236
}
227237

228238
/* Process "security=", if given. */
229-
if (chosen_major_lsm) {
239+
if (lsm_order_legacy) {
230240
struct lsm_info *major;
231241

232242
/*
@@ -237,10 +247,10 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
237247
*/
238248
lsm_for_each_raw(major) {
239249
if ((major->flags & LSM_FLAG_LEGACY_MAJOR) &&
240-
strcmp(major->id->name, chosen_major_lsm) != 0) {
250+
strcmp(major->id->name, lsm_order_legacy) != 0) {
241251
set_enabled(major, false);
242252
init_debug("security=%s disabled: %s (only one legacy major LSM)\n",
243-
chosen_major_lsm, major->id->name);
253+
lsm_order_legacy, major->id->name);
244254
}
245255
}
246256
}
@@ -265,11 +275,11 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
265275
}
266276

267277
/* Process "security=", if given. */
268-
if (chosen_major_lsm) {
278+
if (lsm_order_legacy) {
269279
lsm_for_each_raw(lsm) {
270280
if (exists_ordered_lsm(lsm))
271281
continue;
272-
if (strcmp(lsm->id->name, chosen_major_lsm) == 0)
282+
if (strcmp(lsm->id->name, lsm_order_legacy) == 0)
273283
append_ordered_lsm(lsm, "security=");
274284
}
275285
}
@@ -301,15 +311,15 @@ static void __init lsm_init_ordered(void)
301311
struct lsm_info **lsm;
302312
struct lsm_info *early;
303313

304-
if (chosen_lsm_order) {
305-
if (chosen_major_lsm) {
314+
if (lsm_order_cmdline) {
315+
if (lsm_order_legacy) {
306316
pr_warn("security=%s is ignored because it is superseded by lsm=%s\n",
307-
chosen_major_lsm, chosen_lsm_order);
308-
chosen_major_lsm = NULL;
317+
lsm_order_legacy, lsm_order_cmdline);
318+
lsm_order_legacy = NULL;
309319
}
310-
ordered_lsm_parse(chosen_lsm_order, "cmdline");
320+
ordered_lsm_parse(lsm_order_cmdline, "cmdline");
311321
} else
312-
ordered_lsm_parse(builtin_lsm_order, "builtin");
322+
ordered_lsm_parse(lsm_order_builtin, "builtin");
313323

314324
lsm_order_for_each(lsm) {
315325
lsm_prepare(*lsm);
@@ -473,9 +483,9 @@ int __init security_init(void)
473483
{
474484
struct lsm_info *lsm;
475485

476-
init_debug("legacy security=%s\n", chosen_major_lsm ? : " *unspecified*");
477-
init_debug(" CONFIG_LSM=%s\n", builtin_lsm_order);
478-
init_debug("boot arg lsm=%s\n", chosen_lsm_order ? : " *unspecified*");
486+
init_debug("legacy security=%s\n", lsm_order_legacy ? : " *unspecified*");
487+
init_debug(" CONFIG_LSM=%s\n", lsm_order_builtin);
488+
init_debug("boot arg lsm=%s\n", lsm_order_cmdline ? : " *unspecified*");
479489

480490
/*
481491
* Append the names of the early LSM modules now that kmalloc() is

0 commit comments

Comments
 (0)