@@ -32,6 +32,17 @@ config SECURITY
If you are unsure how to answer this question, answer N.
+config SECURITY_HOOK_LIKELY
+ bool "LSM hooks are likely to be initialized"
+ depends on SECURITY && EXPERT
+ default SECURITY_SELINUX || SECURITY_SMACK || SECURITY_TOMOYO || SECURITY_APPARMOR
+ help
+ This controls the behaviour of the static keys that guard LSM hooks.
+ If LSM hooks are likely to be initialized by LSMs, then one gets
+ better performance by enabling this option. However, if the system is
+ using an LSM where hooks are much likely to be disabled, one gets
+ better performance by disabling this config.
+
config SECURITYFS
bool "Enable the securityfs filesystem"
help
@@ -825,7 +825,8 @@ static int lsm_superblock_alloc(struct super_block *sb)
*/
#define __CALL_STATIC_VOID(NUM, HOOK, ...) \
do { \
- if (static_branch_unlikely(&SECURITY_HOOK_ACTIVE_KEY(HOOK, NUM))) { \
+ if (static_branch_maybe(CONFIG_SECURITY_HOOK_LIKELY, \
+ &SECURITY_HOOK_ACTIVE_KEY(HOOK, NUM))) { \
static_call(LSM_STATIC_CALL(HOOK, NUM))(__VA_ARGS__); \
} \
} while (0);
@@ -837,7 +838,8 @@ do { \
#define __CALL_STATIC_INT(NUM, R, HOOK, LABEL, ...) \
do { \
- if (static_branch_unlikely(&SECURITY_HOOK_ACTIVE_KEY(HOOK, NUM))) { \
+ if (static_branch_maybe(CONFIG_SECURITY_HOOK_LIKELY, \
+ &SECURITY_HOOK_ACTIVE_KEY(HOOK, NUM))) { \
R = static_call(LSM_STATIC_CALL(HOOK, NUM))(__VA_ARGS__); \
if (R != 0) \
goto LABEL; \