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 | ||
b5bc60b4 | 41 | /* Index numbers for operation mode. */ |
cb0abe6a TH |
42 | enum tomoyo_mode_index { |
43 | TOMOYO_CONFIG_DISABLED, | |
44 | TOMOYO_CONFIG_LEARNING, | |
45 | TOMOYO_CONFIG_PERMISSIVE, | |
57c2590f TH |
46 | TOMOYO_CONFIG_ENFORCING, |
47 | TOMOYO_CONFIG_USE_DEFAULT = 255 | |
cb0abe6a TH |
48 | }; |
49 | ||
b5bc60b4 | 50 | /* Index numbers for entry type. */ |
a230f9e7 TH |
51 | enum tomoyo_policy_id { |
52 | TOMOYO_ID_GROUP, | |
53 | TOMOYO_ID_PATH_GROUP, | |
54 | TOMOYO_ID_NUMBER_GROUP, | |
5448ec4f | 55 | TOMOYO_ID_TRANSITION_CONTROL, |
a230f9e7 | 56 | TOMOYO_ID_AGGREGATOR, |
a230f9e7 TH |
57 | TOMOYO_ID_MANAGER, |
58 | TOMOYO_ID_NAME, | |
59 | TOMOYO_ID_ACL, | |
60 | TOMOYO_ID_DOMAIN, | |
61 | TOMOYO_MAX_POLICY | |
62 | }; | |
63 | ||
b5bc60b4 | 64 | /* Index numbers for group entries. */ |
a230f9e7 TH |
65 | enum tomoyo_group_id { |
66 | TOMOYO_PATH_GROUP, | |
67 | TOMOYO_NUMBER_GROUP, | |
68 | TOMOYO_MAX_GROUP | |
69 | }; | |
70 | ||
76bb0895 TH |
71 | /* A domain definition starts with <kernel>. */ |
72 | #define TOMOYO_ROOT_NAME "<kernel>" | |
73 | #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1) | |
74 | ||
b5bc60b4 TH |
75 | /* Index numbers for type of numeric values. */ |
76 | enum tomoyo_value_type { | |
77 | TOMOYO_VALUE_TYPE_INVALID, | |
78 | TOMOYO_VALUE_TYPE_DECIMAL, | |
79 | TOMOYO_VALUE_TYPE_OCTAL, | |
80 | TOMOYO_VALUE_TYPE_HEXADECIMAL, | |
81 | }; | |
4c3e9e2d | 82 | |
b5bc60b4 | 83 | /* Index numbers for domain transition control keywords. */ |
5448ec4f TH |
84 | enum tomoyo_transition_type { |
85 | /* Do not change this order, */ | |
86 | TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE, | |
87 | TOMOYO_TRANSITION_CONTROL_INITIALIZE, | |
88 | TOMOYO_TRANSITION_CONTROL_NO_KEEP, | |
89 | TOMOYO_TRANSITION_CONTROL_KEEP, | |
90 | TOMOYO_MAX_TRANSITION_TYPE | |
91 | }; | |
92 | ||
76bb0895 | 93 | /* Index numbers for Access Controls. */ |
084da356 | 94 | enum tomoyo_acl_entry_type_index { |
7ef61233 TH |
95 | TOMOYO_TYPE_PATH_ACL, |
96 | TOMOYO_TYPE_PATH2_ACL, | |
a1f9bb6a | 97 | TOMOYO_TYPE_PATH_NUMBER_ACL, |
75093152 | 98 | TOMOYO_TYPE_MKDEV_ACL, |
2106ccd9 | 99 | TOMOYO_TYPE_MOUNT_ACL, |
084da356 | 100 | }; |
76bb0895 | 101 | |
b5bc60b4 | 102 | /* Index numbers for access controls with one pathname. */ |
084da356 | 103 | enum tomoyo_path_acl_index { |
7ef61233 TH |
104 | TOMOYO_TYPE_EXECUTE, |
105 | TOMOYO_TYPE_READ, | |
106 | TOMOYO_TYPE_WRITE, | |
7c75964f | 107 | TOMOYO_TYPE_APPEND, |
7ef61233 | 108 | TOMOYO_TYPE_UNLINK, |
7c75964f | 109 | TOMOYO_TYPE_GETATTR, |
7ef61233 | 110 | TOMOYO_TYPE_RMDIR, |
7ef61233 TH |
111 | TOMOYO_TYPE_TRUNCATE, |
112 | TOMOYO_TYPE_SYMLINK, | |
7ef61233 | 113 | TOMOYO_TYPE_CHROOT, |
7ef61233 TH |
114 | TOMOYO_TYPE_UMOUNT, |
115 | TOMOYO_MAX_PATH_OPERATION | |
084da356 TH |
116 | }; |
117 | ||
75093152 | 118 | enum tomoyo_mkdev_acl_index { |
a1f9bb6a TH |
119 | TOMOYO_TYPE_MKBLOCK, |
120 | TOMOYO_TYPE_MKCHAR, | |
75093152 | 121 | TOMOYO_MAX_MKDEV_OPERATION |
a1f9bb6a TH |
122 | }; |
123 | ||
b5bc60b4 | 124 | /* Index numbers for access controls with two pathnames. */ |
084da356 | 125 | enum tomoyo_path2_acl_index { |
7ef61233 TH |
126 | TOMOYO_TYPE_LINK, |
127 | TOMOYO_TYPE_RENAME, | |
128 | TOMOYO_TYPE_PIVOT_ROOT, | |
129 | TOMOYO_MAX_PATH2_OPERATION | |
084da356 TH |
130 | }; |
131 | ||
b5bc60b4 | 132 | /* Index numbers for access controls with one pathname and one number. */ |
a1f9bb6a TH |
133 | enum tomoyo_path_number_acl_index { |
134 | TOMOYO_TYPE_CREATE, | |
135 | TOMOYO_TYPE_MKDIR, | |
136 | TOMOYO_TYPE_MKFIFO, | |
137 | TOMOYO_TYPE_MKSOCK, | |
138 | TOMOYO_TYPE_IOCTL, | |
139 | TOMOYO_TYPE_CHMOD, | |
140 | TOMOYO_TYPE_CHOWN, | |
141 | TOMOYO_TYPE_CHGRP, | |
142 | TOMOYO_MAX_PATH_NUMBER_OPERATION | |
143 | }; | |
144 | ||
b5bc60b4 | 145 | /* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */ |
084da356 TH |
146 | enum tomoyo_securityfs_interface_index { |
147 | TOMOYO_DOMAINPOLICY, | |
148 | TOMOYO_EXCEPTIONPOLICY, | |
149 | TOMOYO_DOMAIN_STATUS, | |
150 | TOMOYO_PROCESS_STATUS, | |
151 | TOMOYO_MEMINFO, | |
152 | TOMOYO_SELFDOMAIN, | |
153 | TOMOYO_VERSION, | |
154 | TOMOYO_PROFILE, | |
17fcfbd9 | 155 | TOMOYO_QUERY, |
084da356 TH |
156 | TOMOYO_MANAGER |
157 | }; | |
9590837b | 158 | |
b5bc60b4 TH |
159 | /* Index numbers for special mount operations. */ |
160 | enum tomoyo_special_mount { | |
161 | TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */ | |
162 | TOMOYO_MOUNT_MOVE, /* mount --move /old /new */ | |
163 | TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */ | |
164 | TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */ | |
165 | TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */ | |
166 | TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */ | |
167 | TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */ | |
168 | TOMOYO_MAX_SPECIAL_MOUNT | |
169 | }; | |
170 | ||
171 | /* Index numbers for functionality. */ | |
57c2590f TH |
172 | enum tomoyo_mac_index { |
173 | TOMOYO_MAC_FILE_EXECUTE, | |
174 | TOMOYO_MAC_FILE_OPEN, | |
175 | TOMOYO_MAC_FILE_CREATE, | |
176 | TOMOYO_MAC_FILE_UNLINK, | |
7c75964f | 177 | TOMOYO_MAC_FILE_GETATTR, |
57c2590f TH |
178 | TOMOYO_MAC_FILE_MKDIR, |
179 | TOMOYO_MAC_FILE_RMDIR, | |
180 | TOMOYO_MAC_FILE_MKFIFO, | |
181 | TOMOYO_MAC_FILE_MKSOCK, | |
182 | TOMOYO_MAC_FILE_TRUNCATE, | |
183 | TOMOYO_MAC_FILE_SYMLINK, | |
57c2590f TH |
184 | TOMOYO_MAC_FILE_MKBLOCK, |
185 | TOMOYO_MAC_FILE_MKCHAR, | |
186 | TOMOYO_MAC_FILE_LINK, | |
187 | TOMOYO_MAC_FILE_RENAME, | |
188 | TOMOYO_MAC_FILE_CHMOD, | |
189 | TOMOYO_MAC_FILE_CHOWN, | |
190 | TOMOYO_MAC_FILE_CHGRP, | |
191 | TOMOYO_MAC_FILE_IOCTL, | |
192 | TOMOYO_MAC_FILE_CHROOT, | |
193 | TOMOYO_MAC_FILE_MOUNT, | |
194 | TOMOYO_MAC_FILE_UMOUNT, | |
195 | TOMOYO_MAC_FILE_PIVOT_ROOT, | |
196 | TOMOYO_MAX_MAC_INDEX | |
197 | }; | |
198 | ||
b5bc60b4 | 199 | /* Index numbers for category of functionality. */ |
57c2590f TH |
200 | enum tomoyo_mac_category_index { |
201 | TOMOYO_MAC_CATEGORY_FILE, | |
202 | TOMOYO_MAX_MAC_CATEGORY_INDEX | |
203 | }; | |
204 | ||
82e0f001 | 205 | /* |
b5bc60b4 TH |
206 | * Retry this request. Returned by tomoyo_supervisor() if policy violation has |
207 | * occurred in enforcing mode and the userspace daemon decided to retry. | |
82e0f001 | 208 | * |
b5bc60b4 TH |
209 | * We must choose a positive value in order to distinguish "granted" (which is |
210 | * 0) and "rejected" (which is a negative value) and "retry". | |
82e0f001 | 211 | */ |
b5bc60b4 TH |
212 | #define TOMOYO_RETRY_REQUEST 1 |
213 | ||
214 | /********** Structure definitions. **********/ | |
215 | ||
216 | /* Common header for holding ACL entries. */ | |
82e0f001 TH |
217 | struct tomoyo_acl_head { |
218 | struct list_head list; | |
219 | bool is_deleted; | |
220 | } __packed; | |
221 | ||
0df7e8b8 TH |
222 | /* Common header for shared entries. */ |
223 | struct tomoyo_shared_acl_head { | |
224 | struct list_head list; | |
225 | atomic_t users; | |
226 | } __packed; | |
227 | ||
b5bc60b4 | 228 | /* Structure for request info. */ |
cb0abe6a TH |
229 | struct tomoyo_request_info { |
230 | struct tomoyo_domain_info *domain; | |
cf6e9a64 TH |
231 | /* For holding parameters. */ |
232 | union { | |
233 | struct { | |
234 | const struct tomoyo_path_info *filename; | |
484ca79c TH |
235 | /* For using wildcards at tomoyo_find_next_domain(). */ |
236 | const struct tomoyo_path_info *matched_path; | |
b5bc60b4 | 237 | /* One of values in "enum tomoyo_path_acl_index". */ |
cf6e9a64 TH |
238 | u8 operation; |
239 | } path; | |
240 | struct { | |
241 | const struct tomoyo_path_info *filename1; | |
242 | const struct tomoyo_path_info *filename2; | |
b5bc60b4 | 243 | /* One of values in "enum tomoyo_path2_acl_index". */ |
cf6e9a64 TH |
244 | u8 operation; |
245 | } path2; | |
246 | struct { | |
247 | const struct tomoyo_path_info *filename; | |
248 | unsigned int mode; | |
249 | unsigned int major; | |
250 | unsigned int minor; | |
b5bc60b4 | 251 | /* One of values in "enum tomoyo_mkdev_acl_index". */ |
cf6e9a64 TH |
252 | u8 operation; |
253 | } mkdev; | |
254 | struct { | |
255 | const struct tomoyo_path_info *filename; | |
256 | unsigned long number; | |
b5bc60b4 TH |
257 | /* |
258 | * One of values in | |
259 | * "enum tomoyo_path_number_acl_index". | |
260 | */ | |
cf6e9a64 TH |
261 | u8 operation; |
262 | } path_number; | |
263 | struct { | |
264 | const struct tomoyo_path_info *type; | |
265 | const struct tomoyo_path_info *dir; | |
266 | const struct tomoyo_path_info *dev; | |
267 | unsigned long flags; | |
268 | int need_dev; | |
269 | } mount; | |
270 | } param; | |
271 | u8 param_type; | |
272 | bool granted; | |
17fcfbd9 TH |
273 | u8 retry; |
274 | u8 profile; | |
cb0abe6a | 275 | u8 mode; /* One of tomoyo_mode_index . */ |
57c2590f | 276 | u8 type; |
cb0abe6a TH |
277 | }; |
278 | ||
b5bc60b4 | 279 | /* Structure for holding a token. */ |
9590837b KT |
280 | struct tomoyo_path_info { |
281 | const char *name; | |
282 | u32 hash; /* = full_name_hash(name, strlen(name)) */ | |
9590837b KT |
283 | u16 const_len; /* = tomoyo_const_part_length(name) */ |
284 | bool is_dir; /* = tomoyo_strendswith(name, "/") */ | |
285 | bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ | |
9590837b KT |
286 | }; |
287 | ||
b5bc60b4 | 288 | /* Structure for holding string data. */ |
e2bf6907 | 289 | struct tomoyo_name { |
0df7e8b8 | 290 | struct tomoyo_shared_acl_head head; |
76bb0895 TH |
291 | struct tomoyo_path_info entry; |
292 | }; | |
9590837b | 293 | |
b5bc60b4 | 294 | /* Structure for holding a word. */ |
7762fbff | 295 | struct tomoyo_name_union { |
b5bc60b4 | 296 | /* Either @filename or @group is NULL. */ |
7762fbff | 297 | const struct tomoyo_path_info *filename; |
a98aa4de | 298 | struct tomoyo_group *group; |
7762fbff TH |
299 | }; |
300 | ||
b5bc60b4 | 301 | /* Structure for holding a number. */ |
4c3e9e2d TH |
302 | struct tomoyo_number_union { |
303 | unsigned long values[2]; | |
b5bc60b4 TH |
304 | struct tomoyo_group *group; /* Maybe NULL. */ |
305 | /* One of values in "enum tomoyo_value_type". */ | |
0df7e8b8 | 306 | u8 value_type[2]; |
4c3e9e2d TH |
307 | }; |
308 | ||
a98aa4de TH |
309 | /* Structure for "path_group"/"number_group" directive. */ |
310 | struct tomoyo_group { | |
0df7e8b8 | 311 | struct tomoyo_shared_acl_head head; |
4c3e9e2d TH |
312 | const struct tomoyo_path_info *group_name; |
313 | struct list_head member_list; | |
4c3e9e2d TH |
314 | }; |
315 | ||
7762fbff | 316 | /* Structure for "path_group" directive. */ |
a98aa4de | 317 | struct tomoyo_path_group { |
82e0f001 | 318 | struct tomoyo_acl_head head; |
7762fbff TH |
319 | const struct tomoyo_path_info *member_name; |
320 | }; | |
321 | ||
4c3e9e2d | 322 | /* Structure for "number_group" directive. */ |
a98aa4de | 323 | struct tomoyo_number_group { |
82e0f001 | 324 | struct tomoyo_acl_head head; |
4c3e9e2d TH |
325 | struct tomoyo_number_union number; |
326 | }; | |
327 | ||
b5bc60b4 | 328 | /* Common header for individual entries. */ |
9590837b KT |
329 | struct tomoyo_acl_info { |
330 | struct list_head list; | |
237ab459 | 331 | bool is_deleted; |
b5bc60b4 | 332 | u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */ |
9590837b KT |
333 | } __packed; |
334 | ||
b5bc60b4 | 335 | /* Structure for domain information. */ |
9590837b KT |
336 | struct tomoyo_domain_info { |
337 | struct list_head list; | |
338 | struct list_head acl_info_list; | |
339 | /* Name of this domain. Never NULL. */ | |
340 | const struct tomoyo_path_info *domainname; | |
341 | u8 profile; /* Profile number to use. */ | |
a0558fc3 | 342 | bool is_deleted; /* Delete flag. */ |
9590837b | 343 | bool quota_warned; /* Quota warnning flag. */ |
ea13ddba | 344 | bool transition_failed; /* Domain transition failed flag. */ |
ec8e6a4e | 345 | atomic_t users; /* Number of referring credentials. */ |
9590837b KT |
346 | }; |
347 | ||
9590837b | 348 | /* |
b5bc60b4 TH |
349 | * Structure for "file execute", "file read", "file write", "file append", |
350 | * "file unlink", "file getattr", "file rmdir", "file truncate", | |
351 | * "file symlink", "file chroot" and "file unmount" directive. | |
9590837b | 352 | */ |
7ef61233 TH |
353 | struct tomoyo_path_acl { |
354 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ | |
b5bc60b4 | 355 | u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */ |
7762fbff | 356 | struct tomoyo_name_union name; |
9590837b KT |
357 | }; |
358 | ||
a1f9bb6a | 359 | /* |
b5bc60b4 TH |
360 | * Structure for "file create", "file mkdir", "file mkfifo", "file mksock", |
361 | * "file ioctl", "file chmod", "file chown" and "file chgrp" directive. | |
a1f9bb6a TH |
362 | */ |
363 | struct tomoyo_path_number_acl { | |
364 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ | |
b5bc60b4 | 365 | /* Bitmask of values in "enum tomoyo_path_number_acl_index". */ |
a1f9bb6a TH |
366 | u8 perm; |
367 | struct tomoyo_name_union name; | |
368 | struct tomoyo_number_union number; | |
369 | }; | |
370 | ||
b5bc60b4 | 371 | /* Structure for "file mkblock" and "file mkchar" directive. */ |
75093152 TH |
372 | struct tomoyo_mkdev_acl { |
373 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */ | |
b5bc60b4 | 374 | u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */ |
a1f9bb6a TH |
375 | struct tomoyo_name_union name; |
376 | struct tomoyo_number_union mode; | |
377 | struct tomoyo_number_union major; | |
378 | struct tomoyo_number_union minor; | |
379 | }; | |
380 | ||
c3fa109a | 381 | /* |
b5bc60b4 | 382 | * Structure for "file rename", "file link" and "file pivot_root" directive. |
c3fa109a | 383 | */ |
7ef61233 TH |
384 | struct tomoyo_path2_acl { |
385 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ | |
b5bc60b4 | 386 | u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */ |
7762fbff TH |
387 | struct tomoyo_name_union name1; |
388 | struct tomoyo_name_union name2; | |
9590837b KT |
389 | }; |
390 | ||
b5bc60b4 | 391 | /* Structure for "file mount" directive. */ |
2106ccd9 TH |
392 | struct tomoyo_mount_acl { |
393 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ | |
2106ccd9 TH |
394 | struct tomoyo_name_union dev_name; |
395 | struct tomoyo_name_union dir_name; | |
396 | struct tomoyo_name_union fs_type; | |
397 | struct tomoyo_number_union flags; | |
398 | }; | |
399 | ||
a238cf5b TH |
400 | /* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */ |
401 | struct tomoyo_acl_param { | |
402 | char *data; | |
403 | struct list_head *list; | |
404 | bool is_delete; | |
405 | }; | |
406 | ||
f23571e8 TH |
407 | #define TOMOYO_MAX_IO_READ_QUEUE 32 |
408 | ||
c3fa109a | 409 | /* |
f23571e8 TH |
410 | * Structure for reading/writing policy via /sys/kernel/security/tomoyo |
411 | * interfaces. | |
c3fa109a | 412 | */ |
9590837b | 413 | struct tomoyo_io_buffer { |
8fbe71f0 | 414 | void (*read) (struct tomoyo_io_buffer *); |
9590837b | 415 | int (*write) (struct tomoyo_io_buffer *); |
17fcfbd9 | 416 | int (*poll) (struct file *file, poll_table *wait); |
9590837b KT |
417 | /* Exclusive lock for this structure. */ |
418 | struct mutex io_sem; | |
fdb8ebb7 TH |
419 | /* Index returned by tomoyo_read_lock(). */ |
420 | int reader_idx; | |
f23571e8 TH |
421 | char __user *read_user_buf; |
422 | int read_user_buf_avail; | |
423 | struct { | |
424 | struct list_head *domain; | |
425 | struct list_head *group; | |
426 | struct list_head *acl; | |
427 | int avail; | |
428 | int step; | |
429 | int query_index; | |
430 | u16 index; | |
431 | u8 bit; | |
432 | u8 w_pos; | |
433 | bool eof; | |
434 | bool print_this_domain_only; | |
435 | bool print_execute_only; | |
436 | const char *w[TOMOYO_MAX_IO_READ_QUEUE]; | |
437 | } r; | |
0df7e8b8 TH |
438 | struct { |
439 | /* The position currently writing to. */ | |
440 | struct tomoyo_domain_info *domain; | |
441 | /* Bytes available for writing. */ | |
442 | int avail; | |
443 | } w; | |
9590837b KT |
444 | /* Buffer for reading. */ |
445 | char *read_buf; | |
9590837b KT |
446 | /* Size of read buffer. */ |
447 | int readbuf_size; | |
448 | /* Buffer for writing. */ | |
449 | char *write_buf; | |
9590837b KT |
450 | /* Size of write buffer. */ |
451 | int writebuf_size; | |
17fcfbd9 TH |
452 | /* Type of this interface. */ |
453 | u8 type; | |
9590837b KT |
454 | }; |
455 | ||
76bb0895 | 456 | /* |
b5bc60b4 TH |
457 | * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/ |
458 | * "no_keep_domain" keyword. | |
76bb0895 | 459 | */ |
5448ec4f | 460 | struct tomoyo_transition_control { |
82e0f001 | 461 | struct tomoyo_acl_head head; |
5448ec4f | 462 | u8 type; /* One of values in "enum tomoyo_transition_type". */ |
76bb0895 TH |
463 | /* True if the domainname is tomoyo_get_last_name(). */ |
464 | bool is_last_name; | |
5448ec4f TH |
465 | const struct tomoyo_path_info *domainname; /* Maybe NULL */ |
466 | const struct tomoyo_path_info *program; /* Maybe NULL */ | |
76bb0895 TH |
467 | }; |
468 | ||
b5bc60b4 | 469 | /* Structure for "aggregator" keyword. */ |
e2bf6907 | 470 | struct tomoyo_aggregator { |
82e0f001 | 471 | struct tomoyo_acl_head head; |
1084307c TH |
472 | const struct tomoyo_path_info *original_name; |
473 | const struct tomoyo_path_info *aggregated_name; | |
1084307c TH |
474 | }; |
475 | ||
b5bc60b4 | 476 | /* Structure for policy manager. */ |
e2bf6907 | 477 | struct tomoyo_manager { |
82e0f001 TH |
478 | struct tomoyo_acl_head head; |
479 | bool is_domain; /* True if manager is a domainname. */ | |
76bb0895 TH |
480 | /* A path to program or a domainname. */ |
481 | const struct tomoyo_path_info *manager; | |
76bb0895 TH |
482 | }; |
483 | ||
57c2590f TH |
484 | struct tomoyo_preference { |
485 | unsigned int learning_max_entry; | |
486 | bool enforcing_verbose; | |
487 | bool learning_verbose; | |
488 | bool permissive_verbose; | |
489 | }; | |
490 | ||
b5bc60b4 | 491 | /* Structure for /sys/kernel/security/tomnoyo/profile interface. */ |
57c2590f TH |
492 | struct tomoyo_profile { |
493 | const struct tomoyo_path_info *comment; | |
494 | struct tomoyo_preference *learning; | |
495 | struct tomoyo_preference *permissive; | |
496 | struct tomoyo_preference *enforcing; | |
497 | struct tomoyo_preference preference; | |
498 | u8 default_config; | |
499 | u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX]; | |
500 | }; | |
501 | ||
76bb0895 TH |
502 | /********** Function prototypes. **********/ |
503 | ||
c3ef1500 | 504 | bool tomoyo_str_starts(char **src, const char *find); |
c3ef1500 | 505 | const char *tomoyo_get_exe(void); |
c3ef1500 | 506 | void tomoyo_normalize_line(unsigned char *buffer); |
c3ef1500 TH |
507 | void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...) |
508 | __attribute__ ((format(printf, 2, 3))); | |
c3ef1500 | 509 | void tomoyo_check_profile(void); |
c3ef1500 | 510 | int tomoyo_open_control(const u8 type, struct file *file); |
0df7e8b8 | 511 | int tomoyo_close_control(struct tomoyo_io_buffer *head); |
0849e3ba | 512 | int tomoyo_poll_control(struct file *file, poll_table *wait); |
0df7e8b8 | 513 | int tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer, |
c3ef1500 | 514 | const int buffer_len); |
0df7e8b8 TH |
515 | int tomoyo_write_control(struct tomoyo_io_buffer *head, |
516 | const char __user *buffer, const int buffer_len); | |
c3ef1500 | 517 | bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); |
c3ef1500 | 518 | void tomoyo_warn_oom(const char *function); |
484ca79c TH |
519 | const struct tomoyo_path_info * |
520 | tomoyo_compare_name_union(const struct tomoyo_path_info *name, | |
521 | const struct tomoyo_name_union *ptr); | |
2106ccd9 TH |
522 | bool tomoyo_compare_number_union(const unsigned long value, |
523 | const struct tomoyo_number_union *ptr); | |
57c2590f | 524 | int tomoyo_get_mode(const u8 profile, const u8 index); |
f23571e8 | 525 | void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) |
9590837b | 526 | __attribute__ ((format(printf, 2, 3))); |
75093152 | 527 | bool tomoyo_correct_domain(const unsigned char *domainname); |
75093152 TH |
528 | bool tomoyo_correct_path(const char *filename); |
529 | bool tomoyo_correct_word(const char *string); | |
75093152 | 530 | bool tomoyo_domain_def(const unsigned char *buffer); |
a238cf5b | 531 | bool tomoyo_parse_name_union(struct tomoyo_acl_param *param, |
7762fbff | 532 | struct tomoyo_name_union *ptr); |
484ca79c TH |
533 | const struct tomoyo_path_info * |
534 | tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, | |
535 | const struct tomoyo_group *group); | |
4c3e9e2d TH |
536 | bool tomoyo_number_matches_group(const unsigned long min, |
537 | const unsigned long max, | |
a98aa4de | 538 | const struct tomoyo_group *group); |
9590837b KT |
539 | bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, |
540 | const struct tomoyo_path_info *pattern); | |
a238cf5b TH |
541 | bool tomoyo_parse_number_union(struct tomoyo_acl_param *param, |
542 | struct tomoyo_number_union *ptr); | |
7762fbff | 543 | bool tomoyo_tokenize(char *buffer, char *w[], size_t size); |
9590837b | 544 | bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); |
2106ccd9 | 545 | int tomoyo_init_request_info(struct tomoyo_request_info *r, |
57c2590f TH |
546 | struct tomoyo_domain_info *domain, |
547 | const u8 index); | |
b5bc60b4 TH |
548 | int tomoyo_mount_permission(char *dev_name, struct path *path, |
549 | const char *type, unsigned long flags, | |
550 | void *data_page); | |
a238cf5b TH |
551 | int tomoyo_write_aggregator(struct tomoyo_acl_param *param); |
552 | int tomoyo_write_transition_control(struct tomoyo_acl_param *param, | |
5448ec4f | 553 | const u8 type); |
a238cf5b TH |
554 | int tomoyo_write_file(struct tomoyo_acl_param *param); |
555 | int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type); | |
17fcfbd9 TH |
556 | int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) |
557 | __attribute__ ((format(printf, 2, 3))); | |
9590837b | 558 | struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); |
e2bf6907 TH |
559 | struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname, |
560 | const u8 profile); | |
57c2590f | 561 | struct tomoyo_profile *tomoyo_profile(const u8 profile); |
a238cf5b TH |
562 | struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param, |
563 | const u8 idx); | |
9590837b KT |
564 | unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, |
565 | const u8 index); | |
9590837b | 566 | void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); |
9590837b | 567 | void tomoyo_load_policy(const char *filename); |
4c3e9e2d | 568 | void tomoyo_put_number_union(struct tomoyo_number_union *ptr); |
c8c57e84 | 569 | char *tomoyo_encode(const char *str); |
0617c7ff | 570 | char *tomoyo_realpath_nofollow(const char *pathname); |
76bb0895 | 571 | char *tomoyo_realpath_from_path(struct path *path); |
76bb0895 | 572 | bool tomoyo_memory_ok(void *ptr); |
9e4b50e9 | 573 | void *tomoyo_commit_ok(void *data, const unsigned int size); |
76bb0895 | 574 | const struct tomoyo_path_info *tomoyo_get_name(const char *name); |
8fbe71f0 | 575 | void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head); |
76bb0895 | 576 | int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head); |
c3ef1500 | 577 | void __init tomoyo_mm_init(void); |
05336dee | 578 | int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, |
76bb0895 TH |
579 | const struct tomoyo_path_info *filename); |
580 | int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, | |
581 | struct path *path, const int flag); | |
a1f9bb6a TH |
582 | int tomoyo_path_number_perm(const u8 operation, struct path *path, |
583 | unsigned long number); | |
75093152 TH |
584 | int tomoyo_mkdev_perm(const u8 operation, struct path *path, |
585 | const unsigned int mode, unsigned int dev); | |
97d6931e TH |
586 | int tomoyo_path_perm(const u8 operation, struct path *path); |
587 | int tomoyo_path2_perm(const u8 operation, struct path *path1, | |
588 | struct path *path2); | |
76bb0895 | 589 | int tomoyo_find_next_domain(struct linux_binprm *bprm); |
a1f9bb6a TH |
590 | void tomoyo_print_ulong(char *buffer, const int buffer_len, |
591 | const unsigned long value, const u8 type); | |
7762fbff | 592 | void tomoyo_put_name_union(struct tomoyo_name_union *ptr); |
847b173e | 593 | void tomoyo_run_gc(void); |
847b173e | 594 | void tomoyo_memory_free(void *ptr); |
237ab459 | 595 | int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size, |
a238cf5b | 596 | struct tomoyo_acl_param *param, |
237ab459 TH |
597 | bool (*check_duplicate) (const struct tomoyo_acl_info |
598 | *, | |
599 | const struct tomoyo_acl_info | |
600 | *), | |
601 | bool (*merge_duplicate) (struct tomoyo_acl_info *, | |
602 | struct tomoyo_acl_info *, | |
603 | const bool)); | |
36f5e1ff | 604 | int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size, |
a238cf5b | 605 | struct tomoyo_acl_param *param, |
36f5e1ff TH |
606 | bool (*check_duplicate) (const struct tomoyo_acl_head |
607 | *, | |
608 | const struct tomoyo_acl_head | |
609 | *)); | |
99a85259 | 610 | void tomoyo_check_acl(struct tomoyo_request_info *r, |
484ca79c | 611 | bool (*check_entry) (struct tomoyo_request_info *, |
99a85259 | 612 | const struct tomoyo_acl_info *)); |
a238cf5b TH |
613 | char *tomoyo_read_token(struct tomoyo_acl_param *param); |
614 | bool tomoyo_permstr(const char *string, const char *keyword); | |
237ab459 | 615 | |
76bb0895 TH |
616 | /********** External variable definitions. **********/ |
617 | ||
618 | /* Lock for GC. */ | |
619 | extern struct srcu_struct tomoyo_ss; | |
620 | ||
621 | /* The list for "struct tomoyo_domain_info". */ | |
622 | extern struct list_head tomoyo_domain_list; | |
623 | ||
a230f9e7 TH |
624 | extern struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY]; |
625 | extern struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP]; | |
847b173e | 626 | extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; |
847b173e | 627 | |
76bb0895 TH |
628 | /* Lock for protecting policy. */ |
629 | extern struct mutex tomoyo_policy_lock; | |
630 | ||
631 | /* Has /sbin/init started? */ | |
632 | extern bool tomoyo_policy_loaded; | |
633 | ||
634 | /* The kernel's domain. */ | |
635 | extern struct tomoyo_domain_info tomoyo_kernel_domain; | |
636 | ||
71c28236 TH |
637 | extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION]; |
638 | extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION]; | |
639 | extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION]; | |
640 | extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION]; | |
641 | ||
17fcfbd9 TH |
642 | extern unsigned int tomoyo_quota_for_query; |
643 | extern unsigned int tomoyo_query_memory_size; | |
644 | ||
76bb0895 TH |
645 | /********** Inlined functions. **********/ |
646 | ||
b5bc60b4 TH |
647 | /** |
648 | * tomoyo_read_lock - Take lock for protecting policy. | |
649 | * | |
650 | * Returns index number for tomoyo_read_unlock(). | |
651 | */ | |
76bb0895 TH |
652 | static inline int tomoyo_read_lock(void) |
653 | { | |
654 | return srcu_read_lock(&tomoyo_ss); | |
655 | } | |
656 | ||
b5bc60b4 TH |
657 | /** |
658 | * tomoyo_read_unlock - Release lock for protecting policy. | |
659 | * | |
660 | * @idx: Index number returned by tomoyo_read_lock(). | |
661 | * | |
662 | * Returns nothing. | |
663 | */ | |
76bb0895 TH |
664 | static inline void tomoyo_read_unlock(int idx) |
665 | { | |
666 | srcu_read_unlock(&tomoyo_ss, idx); | |
667 | } | |
668 | ||
b5bc60b4 TH |
669 | /** |
670 | * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure. | |
671 | * | |
672 | * @a: Pointer to "struct tomoyo_path_info". | |
673 | * @b: Pointer to "struct tomoyo_path_info". | |
674 | * | |
675 | * Returns true if @a == @b, false otherwise. | |
676 | */ | |
9590837b KT |
677 | static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, |
678 | const struct tomoyo_path_info *b) | |
679 | { | |
680 | return a->hash != b->hash || strcmp(a->name, b->name); | |
681 | } | |
682 | ||
b5bc60b4 TH |
683 | /** |
684 | * tomoyo_put_name - Drop reference on "struct tomoyo_name". | |
685 | * | |
686 | * @name: Pointer to "struct tomoyo_path_info". Maybe NULL. | |
687 | * | |
688 | * Returns nothing. | |
689 | */ | |
76bb0895 TH |
690 | static inline void tomoyo_put_name(const struct tomoyo_path_info *name) |
691 | { | |
692 | if (name) { | |
e2bf6907 TH |
693 | struct tomoyo_name *ptr = |
694 | container_of(name, typeof(*ptr), entry); | |
0df7e8b8 | 695 | atomic_dec(&ptr->head.users); |
76bb0895 TH |
696 | } |
697 | } | |
9590837b | 698 | |
b5bc60b4 TH |
699 | /** |
700 | * tomoyo_put_group - Drop reference on "struct tomoyo_group". | |
701 | * | |
702 | * @group: Pointer to "struct tomoyo_group". Maybe NULL. | |
703 | * | |
704 | * Returns nothing. | |
705 | */ | |
a98aa4de | 706 | static inline void tomoyo_put_group(struct tomoyo_group *group) |
4c3e9e2d TH |
707 | { |
708 | if (group) | |
0df7e8b8 | 709 | atomic_dec(&group->head.users); |
4c3e9e2d TH |
710 | } |
711 | ||
b5bc60b4 TH |
712 | /** |
713 | * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread. | |
714 | * | |
715 | * Returns pointer to "struct tomoyo_domain_info" for current thread. | |
716 | */ | |
76bb0895 TH |
717 | static inline struct tomoyo_domain_info *tomoyo_domain(void) |
718 | { | |
719 | return current_cred()->security; | |
720 | } | |
9590837b | 721 | |
b5bc60b4 TH |
722 | /** |
723 | * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread. | |
724 | * | |
725 | * @task: Pointer to "struct task_struct". | |
726 | * | |
727 | * Returns pointer to "struct tomoyo_security" for specified thread. | |
728 | */ | |
76bb0895 TH |
729 | static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct |
730 | *task) | |
731 | { | |
732 | return task_cred_xxx(task, security); | |
733 | } | |
9590837b | 734 | |
b5bc60b4 TH |
735 | /** |
736 | * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry. | |
737 | * | |
738 | * @a: Pointer to "struct tomoyo_name_union". | |
739 | * @b: Pointer to "struct tomoyo_name_union". | |
740 | * | |
741 | * Returns true if @a == @b, false otherwise. | |
742 | */ | |
75093152 | 743 | static inline bool tomoyo_same_name_union |
b5bc60b4 | 744 | (const struct tomoyo_name_union *a, const struct tomoyo_name_union *b) |
7762fbff | 745 | { |
0df7e8b8 | 746 | return a->filename == b->filename && a->group == b->group; |
7762fbff TH |
747 | } |
748 | ||
b5bc60b4 TH |
749 | /** |
750 | * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry. | |
751 | * | |
752 | * @a: Pointer to "struct tomoyo_number_union". | |
753 | * @b: Pointer to "struct tomoyo_number_union". | |
754 | * | |
755 | * Returns true if @a == @b, false otherwise. | |
756 | */ | |
75093152 | 757 | static inline bool tomoyo_same_number_union |
b5bc60b4 | 758 | (const struct tomoyo_number_union *a, const struct tomoyo_number_union *b) |
4c3e9e2d | 759 | { |
b5bc60b4 | 760 | return a->values[0] == b->values[0] && a->values[1] == b->values[1] && |
0df7e8b8 TH |
761 | a->group == b->group && a->value_type[0] == b->value_type[0] && |
762 | a->value_type[1] == b->value_type[1]; | |
4c3e9e2d TH |
763 | } |
764 | ||
9590837b KT |
765 | /** |
766 | * list_for_each_cookie - iterate over a list with cookie. | |
767 | * @pos: the &struct list_head to use as a loop cursor. | |
9590837b | 768 | * @head: the head for your list. |
9590837b | 769 | */ |
475e6fa3 TH |
770 | #define list_for_each_cookie(pos, head) \ |
771 | if (!pos) \ | |
772 | pos = srcu_dereference((head)->next, &tomoyo_ss); \ | |
773 | for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss)) | |
fdb8ebb7 | 774 | |
9590837b | 775 | #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ |