Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

LSM: Maintain a table of LSM attribute data

As LSMs are registered add their lsm_id pointers to a table.
This will be used later for attribute reporting.

Determine the number of possible security modules based on
their respective CONFIG options. This allows the number to be
known at build time. This allows data structures and tables
to use the constant.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Reviewed-by: Mickael Salaun <mic@digikod.net>
Reviewed-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>

authored by

Casey Schaufler and committed by
Paul Moore
9285c5ad f3b8788c

+39
+2
include/linux/security.h
··· 138 138 }; 139 139 140 140 extern const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1]; 141 + extern u32 lsm_active_cnt; 142 + extern const struct lsm_id *lsm_idlist[]; 141 143 142 144 /* These functions are in security/commoncap.c */ 143 145 extern int cap_capable(const struct cred *cred, struct user_namespace *ns,
+37
security/security.c
··· 35 35 #define LSM_COUNT (__end_lsm_info - __start_lsm_info) 36 36 37 37 /* 38 + * How many LSMs are built into the kernel as determined at 39 + * build time. Used to determine fixed array sizes. 40 + * The capability module is accounted for by CONFIG_SECURITY 41 + */ 42 + #define LSM_CONFIG_COUNT ( \ 43 + (IS_ENABLED(CONFIG_SECURITY) ? 1 : 0) + \ 44 + (IS_ENABLED(CONFIG_SECURITY_SELINUX) ? 1 : 0) + \ 45 + (IS_ENABLED(CONFIG_SECURITY_SMACK) ? 1 : 0) + \ 46 + (IS_ENABLED(CONFIG_SECURITY_TOMOYO) ? 1 : 0) + \ 47 + (IS_ENABLED(CONFIG_IMA) ? 1 : 0) + \ 48 + (IS_ENABLED(CONFIG_SECURITY_APPARMOR) ? 1 : 0) + \ 49 + (IS_ENABLED(CONFIG_SECURITY_YAMA) ? 1 : 0) + \ 50 + (IS_ENABLED(CONFIG_SECURITY_LOADPIN) ? 1 : 0) + \ 51 + (IS_ENABLED(CONFIG_SECURITY_SAFESETID) ? 1 : 0) + \ 52 + (IS_ENABLED(CONFIG_SECURITY_LOCKDOWN_LSM) ? 1 : 0) + \ 53 + (IS_ENABLED(CONFIG_BPF_LSM) ? 1 : 0) + \ 54 + (IS_ENABLED(CONFIG_SECURITY_LANDLOCK) ? 1 : 0)) 55 + 56 + /* 38 57 * These are descriptions of the reasons that can be passed to the 39 58 * security_locked_down() LSM hook. Placing this array here allows 40 59 * all security modules to use the same descriptions for auditing ··· 263 244 WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret); 264 245 } 265 246 } 247 + 248 + /* 249 + * Current index to use while initializing the lsm id list. 250 + */ 251 + u32 lsm_active_cnt __ro_after_init; 252 + const struct lsm_id *lsm_idlist[LSM_CONFIG_COUNT]; 266 253 267 254 /* Populate ordered LSMs list from comma-separated LSM name list. */ 268 255 static void __init ordered_lsm_parse(const char *order, const char *origin) ··· 546 521 const struct lsm_id *lsmid) 547 522 { 548 523 int i; 524 + 525 + /* 526 + * A security module may call security_add_hooks() more 527 + * than once during initialization, and LSM initialization 528 + * is serialized. Landlock is one such case. 529 + * Look at the previous entry, if there is one, for duplication. 530 + */ 531 + if (lsm_active_cnt == 0 || lsm_idlist[lsm_active_cnt - 1] != lsmid) { 532 + if (lsm_active_cnt >= LSM_CONFIG_COUNT) 533 + panic("%s Too many LSMs registered.\n", __func__); 534 + lsm_idlist[lsm_active_cnt++] = lsmid; 535 + } 549 536 550 537 for (i = 0; i < count; i++) { 551 538 hooks[i].lsmid = lsmid;