blob: b54455dfe0ca286980c33c03182d86b04b497d28 [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 Handa76bb0892010-02-11 09:42:40 +090024struct linux_binprm;
Kentaro Takeda95908372009-02-05 17:18:13 +090025
Tetsuo Handa76bb0892010-02-11 09:42:40 +090026/********** Constants definitions. **********/
27
28/*
29 * TOMOYO uses this hash only when appending a string into the string
30 * table. Frequency of appending strings is very low. So we don't need
31 * large (e.g. 64k) hash size. 256 will be sufficient.
32 */
33#define TOMOYO_HASH_BITS 8
34#define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS)
35
Tetsuo Handac8c57e82010-06-03 20:36:43 +090036#define TOMOYO_EXEC_TMPSIZE 4096
Tetsuo Handa76bb0892010-02-11 09:42:40 +090037
38/* Profile number is an integer between 0 and 255. */
39#define TOMOYO_MAX_PROFILES 256
40
Tetsuo Handa32997142011-06-26 23:19:28 +090041/* Group number is an integer between 0 and 255. */
42#define TOMOYO_MAX_ACL_GROUPS 256
43
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090044/* Index numbers for operation mode. */
Tetsuo Handacb0abe62010-05-17 10:08:05 +090045enum tomoyo_mode_index {
46 TOMOYO_CONFIG_DISABLED,
47 TOMOYO_CONFIG_LEARNING,
48 TOMOYO_CONFIG_PERMISSIVE,
Tetsuo Handa57c25902010-06-03 20:38:44 +090049 TOMOYO_CONFIG_ENFORCING,
Tetsuo Handaeadd99c2011-06-26 23:18:58 +090050 TOMOYO_CONFIG_MAX_MODE,
51 TOMOYO_CONFIG_WANT_REJECT_LOG = 64,
52 TOMOYO_CONFIG_WANT_GRANT_LOG = 128,
53 TOMOYO_CONFIG_USE_DEFAULT = 255,
Tetsuo Handacb0abe62010-05-17 10:08:05 +090054};
55
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090056/* Index numbers for entry type. */
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090057enum tomoyo_policy_id {
58 TOMOYO_ID_GROUP,
59 TOMOYO_ID_PATH_GROUP,
60 TOMOYO_ID_NUMBER_GROUP,
Tetsuo Handa5448ec42010-06-21 11:14:39 +090061 TOMOYO_ID_TRANSITION_CONTROL,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090062 TOMOYO_ID_AGGREGATOR,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090063 TOMOYO_ID_MANAGER,
64 TOMOYO_ID_NAME,
65 TOMOYO_ID_ACL,
66 TOMOYO_ID_DOMAIN,
67 TOMOYO_MAX_POLICY
68};
69
Tetsuo Handa2c47ab92011-06-26 23:21:19 +090070/* Index numbers for domain's attributes. */
71enum tomoyo_domain_info_flags_index {
72 /* Quota warnning flag. */
73 TOMOYO_DIF_QUOTA_WARNED,
74 /*
75 * This domain was unable to create a new domain at
76 * tomoyo_find_next_domain() because the name of the domain to be
77 * created was too long or it could not allocate memory.
78 * More than one process continued execve() without domain transition.
79 */
80 TOMOYO_DIF_TRANSITION_FAILED,
81 TOMOYO_MAX_DOMAIN_INFO_FLAGS
82};
83
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090084/* Index numbers for group entries. */
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090085enum tomoyo_group_id {
86 TOMOYO_PATH_GROUP,
87 TOMOYO_NUMBER_GROUP,
88 TOMOYO_MAX_GROUP
89};
90
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090091/* Index numbers for type of numeric values. */
92enum tomoyo_value_type {
93 TOMOYO_VALUE_TYPE_INVALID,
94 TOMOYO_VALUE_TYPE_DECIMAL,
95 TOMOYO_VALUE_TYPE_OCTAL,
96 TOMOYO_VALUE_TYPE_HEXADECIMAL,
97};
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +090098
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090099/* Index numbers for domain transition control keywords. */
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900100enum tomoyo_transition_type {
101 /* Do not change this order, */
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900102 TOMOYO_TRANSITION_CONTROL_NO_RESET,
103 TOMOYO_TRANSITION_CONTROL_RESET,
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900104 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE,
105 TOMOYO_TRANSITION_CONTROL_INITIALIZE,
106 TOMOYO_TRANSITION_CONTROL_NO_KEEP,
107 TOMOYO_TRANSITION_CONTROL_KEEP,
108 TOMOYO_MAX_TRANSITION_TYPE
109};
110
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900111/* Index numbers for Access Controls. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900112enum tomoyo_acl_entry_type_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900113 TOMOYO_TYPE_PATH_ACL,
114 TOMOYO_TYPE_PATH2_ACL,
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900115 TOMOYO_TYPE_PATH_NUMBER_ACL,
Tetsuo Handa75093152010-06-16 16:23:55 +0900116 TOMOYO_TYPE_MKDEV_ACL,
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900117 TOMOYO_TYPE_MOUNT_ACL,
Tetsuo Handa084da352010-02-15 15:10:39 +0900118};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900119
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900120/* Index numbers for access controls with one pathname. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900121enum tomoyo_path_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900122 TOMOYO_TYPE_EXECUTE,
123 TOMOYO_TYPE_READ,
124 TOMOYO_TYPE_WRITE,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900125 TOMOYO_TYPE_APPEND,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900126 TOMOYO_TYPE_UNLINK,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900127 TOMOYO_TYPE_GETATTR,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900128 TOMOYO_TYPE_RMDIR,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900129 TOMOYO_TYPE_TRUNCATE,
130 TOMOYO_TYPE_SYMLINK,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900131 TOMOYO_TYPE_CHROOT,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900132 TOMOYO_TYPE_UMOUNT,
133 TOMOYO_MAX_PATH_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900134};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900135
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900136enum tomoyo_memory_stat_type {
137 TOMOYO_MEMORY_POLICY,
138 TOMOYO_MEMORY_AUDIT,
139 TOMOYO_MEMORY_QUERY,
140 TOMOYO_MAX_MEMORY_STAT
141};
142
Tetsuo Handa75093152010-06-16 16:23:55 +0900143enum tomoyo_mkdev_acl_index {
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900144 TOMOYO_TYPE_MKBLOCK,
145 TOMOYO_TYPE_MKCHAR,
Tetsuo Handa75093152010-06-16 16:23:55 +0900146 TOMOYO_MAX_MKDEV_OPERATION
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900147};
148
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900149/* Index numbers for access controls with two pathnames. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900150enum tomoyo_path2_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900151 TOMOYO_TYPE_LINK,
152 TOMOYO_TYPE_RENAME,
153 TOMOYO_TYPE_PIVOT_ROOT,
154 TOMOYO_MAX_PATH2_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900155};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900156
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900157/* Index numbers for access controls with one pathname and one number. */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900158enum tomoyo_path_number_acl_index {
159 TOMOYO_TYPE_CREATE,
160 TOMOYO_TYPE_MKDIR,
161 TOMOYO_TYPE_MKFIFO,
162 TOMOYO_TYPE_MKSOCK,
163 TOMOYO_TYPE_IOCTL,
164 TOMOYO_TYPE_CHMOD,
165 TOMOYO_TYPE_CHOWN,
166 TOMOYO_TYPE_CHGRP,
167 TOMOYO_MAX_PATH_NUMBER_OPERATION
168};
169
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900170/* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900171enum tomoyo_securityfs_interface_index {
172 TOMOYO_DOMAINPOLICY,
173 TOMOYO_EXCEPTIONPOLICY,
174 TOMOYO_DOMAIN_STATUS,
175 TOMOYO_PROCESS_STATUS,
176 TOMOYO_MEMINFO,
177 TOMOYO_SELFDOMAIN,
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900178 TOMOYO_AUDIT,
Tetsuo Handa084da352010-02-15 15:10:39 +0900179 TOMOYO_VERSION,
180 TOMOYO_PROFILE,
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900181 TOMOYO_QUERY,
Tetsuo Handa084da352010-02-15 15:10:39 +0900182 TOMOYO_MANAGER
183};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900184
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900185/* Index numbers for special mount operations. */
186enum tomoyo_special_mount {
187 TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */
188 TOMOYO_MOUNT_MOVE, /* mount --move /old /new */
189 TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */
190 TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */
191 TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */
192 TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */
193 TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */
194 TOMOYO_MAX_SPECIAL_MOUNT
195};
196
197/* Index numbers for functionality. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900198enum tomoyo_mac_index {
199 TOMOYO_MAC_FILE_EXECUTE,
200 TOMOYO_MAC_FILE_OPEN,
201 TOMOYO_MAC_FILE_CREATE,
202 TOMOYO_MAC_FILE_UNLINK,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900203 TOMOYO_MAC_FILE_GETATTR,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900204 TOMOYO_MAC_FILE_MKDIR,
205 TOMOYO_MAC_FILE_RMDIR,
206 TOMOYO_MAC_FILE_MKFIFO,
207 TOMOYO_MAC_FILE_MKSOCK,
208 TOMOYO_MAC_FILE_TRUNCATE,
209 TOMOYO_MAC_FILE_SYMLINK,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900210 TOMOYO_MAC_FILE_MKBLOCK,
211 TOMOYO_MAC_FILE_MKCHAR,
212 TOMOYO_MAC_FILE_LINK,
213 TOMOYO_MAC_FILE_RENAME,
214 TOMOYO_MAC_FILE_CHMOD,
215 TOMOYO_MAC_FILE_CHOWN,
216 TOMOYO_MAC_FILE_CHGRP,
217 TOMOYO_MAC_FILE_IOCTL,
218 TOMOYO_MAC_FILE_CHROOT,
219 TOMOYO_MAC_FILE_MOUNT,
220 TOMOYO_MAC_FILE_UMOUNT,
221 TOMOYO_MAC_FILE_PIVOT_ROOT,
222 TOMOYO_MAX_MAC_INDEX
223};
224
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900225/* Index numbers for category of functionality. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900226enum tomoyo_mac_category_index {
227 TOMOYO_MAC_CATEGORY_FILE,
228 TOMOYO_MAX_MAC_CATEGORY_INDEX
229};
230
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900231/*
232 * Retry this request. Returned by tomoyo_supervisor() if policy violation has
233 * occurred in enforcing mode and the userspace daemon decided to retry.
234 *
235 * We must choose a positive value in order to distinguish "granted" (which is
236 * 0) and "rejected" (which is a negative value) and "retry".
237 */
238#define TOMOYO_RETRY_REQUEST 1
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900239
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900240/* Index numbers for profile's PREFERENCE values. */
241enum tomoyo_pref_index {
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900242 TOMOYO_PREF_MAX_AUDIT_LOG,
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900243 TOMOYO_PREF_MAX_LEARNING_ENTRY,
244 TOMOYO_MAX_PREF
245};
246
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900247/********** Structure definitions. **********/
Kentaro Takeda95908372009-02-05 17:18:13 +0900248
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900249/* Common header for holding ACL entries. */
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900250struct tomoyo_acl_head {
251 struct list_head list;
252 bool is_deleted;
253} __packed;
254
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900255/* Common header for shared entries. */
256struct tomoyo_shared_acl_head {
257 struct list_head list;
258 atomic_t users;
259} __packed;
260
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900261struct tomoyo_policy_namespace;
262
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900263/* Structure for request info. */
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900264struct tomoyo_request_info {
265 struct tomoyo_domain_info *domain;
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900266 /* For holding parameters. */
267 union {
268 struct {
269 const struct tomoyo_path_info *filename;
Tetsuo Handa484ca792010-07-29 14:29:55 +0900270 /* For using wildcards at tomoyo_find_next_domain(). */
271 const struct tomoyo_path_info *matched_path;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900272 /* One of values in "enum tomoyo_path_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900273 u8 operation;
274 } path;
275 struct {
276 const struct tomoyo_path_info *filename1;
277 const struct tomoyo_path_info *filename2;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900278 /* One of values in "enum tomoyo_path2_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900279 u8 operation;
280 } path2;
281 struct {
282 const struct tomoyo_path_info *filename;
283 unsigned int mode;
284 unsigned int major;
285 unsigned int minor;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900286 /* One of values in "enum tomoyo_mkdev_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900287 u8 operation;
288 } mkdev;
289 struct {
290 const struct tomoyo_path_info *filename;
291 unsigned long number;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900292 /*
293 * One of values in
294 * "enum tomoyo_path_number_acl_index".
295 */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900296 u8 operation;
297 } path_number;
298 struct {
299 const struct tomoyo_path_info *type;
300 const struct tomoyo_path_info *dir;
301 const struct tomoyo_path_info *dev;
302 unsigned long flags;
303 int need_dev;
304 } mount;
305 } param;
306 u8 param_type;
307 bool granted;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900308 u8 retry;
309 u8 profile;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900310 u8 mode; /* One of tomoyo_mode_index . */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900311 u8 type;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900312};
313
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900314/* Structure for holding a token. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900315struct tomoyo_path_info {
316 const char *name;
317 u32 hash; /* = full_name_hash(name, strlen(name)) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900318 u16 const_len; /* = tomoyo_const_part_length(name) */
319 bool is_dir; /* = tomoyo_strendswith(name, "/") */
320 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900321};
322
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900323/* Structure for holding string data. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900324struct tomoyo_name {
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900325 struct tomoyo_shared_acl_head head;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900326 struct tomoyo_path_info entry;
327};
Kentaro Takeda95908372009-02-05 17:18:13 +0900328
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900329/* Structure for holding a word. */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900330struct tomoyo_name_union {
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900331 /* Either @filename or @group is NULL. */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900332 const struct tomoyo_path_info *filename;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900333 struct tomoyo_group *group;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900334};
335
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900336/* Structure for holding a number. */
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900337struct tomoyo_number_union {
338 unsigned long values[2];
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900339 struct tomoyo_group *group; /* Maybe NULL. */
340 /* One of values in "enum tomoyo_value_type". */
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900341 u8 value_type[2];
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900342};
343
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900344/* Structure for "path_group"/"number_group" directive. */
345struct tomoyo_group {
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900346 struct tomoyo_shared_acl_head head;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900347 const struct tomoyo_path_info *group_name;
348 struct list_head member_list;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900349};
350
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900351/* Structure for "path_group" directive. */
352struct tomoyo_path_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900353 struct tomoyo_acl_head head;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900354 const struct tomoyo_path_info *member_name;
355};
356
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900357/* Structure for "number_group" directive. */
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900358struct tomoyo_number_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900359 struct tomoyo_acl_head head;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900360 struct tomoyo_number_union number;
361};
362
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900363/* Common header for individual entries. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900364struct tomoyo_acl_info {
365 struct list_head list;
Tetsuo Handa237ab452010-06-12 20:46:22 +0900366 bool is_deleted;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900367 u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */
Kentaro Takeda95908372009-02-05 17:18:13 +0900368} __packed;
369
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900370/* Structure for domain information. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900371struct tomoyo_domain_info {
372 struct list_head list;
373 struct list_head acl_info_list;
374 /* Name of this domain. Never NULL. */
375 const struct tomoyo_path_info *domainname;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900376 /* Namespace for this domain. Never NULL. */
377 struct tomoyo_policy_namespace *ns;
Kentaro Takeda95908372009-02-05 17:18:13 +0900378 u8 profile; /* Profile number to use. */
Tetsuo Handa32997142011-06-26 23:19:28 +0900379 u8 group; /* Group number to use. */
Tetsuo Handaa0558fc2009-04-06 20:49:14 +0900380 bool is_deleted; /* Delete flag. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900381 bool flags[TOMOYO_MAX_DOMAIN_INFO_FLAGS];
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900382 atomic_t users; /* Number of referring credentials. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900383};
384
Kentaro Takeda95908372009-02-05 17:18:13 +0900385/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900386 * Structure for "file execute", "file read", "file write", "file append",
387 * "file unlink", "file getattr", "file rmdir", "file truncate",
388 * "file symlink", "file chroot" and "file unmount" directive.
Kentaro Takeda95908372009-02-05 17:18:13 +0900389 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900390struct tomoyo_path_acl {
391 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900392 u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900393 struct tomoyo_name_union name;
Kentaro Takeda95908372009-02-05 17:18:13 +0900394};
395
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900396/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900397 * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
398 * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900399 */
400struct tomoyo_path_number_acl {
401 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900402 /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900403 u8 perm;
404 struct tomoyo_name_union name;
405 struct tomoyo_number_union number;
406};
407
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900408/* Structure for "file mkblock" and "file mkchar" directive. */
Tetsuo Handa75093152010-06-16 16:23:55 +0900409struct tomoyo_mkdev_acl {
410 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900411 u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900412 struct tomoyo_name_union name;
413 struct tomoyo_number_union mode;
414 struct tomoyo_number_union major;
415 struct tomoyo_number_union minor;
416};
417
418/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900419 * Structure for "file rename", "file link" and "file pivot_root" directive.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900420 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900421struct tomoyo_path2_acl {
422 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900423 u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900424 struct tomoyo_name_union name1;
425 struct tomoyo_name_union name2;
Kentaro Takeda95908372009-02-05 17:18:13 +0900426};
427
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900428/* Structure for "file mount" directive. */
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900429struct tomoyo_mount_acl {
430 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900431 struct tomoyo_name_union dev_name;
432 struct tomoyo_name_union dir_name;
433 struct tomoyo_name_union fs_type;
434 struct tomoyo_number_union flags;
435};
436
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900437/* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
438struct tomoyo_acl_param {
439 char *data;
440 struct list_head *list;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900441 struct tomoyo_policy_namespace *ns;
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900442 bool is_delete;
443};
444
Tetsuo Handa0d2171d2011-06-26 23:17:46 +0900445#define TOMOYO_MAX_IO_READ_QUEUE 64
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900446
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900447/*
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900448 * Structure for reading/writing policy via /sys/kernel/security/tomoyo
449 * interfaces.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900450 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900451struct tomoyo_io_buffer {
Tetsuo Handa8fbe71f2010-06-16 16:29:59 +0900452 void (*read) (struct tomoyo_io_buffer *);
Kentaro Takeda95908372009-02-05 17:18:13 +0900453 int (*write) (struct tomoyo_io_buffer *);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900454 int (*poll) (struct file *file, poll_table *wait);
Kentaro Takeda95908372009-02-05 17:18:13 +0900455 /* Exclusive lock for this structure. */
456 struct mutex io_sem;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900457 char __user *read_user_buf;
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900458 size_t read_user_buf_avail;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900459 struct {
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900460 struct list_head *ns;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900461 struct list_head *domain;
462 struct list_head *group;
463 struct list_head *acl;
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900464 size_t avail;
465 unsigned int step;
466 unsigned int query_index;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900467 u16 index;
Tetsuo Handa32997142011-06-26 23:19:28 +0900468 u8 acl_group_index;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900469 u8 bit;
470 u8 w_pos;
471 bool eof;
472 bool print_this_domain_only;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900473 bool print_transition_related_only;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900474 const char *w[TOMOYO_MAX_IO_READ_QUEUE];
475 } r;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900476 struct {
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900477 struct tomoyo_policy_namespace *ns;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900478 /* The position currently writing to. */
479 struct tomoyo_domain_info *domain;
480 /* Bytes available for writing. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900481 size_t avail;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900482 bool is_delete;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900483 } w;
Kentaro Takeda95908372009-02-05 17:18:13 +0900484 /* Buffer for reading. */
485 char *read_buf;
Kentaro Takeda95908372009-02-05 17:18:13 +0900486 /* Size of read buffer. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900487 size_t readbuf_size;
Kentaro Takeda95908372009-02-05 17:18:13 +0900488 /* Buffer for writing. */
489 char *write_buf;
Kentaro Takeda95908372009-02-05 17:18:13 +0900490 /* Size of write buffer. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900491 size_t writebuf_size;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900492 /* Type of this interface. */
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900493 enum tomoyo_securityfs_interface_index type;
Tetsuo Handa2e503bb2011-06-26 23:20:55 +0900494 /* Users counter protected by tomoyo_io_buffer_list_lock. */
495 u8 users;
496 /* List for telling GC not to kfree() elements. */
497 struct list_head list;
Kentaro Takeda95908372009-02-05 17:18:13 +0900498};
499
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900500/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900501 * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
502 * "no_keep_domain" keyword.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900503 */
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900504struct tomoyo_transition_control {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900505 struct tomoyo_acl_head head;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900506 u8 type; /* One of values in "enum tomoyo_transition_type". */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900507 /* True if the domainname is tomoyo_get_last_name(). */
508 bool is_last_name;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900509 const struct tomoyo_path_info *domainname; /* Maybe NULL */
510 const struct tomoyo_path_info *program; /* Maybe NULL */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900511};
512
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900513/* Structure for "aggregator" keyword. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900514struct tomoyo_aggregator {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900515 struct tomoyo_acl_head head;
Tetsuo Handa10843072010-06-03 20:38:03 +0900516 const struct tomoyo_path_info *original_name;
517 const struct tomoyo_path_info *aggregated_name;
Tetsuo Handa10843072010-06-03 20:38:03 +0900518};
519
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900520/* Structure for policy manager. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900521struct tomoyo_manager {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900522 struct tomoyo_acl_head head;
523 bool is_domain; /* True if manager is a domainname. */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900524 /* A path to program or a domainname. */
525 const struct tomoyo_path_info *manager;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900526};
527
Tetsuo Handa57c25902010-06-03 20:38:44 +0900528struct tomoyo_preference {
529 unsigned int learning_max_entry;
530 bool enforcing_verbose;
531 bool learning_verbose;
532 bool permissive_verbose;
533};
534
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900535/* Structure for /sys/kernel/security/tomnoyo/profile interface. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900536struct tomoyo_profile {
537 const struct tomoyo_path_info *comment;
538 struct tomoyo_preference *learning;
539 struct tomoyo_preference *permissive;
540 struct tomoyo_preference *enforcing;
541 struct tomoyo_preference preference;
542 u8 default_config;
543 u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX];
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900544 unsigned int pref[TOMOYO_MAX_PREF];
Tetsuo Handa57c25902010-06-03 20:38:44 +0900545};
546
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900547/* Structure for representing YYYY/MM/DD hh/mm/ss. */
548struct tomoyo_time {
549 u16 year;
550 u8 month;
551 u8 day;
552 u8 hour;
553 u8 min;
554 u8 sec;
555};
556
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900557/* Structure for policy namespace. */
558struct tomoyo_policy_namespace {
559 /* Profile table. Memory is allocated as needed. */
560 struct tomoyo_profile *profile_ptr[TOMOYO_MAX_PROFILES];
561 /* List of "struct tomoyo_group". */
562 struct list_head group_list[TOMOYO_MAX_GROUP];
563 /* List of policy. */
564 struct list_head policy_list[TOMOYO_MAX_POLICY];
565 /* The global ACL referred by "use_group" keyword. */
566 struct list_head acl_group[TOMOYO_MAX_ACL_GROUPS];
567 /* List for connecting to tomoyo_namespace_list list. */
568 struct list_head namespace_list;
569 /* Profile version. Currently only 20100903 is defined. */
570 unsigned int profile_version;
571 /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */
572 const char *name;
573};
574
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900575/********** Function prototypes. **********/
576
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900577void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900578bool tomoyo_str_starts(char **src, const char *find);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900579const char *tomoyo_get_exe(void);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900580void tomoyo_normalize_line(unsigned char *buffer);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900581void tomoyo_check_profile(void);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900582int tomoyo_open_control(const u8 type, struct file *file);
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900583int tomoyo_close_control(struct tomoyo_io_buffer *head);
Tetsuo Handa0849e3b2010-06-25 12:22:09 +0900584int tomoyo_poll_control(struct file *file, poll_table *wait);
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900585ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer,
586 const int buffer_len);
587ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,
588 const char __user *buffer, const int buffer_len);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900589bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900590void tomoyo_warn_oom(const char *function);
Tetsuo Handa484ca792010-07-29 14:29:55 +0900591const struct tomoyo_path_info *
592tomoyo_compare_name_union(const struct tomoyo_path_info *name,
593 const struct tomoyo_name_union *ptr);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900594bool tomoyo_compare_number_union(const unsigned long value,
595 const struct tomoyo_number_union *ptr);
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900596int tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile,
597 const u8 index);
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900598void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
Kentaro Takeda95908372009-02-05 17:18:13 +0900599 __attribute__ ((format(printf, 2, 3)));
Tetsuo Handa75093152010-06-16 16:23:55 +0900600bool tomoyo_correct_domain(const unsigned char *domainname);
Tetsuo Handa75093152010-06-16 16:23:55 +0900601bool tomoyo_correct_path(const char *filename);
602bool tomoyo_correct_word(const char *string);
Tetsuo Handa75093152010-06-16 16:23:55 +0900603bool tomoyo_domain_def(const unsigned char *buffer);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900604bool tomoyo_parse_name_union(struct tomoyo_acl_param *param,
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900605 struct tomoyo_name_union *ptr);
Tetsuo Handa484ca792010-07-29 14:29:55 +0900606const struct tomoyo_path_info *
607tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
608 const struct tomoyo_group *group);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900609bool tomoyo_number_matches_group(const unsigned long min,
610 const unsigned long max,
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900611 const struct tomoyo_group *group);
Kentaro Takeda95908372009-02-05 17:18:13 +0900612bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
613 const struct tomoyo_path_info *pattern);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900614bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
615 struct tomoyo_number_union *ptr);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900616bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
Kentaro Takeda95908372009-02-05 17:18:13 +0900617bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900618int tomoyo_init_request_info(struct tomoyo_request_info *r,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900619 struct tomoyo_domain_info *domain,
620 const u8 index);
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900621int tomoyo_mount_permission(char *dev_name, struct path *path,
622 const char *type, unsigned long flags,
623 void *data_page);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900624int tomoyo_write_aggregator(struct tomoyo_acl_param *param);
625int tomoyo_write_transition_control(struct tomoyo_acl_param *param,
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900626 const u8 type);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900627int tomoyo_write_file(struct tomoyo_acl_param *param);
628int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900629int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
630 __attribute__ ((format(printf, 2, 3)));
Kentaro Takeda95908372009-02-05 17:18:13 +0900631struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900632struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900633 const bool transit);
634struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns,
635 const u8 profile);
636struct tomoyo_policy_namespace *tomoyo_assign_namespace
637(const char *domainname);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900638struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param,
639 const u8 idx);
Kentaro Takeda95908372009-02-05 17:18:13 +0900640unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
641 const u8 index);
Kentaro Takeda95908372009-02-05 17:18:13 +0900642void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
Kentaro Takeda95908372009-02-05 17:18:13 +0900643void tomoyo_load_policy(const char *filename);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900644void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900645char *tomoyo_encode(const char *str);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900646char *tomoyo_realpath_nofollow(const char *pathname);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900647char *tomoyo_realpath_from_path(struct path *path);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900648bool tomoyo_memory_ok(void *ptr);
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900649void *tomoyo_commit_ok(void *data, const unsigned int size);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900650const struct tomoyo_path_info *tomoyo_get_name(const char *name);
Tetsuo Handa8fbe71f2010-06-16 16:29:59 +0900651void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900652int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900653void __init tomoyo_mm_init(void);
Tetsuo Handa05336de2010-06-16 16:20:24 +0900654int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900655 const struct tomoyo_path_info *filename);
656int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
657 struct path *path, const int flag);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900658int tomoyo_path_number_perm(const u8 operation, struct path *path,
659 unsigned long number);
Tetsuo Handa75093152010-06-16 16:23:55 +0900660int tomoyo_mkdev_perm(const u8 operation, struct path *path,
661 const unsigned int mode, unsigned int dev);
Tetsuo Handa97d69312010-02-16 09:46:15 +0900662int tomoyo_path_perm(const u8 operation, struct path *path);
663int tomoyo_path2_perm(const u8 operation, struct path *path1,
664 struct path *path2);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900665int tomoyo_find_next_domain(struct linux_binprm *bprm);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900666void tomoyo_print_ulong(char *buffer, const int buffer_len,
667 const unsigned long value, const u8 type);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900668void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
Tetsuo Handa2e503bb2011-06-26 23:20:55 +0900669void tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900670void tomoyo_memory_free(void *ptr);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900671int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900672 struct tomoyo_acl_param *param,
Tetsuo Handa237ab452010-06-12 20:46:22 +0900673 bool (*check_duplicate) (const struct tomoyo_acl_info
674 *,
675 const struct tomoyo_acl_info
676 *),
677 bool (*merge_duplicate) (struct tomoyo_acl_info *,
678 struct tomoyo_acl_info *,
679 const bool));
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900680int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900681 struct tomoyo_acl_param *param,
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900682 bool (*check_duplicate) (const struct tomoyo_acl_head
683 *,
684 const struct tomoyo_acl_head
685 *));
Tetsuo Handa99a85252010-06-16 16:22:51 +0900686void tomoyo_check_acl(struct tomoyo_request_info *r,
Tetsuo Handa484ca792010-07-29 14:29:55 +0900687 bool (*check_entry) (struct tomoyo_request_info *,
Tetsuo Handa99a85252010-06-16 16:22:51 +0900688 const struct tomoyo_acl_info *));
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900689char *tomoyo_read_token(struct tomoyo_acl_param *param);
690bool tomoyo_permstr(const char *string, const char *keyword);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900691
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900692const char *tomoyo_yesno(const unsigned int value);
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900693void tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...)
694 __attribute__ ((format(printf, 2, 3)));
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900695void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
696 va_list args);
697void tomoyo_read_log(struct tomoyo_io_buffer *head);
698int tomoyo_poll_log(struct file *file, poll_table *wait);
699char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt,
700 va_list args);
701
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900702/********** External variable definitions. **********/
703
704/* Lock for GC. */
705extern struct srcu_struct tomoyo_ss;
706
707/* The list for "struct tomoyo_domain_info". */
708extern struct list_head tomoyo_domain_list;
709
Tetsuo Handa847b1732010-02-11 09:43:54 +0900710extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
Tetsuo Handa847b1732010-02-11 09:43:54 +0900711
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900712/* Lock for protecting policy. */
713extern struct mutex tomoyo_policy_lock;
714
715/* Has /sbin/init started? */
716extern bool tomoyo_policy_loaded;
717
718/* The kernel's domain. */
719extern struct tomoyo_domain_info tomoyo_kernel_domain;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900720extern struct tomoyo_policy_namespace tomoyo_kernel_namespace;
721extern struct list_head tomoyo_namespace_list;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900722
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900723extern const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX +
724 TOMOYO_MAX_MAC_CATEGORY_INDEX];
725extern const char * const tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
726extern const u8 tomoyo_index2category[TOMOYO_MAX_MAC_INDEX];
727
Tetsuo Handa71c28232010-06-16 16:26:38 +0900728
Tetsuo Handa0d2171d2011-06-26 23:17:46 +0900729extern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION];
730extern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION];
731extern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION];
732
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900733extern const char * const tomoyo_dif[TOMOYO_MAX_DOMAIN_INFO_FLAGS];
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900734extern const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE];
735extern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT];
736extern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT];
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900737
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900738/********** Inlined functions. **********/
739
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900740/**
741 * tomoyo_read_lock - Take lock for protecting policy.
742 *
743 * Returns index number for tomoyo_read_unlock().
744 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900745static inline int tomoyo_read_lock(void)
746{
747 return srcu_read_lock(&tomoyo_ss);
748}
749
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900750/**
751 * tomoyo_read_unlock - Release lock for protecting policy.
752 *
753 * @idx: Index number returned by tomoyo_read_lock().
754 *
755 * Returns nothing.
756 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900757static inline void tomoyo_read_unlock(int idx)
758{
759 srcu_read_unlock(&tomoyo_ss, idx);
760}
761
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900762/**
763 * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
764 *
765 * @a: Pointer to "struct tomoyo_path_info".
766 * @b: Pointer to "struct tomoyo_path_info".
767 *
768 * Returns true if @a == @b, false otherwise.
769 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900770static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
771 const struct tomoyo_path_info *b)
772{
773 return a->hash != b->hash || strcmp(a->name, b->name);
774}
775
Kentaro Takeda95908372009-02-05 17:18:13 +0900776/**
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900777 * tomoyo_put_name - Drop reference on "struct tomoyo_name".
778 *
779 * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
780 *
781 * Returns nothing.
782 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900783static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
784{
785 if (name) {
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900786 struct tomoyo_name *ptr =
787 container_of(name, typeof(*ptr), entry);
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900788 atomic_dec(&ptr->head.users);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900789 }
790}
Kentaro Takeda95908372009-02-05 17:18:13 +0900791
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900792/**
793 * tomoyo_put_group - Drop reference on "struct tomoyo_group".
794 *
795 * @group: Pointer to "struct tomoyo_group". Maybe NULL.
796 *
797 * Returns nothing.
798 */
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900799static inline void tomoyo_put_group(struct tomoyo_group *group)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900800{
801 if (group)
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900802 atomic_dec(&group->head.users);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900803}
804
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900805/**
806 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
807 *
808 * Returns pointer to "struct tomoyo_domain_info" for current thread.
809 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900810static inline struct tomoyo_domain_info *tomoyo_domain(void)
811{
812 return current_cred()->security;
813}
Kentaro Takeda95908372009-02-05 17:18:13 +0900814
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900815/**
816 * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
817 *
818 * @task: Pointer to "struct task_struct".
819 *
820 * Returns pointer to "struct tomoyo_security" for specified thread.
821 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900822static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
823 *task)
824{
825 return task_cred_xxx(task, security);
826}
Kentaro Takeda95908372009-02-05 17:18:13 +0900827
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900828/**
829 * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
830 *
831 * @a: Pointer to "struct tomoyo_name_union".
832 * @b: Pointer to "struct tomoyo_name_union".
833 *
834 * Returns true if @a == @b, false otherwise.
835 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900836static inline bool tomoyo_same_name_union
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900837(const struct tomoyo_name_union *a, const struct tomoyo_name_union *b)
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900838{
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900839 return a->filename == b->filename && a->group == b->group;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900840}
841
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900842/**
843 * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
844 *
845 * @a: Pointer to "struct tomoyo_number_union".
846 * @b: Pointer to "struct tomoyo_number_union".
847 *
848 * Returns true if @a == @b, false otherwise.
849 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900850static inline bool tomoyo_same_number_union
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900851(const struct tomoyo_number_union *a, const struct tomoyo_number_union *b)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900852{
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900853 return a->values[0] == b->values[0] && a->values[1] == b->values[1] &&
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900854 a->group == b->group && a->value_type[0] == b->value_type[0] &&
855 a->value_type[1] == b->value_type[1];
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900856}
857
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900858/**
859 * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread.
860 *
861 * Returns pointer to "struct tomoyo_policy_namespace" for current thread.
862 */
863static inline struct tomoyo_policy_namespace *tomoyo_current_namespace(void)
864{
865 return tomoyo_domain()->ns;
866}
867
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900868#if defined(CONFIG_SLOB)
869
870/**
871 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
872 *
873 * @size: Size to be rounded up.
874 *
875 * Returns @size.
876 *
877 * Since SLOB does not round up, this function simply returns @size.
878 */
879static inline int tomoyo_round2(size_t size)
880{
881 return size;
882}
883
884#else
885
886/**
887 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
888 *
889 * @size: Size to be rounded up.
890 *
891 * Returns rounded size.
892 *
893 * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of
894 * (e.g.) 128 bytes.
895 */
896static inline int tomoyo_round2(size_t size)
897{
898#if PAGE_SIZE == 4096
899 size_t bsize = 32;
900#else
901 size_t bsize = 64;
902#endif
903 if (!size)
904 return 0;
905 while (size > bsize)
906 bsize <<= 1;
907 return bsize;
908}
909
910#endif
911
Kentaro Takeda95908372009-02-05 17:18:13 +0900912/**
913 * list_for_each_cookie - iterate over a list with cookie.
914 * @pos: the &struct list_head to use as a loop cursor.
Kentaro Takeda95908372009-02-05 17:18:13 +0900915 * @head: the head for your list.
Kentaro Takeda95908372009-02-05 17:18:13 +0900916 */
Tetsuo Handa475e6fa2010-06-24 11:28:14 +0900917#define list_for_each_cookie(pos, head) \
918 if (!pos) \
919 pos = srcu_dereference((head)->next, &tomoyo_ss); \
920 for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900921
Kentaro Takeda95908372009-02-05 17:18:13 +0900922#endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */