This source file includes following definitions.
- tomoyo_check_task_acl
- tomoyo_write_self
- tomoyo_read_self
- tomoyo_open
- tomoyo_release
- tomoyo_poll
- tomoyo_read
- tomoyo_write
- tomoyo_create_entry
- tomoyo_initerface_init
1
2
3
4
5
6
7
8 #include <linux/security.h>
9 #include "common.h"
10
11
12
13
14
15
16
17
18
19 static bool tomoyo_check_task_acl(struct tomoyo_request_info *r,
20 const struct tomoyo_acl_info *ptr)
21 {
22 const struct tomoyo_task_acl *acl = container_of(ptr, typeof(*acl),
23 head);
24
25 return !tomoyo_pathcmp(r->param.task.domainname, acl->domainname);
26 }
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 static ssize_t tomoyo_write_self(struct file *file, const char __user *buf,
42 size_t count, loff_t *ppos)
43 {
44 char *data;
45 int error;
46
47 if (!count || count >= TOMOYO_EXEC_TMPSIZE - 10)
48 return -ENOMEM;
49 data = memdup_user_nul(buf, count);
50 if (IS_ERR(data))
51 return PTR_ERR(data);
52 tomoyo_normalize_line(data);
53 if (tomoyo_correct_domain(data)) {
54 const int idx = tomoyo_read_lock();
55 struct tomoyo_path_info name;
56 struct tomoyo_request_info r;
57
58 name.name = data;
59 tomoyo_fill_path_info(&name);
60
61 tomoyo_init_request_info(&r, NULL, TOMOYO_MAC_FILE_EXECUTE);
62 r.param_type = TOMOYO_TYPE_MANUAL_TASK_ACL;
63 r.param.task.domainname = &name;
64 tomoyo_check_acl(&r, tomoyo_check_task_acl);
65 if (!r.granted)
66 error = -EPERM;
67 else {
68 struct tomoyo_domain_info *new_domain =
69 tomoyo_assign_domain(data, true);
70 if (!new_domain) {
71 error = -ENOENT;
72 } else {
73 struct tomoyo_task *s = tomoyo_task(current);
74 struct tomoyo_domain_info *old_domain =
75 s->domain_info;
76
77 s->domain_info = new_domain;
78 atomic_inc(&new_domain->users);
79 atomic_dec(&old_domain->users);
80 error = 0;
81 }
82 }
83 tomoyo_read_unlock(idx);
84 } else
85 error = -EINVAL;
86 kfree(data);
87 return error ? error : count;
88 }
89
90
91
92
93
94
95
96
97
98
99
100 static ssize_t tomoyo_read_self(struct file *file, char __user *buf,
101 size_t count, loff_t *ppos)
102 {
103 const char *domain = tomoyo_domain()->domainname->name;
104 loff_t len = strlen(domain);
105 loff_t pos = *ppos;
106
107 if (pos >= len || !count)
108 return 0;
109 len -= pos;
110 if (count < len)
111 len = count;
112 if (copy_to_user(buf, domain + pos, len))
113 return -EFAULT;
114 *ppos += len;
115 return len;
116 }
117
118
119 static const struct file_operations tomoyo_self_operations = {
120 .write = tomoyo_write_self,
121 .read = tomoyo_read_self,
122 };
123
124
125
126
127
128
129
130
131
132 static int tomoyo_open(struct inode *inode, struct file *file)
133 {
134 const int key = ((u8 *) file_inode(file)->i_private)
135 - ((u8 *) NULL);
136 return tomoyo_open_control(key, file);
137 }
138
139
140
141
142
143
144
145 static int tomoyo_release(struct inode *inode, struct file *file)
146 {
147 tomoyo_close_control(file->private_data);
148 return 0;
149 }
150
151
152
153
154
155
156
157
158
159
160 static __poll_t tomoyo_poll(struct file *file, poll_table *wait)
161 {
162 return tomoyo_poll_control(file, wait);
163 }
164
165
166
167
168
169
170
171
172
173
174
175 static ssize_t tomoyo_read(struct file *file, char __user *buf, size_t count,
176 loff_t *ppos)
177 {
178 return tomoyo_read_control(file->private_data, buf, count);
179 }
180
181
182
183
184
185
186
187
188
189
190
191 static ssize_t tomoyo_write(struct file *file, const char __user *buf,
192 size_t count, loff_t *ppos)
193 {
194 return tomoyo_write_control(file->private_data, buf, count);
195 }
196
197
198
199
200
201
202
203
204 static const struct file_operations tomoyo_operations = {
205 .open = tomoyo_open,
206 .release = tomoyo_release,
207 .poll = tomoyo_poll,
208 .read = tomoyo_read,
209 .write = tomoyo_write,
210 .llseek = noop_llseek,
211 };
212
213
214
215
216
217
218
219
220
221
222
223 static void __init tomoyo_create_entry(const char *name, const umode_t mode,
224 struct dentry *parent, const u8 key)
225 {
226 securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,
227 &tomoyo_operations);
228 }
229
230
231
232
233
234
235 static int __init tomoyo_initerface_init(void)
236 {
237 struct tomoyo_domain_info *domain;
238 struct dentry *tomoyo_dir;
239
240 if (!tomoyo_enabled)
241 return 0;
242 domain = tomoyo_domain();
243
244 if (domain != &tomoyo_kernel_domain)
245 return 0;
246
247 tomoyo_dir = securityfs_create_dir("tomoyo", NULL);
248 tomoyo_create_entry("query", 0600, tomoyo_dir,
249 TOMOYO_QUERY);
250 tomoyo_create_entry("domain_policy", 0600, tomoyo_dir,
251 TOMOYO_DOMAINPOLICY);
252 tomoyo_create_entry("exception_policy", 0600, tomoyo_dir,
253 TOMOYO_EXCEPTIONPOLICY);
254 tomoyo_create_entry("audit", 0400, tomoyo_dir,
255 TOMOYO_AUDIT);
256 tomoyo_create_entry(".process_status", 0600, tomoyo_dir,
257 TOMOYO_PROCESS_STATUS);
258 tomoyo_create_entry("stat", 0644, tomoyo_dir,
259 TOMOYO_STAT);
260 tomoyo_create_entry("profile", 0600, tomoyo_dir,
261 TOMOYO_PROFILE);
262 tomoyo_create_entry("manager", 0600, tomoyo_dir,
263 TOMOYO_MANAGER);
264 tomoyo_create_entry("version", 0400, tomoyo_dir,
265 TOMOYO_VERSION);
266 securityfs_create_file("self_domain", 0666, tomoyo_dir, NULL,
267 &tomoyo_self_operations);
268 tomoyo_load_builtin_policy();
269 return 0;
270 }
271
272 fs_initcall(tomoyo_initerface_init);