History

apparmor: fix ptrace label match when matching stacked labels

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.

John Johansen committed 8 years ago

Commit 0dda0b31 parent c92a9a42 files · +35 −21Browse files

Unified · Split

2 files
  1. security/apparmor/include/perms.h +3 −0
  2. security/apparmor/ipc.c +32 −21
security/apparmor/include/perms.h+3−0
@@ -133,6 +133,9 @@ extern struct aa_perms allperms; · 132 unmodified lines
133133 #define xcheck_labels_profiles(L1, L2, FN, args...) \
134134 xcheck_ns_labels((L1), (L2), xcheck_ns_profile_label, (FN), args)
135135
136+#define xcheck_labels(L1, L2, P, FN1, FN2) \
137+ xcheck(fn_for_each((L1), (P), (FN1)), fn_for_each((L2), (P), (FN2)))
138+
136139
137140 void aa_perm_mask_to_str(char *str, const char *chrs, u32 mask);
138141 void aa_audit_perm_names(struct audit_buffer *ab, const char **names, u32 mask);
security/apparmor/ipc.c+32−21
@@ -64,40 +64,48 @@ static void audit_ptrace_cb(struct audit_buffer *ab, void *va) · 63 unmodified lines
6464 FLAGS_NONE, GFP_ATOMIC);
6565 }
6666
67+/* assumes check for PROFILE_MEDIATES is already done */
6768 /* TODO: conditionals */
6869 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)
7172 {
7273 struct aa_perms perms = { };
7374
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,
8177 &perms);
8278 aa_apply_modes_to_perms(profile, &perms);
8379 return aa_check_perms(profile, &perms, request, sa, audit_ptrace_cb);
8480 }
8581
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)
8985 {
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+
90100 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)
97105 return 0;
98106
99107 aad(sa)->label = &tracer->label;
100− aad(sa)->peer = &tracee->label;
108+ aad(sa)->peer = tracee;
101109 aad(sa)->request = 0;
102110 aad(sa)->error = aa_capable(&tracer->label, CAP_SYS_PTRACE, 1);
103111
@@ -115,10 +123,13 @@ static int cross_ptrace_perm(struct aa_profile *tracer, · 11 unmodified lines
115123 int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
116124 u32 request)
117125 {
126+ struct aa_profile *profile;
127+ u32 xrequest = request << PTRACE_PERM_SHIFT;
118128 DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_PTRACE);
119129
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));
122133 }
123134
124135

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t