blob: 958d433b01154d06ce7dc3296cf6d8049a109cae [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() */
57 TOMOYO_MAX_CONDITION_KEYWORD,
58 TOMOYO_NUMBER_UNION,
59};
60
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090061/* Index numbers for operation mode. */
Tetsuo Handacb0abe62010-05-17 10:08:05 +090062enum tomoyo_mode_index {
63 TOMOYO_CONFIG_DISABLED,
64 TOMOYO_CONFIG_LEARNING,
65 TOMOYO_CONFIG_PERMISSIVE,
Tetsuo Handa57c25902010-06-03 20:38:44 +090066 TOMOYO_CONFIG_ENFORCING,
Tetsuo Handaeadd99c2011-06-26 23:18:58 +090067 TOMOYO_CONFIG_MAX_MODE,
68 TOMOYO_CONFIG_WANT_REJECT_LOG = 64,
69 TOMOYO_CONFIG_WANT_GRANT_LOG = 128,
70 TOMOYO_CONFIG_USE_DEFAULT = 255,
Tetsuo Handacb0abe62010-05-17 10:08:05 +090071};
72
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090073/* Index numbers for entry type. */
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090074enum tomoyo_policy_id {
75 TOMOYO_ID_GROUP,
76 TOMOYO_ID_PATH_GROUP,
77 TOMOYO_ID_NUMBER_GROUP,
Tetsuo Handa5448ec42010-06-21 11:14:39 +090078 TOMOYO_ID_TRANSITION_CONTROL,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090079 TOMOYO_ID_AGGREGATOR,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090080 TOMOYO_ID_MANAGER,
Tetsuo Handa2066a362011-07-08 13:21:37 +090081 TOMOYO_ID_CONDITION,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090082 TOMOYO_ID_NAME,
83 TOMOYO_ID_ACL,
84 TOMOYO_ID_DOMAIN,
85 TOMOYO_MAX_POLICY
86};
87
Tetsuo Handa2c47ab92011-06-26 23:21:19 +090088/* Index numbers for domain's attributes. */
89enum tomoyo_domain_info_flags_index {
90 /* Quota warnning flag. */
91 TOMOYO_DIF_QUOTA_WARNED,
92 /*
93 * This domain was unable to create a new domain at
94 * tomoyo_find_next_domain() because the name of the domain to be
95 * created was too long or it could not allocate memory.
96 * More than one process continued execve() without domain transition.
97 */
98 TOMOYO_DIF_TRANSITION_FAILED,
99 TOMOYO_MAX_DOMAIN_INFO_FLAGS
100};
101
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900102/* Index numbers for group entries. */
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900103enum tomoyo_group_id {
104 TOMOYO_PATH_GROUP,
105 TOMOYO_NUMBER_GROUP,
106 TOMOYO_MAX_GROUP
107};
108
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900109/* Index numbers for type of numeric values. */
110enum tomoyo_value_type {
111 TOMOYO_VALUE_TYPE_INVALID,
112 TOMOYO_VALUE_TYPE_DECIMAL,
113 TOMOYO_VALUE_TYPE_OCTAL,
114 TOMOYO_VALUE_TYPE_HEXADECIMAL,
115};
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900116
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900117/* Index numbers for domain transition control keywords. */
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900118enum tomoyo_transition_type {
119 /* Do not change this order, */
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900120 TOMOYO_TRANSITION_CONTROL_NO_RESET,
121 TOMOYO_TRANSITION_CONTROL_RESET,
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900122 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE,
123 TOMOYO_TRANSITION_CONTROL_INITIALIZE,
124 TOMOYO_TRANSITION_CONTROL_NO_KEEP,
125 TOMOYO_TRANSITION_CONTROL_KEEP,
126 TOMOYO_MAX_TRANSITION_TYPE
127};
128
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900129/* Index numbers for Access Controls. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900130enum tomoyo_acl_entry_type_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900131 TOMOYO_TYPE_PATH_ACL,
132 TOMOYO_TYPE_PATH2_ACL,
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900133 TOMOYO_TYPE_PATH_NUMBER_ACL,
Tetsuo Handa75093152010-06-16 16:23:55 +0900134 TOMOYO_TYPE_MKDEV_ACL,
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900135 TOMOYO_TYPE_MOUNT_ACL,
Tetsuo Handa084da352010-02-15 15:10:39 +0900136};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900137
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900138/* Index numbers for access controls with one pathname. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900139enum tomoyo_path_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900140 TOMOYO_TYPE_EXECUTE,
141 TOMOYO_TYPE_READ,
142 TOMOYO_TYPE_WRITE,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900143 TOMOYO_TYPE_APPEND,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900144 TOMOYO_TYPE_UNLINK,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900145 TOMOYO_TYPE_GETATTR,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900146 TOMOYO_TYPE_RMDIR,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900147 TOMOYO_TYPE_TRUNCATE,
148 TOMOYO_TYPE_SYMLINK,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900149 TOMOYO_TYPE_CHROOT,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900150 TOMOYO_TYPE_UMOUNT,
151 TOMOYO_MAX_PATH_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900152};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900153
Tetsuo Handab22b8b92011-06-26 23:21:50 +0900154/* Index numbers for /sys/kernel/security/tomoyo/stat interface. */
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900155enum tomoyo_memory_stat_type {
156 TOMOYO_MEMORY_POLICY,
157 TOMOYO_MEMORY_AUDIT,
158 TOMOYO_MEMORY_QUERY,
159 TOMOYO_MAX_MEMORY_STAT
160};
161
Tetsuo Handa75093152010-06-16 16:23:55 +0900162enum tomoyo_mkdev_acl_index {
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900163 TOMOYO_TYPE_MKBLOCK,
164 TOMOYO_TYPE_MKCHAR,
Tetsuo Handa75093152010-06-16 16:23:55 +0900165 TOMOYO_MAX_MKDEV_OPERATION
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900166};
167
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900168/* Index numbers for access controls with two pathnames. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900169enum tomoyo_path2_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900170 TOMOYO_TYPE_LINK,
171 TOMOYO_TYPE_RENAME,
172 TOMOYO_TYPE_PIVOT_ROOT,
173 TOMOYO_MAX_PATH2_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900174};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900175
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900176/* Index numbers for access controls with one pathname and one number. */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900177enum tomoyo_path_number_acl_index {
178 TOMOYO_TYPE_CREATE,
179 TOMOYO_TYPE_MKDIR,
180 TOMOYO_TYPE_MKFIFO,
181 TOMOYO_TYPE_MKSOCK,
182 TOMOYO_TYPE_IOCTL,
183 TOMOYO_TYPE_CHMOD,
184 TOMOYO_TYPE_CHOWN,
185 TOMOYO_TYPE_CHGRP,
186 TOMOYO_MAX_PATH_NUMBER_OPERATION
187};
188
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900189/* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900190enum tomoyo_securityfs_interface_index {
191 TOMOYO_DOMAINPOLICY,
192 TOMOYO_EXCEPTIONPOLICY,
Tetsuo Handa084da352010-02-15 15:10:39 +0900193 TOMOYO_PROCESS_STATUS,
Tetsuo Handab22b8b92011-06-26 23:21:50 +0900194 TOMOYO_STAT,
Tetsuo Handa084da352010-02-15 15:10:39 +0900195 TOMOYO_SELFDOMAIN,
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900196 TOMOYO_AUDIT,
Tetsuo Handa084da352010-02-15 15:10:39 +0900197 TOMOYO_VERSION,
198 TOMOYO_PROFILE,
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900199 TOMOYO_QUERY,
Tetsuo Handa084da352010-02-15 15:10:39 +0900200 TOMOYO_MANAGER
201};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900202
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900203/* Index numbers for special mount operations. */
204enum tomoyo_special_mount {
205 TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */
206 TOMOYO_MOUNT_MOVE, /* mount --move /old /new */
207 TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */
208 TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */
209 TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */
210 TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */
211 TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */
212 TOMOYO_MAX_SPECIAL_MOUNT
213};
214
215/* Index numbers for functionality. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900216enum tomoyo_mac_index {
217 TOMOYO_MAC_FILE_EXECUTE,
218 TOMOYO_MAC_FILE_OPEN,
219 TOMOYO_MAC_FILE_CREATE,
220 TOMOYO_MAC_FILE_UNLINK,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900221 TOMOYO_MAC_FILE_GETATTR,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900222 TOMOYO_MAC_FILE_MKDIR,
223 TOMOYO_MAC_FILE_RMDIR,
224 TOMOYO_MAC_FILE_MKFIFO,
225 TOMOYO_MAC_FILE_MKSOCK,
226 TOMOYO_MAC_FILE_TRUNCATE,
227 TOMOYO_MAC_FILE_SYMLINK,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900228 TOMOYO_MAC_FILE_MKBLOCK,
229 TOMOYO_MAC_FILE_MKCHAR,
230 TOMOYO_MAC_FILE_LINK,
231 TOMOYO_MAC_FILE_RENAME,
232 TOMOYO_MAC_FILE_CHMOD,
233 TOMOYO_MAC_FILE_CHOWN,
234 TOMOYO_MAC_FILE_CHGRP,
235 TOMOYO_MAC_FILE_IOCTL,
236 TOMOYO_MAC_FILE_CHROOT,
237 TOMOYO_MAC_FILE_MOUNT,
238 TOMOYO_MAC_FILE_UMOUNT,
239 TOMOYO_MAC_FILE_PIVOT_ROOT,
240 TOMOYO_MAX_MAC_INDEX
241};
242
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900243/* Index numbers for category of functionality. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900244enum tomoyo_mac_category_index {
245 TOMOYO_MAC_CATEGORY_FILE,
246 TOMOYO_MAX_MAC_CATEGORY_INDEX
247};
248
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900249/*
250 * Retry this request. Returned by tomoyo_supervisor() if policy violation has
251 * occurred in enforcing mode and the userspace daemon decided to retry.
252 *
253 * We must choose a positive value in order to distinguish "granted" (which is
254 * 0) and "rejected" (which is a negative value) and "retry".
255 */
256#define TOMOYO_RETRY_REQUEST 1
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900257
Tetsuo Handab22b8b92011-06-26 23:21:50 +0900258/* Index numbers for /sys/kernel/security/tomoyo/stat interface. */
259enum tomoyo_policy_stat_type {
260 /* Do not change this order. */
261 TOMOYO_STAT_POLICY_UPDATES,
262 TOMOYO_STAT_POLICY_LEARNING, /* == TOMOYO_CONFIG_LEARNING */
263 TOMOYO_STAT_POLICY_PERMISSIVE, /* == TOMOYO_CONFIG_PERMISSIVE */
264 TOMOYO_STAT_POLICY_ENFORCING, /* == TOMOYO_CONFIG_ENFORCING */
265 TOMOYO_MAX_POLICY_STAT
266};
267
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900268/* Index numbers for profile's PREFERENCE values. */
269enum tomoyo_pref_index {
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900270 TOMOYO_PREF_MAX_AUDIT_LOG,
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900271 TOMOYO_PREF_MAX_LEARNING_ENTRY,
272 TOMOYO_MAX_PREF
273};
274
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900275/********** Structure definitions. **********/
Kentaro Takeda95908372009-02-05 17:18:13 +0900276
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900277/* Common header for holding ACL entries. */
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900278struct tomoyo_acl_head {
279 struct list_head list;
280 bool is_deleted;
281} __packed;
282
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900283/* Common header for shared entries. */
284struct tomoyo_shared_acl_head {
285 struct list_head list;
286 atomic_t users;
287} __packed;
288
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900289struct tomoyo_policy_namespace;
290
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900291/* Structure for request info. */
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900292struct tomoyo_request_info {
293 struct tomoyo_domain_info *domain;
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900294 /* For holding parameters. */
295 union {
296 struct {
297 const struct tomoyo_path_info *filename;
Tetsuo Handa484ca792010-07-29 14:29:55 +0900298 /* For using wildcards at tomoyo_find_next_domain(). */
299 const struct tomoyo_path_info *matched_path;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900300 /* One of values in "enum tomoyo_path_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900301 u8 operation;
302 } path;
303 struct {
304 const struct tomoyo_path_info *filename1;
305 const struct tomoyo_path_info *filename2;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900306 /* One of values in "enum tomoyo_path2_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900307 u8 operation;
308 } path2;
309 struct {
310 const struct tomoyo_path_info *filename;
311 unsigned int mode;
312 unsigned int major;
313 unsigned int minor;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900314 /* One of values in "enum tomoyo_mkdev_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900315 u8 operation;
316 } mkdev;
317 struct {
318 const struct tomoyo_path_info *filename;
319 unsigned long number;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900320 /*
321 * One of values in
322 * "enum tomoyo_path_number_acl_index".
323 */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900324 u8 operation;
325 } path_number;
326 struct {
327 const struct tomoyo_path_info *type;
328 const struct tomoyo_path_info *dir;
329 const struct tomoyo_path_info *dev;
330 unsigned long flags;
331 int need_dev;
332 } mount;
333 } param;
334 u8 param_type;
335 bool granted;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900336 u8 retry;
337 u8 profile;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900338 u8 mode; /* One of tomoyo_mode_index . */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900339 u8 type;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900340};
341
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900342/* Structure for holding a token. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900343struct tomoyo_path_info {
344 const char *name;
345 u32 hash; /* = full_name_hash(name, strlen(name)) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900346 u16 const_len; /* = tomoyo_const_part_length(name) */
347 bool is_dir; /* = tomoyo_strendswith(name, "/") */
348 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900349};
350
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900351/* Structure for holding string data. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900352struct tomoyo_name {
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900353 struct tomoyo_shared_acl_head head;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900354 struct tomoyo_path_info entry;
355};
Kentaro Takeda95908372009-02-05 17:18:13 +0900356
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900357/* Structure for holding a word. */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900358struct tomoyo_name_union {
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900359 /* Either @filename or @group is NULL. */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900360 const struct tomoyo_path_info *filename;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900361 struct tomoyo_group *group;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900362};
363
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900364/* Structure for holding a number. */
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900365struct tomoyo_number_union {
366 unsigned long values[2];
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900367 struct tomoyo_group *group; /* Maybe NULL. */
368 /* One of values in "enum tomoyo_value_type". */
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900369 u8 value_type[2];
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900370};
371
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900372/* Structure for "path_group"/"number_group" directive. */
373struct tomoyo_group {
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900374 struct tomoyo_shared_acl_head head;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900375 const struct tomoyo_path_info *group_name;
376 struct list_head member_list;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900377};
378
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900379/* Structure for "path_group" directive. */
380struct tomoyo_path_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900381 struct tomoyo_acl_head head;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900382 const struct tomoyo_path_info *member_name;
383};
384
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900385/* Structure for "number_group" directive. */
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900386struct tomoyo_number_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900387 struct tomoyo_acl_head head;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900388 struct tomoyo_number_union number;
389};
390
Tetsuo Handa2066a362011-07-08 13:21:37 +0900391/* Structure for entries which follows "struct tomoyo_condition". */
392struct tomoyo_condition_element {
393 /* Left hand operand. */
394 u8 left;
395 /* Right hand operand. */
396 u8 right;
397 /* Equation operator. True if equals or overlaps, false otherwise. */
398 bool equals;
399};
400
401/* Structure for optional arguments. */
402struct tomoyo_condition {
403 struct tomoyo_shared_acl_head head;
404 u32 size; /* Memory size allocated for this entry. */
405 u16 condc; /* Number of conditions in this struct. */
406 u16 numbers_count; /* Number of "struct tomoyo_number_union values". */
407 /*
408 * struct tomoyo_condition_element condition[condc];
409 * struct tomoyo_number_union values[numbers_count];
410 */
411};
412
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900413/* Common header for individual entries. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900414struct tomoyo_acl_info {
415 struct list_head list;
Tetsuo Handa2066a362011-07-08 13:21:37 +0900416 struct tomoyo_condition *cond; /* Maybe NULL. */
Tetsuo Handa237ab452010-06-12 20:46:22 +0900417 bool is_deleted;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900418 u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */
Kentaro Takeda95908372009-02-05 17:18:13 +0900419} __packed;
420
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900421/* Structure for domain information. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900422struct tomoyo_domain_info {
423 struct list_head list;
424 struct list_head acl_info_list;
425 /* Name of this domain. Never NULL. */
426 const struct tomoyo_path_info *domainname;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900427 /* Namespace for this domain. Never NULL. */
428 struct tomoyo_policy_namespace *ns;
Kentaro Takeda95908372009-02-05 17:18:13 +0900429 u8 profile; /* Profile number to use. */
Tetsuo Handa32997142011-06-26 23:19:28 +0900430 u8 group; /* Group number to use. */
Tetsuo Handaa0558fc2009-04-06 20:49:14 +0900431 bool is_deleted; /* Delete flag. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900432 bool flags[TOMOYO_MAX_DOMAIN_INFO_FLAGS];
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900433 atomic_t users; /* Number of referring credentials. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900434};
435
Kentaro Takeda95908372009-02-05 17:18:13 +0900436/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900437 * Structure for "file execute", "file read", "file write", "file append",
438 * "file unlink", "file getattr", "file rmdir", "file truncate",
439 * "file symlink", "file chroot" and "file unmount" directive.
Kentaro Takeda95908372009-02-05 17:18:13 +0900440 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900441struct tomoyo_path_acl {
442 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900443 u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900444 struct tomoyo_name_union name;
Kentaro Takeda95908372009-02-05 17:18:13 +0900445};
446
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900447/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900448 * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
449 * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900450 */
451struct tomoyo_path_number_acl {
452 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900453 /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900454 u8 perm;
455 struct tomoyo_name_union name;
456 struct tomoyo_number_union number;
457};
458
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900459/* Structure for "file mkblock" and "file mkchar" directive. */
Tetsuo Handa75093152010-06-16 16:23:55 +0900460struct tomoyo_mkdev_acl {
461 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900462 u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900463 struct tomoyo_name_union name;
464 struct tomoyo_number_union mode;
465 struct tomoyo_number_union major;
466 struct tomoyo_number_union minor;
467};
468
469/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900470 * Structure for "file rename", "file link" and "file pivot_root" directive.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900471 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900472struct tomoyo_path2_acl {
473 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900474 u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900475 struct tomoyo_name_union name1;
476 struct tomoyo_name_union name2;
Kentaro Takeda95908372009-02-05 17:18:13 +0900477};
478
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900479/* Structure for "file mount" directive. */
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900480struct tomoyo_mount_acl {
481 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900482 struct tomoyo_name_union dev_name;
483 struct tomoyo_name_union dir_name;
484 struct tomoyo_name_union fs_type;
485 struct tomoyo_number_union flags;
486};
487
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900488/* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
489struct tomoyo_acl_param {
490 char *data;
491 struct list_head *list;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900492 struct tomoyo_policy_namespace *ns;
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900493 bool is_delete;
494};
495
Tetsuo Handa0d2171d2011-06-26 23:17:46 +0900496#define TOMOYO_MAX_IO_READ_QUEUE 64
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900497
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900498/*
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900499 * Structure for reading/writing policy via /sys/kernel/security/tomoyo
500 * interfaces.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900501 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900502struct tomoyo_io_buffer {
Tetsuo Handa8fbe71f2010-06-16 16:29:59 +0900503 void (*read) (struct tomoyo_io_buffer *);
Kentaro Takeda95908372009-02-05 17:18:13 +0900504 int (*write) (struct tomoyo_io_buffer *);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900505 int (*poll) (struct file *file, poll_table *wait);
Kentaro Takeda95908372009-02-05 17:18:13 +0900506 /* Exclusive lock for this structure. */
507 struct mutex io_sem;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900508 char __user *read_user_buf;
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900509 size_t read_user_buf_avail;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900510 struct {
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900511 struct list_head *ns;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900512 struct list_head *domain;
513 struct list_head *group;
514 struct list_head *acl;
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900515 size_t avail;
516 unsigned int step;
517 unsigned int query_index;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900518 u16 index;
Tetsuo Handa2066a362011-07-08 13:21:37 +0900519 u16 cond_index;
Tetsuo Handa32997142011-06-26 23:19:28 +0900520 u8 acl_group_index;
Tetsuo Handa2066a362011-07-08 13:21:37 +0900521 u8 cond_step;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900522 u8 bit;
523 u8 w_pos;
524 bool eof;
525 bool print_this_domain_only;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900526 bool print_transition_related_only;
Tetsuo Handa2066a362011-07-08 13:21:37 +0900527 bool print_cond_part;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900528 const char *w[TOMOYO_MAX_IO_READ_QUEUE];
529 } r;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900530 struct {
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900531 struct tomoyo_policy_namespace *ns;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900532 /* The position currently writing to. */
533 struct tomoyo_domain_info *domain;
534 /* Bytes available for writing. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900535 size_t avail;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900536 bool is_delete;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900537 } w;
Kentaro Takeda95908372009-02-05 17:18:13 +0900538 /* Buffer for reading. */
539 char *read_buf;
Kentaro Takeda95908372009-02-05 17:18:13 +0900540 /* Size of read buffer. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900541 size_t readbuf_size;
Kentaro Takeda95908372009-02-05 17:18:13 +0900542 /* Buffer for writing. */
543 char *write_buf;
Kentaro Takeda95908372009-02-05 17:18:13 +0900544 /* Size of write buffer. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900545 size_t writebuf_size;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900546 /* Type of this interface. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900547 enum tomoyo_securityfs_interface_index type;
Tetsuo Handa2e503bb2011-06-26 23:20:55 +0900548 /* Users counter protected by tomoyo_io_buffer_list_lock. */
549 u8 users;
550 /* List for telling GC not to kfree() elements. */
551 struct list_head list;
Kentaro Takeda95908372009-02-05 17:18:13 +0900552};
553
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900554/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900555 * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
556 * "no_keep_domain" keyword.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900557 */
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900558struct tomoyo_transition_control {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900559 struct tomoyo_acl_head head;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900560 u8 type; /* One of values in "enum tomoyo_transition_type". */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900561 /* True if the domainname is tomoyo_get_last_name(). */
562 bool is_last_name;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900563 const struct tomoyo_path_info *domainname; /* Maybe NULL */
564 const struct tomoyo_path_info *program; /* Maybe NULL */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900565};
566
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900567/* Structure for "aggregator" keyword. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900568struct tomoyo_aggregator {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900569 struct tomoyo_acl_head head;
Tetsuo Handa10843072010-06-03 20:38:03 +0900570 const struct tomoyo_path_info *original_name;
571 const struct tomoyo_path_info *aggregated_name;
Tetsuo Handa10843072010-06-03 20:38:03 +0900572};
573
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900574/* Structure for policy manager. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900575struct tomoyo_manager {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900576 struct tomoyo_acl_head head;
577 bool is_domain; /* True if manager is a domainname. */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900578 /* A path to program or a domainname. */
579 const struct tomoyo_path_info *manager;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900580};
581
Tetsuo Handa57c25902010-06-03 20:38:44 +0900582struct tomoyo_preference {
583 unsigned int learning_max_entry;
584 bool enforcing_verbose;
585 bool learning_verbose;
586 bool permissive_verbose;
587};
588
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900589/* Structure for /sys/kernel/security/tomnoyo/profile interface. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900590struct tomoyo_profile {
591 const struct tomoyo_path_info *comment;
592 struct tomoyo_preference *learning;
593 struct tomoyo_preference *permissive;
594 struct tomoyo_preference *enforcing;
595 struct tomoyo_preference preference;
596 u8 default_config;
597 u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX];
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900598 unsigned int pref[TOMOYO_MAX_PREF];
Tetsuo Handa57c25902010-06-03 20:38:44 +0900599};
600
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900601/* Structure for representing YYYY/MM/DD hh/mm/ss. */
602struct tomoyo_time {
603 u16 year;
604 u8 month;
605 u8 day;
606 u8 hour;
607 u8 min;
608 u8 sec;
609};
610
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900611/* Structure for policy namespace. */
612struct tomoyo_policy_namespace {
613 /* Profile table. Memory is allocated as needed. */
614 struct tomoyo_profile *profile_ptr[TOMOYO_MAX_PROFILES];
615 /* List of "struct tomoyo_group". */
616 struct list_head group_list[TOMOYO_MAX_GROUP];
617 /* List of policy. */
618 struct list_head policy_list[TOMOYO_MAX_POLICY];
619 /* The global ACL referred by "use_group" keyword. */
620 struct list_head acl_group[TOMOYO_MAX_ACL_GROUPS];
621 /* List for connecting to tomoyo_namespace_list list. */
622 struct list_head namespace_list;
623 /* Profile version. Currently only 20100903 is defined. */
624 unsigned int profile_version;
625 /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */
626 const char *name;
627};
628
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900629/********** Function prototypes. **********/
630
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900631bool tomoyo_compare_number_union(const unsigned long value,
632 const struct tomoyo_number_union *ptr);
Tetsuo Handa2066a362011-07-08 13:21:37 +0900633bool tomoyo_condition(struct tomoyo_request_info *r,
634 const struct tomoyo_condition *cond);
Tetsuo Handa75093152010-06-16 16:23:55 +0900635bool tomoyo_correct_domain(const unsigned char *domainname);
Tetsuo Handa75093152010-06-16 16:23:55 +0900636bool tomoyo_correct_path(const char *filename);
637bool tomoyo_correct_word(const char *string);
Tetsuo Handa75093152010-06-16 16:23:55 +0900638bool tomoyo_domain_def(const unsigned char *buffer);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900639bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
640bool tomoyo_memory_ok(void *ptr);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900641bool tomoyo_number_matches_group(const unsigned long min,
642 const unsigned long max,
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900643 const struct tomoyo_group *group);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900644bool tomoyo_parse_name_union(struct tomoyo_acl_param *param,
645 struct tomoyo_name_union *ptr);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900646bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
647 struct tomoyo_number_union *ptr);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900648bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
649 const struct tomoyo_path_info *pattern);
650bool tomoyo_permstr(const char *string, const char *keyword);
651bool tomoyo_str_starts(char **src, const char *find);
652char *tomoyo_encode(const char *str);
653char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt,
654 va_list args);
655char *tomoyo_read_token(struct tomoyo_acl_param *param);
656char *tomoyo_realpath_from_path(struct path *path);
657char *tomoyo_realpath_nofollow(const char *pathname);
658const char *tomoyo_get_exe(void);
659const char *tomoyo_yesno(const unsigned int value);
660const struct tomoyo_path_info *tomoyo_compare_name_union
661(const struct tomoyo_path_info *name, const struct tomoyo_name_union *ptr);
662const struct tomoyo_path_info *tomoyo_get_name(const char *name);
663const struct tomoyo_path_info *tomoyo_path_matches_group
664(const struct tomoyo_path_info *pathname, const struct tomoyo_group *group);
665int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
666 struct path *path, const int flag);
667int tomoyo_close_control(struct tomoyo_io_buffer *head);
668int tomoyo_find_next_domain(struct linux_binprm *bprm);
669int tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile,
670 const u8 index);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900671int tomoyo_init_request_info(struct tomoyo_request_info *r,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900672 struct tomoyo_domain_info *domain,
673 const u8 index);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900674int tomoyo_mkdev_perm(const u8 operation, struct path *path,
675 const unsigned int mode, unsigned int dev);
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900676int tomoyo_mount_permission(char *dev_name, struct path *path,
677 const char *type, unsigned long flags,
678 void *data_page);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900679int tomoyo_open_control(const u8 type, struct file *file);
Tetsuo Handa97d69312010-02-16 09:46:15 +0900680int tomoyo_path2_perm(const u8 operation, struct path *path1,
681 struct path *path2);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900682int tomoyo_path_number_perm(const u8 operation, struct path *path,
683 unsigned long number);
684int tomoyo_path_perm(const u8 operation, struct path *path);
685int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
686 const struct tomoyo_path_info *filename);
687int tomoyo_poll_control(struct file *file, poll_table *wait);
688int tomoyo_poll_log(struct file *file, poll_table *wait);
689int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
690 __printf(2, 3);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900691int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900692 struct tomoyo_acl_param *param,
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900693 bool (*check_duplicate)
694 (const struct tomoyo_acl_info *,
695 const struct tomoyo_acl_info *),
696 bool (*merge_duplicate)
697 (struct tomoyo_acl_info *, struct tomoyo_acl_info *,
698 const bool));
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900699int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900700 struct tomoyo_acl_param *param,
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900701 bool (*check_duplicate)
702 (const struct tomoyo_acl_head *,
703 const struct tomoyo_acl_head *));
704int tomoyo_write_aggregator(struct tomoyo_acl_param *param);
705int tomoyo_write_file(struct tomoyo_acl_param *param);
706int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type);
707int tomoyo_write_transition_control(struct tomoyo_acl_param *param,
708 const u8 type);
709ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer,
710 const int buffer_len);
711ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,
712 const char __user *buffer, const int buffer_len);
Tetsuo Handa2066a362011-07-08 13:21:37 +0900713struct tomoyo_condition *tomoyo_get_condition(struct tomoyo_acl_param *param);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900714struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
715 const bool transit);
716struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
717struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param,
718 const u8 idx);
719struct tomoyo_policy_namespace *tomoyo_assign_namespace
720(const char *domainname);
721struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns,
722 const u8 profile);
723unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
724 const u8 index);
Tetsuo Handa2066a362011-07-08 13:21:37 +0900725u8 tomoyo_parse_ulong(unsigned long *result, char **str);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900726void *tomoyo_commit_ok(void *data, const unsigned int size);
727void __init tomoyo_load_builtin_policy(void);
728void __init tomoyo_mm_init(void);
Tetsuo Handa99a85252010-06-16 16:22:51 +0900729void tomoyo_check_acl(struct tomoyo_request_info *r,
Tetsuo Handa484ca792010-07-29 14:29:55 +0900730 bool (*check_entry) (struct tomoyo_request_info *,
Tetsuo Handa99a85252010-06-16 16:22:51 +0900731 const struct tomoyo_acl_info *));
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900732void tomoyo_check_profile(void);
733void tomoyo_convert_time(time_t time, struct tomoyo_time *stamp);
Tetsuo Handa2066a362011-07-08 13:21:37 +0900734void tomoyo_del_condition(struct list_head *element);
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900735void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
736void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns);
737void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
738 __printf(2, 3);
739void tomoyo_load_policy(const char *filename);
740void tomoyo_memory_free(void *ptr);
741void tomoyo_normalize_line(unsigned char *buffer);
742void tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register);
743void tomoyo_print_ulong(char *buffer, const int buffer_len,
744 const unsigned long value, const u8 type);
745void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
746void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
747void tomoyo_read_log(struct tomoyo_io_buffer *head);
748void tomoyo_update_stat(const u8 index);
749void tomoyo_warn_oom(const char *function);
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900750void tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...)
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900751 __printf(2, 3);
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900752void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
753 va_list args);
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900754
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900755/********** External variable definitions. **********/
756
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900757extern bool tomoyo_policy_loaded;
Tetsuo Handa2066a362011-07-08 13:21:37 +0900758extern const char * const tomoyo_condition_keyword
759[TOMOYO_MAX_CONDITION_KEYWORD];
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900760extern const char * const tomoyo_dif[TOMOYO_MAX_DOMAIN_INFO_FLAGS];
761extern const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX
762 + TOMOYO_MAX_MAC_CATEGORY_INDEX];
763extern const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE];
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900764extern const char * const tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
765extern const u8 tomoyo_index2category[TOMOYO_MAX_MAC_INDEX];
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900766extern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION];
Tetsuo Handa0d2171d2011-06-26 23:17:46 +0900767extern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION];
768extern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION];
Tetsuo Handa2066a362011-07-08 13:21:37 +0900769extern struct list_head tomoyo_condition_list;
Tetsuo Handa3ddf17f2011-06-29 14:22:37 +0900770extern struct list_head tomoyo_domain_list;
771extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
772extern struct list_head tomoyo_namespace_list;
773extern struct mutex tomoyo_policy_lock;
774extern struct srcu_struct tomoyo_ss;
775extern struct tomoyo_domain_info tomoyo_kernel_domain;
776extern struct tomoyo_policy_namespace tomoyo_kernel_namespace;
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900777extern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT];
778extern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT];
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900779
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900780/********** Inlined functions. **********/
781
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900782/**
783 * tomoyo_read_lock - Take lock for protecting policy.
784 *
785 * Returns index number for tomoyo_read_unlock().
786 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900787static inline int tomoyo_read_lock(void)
788{
789 return srcu_read_lock(&tomoyo_ss);
790}
791
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900792/**
793 * tomoyo_read_unlock - Release lock for protecting policy.
794 *
795 * @idx: Index number returned by tomoyo_read_lock().
796 *
797 * Returns nothing.
798 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900799static inline void tomoyo_read_unlock(int idx)
800{
801 srcu_read_unlock(&tomoyo_ss, idx);
802}
803
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900804/**
Tetsuo Handa2066a362011-07-08 13:21:37 +0900805 * tomoyo_sys_getppid - Copy of getppid().
806 *
807 * Returns parent process's PID.
808 *
809 * Alpha does not have getppid() defined. To be able to build this module on
810 * Alpha, I have to copy getppid() from kernel/timer.c.
811 */
812static inline pid_t tomoyo_sys_getppid(void)
813{
814 pid_t pid;
815 rcu_read_lock();
816 pid = task_tgid_vnr(current->real_parent);
817 rcu_read_unlock();
818 return pid;
819}
820
821/**
822 * tomoyo_sys_getpid - Copy of getpid().
823 *
824 * Returns current thread's PID.
825 *
826 * Alpha does not have getpid() defined. To be able to build this module on
827 * Alpha, I have to copy getpid() from kernel/timer.c.
828 */
829static inline pid_t tomoyo_sys_getpid(void)
830{
831 return task_tgid_vnr(current);
832}
833
834/**
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900835 * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
836 *
837 * @a: Pointer to "struct tomoyo_path_info".
838 * @b: Pointer to "struct tomoyo_path_info".
839 *
840 * Returns true if @a == @b, false otherwise.
841 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900842static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
843 const struct tomoyo_path_info *b)
844{
845 return a->hash != b->hash || strcmp(a->name, b->name);
846}
847
Kentaro Takeda95908372009-02-05 17:18:13 +0900848/**
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900849 * tomoyo_put_name - Drop reference on "struct tomoyo_name".
850 *
851 * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
852 *
853 * Returns nothing.
854 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900855static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
856{
857 if (name) {
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900858 struct tomoyo_name *ptr =
859 container_of(name, typeof(*ptr), entry);
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900860 atomic_dec(&ptr->head.users);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900861 }
862}
Kentaro Takeda95908372009-02-05 17:18:13 +0900863
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900864/**
Tetsuo Handa2066a362011-07-08 13:21:37 +0900865 * tomoyo_put_condition - Drop reference on "struct tomoyo_condition".
866 *
867 * @cond: Pointer to "struct tomoyo_condition". Maybe NULL.
868 *
869 * Returns nothing.
870 */
871static inline void tomoyo_put_condition(struct tomoyo_condition *cond)
872{
873 if (cond)
874 atomic_dec(&cond->head.users);
875}
876
877/**
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900878 * tomoyo_put_group - Drop reference on "struct tomoyo_group".
879 *
880 * @group: Pointer to "struct tomoyo_group". Maybe NULL.
881 *
882 * Returns nothing.
883 */
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900884static inline void tomoyo_put_group(struct tomoyo_group *group)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900885{
886 if (group)
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900887 atomic_dec(&group->head.users);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900888}
889
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900890/**
891 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
892 *
893 * Returns pointer to "struct tomoyo_domain_info" for current thread.
894 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900895static inline struct tomoyo_domain_info *tomoyo_domain(void)
896{
897 return current_cred()->security;
898}
Kentaro Takeda95908372009-02-05 17:18:13 +0900899
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900900/**
901 * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
902 *
903 * @task: Pointer to "struct task_struct".
904 *
905 * Returns pointer to "struct tomoyo_security" for specified thread.
906 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900907static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
908 *task)
909{
910 return task_cred_xxx(task, security);
911}
Kentaro Takeda95908372009-02-05 17:18:13 +0900912
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900913/**
914 * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
915 *
916 * @a: Pointer to "struct tomoyo_name_union".
917 * @b: Pointer to "struct tomoyo_name_union".
918 *
919 * Returns true if @a == @b, false otherwise.
920 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900921static inline bool tomoyo_same_name_union
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900922(const struct tomoyo_name_union *a, const struct tomoyo_name_union *b)
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900923{
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900924 return a->filename == b->filename && a->group == b->group;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900925}
926
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900927/**
928 * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
929 *
930 * @a: Pointer to "struct tomoyo_number_union".
931 * @b: Pointer to "struct tomoyo_number_union".
932 *
933 * Returns true if @a == @b, false otherwise.
934 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900935static inline bool tomoyo_same_number_union
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900936(const struct tomoyo_number_union *a, const struct tomoyo_number_union *b)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900937{
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900938 return a->values[0] == b->values[0] && a->values[1] == b->values[1] &&
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900939 a->group == b->group && a->value_type[0] == b->value_type[0] &&
940 a->value_type[1] == b->value_type[1];
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900941}
942
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900943/**
944 * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread.
945 *
946 * Returns pointer to "struct tomoyo_policy_namespace" for current thread.
947 */
948static inline struct tomoyo_policy_namespace *tomoyo_current_namespace(void)
949{
950 return tomoyo_domain()->ns;
951}
952
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900953#if defined(CONFIG_SLOB)
954
955/**
956 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
957 *
958 * @size: Size to be rounded up.
959 *
960 * Returns @size.
961 *
962 * Since SLOB does not round up, this function simply returns @size.
963 */
964static inline int tomoyo_round2(size_t size)
965{
966 return size;
967}
968
969#else
970
971/**
972 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
973 *
974 * @size: Size to be rounded up.
975 *
976 * Returns rounded size.
977 *
978 * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of
979 * (e.g.) 128 bytes.
980 */
981static inline int tomoyo_round2(size_t size)
982{
983#if PAGE_SIZE == 4096
984 size_t bsize = 32;
985#else
986 size_t bsize = 64;
987#endif
988 if (!size)
989 return 0;
990 while (size > bsize)
991 bsize <<= 1;
992 return bsize;
993}
994
995#endif
996
Kentaro Takeda95908372009-02-05 17:18:13 +0900997/**
998 * list_for_each_cookie - iterate over a list with cookie.
999 * @pos: the &struct list_head to use as a loop cursor.
Kentaro Takeda95908372009-02-05 17:18:13 +09001000 * @head: the head for your list.
Kentaro Takeda95908372009-02-05 17:18:13 +09001001 */
Tetsuo Handa475e6fa2010-06-24 11:28:14 +09001002#define list_for_each_cookie(pos, head) \
1003 if (!pos) \
1004 pos = srcu_dereference((head)->next, &tomoyo_ss); \
1005 for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +09001006
Kentaro Takeda95908372009-02-05 17:18:13 +09001007#endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */