Lines Matching defs: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
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
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)
114 AA_BUG(!profile);
115 AA_BUG(!profile->ns);
116 AA_BUG(!mutex_is_locked(&profile->ns->lock));
118 list_add_rcu(&profile->base.list, list);
120 aa_get_profile(profile);
121 l = aa_label_insert(&profile->ns->labels, &profile->label);
122 AA_BUG(l != &profile->label);
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)
140 AA_BUG(!profile);
141 AA_BUG(!profile->ns);
142 AA_BUG(!mutex_is_locked(&profile->ns->lock));
144 list_del_rcu(&profile->base.list);
145 aa_put_profile(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)
156 AA_BUG(!profile);
157 AA_BUG(!profile->ns);
158 AA_BUG(!mutex_is_locked(&profile->ns->lock));
161 __aa_profile_list_release(&profile->base.profiles);
163 aa_label_remove(&profile->label);
164 __aafs_profile_rmdir(profile);
165 __list_remove_profile(profile);
176 struct aa_profile *profile, *tmp;
177 list_for_each_entry_safe(profile, tmp, head, base.list)
178 __remove_profile(profile);
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)
210 AA_DEBUG("%s(%p)\n", __func__, profile);
212 if (!profile)
216 aa_policy_destroy(&profile->base);
217 aa_put_profile(rcu_access_pointer(profile->parent));
219 aa_put_ns(profile->ns);
220 kfree_sensitive(profile->rename);
222 aa_free_file_rules(&profile->file);
223 aa_free_cap_rules(&profile->caps);
224 aa_free_rlimit_rules(&profile->rlimits);
226 for (i = 0; i < profile->xattr_count; i++)
227 kfree_sensitive(profile->xattrs[i]);
228 kfree_sensitive(profile->xattrs);
229 for (i = 0; i < profile->secmark_count; i++)
230 kfree_sensitive(profile->secmark[i].label);
231 kfree_sensitive(profile->secmark);
232 kfree_sensitive(profile->dirname);
233 aa_put_dfa(profile->xmatch);
234 aa_put_dfa(profile->policy.dfa);
236 if (profile->data) {
237 rht = profile->data;
238 profile->data = NULL;
243 kfree_sensitive(profile->hash);
244 aa_put_loaddata(profile->rawdata);
245 aa_label_destroy(&profile->label);
247 kfree_sensitive(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;
263 profile = kzalloc(sizeof(*profile) + sizeof(struct aa_profile *) * 2,
265 if (!profile)
268 if (!aa_policy_init(&profile->base, NULL, hname, gfp))
270 if (!aa_label_init(&profile->label, 1, gfp))
275 proxy = aa_alloc_proxy(&profile->label, gfp);
280 profile->label.proxy = proxy;
282 profile->label.hname = profile->base.hname;
283 profile->label.flags |= FLAG_PROFILE;
284 profile->label.vec[0] = profile;
287 return profile;
290 aa_free_profile(profile);
295 /* TODO: profile accounting - setup in remove */
298 * __strn_find_child - find a profile on @head list using substring of @name
300 * @name: name of profile (NOT NULL)
305 * Returns: unrefcounted profile ptr, or NULL if not found
314 * __find_child - find a profile on @head list with a name matching @name
316 * @name: name of profile (NOT NULL)
320 * Returns: unrefcounted profile ptr, or NULL if not found
328 * aa_find_child - find a profile by @name in @parent
329 * @parent: profile to search (NOT NULL)
330 * @name: profile name to search for (NOT NULL)
332 * Returns: a refcounted profile or NULL if not found
336 struct aa_profile *profile;
340 profile = __find_child(&parent->base.profiles, name);
341 } while (profile && !aa_get_profile_not0(profile));
345 return profile;
349 * __lookup_parent - lookup the parent of a profile of name @hname
350 * @ns: namespace to lookup profile in (NOT NULL)
351 * @hname: hierarchical profile name to find parent of (NOT NULL)
353 * Lookups up the parent of a fully qualified profile name, the profile
355 * is used to load a new profile.
365 struct aa_profile *profile = NULL;
371 profile = __strn_find_child(&policy->profiles, hname,
373 if (!profile)
375 policy = &profile->base;
379 if (!profile)
381 return &profile->base;
385 * __lookupn_profile - lookup the profile matching @hname
386 * @base: base list to start looking up profile name from (NOT NULL)
387 * @hname: hierarchical profile name (NOT NULL)
392 * Returns: unrefcounted profile pointer or NULL if not found
394 * Do a relative name lookup, recursing through profile tree.
399 struct aa_profile *profile = NULL;
404 profile = __strn_find_child(&base->profiles, hname,
406 if (!profile)
409 base = &profile->base;
426 * aa_lookup_profile - find a profile by its full or partial name
431 * Returns: refcounted profile or NULL if not found
436 struct aa_profile *profile;
440 profile = __lookupn_profile(&ns->base, hname, n);
441 } while (profile && !aa_get_profile_not0(profile));
444 /* the unconfined profile is not in the regular profile list */
445 if (!profile && strncmp(hname, "unconfined", n) == 0)
446 profile = aa_get_newest_profile(ns->unconfined);
449 return profile;
460 struct aa_profile *profile;
474 profile = aa_lookupn_profile(ns, name, n - (name - fqname));
476 /* default profile for ns, currently unconfined */
477 profile = aa_get_newest_profile(ns->unconfined);
479 profile = NULL;
482 return profile;
486 * aa_new_null_profile - create or find a null-X learning profile
487 * @parent: profile that caused this profile to be created (NOT NULL)
488 * @hat: true if the null- learning profile is a hat
489 * @base: name to base the null profile off of
492 * Find/Create a null- complain mode profile used in learning mode. The
493 * name of the profile is unique and follows the format of parent//null-XXX.
497 * null profiles are added to the profile list but the list does not
501 * Returns: new refcounted profile else NULL on failure
506 struct aa_profile *p, *profile;
531 profile = aa_find_child(parent, bname);
532 if (profile)
535 profile = aa_alloc_profile(name, NULL, gfp);
536 if (!profile)
539 profile->mode = APPARMOR_COMPLAIN;
540 profile->label.flags |= FLAG_NULL;
542 profile->label.flags |= FLAG_HAT;
543 profile->path_flags = parent->path_flags;
546 rcu_assign_pointer(profile->parent, aa_get_profile(parent));
547 profile->ns = aa_get_ns(parent->ns);
548 profile->file.dfa = aa_get_dfa(nulldfa);
549 profile->policy.dfa = aa_get_dfa(nulldfa);
551 mutex_lock_nested(&profile->ns->lock, profile->ns->level);
554 aa_free_profile(profile);
555 profile = aa_get_profile(p);
557 __add_profile(&parent->base.profiles, profile);
559 mutex_unlock(&profile->ns->lock);
565 return profile;
569 aa_free_profile(profile);
575 * @profile: profile to test if it can be replaced (MAYBE NULL)
581 static int replacement_allowed(struct aa_profile *profile, int noreplace,
584 if (profile) {
585 if (profile->label.flags & FLAG_IMMUTIBLE) {
586 *info = "cannot replace immutable profile";
589 *info = "profile already exists";
612 * @name: name of profile being manipulated (NOT NULL)
706 struct aa_profile *profile)
708 const char *base = basename(profile->base.hname);
709 long len = base - profile->base.hname;
718 if (ent->new == profile)
720 if (strncmp(ent->new->base.hname, profile->base.hname, len) ==
730 * @old: profile to be replaced (NOT NULL)
731 * @new: profile to replace @old with (NOT NULL)
788 * __lookup_replace - lookup replacement information for a profile
790 * @hname - name of profile to lookup
791 * @noreplace - true if not replacing an existing profile
792 * @p - Returns: profile to be replaced
795 * Returns: profile to replace (no ref) on success else ptr error
805 *info = "profile can not be replaced";
844 * aa_replace_profiles - replace profile(s) on the profile list
850 * unpack and replace a profile on the profile list and uses of that profile
851 * by any task creds via invalidating the old version of the profile, which
852 * tasks will notice to update their own cred. If the profile does not exist
853 * on the profile list it is added.
965 /* released on profile replacement or free_profile */
1006 /* dedup actual profile replacement */
1008 "same as current profile, skipping",
1017 * TODO: finer dedup based on profile range in data. Load set
1018 * can differ but profile may remain unchanged
1062 info = "valid profile in failed atomic policy load";
1065 info = "unchecked profile in failed atomic policy load";
1082 * aa_remove_profiles - remove profile(s) from the system
1085 * @fqname: name of the profile or namespace to remove (NOT NULL)
1088 * Remove a profile or sub namespace from the current namespace, so that
1099 struct aa_profile *profile = NULL;
1105 info = "no profile specified";
1133 /* remove profile */
1135 profile = aa_get_profile(__lookup_profile(&ns->base, name));
1136 if (!profile) {
1138 info = "profile does not exist";
1141 name = profile->base.hname;
1143 __remove_profile(profile);
1152 aa_put_profile(profile);