blob: f40ec1fcbc5db607f7713a1cae7a9a0e060ade94 [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 Handab5bc60b2011-06-26 23:16:03 +090041/* Index numbers for operation mode. */
Tetsuo Handacb0abe62010-05-17 10:08:05 +090042enum tomoyo_mode_index {
43 TOMOYO_CONFIG_DISABLED,
44 TOMOYO_CONFIG_LEARNING,
45 TOMOYO_CONFIG_PERMISSIVE,
Tetsuo Handa57c25902010-06-03 20:38:44 +090046 TOMOYO_CONFIG_ENFORCING,
Tetsuo Handaeadd99c2011-06-26 23:18:58 +090047 TOMOYO_CONFIG_MAX_MODE,
48 TOMOYO_CONFIG_WANT_REJECT_LOG = 64,
49 TOMOYO_CONFIG_WANT_GRANT_LOG = 128,
50 TOMOYO_CONFIG_USE_DEFAULT = 255,
Tetsuo Handacb0abe62010-05-17 10:08:05 +090051};
52
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090053/* Index numbers for entry type. */
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090054enum tomoyo_policy_id {
55 TOMOYO_ID_GROUP,
56 TOMOYO_ID_PATH_GROUP,
57 TOMOYO_ID_NUMBER_GROUP,
Tetsuo Handa5448ec42010-06-21 11:14:39 +090058 TOMOYO_ID_TRANSITION_CONTROL,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090059 TOMOYO_ID_AGGREGATOR,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090060 TOMOYO_ID_MANAGER,
61 TOMOYO_ID_NAME,
62 TOMOYO_ID_ACL,
63 TOMOYO_ID_DOMAIN,
64 TOMOYO_MAX_POLICY
65};
66
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090067/* Index numbers for group entries. */
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090068enum tomoyo_group_id {
69 TOMOYO_PATH_GROUP,
70 TOMOYO_NUMBER_GROUP,
71 TOMOYO_MAX_GROUP
72};
73
Tetsuo Handa76bb0892010-02-11 09:42:40 +090074/* A domain definition starts with <kernel>. */
75#define TOMOYO_ROOT_NAME "<kernel>"
76#define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1)
77
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090078/* Index numbers for type of numeric values. */
79enum tomoyo_value_type {
80 TOMOYO_VALUE_TYPE_INVALID,
81 TOMOYO_VALUE_TYPE_DECIMAL,
82 TOMOYO_VALUE_TYPE_OCTAL,
83 TOMOYO_VALUE_TYPE_HEXADECIMAL,
84};
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +090085
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090086/* Index numbers for domain transition control keywords. */
Tetsuo Handa5448ec42010-06-21 11:14:39 +090087enum tomoyo_transition_type {
88 /* Do not change this order, */
89 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE,
90 TOMOYO_TRANSITION_CONTROL_INITIALIZE,
91 TOMOYO_TRANSITION_CONTROL_NO_KEEP,
92 TOMOYO_TRANSITION_CONTROL_KEEP,
93 TOMOYO_MAX_TRANSITION_TYPE
94};
95
Tetsuo Handa76bb0892010-02-11 09:42:40 +090096/* Index numbers for Access Controls. */
Tetsuo Handa084da352010-02-15 15:10:39 +090097enum tomoyo_acl_entry_type_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +090098 TOMOYO_TYPE_PATH_ACL,
99 TOMOYO_TYPE_PATH2_ACL,
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900100 TOMOYO_TYPE_PATH_NUMBER_ACL,
Tetsuo Handa75093152010-06-16 16:23:55 +0900101 TOMOYO_TYPE_MKDEV_ACL,
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900102 TOMOYO_TYPE_MOUNT_ACL,
Tetsuo Handa084da352010-02-15 15:10:39 +0900103};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900104
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900105/* Index numbers for access controls with one pathname. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900106enum tomoyo_path_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900107 TOMOYO_TYPE_EXECUTE,
108 TOMOYO_TYPE_READ,
109 TOMOYO_TYPE_WRITE,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900110 TOMOYO_TYPE_APPEND,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900111 TOMOYO_TYPE_UNLINK,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900112 TOMOYO_TYPE_GETATTR,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900113 TOMOYO_TYPE_RMDIR,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900114 TOMOYO_TYPE_TRUNCATE,
115 TOMOYO_TYPE_SYMLINK,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900116 TOMOYO_TYPE_CHROOT,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900117 TOMOYO_TYPE_UMOUNT,
118 TOMOYO_MAX_PATH_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900119};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900120
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900121enum tomoyo_memory_stat_type {
122 TOMOYO_MEMORY_POLICY,
123 TOMOYO_MEMORY_AUDIT,
124 TOMOYO_MEMORY_QUERY,
125 TOMOYO_MAX_MEMORY_STAT
126};
127
Tetsuo Handa75093152010-06-16 16:23:55 +0900128enum tomoyo_mkdev_acl_index {
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900129 TOMOYO_TYPE_MKBLOCK,
130 TOMOYO_TYPE_MKCHAR,
Tetsuo Handa75093152010-06-16 16:23:55 +0900131 TOMOYO_MAX_MKDEV_OPERATION
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900132};
133
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900134/* Index numbers for access controls with two pathnames. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900135enum tomoyo_path2_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900136 TOMOYO_TYPE_LINK,
137 TOMOYO_TYPE_RENAME,
138 TOMOYO_TYPE_PIVOT_ROOT,
139 TOMOYO_MAX_PATH2_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900140};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900141
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900142/* Index numbers for access controls with one pathname and one number. */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900143enum tomoyo_path_number_acl_index {
144 TOMOYO_TYPE_CREATE,
145 TOMOYO_TYPE_MKDIR,
146 TOMOYO_TYPE_MKFIFO,
147 TOMOYO_TYPE_MKSOCK,
148 TOMOYO_TYPE_IOCTL,
149 TOMOYO_TYPE_CHMOD,
150 TOMOYO_TYPE_CHOWN,
151 TOMOYO_TYPE_CHGRP,
152 TOMOYO_MAX_PATH_NUMBER_OPERATION
153};
154
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900155/* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900156enum tomoyo_securityfs_interface_index {
157 TOMOYO_DOMAINPOLICY,
158 TOMOYO_EXCEPTIONPOLICY,
159 TOMOYO_DOMAIN_STATUS,
160 TOMOYO_PROCESS_STATUS,
161 TOMOYO_MEMINFO,
162 TOMOYO_SELFDOMAIN,
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900163 TOMOYO_AUDIT,
Tetsuo Handa084da352010-02-15 15:10:39 +0900164 TOMOYO_VERSION,
165 TOMOYO_PROFILE,
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900166 TOMOYO_QUERY,
Tetsuo Handa084da352010-02-15 15:10:39 +0900167 TOMOYO_MANAGER
168};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900169
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900170/* Index numbers for special mount operations. */
171enum tomoyo_special_mount {
172 TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */
173 TOMOYO_MOUNT_MOVE, /* mount --move /old /new */
174 TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */
175 TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */
176 TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */
177 TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */
178 TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */
179 TOMOYO_MAX_SPECIAL_MOUNT
180};
181
182/* Index numbers for functionality. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900183enum tomoyo_mac_index {
184 TOMOYO_MAC_FILE_EXECUTE,
185 TOMOYO_MAC_FILE_OPEN,
186 TOMOYO_MAC_FILE_CREATE,
187 TOMOYO_MAC_FILE_UNLINK,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900188 TOMOYO_MAC_FILE_GETATTR,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900189 TOMOYO_MAC_FILE_MKDIR,
190 TOMOYO_MAC_FILE_RMDIR,
191 TOMOYO_MAC_FILE_MKFIFO,
192 TOMOYO_MAC_FILE_MKSOCK,
193 TOMOYO_MAC_FILE_TRUNCATE,
194 TOMOYO_MAC_FILE_SYMLINK,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900195 TOMOYO_MAC_FILE_MKBLOCK,
196 TOMOYO_MAC_FILE_MKCHAR,
197 TOMOYO_MAC_FILE_LINK,
198 TOMOYO_MAC_FILE_RENAME,
199 TOMOYO_MAC_FILE_CHMOD,
200 TOMOYO_MAC_FILE_CHOWN,
201 TOMOYO_MAC_FILE_CHGRP,
202 TOMOYO_MAC_FILE_IOCTL,
203 TOMOYO_MAC_FILE_CHROOT,
204 TOMOYO_MAC_FILE_MOUNT,
205 TOMOYO_MAC_FILE_UMOUNT,
206 TOMOYO_MAC_FILE_PIVOT_ROOT,
207 TOMOYO_MAX_MAC_INDEX
208};
209
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900210/* Index numbers for category of functionality. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900211enum tomoyo_mac_category_index {
212 TOMOYO_MAC_CATEGORY_FILE,
213 TOMOYO_MAX_MAC_CATEGORY_INDEX
214};
215
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900216/*
217 * Retry this request. Returned by tomoyo_supervisor() if policy violation has
218 * occurred in enforcing mode and the userspace daemon decided to retry.
219 *
220 * We must choose a positive value in order to distinguish "granted" (which is
221 * 0) and "rejected" (which is a negative value) and "retry".
222 */
223#define TOMOYO_RETRY_REQUEST 1
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900224
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900225/* Index numbers for profile's PREFERENCE values. */
226enum tomoyo_pref_index {
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900227 TOMOYO_PREF_MAX_AUDIT_LOG,
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900228 TOMOYO_PREF_MAX_LEARNING_ENTRY,
229 TOMOYO_MAX_PREF
230};
231
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900232/********** Structure definitions. **********/
Kentaro Takeda95908372009-02-05 17:18:13 +0900233
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900234/* Common header for holding ACL entries. */
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900235struct tomoyo_acl_head {
236 struct list_head list;
237 bool is_deleted;
238} __packed;
239
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900240/* Common header for shared entries. */
241struct tomoyo_shared_acl_head {
242 struct list_head list;
243 atomic_t users;
244} __packed;
245
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900246/* Structure for request info. */
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900247struct tomoyo_request_info {
248 struct tomoyo_domain_info *domain;
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900249 /* For holding parameters. */
250 union {
251 struct {
252 const struct tomoyo_path_info *filename;
Tetsuo Handa484ca792010-07-29 14:29:55 +0900253 /* For using wildcards at tomoyo_find_next_domain(). */
254 const struct tomoyo_path_info *matched_path;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900255 /* One of values in "enum tomoyo_path_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900256 u8 operation;
257 } path;
258 struct {
259 const struct tomoyo_path_info *filename1;
260 const struct tomoyo_path_info *filename2;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900261 /* One of values in "enum tomoyo_path2_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900262 u8 operation;
263 } path2;
264 struct {
265 const struct tomoyo_path_info *filename;
266 unsigned int mode;
267 unsigned int major;
268 unsigned int minor;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900269 /* One of values in "enum tomoyo_mkdev_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900270 u8 operation;
271 } mkdev;
272 struct {
273 const struct tomoyo_path_info *filename;
274 unsigned long number;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900275 /*
276 * One of values in
277 * "enum tomoyo_path_number_acl_index".
278 */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900279 u8 operation;
280 } path_number;
281 struct {
282 const struct tomoyo_path_info *type;
283 const struct tomoyo_path_info *dir;
284 const struct tomoyo_path_info *dev;
285 unsigned long flags;
286 int need_dev;
287 } mount;
288 } param;
289 u8 param_type;
290 bool granted;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900291 u8 retry;
292 u8 profile;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900293 u8 mode; /* One of tomoyo_mode_index . */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900294 u8 type;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900295};
296
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900297/* Structure for holding a token. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900298struct tomoyo_path_info {
299 const char *name;
300 u32 hash; /* = full_name_hash(name, strlen(name)) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900301 u16 const_len; /* = tomoyo_const_part_length(name) */
302 bool is_dir; /* = tomoyo_strendswith(name, "/") */
303 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900304};
305
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900306/* Structure for holding string data. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900307struct tomoyo_name {
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900308 struct tomoyo_shared_acl_head head;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900309 struct tomoyo_path_info entry;
310};
Kentaro Takeda95908372009-02-05 17:18:13 +0900311
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900312/* Structure for holding a word. */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900313struct tomoyo_name_union {
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900314 /* Either @filename or @group is NULL. */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900315 const struct tomoyo_path_info *filename;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900316 struct tomoyo_group *group;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900317};
318
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900319/* Structure for holding a number. */
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900320struct tomoyo_number_union {
321 unsigned long values[2];
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900322 struct tomoyo_group *group; /* Maybe NULL. */
323 /* One of values in "enum tomoyo_value_type". */
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900324 u8 value_type[2];
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900325};
326
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900327/* Structure for "path_group"/"number_group" directive. */
328struct tomoyo_group {
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900329 struct tomoyo_shared_acl_head head;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900330 const struct tomoyo_path_info *group_name;
331 struct list_head member_list;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900332};
333
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900334/* Structure for "path_group" directive. */
335struct tomoyo_path_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900336 struct tomoyo_acl_head head;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900337 const struct tomoyo_path_info *member_name;
338};
339
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900340/* Structure for "number_group" directive. */
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900341struct tomoyo_number_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900342 struct tomoyo_acl_head head;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900343 struct tomoyo_number_union number;
344};
345
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900346/* Common header for individual entries. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900347struct tomoyo_acl_info {
348 struct list_head list;
Tetsuo Handa237ab452010-06-12 20:46:22 +0900349 bool is_deleted;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900350 u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */
Kentaro Takeda95908372009-02-05 17:18:13 +0900351} __packed;
352
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900353/* Structure for domain information. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900354struct tomoyo_domain_info {
355 struct list_head list;
356 struct list_head acl_info_list;
357 /* Name of this domain. Never NULL. */
358 const struct tomoyo_path_info *domainname;
359 u8 profile; /* Profile number to use. */
Tetsuo Handaa0558fc2009-04-06 20:49:14 +0900360 bool is_deleted; /* Delete flag. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900361 bool quota_warned; /* Quota warnning flag. */
Tetsuo Handaea13ddb2010-02-03 06:43:06 +0900362 bool transition_failed; /* Domain transition failed flag. */
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900363 atomic_t users; /* Number of referring credentials. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900364};
365
Kentaro Takeda95908372009-02-05 17:18:13 +0900366/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900367 * Structure for "file execute", "file read", "file write", "file append",
368 * "file unlink", "file getattr", "file rmdir", "file truncate",
369 * "file symlink", "file chroot" and "file unmount" directive.
Kentaro Takeda95908372009-02-05 17:18:13 +0900370 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900371struct tomoyo_path_acl {
372 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900373 u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900374 struct tomoyo_name_union name;
Kentaro Takeda95908372009-02-05 17:18:13 +0900375};
376
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900377/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900378 * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
379 * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900380 */
381struct tomoyo_path_number_acl {
382 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900383 /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900384 u8 perm;
385 struct tomoyo_name_union name;
386 struct tomoyo_number_union number;
387};
388
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900389/* Structure for "file mkblock" and "file mkchar" directive. */
Tetsuo Handa75093152010-06-16 16:23:55 +0900390struct tomoyo_mkdev_acl {
391 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900392 u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900393 struct tomoyo_name_union name;
394 struct tomoyo_number_union mode;
395 struct tomoyo_number_union major;
396 struct tomoyo_number_union minor;
397};
398
399/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900400 * Structure for "file rename", "file link" and "file pivot_root" directive.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900401 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900402struct tomoyo_path2_acl {
403 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900404 u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900405 struct tomoyo_name_union name1;
406 struct tomoyo_name_union name2;
Kentaro Takeda95908372009-02-05 17:18:13 +0900407};
408
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900409/* Structure for "file mount" directive. */
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900410struct tomoyo_mount_acl {
411 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900412 struct tomoyo_name_union dev_name;
413 struct tomoyo_name_union dir_name;
414 struct tomoyo_name_union fs_type;
415 struct tomoyo_number_union flags;
416};
417
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900418/* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
419struct tomoyo_acl_param {
420 char *data;
421 struct list_head *list;
422 bool is_delete;
423};
424
Tetsuo Handa0d2171d2011-06-26 23:17:46 +0900425#define TOMOYO_MAX_IO_READ_QUEUE 64
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900426
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900427/*
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900428 * Structure for reading/writing policy via /sys/kernel/security/tomoyo
429 * interfaces.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900430 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900431struct tomoyo_io_buffer {
Tetsuo Handa8fbe71f2010-06-16 16:29:59 +0900432 void (*read) (struct tomoyo_io_buffer *);
Kentaro Takeda95908372009-02-05 17:18:13 +0900433 int (*write) (struct tomoyo_io_buffer *);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900434 int (*poll) (struct file *file, poll_table *wait);
Kentaro Takeda95908372009-02-05 17:18:13 +0900435 /* Exclusive lock for this structure. */
436 struct mutex io_sem;
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900437 /* Index returned by tomoyo_read_lock(). */
438 int reader_idx;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900439 char __user *read_user_buf;
440 int read_user_buf_avail;
441 struct {
442 struct list_head *domain;
443 struct list_head *group;
444 struct list_head *acl;
445 int avail;
446 int step;
447 int query_index;
448 u16 index;
449 u8 bit;
450 u8 w_pos;
451 bool eof;
452 bool print_this_domain_only;
453 bool print_execute_only;
454 const char *w[TOMOYO_MAX_IO_READ_QUEUE];
455 } r;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900456 struct {
457 /* The position currently writing to. */
458 struct tomoyo_domain_info *domain;
459 /* Bytes available for writing. */
460 int avail;
461 } w;
Kentaro Takeda95908372009-02-05 17:18:13 +0900462 /* Buffer for reading. */
463 char *read_buf;
Kentaro Takeda95908372009-02-05 17:18:13 +0900464 /* Size of read buffer. */
465 int readbuf_size;
466 /* Buffer for writing. */
467 char *write_buf;
Kentaro Takeda95908372009-02-05 17:18:13 +0900468 /* Size of write buffer. */
469 int writebuf_size;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900470 /* Type of this interface. */
471 u8 type;
Kentaro Takeda95908372009-02-05 17:18:13 +0900472};
473
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900474/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900475 * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
476 * "no_keep_domain" keyword.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900477 */
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900478struct tomoyo_transition_control {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900479 struct tomoyo_acl_head head;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900480 u8 type; /* One of values in "enum tomoyo_transition_type". */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900481 /* True if the domainname is tomoyo_get_last_name(). */
482 bool is_last_name;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900483 const struct tomoyo_path_info *domainname; /* Maybe NULL */
484 const struct tomoyo_path_info *program; /* Maybe NULL */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900485};
486
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900487/* Structure for "aggregator" keyword. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900488struct tomoyo_aggregator {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900489 struct tomoyo_acl_head head;
Tetsuo Handa10843072010-06-03 20:38:03 +0900490 const struct tomoyo_path_info *original_name;
491 const struct tomoyo_path_info *aggregated_name;
Tetsuo Handa10843072010-06-03 20:38:03 +0900492};
493
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900494/* Structure for policy manager. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900495struct tomoyo_manager {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900496 struct tomoyo_acl_head head;
497 bool is_domain; /* True if manager is a domainname. */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900498 /* A path to program or a domainname. */
499 const struct tomoyo_path_info *manager;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900500};
501
Tetsuo Handa57c25902010-06-03 20:38:44 +0900502struct tomoyo_preference {
503 unsigned int learning_max_entry;
504 bool enforcing_verbose;
505 bool learning_verbose;
506 bool permissive_verbose;
507};
508
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900509/* Structure for /sys/kernel/security/tomnoyo/profile interface. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900510struct tomoyo_profile {
511 const struct tomoyo_path_info *comment;
512 struct tomoyo_preference *learning;
513 struct tomoyo_preference *permissive;
514 struct tomoyo_preference *enforcing;
515 struct tomoyo_preference preference;
516 u8 default_config;
517 u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX];
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900518 unsigned int pref[TOMOYO_MAX_PREF];
Tetsuo Handa57c25902010-06-03 20:38:44 +0900519};
520
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900521/* Structure for representing YYYY/MM/DD hh/mm/ss. */
522struct tomoyo_time {
523 u16 year;
524 u8 month;
525 u8 day;
526 u8 hour;
527 u8 min;
528 u8 sec;
529};
530
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900531/********** Function prototypes. **********/
532
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900533bool tomoyo_str_starts(char **src, const char *find);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900534const char *tomoyo_get_exe(void);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900535void tomoyo_normalize_line(unsigned char *buffer);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900536void tomoyo_check_profile(void);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900537int tomoyo_open_control(const u8 type, struct file *file);
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900538int tomoyo_close_control(struct tomoyo_io_buffer *head);
Tetsuo Handa0849e3b2010-06-25 12:22:09 +0900539int tomoyo_poll_control(struct file *file, poll_table *wait);
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900540int tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer,
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900541 const int buffer_len);
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900542int tomoyo_write_control(struct tomoyo_io_buffer *head,
543 const char __user *buffer, const int buffer_len);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900544bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900545void tomoyo_warn_oom(const char *function);
Tetsuo Handa484ca792010-07-29 14:29:55 +0900546const struct tomoyo_path_info *
547tomoyo_compare_name_union(const struct tomoyo_path_info *name,
548 const struct tomoyo_name_union *ptr);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900549bool tomoyo_compare_number_union(const unsigned long value,
550 const struct tomoyo_number_union *ptr);
Tetsuo Handa57c25902010-06-03 20:38:44 +0900551int tomoyo_get_mode(const u8 profile, const u8 index);
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900552void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
Kentaro Takeda95908372009-02-05 17:18:13 +0900553 __attribute__ ((format(printf, 2, 3)));
Tetsuo Handa75093152010-06-16 16:23:55 +0900554bool tomoyo_correct_domain(const unsigned char *domainname);
Tetsuo Handa75093152010-06-16 16:23:55 +0900555bool tomoyo_correct_path(const char *filename);
556bool tomoyo_correct_word(const char *string);
Tetsuo Handa75093152010-06-16 16:23:55 +0900557bool tomoyo_domain_def(const unsigned char *buffer);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900558bool tomoyo_parse_name_union(struct tomoyo_acl_param *param,
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900559 struct tomoyo_name_union *ptr);
Tetsuo Handa484ca792010-07-29 14:29:55 +0900560const struct tomoyo_path_info *
561tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
562 const struct tomoyo_group *group);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900563bool tomoyo_number_matches_group(const unsigned long min,
564 const unsigned long max,
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900565 const struct tomoyo_group *group);
Kentaro Takeda95908372009-02-05 17:18:13 +0900566bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
567 const struct tomoyo_path_info *pattern);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900568bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
569 struct tomoyo_number_union *ptr);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900570bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
Kentaro Takeda95908372009-02-05 17:18:13 +0900571bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900572int tomoyo_init_request_info(struct tomoyo_request_info *r,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900573 struct tomoyo_domain_info *domain,
574 const u8 index);
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900575int tomoyo_mount_permission(char *dev_name, struct path *path,
576 const char *type, unsigned long flags,
577 void *data_page);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900578int tomoyo_write_aggregator(struct tomoyo_acl_param *param);
579int tomoyo_write_transition_control(struct tomoyo_acl_param *param,
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900580 const u8 type);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900581int tomoyo_write_file(struct tomoyo_acl_param *param);
582int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900583int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
584 __attribute__ ((format(printf, 2, 3)));
Kentaro Takeda95908372009-02-05 17:18:13 +0900585struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900586struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
587 const u8 profile);
Tetsuo Handa57c25902010-06-03 20:38:44 +0900588struct tomoyo_profile *tomoyo_profile(const u8 profile);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900589struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param,
590 const u8 idx);
Kentaro Takeda95908372009-02-05 17:18:13 +0900591unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
592 const u8 index);
Kentaro Takeda95908372009-02-05 17:18:13 +0900593void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
Kentaro Takeda95908372009-02-05 17:18:13 +0900594void tomoyo_load_policy(const char *filename);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900595void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900596char *tomoyo_encode(const char *str);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900597char *tomoyo_realpath_nofollow(const char *pathname);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900598char *tomoyo_realpath_from_path(struct path *path);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900599bool tomoyo_memory_ok(void *ptr);
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900600void *tomoyo_commit_ok(void *data, const unsigned int size);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900601const struct tomoyo_path_info *tomoyo_get_name(const char *name);
Tetsuo Handa8fbe71f2010-06-16 16:29:59 +0900602void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900603int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900604void __init tomoyo_mm_init(void);
Tetsuo Handa05336de2010-06-16 16:20:24 +0900605int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900606 const struct tomoyo_path_info *filename);
607int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
608 struct path *path, const int flag);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900609int tomoyo_path_number_perm(const u8 operation, struct path *path,
610 unsigned long number);
Tetsuo Handa75093152010-06-16 16:23:55 +0900611int tomoyo_mkdev_perm(const u8 operation, struct path *path,
612 const unsigned int mode, unsigned int dev);
Tetsuo Handa97d69312010-02-16 09:46:15 +0900613int tomoyo_path_perm(const u8 operation, struct path *path);
614int tomoyo_path2_perm(const u8 operation, struct path *path1,
615 struct path *path2);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900616int tomoyo_find_next_domain(struct linux_binprm *bprm);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900617void tomoyo_print_ulong(char *buffer, const int buffer_len,
618 const unsigned long value, const u8 type);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900619void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900620void tomoyo_run_gc(void);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900621void tomoyo_memory_free(void *ptr);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900622int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900623 struct tomoyo_acl_param *param,
Tetsuo Handa237ab452010-06-12 20:46:22 +0900624 bool (*check_duplicate) (const struct tomoyo_acl_info
625 *,
626 const struct tomoyo_acl_info
627 *),
628 bool (*merge_duplicate) (struct tomoyo_acl_info *,
629 struct tomoyo_acl_info *,
630 const bool));
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900631int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900632 struct tomoyo_acl_param *param,
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900633 bool (*check_duplicate) (const struct tomoyo_acl_head
634 *,
635 const struct tomoyo_acl_head
636 *));
Tetsuo Handa99a85252010-06-16 16:22:51 +0900637void tomoyo_check_acl(struct tomoyo_request_info *r,
Tetsuo Handa484ca792010-07-29 14:29:55 +0900638 bool (*check_entry) (struct tomoyo_request_info *,
Tetsuo Handa99a85252010-06-16 16:22:51 +0900639 const struct tomoyo_acl_info *));
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900640char *tomoyo_read_token(struct tomoyo_acl_param *param);
641bool tomoyo_permstr(const char *string, const char *keyword);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900642
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900643const char *tomoyo_yesno(const unsigned int value);
644void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
645 va_list args);
646void tomoyo_read_log(struct tomoyo_io_buffer *head);
647int tomoyo_poll_log(struct file *file, poll_table *wait);
648char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt,
649 va_list args);
650
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900651/********** External variable definitions. **********/
652
653/* Lock for GC. */
654extern struct srcu_struct tomoyo_ss;
655
656/* The list for "struct tomoyo_domain_info". */
657extern struct list_head tomoyo_domain_list;
658
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900659extern struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY];
660extern struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP];
Tetsuo Handa847b1732010-02-11 09:43:54 +0900661extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
Tetsuo Handa847b1732010-02-11 09:43:54 +0900662
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900663/* Lock for protecting policy. */
664extern struct mutex tomoyo_policy_lock;
665
666/* Has /sbin/init started? */
667extern bool tomoyo_policy_loaded;
668
669/* The kernel's domain. */
670extern struct tomoyo_domain_info tomoyo_kernel_domain;
671
Tetsuo Handa71c28232010-06-16 16:26:38 +0900672extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
673extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION];
674extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION];
675extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION];
676
Tetsuo Handa0d2171d2011-06-26 23:17:46 +0900677extern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION];
678extern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION];
679extern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION];
680
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900681extern const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE];
682extern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT];
683extern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT];
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900684
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900685/********** Inlined functions. **********/
686
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900687/**
688 * tomoyo_read_lock - Take lock for protecting policy.
689 *
690 * Returns index number for tomoyo_read_unlock().
691 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900692static inline int tomoyo_read_lock(void)
693{
694 return srcu_read_lock(&tomoyo_ss);
695}
696
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900697/**
698 * tomoyo_read_unlock - Release lock for protecting policy.
699 *
700 * @idx: Index number returned by tomoyo_read_lock().
701 *
702 * Returns nothing.
703 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900704static inline void tomoyo_read_unlock(int idx)
705{
706 srcu_read_unlock(&tomoyo_ss, idx);
707}
708
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900709/**
710 * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
711 *
712 * @a: Pointer to "struct tomoyo_path_info".
713 * @b: Pointer to "struct tomoyo_path_info".
714 *
715 * Returns true if @a == @b, false otherwise.
716 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900717static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
718 const struct tomoyo_path_info *b)
719{
720 return a->hash != b->hash || strcmp(a->name, b->name);
721}
722
Kentaro Takeda95908372009-02-05 17:18:13 +0900723/**
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900724 * tomoyo_put_name - Drop reference on "struct tomoyo_name".
725 *
726 * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
727 *
728 * Returns nothing.
729 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900730static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
731{
732 if (name) {
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900733 struct tomoyo_name *ptr =
734 container_of(name, typeof(*ptr), entry);
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900735 atomic_dec(&ptr->head.users);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900736 }
737}
Kentaro Takeda95908372009-02-05 17:18:13 +0900738
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900739/**
740 * tomoyo_put_group - Drop reference on "struct tomoyo_group".
741 *
742 * @group: Pointer to "struct tomoyo_group". Maybe NULL.
743 *
744 * Returns nothing.
745 */
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900746static inline void tomoyo_put_group(struct tomoyo_group *group)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900747{
748 if (group)
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900749 atomic_dec(&group->head.users);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900750}
751
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900752/**
753 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
754 *
755 * Returns pointer to "struct tomoyo_domain_info" for current thread.
756 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900757static inline struct tomoyo_domain_info *tomoyo_domain(void)
758{
759 return current_cred()->security;
760}
Kentaro Takeda95908372009-02-05 17:18:13 +0900761
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900762/**
763 * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
764 *
765 * @task: Pointer to "struct task_struct".
766 *
767 * Returns pointer to "struct tomoyo_security" for specified thread.
768 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900769static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
770 *task)
771{
772 return task_cred_xxx(task, security);
773}
Kentaro Takeda95908372009-02-05 17:18:13 +0900774
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900775/**
776 * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
777 *
778 * @a: Pointer to "struct tomoyo_name_union".
779 * @b: Pointer to "struct tomoyo_name_union".
780 *
781 * Returns true if @a == @b, false otherwise.
782 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900783static inline bool tomoyo_same_name_union
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900784(const struct tomoyo_name_union *a, const struct tomoyo_name_union *b)
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900785{
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900786 return a->filename == b->filename && a->group == b->group;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900787}
788
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900789/**
790 * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
791 *
792 * @a: Pointer to "struct tomoyo_number_union".
793 * @b: Pointer to "struct tomoyo_number_union".
794 *
795 * Returns true if @a == @b, false otherwise.
796 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900797static inline bool tomoyo_same_number_union
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900798(const struct tomoyo_number_union *a, const struct tomoyo_number_union *b)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900799{
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900800 return a->values[0] == b->values[0] && a->values[1] == b->values[1] &&
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900801 a->group == b->group && a->value_type[0] == b->value_type[0] &&
802 a->value_type[1] == b->value_type[1];
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900803}
804
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900805#if defined(CONFIG_SLOB)
806
807/**
808 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
809 *
810 * @size: Size to be rounded up.
811 *
812 * Returns @size.
813 *
814 * Since SLOB does not round up, this function simply returns @size.
815 */
816static inline int tomoyo_round2(size_t size)
817{
818 return size;
819}
820
821#else
822
823/**
824 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
825 *
826 * @size: Size to be rounded up.
827 *
828 * Returns rounded size.
829 *
830 * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of
831 * (e.g.) 128 bytes.
832 */
833static inline int tomoyo_round2(size_t size)
834{
835#if PAGE_SIZE == 4096
836 size_t bsize = 32;
837#else
838 size_t bsize = 64;
839#endif
840 if (!size)
841 return 0;
842 while (size > bsize)
843 bsize <<= 1;
844 return bsize;
845}
846
847#endif
848
Kentaro Takeda95908372009-02-05 17:18:13 +0900849/**
850 * list_for_each_cookie - iterate over a list with cookie.
851 * @pos: the &struct list_head to use as a loop cursor.
Kentaro Takeda95908372009-02-05 17:18:13 +0900852 * @head: the head for your list.
Kentaro Takeda95908372009-02-05 17:18:13 +0900853 */
Tetsuo Handa475e6fa2010-06-24 11:28:14 +0900854#define list_for_each_cookie(pos, head) \
855 if (!pos) \
856 pos = srcu_dereference((head)->next, &tomoyo_ss); \
857 for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900858
Kentaro Takeda95908372009-02-05 17:18:13 +0900859#endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */