Skip to content

Commit d6bd12e

Browse files
Tetsuo Handapcmoore
authored andcommitted
lsm: remove LSM_COUNT and LSM_CONFIG_COUNT
Because these are equals to MAX_LSM_COUNT. Also, we can avoid dynamic memory allocation for ordered_lsms because MAX_LSM_COUNT is a constant. Signed-off-by: Tetsuo Handa <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent f5dafb8 commit d6bd12e

File tree

1 file changed

+4
-33
lines changed

1 file changed

+4
-33
lines changed

security/security.c

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,6 @@
3333
#include <net/flow.h>
3434
#include <net/sock.h>
3535

36-
/* How many LSMs were built into the kernel? */
37-
#define LSM_COUNT (__end_lsm_info - __start_lsm_info)
38-
39-
/*
40-
* How many LSMs are built into the kernel as determined at
41-
* build time. Used to determine fixed array sizes.
42-
* The capability module is accounted for by CONFIG_SECURITY
43-
*/
44-
#define LSM_CONFIG_COUNT ( \
45-
(IS_ENABLED(CONFIG_SECURITY) ? 1 : 0) + \
46-
(IS_ENABLED(CONFIG_SECURITY_SELINUX) ? 1 : 0) + \
47-
(IS_ENABLED(CONFIG_SECURITY_SMACK) ? 1 : 0) + \
48-
(IS_ENABLED(CONFIG_SECURITY_TOMOYO) ? 1 : 0) + \
49-
(IS_ENABLED(CONFIG_SECURITY_APPARMOR) ? 1 : 0) + \
50-
(IS_ENABLED(CONFIG_SECURITY_YAMA) ? 1 : 0) + \
51-
(IS_ENABLED(CONFIG_SECURITY_LOADPIN) ? 1 : 0) + \
52-
(IS_ENABLED(CONFIG_SECURITY_SAFESETID) ? 1 : 0) + \
53-
(IS_ENABLED(CONFIG_SECURITY_LOCKDOWN_LSM) ? 1 : 0) + \
54-
(IS_ENABLED(CONFIG_BPF_LSM) ? 1 : 0) + \
55-
(IS_ENABLED(CONFIG_SECURITY_LANDLOCK) ? 1 : 0) + \
56-
(IS_ENABLED(CONFIG_IMA) ? 1 : 0) + \
57-
(IS_ENABLED(CONFIG_EVM) ? 1 : 0) + \
58-
(IS_ENABLED(CONFIG_SECURITY_IPE) ? 1 : 0))
59-
6036
#define SECURITY_HOOK_ACTIVE_KEY(HOOK, IDX) security_hook_active_##HOOK##_##IDX
6137

6238
/*
@@ -130,7 +106,7 @@ static __initdata const char *chosen_major_lsm;
130106
static __initconst const char *const builtin_lsm_order = CONFIG_LSM;
131107

132108
/* Ordered list of LSMs to initialize. */
133-
static __initdata struct lsm_info **ordered_lsms;
109+
static __initdata struct lsm_info *ordered_lsms[MAX_LSM_COUNT + 1];
134110
static __initdata struct lsm_info *exclusive;
135111

136112
#ifdef CONFIG_HAVE_STATIC_CALL
@@ -242,7 +218,7 @@ static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from)
242218
if (exists_ordered_lsm(lsm))
243219
return;
244220

245-
if (WARN(last_lsm == LSM_COUNT, "%s: out of LSM static calls!?\n", from))
221+
if (WARN(last_lsm == MAX_LSM_COUNT, "%s: out of LSM static calls!?\n", from))
246222
return;
247223

248224
/* Enable this LSM, if it is not already set. */
@@ -345,7 +321,7 @@ static void __init initialize_lsm(struct lsm_info *lsm)
345321
* Current index to use while initializing the lsm id list.
346322
*/
347323
u32 lsm_active_cnt __ro_after_init;
348-
const struct lsm_id *lsm_idlist[LSM_CONFIG_COUNT];
324+
const struct lsm_id *lsm_idlist[MAX_LSM_COUNT];
349325

350326
/* Populate ordered LSMs list from comma-separated LSM name list. */
351327
static void __init ordered_lsm_parse(const char *order, const char *origin)
@@ -474,9 +450,6 @@ static void __init ordered_lsm_init(void)
474450
{
475451
struct lsm_info **lsm;
476452

477-
ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms),
478-
GFP_KERNEL);
479-
480453
if (chosen_lsm_order) {
481454
if (chosen_major_lsm) {
482455
pr_warn("security=%s is ignored because it is superseded by lsm=%s\n",
@@ -525,8 +498,6 @@ static void __init ordered_lsm_init(void)
525498
lsm_early_task(current);
526499
for (lsm = ordered_lsms; *lsm; lsm++)
527500
initialize_lsm(*lsm);
528-
529-
kfree(ordered_lsms);
530501
}
531502

532503
int __init early_security_init(void)
@@ -653,7 +624,7 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count,
653624
* Look at the previous entry, if there is one, for duplication.
654625
*/
655626
if (lsm_active_cnt == 0 || lsm_idlist[lsm_active_cnt - 1] != lsmid) {
656-
if (lsm_active_cnt >= LSM_CONFIG_COUNT)
627+
if (lsm_active_cnt >= MAX_LSM_COUNT)
657628
panic("%s Too many LSMs registered.\n", __func__);
658629
lsm_idlist[lsm_active_cnt++] = lsmid;
659630
}

0 commit comments

Comments
 (0)