1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include "include/apparmor.h"
16#include "include/context.h"
17#include "include/policy.h"
18#include "include/domain.h"
19#include "include/procattr.h"
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36int aa_getprocattr(struct aa_profile *profile, char **string)
37{
38 char *str;
39 int len = 0, mode_len = 0, ns_len = 0, name_len;
40 const char *mode_str = aa_profile_mode_names[profile->mode];
41 const char *ns_name = NULL;
42 struct aa_namespace *ns = profile->ns;
43 struct aa_namespace *current_ns = __aa_current_profile()->ns;
44 char *s;
45
46 if (!aa_ns_visible(current_ns, ns))
47 return -EACCES;
48
49 ns_name = aa_ns_name(current_ns, ns);
50 ns_len = strlen(ns_name);
51
52
53 if (ns_len)
54 ns_len += 4;
55
56
57 if (!unconfined(profile))
58 mode_len = strlen(mode_str) + 3;
59
60 name_len = strlen(profile->base.hname);
61 len = mode_len + ns_len + name_len + 1;
62 s = str = kmalloc(len + 1, GFP_KERNEL);
63 if (!str)
64 return -ENOMEM;
65
66 if (ns_len) {
67
68 sprintf(s, ":%s://", ns_name);
69 s += ns_len;
70 }
71 if (unconfined(profile))
72
73 sprintf(s, "%s\n", profile->base.hname);
74 else
75 sprintf(s, "%s (%s)\n", profile->base.hname, mode_str);
76 *string = str;
77
78
79 return len;
80}
81
82
83
84
85
86
87
88
89
90static char *split_token_from_name(int op, char *args, u64 * token)
91{
92 char *name;
93
94 *token = simple_strtoull(args, &name, 16);
95 if ((name == args) || *name != '^') {
96 AA_ERROR("%s: Invalid input '%s'", op_table[op], args);
97 return ERR_PTR(-EINVAL);
98 }
99
100 name++;
101 if (!*name)
102 name = NULL;
103 return name;
104}
105
106
107
108
109
110
111
112
113
114int aa_setprocattr_changehat(char *args, size_t size, int test)
115{
116 char *hat;
117 u64 token;
118 const char *hats[16];
119 int count = 0;
120
121 hat = split_token_from_name(OP_CHANGE_HAT, args, &token);
122 if (IS_ERR(hat))
123 return PTR_ERR(hat);
124
125 if (!hat && !token) {
126 AA_ERROR("change_hat: Invalid input, NULL hat and NULL magic");
127 return -EINVAL;
128 }
129
130 if (hat) {
131
132
133
134
135
136
137 char *end = args + size;
138 for (count = 0; (hat < end) && count < 16; ++count) {
139 char *next = hat + strlen(hat) + 1;
140 hats[count] = hat;
141 hat = next;
142 }
143 }
144
145 AA_DEBUG("%s: Magic 0x%llx Hat '%s'\n",
146 __func__, token, hat ? hat : NULL);
147
148 return aa_change_hat(hats, count, token, test);
149}
150
151
152
153
154
155
156
157
158
159int aa_setprocattr_changeprofile(char *fqname, bool onexec, int test)
160{
161 char *name, *ns_name;
162
163 name = aa_split_fqname(fqname, &ns_name);
164 return aa_change_profile(ns_name, name, onexec, test);
165}
166