Lines Matching full:profile
11 * task is confined by. Every task in the system has a profile attached
15 * Each profile exists in a profile namespace which is a container of
16 * visible profiles. Each namespace contains a special "unconfined" profile,
19 * Namespace and profile names can be written together in either
21 * :namespace:profile - used by kernel interfaces for easy detection
22 * namespace://profile - used by policy
24 * Profile names can not start with : or @ or ^ and may not contain \0
26 * Reserved profile names
27 * unconfined - special automatically generated unconfined profile
28 * inherit - special name to indicate profile inheritance
35 * a // in a profile or namespace name indicates a hierarchical name with the
38 * Profile and namespace hierarchies serve two different but similar purposes.
43 * The profile hierarchy severs two distinct purposes,
45 * subprograms under its own profile with different restriction than it
46 * self, and not have it use the system profile.
52 * but is allowed. NOTE: this is currently suboptimal because profile
53 * aliasing is not currently implemented so that a profile for each
58 * A profile or namespace name that can contain one or more // separators
62 * An fqname is a name that may contain both namespace and profile hnames.
66 * - locking of profile lists is currently fairly coarse. All profile
68 * FIXME: move profile lists to using rcu_lists
103 * @profile: the profile to add (NOT NULL)
105 * refcount @profile, should be put by __list_remove_profile
109 static void __add_profile(struct list_head *list, struct aa_profile *profile) in __add_profile() argument
114 AA_BUG(!profile); in __add_profile()
115 AA_BUG(!profile->ns); in __add_profile()
116 AA_BUG(!mutex_is_locked(&profile->ns->lock)); in __add_profile()
118 list_add_rcu(&profile->base.list, list); in __add_profile()
120 aa_get_profile(profile); in __add_profile()
121 l = aa_label_insert(&profile->ns->labels, &profile->label); in __add_profile()
122 AA_BUG(l != &profile->label); in __add_profile()
127 * __list_remove_profile - remove a profile from the list it is on
128 * @profile: the profile to remove (NOT NULL)
130 * remove a profile from the list, warning generally removal should
131 * be done with __replace_profile as most profile removals are
132 * replacements to the unconfined profile.
134 * put @profile list refcount
138 static void __list_remove_profile(struct aa_profile *profile) in __list_remove_profile() argument
140 AA_BUG(!profile); in __list_remove_profile()
141 AA_BUG(!profile->ns); in __list_remove_profile()
142 AA_BUG(!mutex_is_locked(&profile->ns->lock)); in __list_remove_profile()
144 list_del_rcu(&profile->base.list); in __list_remove_profile()
145 aa_put_profile(profile); in __list_remove_profile()
149 * __remove_profile - remove old profile, and children
150 * @profile: profile to be replaced (NOT NULL)
154 static void __remove_profile(struct aa_profile *profile) in __remove_profile() argument
156 AA_BUG(!profile); in __remove_profile()
157 AA_BUG(!profile->ns); in __remove_profile()
158 AA_BUG(!mutex_is_locked(&profile->ns->lock)); in __remove_profile()
161 __aa_profile_list_release(&profile->base.profiles); in __remove_profile()
163 aa_label_remove(&profile->label); in __remove_profile()
164 __aafs_profile_rmdir(profile); in __remove_profile()
165 __list_remove_profile(profile); in __remove_profile()
176 struct aa_profile *profile, *tmp; in __aa_profile_list_release() local
177 list_for_each_entry_safe(profile, tmp, head, base.list) in __aa_profile_list_release()
178 __remove_profile(profile); in __aa_profile_list_release()
196 * aa_free_profile - free a profile
197 * @profile: the profile to free (MAYBE NULL)
199 * Free a profile, its hats and null_profile. All references to the profile,
202 * If the profile was referenced from a task context, free_profile() will
205 void aa_free_profile(struct aa_profile *profile) in aa_free_profile() argument
210 AA_DEBUG("%s(%p)\n", __func__, profile); in aa_free_profile()
212 if (!profile) in aa_free_profile()
216 aa_policy_destroy(&profile->base); in aa_free_profile()
217 aa_put_profile(rcu_access_pointer(profile->parent)); in aa_free_profile()
219 aa_put_ns(profile->ns); in aa_free_profile()
220 kfree_sensitive(profile->rename); in aa_free_profile()
222 aa_free_file_rules(&profile->file); in aa_free_profile()
223 aa_free_cap_rules(&profile->caps); in aa_free_profile()
224 aa_free_rlimit_rules(&profile->rlimits); in aa_free_profile()
226 for (i = 0; i < profile->xattr_count; i++) in aa_free_profile()
227 kfree_sensitive(profile->xattrs[i]); in aa_free_profile()
228 kfree_sensitive(profile->xattrs); in aa_free_profile()
229 for (i = 0; i < profile->secmark_count; i++) in aa_free_profile()
230 kfree_sensitive(profile->secmark[i].label); in aa_free_profile()
231 kfree_sensitive(profile->secmark); in aa_free_profile()
232 kfree_sensitive(profile->dirname); in aa_free_profile()
233 aa_put_dfa(profile->xmatch); in aa_free_profile()
234 aa_put_dfa(profile->policy.dfa); in aa_free_profile()
236 if (profile->data) { in aa_free_profile()
237 rht = profile->data; in aa_free_profile()
238 profile->data = NULL; in aa_free_profile()
243 kfree_sensitive(profile->hash); in aa_free_profile()
244 aa_put_loaddata(profile->rawdata); in aa_free_profile()
245 aa_label_destroy(&profile->label); in aa_free_profile()
247 kfree_sensitive(profile); in aa_free_profile()
251 * aa_alloc_profile - allocate, initialize and return a new profile
252 * @hname: name of the profile (NOT NULL)
255 * Returns: refcount profile or NULL on failure
260 struct aa_profile *profile; in aa_alloc_profile() local
263 profile = kzalloc(struct_size(profile, label.vec, 2), gfp); in aa_alloc_profile()
264 if (!profile) in aa_alloc_profile()
267 if (!aa_policy_init(&profile->base, NULL, hname, gfp)) in aa_alloc_profile()
269 if (!aa_label_init(&profile->label, 1, gfp)) in aa_alloc_profile()
274 proxy = aa_alloc_proxy(&profile->label, gfp); in aa_alloc_profile()
279 profile->label.proxy = proxy; in aa_alloc_profile()
281 profile->label.hname = profile->base.hname; in aa_alloc_profile()
282 profile->label.flags |= FLAG_PROFILE; in aa_alloc_profile()
283 profile->label.vec[0] = profile; in aa_alloc_profile()
286 return profile; in aa_alloc_profile()
289 aa_free_profile(profile); in aa_alloc_profile()
294 /* TODO: profile accounting - setup in remove */
297 * __strn_find_child - find a profile on @head list using substring of @name
299 * @name: name of profile (NOT NULL)
304 * Returns: unrefcounted profile ptr, or NULL if not found
313 * __find_child - find a profile on @head list with a name matching @name
315 * @name: name of profile (NOT NULL)
319 * Returns: unrefcounted profile ptr, or NULL if not found
327 * aa_find_child - find a profile by @name in @parent
328 * @parent: profile to search (NOT NULL)
329 * @name: profile name to search for (NOT NULL)
331 * Returns: a refcounted profile or NULL if not found
335 struct aa_profile *profile; in aa_find_child() local
339 profile = __find_child(&parent->base.profiles, name); in aa_find_child()
340 } while (profile && !aa_get_profile_not0(profile)); in aa_find_child()
344 return profile; in aa_find_child()
348 * __lookup_parent - lookup the parent of a profile of name @hname
349 * @ns: namespace to lookup profile in (NOT NULL)
350 * @hname: hierarchical profile name to find parent of (NOT NULL)
352 * Lookups up the parent of a fully qualified profile name, the profile
354 * is used to load a new profile.
364 struct aa_profile *profile = NULL; in __lookup_parent() local
370 profile = __strn_find_child(&policy->profiles, hname, in __lookup_parent()
372 if (!profile) in __lookup_parent()
374 policy = &profile->base; in __lookup_parent()
378 if (!profile) in __lookup_parent()
380 return &profile->base; in __lookup_parent()
384 * __lookupn_profile - lookup the profile matching @hname
385 * @base: base list to start looking up profile name from (NOT NULL)
386 * @hname: hierarchical profile name (NOT NULL)
391 * Returns: unrefcounted profile pointer or NULL if not found
393 * Do a relative name lookup, recursing through profile tree.
398 struct aa_profile *profile = NULL; in __lookupn_profile() local
403 profile = __strn_find_child(&base->profiles, hname, in __lookupn_profile()
405 if (!profile) in __lookupn_profile()
408 base = &profile->base; in __lookupn_profile()
425 * aa_lookupn_profile - find a profile by its full or partial name
430 * Returns: refcounted profile or NULL if not found
435 struct aa_profile *profile; in aa_lookupn_profile() local
439 profile = __lookupn_profile(&ns->base, hname, n); in aa_lookupn_profile()
440 } while (profile && !aa_get_profile_not0(profile)); in aa_lookupn_profile()
443 /* the unconfined profile is not in the regular profile list */ in aa_lookupn_profile()
444 if (!profile && strncmp(hname, "unconfined", n) == 0) in aa_lookupn_profile()
445 profile = aa_get_newest_profile(ns->unconfined); in aa_lookupn_profile()
448 return profile; in aa_lookupn_profile()
459 struct aa_profile *profile; in aa_fqlookupn_profile() local
473 profile = aa_lookupn_profile(ns, name, n - (name - fqname)); in aa_fqlookupn_profile()
475 /* default profile for ns, currently unconfined */ in aa_fqlookupn_profile()
476 profile = aa_get_newest_profile(ns->unconfined); in aa_fqlookupn_profile()
478 profile = NULL; in aa_fqlookupn_profile()
481 return profile; in aa_fqlookupn_profile()
485 * aa_new_null_profile - create or find a null-X learning profile
486 * @parent: profile that caused this profile to be created (NOT NULL)
487 * @hat: true if the null- learning profile is a hat
488 * @base: name to base the null profile off of
491 * Find/Create a null- complain mode profile used in learning mode. The
492 * name of the profile is unique and follows the format of parent//null-XXX.
496 * null profiles are added to the profile list but the list does not
500 * Returns: new refcounted profile else NULL on failure
505 struct aa_profile *p, *profile; in aa_new_null_profile() local
530 profile = aa_find_child(parent, bname); in aa_new_null_profile()
531 if (profile) in aa_new_null_profile()
534 profile = aa_alloc_profile(name, NULL, gfp); in aa_new_null_profile()
535 if (!profile) in aa_new_null_profile()
538 profile->mode = APPARMOR_COMPLAIN; in aa_new_null_profile()
539 profile->label.flags |= FLAG_NULL; in aa_new_null_profile()
541 profile->label.flags |= FLAG_HAT; in aa_new_null_profile()
542 profile->path_flags = parent->path_flags; in aa_new_null_profile()
545 rcu_assign_pointer(profile->parent, aa_get_profile(parent)); in aa_new_null_profile()
546 profile->ns = aa_get_ns(parent->ns); in aa_new_null_profile()
547 profile->file.dfa = aa_get_dfa(nulldfa); in aa_new_null_profile()
548 profile->policy.dfa = aa_get_dfa(nulldfa); in aa_new_null_profile()
550 mutex_lock_nested(&profile->ns->lock, profile->ns->level); in aa_new_null_profile()
553 aa_free_profile(profile); in aa_new_null_profile()
554 profile = aa_get_profile(p); in aa_new_null_profile()
556 __add_profile(&parent->base.profiles, profile); in aa_new_null_profile()
558 mutex_unlock(&profile->ns->lock); in aa_new_null_profile()
564 return profile; in aa_new_null_profile()
568 aa_free_profile(profile); in aa_new_null_profile()
574 * @profile: profile to test if it can be replaced (MAYBE NULL)
580 static int replacement_allowed(struct aa_profile *profile, int noreplace, in replacement_allowed() argument
583 if (profile) { in replacement_allowed()
584 if (profile->label.flags & FLAG_IMMUTIBLE) { in replacement_allowed()
585 *info = "cannot replace immutable profile"; in replacement_allowed()
588 *info = "profile already exists"; in replacement_allowed()
611 * @name: name of profile being manipulated (NOT NULL)
746 struct aa_profile *profile) in __list_lookup_parent() argument
748 const char *base = basename(profile->base.hname); in __list_lookup_parent()
749 long len = base - profile->base.hname; in __list_lookup_parent()
758 if (ent->new == profile) in __list_lookup_parent()
760 if (strncmp(ent->new->base.hname, profile->base.hname, len) == in __list_lookup_parent()
770 * @old: profile to be replaced (NOT NULL)
771 * @new: profile to replace @old with (NOT NULL)
828 * __lookup_replace - lookup replacement information for a profile
830 * @hname - name of profile to lookup
831 * @noreplace - true if not replacing an existing profile
832 * @p - Returns: profile to be replaced
835 * Returns: profile to replace (no ref) on success else ptr error
845 *info = "profile can not be replaced"; in __lookup_replace()
884 * aa_replace_profiles - replace profile(s) on the profile list
890 * unpack and replace a profile on the profile list and uses of that profile
891 * by any task creds via invalidating the old version of the profile, which
892 * tasks will notice to update their own cred. If the profile does not exist
893 * on the profile list it is added.
1008 /* released on profile replacement or free_profile */ in aa_replace_profiles()
1051 /* dedup actual profile replacement */ in aa_replace_profiles()
1053 "same as current profile, skipping", in aa_replace_profiles()
1062 * TODO: finer dedup based on profile range in data. Load set in aa_replace_profiles()
1063 * can differ but profile may remain unchanged in aa_replace_profiles()
1107 info = "valid profile in failed atomic policy load"; in aa_replace_profiles()
1110 info = "unchecked profile in failed atomic policy load"; in aa_replace_profiles()
1127 * aa_remove_profiles - remove profile(s) from the system
1130 * @fqname: name of the profile or namespace to remove (NOT NULL)
1133 * Remove a profile or sub namespace from the current namespace, so that
1144 struct aa_profile *profile = NULL; in aa_remove_profiles() local
1150 info = "no profile specified"; in aa_remove_profiles()
1178 /* remove profile */ in aa_remove_profiles()
1180 profile = aa_get_profile(__lookup_profile(&ns->base, name)); in aa_remove_profiles()
1181 if (!profile) { in aa_remove_profiles()
1183 info = "profile does not exist"; in aa_remove_profiles()
1186 name = profile->base.hname; in aa_remove_profiles()
1188 __remove_profile(profile); in aa_remove_profiles()
1197 aa_put_profile(profile); in aa_remove_profiles()