1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef __AA_NAMESPACE_H
16#define __AA_NAMESPACE_H
17
18#include <linux/kref.h>
19
20#include "apparmor.h"
21#include "apparmorfs.h"
22#include "label.h"
23#include "policy.h"
24
25
26
27
28
29
30
31
32struct aa_ns_acct {
33 int max_size;
34 int max_count;
35 int size;
36 int count;
37};
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62struct aa_ns {
63 struct aa_policy base;
64 struct aa_ns *parent;
65 struct mutex lock;
66 struct aa_ns_acct acct;
67 struct aa_profile *unconfined;
68 struct list_head sub_ns;
69 atomic_t uniq_null;
70 long uniq_id;
71 int level;
72 long revision;
73 wait_queue_head_t wait;
74
75 struct aa_labelset labels;
76 struct list_head rawdata_list;
77
78 struct dentry *dents[AAFS_NS_SIZEOF];
79};
80
81extern struct aa_ns *root_ns;
82
83extern const char *aa_hidden_ns_name;
84
85#define ns_unconfined(NS) (&(NS)->unconfined->label)
86
87bool aa_ns_visible(struct aa_ns *curr, struct aa_ns *view, bool subns);
88const char *aa_ns_name(struct aa_ns *parent, struct aa_ns *child, bool subns);
89void aa_free_ns(struct aa_ns *ns);
90int aa_alloc_root_ns(void);
91void aa_free_root_ns(void);
92void aa_free_ns_kref(struct kref *kref);
93
94struct aa_ns *aa_find_ns(struct aa_ns *root, const char *name);
95struct aa_ns *aa_findn_ns(struct aa_ns *root, const char *name, size_t n);
96struct aa_ns *__aa_lookupn_ns(struct aa_ns *view, const char *hname, size_t n);
97struct aa_ns *aa_lookupn_ns(struct aa_ns *view, const char *name, size_t n);
98struct aa_ns *__aa_find_or_create_ns(struct aa_ns *parent, const char *name,
99 struct dentry *dir);
100struct aa_ns *aa_prepare_ns(struct aa_ns *root, const char *name);
101void __aa_remove_ns(struct aa_ns *ns);
102
103static inline struct aa_profile *aa_deref_parent(struct aa_profile *p)
104{
105 return rcu_dereference_protected(p->parent,
106 mutex_is_locked(&p->ns->lock));
107}
108
109
110
111
112
113
114
115
116static inline struct aa_ns *aa_get_ns(struct aa_ns *ns)
117{
118 if (ns)
119 aa_get_profile(ns->unconfined);
120
121 return ns;
122}
123
124
125
126
127
128
129
130static inline void aa_put_ns(struct aa_ns *ns)
131{
132 if (ns)
133 aa_put_profile(ns->unconfined);
134}
135
136
137
138
139
140
141
142
143
144
145static inline struct aa_ns *__aa_findn_ns(struct list_head *head,
146 const char *name, size_t n)
147{
148 return (struct aa_ns *)__policy_strn_find(head, name, n);
149}
150
151static inline struct aa_ns *__aa_find_ns(struct list_head *head,
152 const char *name)
153{
154 return __aa_findn_ns(head, name, strlen(name));
155}
156
157static inline struct aa_ns *__aa_lookup_ns(struct aa_ns *base,
158 const char *hname)
159{
160 return __aa_lookupn_ns(base, hname, strlen(hname));
161}
162
163static inline struct aa_ns *aa_lookup_ns(struct aa_ns *view, const char *name)
164{
165 return aa_lookupn_ns(view, name, strlen(name));
166}
167
168#endif
169