|
4 | 4 | * This file contains AppArmor ipc mediation |
5 | 5 | * |
6 | 6 | * Copyright (C) 1998-2008 Novell/SUSE |
7 | | - * Copyright 2009-2010 Canonical Ltd. |
| 7 | + * Copyright 2009-2017 Canonical Ltd. |
8 | 8 | * |
9 | 9 | * This program is free software; you can redistribute it and/or |
10 | 10 | * modify it under the terms of the GNU General Public License as |
|
25 | 25 | static void audit_ptrace_cb(struct audit_buffer *ab, void *va) |
26 | 26 | { |
27 | 27 | struct common_audit_data *sa = va; |
| 28 | + |
28 | 29 | audit_log_format(ab, " peer="); |
29 | 30 | aa_label_xaudit(ab, labels_ns(aad(sa)->label), aad(sa)->peer, |
30 | 31 | FLAGS_NONE, GFP_ATOMIC); |
31 | 32 | } |
32 | 33 |
|
33 | | -/** |
34 | | - * aa_audit_ptrace - do auditing for ptrace |
35 | | - * @profile: profile being enforced (NOT NULL) |
36 | | - * @target: profile being traced (NOT NULL) |
37 | | - * @error: error condition |
38 | | - * |
39 | | - * Returns: %0 or error code |
40 | | - */ |
41 | | -static int aa_audit_ptrace(struct aa_profile *profile, |
42 | | - struct aa_profile *target, int error) |
| 34 | +static int cross_ptrace_perm(struct aa_profile *tracer, |
| 35 | + struct aa_profile *tracee, u32 request, |
| 36 | + struct common_audit_data *sa) |
43 | 37 | { |
44 | | - DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_PTRACE); |
| 38 | + /* policy uses the old style capability check for ptrace */ |
| 39 | + if (profile_unconfined(tracer) || tracer == tracee) |
| 40 | + return 0; |
45 | 41 |
|
46 | | - aad(&sa)->peer = &target->label; |
47 | | - aad(&sa)->error = error; |
| 42 | + aad(sa)->label = &tracer->label; |
| 43 | + aad(sa)->peer = &tracee->label; |
| 44 | + aad(sa)->request = 0; |
| 45 | + aad(sa)->error = aa_capable(&tracer->label, CAP_SYS_PTRACE, 1); |
48 | 46 |
|
49 | | - return aa_audit(AUDIT_APPARMOR_AUTO, profile, &sa, audit_ptrace_cb); |
| 47 | + return aa_audit(AUDIT_APPARMOR_AUTO, tracer, sa, audit_ptrace_cb); |
50 | 48 | } |
51 | 49 |
|
52 | 50 | /** |
53 | 51 | * aa_may_ptrace - test if tracer task can trace the tracee |
54 | | - * @tracer: profile of the task doing the tracing (NOT NULL) |
55 | | - * @tracee: task to be traced |
56 | | - * @mode: whether PTRACE_MODE_READ || PTRACE_MODE_ATTACH |
| 52 | + * @tracer: label of the task doing the tracing (NOT NULL) |
| 53 | + * @tracee: task label to be traced |
| 54 | + * @request: permission request |
57 | 55 | * |
58 | 56 | * Returns: %0 else error code if permission denied or error |
59 | 57 | */ |
60 | | -int aa_may_ptrace(struct aa_profile *tracer, struct aa_profile *tracee, |
61 | | - unsigned int mode) |
| 58 | +int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee, |
| 59 | + u32 request) |
62 | 60 | { |
63 | | - /* TODO: currently only based on capability, not extended ptrace |
64 | | - * rules, |
65 | | - * Test mode for PTRACE_MODE_READ || PTRACE_MODE_ATTACH |
66 | | - */ |
| 61 | + DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_PTRACE); |
67 | 62 |
|
68 | | - if (profile_unconfined(tracer) || tracer == tracee) |
69 | | - return 0; |
70 | | - /* log this capability request */ |
71 | | - return aa_capable(&tracer->label, CAP_SYS_PTRACE, 1); |
| 63 | + return xcheck_labels_profiles(tracer, tracee, cross_ptrace_perm, |
| 64 | + request, &sa); |
72 | 65 | } |
73 | 66 |
|
74 | | -/** |
75 | | - * aa_ptrace - do ptrace permission check and auditing |
76 | | - * @tracer: task doing the tracing (NOT NULL) |
77 | | - * @tracee: task being traced (NOT NULL) |
78 | | - * @mode: ptrace mode either PTRACE_MODE_READ || PTRACE_MODE_ATTACH |
79 | | - * |
80 | | - * Returns: %0 else error code if permission denied or error |
81 | | - */ |
82 | | -int aa_ptrace(struct task_struct *tracer, struct task_struct *tracee, |
83 | | - unsigned int mode) |
84 | | -{ |
85 | | - /* |
86 | | - * tracer can ptrace tracee when |
87 | | - * - tracer is unconfined || |
88 | | - * - tracer is in complain mode |
89 | | - * - tracer has rules allowing it to trace tracee currently this is: |
90 | | - * - confined by the same profile || |
91 | | - * - tracer profile has CAP_SYS_PTRACE |
92 | | - */ |
93 | 67 |
|
94 | | - struct aa_label *tracer_l = aa_get_task_label(tracer); |
95 | | - int error = 0; |
96 | | - |
97 | | - if (!unconfined(tracer_l)) { |
98 | | - struct aa_label *tracee_l = aa_get_task_label(tracee); |
99 | | - |
100 | | - error = aa_may_ptrace(labels_profile(tracer_l), |
101 | | - labels_profile(tracee_l), |
102 | | - mode); |
103 | | - error = aa_audit_ptrace(labels_profile(tracer_l), |
104 | | - labels_profile(tracee_l), |
105 | | - error); |
106 | | - |
107 | | - aa_put_label(tracee_l); |
108 | | - } |
109 | | - aa_put_label(tracer_l); |
110 | | - |
111 | | - return error; |
112 | | -} |
0 commit comments