security: introduce CONFIG_SECURITY_WRITABLE_HOOKS
authorJames Morris <jmorris@namei.org>
Tue, 14 Feb 2017 13:17:24 +0000 (00:17 +1100)
committerJames Morris <james.l.morris@oracle.com>
Mon, 6 Mar 2017 00:00:12 +0000 (11:00 +1100)
Subsequent patches will add RO hardening to LSM hooks, however, SELinux
still needs to be able to perform runtime disablement after init to handle
architectures where init-time disablement via boot parameters is not feasible.

Introduce a new kernel configuration parameter CONFIG_SECURITY_WRITABLE_HOOKS,
and a helper macro __lsm_ro_after_init, to handle this case.

Signed-off-by: James Morris <james.l.morris@oracle.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Acked-by: Kees Cook <keescook@chromium.org>
include/linux/lsm_hooks.h
security/Kconfig
security/selinux/Kconfig

index ba3049f05aea9a54953e15faecb45ac4607bd023..1aa63335de9ef3e5e2d6d344770460883c0eb463 100644 (file)
@@ -1920,6 +1920,13 @@ static inline void security_delete_hooks(struct security_hook_list *hooks,
 }
 #endif /* CONFIG_SECURITY_SELINUX_DISABLE */
 
+/* Currently required to handle SELinux runtime hook disable. */
+#ifdef CONFIG_SECURITY_WRITABLE_HOOKS
+#define __lsm_ro_after_init
+#else
+#define __lsm_ro_after_init    __ro_after_init
+#endif /* CONFIG_SECURITY_WRITABLE_HOOKS */
+
 extern int __init security_module_enable(const char *module);
 extern void __init capability_add_hooks(void);
 #ifdef CONFIG_SECURITY_YAMA
index d900f47eaa68526704a3bba7058bdc0044c97987..3ff1bf91080eb5c3b1c207c51645fe91027f4cd5 100644 (file)
@@ -31,6 +31,11 @@ config SECURITY
 
          If you are unsure how to answer this question, answer N.
 
+config SECURITY_WRITABLE_HOOKS
+       depends on SECURITY
+       bool
+       default n
+
 config SECURITYFS
        bool "Enable the securityfs filesystem"
        help
index ea7e3efbe0f758ed51dba589e18bd07edd61b76f..8af7a690eb40a15d06f1cba8b5ee25f60c8cdbf9 100644 (file)
@@ -40,6 +40,7 @@ config SECURITY_SELINUX_BOOTPARAM_VALUE
 config SECURITY_SELINUX_DISABLE
        bool "NSA SELinux runtime disable"
        depends on SECURITY_SELINUX
+       select SECURITY_WRITABLE_HOOKS
        default n
        help
          This option enables writing to a selinuxfs node 'disable', which
@@ -50,6 +51,11 @@ config SECURITY_SELINUX_DISABLE
          portability across platforms where boot parameters are difficult
          to employ.
 
+         NOTE: selecting this option will disable the '__ro_after_init'
+         kernel hardening feature for security hooks.   Please consider
+         using the selinux=0 boot parameter instead of enabling this
+         option.
+
          If you are unsure how to answer this question, answer N.
 
 config SECURITY_SELINUX_DEVELOP