1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include "include/apparmor.h"
16#include "include/cred.h"
17#include "include/policy.h"
18#include "include/policy_ns.h"
19#include "include/domain.h"
20#include "include/procattr.h"
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37int aa_getprocattr(struct aa_label *label, char **string)
38{
39 struct aa_ns *ns = labels_ns(label);
40 struct aa_ns *current_ns = aa_get_current_ns();
41 int len;
42
43 if (!aa_ns_visible(current_ns, ns, true)) {
44 aa_put_ns(current_ns);
45 return -EACCES;
46 }
47
48 len = aa_label_snxprint(NULL, 0, current_ns, label,
49 FLAG_SHOW_MODE | FLAG_VIEW_SUBNS |
50 FLAG_HIDDEN_UNCONFINED);
51 AA_BUG(len < 0);
52
53 *string = kmalloc(len + 2, GFP_KERNEL);
54 if (!*string) {
55 aa_put_ns(current_ns);
56 return -ENOMEM;
57 }
58
59 len = aa_label_snxprint(*string, len + 2, current_ns, label,
60 FLAG_SHOW_MODE | FLAG_VIEW_SUBNS |
61 FLAG_HIDDEN_UNCONFINED);
62 if (len < 0) {
63 aa_put_ns(current_ns);
64 return len;
65 }
66
67 (*string)[len] = '\n';
68 (*string)[len + 1] = 0;
69
70 aa_put_ns(current_ns);
71 return len + 1;
72}
73
74
75
76
77
78
79
80
81
82static char *split_token_from_name(const char *op, char *args, u64 *token)
83{
84 char *name;
85
86 *token = simple_strtoull(args, &name, 16);
87 if ((name == args) || *name != '^') {
88 AA_ERROR("%s: Invalid input '%s'", op, args);
89 return ERR_PTR(-EINVAL);
90 }
91
92 name++;
93 if (!*name)
94 name = NULL;
95 return name;
96}
97
98
99
100
101
102
103
104
105
106int aa_setprocattr_changehat(char *args, size_t size, int flags)
107{
108 char *hat;
109 u64 token;
110 const char *hats[16];
111 int count = 0;
112
113 hat = split_token_from_name(OP_CHANGE_HAT, args, &token);
114 if (IS_ERR(hat))
115 return PTR_ERR(hat);
116
117 if (!hat && !token) {
118 AA_ERROR("change_hat: Invalid input, NULL hat and NULL magic");
119 return -EINVAL;
120 }
121
122 if (hat) {
123
124
125
126
127
128
129 char *end = args + size;
130 for (count = 0; (hat < end) && count < 16; ++count) {
131 char *next = hat + strlen(hat) + 1;
132 hats[count] = hat;
133 AA_DEBUG("%s: (pid %d) Magic 0x%llx count %d hat '%s'\n"
134 , __func__, current->pid, token, count, hat);
135 hat = next;
136 }
137 } else
138 AA_DEBUG("%s: (pid %d) Magic 0x%llx count %d Hat '%s'\n",
139 __func__, current->pid, token, count, "<NULL>");
140
141 return aa_change_hat(hats, count, token, flags);
142}
143