0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef __AA_NAMESPACE_H
0012 #define __AA_NAMESPACE_H
0013
0014 #include <linux/kref.h>
0015
0016 #include "apparmor.h"
0017 #include "apparmorfs.h"
0018 #include "label.h"
0019 #include "policy.h"
0020
0021
0022
0023
0024
0025
0026
0027
0028 struct aa_ns_acct {
0029 int max_size;
0030 int max_count;
0031 int size;
0032 int count;
0033 };
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 struct aa_ns {
0059 struct aa_policy base;
0060 struct aa_ns *parent;
0061 struct mutex lock;
0062 struct aa_ns_acct acct;
0063 struct aa_profile *unconfined;
0064 struct list_head sub_ns;
0065 atomic_t uniq_null;
0066 long uniq_id;
0067 int level;
0068 long revision;
0069 wait_queue_head_t wait;
0070
0071 struct aa_labelset labels;
0072 struct list_head rawdata_list;
0073
0074 struct dentry *dents[AAFS_NS_SIZEOF];
0075 };
0076
0077 extern struct aa_label *kernel_t;
0078 extern struct aa_ns *root_ns;
0079
0080 extern const char *aa_hidden_ns_name;
0081
0082 #define ns_unconfined(NS) (&(NS)->unconfined->label)
0083
0084 bool aa_ns_visible(struct aa_ns *curr, struct aa_ns *view, bool subns);
0085 const char *aa_ns_name(struct aa_ns *parent, struct aa_ns *child, bool subns);
0086 void aa_free_ns(struct aa_ns *ns);
0087 int aa_alloc_root_ns(void);
0088 void aa_free_root_ns(void);
0089 void aa_free_ns_kref(struct kref *kref);
0090
0091 struct aa_ns *aa_find_ns(struct aa_ns *root, const char *name);
0092 struct aa_ns *aa_findn_ns(struct aa_ns *root, const char *name, size_t n);
0093 struct aa_ns *__aa_lookupn_ns(struct aa_ns *view, const char *hname, size_t n);
0094 struct aa_ns *aa_lookupn_ns(struct aa_ns *view, const char *name, size_t n);
0095 struct aa_ns *__aa_find_or_create_ns(struct aa_ns *parent, const char *name,
0096 struct dentry *dir);
0097 struct aa_ns *aa_prepare_ns(struct aa_ns *root, const char *name);
0098 void __aa_remove_ns(struct aa_ns *ns);
0099
0100 static inline struct aa_profile *aa_deref_parent(struct aa_profile *p)
0101 {
0102 return rcu_dereference_protected(p->parent,
0103 mutex_is_locked(&p->ns->lock));
0104 }
0105
0106
0107
0108
0109
0110
0111
0112
0113 static inline struct aa_ns *aa_get_ns(struct aa_ns *ns)
0114 {
0115 if (ns)
0116 aa_get_profile(ns->unconfined);
0117
0118 return ns;
0119 }
0120
0121
0122
0123
0124
0125
0126
0127 static inline void aa_put_ns(struct aa_ns *ns)
0128 {
0129 if (ns)
0130 aa_put_profile(ns->unconfined);
0131 }
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142 static inline struct aa_ns *__aa_findn_ns(struct list_head *head,
0143 const char *name, size_t n)
0144 {
0145 return (struct aa_ns *)__policy_strn_find(head, name, n);
0146 }
0147
0148 static inline struct aa_ns *__aa_find_ns(struct list_head *head,
0149 const char *name)
0150 {
0151 return __aa_findn_ns(head, name, strlen(name));
0152 }
0153
0154 static inline struct aa_ns *__aa_lookup_ns(struct aa_ns *base,
0155 const char *hname)
0156 {
0157 return __aa_lookupn_ns(base, hname, strlen(hname));
0158 }
0159
0160 static inline struct aa_ns *aa_lookup_ns(struct aa_ns *view, const char *name)
0161 {
0162 return aa_lookupn_ns(view, name, strlen(name));
0163 }
0164
0165 #endif