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