Thomas Gleixner | b886d83c | 2019-06-01 10:08:55 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 2 | /* |
| 3 | * AppArmor security module |
| 4 | * |
| 5 | * This file contains AppArmor policy manipulation functions |
| 6 | * |
| 7 | * Copyright (C) 1998-2008 Novell/SUSE |
| 8 | * Copyright 2009-2017 Canonical Ltd. |
| 9 | * |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 10 | * AppArmor policy namespaces, allow for different sets of policies |
| 11 | * to be loaded for tasks within the namespace. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/list.h> |
| 15 | #include <linux/mutex.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/string.h> |
| 18 | |
| 19 | #include "include/apparmor.h" |
John Johansen | d8889d4 | 2017-10-11 01:04:48 -0700 | [diff] [blame] | 20 | #include "include/cred.h" |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 21 | #include "include/policy_ns.h" |
John Johansen | 637f688 | 2017-06-09 08:14:28 -0700 | [diff] [blame] | 22 | #include "include/label.h" |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 23 | #include "include/policy.h" |
| 24 | |
| 25 | /* root profile namespace */ |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 26 | struct aa_ns *root_ns; |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 27 | const char *aa_hidden_ns_name = "---"; |
| 28 | |
| 29 | /** |
| 30 | * aa_ns_visible - test if @view is visible from @curr |
| 31 | * @curr: namespace to treat as the parent (NOT NULL) |
| 32 | * @view: namespace to test if visible from @curr (NOT NULL) |
John Johansen | 92b6d8e | 2017-01-16 00:42:25 -0800 | [diff] [blame] | 33 | * @subns: whether view of a subns is allowed |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 34 | * |
| 35 | * Returns: true if @view is visible from @curr else false |
| 36 | */ |
John Johansen | 92b6d8e | 2017-01-16 00:42:25 -0800 | [diff] [blame] | 37 | bool aa_ns_visible(struct aa_ns *curr, struct aa_ns *view, bool subns) |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 38 | { |
| 39 | if (curr == view) |
| 40 | return true; |
| 41 | |
John Johansen | 92b6d8e | 2017-01-16 00:42:25 -0800 | [diff] [blame] | 42 | if (!subns) |
| 43 | return false; |
| 44 | |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 45 | for ( ; view; view = view->parent) { |
| 46 | if (view->parent == curr) |
| 47 | return true; |
| 48 | } |
John Johansen | 92b6d8e | 2017-01-16 00:42:25 -0800 | [diff] [blame] | 49 | |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 50 | return false; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * aa_na_name - Find the ns name to display for @view from @curr |
| 55 | * @curr - current namespace (NOT NULL) |
| 56 | * @view - namespace attempting to view (NOT NULL) |
John Johansen | 92b6d8e | 2017-01-16 00:42:25 -0800 | [diff] [blame] | 57 | * @subns - are subns visible |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 58 | * |
| 59 | * Returns: name of @view visible from @curr |
| 60 | */ |
John Johansen | 92b6d8e | 2017-01-16 00:42:25 -0800 | [diff] [blame] | 61 | const char *aa_ns_name(struct aa_ns *curr, struct aa_ns *view, bool subns) |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 62 | { |
| 63 | /* if view == curr then the namespace name isn't displayed */ |
| 64 | if (curr == view) |
| 65 | return ""; |
| 66 | |
John Johansen | 92b6d8e | 2017-01-16 00:42:25 -0800 | [diff] [blame] | 67 | if (aa_ns_visible(curr, view, subns)) { |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 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. |
| 70 | * Only output the virtualized portion of the name |
| 71 | * Add + 2 to skip over // separating curr hname prefix |
| 72 | * from the visible tail of the views hname |
| 73 | */ |
| 74 | return view->base.hname + strlen(curr->base.hname) + 2; |
| 75 | } |
| 76 | |
| 77 | return aa_hidden_ns_name; |
| 78 | } |
| 79 | |
| 80 | /** |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 81 | * alloc_ns - allocate, initialize and return a new namespace |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 82 | * @prefix: parent namespace name (MAYBE NULL) |
| 83 | * @name: a preallocated name (NOT NULL) |
| 84 | * |
| 85 | * Returns: refcounted namespace or NULL on failure. |
| 86 | */ |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 87 | static struct aa_ns *alloc_ns(const char *prefix, const char *name) |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 88 | { |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 89 | struct aa_ns *ns; |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 90 | |
| 91 | ns = kzalloc(sizeof(*ns), GFP_KERNEL); |
| 92 | AA_DEBUG("%s(%p)\n", __func__, ns); |
| 93 | if (!ns) |
| 94 | return NULL; |
John Johansen | d102d89 | 2017-01-16 00:42:31 -0800 | [diff] [blame] | 95 | if (!aa_policy_init(&ns->base, prefix, name, GFP_KERNEL)) |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 96 | goto fail_ns; |
| 97 | |
| 98 | INIT_LIST_HEAD(&ns->sub_ns); |
John Johansen | 5d5182ca | 2017-05-09 00:08:41 -0700 | [diff] [blame] | 99 | INIT_LIST_HEAD(&ns->rawdata_list); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 100 | mutex_init(&ns->lock); |
John Johansen | d9bf2c2 | 2017-05-26 16:27:58 -0700 | [diff] [blame] | 101 | init_waitqueue_head(&ns->wait); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 102 | |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 103 | /* released by aa_free_ns() */ |
John Johansen | 637f688 | 2017-06-09 08:14:28 -0700 | [diff] [blame] | 104 | ns->unconfined = aa_alloc_profile("unconfined", NULL, GFP_KERNEL); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 105 | if (!ns->unconfined) |
| 106 | goto fail_unconfined; |
| 107 | |
John Johansen | 637f688 | 2017-06-09 08:14:28 -0700 | [diff] [blame] | 108 | ns->unconfined->label.flags |= FLAG_IX_ON_NAME_ERROR | |
| 109 | FLAG_IMMUTIBLE | FLAG_NS_COUNT | FLAG_UNCONFINED; |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 110 | ns->unconfined->mode = APPARMOR_UNCONFINED; |
John Johansen | 15372b9 | 2017-08-16 05:48:06 -0700 | [diff] [blame] | 111 | ns->unconfined->file.dfa = aa_get_dfa(nulldfa); |
| 112 | ns->unconfined->policy.dfa = aa_get_dfa(nulldfa); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 113 | |
| 114 | /* ns and ns->unconfined share ns->unconfined refcount */ |
| 115 | ns->unconfined->ns = ns; |
| 116 | |
| 117 | atomic_set(&ns->uniq_null, 0); |
| 118 | |
John Johansen | 637f688 | 2017-06-09 08:14:28 -0700 | [diff] [blame] | 119 | aa_labelset_init(&ns->labels); |
| 120 | |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 121 | return ns; |
| 122 | |
| 123 | fail_unconfined: |
| 124 | kzfree(ns->base.hname); |
| 125 | fail_ns: |
| 126 | kzfree(ns); |
| 127 | return NULL; |
| 128 | } |
| 129 | |
| 130 | /** |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 131 | * aa_free_ns - free a profile namespace |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 132 | * @ns: the namespace to free (MAYBE NULL) |
| 133 | * |
| 134 | * Requires: All references to the namespace must have been put, if the |
| 135 | * namespace was referenced by a profile confining a task, |
| 136 | */ |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 137 | void aa_free_ns(struct aa_ns *ns) |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 138 | { |
| 139 | if (!ns) |
| 140 | return; |
| 141 | |
| 142 | aa_policy_destroy(&ns->base); |
John Johansen | 637f688 | 2017-06-09 08:14:28 -0700 | [diff] [blame] | 143 | aa_labelset_destroy(&ns->labels); |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 144 | aa_put_ns(ns->parent); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 145 | |
| 146 | ns->unconfined->ns = NULL; |
| 147 | aa_free_profile(ns->unconfined); |
| 148 | kzfree(ns); |
| 149 | } |
| 150 | |
| 151 | /** |
John Johansen | 9a2d40c | 2017-01-16 00:42:22 -0800 | [diff] [blame] | 152 | * aa_findn_ns - look up a profile namespace on the namespace list |
| 153 | * @root: namespace to search in (NOT NULL) |
| 154 | * @name: name of namespace to find (NOT NULL) |
| 155 | * @n: length of @name |
| 156 | * |
| 157 | * Returns: a refcounted namespace on the list, or NULL if no namespace |
| 158 | * called @name exists. |
| 159 | * |
| 160 | * refcount released by caller |
| 161 | */ |
| 162 | struct aa_ns *aa_findn_ns(struct aa_ns *root, const char *name, size_t n) |
| 163 | { |
| 164 | struct aa_ns *ns = NULL; |
| 165 | |
| 166 | rcu_read_lock(); |
| 167 | ns = aa_get_ns(__aa_findn_ns(&root->sub_ns, name, n)); |
| 168 | rcu_read_unlock(); |
| 169 | |
| 170 | return ns; |
| 171 | } |
| 172 | |
| 173 | /** |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 174 | * aa_find_ns - look up a profile namespace on the namespace list |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 175 | * @root: namespace to search in (NOT NULL) |
| 176 | * @name: name of namespace to find (NOT NULL) |
| 177 | * |
| 178 | * Returns: a refcounted namespace on the list, or NULL if no namespace |
| 179 | * called @name exists. |
| 180 | * |
| 181 | * refcount released by caller |
| 182 | */ |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 183 | struct aa_ns *aa_find_ns(struct aa_ns *root, const char *name) |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 184 | { |
John Johansen | 9a2d40c | 2017-01-16 00:42:22 -0800 | [diff] [blame] | 185 | return aa_findn_ns(root, name, strlen(name)); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 186 | } |
| 187 | |
John Johansen | 3664268 | 2017-06-02 17:44:27 -0700 | [diff] [blame] | 188 | /** |
| 189 | * __aa_lookupn_ns - lookup the namespace matching @hname |
| 190 | * @base: base list to start looking up profile name from (NOT NULL) |
| 191 | * @hname: hierarchical ns name (NOT NULL) |
| 192 | * @n: length of @hname |
| 193 | * |
| 194 | * Requires: rcu_read_lock be held |
| 195 | * |
| 196 | * Returns: unrefcounted ns pointer or NULL if not found |
| 197 | * |
| 198 | * Do a relative name lookup, recursing through profile tree. |
| 199 | */ |
| 200 | struct aa_ns *__aa_lookupn_ns(struct aa_ns *view, const char *hname, size_t n) |
| 201 | { |
| 202 | struct aa_ns *ns = view; |
| 203 | const char *split; |
| 204 | |
| 205 | for (split = strnstr(hname, "//", n); split; |
| 206 | split = strnstr(hname, "//", n)) { |
| 207 | ns = __aa_findn_ns(&ns->sub_ns, hname, split - hname); |
| 208 | if (!ns) |
| 209 | return NULL; |
| 210 | |
| 211 | n -= split + 2 - hname; |
| 212 | hname = split + 2; |
| 213 | } |
| 214 | |
| 215 | if (n) |
| 216 | return __aa_findn_ns(&ns->sub_ns, hname, n); |
| 217 | return NULL; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * aa_lookupn_ns - look up a policy namespace relative to @view |
| 222 | * @view: namespace to search in (NOT NULL) |
| 223 | * @name: name of namespace to find (NOT NULL) |
| 224 | * @n: length of @name |
| 225 | * |
| 226 | * Returns: a refcounted namespace on the list, or NULL if no namespace |
| 227 | * called @name exists. |
| 228 | * |
| 229 | * refcount released by caller |
| 230 | */ |
| 231 | struct aa_ns *aa_lookupn_ns(struct aa_ns *view, const char *name, size_t n) |
| 232 | { |
| 233 | struct aa_ns *ns = NULL; |
| 234 | |
| 235 | rcu_read_lock(); |
| 236 | ns = aa_get_ns(__aa_lookupn_ns(view, name, n)); |
| 237 | rcu_read_unlock(); |
| 238 | |
| 239 | return ns; |
| 240 | } |
| 241 | |
John Johansen | 73688d1 | 2017-01-16 00:42:34 -0800 | [diff] [blame] | 242 | static struct aa_ns *__aa_create_ns(struct aa_ns *parent, const char *name, |
| 243 | struct dentry *dir) |
| 244 | { |
| 245 | struct aa_ns *ns; |
| 246 | int error; |
| 247 | |
| 248 | AA_BUG(!parent); |
| 249 | AA_BUG(!name); |
| 250 | AA_BUG(!mutex_is_locked(&parent->lock)); |
| 251 | |
| 252 | ns = alloc_ns(parent->base.hname, name); |
| 253 | if (!ns) |
Dan Carpenter | 0a6b292 | 2018-08-02 11:38:23 +0300 | [diff] [blame] | 254 | return ERR_PTR(-ENOMEM); |
John Johansen | feb3c76 | 2017-11-20 23:24:09 -0800 | [diff] [blame] | 255 | ns->level = parent->level + 1; |
| 256 | mutex_lock_nested(&ns->lock, ns->level); |
John Johansen | 98407f0 | 2017-05-25 06:31:46 -0700 | [diff] [blame] | 257 | error = __aafs_ns_mkdir(ns, ns_subns_dir(parent), name, dir); |
John Johansen | 73688d1 | 2017-01-16 00:42:34 -0800 | [diff] [blame] | 258 | if (error) { |
| 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); |
| 263 | return ERR_PTR(error); |
| 264 | } |
| 265 | ns->parent = aa_get_ns(parent); |
| 266 | list_add_rcu(&ns->base.list, &parent->sub_ns); |
| 267 | /* add list ref */ |
| 268 | aa_get_ns(ns); |
| 269 | mutex_unlock(&ns->lock); |
| 270 | |
| 271 | return ns; |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * aa_create_ns - create an ns, fail if it already exists |
| 276 | * @parent: the parent of the namespace being created |
| 277 | * @name: the name of the namespace |
| 278 | * @dir: if not null the dir to put the ns entries in |
| 279 | * |
| 280 | * Returns: the a refcounted ns that has been add or an ERR_PTR |
| 281 | */ |
| 282 | struct aa_ns *__aa_find_or_create_ns(struct aa_ns *parent, const char *name, |
| 283 | struct dentry *dir) |
| 284 | { |
| 285 | struct aa_ns *ns; |
| 286 | |
| 287 | AA_BUG(!mutex_is_locked(&parent->lock)); |
| 288 | |
| 289 | /* try and find the specified ns */ |
| 290 | /* released by caller */ |
| 291 | ns = aa_get_ns(__aa_find_ns(&parent->sub_ns, name)); |
| 292 | if (!ns) |
| 293 | ns = __aa_create_ns(parent, name, dir); |
| 294 | else |
| 295 | ns = ERR_PTR(-EEXIST); |
| 296 | |
| 297 | /* return ref */ |
| 298 | return ns; |
| 299 | } |
| 300 | |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 301 | /** |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 302 | * aa_prepare_ns - find an existing or create a new namespace of @name |
John Johansen | 73688d1 | 2017-01-16 00:42:34 -0800 | [diff] [blame] | 303 | * @parent: ns to treat as parent |
| 304 | * @name: the namespace to find or add (NOT NULL) |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 305 | * |
John Johansen | 73688d1 | 2017-01-16 00:42:34 -0800 | [diff] [blame] | 306 | * Returns: refcounted namespace or PTR_ERR if failed to create one |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 307 | */ |
John Johansen | 73688d1 | 2017-01-16 00:42:34 -0800 | [diff] [blame] | 308 | struct aa_ns *aa_prepare_ns(struct aa_ns *parent, const char *name) |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 309 | { |
John Johansen | 73688d1 | 2017-01-16 00:42:34 -0800 | [diff] [blame] | 310 | struct aa_ns *ns; |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 311 | |
John Johansen | feb3c76 | 2017-11-20 23:24:09 -0800 | [diff] [blame] | 312 | mutex_lock_nested(&parent->lock, parent->level); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 313 | /* try and find the specified ns and if it doesn't exist create it */ |
| 314 | /* released by caller */ |
John Johansen | 73688d1 | 2017-01-16 00:42:34 -0800 | [diff] [blame] | 315 | ns = aa_get_ns(__aa_find_ns(&parent->sub_ns, name)); |
| 316 | if (!ns) |
| 317 | ns = __aa_create_ns(parent, name, NULL); |
| 318 | mutex_unlock(&parent->lock); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 319 | |
| 320 | /* return ref */ |
| 321 | return ns; |
| 322 | } |
| 323 | |
| 324 | static void __ns_list_release(struct list_head *head); |
| 325 | |
| 326 | /** |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 327 | * destroy_ns - remove everything contained by @ns |
John Johansen | 31617dd | 2017-01-16 00:42:24 -0800 | [diff] [blame] | 328 | * @ns: namespace to have it contents removed (NOT NULL) |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 329 | */ |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 330 | static void destroy_ns(struct aa_ns *ns) |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 331 | { |
| 332 | if (!ns) |
| 333 | return; |
| 334 | |
John Johansen | feb3c76 | 2017-11-20 23:24:09 -0800 | [diff] [blame] | 335 | mutex_lock_nested(&ns->lock, ns->level); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 336 | /* release all profiles in this namespace */ |
| 337 | __aa_profile_list_release(&ns->base.profiles); |
| 338 | |
| 339 | /* release all sub namespaces */ |
| 340 | __ns_list_release(&ns->sub_ns); |
| 341 | |
John Johansen | 637f688 | 2017-06-09 08:14:28 -0700 | [diff] [blame] | 342 | if (ns->parent) { |
| 343 | unsigned long flags; |
| 344 | |
| 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); |
| 349 | } |
John Johansen | c97204b | 2017-05-25 06:23:42 -0700 | [diff] [blame] | 350 | __aafs_ns_rmdir(ns); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 351 | mutex_unlock(&ns->lock); |
| 352 | } |
| 353 | |
| 354 | /** |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 355 | * __aa_remove_ns - remove a namespace and all its children |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 356 | * @ns: namespace to be removed (NOT NULL) |
| 357 | * |
| 358 | * Requires: ns->parent->lock be held and ns removed from parent. |
| 359 | */ |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 360 | void __aa_remove_ns(struct aa_ns *ns) |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 361 | { |
| 362 | /* remove ns from namespace list */ |
| 363 | list_del_rcu(&ns->base.list); |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 364 | destroy_ns(ns); |
| 365 | aa_put_ns(ns); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | /** |
| 369 | * __ns_list_release - remove all profile namespaces on the list put refs |
| 370 | * @head: list of profile namespaces (NOT NULL) |
| 371 | * |
| 372 | * Requires: namespace lock be held |
| 373 | */ |
| 374 | static void __ns_list_release(struct list_head *head) |
| 375 | { |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 376 | struct aa_ns *ns, *tmp; |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 377 | |
| 378 | list_for_each_entry_safe(ns, tmp, head, base.list) |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 379 | __aa_remove_ns(ns); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 380 | |
| 381 | } |
| 382 | |
| 383 | /** |
John Johansen | 31617dd | 2017-01-16 00:42:24 -0800 | [diff] [blame] | 384 | * aa_alloc_root_ns - allocate the root profile namespace |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 385 | * |
| 386 | * Returns: %0 on success else error |
| 387 | * |
| 388 | */ |
| 389 | int __init aa_alloc_root_ns(void) |
| 390 | { |
| 391 | /* released by aa_free_root_ns - used as list ref*/ |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 392 | root_ns = alloc_ns(NULL, "root"); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 393 | if (!root_ns) |
| 394 | return -ENOMEM; |
| 395 | |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * aa_free_root_ns - free the root profile namespace |
| 401 | */ |
| 402 | void __init aa_free_root_ns(void) |
| 403 | { |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 404 | struct aa_ns *ns = root_ns; |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 405 | |
| 406 | root_ns = NULL; |
| 407 | |
John Johansen | 98849df | 2017-01-16 00:42:16 -0800 | [diff] [blame] | 408 | destroy_ns(ns); |
| 409 | aa_put_ns(ns); |
John Johansen | cff281f | 2017-01-16 00:42:15 -0800 | [diff] [blame] | 410 | } |