aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>2011-06-26 10:16:03 -0400
committerJames Morris <jmorris@namei.org>2011-06-28 19:31:19 -0400
commitb5bc60b4ce313b6dbb42e7d32915dcf0a07c2a68 (patch)
tree4a6a4f4cf1b6d0e5fa22c974fb4cf87d59a88e21
parent7c75964f432d14062d8eccfc916aa290f56b5aab (diff)
TOMOYO: Cleanup part 2.
Update (or temporarily remove) comments. Remove or replace some of #define lines. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: James Morris <jmorris@namei.org>
-rw-r--r--security/tomoyo/common.c38
-rw-r--r--security/tomoyo/common.h441
-rw-r--r--security/tomoyo/file.c3
-rw-r--r--security/tomoyo/mount.c79
-rw-r--r--security/tomoyo/securityfs_if.c2
5 files changed, 204 insertions, 359 deletions
diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c
index 0776173b7d2b..1c340217a06a 100644
--- a/security/tomoyo/common.c
+++ b/security/tomoyo/common.c
@@ -643,7 +643,7 @@ static int tomoyo_update_manager_entry(const char *manager,
643static int tomoyo_write_manager(struct tomoyo_io_buffer *head) 643static int tomoyo_write_manager(struct tomoyo_io_buffer *head)
644{ 644{
645 char *data = head->write_buf; 645 char *data = head->write_buf;
646 bool is_delete = tomoyo_str_starts(&data, TOMOYO_KEYWORD_DELETE); 646 bool is_delete = tomoyo_str_starts(&data, "delete ");
647 647
648 if (!strcmp(data, "manage_by_non_root")) { 648 if (!strcmp(data, "manage_by_non_root")) {
649 tomoyo_manage_by_non_root = !is_delete; 649 tomoyo_manage_by_non_root = !is_delete;
@@ -830,7 +830,7 @@ static int tomoyo_delete_domain(char *domainname)
830static int tomoyo_write_domain2(char *data, struct tomoyo_domain_info *domain, 830static int tomoyo_write_domain2(char *data, struct tomoyo_domain_info *domain,
831 const bool is_delete) 831 const bool is_delete)
832{ 832{
833 if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_ALLOW_MOUNT)) 833 if (tomoyo_str_starts(&data, "allow_mount "))
834 return tomoyo_write_mount(data, domain, is_delete); 834 return tomoyo_write_mount(data, domain, is_delete);
835 return tomoyo_write_file(data, domain, is_delete); 835 return tomoyo_write_file(data, domain, is_delete);
836} 836}
@@ -852,9 +852,9 @@ static int tomoyo_write_domain(struct tomoyo_io_buffer *head)
852 bool is_select = false; 852 bool is_select = false;
853 unsigned int profile; 853 unsigned int profile;
854 854
855 if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_DELETE)) 855 if (tomoyo_str_starts(&data, "delete "))
856 is_delete = true; 856 is_delete = true;
857 else if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_SELECT)) 857 else if (tomoyo_str_starts(&data, "select "))
858 is_select = true; 858 is_select = true;
859 if (is_select && tomoyo_select_one(head, data)) 859 if (is_select && tomoyo_select_one(head, data))
860 return 0; 860 return 0;
@@ -875,17 +875,17 @@ static int tomoyo_write_domain(struct tomoyo_io_buffer *head)
875 if (!domain) 875 if (!domain)
876 return -EINVAL; 876 return -EINVAL;
877 877
878 if (sscanf(data, TOMOYO_KEYWORD_USE_PROFILE "%u", &profile) == 1 878 if (sscanf(data, "use_profile %u", &profile) == 1
879 && profile < TOMOYO_MAX_PROFILES) { 879 && profile < TOMOYO_MAX_PROFILES) {
880 if (tomoyo_profile_ptr[profile] || !tomoyo_policy_loaded) 880 if (tomoyo_profile_ptr[profile] || !tomoyo_policy_loaded)
881 domain->profile = (u8) profile; 881 domain->profile = (u8) profile;
882 return 0; 882 return 0;
883 } 883 }
884 if (!strcmp(data, TOMOYO_KEYWORD_QUOTA_EXCEEDED)) { 884 if (!strcmp(data, "quota_exceeded")) {
885 domain->quota_warned = !is_delete; 885 domain->quota_warned = !is_delete;
886 return 0; 886 return 0;
887 } 887 }
888 if (!strcmp(data, TOMOYO_KEYWORD_TRANSITION_FAILED)) { 888 if (!strcmp(data, "transition_failed")) {
889 domain->transition_failed = !is_delete; 889 domain->transition_failed = !is_delete;
890 return 0; 890 return 0;
891 } 891 }
@@ -1039,8 +1039,7 @@ static void tomoyo_read_domain(struct tomoyo_io_buffer *head)
1039 /* Print domainname and flags. */ 1039 /* Print domainname and flags. */
1040 tomoyo_set_string(head, domain->domainname->name); 1040 tomoyo_set_string(head, domain->domainname->name);
1041 tomoyo_set_lf(head); 1041 tomoyo_set_lf(head);
1042 tomoyo_io_printf(head, 1042 tomoyo_io_printf(head, "use_profile %u\n",
1043 TOMOYO_KEYWORD_USE_PROFILE "%u\n",
1044 domain->profile); 1043 domain->profile);
1045 if (domain->quota_warned) 1044 if (domain->quota_warned)
1046 tomoyo_set_string(head, "quota_exceeded\n"); 1045 tomoyo_set_string(head, "quota_exceeded\n");
@@ -1192,17 +1191,15 @@ static void tomoyo_read_pid(struct tomoyo_io_buffer *head)
1192} 1191}
1193 1192
1194static const char *tomoyo_transition_type[TOMOYO_MAX_TRANSITION_TYPE] = { 1193static const char *tomoyo_transition_type[TOMOYO_MAX_TRANSITION_TYPE] = {
1195 [TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE] 1194 [TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE] = "no_initialize_domain",
1196 = TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN, 1195 [TOMOYO_TRANSITION_CONTROL_INITIALIZE] = "initialize_domain",
1197 [TOMOYO_TRANSITION_CONTROL_INITIALIZE] 1196 [TOMOYO_TRANSITION_CONTROL_NO_KEEP] = "no_keep_domain",
1198 = TOMOYO_KEYWORD_INITIALIZE_DOMAIN, 1197 [TOMOYO_TRANSITION_CONTROL_KEEP] = "keep_domain",
1199 [TOMOYO_TRANSITION_CONTROL_NO_KEEP] = TOMOYO_KEYWORD_NO_KEEP_DOMAIN,
1200 [TOMOYO_TRANSITION_CONTROL_KEEP] = TOMOYO_KEYWORD_KEEP_DOMAIN
1201}; 1198};
1202 1199
1203static const char *tomoyo_group_name[TOMOYO_MAX_GROUP] = { 1200static const char *tomoyo_group_name[TOMOYO_MAX_GROUP] = {
1204 [TOMOYO_PATH_GROUP] = TOMOYO_KEYWORD_PATH_GROUP, 1201 [TOMOYO_PATH_GROUP] = "path_group ",
1205 [TOMOYO_NUMBER_GROUP] = TOMOYO_KEYWORD_NUMBER_GROUP 1202 [TOMOYO_NUMBER_GROUP] = "number_group ",
1206}; 1203};
1207 1204
1208/** 1205/**
@@ -1217,13 +1214,13 @@ static const char *tomoyo_group_name[TOMOYO_MAX_GROUP] = {
1217static int tomoyo_write_exception(struct tomoyo_io_buffer *head) 1214static int tomoyo_write_exception(struct tomoyo_io_buffer *head)
1218{ 1215{
1219 char *data = head->write_buf; 1216 char *data = head->write_buf;
1220 bool is_delete = tomoyo_str_starts(&data, TOMOYO_KEYWORD_DELETE); 1217 bool is_delete = tomoyo_str_starts(&data, "delete ");
1221 u8 i; 1218 u8 i;
1222 static const struct { 1219 static const struct {
1223 const char *keyword; 1220 const char *keyword;
1224 int (*write) (char *, const bool); 1221 int (*write) (char *, const bool);
1225 } tomoyo_callback[1] = { 1222 } tomoyo_callback[1] = {
1226 { TOMOYO_KEYWORD_AGGREGATOR, tomoyo_write_aggregator }, 1223 { "aggregator ", tomoyo_write_aggregator },
1227 }; 1224 };
1228 1225
1229 for (i = 0; i < TOMOYO_MAX_TRANSITION_TYPE; i++) 1226 for (i = 0; i < TOMOYO_MAX_TRANSITION_TYPE; i++)
@@ -1324,8 +1321,7 @@ static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx)
1324 { 1321 {
1325 struct tomoyo_aggregator *ptr = 1322 struct tomoyo_aggregator *ptr =
1326 container_of(acl, typeof(*ptr), head); 1323 container_of(acl, typeof(*ptr), head);
1327 tomoyo_set_string(head, 1324 tomoyo_set_string(head, "aggregator ");
1328 TOMOYO_KEYWORD_AGGREGATOR);
1329 tomoyo_set_string(head, 1325 tomoyo_set_string(head,
1330 ptr->original_name->name); 1326 ptr->original_name->name);
1331 tomoyo_set_space(head); 1327 tomoyo_set_space(head);
diff --git a/security/tomoyo/common.h b/security/tomoyo/common.h
index a5d6e212b18f..d0645733c102 100644
--- a/security/tomoyo/common.h
+++ b/security/tomoyo/common.h
@@ -38,6 +38,7 @@ struct linux_binprm;
38/* Profile number is an integer between 0 and 255. */ 38/* Profile number is an integer between 0 and 255. */
39#define TOMOYO_MAX_PROFILES 256 39#define TOMOYO_MAX_PROFILES 256
40 40
41/* Index numbers for operation mode. */
41enum tomoyo_mode_index { 42enum tomoyo_mode_index {
42 TOMOYO_CONFIG_DISABLED, 43 TOMOYO_CONFIG_DISABLED,
43 TOMOYO_CONFIG_LEARNING, 44 TOMOYO_CONFIG_LEARNING,
@@ -46,6 +47,7 @@ enum tomoyo_mode_index {
46 TOMOYO_CONFIG_USE_DEFAULT = 255 47 TOMOYO_CONFIG_USE_DEFAULT = 255
47}; 48};
48 49
50/* Index numbers for entry type. */
49enum tomoyo_policy_id { 51enum tomoyo_policy_id {
50 TOMOYO_ID_GROUP, 52 TOMOYO_ID_GROUP,
51 TOMOYO_ID_PATH_GROUP, 53 TOMOYO_ID_PATH_GROUP,
@@ -59,37 +61,26 @@ enum tomoyo_policy_id {
59 TOMOYO_MAX_POLICY 61 TOMOYO_MAX_POLICY
60}; 62};
61 63
64/* Index numbers for group entries. */
62enum tomoyo_group_id { 65enum tomoyo_group_id {
63 TOMOYO_PATH_GROUP, 66 TOMOYO_PATH_GROUP,
64 TOMOYO_NUMBER_GROUP, 67 TOMOYO_NUMBER_GROUP,
65 TOMOYO_MAX_GROUP 68 TOMOYO_MAX_GROUP
66}; 69};
67 70
68/* Keywords for ACLs. */
69#define TOMOYO_KEYWORD_AGGREGATOR "aggregator "
70#define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount "
71#define TOMOYO_KEYWORD_ALLOW_READ "allow_read "
72#define TOMOYO_KEYWORD_DELETE "delete "
73#define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain "
74#define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain "
75#define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain "
76#define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain "
77#define TOMOYO_KEYWORD_PATH_GROUP "path_group "
78#define TOMOYO_KEYWORD_NUMBER_GROUP "number_group "
79#define TOMOYO_KEYWORD_SELECT "select "
80#define TOMOYO_KEYWORD_USE_PROFILE "use_profile "
81#define TOMOYO_KEYWORD_QUOTA_EXCEEDED "quota_exceeded"
82#define TOMOYO_KEYWORD_TRANSITION_FAILED "transition_failed"
83/* A domain definition starts with <kernel>. */ 71/* A domain definition starts with <kernel>. */
84#define TOMOYO_ROOT_NAME "<kernel>" 72#define TOMOYO_ROOT_NAME "<kernel>"
85#define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1) 73#define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1)
86 74
87/* Value type definition. */ 75/* Index numbers for type of numeric values. */
88#define TOMOYO_VALUE_TYPE_INVALID 0 76enum tomoyo_value_type {
89#define TOMOYO_VALUE_TYPE_DECIMAL 1 77 TOMOYO_VALUE_TYPE_INVALID,
90#define TOMOYO_VALUE_TYPE_OCTAL 2 78 TOMOYO_VALUE_TYPE_DECIMAL,
91#define TOMOYO_VALUE_TYPE_HEXADECIMAL 3 79 TOMOYO_VALUE_TYPE_OCTAL,
80 TOMOYO_VALUE_TYPE_HEXADECIMAL,
81};
92 82
83/* Index numbers for domain transition control keywords. */
93enum tomoyo_transition_type { 84enum tomoyo_transition_type {
94 /* Do not change this order, */ 85 /* Do not change this order, */
95 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE, 86 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE,
@@ -108,7 +99,7 @@ enum tomoyo_acl_entry_type_index {
108 TOMOYO_TYPE_MOUNT_ACL, 99 TOMOYO_TYPE_MOUNT_ACL,
109}; 100};
110 101
111/* Index numbers for File Controls. */ 102/* Index numbers for access controls with one pathname. */
112enum tomoyo_path_acl_index { 103enum tomoyo_path_acl_index {
113 TOMOYO_TYPE_EXECUTE, 104 TOMOYO_TYPE_EXECUTE,
114 TOMOYO_TYPE_READ, 105 TOMOYO_TYPE_READ,
@@ -130,6 +121,7 @@ enum tomoyo_mkdev_acl_index {
130 TOMOYO_MAX_MKDEV_OPERATION 121 TOMOYO_MAX_MKDEV_OPERATION
131}; 122};
132 123
124/* Index numbers for access controls with two pathnames. */
133enum tomoyo_path2_acl_index { 125enum tomoyo_path2_acl_index {
134 TOMOYO_TYPE_LINK, 126 TOMOYO_TYPE_LINK,
135 TOMOYO_TYPE_RENAME, 127 TOMOYO_TYPE_RENAME,
@@ -137,6 +129,7 @@ enum tomoyo_path2_acl_index {
137 TOMOYO_MAX_PATH2_OPERATION 129 TOMOYO_MAX_PATH2_OPERATION
138}; 130};
139 131
132/* Index numbers for access controls with one pathname and one number. */
140enum tomoyo_path_number_acl_index { 133enum tomoyo_path_number_acl_index {
141 TOMOYO_TYPE_CREATE, 134 TOMOYO_TYPE_CREATE,
142 TOMOYO_TYPE_MKDIR, 135 TOMOYO_TYPE_MKDIR,
@@ -149,6 +142,7 @@ enum tomoyo_path_number_acl_index {
149 TOMOYO_MAX_PATH_NUMBER_OPERATION 142 TOMOYO_MAX_PATH_NUMBER_OPERATION
150}; 143};
151 144
145/* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
152enum tomoyo_securityfs_interface_index { 146enum tomoyo_securityfs_interface_index {
153 TOMOYO_DOMAINPOLICY, 147 TOMOYO_DOMAINPOLICY,
154 TOMOYO_EXCEPTIONPOLICY, 148 TOMOYO_EXCEPTIONPOLICY,
@@ -162,6 +156,19 @@ enum tomoyo_securityfs_interface_index {
162 TOMOYO_MANAGER 156 TOMOYO_MANAGER
163}; 157};
164 158
159/* 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. */
165enum tomoyo_mac_index { 172enum tomoyo_mac_index {
166 TOMOYO_MAC_FILE_EXECUTE, 173 TOMOYO_MAC_FILE_EXECUTE,
167 TOMOYO_MAC_FILE_OPEN, 174 TOMOYO_MAC_FILE_OPEN,
@@ -189,37 +196,30 @@ enum tomoyo_mac_index {
189 TOMOYO_MAX_MAC_INDEX 196 TOMOYO_MAX_MAC_INDEX
190}; 197};
191 198
199/* Index numbers for category of functionality. */
192enum tomoyo_mac_category_index { 200enum tomoyo_mac_category_index {
193 TOMOYO_MAC_CATEGORY_FILE, 201 TOMOYO_MAC_CATEGORY_FILE,
194 TOMOYO_MAX_MAC_CATEGORY_INDEX 202 TOMOYO_MAX_MAC_CATEGORY_INDEX
195}; 203};
196 204
197#define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */
198
199/********** Structure definitions. **********/
200
201/* 205/*
202 * tomoyo_acl_head is a structure which is used for holding elements not in 206 * Retry this request. Returned by tomoyo_supervisor() if policy violation has
203 * domain policy. 207 * occurred in enforcing mode and the userspace daemon decided to retry.
204 * It has following fields.
205 * 208 *
206 * (1) "list" which is linked to tomoyo_policy_list[] . 209 * We must choose a positive value in order to distinguish "granted" (which is
207 * (2) "is_deleted" is a bool which is true if marked as deleted, false 210 * 0) and "rejected" (which is a negative value) and "retry".
208 * otherwise.
209 */ 211 */
212#define TOMOYO_RETRY_REQUEST 1
213
214/********** Structure definitions. **********/
215
216/* Common header for holding ACL entries. */
210struct tomoyo_acl_head { 217struct tomoyo_acl_head {
211 struct list_head list; 218 struct list_head list;
212 bool is_deleted; 219 bool is_deleted;
213} __packed; 220} __packed;
214 221
215/* 222/* Structure for request info. */
216 * tomoyo_request_info is a structure which is used for holding
217 *
218 * (1) Domain information of current process.
219 * (2) How many retries are made for this request.
220 * (3) Profile number used for this request.
221 * (4) Access control mode of the profile.
222 */
223struct tomoyo_request_info { 223struct tomoyo_request_info {
224 struct tomoyo_domain_info *domain; 224 struct tomoyo_domain_info *domain;
225 /* For holding parameters. */ 225 /* For holding parameters. */
@@ -228,11 +228,13 @@ struct tomoyo_request_info {
228 const struct tomoyo_path_info *filename; 228 const struct tomoyo_path_info *filename;
229 /* For using wildcards at tomoyo_find_next_domain(). */ 229 /* For using wildcards at tomoyo_find_next_domain(). */
230 const struct tomoyo_path_info *matched_path; 230 const struct tomoyo_path_info *matched_path;
231 /* One of values in "enum tomoyo_path_acl_index". */
231 u8 operation; 232 u8 operation;
232 } path; 233 } path;
233 struct { 234 struct {
234 const struct tomoyo_path_info *filename1; 235 const struct tomoyo_path_info *filename1;
235 const struct tomoyo_path_info *filename2; 236 const struct tomoyo_path_info *filename2;
237 /* One of values in "enum tomoyo_path2_acl_index". */
236 u8 operation; 238 u8 operation;
237 } path2; 239 } path2;
238 struct { 240 struct {
@@ -240,11 +242,16 @@ struct tomoyo_request_info {
240 unsigned int mode; 242 unsigned int mode;
241 unsigned int major; 243 unsigned int major;
242 unsigned int minor; 244 unsigned int minor;
245 /* One of values in "enum tomoyo_mkdev_acl_index". */
243 u8 operation; 246 u8 operation;
244 } mkdev; 247 } mkdev;
245 struct { 248 struct {
246 const struct tomoyo_path_info *filename; 249 const struct tomoyo_path_info *filename;
247 unsigned long number; 250 unsigned long number;
251 /*
252 * One of values in
253 * "enum tomoyo_path_number_acl_index".
254 */
248 u8 operation; 255 u8 operation;
249 } path_number; 256 } path_number;
250 struct { 257 struct {
@@ -263,26 +270,7 @@ struct tomoyo_request_info {
263 u8 type; 270 u8 type;
264}; 271};
265 272
266/* 273/* Structure for holding a token. */
267 * tomoyo_path_info is a structure which is used for holding a string data
268 * used by TOMOYO.
269 * This structure has several fields for supporting pattern matching.
270 *
271 * (1) "name" is the '\0' terminated string data.
272 * (2) "hash" is full_name_hash(name, strlen(name)).
273 * This allows tomoyo_pathcmp() to compare by hash before actually compare
274 * using strcmp().
275 * (3) "const_len" is the length of the initial segment of "name" which
276 * consists entirely of non wildcard characters. In other words, the length
277 * which we can compare two strings using strncmp().
278 * (4) "is_dir" is a bool which is true if "name" ends with "/",
279 * false otherwise.
280 * TOMOYO distinguishes directory and non-directory. A directory ends with
281 * "/" and non-directory does not end with "/".
282 * (5) "is_patterned" is a bool which is true if "name" contains wildcard
283 * characters, false otherwise. This allows TOMOYO to use "hash" and
284 * strcmp() for string comparison if "is_patterned" is false.
285 */
286struct tomoyo_path_info { 274struct tomoyo_path_info {
287 const char *name; 275 const char *name;
288 u32 hash; /* = full_name_hash(name, strlen(name)) */ 276 u32 hash; /* = full_name_hash(name, strlen(name)) */
@@ -291,27 +279,30 @@ struct tomoyo_path_info {
291 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ 279 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
292}; 280};
293 281
294/* 282/* Structure for holding string data. */
295 * tomoyo_name is a structure which is used for linking
296 * "struct tomoyo_path_info" into tomoyo_name_list .
297 */
298struct tomoyo_name { 283struct tomoyo_name {
299 struct list_head list; 284 struct list_head list;
300 atomic_t users; 285 atomic_t users;
301 struct tomoyo_path_info entry; 286 struct tomoyo_path_info entry;
302}; 287};
303 288
289/* Structure for holding a word. */
304struct tomoyo_name_union { 290struct tomoyo_name_union {
291 /* Either @filename or @group is NULL. */
305 const struct tomoyo_path_info *filename; 292 const struct tomoyo_path_info *filename;
306 struct tomoyo_group *group; 293 struct tomoyo_group *group;
294 /* True if @group != NULL, false if @filename != NULL. */
307 u8 is_group; 295 u8 is_group;
308}; 296};
309 297
298/* Structure for holding a number. */
310struct tomoyo_number_union { 299struct tomoyo_number_union {
311 unsigned long values[2]; 300 unsigned long values[2];
312 struct tomoyo_group *group; 301 struct tomoyo_group *group; /* Maybe NULL. */
302 /* One of values in "enum tomoyo_value_type". */
313 u8 min_type; 303 u8 min_type;
314 u8 max_type; 304 u8 max_type;
305 /* True if @group != NULL, false otherwise. */
315 u8 is_group; 306 u8 is_group;
316}; 307};
317 308
@@ -335,56 +326,14 @@ struct tomoyo_number_group {
335 struct tomoyo_number_union number; 326 struct tomoyo_number_union number;
336}; 327};
337 328
338/* 329/* Common header for individual entries. */
339 * tomoyo_acl_info is a structure which is used for holding
340 *
341 * (1) "list" which is linked to the ->acl_info_list of
342 * "struct tomoyo_domain_info"
343 * (2) "is_deleted" is a bool which is true if this domain is marked as
344 * "deleted", false otherwise.
345 * (3) "type" which tells type of the entry.
346 *
347 * Packing "struct tomoyo_acl_info" allows
348 * "struct tomoyo_path_acl" to embed "u16" and "struct tomoyo_path2_acl"
349 * "struct tomoyo_path_number_acl" "struct tomoyo_mkdev_acl" to embed
350 * "u8" without enlarging their structure size.
351 */
352struct tomoyo_acl_info { 330struct tomoyo_acl_info {
353 struct list_head list; 331 struct list_head list;
354 bool is_deleted; 332 bool is_deleted;
355 u8 type; /* = one of values in "enum tomoyo_acl_entry_type_index". */ 333 u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */
356} __packed; 334} __packed;
357 335
358/* 336/* Structure for domain information. */
359 * tomoyo_domain_info is a structure which is used for holding permissions
360 * (e.g. "allow_read /lib/libc-2.5.so") given to each domain.
361 * It has following fields.
362 *
363 * (1) "list" which is linked to tomoyo_domain_list .
364 * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info".
365 * (3) "domainname" which holds the name of the domain.
366 * (4) "profile" which remembers profile number assigned to this domain.
367 * (5) "is_deleted" is a bool which is true if this domain is marked as
368 * "deleted", false otherwise.
369 * (6) "quota_warned" is a bool which is used for suppressing warning message
370 * when learning mode learned too much entries.
371 * (7) "transition_failed" is a bool which is set to true when this domain was
372 * unable to create a new domain at tomoyo_find_next_domain() because the
373 * name of the domain to be created was too long or it could not allocate
374 * memory. If set to true, more than one process continued execve()
375 * without domain transition.
376 * (9) "users" is an atomic_t that holds how many "struct cred"->security
377 * are referring this "struct tomoyo_domain_info". If is_deleted == true
378 * and users == 0, this struct will be kfree()d upon next garbage
379 * collection.
380 *
381 * A domain's lifecycle is an analogy of files on / directory.
382 * Multiple domains with the same domainname cannot be created (as with
383 * creating files with the same filename fails with -EEXIST).
384 * If a process reached a domain, that process can reside in that domain after
385 * that domain is marked as "deleted" (as with a process can access an already
386 * open()ed file after that file was unlink()ed).
387 */
388struct tomoyo_domain_info { 337struct tomoyo_domain_info {
389 struct list_head list; 338 struct list_head list;
390 struct list_head acl_info_list; 339 struct list_head acl_info_list;
@@ -398,63 +347,32 @@ struct tomoyo_domain_info {
398}; 347};
399 348
400/* 349/*
401 * tomoyo_path_acl is a structure which is used for holding an 350 * Structure for "file execute", "file read", "file write", "file append",
402 * entry with one pathname operation (e.g. open(), mkdir()). 351 * "file unlink", "file getattr", "file rmdir", "file truncate",
403 * It has following fields. 352 * "file symlink", "file chroot" and "file unmount" directive.
404 *
405 * (1) "head" which is a "struct tomoyo_acl_info".
406 * (2) "perm" which is a bitmask of permitted operations.
407 * (3) "name" is the pathname.
408 *
409 * Directives held by this structure are "allow_execute", "allow_read",
410 * "allow_write", "allow_append", "allow_unlink", "allow_rmdir",
411 * "allow_truncate", "allow_symlink", "allow_chroot" and "allow_unmount".
412 */ 353 */
413struct tomoyo_path_acl { 354struct tomoyo_path_acl {
414 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ 355 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
415 u16 perm; 356 u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */
416 struct tomoyo_name_union name; 357 struct tomoyo_name_union name;
417}; 358};
418 359
419/* 360/*
420 * tomoyo_path_number_acl is a structure which is used for holding an 361 * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
421 * entry with one pathname and one number operation. 362 * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
422 * It has following fields.
423 *
424 * (1) "head" which is a "struct tomoyo_acl_info".
425 * (2) "perm" which is a bitmask of permitted operations.
426 * (3) "name" is the pathname.
427 * (4) "number" is the numeric value.
428 *
429 * Directives held by this structure are "allow_create", "allow_mkdir",
430 * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown"
431 * and "allow_chgrp".
432 *
433 */ 363 */
434struct tomoyo_path_number_acl { 364struct tomoyo_path_number_acl {
435 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ 365 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
366 /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
436 u8 perm; 367 u8 perm;
437 struct tomoyo_name_union name; 368 struct tomoyo_name_union name;
438 struct tomoyo_number_union number; 369 struct tomoyo_number_union number;
439}; 370};
440 371
441/* 372/* Structure for "file mkblock" and "file mkchar" directive. */
442 * tomoyo_mkdev_acl is a structure which is used for holding an
443 * entry with one pathname and three numbers operation.
444 * It has following fields.
445 *
446 * (1) "head" which is a "struct tomoyo_acl_info".
447 * (2) "perm" which is a bitmask of permitted operations.
448 * (3) "mode" is the create mode.
449 * (4) "major" is the major number of device node.
450 * (5) "minor" is the minor number of device node.
451 *
452 * Directives held by this structure are "allow_mkchar", "allow_mkblock".
453 *
454 */
455struct tomoyo_mkdev_acl { 373struct tomoyo_mkdev_acl {
456 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */ 374 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */
457 u8 perm; 375 u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
458 struct tomoyo_name_union name; 376 struct tomoyo_name_union name;
459 struct tomoyo_number_union mode; 377 struct tomoyo_number_union mode;
460 struct tomoyo_number_union major; 378 struct tomoyo_number_union major;
@@ -462,38 +380,16 @@ struct tomoyo_mkdev_acl {
462}; 380};
463 381
464/* 382/*
465 * tomoyo_path2_acl is a structure which is used for holding an 383 * Structure for "file rename", "file link" and "file pivot_root" directive.
466 * entry with two pathnames operation (i.e. link(), rename() and pivot_root()).
467 * It has following fields.
468 *
469 * (1) "head" which is a "struct tomoyo_acl_info".
470 * (2) "perm" which is a bitmask of permitted operations.
471 * (3) "name1" is the source/old pathname.
472 * (4) "name2" is the destination/new pathname.
473 *
474 * Directives held by this structure are "allow_rename", "allow_link" and
475 * "allow_pivot_root".
476 */ 384 */
477struct tomoyo_path2_acl { 385struct tomoyo_path2_acl {
478 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ 386 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
479 u8 perm; 387 u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
480 struct tomoyo_name_union name1; 388 struct tomoyo_name_union name1;
481 struct tomoyo_name_union name2; 389 struct tomoyo_name_union name2;
482}; 390};
483 391
484/* 392/* Structure for "file mount" directive. */
485 * tomoyo_mount_acl is a structure which is used for holding an
486 * entry for mount operation.
487 * It has following fields.
488 *
489 * (1) "head" which is a "struct tomoyo_acl_info".
490 * (2) "dev_name" is the device name.
491 * (3) "dir_name" is the mount point.
492 * (4) "fs_type" is the filesystem type.
493 * (5) "flags" is the mount flags.
494 *
495 * Directive held by this structure is "allow_mount".
496 */
497struct tomoyo_mount_acl { 393struct tomoyo_mount_acl {
498 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ 394 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
499 struct tomoyo_name_union dev_name; 395 struct tomoyo_name_union dev_name;
@@ -550,18 +446,8 @@ struct tomoyo_io_buffer {
550}; 446};
551 447
552/* 448/*
553 * tomoyo_transition_control is a structure which is used for holding 449 * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
554 * "initialize_domain"/"no_initialize_domain"/"keep_domain"/"no_keep_domain" 450 * "no_keep_domain" keyword.
555 * entries.
556 * It has following fields.
557 *
558 * (1) "head" is "struct tomoyo_acl_head".
559 * (2) "type" is type of this entry.
560 * (3) "is_last_name" is a bool which is true if "domainname" is "the last
561 * component of a domainname", false otherwise.
562 * (4) "domainname" which is "a domainname" or "the last component of a
563 * domainname".
564 * (5) "program" which is a program's pathname.
565 */ 451 */
566struct tomoyo_transition_control { 452struct tomoyo_transition_control {
567 struct tomoyo_acl_head head; 453 struct tomoyo_acl_head head;
@@ -572,32 +458,14 @@ struct tomoyo_transition_control {
572 const struct tomoyo_path_info *program; /* Maybe NULL */ 458 const struct tomoyo_path_info *program; /* Maybe NULL */
573}; 459};
574 460
575/* 461/* Structure for "aggregator" keyword. */
576 * tomoyo_aggregator is a structure which is used for holding
577 * "aggregator" entries.
578 * It has following fields.
579 *
580 * (1) "head" is "struct tomoyo_acl_head".
581 * (2) "original_name" which is originally requested name.
582 * (3) "aggregated_name" which is name to rewrite.
583 */
584struct tomoyo_aggregator { 462struct tomoyo_aggregator {
585 struct tomoyo_acl_head head; 463 struct tomoyo_acl_head head;
586 const struct tomoyo_path_info *original_name; 464 const struct tomoyo_path_info *original_name;
587 const struct tomoyo_path_info *aggregated_name; 465 const struct tomoyo_path_info *aggregated_name;
588}; 466};
589 467
590/* 468/* Structure for policy manager. */
591 * tomoyo_manager is a structure which is used for holding list of
592 * domainnames or programs which are permitted to modify configuration via
593 * /sys/kernel/security/tomoyo/ interface.
594 * It has following fields.
595 *
596 * (1) "head" is "struct tomoyo_acl_head".
597 * (2) "is_domain" is a bool which is true if "manager" is a domainname, false
598 * otherwise.
599 * (3) "manager" is a domainname or a program's pathname.
600 */
601struct tomoyo_manager { 469struct tomoyo_manager {
602 struct tomoyo_acl_head head; 470 struct tomoyo_acl_head head;
603 bool is_domain; /* True if manager is a domainname. */ 471 bool is_domain; /* True if manager is a domainname. */
@@ -612,6 +480,7 @@ struct tomoyo_preference {
612 bool permissive_verbose; 480 bool permissive_verbose;
613}; 481};
614 482
483/* Structure for /sys/kernel/security/tomnoyo/profile interface. */
615struct tomoyo_profile { 484struct tomoyo_profile {
616 const struct tomoyo_path_info *comment; 485 const struct tomoyo_path_info *comment;
617 struct tomoyo_preference *learning; 486 struct tomoyo_preference *learning;
@@ -624,148 +493,80 @@ struct tomoyo_profile {
624 493
625/********** Function prototypes. **********/ 494/********** Function prototypes. **********/
626 495
627/* Check whether the given string starts with the given keyword. */
628bool tomoyo_str_starts(char **src, const char *find); 496bool tomoyo_str_starts(char **src, const char *find);
629/* Get tomoyo_realpath() of current process. */
630const char *tomoyo_get_exe(void); 497const char *tomoyo_get_exe(void);
631/* Format string. */
632void tomoyo_normalize_line(unsigned char *buffer); 498void tomoyo_normalize_line(unsigned char *buffer);
633/* Print warning or error message on console. */
634void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...) 499void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...)
635 __attribute__ ((format(printf, 2, 3))); 500 __attribute__ ((format(printf, 2, 3)));
636/* Check all profiles currently assigned to domains are defined. */
637void tomoyo_check_profile(void); 501void tomoyo_check_profile(void);
638/* Open operation for /sys/kernel/security/tomoyo/ interface. */
639int tomoyo_open_control(const u8 type, struct file *file); 502int tomoyo_open_control(const u8 type, struct file *file);
640/* Close /sys/kernel/security/tomoyo/ interface. */
641int tomoyo_close_control(struct file *file); 503int tomoyo_close_control(struct file *file);
642/* Poll operation for /sys/kernel/security/tomoyo/ interface. */
643int tomoyo_poll_control(struct file *file, poll_table *wait); 504int tomoyo_poll_control(struct file *file, poll_table *wait);
644/* Read operation for /sys/kernel/security/tomoyo/ interface. */
645int tomoyo_read_control(struct file *file, char __user *buffer, 505int tomoyo_read_control(struct file *file, char __user *buffer,
646 const int buffer_len); 506 const int buffer_len);
647/* Write operation for /sys/kernel/security/tomoyo/ interface. */
648int tomoyo_write_control(struct file *file, const char __user *buffer, 507int tomoyo_write_control(struct file *file, const char __user *buffer,
649 const int buffer_len); 508 const int buffer_len);
650/* Check whether the domain has too many ACL entries to hold. */
651bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); 509bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
652/* Print out of memory warning message. */
653void tomoyo_warn_oom(const char *function); 510void tomoyo_warn_oom(const char *function);
654/* Check whether the given name matches the given name_union. */
655const struct tomoyo_path_info * 511const struct tomoyo_path_info *
656tomoyo_compare_name_union(const struct tomoyo_path_info *name, 512tomoyo_compare_name_union(const struct tomoyo_path_info *name,
657 const struct tomoyo_name_union *ptr); 513 const struct tomoyo_name_union *ptr);
658/* Check whether the given number matches the given number_union. */
659bool tomoyo_compare_number_union(const unsigned long value, 514bool tomoyo_compare_number_union(const unsigned long value,
660 const struct tomoyo_number_union *ptr); 515 const struct tomoyo_number_union *ptr);
661int tomoyo_get_mode(const u8 profile, const u8 index); 516int tomoyo_get_mode(const u8 profile, const u8 index);
662void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) 517void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
663 __attribute__ ((format(printf, 2, 3))); 518 __attribute__ ((format(printf, 2, 3)));
664/* Check whether the domainname is correct. */
665bool tomoyo_correct_domain(const unsigned char *domainname); 519bool tomoyo_correct_domain(const unsigned char *domainname);
666/* Check whether the token is correct. */
667bool tomoyo_correct_path(const char *filename); 520bool tomoyo_correct_path(const char *filename);
668bool tomoyo_correct_word(const char *string); 521bool tomoyo_correct_word(const char *string);
669/* Check whether the token can be a domainname. */
670bool tomoyo_domain_def(const unsigned char *buffer); 522bool tomoyo_domain_def(const unsigned char *buffer);
671bool tomoyo_parse_name_union(const char *filename, 523bool tomoyo_parse_name_union(const char *filename,
672 struct tomoyo_name_union *ptr); 524 struct tomoyo_name_union *ptr);
673/* Check whether the given filename matches the given path_group. */
674const struct tomoyo_path_info * 525const struct tomoyo_path_info *
675tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, 526tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
676 const struct tomoyo_group *group); 527 const struct tomoyo_group *group);
677/* Check whether the given value matches the given number_group. */
678bool tomoyo_number_matches_group(const unsigned long min, 528bool tomoyo_number_matches_group(const unsigned long min,
679 const unsigned long max, 529 const unsigned long max,
680 const struct tomoyo_group *group); 530 const struct tomoyo_group *group);
681/* Check whether the given filename matches the given pattern. */
682bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, 531bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
683 const struct tomoyo_path_info *pattern); 532 const struct tomoyo_path_info *pattern);
684
685bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num); 533bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num);
686/* Tokenize a line. */
687bool tomoyo_tokenize(char *buffer, char *w[], size_t size); 534bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
688/* Write domain policy violation warning message to console? */
689bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); 535bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
690/* Fill "struct tomoyo_request_info". */
691int tomoyo_init_request_info(struct tomoyo_request_info *r, 536int tomoyo_init_request_info(struct tomoyo_request_info *r,
692 struct tomoyo_domain_info *domain, 537 struct tomoyo_domain_info *domain,
693 const u8 index); 538 const u8 index);
694/* Check permission for mount operation. */ 539int tomoyo_mount_permission(char *dev_name, struct path *path,
695int tomoyo_mount_permission(char *dev_name, struct path *path, char *type, 540 const char *type, unsigned long flags,
696 unsigned long flags, void *data_page); 541 void *data_page);
697/* Create "aggregator" entry in exception policy. */
698int tomoyo_write_aggregator(char *data, const bool is_delete); 542int tomoyo_write_aggregator(char *data, const bool is_delete);
699int tomoyo_write_transition_control(char *data, const bool is_delete, 543int tomoyo_write_transition_control(char *data, const bool is_delete,
700 const u8 type); 544 const u8 type);
701/*
702 * Create "allow_execute", "allow_read", "allow_write", "allow_append",
703 * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir",
704 * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar",
705 * "allow_truncate", "allow_symlink", "allow_rename" and "allow_link" entry
706 * in domain policy.
707 */
708int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain, 545int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain,
709 const bool is_delete); 546 const bool is_delete);
710/* Create "allow_mount" entry in domain policy. */
711int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain, 547int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain,
712 const bool is_delete); 548 const bool is_delete);
713/* Create "path_group"/"number_group" entry in exception policy. */
714int tomoyo_write_group(char *data, const bool is_delete, const u8 type); 549int tomoyo_write_group(char *data, const bool is_delete, const u8 type);
715int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) 550int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
716 __attribute__ ((format(printf, 2, 3))); 551 __attribute__ ((format(printf, 2, 3)));
717/* Find a domain by the given name. */
718struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); 552struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
719/* Find or create a domain by the given name. */
720struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname, 553struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
721 const u8 profile); 554 const u8 profile);
722struct tomoyo_profile *tomoyo_profile(const u8 profile); 555struct tomoyo_profile *tomoyo_profile(const u8 profile);
723/*
724 * Allocate memory for "struct tomoyo_path_group"/"struct tomoyo_number_group".
725 */
726struct tomoyo_group *tomoyo_get_group(const char *group_name, const u8 type); 556struct tomoyo_group *tomoyo_get_group(const char *group_name, const u8 type);
727
728/* Check mode for specified functionality. */
729unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, 557unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
730 const u8 index); 558 const u8 index);
731/* Fill in "struct tomoyo_path_info" members. */
732void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); 559void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
733/* Run policy loader when /sbin/init starts. */
734void tomoyo_load_policy(const char *filename); 560void tomoyo_load_policy(const char *filename);
735
736void tomoyo_put_number_union(struct tomoyo_number_union *ptr); 561void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
737
738/* Convert binary string to ascii string. */
739char *tomoyo_encode(const char *str); 562char *tomoyo_encode(const char *str);
740
741/*
742 * Returns realpath(3) of the given pathname except that
743 * ignores chroot'ed root and does not follow the final symlink.
744 */
745char *tomoyo_realpath_nofollow(const char *pathname); 563char *tomoyo_realpath_nofollow(const char *pathname);
746/*
747 * Returns realpath(3) of the given pathname except that
748 * ignores chroot'ed root and the pathname is already solved.
749 */
750char *tomoyo_realpath_from_path(struct path *path); 564char *tomoyo_realpath_from_path(struct path *path);
751
752/* Check memory quota. */
753bool tomoyo_memory_ok(void *ptr); 565bool tomoyo_memory_ok(void *ptr);
754void *tomoyo_commit_ok(void *data, const unsigned int size); 566void *tomoyo_commit_ok(void *data, const unsigned int size);
755
756/*
757 * Keep the given name on the RAM.
758 * The RAM is shared, so NEVER try to modify or kfree() the returned name.
759 */
760const struct tomoyo_path_info *tomoyo_get_name(const char *name); 567const struct tomoyo_path_info *tomoyo_get_name(const char *name);
761
762/* Check for memory usage. */
763void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head); 568void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
764
765/* Set memory quota. */
766int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head); 569int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);
767
768/* Initialize mm related code. */
769void __init tomoyo_mm_init(void); 570void __init tomoyo_mm_init(void);
770int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, 571int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
771 const struct tomoyo_path_info *filename); 572 const struct tomoyo_path_info *filename);
@@ -779,18 +580,11 @@ int tomoyo_path_perm(const u8 operation, struct path *path);
779int tomoyo_path2_perm(const u8 operation, struct path *path1, 580int tomoyo_path2_perm(const u8 operation, struct path *path1,
780 struct path *path2); 581 struct path *path2);
781int tomoyo_find_next_domain(struct linux_binprm *bprm); 582int tomoyo_find_next_domain(struct linux_binprm *bprm);
782
783void tomoyo_print_ulong(char *buffer, const int buffer_len, 583void tomoyo_print_ulong(char *buffer, const int buffer_len,
784 const unsigned long value, const u8 type); 584 const unsigned long value, const u8 type);
785
786/* Drop refcount on tomoyo_name_union. */
787void tomoyo_put_name_union(struct tomoyo_name_union *ptr); 585void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
788
789/* Run garbage collector. */
790void tomoyo_run_gc(void); 586void tomoyo_run_gc(void);
791
792void tomoyo_memory_free(void *ptr); 587void tomoyo_memory_free(void *ptr);
793
794int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size, 588int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
795 bool is_delete, struct tomoyo_domain_info *domain, 589 bool is_delete, struct tomoyo_domain_info *domain,
796 bool (*check_duplicate) (const struct tomoyo_acl_info 590 bool (*check_duplicate) (const struct tomoyo_acl_info
@@ -841,17 +635,36 @@ extern unsigned int tomoyo_query_memory_size;
841 635
842/********** Inlined functions. **********/ 636/********** Inlined functions. **********/
843 637
638/**
639 * tomoyo_read_lock - Take lock for protecting policy.
640 *
641 * Returns index number for tomoyo_read_unlock().
642 */
844static inline int tomoyo_read_lock(void) 643static inline int tomoyo_read_lock(void)
845{ 644{
846 return srcu_read_lock(&tomoyo_ss); 645 return srcu_read_lock(&tomoyo_ss);
847} 646}
848 647
648/**
649 * tomoyo_read_unlock - Release lock for protecting policy.
650 *
651 * @idx: Index number returned by tomoyo_read_lock().
652 *
653 * Returns nothing.
654 */
849static inline void tomoyo_read_unlock(int idx) 655static inline void tomoyo_read_unlock(int idx)
850{ 656{
851 srcu_read_unlock(&tomoyo_ss, idx); 657 srcu_read_unlock(&tomoyo_ss, idx);
852} 658}
853 659
854/* strcmp() for "struct tomoyo_path_info" structure. */ 660/**
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 */
855static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, 668static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
856 const struct tomoyo_path_info *b) 669 const struct tomoyo_path_info *b)
857{ 670{
@@ -882,6 +695,13 @@ static inline bool tomoyo_invalid(const unsigned char c)
882 return c && (c <= ' ' || c >= 127); 695 return c && (c <= ' ' || c >= 127);
883} 696}
884 697
698/**
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 */
885static inline void tomoyo_put_name(const struct tomoyo_path_info *name) 705static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
886{ 706{
887 if (name) { 707 if (name) {
@@ -891,17 +711,36 @@ static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
891 } 711 }
892} 712}
893 713
714/**
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 */
894static inline void tomoyo_put_group(struct tomoyo_group *group) 721static inline void tomoyo_put_group(struct tomoyo_group *group)
895{ 722{
896 if (group) 723 if (group)
897 atomic_dec(&group->users); 724 atomic_dec(&group->users);
898} 725}
899 726
727/**
728 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
729 *
730 * Returns pointer to "struct tomoyo_domain_info" for current thread.
731 */
900static inline struct tomoyo_domain_info *tomoyo_domain(void) 732static inline struct tomoyo_domain_info *tomoyo_domain(void)
901{ 733{
902 return current_cred()->security; 734 return current_cred()->security;
903} 735}
904 736
737/**
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 */
905static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct 744static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
906 *task) 745 *task)
907{ 746{
@@ -909,24 +748,40 @@ static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
909} 748}
910 749
911static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info *p1, 750static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info *p1,
912 const struct tomoyo_acl_info *p2) 751 const struct tomoyo_acl_info *p2)
913{ 752{
914 return p1->type == p2->type; 753 return p1->type == p2->type;
915} 754}
916 755
756/**
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 */
917static inline bool tomoyo_same_name_union 764static inline bool tomoyo_same_name_union
918(const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2) 765(const struct tomoyo_name_union *a, const struct tomoyo_name_union *b)
919{ 766{
920 return p1->filename == p2->filename && p1->group == p2->group && 767 return a->filename == b->filename && a->group == b->group &&
921 p1->is_group == p2->is_group; 768 a->is_group == b->is_group;
922} 769}
923 770
771/**
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 */
924static inline bool tomoyo_same_number_union 779static inline bool tomoyo_same_number_union
925(const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2) 780(const struct tomoyo_number_union *a, const struct tomoyo_number_union *b)
926{ 781{
927 return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1] 782 return a->values[0] == b->values[0] && a->values[1] == b->values[1] &&
928 && p1->group == p2->group && p1->min_type == p2->min_type && 783 a->group == b->group && a->min_type == b->min_type &&
929 p1->max_type == p2->max_type && p1->is_group == p2->is_group; 784 a->max_type == b->max_type && a->is_group == b->is_group;
930} 785}
931 786
932/** 787/**
diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
index 41ed7de44ef1..332380288078 100644
--- a/security/tomoyo/file.c
+++ b/security/tomoyo/file.c
@@ -212,8 +212,7 @@ static int tomoyo_audit_mkdev_log(struct tomoyo_request_info *r)
212/** 212/**
213 * tomoyo_audit_path_number_log - Audit path/number request log. 213 * tomoyo_audit_path_number_log - Audit path/number request log.
214 * 214 *
215 * @r: Pointer to "struct tomoyo_request_info". 215 * @r: Pointer to "struct tomoyo_request_info".
216 * @error: Error code.
217 * 216 *
218 * Returns 0 on success, negative value otherwise. 217 * Returns 0 on success, negative value otherwise.
219 */ 218 */
diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
index f1d9e1a9eff4..5cfc72078742 100644
--- a/security/tomoyo/mount.c
+++ b/security/tomoyo/mount.c
@@ -7,22 +7,16 @@
7#include <linux/slab.h> 7#include <linux/slab.h>
8#include "common.h" 8#include "common.h"
9 9
10/* Keywords for mount restrictions. */ 10/* String table for special mount operations. */
11 11static const char * const tomoyo_mounts[TOMOYO_MAX_SPECIAL_MOUNT] = {
12/* Allow to call 'mount --bind /source_dir /dest_dir' */ 12 [TOMOYO_MOUNT_BIND] = "--bind",
13#define TOMOYO_MOUNT_BIND_KEYWORD "--bind" 13 [TOMOYO_MOUNT_MOVE] = "--move",
14/* Allow to call 'mount --move /old_dir /new_dir ' */ 14 [TOMOYO_MOUNT_REMOUNT] = "--remount",
15#define TOMOYO_MOUNT_MOVE_KEYWORD "--move" 15 [TOMOYO_MOUNT_MAKE_UNBINDABLE] = "--make-unbindable",
16/* Allow to call 'mount -o remount /dir ' */ 16 [TOMOYO_MOUNT_MAKE_PRIVATE] = "--make-private",
17#define TOMOYO_MOUNT_REMOUNT_KEYWORD "--remount" 17 [TOMOYO_MOUNT_MAKE_SLAVE] = "--make-slave",
18/* Allow to call 'mount --make-unbindable /dir' */ 18 [TOMOYO_MOUNT_MAKE_SHARED] = "--make-shared",
19#define TOMOYO_MOUNT_MAKE_UNBINDABLE_KEYWORD "--make-unbindable" 19};
20/* Allow to call 'mount --make-private /dir' */
21#define TOMOYO_MOUNT_MAKE_PRIVATE_KEYWORD "--make-private"
22/* Allow to call 'mount --make-slave /dir' */
23#define TOMOYO_MOUNT_MAKE_SLAVE_KEYWORD "--make-slave"
24/* Allow to call 'mount --make-shared /dir' */
25#define TOMOYO_MOUNT_MAKE_SHARED_KEYWORD "--make-shared"
26 20
27/** 21/**
28 * tomoyo_audit_mount_log - Audit mount log. 22 * tomoyo_audit_mount_log - Audit mount log.
@@ -39,22 +33,21 @@ static int tomoyo_audit_mount_log(struct tomoyo_request_info *r)
39 const unsigned long flags = r->param.mount.flags; 33 const unsigned long flags = r->param.mount.flags;
40 if (r->granted) 34 if (r->granted)
41 return 0; 35 return 0;
42 if (!strcmp(type, TOMOYO_MOUNT_REMOUNT_KEYWORD)) 36 if (type == tomoyo_mounts[TOMOYO_MOUNT_REMOUNT])
43 tomoyo_warn_log(r, "mount -o remount %s 0x%lX", dir, flags); 37 tomoyo_warn_log(r, "mount -o remount %s 0x%lX", dir, flags);
44 else if (!strcmp(type, TOMOYO_MOUNT_BIND_KEYWORD) 38 else if (type == tomoyo_mounts[TOMOYO_MOUNT_BIND]
45 || !strcmp(type, TOMOYO_MOUNT_MOVE_KEYWORD)) 39 || type == tomoyo_mounts[TOMOYO_MOUNT_MOVE])
46 tomoyo_warn_log(r, "mount %s %s %s 0x%lX", type, dev, dir, 40 tomoyo_warn_log(r, "mount %s %s %s 0x%lX", type, dev, dir,
47 flags); 41 flags);
48 else if (!strcmp(type, TOMOYO_MOUNT_MAKE_UNBINDABLE_KEYWORD) || 42 else if (type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_UNBINDABLE] ||
49 !strcmp(type, TOMOYO_MOUNT_MAKE_PRIVATE_KEYWORD) || 43 type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_PRIVATE] ||
50 !strcmp(type, TOMOYO_MOUNT_MAKE_SLAVE_KEYWORD) || 44 type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_SLAVE] ||
51 !strcmp(type, TOMOYO_MOUNT_MAKE_SHARED_KEYWORD)) 45 type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_SHARED])
52 tomoyo_warn_log(r, "mount %s %s 0x%lX", type, dir, flags); 46 tomoyo_warn_log(r, "mount %s %s 0x%lX", type, dir, flags);
53 else 47 else
54 tomoyo_warn_log(r, "mount -t %s %s %s 0x%lX", type, dev, dir, 48 tomoyo_warn_log(r, "mount -t %s %s %s 0x%lX", type, dev, dir,
55 flags); 49 flags);
56 return tomoyo_supervisor(r, 50 return tomoyo_supervisor(r, "allow_mount %s %s %s 0x%lX\n",
57 TOMOYO_KEYWORD_ALLOW_MOUNT "%s %s %s 0x%lX\n",
58 r->param.mount.dev->name, 51 r->param.mount.dev->name,
59 r->param.mount.dir->name, type, flags); 52 r->param.mount.dir->name, type, flags);
60} 53}
@@ -85,7 +78,8 @@ static bool tomoyo_check_mount_acl(struct tomoyo_request_info *r,
85 * Caller holds tomoyo_read_lock(). 78 * Caller holds tomoyo_read_lock().
86 */ 79 */
87static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name, 80static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name,
88 struct path *dir, char *type, unsigned long flags) 81 struct path *dir, const char *type,
82 unsigned long flags)
89{ 83{
90 struct path path; 84 struct path path;
91 struct file_system_type *fstype = NULL; 85 struct file_system_type *fstype = NULL;
@@ -115,15 +109,15 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name,
115 tomoyo_fill_path_info(&rdir); 109 tomoyo_fill_path_info(&rdir);
116 110
117 /* Compare fs name. */ 111 /* Compare fs name. */
118 if (!strcmp(type, TOMOYO_MOUNT_REMOUNT_KEYWORD)) { 112 if (type == tomoyo_mounts[TOMOYO_MOUNT_REMOUNT]) {
119 /* dev_name is ignored. */ 113 /* dev_name is ignored. */
120 } else if (!strcmp(type, TOMOYO_MOUNT_MAKE_UNBINDABLE_KEYWORD) || 114 } else if (type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_UNBINDABLE] ||
121 !strcmp(type, TOMOYO_MOUNT_MAKE_PRIVATE_KEYWORD) || 115 type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_PRIVATE] ||
122 !strcmp(type, TOMOYO_MOUNT_MAKE_SLAVE_KEYWORD) || 116 type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_SLAVE] ||
123 !strcmp(type, TOMOYO_MOUNT_MAKE_SHARED_KEYWORD)) { 117 type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_SHARED]) {
124 /* dev_name is ignored. */ 118 /* dev_name is ignored. */
125 } else if (!strcmp(type, TOMOYO_MOUNT_BIND_KEYWORD) || 119 } else if (type == tomoyo_mounts[TOMOYO_MOUNT_BIND] ||
126 !strcmp(type, TOMOYO_MOUNT_MOVE_KEYWORD)) { 120 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
127 need_dev = -1; /* dev_name is a directory */ 121 need_dev = -1; /* dev_name is a directory */
128 } else { 122 } else {
129 fstype = get_fs_type(type); 123 fstype = get_fs_type(type);
@@ -189,8 +183,9 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name,
189 * 183 *
190 * Returns 0 on success, negative value otherwise. 184 * Returns 0 on success, negative value otherwise.
191 */ 185 */
192int tomoyo_mount_permission(char *dev_name, struct path *path, char *type, 186int tomoyo_mount_permission(char *dev_name, struct path *path,
193 unsigned long flags, void *data_page) 187 const char *type, unsigned long flags,
188 void *data_page)
194{ 189{
195 struct tomoyo_request_info r; 190 struct tomoyo_request_info r;
196 int error; 191 int error;
@@ -202,31 +197,31 @@ int tomoyo_mount_permission(char *dev_name, struct path *path, char *type,
202 if ((flags & MS_MGC_MSK) == MS_MGC_VAL) 197 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
203 flags &= ~MS_MGC_MSK; 198 flags &= ~MS_MGC_MSK;
204 if (flags & MS_REMOUNT) { 199 if (flags & MS_REMOUNT) {
205 type = TOMOYO_MOUNT_REMOUNT_KEYWORD; 200 type = tomoyo_mounts[TOMOYO_MOUNT_REMOUNT];
206 flags &= ~MS_REMOUNT; 201 flags &= ~MS_REMOUNT;
207 } 202 }
208 if (flags & MS_MOVE) { 203 if (flags & MS_MOVE) {
209 type = TOMOYO_MOUNT_MOVE_KEYWORD; 204 type = tomoyo_mounts[TOMOYO_MOUNT_MOVE];
210 flags &= ~MS_MOVE; 205 flags &= ~MS_MOVE;
211 } 206 }
212 if (flags & MS_BIND) { 207 if (flags & MS_BIND) {
213 type = TOMOYO_MOUNT_BIND_KEYWORD; 208 type = tomoyo_mounts[TOMOYO_MOUNT_BIND];
214 flags &= ~MS_BIND; 209 flags &= ~MS_BIND;
215 } 210 }
216 if (flags & MS_UNBINDABLE) { 211 if (flags & MS_UNBINDABLE) {
217 type = TOMOYO_MOUNT_MAKE_UNBINDABLE_KEYWORD; 212 type = tomoyo_mounts[TOMOYO_MOUNT_MAKE_UNBINDABLE];
218 flags &= ~MS_UNBINDABLE; 213 flags &= ~MS_UNBINDABLE;
219 } 214 }
220 if (flags & MS_PRIVATE) { 215 if (flags & MS_PRIVATE) {
221 type = TOMOYO_MOUNT_MAKE_PRIVATE_KEYWORD; 216 type = tomoyo_mounts[TOMOYO_MOUNT_MAKE_PRIVATE];
222 flags &= ~MS_PRIVATE; 217 flags &= ~MS_PRIVATE;
223 } 218 }
224 if (flags & MS_SLAVE) { 219 if (flags & MS_SLAVE) {
225 type = TOMOYO_MOUNT_MAKE_SLAVE_KEYWORD; 220 type = tomoyo_mounts[TOMOYO_MOUNT_MAKE_SLAVE];
226 flags &= ~MS_SLAVE; 221 flags &= ~MS_SLAVE;
227 } 222 }
228 if (flags & MS_SHARED) { 223 if (flags & MS_SHARED) {
229 type = TOMOYO_MOUNT_MAKE_SHARED_KEYWORD; 224 type = tomoyo_mounts[TOMOYO_MOUNT_MAKE_SHARED];
230 flags &= ~MS_SHARED; 225 flags &= ~MS_SHARED;
231 } 226 }
232 if (!type) 227 if (!type)
diff --git a/security/tomoyo/securityfs_if.c b/security/tomoyo/securityfs_if.c
index e43d5554b506..a5bd76d7f6be 100644
--- a/security/tomoyo/securityfs_if.c
+++ b/security/tomoyo/securityfs_if.c
@@ -38,7 +38,7 @@ static int tomoyo_release(struct inode *inode, struct file *file)
38} 38}
39 39
40/** 40/**
41 * tomoyo_poll - poll() for /proc/ccs/ interface. 41 * tomoyo_poll - poll() for /sys/kernel/security/tomoyo/ interface.
42 * 42 *
43 * @file: Pointer to "struct file". 43 * @file: Pointer to "struct file".
44 * @wait: Pointer to "poll_table". 44 * @wait: Pointer to "poll_table".