]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - security/tomoyo/common.h
UBUNTU: SAUCE: LSM stacking: LSM: General stacking
[mirror_ubuntu-bionic-kernel.git] / security / tomoyo / common.h
index 7adccdd8e36d9b9117c9a8643495dcb2d880cc9a..837ab22fccd511128a8080931b6b62b88ef29e48 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/in.h>
 #include <linux/in6.h>
 #include <linux/un.h>
+#include <linux/lsm_hooks.h>
 #include <net/sock.h>
 #include <net/af_unix.h>
 #include <net/ip.h>
@@ -1062,6 +1063,7 @@ void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
 /********** External variable definitions. **********/
 
 extern bool tomoyo_policy_loaded;
+extern bool tomoyo_enabled;
 extern const char * const tomoyo_condition_keyword
 [TOMOYO_MAX_CONDITION_KEYWORD];
 extern const char * const tomoyo_dif[TOMOYO_MAX_DOMAIN_INFO_FLAGS];
@@ -1085,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. **********/
 
@@ -1196,6 +1199,21 @@ static inline void tomoyo_put_group(struct tomoyo_group *group)
                atomic_dec(&group->head.users);
 }
 
+/**
+ * tomoyo_cred - Get a pointer to the tomoyo cred security blob
+ * @cred - the relevant cred
+ *
+ * Returns pointer to the tomoyo cred blob.
+ */
+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
+}
+
 /**
  * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
  *
@@ -1203,7 +1221,14 @@ static inline void tomoyo_put_group(struct tomoyo_group *group)
  */
 static inline struct tomoyo_domain_info *tomoyo_domain(void)
 {
-       return current_cred()->security;
+       const struct cred *cred = current_cred();
+       struct tomoyo_domain_info **blob;
+
+       if (cred->security == NULL)
+               return NULL;
+
+       blob = tomoyo_cred(cred);
+       return *blob;
 }
 
 /**
@@ -1216,7 +1241,9 @@ static inline struct tomoyo_domain_info *tomoyo_domain(void)
 static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
                                                            *task)
 {
-       return task_cred_xxx(task, security);
+       struct tomoyo_domain_info **blob = tomoyo_cred(get_task_cred(task));
+
+       return *blob;
 }
 
 /**