|
33 | 33 | #include <net/flow.h> |
34 | 34 | #include <net/sock.h> |
35 | 35 |
|
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 | | - |
60 | 36 | #define SECURITY_HOOK_ACTIVE_KEY(HOOK, IDX) security_hook_active_##HOOK##_##IDX |
61 | 37 |
|
62 | 38 | /* |
@@ -130,7 +106,7 @@ static __initdata const char *chosen_major_lsm; |
130 | 106 | static __initconst const char *const builtin_lsm_order = CONFIG_LSM; |
131 | 107 |
|
132 | 108 | /* 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]; |
134 | 110 | static __initdata struct lsm_info *exclusive; |
135 | 111 |
|
136 | 112 | #ifdef CONFIG_HAVE_STATIC_CALL |
@@ -242,7 +218,7 @@ static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from) |
242 | 218 | if (exists_ordered_lsm(lsm)) |
243 | 219 | return; |
244 | 220 |
|
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)) |
246 | 222 | return; |
247 | 223 |
|
248 | 224 | /* Enable this LSM, if it is not already set. */ |
@@ -345,7 +321,7 @@ static void __init initialize_lsm(struct lsm_info *lsm) |
345 | 321 | * Current index to use while initializing the lsm id list. |
346 | 322 | */ |
347 | 323 | 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]; |
349 | 325 |
|
350 | 326 | /* Populate ordered LSMs list from comma-separated LSM name list. */ |
351 | 327 | static void __init ordered_lsm_parse(const char *order, const char *origin) |
@@ -474,9 +450,6 @@ static void __init ordered_lsm_init(void) |
474 | 450 | { |
475 | 451 | struct lsm_info **lsm; |
476 | 452 |
|
477 | | - ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms), |
478 | | - GFP_KERNEL); |
479 | | - |
480 | 453 | if (chosen_lsm_order) { |
481 | 454 | if (chosen_major_lsm) { |
482 | 455 | 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) |
525 | 498 | lsm_early_task(current); |
526 | 499 | for (lsm = ordered_lsms; *lsm; lsm++) |
527 | 500 | initialize_lsm(*lsm); |
528 | | - |
529 | | - kfree(ordered_lsms); |
530 | 501 | } |
531 | 502 |
|
532 | 503 | int __init early_security_init(void) |
@@ -653,7 +624,7 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count, |
653 | 624 | * Look at the previous entry, if there is one, for duplication. |
654 | 625 | */ |
655 | 626 | 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) |
657 | 628 | panic("%s Too many LSMs registered.\n", __func__); |
658 | 629 | lsm_idlist[lsm_active_cnt++] = lsmid; |
659 | 630 | } |
|
0 commit comments