Given a label with a profile stack of A//&B or A//&C ... A ptrace rule should be able to specify a generic trace pattern with a rule like ptrace trace A//&**, however this is failing because while the correct label match routine is called, it is being done post label decomposition so it is always being done against a profile instead of the stacked label. To fix this refactor the cross check to pass the full peer label in to the label_match.
Unified · Split
| @@ -133,6 +133,9 @@ extern struct aa_perms allperms; · 132 unmodified lines | ||
| 133 | 133 | #define xcheck_labels_profiles(L1, L2, FN, args...) \ |
| 134 | 134 | xcheck_ns_labels((L1), (L2), xcheck_ns_profile_label, (FN), args) |
| 135 | 135 | |
| 136 | +#define xcheck_labels(L1, L2, P, FN1, FN2) \ | |
| 137 | + xcheck(fn_for_each((L1), (P), (FN1)), fn_for_each((L2), (P), (FN2))) | |
| 138 | + | |
| 136 | 139 | |
| 137 | 140 | void aa_perm_mask_to_str(char *str, const char *chrs, u32 mask); |
| 138 | 141 | void aa_audit_perm_names(struct audit_buffer *ab, const char **names, u32 mask); |
| @@ -64,40 +64,48 @@ static void audit_ptrace_cb(struct audit_buffer *ab, void *va) · 63 unmodified lines | ||
| 64 | 64 | FLAGS_NONE, GFP_ATOMIC); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | +/* assumes check for PROFILE_MEDIATES is already done */ | |
| 67 | 68 | /* TODO: conditionals */ |
| 68 | 69 | static int profile_ptrace_perm(struct aa_profile *profile, |
| 69 | − struct aa_profile *peer, u32 request, | |
| 70 | − struct common_audit_data *sa) | |
| 70 | + struct aa_label *peer, u32 request, | |
| 71 | + struct common_audit_data *sa) | |
| 71 | 72 | { |
| 72 | 73 | struct aa_perms perms = { }; |
| 73 | 74 | |
| 74 | − /* need because of peer in cross check */ | |
| 75 | − if (profile_unconfined(profile) || | |
| 76 | − !PROFILE_MEDIATES(profile, AA_CLASS_PTRACE)) | |
| 77 | − return 0; | |
| 78 | − | |
| 79 | − aad(sa)->peer = &peer->label; | |
| 80 | − aa_profile_match_label(profile, &peer->label, AA_CLASS_PTRACE, request, | |
| 75 | + aad(sa)->peer = peer; | |
| 76 | + aa_profile_match_label(profile, peer, AA_CLASS_PTRACE, request, | |
| 81 | 77 | &perms); |
| 82 | 78 | aa_apply_modes_to_perms(profile, &perms); |
| 83 | 79 | return aa_check_perms(profile, &perms, request, sa, audit_ptrace_cb); |
| 84 | 80 | } |
| 85 | 81 | |
| 86 | −static int cross_ptrace_perm(struct aa_profile *tracer, | |
| 87 | − struct aa_profile *tracee, u32 request, | |
| 88 | − struct common_audit_data *sa) | |
| 82 | +static int profile_tracee_perm(struct aa_profile *tracee, | |
| 83 | + struct aa_label *tracer, u32 request, | |
| 84 | + struct common_audit_data *sa) | |
| 89 | 85 | { |
| 86 | + if (profile_unconfined(tracee) || unconfined(tracer) || | |
| 87 | + !PROFILE_MEDIATES(tracee, AA_CLASS_PTRACE)) | |
| 88 | + return 0; | |
| 89 | + | |
| 90 | + return profile_ptrace_perm(tracee, tracer, request, sa); | |
| 91 | +} | |
| 92 | + | |
| 93 | +static int profile_tracer_perm(struct aa_profile *tracer, | |
| 94 | + struct aa_label *tracee, u32 request, | |
| 95 | + struct common_audit_data *sa) | |
| 96 | +{ | |
| 97 | + if (profile_unconfined(tracer)) | |
| 98 | + return 0; | |
| 99 | + | |
| 90 | 100 | if (PROFILE_MEDIATES(tracer, AA_CLASS_PTRACE)) |
| 91 | − return xcheck(profile_ptrace_perm(tracer, tracee, request, sa), | |
| 92 | − profile_ptrace_perm(tracee, tracer, | |
| 93 | − request << PTRACE_PERM_SHIFT, | |
| 94 | − sa)); | |
| 95 | − /* policy uses the old style capability check for ptrace */ | |
| 96 | − if (profile_unconfined(tracer) || tracer == tracee) | |
| 101 | + return profile_ptrace_perm(tracer, tracee, request, sa); | |
| 102 | + | |
| 103 | + /* profile uses the old style capability check for ptrace */ | |
| 104 | + if (&tracer->label == tracee) | |
| 97 | 105 | return 0; |
| 98 | 106 | |
| 99 | 107 | aad(sa)->label = &tracer->label; |
| 100 | − aad(sa)->peer = &tracee->label; | |
| 108 | + aad(sa)->peer = tracee; | |
| 101 | 109 | aad(sa)->request = 0; |
| 102 | 110 | aad(sa)->error = aa_capable(&tracer->label, CAP_SYS_PTRACE, 1); |
| 103 | 111 | |
| @@ -115,10 +123,13 @@ static int cross_ptrace_perm(struct aa_profile *tracer, · 11 unmodified lines | ||
| 115 | 123 | int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee, |
| 116 | 124 | u32 request) |
| 117 | 125 | { |
| 126 | + struct aa_profile *profile; | |
| 127 | + u32 xrequest = request << PTRACE_PERM_SHIFT; | |
| 118 | 128 | DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_PTRACE); |
| 119 | 129 | |
| 120 | − return xcheck_labels_profiles(tracer, tracee, cross_ptrace_perm, | |
| 121 | − request, &sa); | |
| 130 | + return xcheck_labels(tracer, tracee, profile, | |
| 131 | + profile_tracer_perm(profile, tracee, request, &sa), | |
| 132 | + profile_tracee_perm(profile, tracer, xrequest, &sa)); | |
| 122 | 133 | } |
| 123 | 134 | |
| 124 | 135 | |