]>
Commit | Line | Data |
---|---|---|
9590837b KT |
1 | /* |
2 | * security/tomoyo/common.h | |
3 | * | |
76bb0895 | 4 | * Header file for TOMOYO. |
9590837b | 5 | * |
76bb0895 | 6 | * Copyright (C) 2005-2010 NTT DATA CORPORATION |
9590837b KT |
7 | */ |
8 | ||
9 | #ifndef _SECURITY_TOMOYO_COMMON_H | |
10 | #define _SECURITY_TOMOYO_COMMON_H | |
11 | ||
12 | #include <linux/ctype.h> | |
13 | #include <linux/string.h> | |
14 | #include <linux/mm.h> | |
15 | #include <linux/file.h> | |
16 | #include <linux/kmod.h> | |
17 | #include <linux/fs.h> | |
18 | #include <linux/sched.h> | |
19 | #include <linux/namei.h> | |
20 | #include <linux/mount.h> | |
21 | #include <linux/list.h> | |
76bb0895 | 22 | #include <linux/cred.h> |
17fcfbd9 | 23 | #include <linux/poll.h> |
76bb0895 TH |
24 | struct linux_binprm; |
25 | ||
26 | /********** Constants definitions. **********/ | |
27 | ||
28 | /* | |
29 | * TOMOYO uses this hash only when appending a string into the string | |
30 | * table. Frequency of appending strings is very low. So we don't need | |
31 | * large (e.g. 64k) hash size. 256 will be sufficient. | |
32 | */ | |
33 | #define TOMOYO_HASH_BITS 8 | |
34 | #define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS) | |
35 | ||
c8c57e84 | 36 | #define TOMOYO_EXEC_TMPSIZE 4096 |
76bb0895 TH |
37 | |
38 | /* Profile number is an integer between 0 and 255. */ | |
39 | #define TOMOYO_MAX_PROFILES 256 | |
40 | ||
cb0abe6a TH |
41 | enum tomoyo_mode_index { |
42 | TOMOYO_CONFIG_DISABLED, | |
43 | TOMOYO_CONFIG_LEARNING, | |
44 | TOMOYO_CONFIG_PERMISSIVE, | |
57c2590f TH |
45 | TOMOYO_CONFIG_ENFORCING, |
46 | TOMOYO_CONFIG_USE_DEFAULT = 255 | |
cb0abe6a TH |
47 | }; |
48 | ||
a230f9e7 TH |
49 | enum tomoyo_policy_id { |
50 | TOMOYO_ID_GROUP, | |
51 | TOMOYO_ID_PATH_GROUP, | |
52 | TOMOYO_ID_NUMBER_GROUP, | |
53 | TOMOYO_ID_DOMAIN_INITIALIZER, | |
54 | TOMOYO_ID_DOMAIN_KEEPER, | |
55 | TOMOYO_ID_AGGREGATOR, | |
56 | TOMOYO_ID_ALIAS, | |
57 | TOMOYO_ID_GLOBALLY_READABLE, | |
58 | TOMOYO_ID_PATTERN, | |
59 | TOMOYO_ID_NO_REWRITE, | |
60 | TOMOYO_ID_MANAGER, | |
61 | TOMOYO_ID_NAME, | |
62 | TOMOYO_ID_ACL, | |
63 | TOMOYO_ID_DOMAIN, | |
64 | TOMOYO_MAX_POLICY | |
65 | }; | |
66 | ||
67 | enum tomoyo_group_id { | |
68 | TOMOYO_PATH_GROUP, | |
69 | TOMOYO_NUMBER_GROUP, | |
70 | TOMOYO_MAX_GROUP | |
71 | }; | |
72 | ||
76bb0895 | 73 | /* Keywords for ACLs. */ |
1084307c | 74 | #define TOMOYO_KEYWORD_AGGREGATOR "aggregator " |
76bb0895 | 75 | #define TOMOYO_KEYWORD_ALIAS "alias " |
2106ccd9 | 76 | #define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount " |
76bb0895 TH |
77 | #define TOMOYO_KEYWORD_ALLOW_READ "allow_read " |
78 | #define TOMOYO_KEYWORD_DELETE "delete " | |
79 | #define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite " | |
80 | #define TOMOYO_KEYWORD_FILE_PATTERN "file_pattern " | |
81 | #define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain " | |
82 | #define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain " | |
83 | #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain " | |
84 | #define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain " | |
7762fbff | 85 | #define TOMOYO_KEYWORD_PATH_GROUP "path_group " |
4c3e9e2d | 86 | #define TOMOYO_KEYWORD_NUMBER_GROUP "number_group " |
76bb0895 TH |
87 | #define TOMOYO_KEYWORD_SELECT "select " |
88 | #define TOMOYO_KEYWORD_USE_PROFILE "use_profile " | |
89 | #define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read" | |
9b244373 TH |
90 | #define TOMOYO_KEYWORD_QUOTA_EXCEEDED "quota_exceeded" |
91 | #define TOMOYO_KEYWORD_TRANSITION_FAILED "transition_failed" | |
76bb0895 TH |
92 | /* A domain definition starts with <kernel>. */ |
93 | #define TOMOYO_ROOT_NAME "<kernel>" | |
94 | #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1) | |
95 | ||
4c3e9e2d TH |
96 | /* Value type definition. */ |
97 | #define TOMOYO_VALUE_TYPE_INVALID 0 | |
98 | #define TOMOYO_VALUE_TYPE_DECIMAL 1 | |
99 | #define TOMOYO_VALUE_TYPE_OCTAL 2 | |
100 | #define TOMOYO_VALUE_TYPE_HEXADECIMAL 3 | |
101 | ||
76bb0895 | 102 | /* Index numbers for Access Controls. */ |
084da356 | 103 | enum tomoyo_acl_entry_type_index { |
7ef61233 TH |
104 | TOMOYO_TYPE_PATH_ACL, |
105 | TOMOYO_TYPE_PATH2_ACL, | |
a1f9bb6a | 106 | TOMOYO_TYPE_PATH_NUMBER_ACL, |
75093152 | 107 | TOMOYO_TYPE_MKDEV_ACL, |
2106ccd9 | 108 | TOMOYO_TYPE_MOUNT_ACL, |
084da356 | 109 | }; |
76bb0895 TH |
110 | |
111 | /* Index numbers for File Controls. */ | |
112 | ||
113 | /* | |
a1f9bb6a TH |
114 | * TOMOYO_TYPE_READ_WRITE is special. TOMOYO_TYPE_READ_WRITE is automatically |
115 | * set if both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are set. | |
116 | * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically set if | |
117 | * TOMOYO_TYPE_READ_WRITE is set. | |
118 | * TOMOYO_TYPE_READ_WRITE is automatically cleared if either TOMOYO_TYPE_READ | |
119 | * or TOMOYO_TYPE_WRITE is cleared. | |
120 | * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically cleared if | |
121 | * TOMOYO_TYPE_READ_WRITE is cleared. | |
76bb0895 TH |
122 | */ |
123 | ||
084da356 | 124 | enum tomoyo_path_acl_index { |
7ef61233 TH |
125 | TOMOYO_TYPE_READ_WRITE, |
126 | TOMOYO_TYPE_EXECUTE, | |
127 | TOMOYO_TYPE_READ, | |
128 | TOMOYO_TYPE_WRITE, | |
7ef61233 | 129 | TOMOYO_TYPE_UNLINK, |
7ef61233 | 130 | TOMOYO_TYPE_RMDIR, |
7ef61233 TH |
131 | TOMOYO_TYPE_TRUNCATE, |
132 | TOMOYO_TYPE_SYMLINK, | |
133 | TOMOYO_TYPE_REWRITE, | |
7ef61233 | 134 | TOMOYO_TYPE_CHROOT, |
7ef61233 TH |
135 | TOMOYO_TYPE_UMOUNT, |
136 | TOMOYO_MAX_PATH_OPERATION | |
084da356 TH |
137 | }; |
138 | ||
237ab459 TH |
139 | #define TOMOYO_RW_MASK ((1 << TOMOYO_TYPE_READ) | (1 << TOMOYO_TYPE_WRITE)) |
140 | ||
75093152 | 141 | enum tomoyo_mkdev_acl_index { |
a1f9bb6a TH |
142 | TOMOYO_TYPE_MKBLOCK, |
143 | TOMOYO_TYPE_MKCHAR, | |
75093152 | 144 | TOMOYO_MAX_MKDEV_OPERATION |
a1f9bb6a TH |
145 | }; |
146 | ||
084da356 | 147 | enum tomoyo_path2_acl_index { |
7ef61233 TH |
148 | TOMOYO_TYPE_LINK, |
149 | TOMOYO_TYPE_RENAME, | |
150 | TOMOYO_TYPE_PIVOT_ROOT, | |
151 | TOMOYO_MAX_PATH2_OPERATION | |
084da356 TH |
152 | }; |
153 | ||
a1f9bb6a TH |
154 | enum tomoyo_path_number_acl_index { |
155 | TOMOYO_TYPE_CREATE, | |
156 | TOMOYO_TYPE_MKDIR, | |
157 | TOMOYO_TYPE_MKFIFO, | |
158 | TOMOYO_TYPE_MKSOCK, | |
159 | TOMOYO_TYPE_IOCTL, | |
160 | TOMOYO_TYPE_CHMOD, | |
161 | TOMOYO_TYPE_CHOWN, | |
162 | TOMOYO_TYPE_CHGRP, | |
163 | TOMOYO_MAX_PATH_NUMBER_OPERATION | |
164 | }; | |
165 | ||
084da356 TH |
166 | enum tomoyo_securityfs_interface_index { |
167 | TOMOYO_DOMAINPOLICY, | |
168 | TOMOYO_EXCEPTIONPOLICY, | |
169 | TOMOYO_DOMAIN_STATUS, | |
170 | TOMOYO_PROCESS_STATUS, | |
171 | TOMOYO_MEMINFO, | |
172 | TOMOYO_SELFDOMAIN, | |
173 | TOMOYO_VERSION, | |
174 | TOMOYO_PROFILE, | |
17fcfbd9 | 175 | TOMOYO_QUERY, |
084da356 TH |
176 | TOMOYO_MANAGER |
177 | }; | |
9590837b | 178 | |
57c2590f TH |
179 | enum tomoyo_mac_index { |
180 | TOMOYO_MAC_FILE_EXECUTE, | |
181 | TOMOYO_MAC_FILE_OPEN, | |
182 | TOMOYO_MAC_FILE_CREATE, | |
183 | TOMOYO_MAC_FILE_UNLINK, | |
184 | TOMOYO_MAC_FILE_MKDIR, | |
185 | TOMOYO_MAC_FILE_RMDIR, | |
186 | TOMOYO_MAC_FILE_MKFIFO, | |
187 | TOMOYO_MAC_FILE_MKSOCK, | |
188 | TOMOYO_MAC_FILE_TRUNCATE, | |
189 | TOMOYO_MAC_FILE_SYMLINK, | |
190 | TOMOYO_MAC_FILE_REWRITE, | |
191 | TOMOYO_MAC_FILE_MKBLOCK, | |
192 | TOMOYO_MAC_FILE_MKCHAR, | |
193 | TOMOYO_MAC_FILE_LINK, | |
194 | TOMOYO_MAC_FILE_RENAME, | |
195 | TOMOYO_MAC_FILE_CHMOD, | |
196 | TOMOYO_MAC_FILE_CHOWN, | |
197 | TOMOYO_MAC_FILE_CHGRP, | |
198 | TOMOYO_MAC_FILE_IOCTL, | |
199 | TOMOYO_MAC_FILE_CHROOT, | |
200 | TOMOYO_MAC_FILE_MOUNT, | |
201 | TOMOYO_MAC_FILE_UMOUNT, | |
202 | TOMOYO_MAC_FILE_PIVOT_ROOT, | |
203 | TOMOYO_MAX_MAC_INDEX | |
204 | }; | |
205 | ||
206 | enum tomoyo_mac_category_index { | |
207 | TOMOYO_MAC_CATEGORY_FILE, | |
208 | TOMOYO_MAX_MAC_CATEGORY_INDEX | |
209 | }; | |
210 | ||
17fcfbd9 TH |
211 | #define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */ |
212 | ||
76bb0895 | 213 | /********** Structure definitions. **********/ |
9590837b | 214 | |
82e0f001 TH |
215 | /* |
216 | * tomoyo_acl_head is a structure which is used for holding elements not in | |
217 | * domain policy. | |
218 | * It has following fields. | |
219 | * | |
220 | * (1) "list" which is linked to tomoyo_policy_list[] . | |
221 | * (2) "is_deleted" is a bool which is true if marked as deleted, false | |
222 | * otherwise. | |
223 | */ | |
224 | struct tomoyo_acl_head { | |
225 | struct list_head list; | |
226 | bool is_deleted; | |
227 | } __packed; | |
228 | ||
cb0abe6a TH |
229 | /* |
230 | * tomoyo_request_info is a structure which is used for holding | |
231 | * | |
232 | * (1) Domain information of current process. | |
17fcfbd9 TH |
233 | * (2) How many retries are made for this request. |
234 | * (3) Profile number used for this request. | |
235 | * (4) Access control mode of the profile. | |
cb0abe6a TH |
236 | */ |
237 | struct tomoyo_request_info { | |
238 | struct tomoyo_domain_info *domain; | |
cf6e9a64 TH |
239 | /* For holding parameters. */ |
240 | union { | |
241 | struct { | |
242 | const struct tomoyo_path_info *filename; | |
243 | u8 operation; | |
244 | } path; | |
245 | struct { | |
246 | const struct tomoyo_path_info *filename1; | |
247 | const struct tomoyo_path_info *filename2; | |
248 | u8 operation; | |
249 | } path2; | |
250 | struct { | |
251 | const struct tomoyo_path_info *filename; | |
252 | unsigned int mode; | |
253 | unsigned int major; | |
254 | unsigned int minor; | |
255 | u8 operation; | |
256 | } mkdev; | |
257 | struct { | |
258 | const struct tomoyo_path_info *filename; | |
259 | unsigned long number; | |
260 | u8 operation; | |
261 | } path_number; | |
262 | struct { | |
263 | const struct tomoyo_path_info *type; | |
264 | const struct tomoyo_path_info *dir; | |
265 | const struct tomoyo_path_info *dev; | |
266 | unsigned long flags; | |
267 | int need_dev; | |
268 | } mount; | |
269 | } param; | |
270 | u8 param_type; | |
271 | bool granted; | |
17fcfbd9 TH |
272 | u8 retry; |
273 | u8 profile; | |
cb0abe6a | 274 | u8 mode; /* One of tomoyo_mode_index . */ |
57c2590f | 275 | u8 type; |
cb0abe6a TH |
276 | }; |
277 | ||
c3fa109a TH |
278 | /* |
279 | * tomoyo_path_info is a structure which is used for holding a string data | |
280 | * used by TOMOYO. | |
281 | * This structure has several fields for supporting pattern matching. | |
282 | * | |
283 | * (1) "name" is the '\0' terminated string data. | |
284 | * (2) "hash" is full_name_hash(name, strlen(name)). | |
285 | * This allows tomoyo_pathcmp() to compare by hash before actually compare | |
286 | * using strcmp(). | |
287 | * (3) "const_len" is the length of the initial segment of "name" which | |
288 | * consists entirely of non wildcard characters. In other words, the length | |
289 | * which we can compare two strings using strncmp(). | |
290 | * (4) "is_dir" is a bool which is true if "name" ends with "/", | |
291 | * false otherwise. | |
292 | * TOMOYO distinguishes directory and non-directory. A directory ends with | |
293 | * "/" and non-directory does not end with "/". | |
294 | * (5) "is_patterned" is a bool which is true if "name" contains wildcard | |
295 | * characters, false otherwise. This allows TOMOYO to use "hash" and | |
296 | * strcmp() for string comparison if "is_patterned" is false. | |
c3fa109a | 297 | */ |
9590837b KT |
298 | struct tomoyo_path_info { |
299 | const char *name; | |
300 | u32 hash; /* = full_name_hash(name, strlen(name)) */ | |
9590837b KT |
301 | u16 const_len; /* = tomoyo_const_part_length(name) */ |
302 | bool is_dir; /* = tomoyo_strendswith(name, "/") */ | |
303 | bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ | |
9590837b KT |
304 | }; |
305 | ||
306 | /* | |
76bb0895 TH |
307 | * tomoyo_name_entry is a structure which is used for linking |
308 | * "struct tomoyo_path_info" into tomoyo_name_list . | |
9590837b | 309 | */ |
76bb0895 TH |
310 | struct tomoyo_name_entry { |
311 | struct list_head list; | |
312 | atomic_t users; | |
313 | struct tomoyo_path_info entry; | |
314 | }; | |
9590837b | 315 | |
7762fbff TH |
316 | struct tomoyo_name_union { |
317 | const struct tomoyo_path_info *filename; | |
a98aa4de | 318 | struct tomoyo_group *group; |
7762fbff TH |
319 | u8 is_group; |
320 | }; | |
321 | ||
4c3e9e2d TH |
322 | struct tomoyo_number_union { |
323 | unsigned long values[2]; | |
a98aa4de | 324 | struct tomoyo_group *group; |
4c3e9e2d TH |
325 | u8 min_type; |
326 | u8 max_type; | |
327 | u8 is_group; | |
328 | }; | |
329 | ||
a98aa4de TH |
330 | /* Structure for "path_group"/"number_group" directive. */ |
331 | struct tomoyo_group { | |
4c3e9e2d TH |
332 | struct list_head list; |
333 | const struct tomoyo_path_info *group_name; | |
334 | struct list_head member_list; | |
335 | atomic_t users; | |
336 | }; | |
337 | ||
7762fbff | 338 | /* Structure for "path_group" directive. */ |
a98aa4de | 339 | struct tomoyo_path_group { |
82e0f001 | 340 | struct tomoyo_acl_head head; |
7762fbff TH |
341 | const struct tomoyo_path_info *member_name; |
342 | }; | |
343 | ||
4c3e9e2d | 344 | /* Structure for "number_group" directive. */ |
a98aa4de | 345 | struct tomoyo_number_group { |
82e0f001 | 346 | struct tomoyo_acl_head head; |
4c3e9e2d TH |
347 | struct tomoyo_number_union number; |
348 | }; | |
349 | ||
9590837b | 350 | /* |
c3fa109a TH |
351 | * tomoyo_acl_info is a structure which is used for holding |
352 | * | |
353 | * (1) "list" which is linked to the ->acl_info_list of | |
354 | * "struct tomoyo_domain_info" | |
237ab459 TH |
355 | * (2) "is_deleted" is a bool which is true if this domain is marked as |
356 | * "deleted", false otherwise. | |
357 | * (3) "type" which tells type of the entry. | |
9590837b KT |
358 | * |
359 | * Packing "struct tomoyo_acl_info" allows | |
237ab459 | 360 | * "struct tomoyo_path_acl" to embed "u16" and "struct tomoyo_path2_acl" |
75093152 | 361 | * "struct tomoyo_path_number_acl" "struct tomoyo_mkdev_acl" to embed |
237ab459 | 362 | * "u8" without enlarging their structure size. |
9590837b KT |
363 | */ |
364 | struct tomoyo_acl_info { | |
365 | struct list_head list; | |
237ab459 TH |
366 | bool is_deleted; |
367 | u8 type; /* = one of values in "enum tomoyo_acl_entry_type_index". */ | |
9590837b KT |
368 | } __packed; |
369 | ||
c3fa109a TH |
370 | /* |
371 | * tomoyo_domain_info is a structure which is used for holding permissions | |
372 | * (e.g. "allow_read /lib/libc-2.5.so") given to each domain. | |
373 | * It has following fields. | |
374 | * | |
375 | * (1) "list" which is linked to tomoyo_domain_list . | |
376 | * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info". | |
377 | * (3) "domainname" which holds the name of the domain. | |
378 | * (4) "profile" which remembers profile number assigned to this domain. | |
379 | * (5) "is_deleted" is a bool which is true if this domain is marked as | |
380 | * "deleted", false otherwise. | |
381 | * (6) "quota_warned" is a bool which is used for suppressing warning message | |
382 | * when learning mode learned too much entries. | |
ea13ddba TH |
383 | * (7) "ignore_global_allow_read" is a bool which is true if this domain |
384 | * should ignore "allow_read" directive in exception policy. | |
385 | * (8) "transition_failed" is a bool which is set to true when this domain was | |
386 | * unable to create a new domain at tomoyo_find_next_domain() because the | |
387 | * name of the domain to be created was too long or it could not allocate | |
388 | * memory. If set to true, more than one process continued execve() | |
389 | * without domain transition. | |
ec8e6a4e TH |
390 | * (9) "users" is an atomic_t that holds how many "struct cred"->security |
391 | * are referring this "struct tomoyo_domain_info". If is_deleted == true | |
392 | * and users == 0, this struct will be kfree()d upon next garbage | |
393 | * collection. | |
c3fa109a TH |
394 | * |
395 | * A domain's lifecycle is an analogy of files on / directory. | |
396 | * Multiple domains with the same domainname cannot be created (as with | |
397 | * creating files with the same filename fails with -EEXIST). | |
398 | * If a process reached a domain, that process can reside in that domain after | |
399 | * that domain is marked as "deleted" (as with a process can access an already | |
400 | * open()ed file after that file was unlink()ed). | |
401 | */ | |
9590837b KT |
402 | struct tomoyo_domain_info { |
403 | struct list_head list; | |
404 | struct list_head acl_info_list; | |
405 | /* Name of this domain. Never NULL. */ | |
406 | const struct tomoyo_path_info *domainname; | |
407 | u8 profile; /* Profile number to use. */ | |
a0558fc3 | 408 | bool is_deleted; /* Delete flag. */ |
9590837b | 409 | bool quota_warned; /* Quota warnning flag. */ |
ea13ddba TH |
410 | bool ignore_global_allow_read; /* Ignore "allow_read" flag. */ |
411 | bool transition_failed; /* Domain transition failed flag. */ | |
ec8e6a4e | 412 | atomic_t users; /* Number of referring credentials. */ |
9590837b KT |
413 | }; |
414 | ||
9590837b | 415 | /* |
7ef61233 | 416 | * tomoyo_path_acl is a structure which is used for holding an |
c3fa109a TH |
417 | * entry with one pathname operation (e.g. open(), mkdir()). |
418 | * It has following fields. | |
419 | * | |
420 | * (1) "head" which is a "struct tomoyo_acl_info". | |
421 | * (2) "perm" which is a bitmask of permitted operations. | |
7762fbff | 422 | * (3) "name" is the pathname. |
c3fa109a TH |
423 | * |
424 | * Directives held by this structure are "allow_read/write", "allow_execute", | |
a1f9bb6a | 425 | * "allow_read", "allow_write", "allow_unlink", "allow_rmdir", |
2106ccd9 TH |
426 | * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot" and |
427 | * "allow_unmount". | |
9590837b | 428 | */ |
7ef61233 TH |
429 | struct tomoyo_path_acl { |
430 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ | |
9590837b | 431 | u16 perm; |
7762fbff | 432 | struct tomoyo_name_union name; |
9590837b KT |
433 | }; |
434 | ||
a1f9bb6a TH |
435 | /* |
436 | * tomoyo_path_number_acl is a structure which is used for holding an | |
437 | * entry with one pathname and one number operation. | |
438 | * It has following fields. | |
439 | * | |
440 | * (1) "head" which is a "struct tomoyo_acl_info". | |
441 | * (2) "perm" which is a bitmask of permitted operations. | |
442 | * (3) "name" is the pathname. | |
443 | * (4) "number" is the numeric value. | |
444 | * | |
445 | * Directives held by this structure are "allow_create", "allow_mkdir", | |
446 | * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown" | |
447 | * and "allow_chgrp". | |
448 | * | |
449 | */ | |
450 | struct tomoyo_path_number_acl { | |
451 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ | |
452 | u8 perm; | |
453 | struct tomoyo_name_union name; | |
454 | struct tomoyo_number_union number; | |
455 | }; | |
456 | ||
457 | /* | |
75093152 | 458 | * tomoyo_mkdev_acl is a structure which is used for holding an |
a1f9bb6a TH |
459 | * entry with one pathname and three numbers operation. |
460 | * It has following fields. | |
461 | * | |
462 | * (1) "head" which is a "struct tomoyo_acl_info". | |
463 | * (2) "perm" which is a bitmask of permitted operations. | |
464 | * (3) "mode" is the create mode. | |
465 | * (4) "major" is the major number of device node. | |
466 | * (5) "minor" is the minor number of device node. | |
467 | * | |
468 | * Directives held by this structure are "allow_mkchar", "allow_mkblock". | |
469 | * | |
470 | */ | |
75093152 TH |
471 | struct tomoyo_mkdev_acl { |
472 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */ | |
a1f9bb6a TH |
473 | u8 perm; |
474 | struct tomoyo_name_union name; | |
475 | struct tomoyo_number_union mode; | |
476 | struct tomoyo_number_union major; | |
477 | struct tomoyo_number_union minor; | |
478 | }; | |
479 | ||
c3fa109a | 480 | /* |
7ef61233 | 481 | * tomoyo_path2_acl is a structure which is used for holding an |
937bf613 | 482 | * entry with two pathnames operation (i.e. link(), rename() and pivot_root()). |
c3fa109a TH |
483 | * It has following fields. |
484 | * | |
485 | * (1) "head" which is a "struct tomoyo_acl_info". | |
486 | * (2) "perm" which is a bitmask of permitted operations. | |
7762fbff TH |
487 | * (3) "name1" is the source/old pathname. |
488 | * (4) "name2" is the destination/new pathname. | |
c3fa109a | 489 | * |
937bf613 TH |
490 | * Directives held by this structure are "allow_rename", "allow_link" and |
491 | * "allow_pivot_root". | |
c3fa109a | 492 | */ |
7ef61233 TH |
493 | struct tomoyo_path2_acl { |
494 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ | |
9590837b | 495 | u8 perm; |
7762fbff TH |
496 | struct tomoyo_name_union name1; |
497 | struct tomoyo_name_union name2; | |
9590837b KT |
498 | }; |
499 | ||
2106ccd9 TH |
500 | /* |
501 | * tomoyo_mount_acl is a structure which is used for holding an | |
502 | * entry for mount operation. | |
503 | * It has following fields. | |
504 | * | |
505 | * (1) "head" which is a "struct tomoyo_acl_info". | |
237ab459 TH |
506 | * (2) "dev_name" is the device name. |
507 | * (3) "dir_name" is the mount point. | |
508 | * (4) "fs_type" is the filesystem type. | |
2106ccd9 TH |
509 | * (5) "flags" is the mount flags. |
510 | * | |
237ab459 | 511 | * Directive held by this structure is "allow_mount". |
2106ccd9 TH |
512 | */ |
513 | struct tomoyo_mount_acl { | |
514 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ | |
2106ccd9 TH |
515 | struct tomoyo_name_union dev_name; |
516 | struct tomoyo_name_union dir_name; | |
517 | struct tomoyo_name_union fs_type; | |
518 | struct tomoyo_number_union flags; | |
519 | }; | |
520 | ||
c3fa109a TH |
521 | /* |
522 | * tomoyo_io_buffer is a structure which is used for reading and modifying | |
523 | * configuration via /sys/kernel/security/tomoyo/ interface. | |
524 | * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as | |
525 | * cursors. | |
526 | * | |
527 | * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of | |
528 | * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info" | |
529 | * entry has a list of "struct tomoyo_acl_info", we need two cursors when | |
530 | * reading (one is for traversing tomoyo_domain_list and the other is for | |
531 | * traversing "struct tomoyo_acl_info"->acl_info_list ). | |
532 | * | |
533 | * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with | |
534 | * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the | |
535 | * domain with the domainname specified by the rest of that line (NULL is set | |
536 | * if seek failed). | |
537 | * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with | |
538 | * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that | |
539 | * line (->write_var1 is set to NULL if a domain was deleted). | |
540 | * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with | |
541 | * neither "select " nor "delete ", an entry or a domain specified by that line | |
542 | * is appended. | |
543 | */ | |
9590837b | 544 | struct tomoyo_io_buffer { |
8fbe71f0 | 545 | void (*read) (struct tomoyo_io_buffer *); |
9590837b | 546 | int (*write) (struct tomoyo_io_buffer *); |
17fcfbd9 | 547 | int (*poll) (struct file *file, poll_table *wait); |
9590837b KT |
548 | /* Exclusive lock for this structure. */ |
549 | struct mutex io_sem; | |
fdb8ebb7 TH |
550 | /* Index returned by tomoyo_read_lock(). */ |
551 | int reader_idx; | |
9590837b KT |
552 | /* The position currently reading from. */ |
553 | struct list_head *read_var1; | |
554 | /* Extra variables for reading. */ | |
555 | struct list_head *read_var2; | |
556 | /* The position currently writing to. */ | |
557 | struct tomoyo_domain_info *write_var1; | |
558 | /* The step for reading. */ | |
559 | int read_step; | |
560 | /* Buffer for reading. */ | |
561 | char *read_buf; | |
562 | /* EOF flag for reading. */ | |
563 | bool read_eof; | |
564 | /* Read domain ACL of specified PID? */ | |
565 | bool read_single_domain; | |
566 | /* Extra variable for reading. */ | |
567 | u8 read_bit; | |
568 | /* Bytes available for reading. */ | |
569 | int read_avail; | |
570 | /* Size of read buffer. */ | |
571 | int readbuf_size; | |
572 | /* Buffer for writing. */ | |
573 | char *write_buf; | |
574 | /* Bytes available for writing. */ | |
575 | int write_avail; | |
576 | /* Size of write buffer. */ | |
577 | int writebuf_size; | |
17fcfbd9 TH |
578 | /* Type of this interface. */ |
579 | u8 type; | |
9590837b KT |
580 | }; |
581 | ||
76bb0895 TH |
582 | /* |
583 | * tomoyo_globally_readable_file_entry is a structure which is used for holding | |
584 | * "allow_read" entries. | |
585 | * It has following fields. | |
586 | * | |
82e0f001 | 587 | * (1) "head" is "struct tomoyo_acl_head". |
76bb0895 | 588 | * (2) "filename" is a pathname which is allowed to open(O_RDONLY). |
76bb0895 TH |
589 | */ |
590 | struct tomoyo_globally_readable_file_entry { | |
82e0f001 | 591 | struct tomoyo_acl_head head; |
76bb0895 | 592 | const struct tomoyo_path_info *filename; |
76bb0895 TH |
593 | }; |
594 | ||
595 | /* | |
596 | * tomoyo_pattern_entry is a structure which is used for holding | |
a230f9e7 | 597 | * "file_pattern" entries. |
76bb0895 TH |
598 | * It has following fields. |
599 | * | |
82e0f001 | 600 | * (1) "head" is "struct tomoyo_acl_head". |
76bb0895 TH |
601 | * (2) "pattern" is a pathname pattern which is used for converting pathnames |
602 | * to pathname patterns during learning mode. | |
76bb0895 TH |
603 | */ |
604 | struct tomoyo_pattern_entry { | |
82e0f001 | 605 | struct tomoyo_acl_head head; |
76bb0895 | 606 | const struct tomoyo_path_info *pattern; |
76bb0895 TH |
607 | }; |
608 | ||
609 | /* | |
610 | * tomoyo_no_rewrite_entry is a structure which is used for holding | |
611 | * "deny_rewrite" entries. | |
612 | * It has following fields. | |
613 | * | |
82e0f001 | 614 | * (1) "head" is "struct tomoyo_acl_head". |
76bb0895 TH |
615 | * (2) "pattern" is a pathname which is by default not permitted to modify |
616 | * already existing content. | |
76bb0895 TH |
617 | */ |
618 | struct tomoyo_no_rewrite_entry { | |
82e0f001 | 619 | struct tomoyo_acl_head head; |
76bb0895 | 620 | const struct tomoyo_path_info *pattern; |
76bb0895 TH |
621 | }; |
622 | ||
623 | /* | |
624 | * tomoyo_domain_initializer_entry is a structure which is used for holding | |
625 | * "initialize_domain" and "no_initialize_domain" entries. | |
626 | * It has following fields. | |
627 | * | |
82e0f001 TH |
628 | * (1) "head" is "struct tomoyo_acl_head". |
629 | * (2) "is_not" is a bool which is true if "no_initialize_domain", false | |
76bb0895 | 630 | * otherwise. |
82e0f001 | 631 | * (3) "is_last_name" is a bool which is true if "domainname" is "the last |
76bb0895 | 632 | * component of a domainname", false otherwise. |
82e0f001 TH |
633 | * (4) "domainname" which is "a domainname" or "the last component of a |
634 | * domainname". This field is NULL if "from" clause is not specified. | |
635 | * (5) "program" which is a program's pathname. | |
76bb0895 TH |
636 | */ |
637 | struct tomoyo_domain_initializer_entry { | |
82e0f001 | 638 | struct tomoyo_acl_head head; |
76bb0895 TH |
639 | bool is_not; /* True if this entry is "no_initialize_domain". */ |
640 | /* True if the domainname is tomoyo_get_last_name(). */ | |
641 | bool is_last_name; | |
82e0f001 TH |
642 | const struct tomoyo_path_info *domainname; /* This may be NULL */ |
643 | const struct tomoyo_path_info *program; | |
76bb0895 TH |
644 | }; |
645 | ||
646 | /* | |
647 | * tomoyo_domain_keeper_entry is a structure which is used for holding | |
648 | * "keep_domain" and "no_keep_domain" entries. | |
649 | * It has following fields. | |
650 | * | |
82e0f001 TH |
651 | * (1) "head" is "struct tomoyo_acl_head". |
652 | * (2) "is_not" is a bool which is true if "no_initialize_domain", false | |
76bb0895 | 653 | * otherwise. |
82e0f001 | 654 | * (3) "is_last_name" is a bool which is true if "domainname" is "the last |
76bb0895 | 655 | * component of a domainname", false otherwise. |
82e0f001 TH |
656 | * (4) "domainname" which is "a domainname" or "the last component of a |
657 | * domainname". | |
658 | * (5) "program" which is a program's pathname. | |
659 | * This field is NULL if "from" clause is not specified. | |
76bb0895 TH |
660 | */ |
661 | struct tomoyo_domain_keeper_entry { | |
82e0f001 | 662 | struct tomoyo_acl_head head; |
76bb0895 TH |
663 | bool is_not; /* True if this entry is "no_keep_domain". */ |
664 | /* True if the domainname is tomoyo_get_last_name(). */ | |
665 | bool is_last_name; | |
82e0f001 TH |
666 | const struct tomoyo_path_info *domainname; |
667 | const struct tomoyo_path_info *program; /* This may be NULL */ | |
76bb0895 TH |
668 | }; |
669 | ||
1084307c TH |
670 | /* |
671 | * tomoyo_aggregator_entry is a structure which is used for holding | |
672 | * "aggregator" entries. | |
673 | * It has following fields. | |
674 | * | |
82e0f001 | 675 | * (1) "head" is "struct tomoyo_acl_head". |
1084307c TH |
676 | * (2) "original_name" which is originally requested name. |
677 | * (3) "aggregated_name" which is name to rewrite. | |
1084307c TH |
678 | */ |
679 | struct tomoyo_aggregator_entry { | |
82e0f001 | 680 | struct tomoyo_acl_head head; |
1084307c TH |
681 | const struct tomoyo_path_info *original_name; |
682 | const struct tomoyo_path_info *aggregated_name; | |
1084307c TH |
683 | }; |
684 | ||
76bb0895 TH |
685 | /* |
686 | * tomoyo_alias_entry is a structure which is used for holding "alias" entries. | |
687 | * It has following fields. | |
688 | * | |
82e0f001 | 689 | * (1) "head" is "struct tomoyo_acl_head". |
76bb0895 TH |
690 | * (2) "original_name" which is a dereferenced pathname. |
691 | * (3) "aliased_name" which is a symlink's pathname. | |
76bb0895 TH |
692 | */ |
693 | struct tomoyo_alias_entry { | |
82e0f001 | 694 | struct tomoyo_acl_head head; |
76bb0895 TH |
695 | const struct tomoyo_path_info *original_name; |
696 | const struct tomoyo_path_info *aliased_name; | |
76bb0895 TH |
697 | }; |
698 | ||
699 | /* | |
700 | * tomoyo_policy_manager_entry is a structure which is used for holding list of | |
701 | * domainnames or programs which are permitted to modify configuration via | |
702 | * /sys/kernel/security/tomoyo/ interface. | |
703 | * It has following fields. | |
704 | * | |
82e0f001 TH |
705 | * (1) "head" is "struct tomoyo_acl_head". |
706 | * (2) "is_domain" is a bool which is true if "manager" is a domainname, false | |
76bb0895 | 707 | * otherwise. |
82e0f001 | 708 | * (3) "manager" is a domainname or a program's pathname. |
76bb0895 TH |
709 | */ |
710 | struct tomoyo_policy_manager_entry { | |
82e0f001 TH |
711 | struct tomoyo_acl_head head; |
712 | bool is_domain; /* True if manager is a domainname. */ | |
76bb0895 TH |
713 | /* A path to program or a domainname. */ |
714 | const struct tomoyo_path_info *manager; | |
76bb0895 TH |
715 | }; |
716 | ||
57c2590f TH |
717 | struct tomoyo_preference { |
718 | unsigned int learning_max_entry; | |
719 | bool enforcing_verbose; | |
720 | bool learning_verbose; | |
721 | bool permissive_verbose; | |
722 | }; | |
723 | ||
724 | struct tomoyo_profile { | |
725 | const struct tomoyo_path_info *comment; | |
726 | struct tomoyo_preference *learning; | |
727 | struct tomoyo_preference *permissive; | |
728 | struct tomoyo_preference *enforcing; | |
729 | struct tomoyo_preference preference; | |
730 | u8 default_config; | |
731 | u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX]; | |
732 | }; | |
733 | ||
76bb0895 TH |
734 | /********** Function prototypes. **********/ |
735 | ||
17fcfbd9 TH |
736 | extern asmlinkage long sys_getpid(void); |
737 | extern asmlinkage long sys_getppid(void); | |
738 | ||
c3ef1500 TH |
739 | /* Check whether the given string starts with the given keyword. */ |
740 | bool tomoyo_str_starts(char **src, const char *find); | |
741 | /* Get tomoyo_realpath() of current process. */ | |
742 | const char *tomoyo_get_exe(void); | |
743 | /* Format string. */ | |
744 | void tomoyo_normalize_line(unsigned char *buffer); | |
745 | /* Print warning or error message on console. */ | |
746 | void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...) | |
747 | __attribute__ ((format(printf, 2, 3))); | |
748 | /* Check all profiles currently assigned to domains are defined. */ | |
749 | void tomoyo_check_profile(void); | |
750 | /* Open operation for /sys/kernel/security/tomoyo/ interface. */ | |
751 | int tomoyo_open_control(const u8 type, struct file *file); | |
752 | /* Close /sys/kernel/security/tomoyo/ interface. */ | |
753 | int tomoyo_close_control(struct file *file); | |
754 | /* Read operation for /sys/kernel/security/tomoyo/ interface. */ | |
755 | int tomoyo_read_control(struct file *file, char __user *buffer, | |
756 | const int buffer_len); | |
757 | /* Write operation for /sys/kernel/security/tomoyo/ interface. */ | |
758 | int tomoyo_write_control(struct file *file, const char __user *buffer, | |
759 | const int buffer_len); | |
760 | /* Check whether the domain has too many ACL entries to hold. */ | |
761 | bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); | |
762 | /* Print out of memory warning message. */ | |
763 | void tomoyo_warn_oom(const char *function); | |
7762fbff TH |
764 | /* Check whether the given name matches the given name_union. */ |
765 | bool tomoyo_compare_name_union(const struct tomoyo_path_info *name, | |
766 | const struct tomoyo_name_union *ptr); | |
2106ccd9 TH |
767 | /* Check whether the given number matches the given number_union. */ |
768 | bool tomoyo_compare_number_union(const unsigned long value, | |
769 | const struct tomoyo_number_union *ptr); | |
57c2590f | 770 | int tomoyo_get_mode(const u8 profile, const u8 index); |
9590837b KT |
771 | /* Transactional sprintf() for policy dump. */ |
772 | bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) | |
773 | __attribute__ ((format(printf, 2, 3))); | |
774 | /* Check whether the domainname is correct. */ | |
75093152 | 775 | bool tomoyo_correct_domain(const unsigned char *domainname); |
9590837b | 776 | /* Check whether the token is correct. */ |
75093152 TH |
777 | bool tomoyo_correct_path(const char *filename); |
778 | bool tomoyo_correct_word(const char *string); | |
9590837b | 779 | /* Check whether the token can be a domainname. */ |
75093152 | 780 | bool tomoyo_domain_def(const unsigned char *buffer); |
7762fbff TH |
781 | bool tomoyo_parse_name_union(const char *filename, |
782 | struct tomoyo_name_union *ptr); | |
783 | /* Check whether the given filename matches the given path_group. */ | |
784 | bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, | |
a98aa4de | 785 | const struct tomoyo_group *group); |
4c3e9e2d TH |
786 | /* Check whether the given value matches the given number_group. */ |
787 | bool tomoyo_number_matches_group(const unsigned long min, | |
788 | const unsigned long max, | |
a98aa4de | 789 | const struct tomoyo_group *group); |
9590837b KT |
790 | /* Check whether the given filename matches the given pattern. */ |
791 | bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, | |
792 | const struct tomoyo_path_info *pattern); | |
4c3e9e2d TH |
793 | |
794 | bool tomoyo_print_number_union(struct tomoyo_io_buffer *head, | |
795 | const struct tomoyo_number_union *ptr); | |
796 | bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num); | |
7762fbff TH |
797 | /* Tokenize a line. */ |
798 | bool tomoyo_tokenize(char *buffer, char *w[], size_t size); | |
9590837b KT |
799 | /* Write domain policy violation warning message to console? */ |
800 | bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); | |
9590837b KT |
801 | /* Get the last component of the given domainname. */ |
802 | const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain); | |
2106ccd9 TH |
803 | /* Fill "struct tomoyo_request_info". */ |
804 | int tomoyo_init_request_info(struct tomoyo_request_info *r, | |
57c2590f TH |
805 | struct tomoyo_domain_info *domain, |
806 | const u8 index); | |
2106ccd9 TH |
807 | /* Check permission for mount operation. */ |
808 | int tomoyo_mount_permission(char *dev_name, struct path *path, char *type, | |
809 | unsigned long flags, void *data_page); | |
1084307c TH |
810 | /* Create "aggregator" entry in exception policy. */ |
811 | int tomoyo_write_aggregator_policy(char *data, const bool is_delete); | |
9590837b KT |
812 | /* Create "alias" entry in exception policy. */ |
813 | int tomoyo_write_alias_policy(char *data, const bool is_delete); | |
814 | /* | |
815 | * Create "initialize_domain" and "no_initialize_domain" entry | |
816 | * in exception policy. | |
817 | */ | |
818 | int tomoyo_write_domain_initializer_policy(char *data, const bool is_not, | |
819 | const bool is_delete); | |
820 | /* Create "keep_domain" and "no_keep_domain" entry in exception policy. */ | |
821 | int tomoyo_write_domain_keeper_policy(char *data, const bool is_not, | |
822 | const bool is_delete); | |
823 | /* | |
824 | * Create "allow_read/write", "allow_execute", "allow_read", "allow_write", | |
825 | * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir", | |
826 | * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar", | |
827 | * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and | |
828 | * "allow_link" entry in domain policy. | |
829 | */ | |
830 | int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain, | |
831 | const bool is_delete); | |
832 | /* Create "allow_read" entry in exception policy. */ | |
833 | int tomoyo_write_globally_readable_policy(char *data, const bool is_delete); | |
2106ccd9 TH |
834 | /* Create "allow_mount" entry in domain policy. */ |
835 | int tomoyo_write_mount_policy(char *data, struct tomoyo_domain_info *domain, | |
836 | const bool is_delete); | |
9590837b KT |
837 | /* Create "deny_rewrite" entry in exception policy. */ |
838 | int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete); | |
839 | /* Create "file_pattern" entry in exception policy. */ | |
840 | int tomoyo_write_pattern_policy(char *data, const bool is_delete); | |
7762fbff TH |
841 | /* Create "path_group" entry in exception policy. */ |
842 | int tomoyo_write_path_group_policy(char *data, const bool is_delete); | |
17fcfbd9 TH |
843 | int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) |
844 | __attribute__ ((format(printf, 2, 3))); | |
4c3e9e2d TH |
845 | /* Create "number_group" entry in exception policy. */ |
846 | int tomoyo_write_number_group_policy(char *data, const bool is_delete); | |
9590837b KT |
847 | /* Find a domain by the given name. */ |
848 | struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); | |
849 | /* Find or create a domain by the given name. */ | |
850 | struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char * | |
851 | domainname, | |
852 | const u8 profile); | |
57c2590f | 853 | struct tomoyo_profile *tomoyo_profile(const u8 profile); |
7762fbff | 854 | /* Allocate memory for "struct tomoyo_path_group". */ |
a98aa4de TH |
855 | struct tomoyo_group *tomoyo_get_path_group(const char *group_name); |
856 | struct tomoyo_group *tomoyo_get_number_group(const char *group_name); | |
7762fbff | 857 | |
9590837b KT |
858 | /* Check mode for specified functionality. */ |
859 | unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, | |
860 | const u8 index); | |
9590837b KT |
861 | /* Fill in "struct tomoyo_path_info" members. */ |
862 | void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); | |
863 | /* Run policy loader when /sbin/init starts. */ | |
864 | void tomoyo_load_policy(const char *filename); | |
9590837b | 865 | |
4c3e9e2d TH |
866 | void tomoyo_put_number_union(struct tomoyo_number_union *ptr); |
867 | ||
76bb0895 | 868 | /* Convert binary string to ascii string. */ |
c8c57e84 | 869 | char *tomoyo_encode(const char *str); |
76bb0895 TH |
870 | |
871 | /* | |
872 | * Returns realpath(3) of the given pathname but ignores chroot'ed root. | |
873 | * These functions use kzalloc(), so the caller must call kfree() | |
874 | * if these functions didn't return NULL. | |
875 | */ | |
876 | char *tomoyo_realpath(const char *pathname); | |
877 | /* | |
878 | * Same with tomoyo_realpath() except that it doesn't follow the final symlink. | |
879 | */ | |
880 | char *tomoyo_realpath_nofollow(const char *pathname); | |
881 | /* Same with tomoyo_realpath() except that the pathname is already solved. */ | |
882 | char *tomoyo_realpath_from_path(struct path *path); | |
17fcfbd9 TH |
883 | /* Get patterned pathname. */ |
884 | const char *tomoyo_file_pattern(const struct tomoyo_path_info *filename); | |
76bb0895 TH |
885 | |
886 | /* Check memory quota. */ | |
887 | bool tomoyo_memory_ok(void *ptr); | |
9e4b50e9 | 888 | void *tomoyo_commit_ok(void *data, const unsigned int size); |
76bb0895 TH |
889 | |
890 | /* | |
891 | * Keep the given name on the RAM. | |
892 | * The RAM is shared, so NEVER try to modify or kfree() the returned name. | |
893 | */ | |
894 | const struct tomoyo_path_info *tomoyo_get_name(const char *name); | |
895 | ||
896 | /* Check for memory usage. */ | |
8fbe71f0 | 897 | void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head); |
76bb0895 TH |
898 | |
899 | /* Set memory quota. */ | |
900 | int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head); | |
901 | ||
c3ef1500 TH |
902 | /* Initialize mm related code. */ |
903 | void __init tomoyo_mm_init(void); | |
05336dee | 904 | int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, |
76bb0895 TH |
905 | const struct tomoyo_path_info *filename); |
906 | int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, | |
907 | struct path *path, const int flag); | |
a1f9bb6a TH |
908 | int tomoyo_path_number_perm(const u8 operation, struct path *path, |
909 | unsigned long number); | |
75093152 TH |
910 | int tomoyo_mkdev_perm(const u8 operation, struct path *path, |
911 | const unsigned int mode, unsigned int dev); | |
97d6931e TH |
912 | int tomoyo_path_perm(const u8 operation, struct path *path); |
913 | int tomoyo_path2_perm(const u8 operation, struct path *path1, | |
914 | struct path *path2); | |
76bb0895 TH |
915 | int tomoyo_find_next_domain(struct linux_binprm *bprm); |
916 | ||
a1f9bb6a TH |
917 | void tomoyo_print_ulong(char *buffer, const int buffer_len, |
918 | const unsigned long value, const u8 type); | |
919 | ||
7762fbff TH |
920 | /* Drop refcount on tomoyo_name_union. */ |
921 | void tomoyo_put_name_union(struct tomoyo_name_union *ptr); | |
922 | ||
847b173e TH |
923 | /* Run garbage collector. */ |
924 | void tomoyo_run_gc(void); | |
925 | ||
926 | void tomoyo_memory_free(void *ptr); | |
927 | ||
237ab459 TH |
928 | int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size, |
929 | bool is_delete, struct tomoyo_domain_info *domain, | |
930 | bool (*check_duplicate) (const struct tomoyo_acl_info | |
931 | *, | |
932 | const struct tomoyo_acl_info | |
933 | *), | |
934 | bool (*merge_duplicate) (struct tomoyo_acl_info *, | |
935 | struct tomoyo_acl_info *, | |
936 | const bool)); | |
36f5e1ff TH |
937 | int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size, |
938 | bool is_delete, struct list_head *list, | |
939 | bool (*check_duplicate) (const struct tomoyo_acl_head | |
940 | *, | |
941 | const struct tomoyo_acl_head | |
942 | *)); | |
99a85259 TH |
943 | void tomoyo_check_acl(struct tomoyo_request_info *r, |
944 | bool (*check_entry) (const struct tomoyo_request_info *, | |
945 | const struct tomoyo_acl_info *)); | |
237ab459 | 946 | |
76bb0895 TH |
947 | /********** External variable definitions. **********/ |
948 | ||
949 | /* Lock for GC. */ | |
950 | extern struct srcu_struct tomoyo_ss; | |
951 | ||
952 | /* The list for "struct tomoyo_domain_info". */ | |
953 | extern struct list_head tomoyo_domain_list; | |
954 | ||
a230f9e7 TH |
955 | extern struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY]; |
956 | extern struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP]; | |
847b173e | 957 | extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; |
847b173e | 958 | |
76bb0895 TH |
959 | /* Lock for protecting policy. */ |
960 | extern struct mutex tomoyo_policy_lock; | |
961 | ||
962 | /* Has /sbin/init started? */ | |
963 | extern bool tomoyo_policy_loaded; | |
964 | ||
965 | /* The kernel's domain. */ | |
966 | extern struct tomoyo_domain_info tomoyo_kernel_domain; | |
967 | ||
71c28236 TH |
968 | extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION]; |
969 | extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION]; | |
970 | extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION]; | |
971 | extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION]; | |
972 | ||
17fcfbd9 TH |
973 | extern unsigned int tomoyo_quota_for_query; |
974 | extern unsigned int tomoyo_query_memory_size; | |
975 | ||
76bb0895 TH |
976 | /********** Inlined functions. **********/ |
977 | ||
978 | static inline int tomoyo_read_lock(void) | |
979 | { | |
980 | return srcu_read_lock(&tomoyo_ss); | |
981 | } | |
982 | ||
983 | static inline void tomoyo_read_unlock(int idx) | |
984 | { | |
985 | srcu_read_unlock(&tomoyo_ss, idx); | |
986 | } | |
987 | ||
9590837b KT |
988 | /* strcmp() for "struct tomoyo_path_info" structure. */ |
989 | static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, | |
990 | const struct tomoyo_path_info *b) | |
991 | { | |
992 | return a->hash != b->hash || strcmp(a->name, b->name); | |
993 | } | |
994 | ||
9590837b | 995 | /** |
75093152 | 996 | * tomoyo_valid - Check whether the character is a valid char. |
9590837b KT |
997 | * |
998 | * @c: The character to check. | |
999 | * | |
1000 | * Returns true if @c is a valid character, false otherwise. | |
1001 | */ | |
75093152 | 1002 | static inline bool tomoyo_valid(const unsigned char c) |
9590837b KT |
1003 | { |
1004 | return c > ' ' && c < 127; | |
1005 | } | |
1006 | ||
1007 | /** | |
75093152 | 1008 | * tomoyo_invalid - Check whether the character is an invalid char. |
9590837b KT |
1009 | * |
1010 | * @c: The character to check. | |
1011 | * | |
1012 | * Returns true if @c is an invalid character, false otherwise. | |
1013 | */ | |
75093152 | 1014 | static inline bool tomoyo_invalid(const unsigned char c) |
9590837b KT |
1015 | { |
1016 | return c && (c <= ' ' || c >= 127); | |
1017 | } | |
1018 | ||
76bb0895 TH |
1019 | static inline void tomoyo_put_name(const struct tomoyo_path_info *name) |
1020 | { | |
1021 | if (name) { | |
1022 | struct tomoyo_name_entry *ptr = | |
1023 | container_of(name, struct tomoyo_name_entry, entry); | |
1024 | atomic_dec(&ptr->users); | |
1025 | } | |
1026 | } | |
9590837b | 1027 | |
a98aa4de | 1028 | static inline void tomoyo_put_group(struct tomoyo_group *group) |
4c3e9e2d TH |
1029 | { |
1030 | if (group) | |
1031 | atomic_dec(&group->users); | |
1032 | } | |
1033 | ||
76bb0895 TH |
1034 | static inline struct tomoyo_domain_info *tomoyo_domain(void) |
1035 | { | |
1036 | return current_cred()->security; | |
1037 | } | |
9590837b | 1038 | |
76bb0895 TH |
1039 | static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct |
1040 | *task) | |
1041 | { | |
1042 | return task_cred_xxx(task, security); | |
1043 | } | |
9590837b | 1044 | |
75093152 | 1045 | static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info *p1, |
7762fbff TH |
1046 | const struct tomoyo_acl_info *p2) |
1047 | { | |
1048 | return p1->type == p2->type; | |
1049 | } | |
1050 | ||
75093152 | 1051 | static inline bool tomoyo_same_name_union |
7762fbff TH |
1052 | (const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2) |
1053 | { | |
1054 | return p1->filename == p2->filename && p1->group == p2->group && | |
1055 | p1->is_group == p2->is_group; | |
1056 | } | |
1057 | ||
75093152 | 1058 | static inline bool tomoyo_same_number_union |
4c3e9e2d TH |
1059 | (const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2) |
1060 | { | |
1061 | return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1] | |
1062 | && p1->group == p2->group && p1->min_type == p2->min_type && | |
1063 | p1->max_type == p2->max_type && p1->is_group == p2->is_group; | |
1064 | } | |
1065 | ||
9590837b KT |
1066 | /** |
1067 | * list_for_each_cookie - iterate over a list with cookie. | |
1068 | * @pos: the &struct list_head to use as a loop cursor. | |
1069 | * @cookie: the &struct list_head to use as a cookie. | |
1070 | * @head: the head for your list. | |
1071 | * | |
fdb8ebb7 | 1072 | * Same with list_for_each_rcu() except that this primitive uses @cookie |
9590837b KT |
1073 | * so that we can continue iteration. |
1074 | * @cookie must be NULL when iteration starts, and @cookie will become | |
1075 | * NULL when iteration finishes. | |
1076 | */ | |
fdb8ebb7 TH |
1077 | #define list_for_each_cookie(pos, cookie, head) \ |
1078 | for (({ if (!cookie) \ | |
1079 | cookie = head; }), \ | |
1080 | pos = rcu_dereference((cookie)->next); \ | |
1081 | prefetch(pos->next), pos != (head) || ((cookie) = NULL); \ | |
1082 | (cookie) = pos, pos = rcu_dereference(pos->next)) | |
1083 | ||
9590837b | 1084 | #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ |