]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
UBUNTU: SAUCE: LSM stacking: LSM: General stacking
authorCasey Schaufler <casey@schaufler-ca.com>
Wed, 7 Mar 2018 22:39:43 +0000 (14:39 -0800)
committerSeth Forshee <seth.forshee@canonical.com>
Tue, 10 Apr 2018 18:06:12 +0000 (13:06 -0500)
BugLink: http://bugs.launchpad.net/bugs/1763062
Leverage the infrastructure management of the security blobs
to allow stacking of security modules in all but the most
extreme case. Security modules are informed of the location
of their data within the blobs at module initialization.

Stacking is optional. If stacking is not configured the old
limit of one "major" security module applies. If stacking is
configured TOMOYO can be configured with an of the other
modules. SELinux, Smack and AppArmor use (or in the AppArmor
case, threaten to use) secids, which are not (yet) shareable.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
12 files changed:
Documentation/admin-guide/LSM/index.rst
include/linux/lsm_hooks.h
security/Kconfig
security/apparmor/include/context.h
security/apparmor/lsm.c
security/security.c
security/selinux/hooks.c
security/selinux/include/objsec.h
security/smack/smack.h
security/smack/smack_lsm.c
security/tomoyo/common.h
security/tomoyo/tomoyo.c

index 9842e21afd4afa593eb6e4788d16e6c3cb23fc65..d3d8af1740426ad07318eeb4d85a3796aca8758f 100644 (file)
@@ -17,10 +17,16 @@ MAC extensions, other extensions can be built using the LSM to provide
 specific changes to system operation when these tweaks are not available
 in the core functionality of Linux itself.
 
-The Linux capabilities modules will always be included. This may be
-followed by any number of "minor" modules and at most one "major" module.
-For more details on capabilities, see ``capabilities(7)`` in the Linux
-man-pages project.
+The Linux capabilities modules will always be included. For more details
+on capabilities, see ``capabilities(7)`` in the Linux man-pages project.
+
+Security modules that do not use the security data blobs maintained
+by the LSM infrastructure are considered "minor" modules. These may be
+included at compile time and stacked explicitly. Security modules that
+use the LSM maintained security blobs are considered "major" modules.
+These may only be stacked if the CONFIG_LSM_STACKED configuration
+option is used. If this is chosen all of the security modules selected
+will be used.
 
 A list of the active security modules can be found by reading
 ``/sys/kernel/security/lsm``. This is a comma separated list, and
index 1fea68a917297b3823e37be706b103be1c1bb6ce..8bb315d31bd56483b77d468ba1ab51be63968218 100644 (file)
@@ -2029,7 +2029,7 @@ static inline void security_delete_hooks(struct security_hook_list *hooks,
 #define __lsm_ro_after_init    __ro_after_init
 #endif /* CONFIG_SECURITY_WRITABLE_HOOKS */
 
-extern int __init security_module_enable(const char *module);
+extern bool __init security_module_enable(const char *lsm, const bool stacked);
 extern void __init capability_add_hooks(void);
 #ifdef CONFIG_SECURITY_YAMA
 extern void __init yama_add_hooks(void);
index 62032b46f5b2179db736bd3bb1d86ac8af39656e..2efb977763b200ab5f737c8522abc88fd9b28a8c 100644 (file)
@@ -45,6 +45,28 @@ config SECURITY_WRITABLE_HOOKS
        bool
        default n
 
+config SECURITY_STACKING
+       bool "Security module stacking"
+       depends on SECURITY
+       help
+         Allows multiple major security modules to be stacked.
+         Modules are invoked in the order registered with a
+         "bail on fail" policy, in which the infrastructure
+         will stop processing once a denial is detected. Not
+         all modules can be stacked. SELinux and Smack are
+         known to be incompatible. User space components may
+         have trouble identifying the security module providing
+         data in some cases.
+
+         If you select this option you will have to select which
+         of the stackable modules you wish to be active. The
+         "Default security module" will be ignored. The boot line
+         "security=" option can be used to specify that one of
+         the modules identifed for stacking should be used instead
+         of the entire stack.
+
+         If you are unsure how to answer this question, answer N.
+
 config SECURITY_LSM_DEBUG
        bool "Enable debugging of the LSM infrastructure"
        depends on SECURITY
@@ -276,6 +298,9 @@ source security/yama/Kconfig
 
 source security/integrity/Kconfig
 
+menu "Security Module Selection"
+       visible if !SECURITY_STACKING
+
 choice
        prompt "Default security module"
        default DEFAULT_SECURITY_SELINUX if SECURITY_SELINUX
@@ -315,3 +340,64 @@ config DEFAULT_SECURITY
 
 endmenu
 
+menu "Security Module Stack"
+       visible if SECURITY_STACKING
+
+choice
+       prompt "Stacked 'extreme' security module"
+       default SECURITY_SELINUX_STACKED if SECURITY_SELINUX
+       default SECURITY_SMACK_STACKED if SECURITY_SMACK
+       default SECURITY_APPARMOR_STACKED if SECURITY_APPARMOR
+
+       help
+         Enable an extreme security module. These modules cannot
+         be used at the same time.
+
+       config SECURITY_SELINUX_STACKED
+               bool "SELinux" if SECURITY_SELINUX=y
+       help
+         This option instructs the system to use the SELinux checks.
+         At this time the Smack security module is incompatible with this
+         module.
+         At this time the AppArmor security module is incompatible with this
+         module.
+
+       config SECURITY_SMACK_STACKED
+               bool "Simplified Mandatory Access Control" if SECURITY_SMACK=y
+       help
+         This option instructs the system to use the Smack checks.
+         At this time the SELinux security module is incompatible with this
+         module.
+         At this time the AppArmor security module is incompatible with this
+         module.
+
+       config SECURITY_APPARMOR_STACKED
+               bool "AppArmor" if SECURITY_APPARMOR=y
+       help
+         This option instructs the system to use the AppArmor checks.
+         At this time the SELinux security module is incompatible with this
+         module.
+         At this time the Smack security module is incompatible with this
+         module.
+
+       config SECURITY_NOTHING_STACKED
+               bool "Use no 'extreme' security module"
+       help
+         Use none of the SELinux, Smack or AppArmor security module.
+
+endchoice
+
+config SECURITY_TOMOYO_STACKED
+       bool "TOMOYO support is enabled by default"
+       depends on SECURITY_TOMOYO && SECURITY_STACKING
+       default n
+       help
+         This option instructs the system to use the TOMOYO checks.
+         If not selected the module will not be invoked.
+         Stacked security modules may interact in unexpected ways.
+
+         If you are unsure how to answer this question, answer N.
+
+endmenu
+
+endmenu
index c6e106a533e8e1dd7e50d093e477a0ae9ae81b35..c6d5dbbd18b01ede369eb523524c8154321fe436 100644 (file)
@@ -55,9 +55,15 @@ int aa_set_current_hat(struct aa_label *label, u64 token);
 int aa_restore_previous_label(u64 cookie);
 struct aa_label *aa_get_task_label(struct task_struct *task);
 
+extern struct lsm_blob_sizes apparmor_blob_sizes;
+
 static inline struct aa_task_ctx *apparmor_cred(const struct cred *cred)
 {
+#ifdef CONFIG_SECURITY_STACKING
+       return cred->security + apparmor_blob_sizes.lbs_cred;
+#else
        return cred->security;
+#endif
 }
 
 /**
@@ -89,7 +95,11 @@ static inline struct aa_label *aa_get_newest_cred_label(const struct cred *cred)
 
 static inline struct aa_file_ctx *apparmor_file(const struct file *file)
 {
+#ifdef CONFIG_SECURITY_STACKING
+       return file->f_security + apparmor_blob_sizes.lbs_file;
+#else
        return file->f_security;
+#endif
 }
 
 /**
index f660b531f2c944a537ab43c0d958153e91714db2..cf2ef94f3d1b54feb1ae3109ef9bfeee7249a7bc 100644 (file)
@@ -1532,7 +1532,9 @@ static int __init apparmor_init(void)
        int error;
 
        if (!finish) {
-               if (apparmor_enabled && security_module_enable("apparmor"))
+               if (apparmor_enabled &&
+                   security_module_enable("apparmor",
+                               IS_ENABLED(CONFIG_SECURITY_APPARMOR_STACKED)))
                        security_add_blobs(&apparmor_blob_sizes);
                else
                        apparmor_enabled = false;
@@ -1540,7 +1542,9 @@ static int __init apparmor_init(void)
                return 0;
        }
 
-       if (!apparmor_enabled || !security_module_enable("apparmor")) {
+       if (!apparmor_enabled ||
+           !security_module_enable("apparmor",
+                               IS_ENABLED(CONFIG_SECURITY_APPARMOR_STACKED))) {
                aa_info_message("AppArmor disabled by boot time parameter");
                apparmor_enabled = false;
                return 0;
index b517fcb801d171104423039271a1046837b91e68..1cdb8e1e9d3bbc09440e1c63bca16f90ff34200d 100644 (file)
@@ -36,6 +36,7 @@
 
 /* Maximum number of letters for an LSM name string */
 #define SECURITY_NAME_MAX      10
+#define MODULE_STACK           "(stacking)"
 
 struct security_hook_heads security_hook_heads __lsm_ro_after_init;
 static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain);
@@ -48,7 +49,11 @@ static struct lsm_blob_sizes blob_sizes;
 
 /* Boot-time LSM user choice */
 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
+#ifdef CONFIG_SECURITY_STACKING
+       MODULE_STACK;
+#else
        CONFIG_DEFAULT_SECURITY;
+#endif
 
 static void __init do_security_initcalls(void)
 {
@@ -168,6 +173,7 @@ static int lsm_append(char *new, char **result)
 /**
  * security_module_enable - Load given security module on boot ?
  * @module: the name of the module
+ * @stacked: indicates that the module wants to be stacked
  *
  * Each LSM must pass this method before registering its own operations
  * to avoid security registration races. This method may also be used
@@ -183,9 +189,29 @@ static int lsm_append(char *new, char **result)
  *
  * Otherwise, return false.
  */
-int __init security_module_enable(const char *module)
+bool __init security_module_enable(const char *lsm, const bool stacked)
 {
-       return !strcmp(module, chosen_lsm);
+#ifdef CONFIG_SECURITY_STACKING
+       /*
+        * Module defined on the command line security=XXXX
+        */
+       if (strcmp(chosen_lsm, MODULE_STACK)) {
+               if (!strcmp(lsm, chosen_lsm)) {
+                       pr_info("Command line sets the %s security module.\n",
+                               lsm);
+                       return true;
+               }
+               return false;
+       }
+       /*
+        * Module configured as stacked.
+        */
+       return stacked;
+#else
+       if (strcmp(lsm, chosen_lsm) == 0)
+               return true;
+       return false;
+#endif
 }
 
 /**
index bf72c5ccd2467e552ea5869c5890f82fdef7d314..539e9d9ad2654145d1733f7686b8159c11512e27 100644 (file)
@@ -6451,7 +6451,8 @@ static __init int selinux_init(void)
 {
        static int finish;
 
-       if (!security_module_enable("selinux")) {
+       if (!security_module_enable("selinux",
+                               IS_ENABLED(CONFIG_SECURITY_SELINUX_STACKED))) {
                selinux_enabled = 0;
                return 0;
        }
index 56b9428ac93418e9c2c9d72a66a706d62bfe7c2a..e3f4f7b57b237710376ba96fa3bf0267b5bad603 100644 (file)
@@ -159,12 +159,20 @@ extern struct lsm_blob_sizes selinux_blob_sizes;
 
 static inline struct task_security_struct *selinux_cred(const struct cred *cred)
 {
+#ifdef CONFIG_SECURITY_STACKING
+       return cred->security + selinux_blob_sizes.lbs_cred;
+#else
        return cred->security;
+#endif
 }
 
 static inline struct file_security_struct *selinux_file(const struct file *file)
 {
+#ifdef CONFIG_SECURITY_STACKING
+       return file->f_security + selinux_blob_sizes.lbs_file;
+#else
        return file->f_security;
+#endif
 }
 
 static inline struct inode_security_struct *selinux_inode(
index 1b875c2f3d9dc2dfd6a14b58924a0254adbcf5f8..e7611de071f155ea7ee1cb2df93587209e2b68b9 100644 (file)
@@ -336,6 +336,7 @@ extern struct smack_known *smack_syslog_label;
 extern struct smack_known *smack_unconfined;
 #endif
 extern int smack_ptrace_rule;
+extern struct lsm_blob_sizes smack_blob_sizes;
 
 extern struct smack_known smack_known_floor;
 extern struct smack_known smack_known_hat;
@@ -358,12 +359,20 @@ extern struct hlist_head smack_known_hash[SMACK_HASH_SLOTS];
 
 static inline struct task_smack *smack_cred(const struct cred *cred)
 {
+#ifdef CONFIG_SECURITY_STACKING
+       return cred->security + smack_blob_sizes.lbs_cred;
+#else
        return cred->security;
+#endif
 }
 
 static inline struct smack_known **smack_file(const struct file *file)
 {
+#ifdef CONFIG_SECURITY_STACKING
+       return file->f_security + smack_blob_sizes.lbs_file;
+#else
        return file->f_security;
+#endif
 }
 
 static inline struct inode_smack *smack_inode(const struct inode *inode)
index a76f25cf33a53b64a763087b9b9422ed3be6a296..88eaebe300cb9749d297e90190f1a5c738cea07f 100644 (file)
@@ -3422,18 +3422,16 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
 {
        struct smack_known *skp = smk_of_task_struct(p);
        char *cp;
-       int slen;
 
-       if (strcmp(name, "current") != 0)
+       if (strcmp(name, "current") == 0) {
+               cp = kstrdup(skp->smk_known, GFP_KERNEL);
+               if (cp == NULL)
+                       return -ENOMEM;
+       } else
                return -EINVAL;
 
-       cp = kstrdup(skp->smk_known, GFP_KERNEL);
-       if (cp == NULL)
-               return -ENOMEM;
-
-       slen = strlen(cp);
        *value = cp;
-       return slen;
+       return strlen(cp);
 }
 
 /**
@@ -4668,7 +4666,8 @@ static __init int smack_init(void)
        struct cred *cred = (struct cred *) current->cred;
        struct task_smack *tsp;
 
-       if (!security_module_enable("smack"))
+       if (!security_module_enable("smack",
+                               IS_ENABLED(CONFIG_SECURITY_SMACK_STACKED)))
                return 0;
 
        if (!finish) {
index 13e3d167421aa638738122088c6cf5d7df35de33..837ab22fccd511128a8080931b6b62b88ef29e48 100644 (file)
@@ -1087,6 +1087,7 @@ extern struct tomoyo_domain_info tomoyo_kernel_domain;
 extern struct tomoyo_policy_namespace tomoyo_kernel_namespace;
 extern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT];
 extern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT];
+extern struct lsm_blob_sizes tomoyo_blob_sizes;
 
 /********** Inlined functions. **********/
 
@@ -1206,7 +1207,11 @@ static inline void tomoyo_put_group(struct tomoyo_group *group)
  */
 static inline struct tomoyo_domain_info **tomoyo_cred(const struct cred *cred)
 {
+#ifdef CONFIG_SECURITY_STACKING
+       return cred->security + tomoyo_blob_sizes.lbs_cred;
+#else
        return cred->security;
+#endif
 }
 
 /**
@@ -1216,8 +1221,13 @@ static inline struct tomoyo_domain_info **tomoyo_cred(const struct cred *cred)
  */
 static inline struct tomoyo_domain_info *tomoyo_domain(void)
 {
-       struct tomoyo_domain_info **blob = tomoyo_cred(current_cred());
+       const struct cred *cred = current_cred();
+       struct tomoyo_domain_info **blob;
+
+       if (cred->security == NULL)
+               return NULL;
 
+       blob = tomoyo_cred(cred);
        return *blob;
 }
 
index 821ca242a194987a249df2479bd86ad6888db6d0..eb4b886b6076005f3c7a6d5fcdaa06a1f2d57555 100644 (file)
@@ -564,7 +564,8 @@ static int __init tomoyo_init(void)
        struct cred *cred = (struct cred *) current_cred();
        struct tomoyo_domain_info **blob;
 
-       if (!security_module_enable("tomoyo")) {
+       if (!security_module_enable("tomoyo",
+                               IS_ENABLED(CONFIG_SECURITY_TOMOYO_STACKED))) {
                tomoyo_enabled = false;
                return 0;
        }