Lines Matching full:ns
54 * aa_na_name - Find the ns name to display for @view from @curr
68 /* at this point if a ns is visible it is in a view ns in aa_ns_name()
69 * thus the curr ns.hname is a prefix of its name. in aa_ns_name()
89 struct aa_ns *ns; in alloc_ns() local
91 ns = kzalloc(sizeof(*ns), GFP_KERNEL); in alloc_ns()
92 AA_DEBUG("%s(%p)\n", __func__, ns); in alloc_ns()
93 if (!ns) in alloc_ns()
95 if (!aa_policy_init(&ns->base, prefix, name, GFP_KERNEL)) in alloc_ns()
98 INIT_LIST_HEAD(&ns->sub_ns); in alloc_ns()
99 INIT_LIST_HEAD(&ns->rawdata_list); in alloc_ns()
100 mutex_init(&ns->lock); in alloc_ns()
101 init_waitqueue_head(&ns->wait); in alloc_ns()
104 ns->unconfined = aa_alloc_profile("unconfined", NULL, GFP_KERNEL); in alloc_ns()
105 if (!ns->unconfined) in alloc_ns()
108 ns->unconfined->label.flags |= FLAG_IX_ON_NAME_ERROR | in alloc_ns()
110 ns->unconfined->mode = APPARMOR_UNCONFINED; in alloc_ns()
111 ns->unconfined->file.dfa = aa_get_dfa(nulldfa); in alloc_ns()
112 ns->unconfined->policy.dfa = aa_get_dfa(nulldfa); in alloc_ns()
114 /* ns and ns->unconfined share ns->unconfined refcount */ in alloc_ns()
115 ns->unconfined->ns = ns; in alloc_ns()
117 atomic_set(&ns->uniq_null, 0); in alloc_ns()
119 aa_labelset_init(&ns->labels); in alloc_ns()
121 return ns; in alloc_ns()
124 kfree_sensitive(ns->base.hname); in alloc_ns()
126 kfree_sensitive(ns); in alloc_ns()
132 * @ns: the namespace to free (MAYBE NULL)
137 void aa_free_ns(struct aa_ns *ns) in aa_free_ns() argument
139 if (!ns) in aa_free_ns()
142 aa_policy_destroy(&ns->base); in aa_free_ns()
143 aa_labelset_destroy(&ns->labels); in aa_free_ns()
144 aa_put_ns(ns->parent); in aa_free_ns()
146 ns->unconfined->ns = NULL; in aa_free_ns()
147 aa_free_profile(ns->unconfined); in aa_free_ns()
148 kfree_sensitive(ns); in aa_free_ns()
164 struct aa_ns *ns = NULL; in aa_findn_ns() local
167 ns = aa_get_ns(__aa_findn_ns(&root->sub_ns, name, n)); in aa_findn_ns()
170 return ns; in aa_findn_ns()
191 * @hname: hierarchical ns name (NOT NULL)
196 * Returns: unrefcounted ns pointer or NULL if not found
202 struct aa_ns *ns = view; in __aa_lookupn_ns() local
207 ns = __aa_findn_ns(&ns->sub_ns, hname, split - hname); in __aa_lookupn_ns()
208 if (!ns) in __aa_lookupn_ns()
216 return __aa_findn_ns(&ns->sub_ns, hname, n); in __aa_lookupn_ns()
233 struct aa_ns *ns = NULL; in aa_lookupn_ns() local
236 ns = aa_get_ns(__aa_lookupn_ns(view, name, n)); in aa_lookupn_ns()
239 return ns; in aa_lookupn_ns()
245 struct aa_ns *ns; in __aa_create_ns() local
252 ns = alloc_ns(parent->base.hname, name); in __aa_create_ns()
253 if (!ns) in __aa_create_ns()
255 ns->level = parent->level + 1; in __aa_create_ns()
256 mutex_lock_nested(&ns->lock, ns->level); in __aa_create_ns()
257 error = __aafs_ns_mkdir(ns, ns_subns_dir(parent), name, dir); in __aa_create_ns()
259 AA_ERROR("Failed to create interface for ns %s\n", in __aa_create_ns()
260 ns->base.name); in __aa_create_ns()
261 mutex_unlock(&ns->lock); in __aa_create_ns()
262 aa_free_ns(ns); in __aa_create_ns()
265 ns->parent = aa_get_ns(parent); in __aa_create_ns()
266 list_add_rcu(&ns->base.list, &parent->sub_ns); in __aa_create_ns()
268 aa_get_ns(ns); in __aa_create_ns()
269 mutex_unlock(&ns->lock); in __aa_create_ns()
271 return ns; in __aa_create_ns()
275 * aa_create_ns - create an ns, fail if it already exists
278 * @dir: if not null the dir to put the ns entries in
280 * Returns: the a refcounted ns that has been add or an ERR_PTR
285 struct aa_ns *ns; in __aa_find_or_create_ns() local
289 /* try and find the specified ns */ in __aa_find_or_create_ns()
291 ns = aa_get_ns(__aa_find_ns(&parent->sub_ns, name)); in __aa_find_or_create_ns()
292 if (!ns) in __aa_find_or_create_ns()
293 ns = __aa_create_ns(parent, name, dir); in __aa_find_or_create_ns()
295 ns = ERR_PTR(-EEXIST); in __aa_find_or_create_ns()
298 return ns; in __aa_find_or_create_ns()
303 * @parent: ns to treat as parent
310 struct aa_ns *ns; in aa_prepare_ns() local
313 /* try and find the specified ns and if it doesn't exist create it */ in aa_prepare_ns()
315 ns = aa_get_ns(__aa_find_ns(&parent->sub_ns, name)); in aa_prepare_ns()
316 if (!ns) in aa_prepare_ns()
317 ns = __aa_create_ns(parent, name, NULL); in aa_prepare_ns()
321 return ns; in aa_prepare_ns()
327 * destroy_ns - remove everything contained by @ns
328 * @ns: namespace to have it contents removed (NOT NULL)
330 static void destroy_ns(struct aa_ns *ns) in destroy_ns() argument
332 if (!ns) in destroy_ns()
335 mutex_lock_nested(&ns->lock, ns->level); in destroy_ns()
337 __aa_profile_list_release(&ns->base.profiles); in destroy_ns()
340 __ns_list_release(&ns->sub_ns); in destroy_ns()
342 if (ns->parent) { in destroy_ns()
345 write_lock_irqsave(&ns->labels.lock, flags); in destroy_ns()
346 __aa_proxy_redirect(ns_unconfined(ns), in destroy_ns()
347 ns_unconfined(ns->parent)); in destroy_ns()
348 write_unlock_irqrestore(&ns->labels.lock, flags); in destroy_ns()
350 __aafs_ns_rmdir(ns); in destroy_ns()
351 mutex_unlock(&ns->lock); in destroy_ns()
356 * @ns: namespace to be removed (NOT NULL)
358 * Requires: ns->parent->lock be held and ns removed from parent.
360 void __aa_remove_ns(struct aa_ns *ns) in __aa_remove_ns() argument
362 /* remove ns from namespace list */ in __aa_remove_ns()
363 list_del_rcu(&ns->base.list); in __aa_remove_ns()
364 destroy_ns(ns); in __aa_remove_ns()
365 aa_put_ns(ns); in __aa_remove_ns()
376 struct aa_ns *ns, *tmp; in __ns_list_release() local
378 list_for_each_entry_safe(ns, tmp, head, base.list) in __ns_list_release()
379 __aa_remove_ns(ns); in __ns_list_release()
404 struct aa_ns *ns = root_ns; in aa_free_root_ns() local
408 destroy_ns(ns); in aa_free_root_ns()
409 aa_put_ns(ns); in aa_free_root_ns()