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