blob: d0645733c102c88f8260adf1b23da50424548dfb [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,
47 TOMOYO_CONFIG_USE_DEFAULT = 255
Tetsuo Handacb0abe62010-05-17 10:08:05 +090048};
49
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090050/* Index numbers for entry type. */
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090051enum tomoyo_policy_id {
52 TOMOYO_ID_GROUP,
53 TOMOYO_ID_PATH_GROUP,
54 TOMOYO_ID_NUMBER_GROUP,
Tetsuo Handa5448ec42010-06-21 11:14:39 +090055 TOMOYO_ID_TRANSITION_CONTROL,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090056 TOMOYO_ID_AGGREGATOR,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090057 TOMOYO_ID_MANAGER,
58 TOMOYO_ID_NAME,
59 TOMOYO_ID_ACL,
60 TOMOYO_ID_DOMAIN,
61 TOMOYO_MAX_POLICY
62};
63
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090064/* Index numbers for group entries. */
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090065enum tomoyo_group_id {
66 TOMOYO_PATH_GROUP,
67 TOMOYO_NUMBER_GROUP,
68 TOMOYO_MAX_GROUP
69};
70
Tetsuo Handa76bb0892010-02-11 09:42:40 +090071/* A domain definition starts with <kernel>. */
72#define TOMOYO_ROOT_NAME "<kernel>"
73#define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1)
74
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090075/* Index numbers for type of numeric values. */
76enum tomoyo_value_type {
77 TOMOYO_VALUE_TYPE_INVALID,
78 TOMOYO_VALUE_TYPE_DECIMAL,
79 TOMOYO_VALUE_TYPE_OCTAL,
80 TOMOYO_VALUE_TYPE_HEXADECIMAL,
81};
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +090082
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090083/* Index numbers for domain transition control keywords. */
Tetsuo Handa5448ec42010-06-21 11:14:39 +090084enum tomoyo_transition_type {
85 /* Do not change this order, */
86 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE,
87 TOMOYO_TRANSITION_CONTROL_INITIALIZE,
88 TOMOYO_TRANSITION_CONTROL_NO_KEEP,
89 TOMOYO_TRANSITION_CONTROL_KEEP,
90 TOMOYO_MAX_TRANSITION_TYPE
91};
92
Tetsuo Handa76bb0892010-02-11 09:42:40 +090093/* Index numbers for Access Controls. */
Tetsuo Handa084da352010-02-15 15:10:39 +090094enum tomoyo_acl_entry_type_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +090095 TOMOYO_TYPE_PATH_ACL,
96 TOMOYO_TYPE_PATH2_ACL,
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +090097 TOMOYO_TYPE_PATH_NUMBER_ACL,
Tetsuo Handa75093152010-06-16 16:23:55 +090098 TOMOYO_TYPE_MKDEV_ACL,
Tetsuo Handa2106ccd2010-05-17 10:10:31 +090099 TOMOYO_TYPE_MOUNT_ACL,
Tetsuo Handa084da352010-02-15 15:10:39 +0900100};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900101
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900102/* Index numbers for access controls with one pathname. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900103enum tomoyo_path_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900104 TOMOYO_TYPE_EXECUTE,
105 TOMOYO_TYPE_READ,
106 TOMOYO_TYPE_WRITE,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900107 TOMOYO_TYPE_APPEND,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900108 TOMOYO_TYPE_UNLINK,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900109 TOMOYO_TYPE_GETATTR,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900110 TOMOYO_TYPE_RMDIR,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900111 TOMOYO_TYPE_TRUNCATE,
112 TOMOYO_TYPE_SYMLINK,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900113 TOMOYO_TYPE_CHROOT,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900114 TOMOYO_TYPE_UMOUNT,
115 TOMOYO_MAX_PATH_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900116};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900117
Tetsuo Handa75093152010-06-16 16:23:55 +0900118enum tomoyo_mkdev_acl_index {
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900119 TOMOYO_TYPE_MKBLOCK,
120 TOMOYO_TYPE_MKCHAR,
Tetsuo Handa75093152010-06-16 16:23:55 +0900121 TOMOYO_MAX_MKDEV_OPERATION
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900122};
123
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900124/* Index numbers for access controls with two pathnames. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900125enum tomoyo_path2_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900126 TOMOYO_TYPE_LINK,
127 TOMOYO_TYPE_RENAME,
128 TOMOYO_TYPE_PIVOT_ROOT,
129 TOMOYO_MAX_PATH2_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900130};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900131
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900132/* Index numbers for access controls with one pathname and one number. */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900133enum tomoyo_path_number_acl_index {
134 TOMOYO_TYPE_CREATE,
135 TOMOYO_TYPE_MKDIR,
136 TOMOYO_TYPE_MKFIFO,
137 TOMOYO_TYPE_MKSOCK,
138 TOMOYO_TYPE_IOCTL,
139 TOMOYO_TYPE_CHMOD,
140 TOMOYO_TYPE_CHOWN,
141 TOMOYO_TYPE_CHGRP,
142 TOMOYO_MAX_PATH_NUMBER_OPERATION
143};
144
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900145/* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900146enum tomoyo_securityfs_interface_index {
147 TOMOYO_DOMAINPOLICY,
148 TOMOYO_EXCEPTIONPOLICY,
149 TOMOYO_DOMAIN_STATUS,
150 TOMOYO_PROCESS_STATUS,
151 TOMOYO_MEMINFO,
152 TOMOYO_SELFDOMAIN,
153 TOMOYO_VERSION,
154 TOMOYO_PROFILE,
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900155 TOMOYO_QUERY,
Tetsuo Handa084da352010-02-15 15:10:39 +0900156 TOMOYO_MANAGER
157};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900158
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900159/* Index numbers for special mount operations. */
160enum tomoyo_special_mount {
161 TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */
162 TOMOYO_MOUNT_MOVE, /* mount --move /old /new */
163 TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */
164 TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */
165 TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */
166 TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */
167 TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */
168 TOMOYO_MAX_SPECIAL_MOUNT
169};
170
171/* Index numbers for functionality. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900172enum tomoyo_mac_index {
173 TOMOYO_MAC_FILE_EXECUTE,
174 TOMOYO_MAC_FILE_OPEN,
175 TOMOYO_MAC_FILE_CREATE,
176 TOMOYO_MAC_FILE_UNLINK,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900177 TOMOYO_MAC_FILE_GETATTR,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900178 TOMOYO_MAC_FILE_MKDIR,
179 TOMOYO_MAC_FILE_RMDIR,
180 TOMOYO_MAC_FILE_MKFIFO,
181 TOMOYO_MAC_FILE_MKSOCK,
182 TOMOYO_MAC_FILE_TRUNCATE,
183 TOMOYO_MAC_FILE_SYMLINK,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900184 TOMOYO_MAC_FILE_MKBLOCK,
185 TOMOYO_MAC_FILE_MKCHAR,
186 TOMOYO_MAC_FILE_LINK,
187 TOMOYO_MAC_FILE_RENAME,
188 TOMOYO_MAC_FILE_CHMOD,
189 TOMOYO_MAC_FILE_CHOWN,
190 TOMOYO_MAC_FILE_CHGRP,
191 TOMOYO_MAC_FILE_IOCTL,
192 TOMOYO_MAC_FILE_CHROOT,
193 TOMOYO_MAC_FILE_MOUNT,
194 TOMOYO_MAC_FILE_UMOUNT,
195 TOMOYO_MAC_FILE_PIVOT_ROOT,
196 TOMOYO_MAX_MAC_INDEX
197};
198
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900199/* Index numbers for category of functionality. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900200enum tomoyo_mac_category_index {
201 TOMOYO_MAC_CATEGORY_FILE,
202 TOMOYO_MAX_MAC_CATEGORY_INDEX
203};
204
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900205/*
206 * Retry this request. Returned by tomoyo_supervisor() if policy violation has
207 * occurred in enforcing mode and the userspace daemon decided to retry.
208 *
209 * We must choose a positive value in order to distinguish "granted" (which is
210 * 0) and "rejected" (which is a negative value) and "retry".
211 */
212#define TOMOYO_RETRY_REQUEST 1
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900213
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900214/********** Structure definitions. **********/
Kentaro Takeda95908372009-02-05 17:18:13 +0900215
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900216/* Common header for holding ACL entries. */
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900217struct tomoyo_acl_head {
218 struct list_head list;
219 bool is_deleted;
220} __packed;
221
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900222/* Structure for request info. */
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900223struct tomoyo_request_info {
224 struct tomoyo_domain_info *domain;
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900225 /* For holding parameters. */
226 union {
227 struct {
228 const struct tomoyo_path_info *filename;
Tetsuo Handa484ca792010-07-29 14:29:55 +0900229 /* For using wildcards at tomoyo_find_next_domain(). */
230 const struct tomoyo_path_info *matched_path;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900231 /* One of values in "enum tomoyo_path_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900232 u8 operation;
233 } path;
234 struct {
235 const struct tomoyo_path_info *filename1;
236 const struct tomoyo_path_info *filename2;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900237 /* One of values in "enum tomoyo_path2_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900238 u8 operation;
239 } path2;
240 struct {
241 const struct tomoyo_path_info *filename;
242 unsigned int mode;
243 unsigned int major;
244 unsigned int minor;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900245 /* One of values in "enum tomoyo_mkdev_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900246 u8 operation;
247 } mkdev;
248 struct {
249 const struct tomoyo_path_info *filename;
250 unsigned long number;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900251 /*
252 * One of values in
253 * "enum tomoyo_path_number_acl_index".
254 */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900255 u8 operation;
256 } path_number;
257 struct {
258 const struct tomoyo_path_info *type;
259 const struct tomoyo_path_info *dir;
260 const struct tomoyo_path_info *dev;
261 unsigned long flags;
262 int need_dev;
263 } mount;
264 } param;
265 u8 param_type;
266 bool granted;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900267 u8 retry;
268 u8 profile;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900269 u8 mode; /* One of tomoyo_mode_index . */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900270 u8 type;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900271};
272
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900273/* Structure for holding a token. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900274struct tomoyo_path_info {
275 const char *name;
276 u32 hash; /* = full_name_hash(name, strlen(name)) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900277 u16 const_len; /* = tomoyo_const_part_length(name) */
278 bool is_dir; /* = tomoyo_strendswith(name, "/") */
279 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900280};
281
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900282/* Structure for holding string data. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900283struct tomoyo_name {
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900284 struct list_head list;
285 atomic_t users;
286 struct tomoyo_path_info entry;
287};
Kentaro Takeda95908372009-02-05 17:18:13 +0900288
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900289/* Structure for holding a word. */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900290struct tomoyo_name_union {
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900291 /* Either @filename or @group is NULL. */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900292 const struct tomoyo_path_info *filename;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900293 struct tomoyo_group *group;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900294 /* True if @group != NULL, false if @filename != NULL. */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900295 u8 is_group;
296};
297
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900298/* Structure for holding a number. */
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900299struct tomoyo_number_union {
300 unsigned long values[2];
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900301 struct tomoyo_group *group; /* Maybe NULL. */
302 /* One of values in "enum tomoyo_value_type". */
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900303 u8 min_type;
304 u8 max_type;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900305 /* True if @group != NULL, false otherwise. */
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900306 u8 is_group;
307};
308
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900309/* Structure for "path_group"/"number_group" directive. */
310struct tomoyo_group {
311 struct list_head list;
312 const struct tomoyo_path_info *group_name;
313 struct list_head member_list;
314 atomic_t users;
315};
316
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900317/* Structure for "path_group" directive. */
318struct tomoyo_path_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900319 struct tomoyo_acl_head head;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900320 const struct tomoyo_path_info *member_name;
321};
322
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900323/* Structure for "number_group" directive. */
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900324struct tomoyo_number_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900325 struct tomoyo_acl_head head;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900326 struct tomoyo_number_union number;
327};
328
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900329/* Common header for individual entries. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900330struct tomoyo_acl_info {
331 struct list_head list;
Tetsuo Handa237ab452010-06-12 20:46:22 +0900332 bool is_deleted;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900333 u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */
Kentaro Takeda95908372009-02-05 17:18:13 +0900334} __packed;
335
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900336/* Structure for domain information. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900337struct tomoyo_domain_info {
338 struct list_head list;
339 struct list_head acl_info_list;
340 /* Name of this domain. Never NULL. */
341 const struct tomoyo_path_info *domainname;
342 u8 profile; /* Profile number to use. */
Tetsuo Handaa0558fc2009-04-06 20:49:14 +0900343 bool is_deleted; /* Delete flag. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900344 bool quota_warned; /* Quota warnning flag. */
Tetsuo Handaea13ddb2010-02-03 06:43:06 +0900345 bool transition_failed; /* Domain transition failed flag. */
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900346 atomic_t users; /* Number of referring credentials. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900347};
348
Kentaro Takeda95908372009-02-05 17:18:13 +0900349/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900350 * Structure for "file execute", "file read", "file write", "file append",
351 * "file unlink", "file getattr", "file rmdir", "file truncate",
352 * "file symlink", "file chroot" and "file unmount" directive.
Kentaro Takeda95908372009-02-05 17:18:13 +0900353 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900354struct tomoyo_path_acl {
355 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900356 u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900357 struct tomoyo_name_union name;
Kentaro Takeda95908372009-02-05 17:18:13 +0900358};
359
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900360/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900361 * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
362 * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900363 */
364struct tomoyo_path_number_acl {
365 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900366 /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900367 u8 perm;
368 struct tomoyo_name_union name;
369 struct tomoyo_number_union number;
370};
371
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900372/* Structure for "file mkblock" and "file mkchar" directive. */
Tetsuo Handa75093152010-06-16 16:23:55 +0900373struct tomoyo_mkdev_acl {
374 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900375 u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900376 struct tomoyo_name_union name;
377 struct tomoyo_number_union mode;
378 struct tomoyo_number_union major;
379 struct tomoyo_number_union minor;
380};
381
382/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900383 * Structure for "file rename", "file link" and "file pivot_root" directive.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900384 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900385struct tomoyo_path2_acl {
386 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900387 u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900388 struct tomoyo_name_union name1;
389 struct tomoyo_name_union name2;
Kentaro Takeda95908372009-02-05 17:18:13 +0900390};
391
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900392/* Structure for "file mount" directive. */
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900393struct tomoyo_mount_acl {
394 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900395 struct tomoyo_name_union dev_name;
396 struct tomoyo_name_union dir_name;
397 struct tomoyo_name_union fs_type;
398 struct tomoyo_number_union flags;
399};
400
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900401#define TOMOYO_MAX_IO_READ_QUEUE 32
402
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900403/*
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900404 * Structure for reading/writing policy via /sys/kernel/security/tomoyo
405 * interfaces.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900406 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900407struct tomoyo_io_buffer {
Tetsuo Handa8fbe71f2010-06-16 16:29:59 +0900408 void (*read) (struct tomoyo_io_buffer *);
Kentaro Takeda95908372009-02-05 17:18:13 +0900409 int (*write) (struct tomoyo_io_buffer *);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900410 int (*poll) (struct file *file, poll_table *wait);
Kentaro Takeda95908372009-02-05 17:18:13 +0900411 /* Exclusive lock for this structure. */
412 struct mutex io_sem;
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900413 /* Index returned by tomoyo_read_lock(). */
414 int reader_idx;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900415 char __user *read_user_buf;
416 int read_user_buf_avail;
417 struct {
418 struct list_head *domain;
419 struct list_head *group;
420 struct list_head *acl;
421 int avail;
422 int step;
423 int query_index;
424 u16 index;
425 u8 bit;
426 u8 w_pos;
427 bool eof;
428 bool print_this_domain_only;
429 bool print_execute_only;
430 const char *w[TOMOYO_MAX_IO_READ_QUEUE];
431 } r;
Kentaro Takeda95908372009-02-05 17:18:13 +0900432 /* The position currently writing to. */
433 struct tomoyo_domain_info *write_var1;
Kentaro Takeda95908372009-02-05 17:18:13 +0900434 /* Buffer for reading. */
435 char *read_buf;
Kentaro Takeda95908372009-02-05 17:18:13 +0900436 /* Size of read buffer. */
437 int readbuf_size;
438 /* Buffer for writing. */
439 char *write_buf;
440 /* Bytes available for writing. */
441 int write_avail;
442 /* Size of write buffer. */
443 int writebuf_size;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900444 /* Type of this interface. */
445 u8 type;
Kentaro Takeda95908372009-02-05 17:18:13 +0900446};
447
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900448/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900449 * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
450 * "no_keep_domain" keyword.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900451 */
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900452struct tomoyo_transition_control {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900453 struct tomoyo_acl_head head;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900454 u8 type; /* One of values in "enum tomoyo_transition_type". */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900455 /* True if the domainname is tomoyo_get_last_name(). */
456 bool is_last_name;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900457 const struct tomoyo_path_info *domainname; /* Maybe NULL */
458 const struct tomoyo_path_info *program; /* Maybe NULL */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900459};
460
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900461/* Structure for "aggregator" keyword. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900462struct tomoyo_aggregator {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900463 struct tomoyo_acl_head head;
Tetsuo Handa10843072010-06-03 20:38:03 +0900464 const struct tomoyo_path_info *original_name;
465 const struct tomoyo_path_info *aggregated_name;
Tetsuo Handa10843072010-06-03 20:38:03 +0900466};
467
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900468/* Structure for policy manager. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900469struct tomoyo_manager {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900470 struct tomoyo_acl_head head;
471 bool is_domain; /* True if manager is a domainname. */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900472 /* A path to program or a domainname. */
473 const struct tomoyo_path_info *manager;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900474};
475
Tetsuo Handa57c25902010-06-03 20:38:44 +0900476struct tomoyo_preference {
477 unsigned int learning_max_entry;
478 bool enforcing_verbose;
479 bool learning_verbose;
480 bool permissive_verbose;
481};
482
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900483/* Structure for /sys/kernel/security/tomnoyo/profile interface. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900484struct tomoyo_profile {
485 const struct tomoyo_path_info *comment;
486 struct tomoyo_preference *learning;
487 struct tomoyo_preference *permissive;
488 struct tomoyo_preference *enforcing;
489 struct tomoyo_preference preference;
490 u8 default_config;
491 u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX];
492};
493
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900494/********** Function prototypes. **********/
495
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900496bool tomoyo_str_starts(char **src, const char *find);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900497const char *tomoyo_get_exe(void);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900498void tomoyo_normalize_line(unsigned char *buffer);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900499void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...)
500 __attribute__ ((format(printf, 2, 3)));
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900501void tomoyo_check_profile(void);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900502int tomoyo_open_control(const u8 type, struct file *file);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900503int tomoyo_close_control(struct file *file);
Tetsuo Handa0849e3b2010-06-25 12:22:09 +0900504int tomoyo_poll_control(struct file *file, poll_table *wait);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900505int tomoyo_read_control(struct file *file, char __user *buffer,
506 const int buffer_len);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900507int tomoyo_write_control(struct file *file, const char __user *buffer,
508 const int buffer_len);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900509bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900510void tomoyo_warn_oom(const char *function);
Tetsuo Handa484ca792010-07-29 14:29:55 +0900511const struct tomoyo_path_info *
512tomoyo_compare_name_union(const struct tomoyo_path_info *name,
513 const struct tomoyo_name_union *ptr);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900514bool tomoyo_compare_number_union(const unsigned long value,
515 const struct tomoyo_number_union *ptr);
Tetsuo Handa57c25902010-06-03 20:38:44 +0900516int tomoyo_get_mode(const u8 profile, const u8 index);
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900517void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
Kentaro Takeda95908372009-02-05 17:18:13 +0900518 __attribute__ ((format(printf, 2, 3)));
Tetsuo Handa75093152010-06-16 16:23:55 +0900519bool tomoyo_correct_domain(const unsigned char *domainname);
Tetsuo Handa75093152010-06-16 16:23:55 +0900520bool tomoyo_correct_path(const char *filename);
521bool tomoyo_correct_word(const char *string);
Tetsuo Handa75093152010-06-16 16:23:55 +0900522bool tomoyo_domain_def(const unsigned char *buffer);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900523bool tomoyo_parse_name_union(const char *filename,
524 struct tomoyo_name_union *ptr);
Tetsuo Handa484ca792010-07-29 14:29:55 +0900525const struct tomoyo_path_info *
526tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
527 const struct tomoyo_group *group);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900528bool tomoyo_number_matches_group(const unsigned long min,
529 const unsigned long max,
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900530 const struct tomoyo_group *group);
Kentaro Takeda95908372009-02-05 17:18:13 +0900531bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
532 const struct tomoyo_path_info *pattern);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900533bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900534bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
Kentaro Takeda95908372009-02-05 17:18:13 +0900535bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900536int tomoyo_init_request_info(struct tomoyo_request_info *r,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900537 struct tomoyo_domain_info *domain,
538 const u8 index);
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900539int tomoyo_mount_permission(char *dev_name, struct path *path,
540 const char *type, unsigned long flags,
541 void *data_page);
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900542int tomoyo_write_aggregator(char *data, const bool is_delete);
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900543int tomoyo_write_transition_control(char *data, const bool is_delete,
544 const u8 type);
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900545int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain,
546 const bool is_delete);
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900547int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain,
548 const bool is_delete);
Tetsuo Handa7c2ea222010-06-17 16:55:58 +0900549int tomoyo_write_group(char *data, const bool is_delete, const u8 type);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900550int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
551 __attribute__ ((format(printf, 2, 3)));
Kentaro Takeda95908372009-02-05 17:18:13 +0900552struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900553struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
554 const u8 profile);
Tetsuo Handa57c25902010-06-03 20:38:44 +0900555struct tomoyo_profile *tomoyo_profile(const u8 profile);
Tetsuo Handa7c2ea222010-06-17 16:55:58 +0900556struct tomoyo_group *tomoyo_get_group(const char *group_name, const u8 type);
Kentaro Takeda95908372009-02-05 17:18:13 +0900557unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
558 const u8 index);
Kentaro Takeda95908372009-02-05 17:18:13 +0900559void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
Kentaro Takeda95908372009-02-05 17:18:13 +0900560void tomoyo_load_policy(const char *filename);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900561void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900562char *tomoyo_encode(const char *str);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900563char *tomoyo_realpath_nofollow(const char *pathname);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900564char *tomoyo_realpath_from_path(struct path *path);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900565bool tomoyo_memory_ok(void *ptr);
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900566void *tomoyo_commit_ok(void *data, const unsigned int size);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900567const struct tomoyo_path_info *tomoyo_get_name(const char *name);
Tetsuo Handa8fbe71f2010-06-16 16:29:59 +0900568void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900569int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900570void __init tomoyo_mm_init(void);
Tetsuo Handa05336de2010-06-16 16:20:24 +0900571int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900572 const struct tomoyo_path_info *filename);
573int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
574 struct path *path, const int flag);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900575int tomoyo_path_number_perm(const u8 operation, struct path *path,
576 unsigned long number);
Tetsuo Handa75093152010-06-16 16:23:55 +0900577int tomoyo_mkdev_perm(const u8 operation, struct path *path,
578 const unsigned int mode, unsigned int dev);
Tetsuo Handa97d69312010-02-16 09:46:15 +0900579int tomoyo_path_perm(const u8 operation, struct path *path);
580int tomoyo_path2_perm(const u8 operation, struct path *path1,
581 struct path *path2);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900582int tomoyo_find_next_domain(struct linux_binprm *bprm);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900583void tomoyo_print_ulong(char *buffer, const int buffer_len,
584 const unsigned long value, const u8 type);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900585void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900586void tomoyo_run_gc(void);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900587void tomoyo_memory_free(void *ptr);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900588int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
589 bool is_delete, struct tomoyo_domain_info *domain,
590 bool (*check_duplicate) (const struct tomoyo_acl_info
591 *,
592 const struct tomoyo_acl_info
593 *),
594 bool (*merge_duplicate) (struct tomoyo_acl_info *,
595 struct tomoyo_acl_info *,
596 const bool));
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900597int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
598 bool is_delete, struct list_head *list,
599 bool (*check_duplicate) (const struct tomoyo_acl_head
600 *,
601 const struct tomoyo_acl_head
602 *));
Tetsuo Handa99a85252010-06-16 16:22:51 +0900603void tomoyo_check_acl(struct tomoyo_request_info *r,
Tetsuo Handa484ca792010-07-29 14:29:55 +0900604 bool (*check_entry) (struct tomoyo_request_info *,
Tetsuo Handa99a85252010-06-16 16:22:51 +0900605 const struct tomoyo_acl_info *));
Tetsuo Handa237ab452010-06-12 20:46:22 +0900606
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900607/********** External variable definitions. **********/
608
609/* Lock for GC. */
610extern struct srcu_struct tomoyo_ss;
611
612/* The list for "struct tomoyo_domain_info". */
613extern struct list_head tomoyo_domain_list;
614
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900615extern struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY];
616extern struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP];
Tetsuo Handa847b1732010-02-11 09:43:54 +0900617extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
Tetsuo Handa847b1732010-02-11 09:43:54 +0900618
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900619/* Lock for protecting policy. */
620extern struct mutex tomoyo_policy_lock;
621
622/* Has /sbin/init started? */
623extern bool tomoyo_policy_loaded;
624
625/* The kernel's domain. */
626extern struct tomoyo_domain_info tomoyo_kernel_domain;
627
Tetsuo Handa71c28232010-06-16 16:26:38 +0900628extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
629extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION];
630extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION];
631extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION];
632
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900633extern unsigned int tomoyo_quota_for_query;
634extern unsigned int tomoyo_query_memory_size;
635
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900636/********** Inlined functions. **********/
637
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900638/**
639 * tomoyo_read_lock - Take lock for protecting policy.
640 *
641 * Returns index number for tomoyo_read_unlock().
642 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900643static inline int tomoyo_read_lock(void)
644{
645 return srcu_read_lock(&tomoyo_ss);
646}
647
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900648/**
649 * tomoyo_read_unlock - Release lock for protecting policy.
650 *
651 * @idx: Index number returned by tomoyo_read_lock().
652 *
653 * Returns nothing.
654 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900655static inline void tomoyo_read_unlock(int idx)
656{
657 srcu_read_unlock(&tomoyo_ss, idx);
658}
659
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900660/**
661 * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
662 *
663 * @a: Pointer to "struct tomoyo_path_info".
664 * @b: Pointer to "struct tomoyo_path_info".
665 *
666 * Returns true if @a == @b, false otherwise.
667 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900668static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
669 const struct tomoyo_path_info *b)
670{
671 return a->hash != b->hash || strcmp(a->name, b->name);
672}
673
Kentaro Takeda95908372009-02-05 17:18:13 +0900674/**
Tetsuo Handa75093152010-06-16 16:23:55 +0900675 * tomoyo_valid - Check whether the character is a valid char.
Kentaro Takeda95908372009-02-05 17:18:13 +0900676 *
677 * @c: The character to check.
678 *
679 * Returns true if @c is a valid character, false otherwise.
680 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900681static inline bool tomoyo_valid(const unsigned char c)
Kentaro Takeda95908372009-02-05 17:18:13 +0900682{
683 return c > ' ' && c < 127;
684}
685
686/**
Tetsuo Handa75093152010-06-16 16:23:55 +0900687 * tomoyo_invalid - Check whether the character is an invalid char.
Kentaro Takeda95908372009-02-05 17:18:13 +0900688 *
689 * @c: The character to check.
690 *
691 * Returns true if @c is an invalid character, false otherwise.
692 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900693static inline bool tomoyo_invalid(const unsigned char c)
Kentaro Takeda95908372009-02-05 17:18:13 +0900694{
695 return c && (c <= ' ' || c >= 127);
696}
697
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900698/**
699 * tomoyo_put_name - Drop reference on "struct tomoyo_name".
700 *
701 * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
702 *
703 * Returns nothing.
704 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900705static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
706{
707 if (name) {
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900708 struct tomoyo_name *ptr =
709 container_of(name, typeof(*ptr), entry);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900710 atomic_dec(&ptr->users);
711 }
712}
Kentaro Takeda95908372009-02-05 17:18:13 +0900713
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900714/**
715 * tomoyo_put_group - Drop reference on "struct tomoyo_group".
716 *
717 * @group: Pointer to "struct tomoyo_group". Maybe NULL.
718 *
719 * Returns nothing.
720 */
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900721static inline void tomoyo_put_group(struct tomoyo_group *group)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900722{
723 if (group)
724 atomic_dec(&group->users);
725}
726
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900727/**
728 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
729 *
730 * Returns pointer to "struct tomoyo_domain_info" for current thread.
731 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900732static inline struct tomoyo_domain_info *tomoyo_domain(void)
733{
734 return current_cred()->security;
735}
Kentaro Takeda95908372009-02-05 17:18:13 +0900736
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900737/**
738 * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
739 *
740 * @task: Pointer to "struct task_struct".
741 *
742 * Returns pointer to "struct tomoyo_security" for specified thread.
743 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900744static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
745 *task)
746{
747 return task_cred_xxx(task, security);
748}
Kentaro Takeda95908372009-02-05 17:18:13 +0900749
Tetsuo Handa75093152010-06-16 16:23:55 +0900750static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info *p1,
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900751 const struct tomoyo_acl_info *p2)
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900752{
753 return p1->type == p2->type;
754}
755
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900756/**
757 * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
758 *
759 * @a: Pointer to "struct tomoyo_name_union".
760 * @b: Pointer to "struct tomoyo_name_union".
761 *
762 * Returns true if @a == @b, false otherwise.
763 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900764static inline bool tomoyo_same_name_union
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900765(const struct tomoyo_name_union *a, const struct tomoyo_name_union *b)
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900766{
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900767 return a->filename == b->filename && a->group == b->group &&
768 a->is_group == b->is_group;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900769}
770
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900771/**
772 * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
773 *
774 * @a: Pointer to "struct tomoyo_number_union".
775 * @b: Pointer to "struct tomoyo_number_union".
776 *
777 * Returns true if @a == @b, false otherwise.
778 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900779static inline bool tomoyo_same_number_union
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900780(const struct tomoyo_number_union *a, const struct tomoyo_number_union *b)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900781{
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900782 return a->values[0] == b->values[0] && a->values[1] == b->values[1] &&
783 a->group == b->group && a->min_type == b->min_type &&
784 a->max_type == b->max_type && a->is_group == b->is_group;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900785}
786
Kentaro Takeda95908372009-02-05 17:18:13 +0900787/**
788 * list_for_each_cookie - iterate over a list with cookie.
789 * @pos: the &struct list_head to use as a loop cursor.
Kentaro Takeda95908372009-02-05 17:18:13 +0900790 * @head: the head for your list.
Kentaro Takeda95908372009-02-05 17:18:13 +0900791 */
Tetsuo Handa475e6fa2010-06-24 11:28:14 +0900792#define list_for_each_cookie(pos, head) \
793 if (!pos) \
794 pos = srcu_dereference((head)->next, &tomoyo_ss); \
795 for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900796
Kentaro Takeda95908372009-02-05 17:18:13 +0900797#endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */