aboutsummaryrefslogtreecommitdiffstats
path: root/security/tomoyo/common.h
diff options
context:
space:
mode:
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>2010-05-16 21:09:15 -0400
committerJames Morris <jmorris@namei.org>2010-08-02 01:33:37 -0400
commita1f9bb6a375a8dbf7797ffbd6739c46b338a77f7 (patch)
tree44df8f05e6ad6bd7cf9ce398c99efbd7cff24c20 /security/tomoyo/common.h
parentcb0abe6a5b58499bd4bc1403f4987af9ead0642c (diff)
TOMOYO: Split file access control functions by type of parameters.
Check numeric parameters for operations that deal them (e.g. chmod/chown/ioctl). Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security/tomoyo/common.h')
-rw-r--r--security/tomoyo/common.h126
1 files changed, 105 insertions, 21 deletions
diff --git a/security/tomoyo/common.h b/security/tomoyo/common.h
index 91e2bcfd56e3..565a1c11da53 100644
--- a/security/tomoyo/common.h
+++ b/security/tomoyo/common.h
@@ -88,17 +88,21 @@ enum tomoyo_mac_index {
88enum tomoyo_acl_entry_type_index { 88enum tomoyo_acl_entry_type_index {
89 TOMOYO_TYPE_PATH_ACL, 89 TOMOYO_TYPE_PATH_ACL,
90 TOMOYO_TYPE_PATH2_ACL, 90 TOMOYO_TYPE_PATH2_ACL,
91 TOMOYO_TYPE_PATH_NUMBER_ACL,
92 TOMOYO_TYPE_PATH_NUMBER3_ACL,
91}; 93};
92 94
93/* Index numbers for File Controls. */ 95/* Index numbers for File Controls. */
94 96
95/* 97/*
96 * TYPE_READ_WRITE_ACL is special. TYPE_READ_WRITE_ACL is automatically set 98 * TOMOYO_TYPE_READ_WRITE is special. TOMOYO_TYPE_READ_WRITE is automatically
97 * if both TYPE_READ_ACL and TYPE_WRITE_ACL are set. Both TYPE_READ_ACL and 99 * set if both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are set.
98 * TYPE_WRITE_ACL are automatically set if TYPE_READ_WRITE_ACL is set. 100 * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically set if
99 * TYPE_READ_WRITE_ACL is automatically cleared if either TYPE_READ_ACL or 101 * TOMOYO_TYPE_READ_WRITE is set.
100 * TYPE_WRITE_ACL is cleared. Both TYPE_READ_ACL and TYPE_WRITE_ACL are 102 * TOMOYO_TYPE_READ_WRITE is automatically cleared if either TOMOYO_TYPE_READ
101 * automatically cleared if TYPE_READ_WRITE_ACL is cleared. 103 * or TOMOYO_TYPE_WRITE is cleared.
104 * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically cleared if
105 * TOMOYO_TYPE_READ_WRITE is cleared.
102 */ 106 */
103 107
104enum tomoyo_path_acl_index { 108enum tomoyo_path_acl_index {
@@ -106,27 +110,23 @@ enum tomoyo_path_acl_index {
106 TOMOYO_TYPE_EXECUTE, 110 TOMOYO_TYPE_EXECUTE,
107 TOMOYO_TYPE_READ, 111 TOMOYO_TYPE_READ,
108 TOMOYO_TYPE_WRITE, 112 TOMOYO_TYPE_WRITE,
109 TOMOYO_TYPE_CREATE,
110 TOMOYO_TYPE_UNLINK, 113 TOMOYO_TYPE_UNLINK,
111 TOMOYO_TYPE_MKDIR,
112 TOMOYO_TYPE_RMDIR, 114 TOMOYO_TYPE_RMDIR,
113 TOMOYO_TYPE_MKFIFO,
114 TOMOYO_TYPE_MKSOCK,
115 TOMOYO_TYPE_MKBLOCK,
116 TOMOYO_TYPE_MKCHAR,
117 TOMOYO_TYPE_TRUNCATE, 115 TOMOYO_TYPE_TRUNCATE,
118 TOMOYO_TYPE_SYMLINK, 116 TOMOYO_TYPE_SYMLINK,
119 TOMOYO_TYPE_REWRITE, 117 TOMOYO_TYPE_REWRITE,
120 TOMOYO_TYPE_IOCTL,
121 TOMOYO_TYPE_CHMOD,
122 TOMOYO_TYPE_CHOWN,
123 TOMOYO_TYPE_CHGRP,
124 TOMOYO_TYPE_CHROOT, 118 TOMOYO_TYPE_CHROOT,
125 TOMOYO_TYPE_MOUNT, 119 TOMOYO_TYPE_MOUNT,
126 TOMOYO_TYPE_UMOUNT, 120 TOMOYO_TYPE_UMOUNT,
127 TOMOYO_MAX_PATH_OPERATION 121 TOMOYO_MAX_PATH_OPERATION
128}; 122};
129 123
124enum tomoyo_path_number3_acl_index {
125 TOMOYO_TYPE_MKBLOCK,
126 TOMOYO_TYPE_MKCHAR,
127 TOMOYO_MAX_PATH_NUMBER3_OPERATION
128};
129
130enum tomoyo_path2_acl_index { 130enum tomoyo_path2_acl_index {
131 TOMOYO_TYPE_LINK, 131 TOMOYO_TYPE_LINK,
132 TOMOYO_TYPE_RENAME, 132 TOMOYO_TYPE_RENAME,
@@ -134,6 +134,18 @@ enum tomoyo_path2_acl_index {
134 TOMOYO_MAX_PATH2_OPERATION 134 TOMOYO_MAX_PATH2_OPERATION
135}; 135};
136 136
137enum tomoyo_path_number_acl_index {
138 TOMOYO_TYPE_CREATE,
139 TOMOYO_TYPE_MKDIR,
140 TOMOYO_TYPE_MKFIFO,
141 TOMOYO_TYPE_MKSOCK,
142 TOMOYO_TYPE_IOCTL,
143 TOMOYO_TYPE_CHMOD,
144 TOMOYO_TYPE_CHOWN,
145 TOMOYO_TYPE_CHGRP,
146 TOMOYO_MAX_PATH_NUMBER_OPERATION
147};
148
137enum tomoyo_securityfs_interface_index { 149enum tomoyo_securityfs_interface_index {
138 TOMOYO_DOMAINPOLICY, 150 TOMOYO_DOMAINPOLICY,
139 TOMOYO_EXCEPTIONPOLICY, 151 TOMOYO_EXCEPTIONPOLICY,
@@ -347,20 +359,62 @@ struct tomoyo_domain_info {
347 * (3) "name" is the pathname. 359 * (3) "name" is the pathname.
348 * 360 *
349 * Directives held by this structure are "allow_read/write", "allow_execute", 361 * Directives held by this structure are "allow_read/write", "allow_execute",
350 * "allow_read", "allow_write", "allow_create", "allow_unlink", "allow_mkdir", 362 * "allow_read", "allow_write", "allow_unlink", "allow_rmdir",
351 * "allow_rmdir", "allow_mkfifo", "allow_mksock", "allow_mkblock", 363 * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot",
352 * "allow_mkchar", "allow_truncate", "allow_symlink", "allow_rewrite",
353 * "allow_ioctl", "allow_chmod", "allow_chown", "allow_chgrp", "allow_chroot",
354 * "allow_mount" and "allow_unmount". 364 * "allow_mount" and "allow_unmount".
355 */ 365 */
356struct tomoyo_path_acl { 366struct tomoyo_path_acl {
357 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ 367 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
358 u8 perm_high;
359 u16 perm; 368 u16 perm;
360 struct tomoyo_name_union name; 369 struct tomoyo_name_union name;
361}; 370};
362 371
363/* 372/*
373 * tomoyo_path_number_acl is a structure which is used for holding an
374 * entry with one pathname and one number operation.
375 * It has following fields.
376 *
377 * (1) "head" which is a "struct tomoyo_acl_info".
378 * (2) "perm" which is a bitmask of permitted operations.
379 * (3) "name" is the pathname.
380 * (4) "number" is the numeric value.
381 *
382 * Directives held by this structure are "allow_create", "allow_mkdir",
383 * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown"
384 * and "allow_chgrp".
385 *
386 */
387struct tomoyo_path_number_acl {
388 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
389 u8 perm;
390 struct tomoyo_name_union name;
391 struct tomoyo_number_union number;
392};
393
394/*
395 * tomoyo_path_number3_acl is a structure which is used for holding an
396 * entry with one pathname and three numbers operation.
397 * It has following fields.
398 *
399 * (1) "head" which is a "struct tomoyo_acl_info".
400 * (2) "perm" which is a bitmask of permitted operations.
401 * (3) "mode" is the create mode.
402 * (4) "major" is the major number of device node.
403 * (5) "minor" is the minor number of device node.
404 *
405 * Directives held by this structure are "allow_mkchar", "allow_mkblock".
406 *
407 */
408struct tomoyo_path_number3_acl {
409 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER3_ACL */
410 u8 perm;
411 struct tomoyo_name_union name;
412 struct tomoyo_number_union mode;
413 struct tomoyo_number_union major;
414 struct tomoyo_number_union minor;
415};
416
417/*
364 * tomoyo_path2_acl is a structure which is used for holding an 418 * tomoyo_path2_acl is a structure which is used for holding an
365 * entry with two pathnames operation (i.e. link(), rename() and pivot_root()). 419 * entry with two pathnames operation (i.e. link(), rename() and pivot_root()).
366 * It has following fields. 420 * It has following fields.
@@ -639,6 +693,8 @@ bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
639bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); 693bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
640/* Convert double path operation to operation name. */ 694/* Convert double path operation to operation name. */
641const char *tomoyo_path22keyword(const u8 operation); 695const char *tomoyo_path22keyword(const u8 operation);
696const char *tomoyo_path_number2keyword(const u8 operation);
697const char *tomoyo_path_number32keyword(const u8 operation);
642/* Get the last component of the given domainname. */ 698/* Get the last component of the given domainname. */
643const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain); 699const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain);
644/* Convert single path operation to operation name. */ 700/* Convert single path operation to operation name. */
@@ -736,11 +792,18 @@ int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain,
736 const struct tomoyo_path_info *filename); 792 const struct tomoyo_path_info *filename);
737int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, 793int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
738 struct path *path, const int flag); 794 struct path *path, const int flag);
795int tomoyo_path_number_perm(const u8 operation, struct path *path,
796 unsigned long number);
797int tomoyo_path_number3_perm(const u8 operation, struct path *path,
798 const unsigned int mode, unsigned int dev);
739int tomoyo_path_perm(const u8 operation, struct path *path); 799int tomoyo_path_perm(const u8 operation, struct path *path);
740int tomoyo_path2_perm(const u8 operation, struct path *path1, 800int tomoyo_path2_perm(const u8 operation, struct path *path1,
741 struct path *path2); 801 struct path *path2);
742int tomoyo_find_next_domain(struct linux_binprm *bprm); 802int tomoyo_find_next_domain(struct linux_binprm *bprm);
743 803
804void tomoyo_print_ulong(char *buffer, const int buffer_len,
805 const unsigned long value, const u8 type);
806
744/* Drop refcount on tomoyo_name_union. */ 807/* Drop refcount on tomoyo_name_union. */
745void tomoyo_put_name_union(struct tomoyo_name_union *ptr); 808void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
746 809
@@ -880,6 +943,18 @@ static inline bool tomoyo_is_same_path_acl(const struct tomoyo_path_acl *p1,
880 tomoyo_is_same_name_union(&p1->name, &p2->name); 943 tomoyo_is_same_name_union(&p1->name, &p2->name);
881} 944}
882 945
946static inline bool tomoyo_is_same_path_number3_acl
947(const struct tomoyo_path_number3_acl *p1,
948 const struct tomoyo_path_number3_acl *p2)
949{
950 return tomoyo_is_same_acl_head(&p1->head, &p2->head)
951 && tomoyo_is_same_name_union(&p1->name, &p2->name)
952 && tomoyo_is_same_number_union(&p1->mode, &p2->mode)
953 && tomoyo_is_same_number_union(&p1->major, &p2->major)
954 && tomoyo_is_same_number_union(&p1->minor, &p2->minor);
955}
956
957
883static inline bool tomoyo_is_same_path2_acl(const struct tomoyo_path2_acl *p1, 958static inline bool tomoyo_is_same_path2_acl(const struct tomoyo_path2_acl *p1,
884 const struct tomoyo_path2_acl *p2) 959 const struct tomoyo_path2_acl *p2)
885{ 960{
@@ -888,6 +963,15 @@ static inline bool tomoyo_is_same_path2_acl(const struct tomoyo_path2_acl *p1,
888 tomoyo_is_same_name_union(&p1->name2, &p2->name2); 963 tomoyo_is_same_name_union(&p1->name2, &p2->name2);
889} 964}
890 965
966static inline bool tomoyo_is_same_path_number_acl
967(const struct tomoyo_path_number_acl *p1,
968 const struct tomoyo_path_number_acl *p2)
969{
970 return tomoyo_is_same_acl_head(&p1->head, &p2->head)
971 && tomoyo_is_same_name_union(&p1->name, &p2->name)
972 && tomoyo_is_same_number_union(&p1->number, &p2->number);
973}
974
891static inline bool tomoyo_is_same_domain_initializer_entry 975static inline bool tomoyo_is_same_domain_initializer_entry
892(const struct tomoyo_domain_initializer_entry *p1, 976(const struct tomoyo_domain_initializer_entry *p1,
893 const struct tomoyo_domain_initializer_entry *p2) 977 const struct tomoyo_domain_initializer_entry *p2)