2 * security/tomoyo/condition.c
4 * Copyright (C) 2005-2011 NTT DATA CORPORATION
8 #include <linux/slab.h>
10 /* List of "struct tomoyo_condition". */
11 LIST_HEAD(tomoyo_condition_list
);
14 * tomoyo_argv - Check argv[] in "struct linux_binbrm".
16 * @index: Index number of @arg_ptr.
17 * @arg_ptr: Contents of argv[@index].
18 * @argc: Length of @argv.
19 * @argv: Pointer to "struct tomoyo_argv".
20 * @checked: Set to true if @argv[@index] was found.
22 * Returns true on success, false otherwise.
24 static bool tomoyo_argv(const unsigned int index
, const char *arg_ptr
,
25 const int argc
, const struct tomoyo_argv
*argv
,
29 struct tomoyo_path_info arg
;
31 for (i
= 0; i
< argc
; argv
++, checked
++, i
++) {
33 if (index
!= argv
->index
)
36 tomoyo_fill_path_info(&arg
);
37 result
= tomoyo_path_matches_pattern(&arg
, argv
->value
);
47 * tomoyo_envp - Check envp[] in "struct linux_binbrm".
49 * @env_name: The name of environment variable.
50 * @env_value: The value of environment variable.
51 * @envc: Length of @envp.
52 * @envp: Pointer to "struct tomoyo_envp".
53 * @checked: Set to true if @envp[@env_name] was found.
55 * Returns true on success, false otherwise.
57 static bool tomoyo_envp(const char *env_name
, const char *env_value
,
58 const int envc
, const struct tomoyo_envp
*envp
,
62 struct tomoyo_path_info name
;
63 struct tomoyo_path_info value
;
65 tomoyo_fill_path_info(&name
);
66 value
.name
= env_value
;
67 tomoyo_fill_path_info(&value
);
68 for (i
= 0; i
< envc
; envp
++, checked
++, i
++) {
70 if (!tomoyo_path_matches_pattern(&name
, envp
->name
))
74 result
= tomoyo_path_matches_pattern(&value
,
90 * tomoyo_scan_bprm - Scan "struct linux_binprm".
92 * @ee: Pointer to "struct tomoyo_execve".
93 * @argc: Length of @argc.
94 * @argv: Pointer to "struct tomoyo_argv".
95 * @envc: Length of @envp.
96 * @envp: Poiner to "struct tomoyo_envp".
98 * Returns true on success, false otherwise.
100 static bool tomoyo_scan_bprm(struct tomoyo_execve
*ee
,
101 const u16 argc
, const struct tomoyo_argv
*argv
,
102 const u16 envc
, const struct tomoyo_envp
*envp
)
104 struct linux_binprm
*bprm
= ee
->bprm
;
105 struct tomoyo_page_dump
*dump
= &ee
->dump
;
106 char *arg_ptr
= ee
->tmp
;
108 unsigned long pos
= bprm
->p
;
109 int offset
= pos
% PAGE_SIZE
;
110 int argv_count
= bprm
->argc
;
111 int envp_count
= bprm
->envc
;
113 u8 local_checked
[32];
115 if (argc
+ envc
<= sizeof(local_checked
)) {
116 checked
= local_checked
;
117 memset(local_checked
, 0, sizeof(local_checked
));
119 checked
= kzalloc(argc
+ envc
, GFP_NOFS
);
123 while (argv_count
|| envp_count
) {
124 if (!tomoyo_dump_page(bprm
, pos
, dump
)) {
128 pos
+= PAGE_SIZE
- offset
;
129 while (offset
< PAGE_SIZE
) {
131 const char *kaddr
= dump
->data
;
132 const unsigned char c
= kaddr
[offset
++];
133 if (c
&& arg_len
< TOMOYO_EXEC_TMPSIZE
- 10) {
135 arg_ptr
[arg_len
++] = '\\';
136 arg_ptr
[arg_len
++] = '\\';
137 } else if (c
> ' ' && c
< 127) {
138 arg_ptr
[arg_len
++] = c
;
140 arg_ptr
[arg_len
++] = '\\';
141 arg_ptr
[arg_len
++] = (c
>> 6) + '0';
143 ((c
>> 3) & 7) + '0';
144 arg_ptr
[arg_len
++] = (c
& 7) + '0';
147 arg_ptr
[arg_len
] = '\0';
153 if (!tomoyo_argv(bprm
->argc
- argv_count
,
160 } else if (envp_count
) {
161 char *cp
= strchr(arg_ptr
, '=');
164 if (!tomoyo_envp(arg_ptr
, cp
+ 1,
184 /* Check not-yet-checked entries. */
185 for (i
= 0; i
< argc
; i
++) {
189 * Return true only if all unchecked indexes in
190 * bprm->argv[] are not matched.
197 for (i
= 0; i
< envc
; envp
++, i
++) {
198 if (checked
[argc
+ i
])
201 * Return true only if all unchecked environ variables
202 * in bprm->envp[] are either undefined or not matched.
204 if ((!envp
->value
&& !envp
->is_not
) ||
205 (envp
->value
&& envp
->is_not
))
211 if (checked
!= local_checked
)
217 * tomoyo_scan_exec_realpath - Check "exec.realpath" parameter of "struct tomoyo_condition".
219 * @file: Pointer to "struct file".
220 * @ptr: Pointer to "struct tomoyo_name_union".
221 * @match: True if "exec.realpath=", false if "exec.realpath!=".
223 * Returns true on success, false otherwise.
225 static bool tomoyo_scan_exec_realpath(struct file
*file
,
226 const struct tomoyo_name_union
*ptr
,
230 struct tomoyo_path_info exe
;
233 exe
.name
= tomoyo_realpath_from_path(&file
->f_path
);
236 tomoyo_fill_path_info(&exe
);
237 result
= tomoyo_compare_name_union(&exe
, ptr
);
239 return result
== match
;
243 * tomoyo_get_dqword - tomoyo_get_name() for a quoted string.
245 * @start: String to save.
247 * Returns pointer to "struct tomoyo_path_info" on success, NULL otherwise.
249 static const struct tomoyo_path_info
*tomoyo_get_dqword(char *start
)
251 char *cp
= start
+ strlen(start
) - 1;
252 if (cp
== start
|| *start
++ != '"' || *cp
!= '"')
255 if (*start
&& !tomoyo_correct_word(start
))
257 return tomoyo_get_name(start
);
261 * tomoyo_parse_name_union_quoted - Parse a quoted word.
263 * @param: Pointer to "struct tomoyo_acl_param".
264 * @ptr: Pointer to "struct tomoyo_name_union".
266 * Returns true on success, false otherwise.
268 static bool tomoyo_parse_name_union_quoted(struct tomoyo_acl_param
*param
,
269 struct tomoyo_name_union
*ptr
)
271 char *filename
= param
->data
;
272 if (*filename
== '@')
273 return tomoyo_parse_name_union(param
, ptr
);
274 ptr
->filename
= tomoyo_get_dqword(filename
);
275 return ptr
->filename
!= NULL
;
279 * tomoyo_parse_argv - Parse an argv[] condition part.
281 * @left: Lefthand value.
282 * @right: Righthand value.
283 * @argv: Pointer to "struct tomoyo_argv".
285 * Returns true on success, false otherwise.
287 static bool tomoyo_parse_argv(char *left
, char *right
,
288 struct tomoyo_argv
*argv
)
290 if (tomoyo_parse_ulong(&argv
->index
, &left
) !=
291 TOMOYO_VALUE_TYPE_DECIMAL
|| *left
++ != ']' || *left
)
293 argv
->value
= tomoyo_get_dqword(right
);
294 return argv
->value
!= NULL
;
298 * tomoyo_parse_envp - Parse an envp[] condition part.
300 * @left: Lefthand value.
301 * @right: Righthand value.
302 * @envp: Pointer to "struct tomoyo_envp".
304 * Returns true on success, false otherwise.
306 static bool tomoyo_parse_envp(char *left
, char *right
,
307 struct tomoyo_envp
*envp
)
309 const struct tomoyo_path_info
*name
;
310 const struct tomoyo_path_info
*value
;
311 char *cp
= left
+ strlen(left
) - 1;
312 if (*cp
-- != ']' || *cp
!= '"')
315 if (!tomoyo_correct_word(left
))
317 name
= tomoyo_get_name(left
);
320 if (!strcmp(right
, "NULL")) {
323 value
= tomoyo_get_dqword(right
);
325 tomoyo_put_name(name
);
337 * tomoyo_same_condition - Check for duplicated "struct tomoyo_condition" entry.
339 * @a: Pointer to "struct tomoyo_condition".
340 * @b: Pointer to "struct tomoyo_condition".
342 * Returns true if @a == @b, false otherwise.
344 static inline bool tomoyo_same_condition(const struct tomoyo_condition
*a
,
345 const struct tomoyo_condition
*b
)
347 return a
->size
== b
->size
&& a
->condc
== b
->condc
&&
348 a
->numbers_count
== b
->numbers_count
&&
349 a
->names_count
== b
->names_count
&&
350 a
->argc
== b
->argc
&& a
->envc
== b
->envc
&&
351 a
->grant_log
== b
->grant_log
&& a
->transit
== b
->transit
&&
352 !memcmp(a
+ 1, b
+ 1, a
->size
- sizeof(*a
));
356 * tomoyo_condition_type - Get condition type.
358 * @word: Keyword string.
360 * Returns one of values in "enum tomoyo_conditions_index" on success,
361 * TOMOYO_MAX_CONDITION_KEYWORD otherwise.
363 static u8
tomoyo_condition_type(const char *word
)
366 for (i
= 0; i
< TOMOYO_MAX_CONDITION_KEYWORD
; i
++) {
367 if (!strcmp(word
, tomoyo_condition_keyword
[i
]))
373 /* Define this to enable debug mode. */
374 /* #define DEBUG_CONDITION */
376 #ifdef DEBUG_CONDITION
377 #define dprintk printk
379 #define dprintk(...) do { } while (0)
383 * tomoyo_commit_condition - Commit "struct tomoyo_condition".
385 * @entry: Pointer to "struct tomoyo_condition".
387 * Returns pointer to "struct tomoyo_condition" on success, NULL otherwise.
389 * This function merges duplicated entries. This function returns NULL if
390 * @entry is not duplicated but memory quota for policy has exceeded.
392 static struct tomoyo_condition
*tomoyo_commit_condition
393 (struct tomoyo_condition
*entry
)
395 struct tomoyo_condition
*ptr
;
397 if (mutex_lock_interruptible(&tomoyo_policy_lock
)) {
398 dprintk(KERN_WARNING
"%u: %s failed\n", __LINE__
, __func__
);
403 list_for_each_entry(ptr
, &tomoyo_condition_list
, head
.list
) {
404 if (!tomoyo_same_condition(ptr
, entry
) ||
405 atomic_read(&ptr
->head
.users
) == TOMOYO_GC_IN_PROGRESS
)
407 /* Same entry found. Share this entry. */
408 atomic_inc(&ptr
->head
.users
);
413 if (tomoyo_memory_ok(entry
)) {
414 atomic_set(&entry
->head
.users
, 1);
415 list_add(&entry
->head
.list
, &tomoyo_condition_list
);
421 mutex_unlock(&tomoyo_policy_lock
);
424 tomoyo_del_condition(&entry
->head
.list
);
432 * tomoyo_get_transit_preference - Parse domain transition preference for execve().
434 * @param: Pointer to "struct tomoyo_acl_param".
435 * @e: Pointer to "struct tomoyo_condition".
437 * Returns the condition string part.
439 static char *tomoyo_get_transit_preference(struct tomoyo_acl_param
*param
,
440 struct tomoyo_condition
*e
)
442 char * const pos
= param
->data
;
445 e
->transit
= tomoyo_get_domainname(param
);
449 char *cp
= strchr(pos
, ' ');
452 flag
= tomoyo_correct_path(pos
) || !strcmp(pos
, "keep") ||
453 !strcmp(pos
, "initialize") || !strcmp(pos
, "reset") ||
454 !strcmp(pos
, "child") || !strcmp(pos
, "parent");
460 e
->transit
= tomoyo_get_name(tomoyo_read_token(param
));
465 * Return a bad read-only condition string that will let
466 * tomoyo_get_condition() return NULL.
472 * tomoyo_get_condition - Parse condition part.
474 * @param: Pointer to "struct tomoyo_acl_param".
476 * Returns pointer to "struct tomoyo_condition" on success, NULL otherwise.
478 struct tomoyo_condition
*tomoyo_get_condition(struct tomoyo_acl_param
*param
)
480 struct tomoyo_condition
*entry
= NULL
;
481 struct tomoyo_condition_element
*condp
= NULL
;
482 struct tomoyo_number_union
*numbers_p
= NULL
;
483 struct tomoyo_name_union
*names_p
= NULL
;
484 struct tomoyo_argv
*argv
= NULL
;
485 struct tomoyo_envp
*envp
= NULL
;
486 struct tomoyo_condition e
= { };
487 char * const start_of_string
=
488 tomoyo_get_transit_preference(param
, &e
);
489 char * const end_of_string
= start_of_string
+ strlen(start_of_string
);
492 pos
= start_of_string
;
496 char *left_word
= pos
;
503 * Since left-hand condition does not allow use of "path_group"
504 * or "number_group" and environment variable's names do not
505 * accept '=', it is guaranteed that the original line consists
506 * of one or more repetition of $left$operator$right blocks
507 * where "$left is free from '=' and ' '" and "$operator is
508 * either '=' or '!='" and "$right is free from ' '".
509 * Therefore, we can reconstruct the original line at the end
510 * of dry run even if we overwrite $operator with '\0'.
512 cp
= strchr(pos
, ' ');
514 *cp
= '\0'; /* Will restore later. */
519 right_word
= strchr(left_word
, '=');
520 if (!right_word
|| right_word
== left_word
)
522 is_not
= *(right_word
- 1) == '!';
524 *(right_word
++ - 1) = '\0'; /* Will restore later. */
525 else if (*(right_word
+ 1) != '=')
526 *right_word
++ = '\0'; /* Will restore later. */
529 dprintk(KERN_WARNING
"%u: <%s>%s=<%s>\n", __LINE__
, left_word
,
530 is_not
? "!" : "", right_word
);
531 if (!strcmp(left_word
, "grant_log")) {
534 entry
->grant_log
!= TOMOYO_GRANTLOG_AUTO
)
536 else if (!strcmp(right_word
, "yes"))
537 entry
->grant_log
= TOMOYO_GRANTLOG_YES
;
538 else if (!strcmp(right_word
, "no"))
539 entry
->grant_log
= TOMOYO_GRANTLOG_NO
;
545 if (!strncmp(left_word
, "exec.argv[", 10)) {
552 left
= TOMOYO_ARGV_ENTRY
;
553 argv
->is_not
= is_not
;
554 if (!tomoyo_parse_argv(left_word
+ 10,
560 if (!strncmp(left_word
, "exec.envp[\"", 11)) {
567 left
= TOMOYO_ENVP_ENTRY
;
568 envp
->is_not
= is_not
;
569 if (!tomoyo_parse_envp(left_word
+ 11,
575 left
= tomoyo_condition_type(left_word
);
576 dprintk(KERN_WARNING
"%u: <%s> left=%u\n", __LINE__
, left_word
,
578 if (left
== TOMOYO_MAX_CONDITION_KEYWORD
) {
583 left
= TOMOYO_NUMBER_UNION
;
584 param
->data
= left_word
;
585 if (*left_word
== '@' ||
586 !tomoyo_parse_number_union(param
,
595 if (left
== TOMOYO_EXEC_REALPATH
||
596 left
== TOMOYO_SYMLINK_TARGET
) {
601 right
= TOMOYO_NAME_UNION
;
602 param
->data
= right_word
;
603 if (!tomoyo_parse_name_union_quoted(param
,
609 right
= tomoyo_condition_type(right_word
);
610 if (right
== TOMOYO_MAX_CONDITION_KEYWORD
) {
615 right
= TOMOYO_NUMBER_UNION
;
616 param
->data
= right_word
;
617 if (!tomoyo_parse_number_union(param
,
624 dprintk(KERN_WARNING
"%u: dry_run left=%u right=%u "
625 "match=%u\n", __LINE__
, left
, right
, !is_not
);
629 condp
->right
= right
;
630 condp
->equals
= !is_not
;
631 dprintk(KERN_WARNING
"%u: left=%u right=%u match=%u\n",
632 __LINE__
, condp
->left
, condp
->right
,
636 dprintk(KERN_INFO
"%u: cond=%u numbers=%u names=%u ac=%u ec=%u\n",
637 __LINE__
, e
.condc
, e
.numbers_count
, e
.names_count
, e
.argc
,
640 BUG_ON(e
.names_count
| e
.numbers_count
| e
.argc
| e
.envc
|
642 return tomoyo_commit_condition(entry
);
644 e
.size
= sizeof(*entry
)
645 + e
.condc
* sizeof(struct tomoyo_condition_element
)
646 + e
.numbers_count
* sizeof(struct tomoyo_number_union
)
647 + e
.names_count
* sizeof(struct tomoyo_name_union
)
648 + e
.argc
* sizeof(struct tomoyo_argv
)
649 + e
.envc
* sizeof(struct tomoyo_envp
);
650 entry
= kzalloc(e
.size
, GFP_NOFS
);
655 condp
= (struct tomoyo_condition_element
*) (entry
+ 1);
656 numbers_p
= (struct tomoyo_number_union
*) (condp
+ e
.condc
);
657 names_p
= (struct tomoyo_name_union
*) (numbers_p
+ e
.numbers_count
);
658 argv
= (struct tomoyo_argv
*) (names_p
+ e
.names_count
);
659 envp
= (struct tomoyo_envp
*) (argv
+ e
.argc
);
662 for (pos
= start_of_string
; pos
< end_of_string
; pos
++) {
665 if (flag
) /* Restore " ". */
667 else if (*(pos
+ 1) == '=') /* Restore "!=". */
669 else /* Restore "=". */
676 dprintk(KERN_WARNING
"%u: %s failed\n", __LINE__
, __func__
);
678 tomoyo_del_condition(&entry
->head
.list
);
682 tomoyo_put_name(e
.transit
);
687 * tomoyo_get_attributes - Revalidate "struct inode".
689 * @obj: Pointer to "struct tomoyo_obj_info".
693 void tomoyo_get_attributes(struct tomoyo_obj_info
*obj
)
696 struct dentry
*dentry
= NULL
;
698 for (i
= 0; i
< TOMOYO_MAX_PATH_STAT
; i
++) {
702 dentry
= obj
->path1
.dentry
;
707 dentry
= obj
->path2
.dentry
;
714 dentry
= dget_parent(dentry
);
717 inode
= dentry
->d_inode
;
719 struct tomoyo_mini_stat
*stat
= &obj
->stat
[i
];
720 stat
->uid
= inode
->i_uid
;
721 stat
->gid
= inode
->i_gid
;
722 stat
->ino
= inode
->i_ino
;
723 stat
->mode
= inode
->i_mode
;
724 stat
->dev
= inode
->i_sb
->s_dev
;
725 stat
->rdev
= inode
->i_rdev
;
726 obj
->stat_valid
[i
] = true;
728 if (i
& 1) /* i == TOMOYO_PATH1_PARENT ||
729 i == TOMOYO_PATH2_PARENT */
735 * tomoyo_condition - Check condition part.
737 * @r: Pointer to "struct tomoyo_request_info".
738 * @cond: Pointer to "struct tomoyo_condition". Maybe NULL.
740 * Returns true on success, false otherwise.
742 * Caller holds tomoyo_read_lock().
744 bool tomoyo_condition(struct tomoyo_request_info
*r
,
745 const struct tomoyo_condition
*cond
)
748 unsigned long min_v
[2] = { 0, 0 };
749 unsigned long max_v
[2] = { 0, 0 };
750 const struct tomoyo_condition_element
*condp
;
751 const struct tomoyo_number_union
*numbers_p
;
752 const struct tomoyo_name_union
*names_p
;
753 const struct tomoyo_argv
*argv
;
754 const struct tomoyo_envp
*envp
;
755 struct tomoyo_obj_info
*obj
;
759 struct linux_binprm
*bprm
= NULL
;
768 if (!bprm
&& (argc
|| envc
))
770 condp
= (struct tomoyo_condition_element
*) (cond
+ 1);
771 numbers_p
= (const struct tomoyo_number_union
*) (condp
+ condc
);
772 names_p
= (const struct tomoyo_name_union
*)
773 (numbers_p
+ cond
->numbers_count
);
774 argv
= (const struct tomoyo_argv
*) (names_p
+ cond
->names_count
);
775 envp
= (const struct tomoyo_envp
*) (argv
+ argc
);
776 for (i
= 0; i
< condc
; i
++) {
777 const bool match
= condp
->equals
;
778 const u8 left
= condp
->left
;
779 const u8 right
= condp
->right
;
780 bool is_bitop
[2] = { false, false };
783 /* Check argv[] and envp[] later. */
784 if (left
== TOMOYO_ARGV_ENTRY
|| left
== TOMOYO_ENVP_ENTRY
)
786 /* Check string expressions. */
787 if (right
== TOMOYO_NAME_UNION
) {
788 const struct tomoyo_name_union
*ptr
= names_p
++;
790 struct tomoyo_path_info
*symlink
;
791 struct tomoyo_execve
*ee
;
793 case TOMOYO_SYMLINK_TARGET
:
794 symlink
= obj
? obj
->symlink_target
: NULL
;
796 !tomoyo_compare_name_union(symlink
, ptr
)
800 case TOMOYO_EXEC_REALPATH
:
802 file
= ee
? ee
->bprm
->file
: NULL
;
803 if (!tomoyo_scan_exec_realpath(file
, ptr
,
810 /* Check numeric or bit-op expressions. */
811 for (j
= 0; j
< 2; j
++) {
812 const u8 index
= j
? right
: left
;
813 unsigned long value
= 0;
815 case TOMOYO_TASK_UID
:
816 value
= current_uid();
818 case TOMOYO_TASK_EUID
:
819 value
= current_euid();
821 case TOMOYO_TASK_SUID
:
822 value
= current_suid();
824 case TOMOYO_TASK_FSUID
:
825 value
= current_fsuid();
827 case TOMOYO_TASK_GID
:
828 value
= current_gid();
830 case TOMOYO_TASK_EGID
:
831 value
= current_egid();
833 case TOMOYO_TASK_SGID
:
834 value
= current_sgid();
836 case TOMOYO_TASK_FSGID
:
837 value
= current_fsgid();
839 case TOMOYO_TASK_PID
:
840 value
= tomoyo_sys_getpid();
842 case TOMOYO_TASK_PPID
:
843 value
= tomoyo_sys_getppid();
845 case TOMOYO_TYPE_IS_SOCKET
:
848 case TOMOYO_TYPE_IS_SYMLINK
:
851 case TOMOYO_TYPE_IS_FILE
:
854 case TOMOYO_TYPE_IS_BLOCK_DEV
:
857 case TOMOYO_TYPE_IS_DIRECTORY
:
860 case TOMOYO_TYPE_IS_CHAR_DEV
:
863 case TOMOYO_TYPE_IS_FIFO
:
866 case TOMOYO_MODE_SETUID
:
869 case TOMOYO_MODE_SETGID
:
872 case TOMOYO_MODE_STICKY
:
875 case TOMOYO_MODE_OWNER_READ
:
878 case TOMOYO_MODE_OWNER_WRITE
:
881 case TOMOYO_MODE_OWNER_EXECUTE
:
884 case TOMOYO_MODE_GROUP_READ
:
887 case TOMOYO_MODE_GROUP_WRITE
:
890 case TOMOYO_MODE_GROUP_EXECUTE
:
893 case TOMOYO_MODE_OTHERS_READ
:
896 case TOMOYO_MODE_OTHERS_WRITE
:
899 case TOMOYO_MODE_OTHERS_EXECUTE
:
902 case TOMOYO_EXEC_ARGC
:
907 case TOMOYO_EXEC_ENVC
:
912 case TOMOYO_NUMBER_UNION
:
913 /* Fetch values later. */
918 if (!obj
->validate_done
) {
919 tomoyo_get_attributes(obj
);
920 obj
->validate_done
= true;
924 struct tomoyo_mini_stat
*stat
;
926 case TOMOYO_PATH1_UID
:
927 case TOMOYO_PATH1_GID
:
928 case TOMOYO_PATH1_INO
:
929 case TOMOYO_PATH1_MAJOR
:
930 case TOMOYO_PATH1_MINOR
:
931 case TOMOYO_PATH1_TYPE
:
932 case TOMOYO_PATH1_DEV_MAJOR
:
933 case TOMOYO_PATH1_DEV_MINOR
:
934 case TOMOYO_PATH1_PERM
:
935 stat_index
= TOMOYO_PATH1
;
937 case TOMOYO_PATH2_UID
:
938 case TOMOYO_PATH2_GID
:
939 case TOMOYO_PATH2_INO
:
940 case TOMOYO_PATH2_MAJOR
:
941 case TOMOYO_PATH2_MINOR
:
942 case TOMOYO_PATH2_TYPE
:
943 case TOMOYO_PATH2_DEV_MAJOR
:
944 case TOMOYO_PATH2_DEV_MINOR
:
945 case TOMOYO_PATH2_PERM
:
946 stat_index
= TOMOYO_PATH2
;
948 case TOMOYO_PATH1_PARENT_UID
:
949 case TOMOYO_PATH1_PARENT_GID
:
950 case TOMOYO_PATH1_PARENT_INO
:
951 case TOMOYO_PATH1_PARENT_PERM
:
955 case TOMOYO_PATH2_PARENT_UID
:
956 case TOMOYO_PATH2_PARENT_GID
:
957 case TOMOYO_PATH2_PARENT_INO
:
958 case TOMOYO_PATH2_PARENT_PERM
:
965 if (!obj
->stat_valid
[stat_index
])
967 stat
= &obj
->stat
[stat_index
];
969 case TOMOYO_PATH1_UID
:
970 case TOMOYO_PATH2_UID
:
971 case TOMOYO_PATH1_PARENT_UID
:
972 case TOMOYO_PATH2_PARENT_UID
:
975 case TOMOYO_PATH1_GID
:
976 case TOMOYO_PATH2_GID
:
977 case TOMOYO_PATH1_PARENT_GID
:
978 case TOMOYO_PATH2_PARENT_GID
:
981 case TOMOYO_PATH1_INO
:
982 case TOMOYO_PATH2_INO
:
983 case TOMOYO_PATH1_PARENT_INO
:
984 case TOMOYO_PATH2_PARENT_INO
:
987 case TOMOYO_PATH1_MAJOR
:
988 case TOMOYO_PATH2_MAJOR
:
989 value
= MAJOR(stat
->dev
);
991 case TOMOYO_PATH1_MINOR
:
992 case TOMOYO_PATH2_MINOR
:
993 value
= MINOR(stat
->dev
);
995 case TOMOYO_PATH1_TYPE
:
996 case TOMOYO_PATH2_TYPE
:
997 value
= stat
->mode
& S_IFMT
;
999 case TOMOYO_PATH1_DEV_MAJOR
:
1000 case TOMOYO_PATH2_DEV_MAJOR
:
1001 value
= MAJOR(stat
->rdev
);
1003 case TOMOYO_PATH1_DEV_MINOR
:
1004 case TOMOYO_PATH2_DEV_MINOR
:
1005 value
= MINOR(stat
->rdev
);
1007 case TOMOYO_PATH1_PERM
:
1008 case TOMOYO_PATH2_PERM
:
1009 case TOMOYO_PATH1_PARENT_PERM
:
1010 case TOMOYO_PATH2_PARENT_PERM
:
1011 value
= stat
->mode
& S_IALLUGO
;
1020 case TOMOYO_MODE_SETUID
:
1021 case TOMOYO_MODE_SETGID
:
1022 case TOMOYO_MODE_STICKY
:
1023 case TOMOYO_MODE_OWNER_READ
:
1024 case TOMOYO_MODE_OWNER_WRITE
:
1025 case TOMOYO_MODE_OWNER_EXECUTE
:
1026 case TOMOYO_MODE_GROUP_READ
:
1027 case TOMOYO_MODE_GROUP_WRITE
:
1028 case TOMOYO_MODE_GROUP_EXECUTE
:
1029 case TOMOYO_MODE_OTHERS_READ
:
1030 case TOMOYO_MODE_OTHERS_WRITE
:
1031 case TOMOYO_MODE_OTHERS_EXECUTE
:
1035 if (left
== TOMOYO_NUMBER_UNION
) {
1036 /* Fetch values now. */
1037 const struct tomoyo_number_union
*ptr
= numbers_p
++;
1038 min_v
[0] = ptr
->values
[0];
1039 max_v
[0] = ptr
->values
[1];
1041 if (right
== TOMOYO_NUMBER_UNION
) {
1042 /* Fetch values now. */
1043 const struct tomoyo_number_union
*ptr
= numbers_p
++;
1045 if (tomoyo_number_matches_group(min_v
[0],
1051 if ((min_v
[0] <= ptr
->values
[1] &&
1052 max_v
[0] >= ptr
->values
[0]) == match
)
1058 * Bit operation is valid only when counterpart value
1059 * represents permission.
1061 if (is_bitop
[0] && is_bitop
[1]) {
1063 } else if (is_bitop
[0]) {
1065 case TOMOYO_PATH1_PERM
:
1066 case TOMOYO_PATH1_PARENT_PERM
:
1067 case TOMOYO_PATH2_PERM
:
1068 case TOMOYO_PATH2_PARENT_PERM
:
1069 if (!(max_v
[0] & max_v
[1]) == !match
)
1073 } else if (is_bitop
[1]) {
1075 case TOMOYO_PATH1_PERM
:
1076 case TOMOYO_PATH1_PARENT_PERM
:
1077 case TOMOYO_PATH2_PERM
:
1078 case TOMOYO_PATH2_PARENT_PERM
:
1079 if (!(max_v
[0] & max_v
[1]) == !match
)
1084 /* Normal value range comparison. */
1085 if ((min_v
[0] <= max_v
[1] && max_v
[0] >= min_v
[1]) == match
)
1090 /* Check argv[] and envp[] now. */
1091 if (r
->ee
&& (argc
|| envc
))
1092 return tomoyo_scan_bprm(r
->ee
, argc
, argv
, envc
, envp
);