blob: 5a0fcedb332b7d8b1379667fd10b1d37f4d821a8 [file] [log] [blame]
Kentaro Takeda95908372009-02-05 17:18:13 +09001/*
2 * security/tomoyo/common.h
3 *
Tetsuo Handa76bb0892010-02-11 09:42:40 +09004 * Header file for TOMOYO.
Kentaro Takeda95908372009-02-05 17:18:13 +09005 *
Tetsuo Handa76bb0892010-02-11 09:42:40 +09006 * Copyright (C) 2005-2010 NTT DATA CORPORATION
Kentaro Takeda95908372009-02-05 17:18:13 +09007 */
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>
Tetsuo Handa76bb0892010-02-11 09:42:40 +090022#include <linux/cred.h>
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +090023#include <linux/poll.h>
Tetsuo Handa2066a362011-07-08 13:21:37 +090024#include <linux/binfmts.h>
25#include <linux/highmem.h>
Kentaro Takeda95908372009-02-05 17:18:13 +090026
Tetsuo Handa76bb0892010-02-11 09:42:40 +090027/********** Constants definitions. **********/
28
29/*
30 * TOMOYO uses this hash only when appending a string into the string
31 * table. Frequency of appending strings is very low. So we don't need
32 * large (e.g. 64k) hash size. 256 will be sufficient.
33 */
34#define TOMOYO_HASH_BITS 8
35#define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS)
36
Tetsuo Handac8c57e82010-06-03 20:36:43 +090037#define TOMOYO_EXEC_TMPSIZE 4096
Tetsuo Handa76bb0892010-02-11 09:42:40 +090038
39/* Profile number is an integer between 0 and 255. */
40#define TOMOYO_MAX_PROFILES 256
41
Tetsuo Handa32997142011-06-26 23:19:28 +090042/* Group number is an integer between 0 and 255. */
43#define TOMOYO_MAX_ACL_GROUPS 256
44
Tetsuo Handa2066a362011-07-08 13:21:37 +090045/* Index numbers for "struct tomoyo_condition". */
46enum tomoyo_conditions_index {
47 TOMOYO_TASK_UID, /* current_uid() */
48 TOMOYO_TASK_EUID, /* current_euid() */
49 TOMOYO_TASK_SUID, /* current_suid() */
50 TOMOYO_TASK_FSUID, /* current_fsuid() */
51 TOMOYO_TASK_GID, /* current_gid() */
52 TOMOYO_TASK_EGID, /* current_egid() */
53 TOMOYO_TASK_SGID, /* current_sgid() */
54 TOMOYO_TASK_FSGID, /* current_fsgid() */
55 TOMOYO_TASK_PID, /* sys_getpid() */
56 TOMOYO_TASK_PPID, /* sys_getppid() */
Tetsuo Handa8761afd2011-07-08 13:22:41 +090057 TOMOYO_TYPE_IS_SOCKET, /* S_IFSOCK */
58 TOMOYO_TYPE_IS_SYMLINK, /* S_IFLNK */
59 TOMOYO_TYPE_IS_FILE, /* S_IFREG */
60 TOMOYO_TYPE_IS_BLOCK_DEV, /* S_IFBLK */
61 TOMOYO_TYPE_IS_DIRECTORY, /* S_IFDIR */
62 TOMOYO_TYPE_IS_CHAR_DEV, /* S_IFCHR */
63 TOMOYO_TYPE_IS_FIFO, /* S_IFIFO */
64 TOMOYO_MODE_SETUID, /* S_ISUID */
65 TOMOYO_MODE_SETGID, /* S_ISGID */
66 TOMOYO_MODE_STICKY, /* S_ISVTX */
67 TOMOYO_MODE_OWNER_READ, /* S_IRUSR */
68 TOMOYO_MODE_OWNER_WRITE, /* S_IWUSR */
69 TOMOYO_MODE_OWNER_EXECUTE, /* S_IXUSR */
70 TOMOYO_MODE_GROUP_READ, /* S_IRGRP */
71 TOMOYO_MODE_GROUP_WRITE, /* S_IWGRP */
72 TOMOYO_MODE_GROUP_EXECUTE, /* S_IXGRP */
73 TOMOYO_MODE_OTHERS_READ, /* S_IROTH */
74 TOMOYO_MODE_OTHERS_WRITE, /* S_IWOTH */
75 TOMOYO_MODE_OTHERS_EXECUTE, /* S_IXOTH */
76 TOMOYO_PATH1_UID,
77 TOMOYO_PATH1_GID,
78 TOMOYO_PATH1_INO,
79 TOMOYO_PATH1_MAJOR,
80 TOMOYO_PATH1_MINOR,
81 TOMOYO_PATH1_PERM,
82 TOMOYO_PATH1_TYPE,
83 TOMOYO_PATH1_DEV_MAJOR,
84 TOMOYO_PATH1_DEV_MINOR,
85 TOMOYO_PATH2_UID,
86 TOMOYO_PATH2_GID,
87 TOMOYO_PATH2_INO,
88 TOMOYO_PATH2_MAJOR,
89 TOMOYO_PATH2_MINOR,
90 TOMOYO_PATH2_PERM,
91 TOMOYO_PATH2_TYPE,
92 TOMOYO_PATH2_DEV_MAJOR,
93 TOMOYO_PATH2_DEV_MINOR,
94 TOMOYO_PATH1_PARENT_UID,
95 TOMOYO_PATH1_PARENT_GID,
96 TOMOYO_PATH1_PARENT_INO,
97 TOMOYO_PATH1_PARENT_PERM,
98 TOMOYO_PATH2_PARENT_UID,
99 TOMOYO_PATH2_PARENT_GID,
100 TOMOYO_PATH2_PARENT_INO,
101 TOMOYO_PATH2_PARENT_PERM,
Tetsuo Handa2066a362011-07-08 13:21:37 +0900102 TOMOYO_MAX_CONDITION_KEYWORD,
103 TOMOYO_NUMBER_UNION,
104};
105
Tetsuo Handa8761afd2011-07-08 13:22:41 +0900106
107/* Index numbers for stat(). */
108enum tomoyo_path_stat_index {
109 /* Do not change this order. */
110 TOMOYO_PATH1,
111 TOMOYO_PATH1_PARENT,
112 TOMOYO_PATH2,
113 TOMOYO_PATH2_PARENT,
114 TOMOYO_MAX_PATH_STAT
115};
116
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900117/* Index numbers for operation mode. */
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900118enum tomoyo_mode_index {
119 TOMOYO_CONFIG_DISABLED,
120 TOMOYO_CONFIG_LEARNING,
121 TOMOYO_CONFIG_PERMISSIVE,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900122 TOMOYO_CONFIG_ENFORCING,
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900123 TOMOYO_CONFIG_MAX_MODE,
124 TOMOYO_CONFIG_WANT_REJECT_LOG = 64,
125 TOMOYO_CONFIG_WANT_GRANT_LOG = 128,
126 TOMOYO_CONFIG_USE_DEFAULT = 255,
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900127};
128
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900129/* Index numbers for entry type. */
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900130enum tomoyo_policy_id {
131 TOMOYO_ID_GROUP,
132 TOMOYO_ID_PATH_GROUP,
133 TOMOYO_ID_NUMBER_GROUP,
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900134 TOMOYO_ID_TRANSITION_CONTROL,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900135 TOMOYO_ID_AGGREGATOR,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900136 TOMOYO_ID_MANAGER,
Tetsuo Handa2066a362011-07-08 13:21:37 +0900137 TOMOYO_ID_CONDITION,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900138 TOMOYO_ID_NAME,
139 TOMOYO_ID_ACL,
140 TOMOYO_ID_DOMAIN,
141 TOMOYO_MAX_POLICY
142};
143
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900144/* Index numbers for domain's attributes. */
145enum tomoyo_domain_info_flags_index {
146 /* Quota warnning flag. */
147 TOMOYO_DIF_QUOTA_WARNED,
148 /*
149 * This domain was unable to create a new domain at
150 * tomoyo_find_next_domain() because the name of the domain to be
151 * created was too long or it could not allocate memory.
152 * More than one process continued execve() without domain transition.
153 */
154 TOMOYO_DIF_TRANSITION_FAILED,
155 TOMOYO_MAX_DOMAIN_INFO_FLAGS
156};
157
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900158/* Index numbers for group entries. */
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900159enum tomoyo_group_id {
160 TOMOYO_PATH_GROUP,
161 TOMOYO_NUMBER_GROUP,
162 TOMOYO_MAX_GROUP
163};
164
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900165/* Index numbers for type of numeric values. */
166enum tomoyo_value_type {
167 TOMOYO_VALUE_TYPE_INVALID,
168 TOMOYO_VALUE_TYPE_DECIMAL,
169 TOMOYO_VALUE_TYPE_OCTAL,
170 TOMOYO_VALUE_TYPE_HEXADECIMAL,
171};
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900172
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900173/* Index numbers for domain transition control keywords. */
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900174enum tomoyo_transition_type {
175 /* Do not change this order, */
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900176 TOMOYO_TRANSITION_CONTROL_NO_RESET,
177 TOMOYO_TRANSITION_CONTROL_RESET,
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900178 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE,
179 TOMOYO_TRANSITION_CONTROL_INITIALIZE,
180 TOMOYO_TRANSITION_CONTROL_NO_KEEP,
181 TOMOYO_TRANSITION_CONTROL_KEEP,
182 TOMOYO_MAX_TRANSITION_TYPE
183};
184
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900185/* Index numbers for Access Controls. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900186enum tomoyo_acl_entry_type_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900187 TOMOYO_TYPE_PATH_ACL,
188 TOMOYO_TYPE_PATH2_ACL,
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900189 TOMOYO_TYPE_PATH_NUMBER_ACL,
Tetsuo Handa75093152010-06-16 16:23:55 +0900190 TOMOYO_TYPE_MKDEV_ACL,
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900191 TOMOYO_TYPE_MOUNT_ACL,
Tetsuo Handa084da352010-02-15 15:10:39 +0900192};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900193
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900194/* Index numbers for access controls with one pathname. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900195enum tomoyo_path_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900196 TOMOYO_TYPE_EXECUTE,
197 TOMOYO_TYPE_READ,
198 TOMOYO_TYPE_WRITE,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900199 TOMOYO_TYPE_APPEND,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900200 TOMOYO_TYPE_UNLINK,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900201 TOMOYO_TYPE_GETATTR,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900202 TOMOYO_TYPE_RMDIR,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900203 TOMOYO_TYPE_TRUNCATE,
204 TOMOYO_TYPE_SYMLINK,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900205 TOMOYO_TYPE_CHROOT,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900206 TOMOYO_TYPE_UMOUNT,
207 TOMOYO_MAX_PATH_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900208};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900209
Tetsuo Handab22b8b92011-06-26 23:21:50 +0900210/* Index numbers for /sys/kernel/security/tomoyo/stat interface. */
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900211enum tomoyo_memory_stat_type {
212 TOMOYO_MEMORY_POLICY,
213 TOMOYO_MEMORY_AUDIT,
214 TOMOYO_MEMORY_QUERY,
215 TOMOYO_MAX_MEMORY_STAT
216};
217
Tetsuo Handa75093152010-06-16 16:23:55 +0900218enum tomoyo_mkdev_acl_index {
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900219 TOMOYO_TYPE_MKBLOCK,
220 TOMOYO_TYPE_MKCHAR,
Tetsuo Handa75093152010-06-16 16:23:55 +0900221 TOMOYO_MAX_MKDEV_OPERATION
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900222};
223
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900224/* Index numbers for access controls with two pathnames. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900225enum tomoyo_path2_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900226 TOMOYO_TYPE_LINK,
227 TOMOYO_TYPE_RENAME,
228 TOMOYO_TYPE_PIVOT_ROOT,
229 TOMOYO_MAX_PATH2_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900230};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900231
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900232/* Index numbers for access controls with one pathname and one number. */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900233enum tomoyo_path_number_acl_index {
234 TOMOYO_TYPE_CREATE,
235 TOMOYO_TYPE_MKDIR,
236 TOMOYO_TYPE_MKFIFO,
237 TOMOYO_TYPE_MKSOCK,
238 TOMOYO_TYPE_IOCTL,
239 TOMOYO_TYPE_CHMOD,
240 TOMOYO_TYPE_CHOWN,
241 TOMOYO_TYPE_CHGRP,
242 TOMOYO_MAX_PATH_NUMBER_OPERATION
243};
244
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900245/* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900246enum tomoyo_securityfs_interface_index {
247 TOMOYO_DOMAINPOLICY,
248 TOMOYO_EXCEPTIONPOLICY,
Tetsuo Handa084da352010-02-15 15:10:39 +0900249 TOMOYO_PROCESS_STATUS,
Tetsuo Handab22b8b92011-06-26 23:21:50 +0900250 TOMOYO_STAT,
Tetsuo Handa084da352010-02-15 15:10:39 +0900251 TOMOYO_SELFDOMAIN,
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900252 TOMOYO_AUDIT,
Tetsuo Handa084da352010-02-15 15:10:39 +0900253 TOMOYO_VERSION,
254 TOMOYO_PROFILE,
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900255 TOMOYO_QUERY,
Tetsuo Handa084da352010-02-15 15:10:39 +0900256 TOMOYO_MANAGER
257};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900258
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900259/* Index numbers for special mount operations. */
260enum tomoyo_special_mount {
261 TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */
262 TOMOYO_MOUNT_MOVE, /* mount --move /old /new */
263 TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */
264 TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */
265 TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */
266 TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */
267 TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */
268 TOMOYO_MAX_SPECIAL_MOUNT
269};
270
271/* Index numbers for functionality. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900272enum tomoyo_mac_index {
273 TOMOYO_MAC_FILE_EXECUTE,
274 TOMOYO_MAC_FILE_OPEN,
275 TOMOYO_MAC_FILE_CREATE,
276 TOMOYO_MAC_FILE_UNLINK,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900277 TOMOYO_MAC_FILE_GETATTR,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900278 TOMOYO_MAC_FILE_MKDIR,
279 TOMOYO_MAC_FILE_RMDIR,
280 TOMOYO_MAC_FILE_MKFIFO,
281 TOMOYO_MAC_FILE_MKSOCK,
282 TOMOYO_MAC_FILE_TRUNCATE,
283 TOMOYO_MAC_FILE_SYMLINK,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900284 TOMOYO_MAC_FILE_MKBLOCK,
285 TOMOYO_MAC_FILE_MKCHAR,
286 TOMOYO_MAC_FILE_LINK,
287 TOMOYO_MAC_FILE_RENAME,
288 TOMOYO_MAC_FILE_CHMOD,
289 TOMOYO_MAC_FILE_CHOWN,
290 TOMOYO_MAC_FILE_CHGRP,
291 TOMOYO_MAC_FILE_IOCTL,
292 TOMOYO_MAC_FILE_CHROOT,
293 TOMOYO_MAC_FILE_MOUNT,
294 TOMOYO_MAC_FILE_UMOUNT,
295 TOMOYO_MAC_FILE_PIVOT_ROOT,
296 TOMOYO_MAX_MAC_INDEX
297};
298
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900299/* Index numbers for category of functionality. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900300enum tomoyo_mac_category_index {
301 TOMOYO_MAC_CATEGORY_FILE,
302 TOMOYO_MAX_MAC_CATEGORY_INDEX
303};
304
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900305/*
306 * Retry this request. Returned by tomoyo_supervisor() if policy violation has
307 * occurred in enforcing mode and the userspace daemon decided to retry.
308 *
309 * We must choose a positive value in order to distinguish "granted" (which is
310 * 0) and "rejected" (which is a negative value) and "retry".
311 */
312#define TOMOYO_RETRY_REQUEST 1
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900313
Tetsuo Handab22b8b92011-06-26 23:21:50 +0900314/* Index numbers for /sys/kernel/security/tomoyo/stat interface. */
315enum tomoyo_policy_stat_type {
316 /* Do not change this order. */
317 TOMOYO_STAT_POLICY_UPDATES,
318 TOMOYO_STAT_POLICY_LEARNING, /* == TOMOYO_CONFIG_LEARNING */
319 TOMOYO_STAT_POLICY_PERMISSIVE, /* == TOMOYO_CONFIG_PERMISSIVE */
320 TOMOYO_STAT_POLICY_ENFORCING, /* == TOMOYO_CONFIG_ENFORCING */
321 TOMOYO_MAX_POLICY_STAT
322};
323
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900324/* Index numbers for profile's PREFERENCE values. */
325enum tomoyo_pref_index {
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900326 TOMOYO_PREF_MAX_AUDIT_LOG,
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900327 TOMOYO_PREF_MAX_LEARNING_ENTRY,
328 TOMOYO_MAX_PREF
329};
330
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900331/********** Structure definitions. **********/
Kentaro Takeda95908372009-02-05 17:18:13 +0900332
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900333/* Common header for holding ACL entries. */
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900334struct tomoyo_acl_head {
335 struct list_head list;
336 bool is_deleted;
337} __packed;
338
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900339/* Common header for shared entries. */
340struct tomoyo_shared_acl_head {
341 struct list_head list;
342 atomic_t users;
343} __packed;
344
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900345struct tomoyo_policy_namespace;
346
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900347/* Structure for request info. */
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900348struct tomoyo_request_info {
Tetsuo Handa8761afd2011-07-08 13:22:41 +0900349 /*
350 * For holding parameters specific to operations which deal files.
351 * NULL if not dealing files.
352 */
353 struct tomoyo_obj_info *obj;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900354 struct tomoyo_domain_info *domain;
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900355 /* For holding parameters. */
356 union {
357 struct {
358 const struct tomoyo_path_info *filename;
Tetsuo Handa484ca792010-07-29 14:29:55 +0900359 /* For using wildcards at tomoyo_find_next_domain(). */
360 const struct tomoyo_path_info *matched_path;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900361 /* One of values in "enum tomoyo_path_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900362 u8 operation;
363 } path;
364 struct {
365 const struct tomoyo_path_info *filename1;
366 const struct tomoyo_path_info *filename2;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900367 /* One of values in "enum tomoyo_path2_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900368 u8 operation;
369 } path2;
370 struct {
371 const struct tomoyo_path_info *filename;
372 unsigned int mode;
373 unsigned int major;
374 unsigned int minor;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900375 /* One of values in "enum tomoyo_mkdev_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900376 u8 operation;
377 } mkdev;
378 struct {
379 const struct tomoyo_path_info *filename;
380 unsigned long number;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900381 /*
382 * One of values in
383 * "enum tomoyo_path_number_acl_index".
384 */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900385 u8 operation;
386 } path_number;
387 struct {
388 const struct tomoyo_path_info *type;
389 const struct tomoyo_path_info *dir;
390 const struct tomoyo_path_info *dev;
391 unsigned long flags;
392 int need_dev;
393 } mount;
394 } param;
395 u8 param_type;
396 bool granted;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900397 u8 retry;
398 u8 profile;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900399 u8 mode; /* One of tomoyo_mode_index . */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900400 u8 type;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900401};
402
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900403/* Structure for holding a token. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900404struct tomoyo_path_info {
405 const char *name;
406 u32 hash; /* = full_name_hash(name, strlen(name)) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900407 u16 const_len; /* = tomoyo_const_part_length(name) */
408 bool is_dir; /* = tomoyo_strendswith(name, "/") */
409 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900410};
411
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900412/* Structure for holding string data. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900413struct tomoyo_name {
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900414 struct tomoyo_shared_acl_head head;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900415 struct tomoyo_path_info entry;
416};
Kentaro Takeda95908372009-02-05 17:18:13 +0900417
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900418/* Structure for holding a word. */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900419struct tomoyo_name_union {
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900420 /* Either @filename or @group is NULL. */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900421 const struct tomoyo_path_info *filename;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900422 struct tomoyo_group *group;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900423};
424
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900425/* Structure for holding a number. */
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900426struct tomoyo_number_union {
427 unsigned long values[2];
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900428 struct tomoyo_group *group; /* Maybe NULL. */
429 /* One of values in "enum tomoyo_value_type". */
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900430 u8 value_type[2];
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900431};
432
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900433/* Structure for "path_group"/"number_group" directive. */
434struct tomoyo_group {
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900435 struct tomoyo_shared_acl_head head;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900436 const struct tomoyo_path_info *group_name;
437 struct list_head member_list;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900438};
439
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900440/* Structure for "path_group" directive. */
441struct tomoyo_path_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900442 struct tomoyo_acl_head head;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900443 const struct tomoyo_path_info *member_name;
444};
445
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900446/* Structure for "number_group" directive. */
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900447struct tomoyo_number_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900448 struct tomoyo_acl_head head;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900449 struct tomoyo_number_union number;
450};
451
Tetsuo Handa8761afd2011-07-08 13:22:41 +0900452/* Subset of "struct stat". Used by conditional ACL and audit logs. */
453struct tomoyo_mini_stat {
454 uid_t uid;
455 gid_t gid;
456 ino_t ino;
457 mode_t mode;
458 dev_t dev;
459 dev_t rdev;
460};
461
462/* Structure for attribute checks in addition to pathname checks. */
463struct tomoyo_obj_info {
464 /*
465 * True if tomoyo_get_attributes() was already called, false otherwise.
466 */
467 bool validate_done;
468 /* True if @stat[] is valid. */
469 bool stat_valid[TOMOYO_MAX_PATH_STAT];
470 /* First pathname. Initialized with { NULL, NULL } if no path. */
471 struct path path1;
472 /* Second pathname. Initialized with { NULL, NULL } if no path. */
473 struct path path2;
474 /*
475 * Information on @path1, @path1's parent directory, @path2, @path2's
476 * parent directory.
477 */
478 struct tomoyo_mini_stat stat[TOMOYO_MAX_PATH_STAT];
479};
480
Tetsuo Handa2066a362011-07-08 13:21:37 +0900481/* Structure for entries which follows "struct tomoyo_condition". */
482struct tomoyo_condition_element {
483 /* Left hand operand. */
484 u8 left;
485 /* Right hand operand. */
486 u8 right;
487 /* Equation operator. True if equals or overlaps, false otherwise. */
488 bool equals;
489};
490
491/* Structure for optional arguments. */
492struct tomoyo_condition {
493 struct tomoyo_shared_acl_head head;
494 u32 size; /* Memory size allocated for this entry. */
495 u16 condc; /* Number of conditions in this struct. */
496 u16 numbers_count; /* Number of "struct tomoyo_number_union values". */
497 /*
498 * struct tomoyo_condition_element condition[condc];
499 * struct tomoyo_number_union values[numbers_count];
500 */
501};
502
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900503/* Common header for individual entries. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900504struct tomoyo_acl_info {
505 struct list_head list;
Tetsuo Handa2066a362011-07-08 13:21:37 +0900506 struct tomoyo_condition *cond; /* Maybe NULL. */
Tetsuo Handa237ab452010-06-12 20:46:22 +0900507 bool is_deleted;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900508 u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */
Kentaro Takeda95908372009-02-05 17:18:13 +0900509} __packed;
510
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900511/* Structure for domain information. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900512struct tomoyo_domain_info {
513 struct list_head list;
514 struct list_head acl_info_list;
515 /* Name of this domain. Never NULL. */
516 const struct tomoyo_path_info *domainname;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900517 /* Namespace for this domain. Never NULL. */
518 struct tomoyo_policy_namespace *ns;
Kentaro Takeda95908372009-02-05 17:18:13 +0900519 u8 profile; /* Profile number to use. */
Tetsuo Handa32997142011-06-26 23:19:28 +0900520 u8 group; /* Group number to use. */
Tetsuo Handaa0558fc2009-04-06 20:49:14 +0900521 bool is_deleted; /* Delete flag. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900522 bool flags[TOMOYO_MAX_DOMAIN_INFO_FLAGS];
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900523 atomic_t users; /* Number of referring credentials. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900524};
525
Kentaro Takeda95908372009-02-05 17:18:13 +0900526/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900527 * Structure for "file execute", "file read", "file write", "file append",
528 * "file unlink", "file getattr", "file rmdir", "file truncate",
529 * "file symlink", "file chroot" and "file unmount" directive.
Kentaro Takeda95908372009-02-05 17:18:13 +0900530 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900531struct tomoyo_path_acl {
532 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900533 u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900534 struct tomoyo_name_union name;
Kentaro Takeda95908372009-02-05 17:18:13 +0900535};
536
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900537/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900538 * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
539 * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900540 */
541struct tomoyo_path_number_acl {
542 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900543 /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900544 u8 perm;
545 struct tomoyo_name_union name;
546 struct tomoyo_number_union number;
547};
548
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900549/* Structure for "file mkblock" and "file mkchar" directive. */
Tetsuo Handa75093152010-06-16 16:23:55 +0900550struct tomoyo_mkdev_acl {
551 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900552 u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900553 struct tomoyo_name_union name;
554 struct tomoyo_number_union mode;
555 struct tomoyo_number_union major;
556 struct tomoyo_number_union minor;
557};
558
559/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900560 * Structure for "file rename", "file link" and "file pivot_root" directive.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900561 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900562struct tomoyo_path2_acl {
563 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900564 u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900565 struct tomoyo_name_union name1;
566 struct tomoyo_name_union name2;
Kentaro Takeda95908372009-02-05 17:18:13 +0900567};
568
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900569/* Structure for "file mount" directive. */
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900570struct tomoyo_mount_acl {
571 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900572 struct tomoyo_name_union dev_name;
573 struct tomoyo_name_union dir_name;
574 struct tomoyo_name_union fs_type;
575 struct tomoyo_number_union flags;
576};
577
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900578/* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
579struct tomoyo_acl_param {
580 char *data;
581 struct list_head *list;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900582 struct tomoyo_policy_namespace *ns;
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900583 bool is_delete;
584};
585
Tetsuo Handa0d2171d2011-06-26 23:17:46 +0900586#define TOMOYO_MAX_IO_READ_QUEUE 64
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900587
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900588/*
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900589 * Structure for reading/writing policy via /sys/kernel/security/tomoyo
590 * interfaces.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900591 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900592struct tomoyo_io_buffer {
Tetsuo Handa8fbe71f2010-06-16 16:29:59 +0900593 void (*read) (struct tomoyo_io_buffer *);
Kentaro Takeda95908372009-02-05 17:18:13 +0900594 int (*write) (struct tomoyo_io_buffer *);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900595 int (*poll) (struct file *file, poll_table *wait);
Kentaro Takeda95908372009-02-05 17:18:13 +0900596 /* Exclusive lock for this structure. */
597 struct mutex io_sem;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900598 char __user *read_user_buf;
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900599 size_t read_user_buf_avail;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900600 struct {
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900601 struct list_head *ns;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900602 struct list_head *domain;
603 struct list_head *group;
604 struct list_head *acl;
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900605 size_t avail;
606 unsigned int step;
607 unsigned int query_index;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900608 u16 index;
Tetsuo Handa2066a362011-07-08 13:21:37 +0900609 u16 cond_index;
Tetsuo Handa32997142011-06-26 23:19:28 +0900610 u8 acl_group_index;
Tetsuo Handa2066a362011-07-08 13:21:37 +0900611 u8 cond_step;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900612 u8 bit;
613 u8 w_pos;
614 bool eof;
615 bool print_this_domain_only;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900616 bool print_transition_related_only;
Tetsuo Handa2066a362011-07-08 13:21:37 +0900617 bool print_cond_part;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900618 const char *w[TOMOYO_MAX_IO_READ_QUEUE];
619 } r;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900620 struct {
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900621 struct tomoyo_policy_namespace *ns;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900622 /* The position currently writing to. */
623 struct tomoyo_domain_info *domain;
624 /* Bytes available for writing. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900625 size_t avail;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900626 bool is_delete;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900627 } w;
Kentaro Takeda95908372009-02-05 17:18:13 +0900628 /* Buffer for reading. */
629 char *read_buf;
Kentaro Takeda95908372009-02-05 17:18:13 +0900630 /* Size of read buffer. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900631 size_t readbuf_size;
Kentaro Takeda95908372009-02-05 17:18:13 +0900632 /* Buffer for writing. */
633 char *write_buf;
Kentaro Takeda95908372009-02-05 17:18:13 +0900634 /* Size of write buffer. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900635 size_t writebuf_size;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900636 /* Type of this interface. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900637 enum tomoyo_securityfs_interface_index type;
Tetsuo Handa2e503bb2011-06-26 23:20:55 +0900638 /* Users counter protected by tomoyo_io_buffer_list_lock. */
639 u8 users;
640 /* List for telling GC not to kfree() elements. */
641 struct list_head list;
Kentaro Takeda95908372009-02-05 17:18:13 +0900642};
643
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900644/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900645 * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
646 * "no_keep_domain" keyword.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900647 */
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900648struct tomoyo_transition_control {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900649 struct tomoyo_acl_head head;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900650 u8 type; /* One of values in "enum tomoyo_transition_type". */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900651 /* True if the domainname is tomoyo_get_last_name(). */
652 bool is_last_name;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900653 const struct tomoyo_path_info *domainname; /* Maybe NULL */
654 const struct tomoyo_path_info *program; /* Maybe NULL */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900655};
656
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900657/* Structure for "aggregator" keyword. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900658struct tomoyo_aggregator {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900659 struct tomoyo_acl_head head;
Tetsuo Handa10843072010-06-03 20:38:03 +0900660 const struct tomoyo_path_info *original_name;
661 const struct tomoyo_path_info *aggregated_name;
Tetsuo Handa10843072010-06-03 20:38:03 +0900662};
663
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900664/* Structure for policy manager. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900665struct tomoyo_manager {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900666 struct tomoyo_acl_head head;
667 bool is_domain; /* True if manager is a domainname. */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900668 /* A path to program or a domainname. */
669 const struct tomoyo_path_info *manager;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900670};
671
Tetsuo Handa57c25902010-06-03 20:38:44 +0900672struct tomoyo_preference {
673 unsigned int learning_max_entry;
674 bool enforcing_verbose;
675 bool learning_verbose;
676 bool permissive_verbose;
677};
678
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900679/* Structure for /sys/kernel/security/tomnoyo/profile interface. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900680struct tomoyo_profile {
681 const struct tomoyo_path_info *comment;
682 struct tomoyo_preference *learning;
683 struct tomoyo_preference *permissive;
684 struct tomoyo_preference *enforcing;
685 struct tomoyo_preference preference;
686 u8 default_config;
687 u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX];
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900688 unsigned int pref[TOMOYO_MAX_PREF];
Tetsuo Handa57c25902010-06-03 20:38:44 +0900689};
690
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900691/* Structure for representing YYYY/MM/DD hh/mm/ss. */
692struct tomoyo_time {
693 u16 year;
694 u8 month;
695 u8 day;
696 u8 hour;
697 u8 min;
698 u8 sec;
699};
700
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900701/* Structure for policy namespace. */
702struct tomoyo_policy_namespace {
703 /* Profile table. Memory is allocated as needed. */
704 struct tomoyo_profile *profile_ptr[TOMOYO_MAX_PROFILES];
705 /* List of "struct tomoyo_group". */
706 struct list_head group_list[TOMOYO_MAX_GROUP];
707 /* List of policy. */
708 struct list_head policy_list[TOMOYO_MAX_POLICY];
709 /* The global ACL referred by "use_group" keyword. */
710 struct list_head acl_group[TOMOYO_MAX_ACL_GROUPS];
711 /* List for connecting to tomoyo_namespace_list list. */
712 struct list_head namespace_list;
713 /* Profile version. Currently only 20100903 is defined. */
714 unsigned int profile_version;
715 /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */
716 const char *name;
717};
718
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900719/********** Function prototypes. **********/
720
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900721bool tomoyo_compare_number_union(const unsigned long value,
722 const struct tomoyo_number_union *ptr);
Tetsuo Handa2066a362011-07-08 13:21:37 +0900723bool tomoyo_condition(struct tomoyo_request_info *r,
724 const struct tomoyo_condition *cond);
Tetsuo Handa75093152010-06-16 16:23:55 +0900725bool tomoyo_correct_domain(const unsigned char *domainname);
Tetsuo Handa75093152010-06-16 16:23:55 +0900726bool tomoyo_correct_path(const char *filename);
727bool tomoyo_correct_word(const char *string);
Tetsuo Handa75093152010-06-16 16:23:55 +0900728bool tomoyo_domain_def(const unsigned char *buffer);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900729bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
730bool tomoyo_memory_ok(void *ptr);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900731bool tomoyo_number_matches_group(const unsigned long min,
732 const unsigned long max,
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900733 const struct tomoyo_group *group);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900734bool tomoyo_parse_name_union(struct tomoyo_acl_param *param,
735 struct tomoyo_name_union *ptr);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900736bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
737 struct tomoyo_number_union *ptr);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900738bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
739 const struct tomoyo_path_info *pattern);
740bool tomoyo_permstr(const char *string, const char *keyword);
741bool tomoyo_str_starts(char **src, const char *find);
742char *tomoyo_encode(const char *str);
743char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt,
744 va_list args);
745char *tomoyo_read_token(struct tomoyo_acl_param *param);
746char *tomoyo_realpath_from_path(struct path *path);
747char *tomoyo_realpath_nofollow(const char *pathname);
748const char *tomoyo_get_exe(void);
749const char *tomoyo_yesno(const unsigned int value);
750const struct tomoyo_path_info *tomoyo_compare_name_union
751(const struct tomoyo_path_info *name, const struct tomoyo_name_union *ptr);
752const struct tomoyo_path_info *tomoyo_get_name(const char *name);
753const struct tomoyo_path_info *tomoyo_path_matches_group
754(const struct tomoyo_path_info *pathname, const struct tomoyo_group *group);
755int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
756 struct path *path, const int flag);
757int tomoyo_close_control(struct tomoyo_io_buffer *head);
758int tomoyo_find_next_domain(struct linux_binprm *bprm);
759int tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile,
760 const u8 index);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900761int tomoyo_init_request_info(struct tomoyo_request_info *r,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900762 struct tomoyo_domain_info *domain,
763 const u8 index);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900764int tomoyo_mkdev_perm(const u8 operation, struct path *path,
765 const unsigned int mode, unsigned int dev);
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900766int tomoyo_mount_permission(char *dev_name, struct path *path,
767 const char *type, unsigned long flags,
768 void *data_page);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900769int tomoyo_open_control(const u8 type, struct file *file);
Tetsuo Handa97d69312010-02-16 09:46:15 +0900770int tomoyo_path2_perm(const u8 operation, struct path *path1,
771 struct path *path2);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900772int tomoyo_path_number_perm(const u8 operation, struct path *path,
773 unsigned long number);
774int tomoyo_path_perm(const u8 operation, struct path *path);
775int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
776 const struct tomoyo_path_info *filename);
777int tomoyo_poll_control(struct file *file, poll_table *wait);
778int tomoyo_poll_log(struct file *file, poll_table *wait);
779int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
780 __printf(2, 3);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900781int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900782 struct tomoyo_acl_param *param,
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900783 bool (*check_duplicate)
784 (const struct tomoyo_acl_info *,
785 const struct tomoyo_acl_info *),
786 bool (*merge_duplicate)
787 (struct tomoyo_acl_info *, struct tomoyo_acl_info *,
788 const bool));
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900789int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900790 struct tomoyo_acl_param *param,
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900791 bool (*check_duplicate)
792 (const struct tomoyo_acl_head *,
793 const struct tomoyo_acl_head *));
794int tomoyo_write_aggregator(struct tomoyo_acl_param *param);
795int tomoyo_write_file(struct tomoyo_acl_param *param);
796int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type);
797int tomoyo_write_transition_control(struct tomoyo_acl_param *param,
798 const u8 type);
799ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer,
800 const int buffer_len);
801ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,
802 const char __user *buffer, const int buffer_len);
Tetsuo Handa2066a362011-07-08 13:21:37 +0900803struct tomoyo_condition *tomoyo_get_condition(struct tomoyo_acl_param *param);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900804struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
805 const bool transit);
806struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
807struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param,
808 const u8 idx);
809struct tomoyo_policy_namespace *tomoyo_assign_namespace
810(const char *domainname);
811struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns,
812 const u8 profile);
813unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
814 const u8 index);
Tetsuo Handa2066a362011-07-08 13:21:37 +0900815u8 tomoyo_parse_ulong(unsigned long *result, char **str);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900816void *tomoyo_commit_ok(void *data, const unsigned int size);
817void __init tomoyo_load_builtin_policy(void);
818void __init tomoyo_mm_init(void);
Tetsuo Handa99a85252010-06-16 16:22:51 +0900819void tomoyo_check_acl(struct tomoyo_request_info *r,
Tetsuo Handa484ca792010-07-29 14:29:55 +0900820 bool (*check_entry) (struct tomoyo_request_info *,
Tetsuo Handa99a85252010-06-16 16:22:51 +0900821 const struct tomoyo_acl_info *));
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900822void tomoyo_check_profile(void);
823void tomoyo_convert_time(time_t time, struct tomoyo_time *stamp);
Tetsuo Handa2066a362011-07-08 13:21:37 +0900824void tomoyo_del_condition(struct list_head *element);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900825void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
Tetsuo Handa8761afd2011-07-08 13:22:41 +0900826void tomoyo_get_attributes(struct tomoyo_obj_info *obj);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900827void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns);
828void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
829 __printf(2, 3);
830void tomoyo_load_policy(const char *filename);
831void tomoyo_memory_free(void *ptr);
832void tomoyo_normalize_line(unsigned char *buffer);
833void tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register);
834void tomoyo_print_ulong(char *buffer, const int buffer_len,
835 const unsigned long value, const u8 type);
836void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
837void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
838void tomoyo_read_log(struct tomoyo_io_buffer *head);
839void tomoyo_update_stat(const u8 index);
840void tomoyo_warn_oom(const char *function);
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900841void tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...)
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900842 __printf(2, 3);
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900843void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
844 va_list args);
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900845
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900846/********** External variable definitions. **********/
847
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900848extern bool tomoyo_policy_loaded;
Tetsuo Handa2066a362011-07-08 13:21:37 +0900849extern const char * const tomoyo_condition_keyword
850[TOMOYO_MAX_CONDITION_KEYWORD];
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900851extern const char * const tomoyo_dif[TOMOYO_MAX_DOMAIN_INFO_FLAGS];
852extern const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX
853 + TOMOYO_MAX_MAC_CATEGORY_INDEX];
854extern const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE];
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900855extern const char * const tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
856extern const u8 tomoyo_index2category[TOMOYO_MAX_MAC_INDEX];
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900857extern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION];
Tetsuo Handa0d2171d2011-06-26 23:17:46 +0900858extern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION];
859extern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION];
Tetsuo Handa2066a362011-07-08 13:21:37 +0900860extern struct list_head tomoyo_condition_list;
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900861extern struct list_head tomoyo_domain_list;
862extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
863extern struct list_head tomoyo_namespace_list;
864extern struct mutex tomoyo_policy_lock;
865extern struct srcu_struct tomoyo_ss;
866extern struct tomoyo_domain_info tomoyo_kernel_domain;
867extern struct tomoyo_policy_namespace tomoyo_kernel_namespace;
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900868extern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT];
869extern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT];
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900870
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900871/********** Inlined functions. **********/
872
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900873/**
874 * tomoyo_read_lock - Take lock for protecting policy.
875 *
876 * Returns index number for tomoyo_read_unlock().
877 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900878static inline int tomoyo_read_lock(void)
879{
880 return srcu_read_lock(&tomoyo_ss);
881}
882
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900883/**
884 * tomoyo_read_unlock - Release lock for protecting policy.
885 *
886 * @idx: Index number returned by tomoyo_read_lock().
887 *
888 * Returns nothing.
889 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900890static inline void tomoyo_read_unlock(int idx)
891{
892 srcu_read_unlock(&tomoyo_ss, idx);
893}
894
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900895/**
Tetsuo Handa2066a362011-07-08 13:21:37 +0900896 * tomoyo_sys_getppid - Copy of getppid().
897 *
898 * Returns parent process's PID.
899 *
900 * Alpha does not have getppid() defined. To be able to build this module on
901 * Alpha, I have to copy getppid() from kernel/timer.c.
902 */
903static inline pid_t tomoyo_sys_getppid(void)
904{
905 pid_t pid;
906 rcu_read_lock();
907 pid = task_tgid_vnr(current->real_parent);
908 rcu_read_unlock();
909 return pid;
910}
911
912/**
913 * tomoyo_sys_getpid - Copy of getpid().
914 *
915 * Returns current thread's PID.
916 *
917 * Alpha does not have getpid() defined. To be able to build this module on
918 * Alpha, I have to copy getpid() from kernel/timer.c.
919 */
920static inline pid_t tomoyo_sys_getpid(void)
921{
922 return task_tgid_vnr(current);
923}
924
925/**
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900926 * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
927 *
928 * @a: Pointer to "struct tomoyo_path_info".
929 * @b: Pointer to "struct tomoyo_path_info".
930 *
931 * Returns true if @a == @b, false otherwise.
932 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900933static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
934 const struct tomoyo_path_info *b)
935{
936 return a->hash != b->hash || strcmp(a->name, b->name);
937}
938
Kentaro Takeda95908372009-02-05 17:18:13 +0900939/**
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900940 * tomoyo_put_name - Drop reference on "struct tomoyo_name".
941 *
942 * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
943 *
944 * Returns nothing.
945 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900946static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
947{
948 if (name) {
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900949 struct tomoyo_name *ptr =
950 container_of(name, typeof(*ptr), entry);
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900951 atomic_dec(&ptr->head.users);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900952 }
953}
Kentaro Takeda95908372009-02-05 17:18:13 +0900954
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900955/**
Tetsuo Handa2066a362011-07-08 13:21:37 +0900956 * tomoyo_put_condition - Drop reference on "struct tomoyo_condition".
957 *
958 * @cond: Pointer to "struct tomoyo_condition". Maybe NULL.
959 *
960 * Returns nothing.
961 */
962static inline void tomoyo_put_condition(struct tomoyo_condition *cond)
963{
964 if (cond)
965 atomic_dec(&cond->head.users);
966}
967
968/**
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900969 * tomoyo_put_group - Drop reference on "struct tomoyo_group".
970 *
971 * @group: Pointer to "struct tomoyo_group". Maybe NULL.
972 *
973 * Returns nothing.
974 */
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900975static inline void tomoyo_put_group(struct tomoyo_group *group)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900976{
977 if (group)
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900978 atomic_dec(&group->head.users);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900979}
980
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900981/**
982 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
983 *
984 * Returns pointer to "struct tomoyo_domain_info" for current thread.
985 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900986static inline struct tomoyo_domain_info *tomoyo_domain(void)
987{
988 return current_cred()->security;
989}
Kentaro Takeda95908372009-02-05 17:18:13 +0900990
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900991/**
992 * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
993 *
994 * @task: Pointer to "struct task_struct".
995 *
996 * Returns pointer to "struct tomoyo_security" for specified thread.
997 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900998static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
999 *task)
1000{
1001 return task_cred_xxx(task, security);
1002}
Kentaro Takeda95908372009-02-05 17:18:13 +09001003
Tetsuo Handab5bc60b2011-06-26 23:16:03 +09001004/**
1005 * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
1006 *
1007 * @a: Pointer to "struct tomoyo_name_union".
1008 * @b: Pointer to "struct tomoyo_name_union".
1009 *
1010 * Returns true if @a == @b, false otherwise.
1011 */
Tetsuo Handa75093152010-06-16 16:23:55 +09001012static inline bool tomoyo_same_name_union
Tetsuo Handab5bc60b2011-06-26 23:16:03 +09001013(const struct tomoyo_name_union *a, const struct tomoyo_name_union *b)
Tetsuo Handa7762fbf2010-05-10 17:30:26 +09001014{
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +09001015 return a->filename == b->filename && a->group == b->group;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +09001016}
1017
Tetsuo Handab5bc60b2011-06-26 23:16:03 +09001018/**
1019 * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
1020 *
1021 * @a: Pointer to "struct tomoyo_number_union".
1022 * @b: Pointer to "struct tomoyo_number_union".
1023 *
1024 * Returns true if @a == @b, false otherwise.
1025 */
Tetsuo Handa75093152010-06-16 16:23:55 +09001026static inline bool tomoyo_same_number_union
Tetsuo Handab5bc60b2011-06-26 23:16:03 +09001027(const struct tomoyo_number_union *a, const struct tomoyo_number_union *b)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +09001028{
Tetsuo Handab5bc60b2011-06-26 23:16:03 +09001029 return a->values[0] == b->values[0] && a->values[1] == b->values[1] &&
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +09001030 a->group == b->group && a->value_type[0] == b->value_type[0] &&
1031 a->value_type[1] == b->value_type[1];
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +09001032}
1033
Tetsuo Handabd03a3e2011-06-26 23:19:52 +09001034/**
1035 * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread.
1036 *
1037 * Returns pointer to "struct tomoyo_policy_namespace" for current thread.
1038 */
1039static inline struct tomoyo_policy_namespace *tomoyo_current_namespace(void)
1040{
1041 return tomoyo_domain()->ns;
1042}
1043
Tetsuo Handaeadd99c2011-06-26 23:18:58 +09001044#if defined(CONFIG_SLOB)
1045
1046/**
1047 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
1048 *
1049 * @size: Size to be rounded up.
1050 *
1051 * Returns @size.
1052 *
1053 * Since SLOB does not round up, this function simply returns @size.
1054 */
1055static inline int tomoyo_round2(size_t size)
1056{
1057 return size;
1058}
1059
1060#else
1061
1062/**
1063 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
1064 *
1065 * @size: Size to be rounded up.
1066 *
1067 * Returns rounded size.
1068 *
1069 * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of
1070 * (e.g.) 128 bytes.
1071 */
1072static inline int tomoyo_round2(size_t size)
1073{
1074#if PAGE_SIZE == 4096
1075 size_t bsize = 32;
1076#else
1077 size_t bsize = 64;
1078#endif
1079 if (!size)
1080 return 0;
1081 while (size > bsize)
1082 bsize <<= 1;
1083 return bsize;
1084}
1085
1086#endif
1087
Kentaro Takeda95908372009-02-05 17:18:13 +09001088/**
1089 * list_for_each_cookie - iterate over a list with cookie.
1090 * @pos: the &struct list_head to use as a loop cursor.
Kentaro Takeda95908372009-02-05 17:18:13 +09001091 * @head: the head for your list.
Kentaro Takeda95908372009-02-05 17:18:13 +09001092 */
Tetsuo Handa475e6fa2010-06-24 11:28:14 +09001093#define list_for_each_cookie(pos, head) \
1094 if (!pos) \
1095 pos = srcu_dereference((head)->next, &tomoyo_ss); \
1096 for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +09001097
Kentaro Takeda95908372009-02-05 17:18:13 +09001098#endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */