Lines Matching refs:profile

101 static inline unsigned int match_component(struct aa_profile *profile,  in match_component()  argument
108 state = aa_dfa_match(profile->file.dfa, state, "&"); in match_component()
109 if (profile->ns == tp->ns) in match_component()
110 return aa_dfa_match(profile->file.dfa, state, tp->base.hname); in match_component()
113 ns_name = aa_ns_name(profile->ns, tp->ns, true); in match_component()
114 state = aa_dfa_match_len(profile->file.dfa, state, ":", 1); in match_component()
115 state = aa_dfa_match(profile->file.dfa, state, ns_name); in match_component()
116 state = aa_dfa_match_len(profile->file.dfa, state, ":", 1); in match_component()
117 return aa_dfa_match(profile->file.dfa, state, tp->base.hname); in match_component()
136 static int label_compound_match(struct aa_profile *profile, in label_compound_match() argument
147 if (!aa_ns_visible(profile->ns, tp->ns, subns)) in label_compound_match()
149 state = match_component(profile, tp, stack, state); in label_compound_match()
161 if (!aa_ns_visible(profile->ns, tp->ns, subns)) in label_compound_match()
163 state = aa_dfa_match(profile->file.dfa, state, "//&"); in label_compound_match()
164 state = match_component(profile, tp, false, state); in label_compound_match()
168 *perms = aa_compute_fperms(profile->file.dfa, state, &cond); in label_compound_match()
169 aa_apply_modes_to_perms(profile, perms); in label_compound_match()
196 static int label_components_match(struct aa_profile *profile, in label_components_match() argument
209 if (!aa_ns_visible(profile->ns, tp->ns, subns)) in label_components_match()
211 state = match_component(profile, tp, stack, start); in label_components_match()
221 tmp = aa_compute_fperms(profile->file.dfa, state, &cond); in label_components_match()
222 aa_apply_modes_to_perms(profile, &tmp); in label_components_match()
225 if (!aa_ns_visible(profile->ns, tp->ns, subns)) in label_components_match()
227 state = match_component(profile, tp, stack, start); in label_components_match()
230 tmp = aa_compute_fperms(profile->file.dfa, state, &cond); in label_components_match()
231 aa_apply_modes_to_perms(profile, &tmp); in label_components_match()
257 static int label_match(struct aa_profile *profile, struct aa_label *label, in label_match() argument
264 error = label_compound_match(profile, label, stack, state, subns, in label_match()
270 return label_components_match(profile, label, stack, state, subns, in label_match()
290 static int change_profile_perms(struct aa_profile *profile, in change_profile_perms() argument
295 if (profile_unconfined(profile)) { in change_profile_perms()
302 return label_match(profile, target, stack, start, true, request, perms); in change_profile_perms()
314 struct aa_profile *profile, unsigned int state) in aa_xattrs_match() argument
320 int value_size = 0, ret = profile->xattr_count; in aa_xattrs_match()
322 if (!bprm || !profile->xattr_count) in aa_xattrs_match()
326 state = aa_dfa_null_transition(profile->xmatch, state); in aa_xattrs_match()
330 for (i = 0; i < profile->xattr_count; i++) { in aa_xattrs_match()
331 size = vfs_getxattr_alloc(d, profile->xattrs[i], &value, in aa_xattrs_match()
337 state = aa_dfa_match_len(profile->xmatch, state, value, in aa_xattrs_match()
339 perm = dfa_user_allow(profile->xmatch, state); in aa_xattrs_match()
346 state = aa_dfa_null_transition(profile->xmatch, state); in aa_xattrs_match()
390 struct aa_profile *profile, *candidate = NULL; in __attach_match() local
395 list_for_each_entry_rcu(profile, head, base.list) { in __attach_match()
396 if (profile->label.flags & FLAG_NULL && in __attach_match()
397 &profile->label == ns_unconfined(profile->ns)) in __attach_match()
411 if (profile->xmatch) { in __attach_match()
415 state = aa_dfa_leftmatch(profile->xmatch, DFA_START, in __attach_match()
417 perm = dfa_user_allow(profile->xmatch, state); in __attach_match()
425 ret = aa_xattrs_match(bprm, profile, state); in __attach_match()
447 candidate = profile; in __attach_match()
448 candidate_len = profile->xmatch_len; in __attach_match()
452 } else if (!strcmp(profile->base.name, name)) in __attach_match()
457 return profile; in __attach_match()
482 struct aa_profile *profile; in find_attach() local
485 profile = aa_get_profile(__attach_match(bprm, name, list, info)); in find_attach()
488 return profile ? &profile->label : NULL; in find_attach()
504 struct aa_label *x_table_lookup(struct aa_profile *profile, u32 xindex, in x_table_lookup() argument
517 for (*name = profile->file.trans.table[index]; !label && *name; in x_table_lookup()
522 new_profile = aa_find_child(profile, *name); in x_table_lookup()
527 label = aa_label_parse(&profile->label, *name, GFP_ATOMIC, in x_table_lookup()
550 static struct aa_label *x_to_label(struct aa_profile *profile, in x_to_label() argument
557 struct aa_ns *ns = profile->ns; in x_to_label()
568 stack = profile->file.trans.table[xindex & AA_X_INDEX_MASK]; in x_to_label()
571 new = x_table_lookup(profile, xindex, lookupname); in x_to_label()
579 new = find_attach(bprm, ns, &profile->base.profiles, in x_to_label()
596 new = aa_get_newest_label(&profile->label); in x_to_label()
598 new = aa_get_newest_label(ns_unconfined(profile->ns)); in x_to_label()
617 static struct aa_label *profile_transition(struct aa_profile *profile, in profile_transition() argument
626 unsigned int state = profile->file.start; in profile_transition()
631 AA_BUG(!profile); in profile_transition()
635 error = aa_path_name(&bprm->file->f_path, profile->path_flags, buffer, in profile_transition()
636 &name, &info, profile->disconnected); in profile_transition()
638 if (profile_unconfined(profile) || in profile_transition()
639 (profile->label.flags & FLAG_IX_ON_NAME_ERROR)) { in profile_transition()
642 new = aa_get_newest_label(&profile->label); in profile_transition()
648 if (profile_unconfined(profile)) { in profile_transition()
649 new = find_attach(bprm, profile->ns, in profile_transition()
650 &profile->ns->base.profiles, name, &info); in profile_transition()
656 return aa_get_newest_label(&profile->label); in profile_transition()
660 state = aa_str_perms(profile->file.dfa, state, name, cond, &perms); in profile_transition()
663 new = x_to_label(profile, bprm, name, perms.xindex, &target, in profile_transition()
665 if (new && new->proxy == profile->label.proxy && info) { in profile_transition()
689 } else if (COMPLAIN_MODE(profile)) { in profile_transition()
699 new_profile = aa_new_null_profile(profile, false, n, in profile_transition()
733 aa_audit_file(profile, &perms, OP_EXEC, MAY_EXEC, name, target, new, in profile_transition()
743 static int profile_onexec(struct aa_profile *profile, struct aa_label *onexec, in profile_onexec() argument
748 unsigned int state = profile->file.start; in profile_onexec()
753 AA_BUG(!profile); in profile_onexec()
758 if (profile_unconfined(profile)) { in profile_onexec()
768 error = aa_path_name(&bprm->file->f_path, profile->path_flags, buffer, in profile_onexec()
769 &xname, &info, profile->disconnected); in profile_onexec()
771 if (profile_unconfined(profile) || in profile_onexec()
772 (profile->label.flags & FLAG_IX_ON_NAME_ERROR)) { in profile_onexec()
781 state = aa_str_perms(profile->file.dfa, state, xname, cond, &perms); in profile_onexec()
790 state = aa_dfa_null_transition(profile->file.dfa, state); in profile_onexec()
791 error = change_profile_perms(profile, onexec, stack, AA_MAY_ONEXEC, in profile_onexec()
809 return aa_audit_file(profile, &perms, OP_EXEC, AA_MAY_ONEXEC, xname, in profile_onexec()
821 struct aa_profile *profile; in handle_onexec() local
831 error = fn_for_each_in_ns(label, profile, in handle_onexec()
832 profile_onexec(profile, onexec, stack, in handle_onexec()
836 new = fn_label_build_in_ns(label, profile, GFP_ATOMIC, in handle_onexec()
838 profile_transition(profile, bprm, buffer, in handle_onexec()
843 error = fn_for_each_in_ns(label, profile, in handle_onexec()
844 profile_onexec(profile, onexec, stack, bprm, in handle_onexec()
848 new = fn_label_build_in_ns(label, profile, GFP_ATOMIC, in handle_onexec()
849 aa_label_merge(&profile->label, onexec, in handle_onexec()
851 profile_transition(profile, bprm, buffer, in handle_onexec()
859 error = fn_for_each_in_ns(label, profile, in handle_onexec()
860 aa_audit_file(profile, &nullperms, OP_CHANGE_ONEXEC, in handle_onexec()
879 struct aa_profile *profile; in apparmor_bprm_set_creds() local
916 new = fn_label_build(label, profile, GFP_ATOMIC, in apparmor_bprm_set_creds()
917 profile_transition(profile, bprm, buffer, in apparmor_bprm_set_creds()
987 error = fn_for_each(label, profile, in apparmor_bprm_set_creds()
988 aa_audit_file(profile, &nullperms, OP_EXEC, MAY_EXEC, in apparmor_bprm_set_creds()
1005 static struct aa_label *build_change_hat(struct aa_profile *profile, in build_change_hat() argument
1012 if (sibling && PROFILE_IS_HAT(profile)) { in build_change_hat()
1013 root = aa_get_profile_rcu(&profile->parent); in build_change_hat()
1014 } else if (!sibling && !PROFILE_IS_HAT(profile)) { in build_change_hat()
1015 root = aa_get_profile(profile); in build_change_hat()
1025 if (COMPLAIN_MODE(profile)) { in build_change_hat()
1026 hat = aa_new_null_profile(profile, true, name, in build_change_hat()
1037 aa_audit_file(profile, &nullperms, OP_CHANGE_HAT, AA_MAY_CHANGEHAT, in build_change_hat()
1056 struct aa_profile *profile, *root, *hat = NULL; in change_hat() local
1073 label_for_each_in_ns(it, labels_ns(label), label, profile) { in change_hat()
1074 if (sibling && PROFILE_IS_HAT(profile)) { in change_hat()
1075 root = aa_get_profile_rcu(&profile->parent); in change_hat()
1076 } else if (!sibling && !PROFILE_IS_HAT(profile)) { in change_hat()
1077 root = aa_get_profile(profile); in change_hat()
1086 if (!COMPLAIN_MODE(profile)) in change_hat()
1109 label_for_each_in_ns(it, labels_ns(label), label, profile) { in change_hat()
1110 if (!list_empty(&profile->base.profiles)) { in change_hat()
1120 label_for_each_in_ns(it, labels_ns(label), label, profile) { in change_hat()
1128 if (count > 1 || COMPLAIN_MODE(profile)) { in change_hat()
1129 aa_audit_file(profile, &nullperms, OP_CHANGE_HAT, in change_hat()
1137 new = fn_label_build_in_ns(label, profile, GFP_KERNEL, in change_hat()
1138 build_change_hat(profile, name, sibling), in change_hat()
1139 aa_get_label(&profile->label)); in change_hat()
1171 struct aa_profile *profile; in aa_change_hat() local
1269 fn_for_each_in_ns(label, profile, in aa_change_hat()
1270 aa_audit_file(profile, &perms, OP_CHANGE_HAT, in aa_change_hat()
1279 struct aa_profile *profile, in change_profile_perms_wrapper() argument
1287 error = change_profile_perms(profile, target, stack, request, in change_profile_perms_wrapper()
1288 profile->file.start, perms); in change_profile_perms_wrapper()
1290 error = aa_audit_file(profile, perms, op, request, name, in change_profile_perms_wrapper()
1314 struct aa_profile *profile; in aa_change_profile() local
1396 error = fn_for_each_in_ns(label, profile, in aa_change_profile()
1398 profile, target, stack, in aa_change_profile()
1409 if (error && !fn_for_each_in_ns(label, profile, in aa_change_profile()
1410 COMPLAIN_MODE(profile))) in aa_change_profile()
1425 new = fn_label_build_in_ns(label, profile, GFP_KERNEL, in aa_change_profile()
1427 aa_get_label(&profile->label)); in aa_change_profile()
1464 error = fn_for_each_in_ns(label, profile, in aa_change_profile()
1465 aa_audit_file(profile, &perms, op, request, auditname, in aa_change_profile()