1 // SPDX-License-Identifier: GPL-2.0
3 * security/tomoyo/condition.c
5 * Copyright (C) 2005-2011 NTT DATA CORPORATION
9 #include <linux/slab.h>
11 /* List of "struct tomoyo_condition". */
12 LIST_HEAD(tomoyo_condition_list
);
15 * tomoyo_argv - Check argv[] in "struct linux_binbrm".
17 * @index: Index number of @arg_ptr.
18 * @arg_ptr: Contents of argv[@index].
19 * @argc: Length of @argv.
20 * @argv: Pointer to "struct tomoyo_argv".
21 * @checked: Set to true if @argv[@index] was found.
23 * Returns true on success, false otherwise.
25 static bool tomoyo_argv(const unsigned int index
, const char *arg_ptr
,
26 const int argc
, const struct tomoyo_argv
*argv
,
30 struct tomoyo_path_info arg
;
32 for (i
= 0; i
< argc
; argv
++, checked
++, i
++) {
34 if (index
!= argv
->index
)
37 tomoyo_fill_path_info(&arg
);
38 result
= tomoyo_path_matches_pattern(&arg
, argv
->value
);
48 * tomoyo_envp - Check envp[] in "struct linux_binbrm".
50 * @env_name: The name of environment variable.
51 * @env_value: The value of environment variable.
52 * @envc: Length of @envp.
53 * @envp: Pointer to "struct tomoyo_envp".
54 * @checked: Set to true if @envp[@env_name] was found.
56 * Returns true on success, false otherwise.
58 static bool tomoyo_envp(const char *env_name
, const char *env_value
,
59 const int envc
, const struct tomoyo_envp
*envp
,
63 struct tomoyo_path_info name
;
64 struct tomoyo_path_info value
;
66 tomoyo_fill_path_info(&name
);
67 value
.name
= env_value
;
68 tomoyo_fill_path_info(&value
);
69 for (i
= 0; i
< envc
; envp
++, checked
++, i
++) {
71 if (!tomoyo_path_matches_pattern(&name
, envp
->name
))
75 result
= tomoyo_path_matches_pattern(&value
,
91 * tomoyo_scan_bprm - Scan "struct linux_binprm".
93 * @ee: Pointer to "struct tomoyo_execve".
94 * @argc: Length of @argc.
95 * @argv: Pointer to "struct tomoyo_argv".
96 * @envc: Length of @envp.
97 * @envp: Poiner to "struct tomoyo_envp".
99 * Returns true on success, false otherwise.
101 static bool tomoyo_scan_bprm(struct tomoyo_execve
*ee
,
102 const u16 argc
, const struct tomoyo_argv
*argv
,
103 const u16 envc
, const struct tomoyo_envp
*envp
)
105 struct linux_binprm
*bprm
= ee
->bprm
;
106 struct tomoyo_page_dump
*dump
= &ee
->dump
;
107 char *arg_ptr
= ee
->tmp
;
109 unsigned long pos
= bprm
->p
;
110 int offset
= pos
% PAGE_SIZE
;
111 int argv_count
= bprm
->argc
;
112 int envp_count
= bprm
->envc
;
114 u8 local_checked
[32];
116 if (argc
+ envc
<= sizeof(local_checked
)) {
117 checked
= local_checked
;
118 memset(local_checked
, 0, sizeof(local_checked
));
120 checked
= kzalloc(argc
+ envc
, GFP_NOFS
);
124 while (argv_count
|| envp_count
) {
125 if (!tomoyo_dump_page(bprm
, pos
, dump
)) {
129 pos
+= PAGE_SIZE
- offset
;
130 while (offset
< PAGE_SIZE
) {
132 const char *kaddr
= dump
->data
;
133 const unsigned char c
= kaddr
[offset
++];
134 if (c
&& arg_len
< TOMOYO_EXEC_TMPSIZE
- 10) {
136 arg_ptr
[arg_len
++] = '\\';
137 arg_ptr
[arg_len
++] = '\\';
138 } else if (c
> ' ' && c
< 127) {
139 arg_ptr
[arg_len
++] = c
;
141 arg_ptr
[arg_len
++] = '\\';
142 arg_ptr
[arg_len
++] = (c
>> 6) + '0';
144 ((c
>> 3) & 7) + '0';
145 arg_ptr
[arg_len
++] = (c
& 7) + '0';
148 arg_ptr
[arg_len
] = '\0';
154 if (!tomoyo_argv(bprm
->argc
- argv_count
,
161 } else if (envp_count
) {
162 char *cp
= strchr(arg_ptr
, '=');
165 if (!tomoyo_envp(arg_ptr
, cp
+ 1,
185 /* Check not-yet-checked entries. */
186 for (i
= 0; i
< argc
; i
++) {
190 * Return true only if all unchecked indexes in
191 * bprm->argv[] are not matched.
198 for (i
= 0; i
< envc
; envp
++, i
++) {
199 if (checked
[argc
+ i
])
202 * Return true only if all unchecked environ variables
203 * in bprm->envp[] are either undefined or not matched.
205 if ((!envp
->value
&& !envp
->is_not
) ||
206 (envp
->value
&& envp
->is_not
))
212 if (checked
!= local_checked
)
218 * tomoyo_scan_exec_realpath - Check "exec.realpath" parameter of "struct tomoyo_condition".
220 * @file: Pointer to "struct file".
221 * @ptr: Pointer to "struct tomoyo_name_union".
222 * @match: True if "exec.realpath=", false if "exec.realpath!=".
224 * Returns true on success, false otherwise.
226 static bool tomoyo_scan_exec_realpath(struct file
*file
,
227 const struct tomoyo_name_union
*ptr
,
231 struct tomoyo_path_info exe
;
234 exe
.name
= tomoyo_realpath_from_path(&file
->f_path
);
237 tomoyo_fill_path_info(&exe
);
238 result
= tomoyo_compare_name_union(&exe
, ptr
);
240 return result
== match
;
244 * tomoyo_get_dqword - tomoyo_get_name() for a quoted string.
246 * @start: String to save.
248 * Returns pointer to "struct tomoyo_path_info" on success, NULL otherwise.
250 static const struct tomoyo_path_info
*tomoyo_get_dqword(char *start
)
252 char *cp
= start
+ strlen(start
) - 1;
253 if (cp
== start
|| *start
++ != '"' || *cp
!= '"')
256 if (*start
&& !tomoyo_correct_word(start
))
258 return tomoyo_get_name(start
);
262 * tomoyo_parse_name_union_quoted - Parse a quoted word.
264 * @param: Pointer to "struct tomoyo_acl_param".
265 * @ptr: Pointer to "struct tomoyo_name_union".
267 * Returns true on success, false otherwise.
269 static bool tomoyo_parse_name_union_quoted(struct tomoyo_acl_param
*param
,
270 struct tomoyo_name_union
*ptr
)
272 char *filename
= param
->data
;
273 if (*filename
== '@')
274 return tomoyo_parse_name_union(param
, ptr
);
275 ptr
->filename
= tomoyo_get_dqword(filename
);
276 return ptr
->filename
!= NULL
;
280 * tomoyo_parse_argv - Parse an argv[] condition part.
282 * @left: Lefthand value.
283 * @right: Righthand value.
284 * @argv: Pointer to "struct tomoyo_argv".
286 * Returns true on success, false otherwise.
288 static bool tomoyo_parse_argv(char *left
, char *right
,
289 struct tomoyo_argv
*argv
)
291 if (tomoyo_parse_ulong(&argv
->index
, &left
) !=
292 TOMOYO_VALUE_TYPE_DECIMAL
|| *left
++ != ']' || *left
)
294 argv
->value
= tomoyo_get_dqword(right
);
295 return argv
->value
!= NULL
;
299 * tomoyo_parse_envp - Parse an envp[] condition part.
301 * @left: Lefthand value.
302 * @right: Righthand value.
303 * @envp: Pointer to "struct tomoyo_envp".
305 * Returns true on success, false otherwise.
307 static bool tomoyo_parse_envp(char *left
, char *right
,
308 struct tomoyo_envp
*envp
)
310 const struct tomoyo_path_info
*name
;
311 const struct tomoyo_path_info
*value
;
312 char *cp
= left
+ strlen(left
) - 1;
313 if (*cp
-- != ']' || *cp
!= '"')
316 if (!tomoyo_correct_word(left
))
318 name
= tomoyo_get_name(left
);
321 if (!strcmp(right
, "NULL")) {
324 value
= tomoyo_get_dqword(right
);
326 tomoyo_put_name(name
);
338 * tomoyo_same_condition - Check for duplicated "struct tomoyo_condition" entry.
340 * @a: Pointer to "struct tomoyo_condition".
341 * @b: Pointer to "struct tomoyo_condition".
343 * Returns true if @a == @b, false otherwise.
345 static inline bool tomoyo_same_condition(const struct tomoyo_condition
*a
,
346 const struct tomoyo_condition
*b
)
348 return a
->size
== b
->size
&& a
->condc
== b
->condc
&&
349 a
->numbers_count
== b
->numbers_count
&&
350 a
->names_count
== b
->names_count
&&
351 a
->argc
== b
->argc
&& a
->envc
== b
->envc
&&
352 a
->grant_log
== b
->grant_log
&& a
->transit
== b
->transit
&&
353 !memcmp(a
+ 1, b
+ 1, a
->size
- sizeof(*a
));
357 * tomoyo_condition_type - Get condition type.
359 * @word: Keyword string.
361 * Returns one of values in "enum tomoyo_conditions_index" on success,
362 * TOMOYO_MAX_CONDITION_KEYWORD otherwise.
364 static u8
tomoyo_condition_type(const char *word
)
367 for (i
= 0; i
< TOMOYO_MAX_CONDITION_KEYWORD
; i
++) {
368 if (!strcmp(word
, tomoyo_condition_keyword
[i
]))
374 /* Define this to enable debug mode. */
375 /* #define DEBUG_CONDITION */
377 #ifdef DEBUG_CONDITION
378 #define dprintk printk
380 #define dprintk(...) do { } while (0)
384 * tomoyo_commit_condition - Commit "struct tomoyo_condition".
386 * @entry: Pointer to "struct tomoyo_condition".
388 * Returns pointer to "struct tomoyo_condition" on success, NULL otherwise.
390 * This function merges duplicated entries. This function returns NULL if
391 * @entry is not duplicated but memory quota for policy has exceeded.
393 static struct tomoyo_condition
*tomoyo_commit_condition
394 (struct tomoyo_condition
*entry
)
396 struct tomoyo_condition
*ptr
;
398 if (mutex_lock_interruptible(&tomoyo_policy_lock
)) {
399 dprintk(KERN_WARNING
"%u: %s failed\n", __LINE__
, __func__
);
404 list_for_each_entry(ptr
, &tomoyo_condition_list
, head
.list
) {
405 if (!tomoyo_same_condition(ptr
, entry
) ||
406 atomic_read(&ptr
->head
.users
) == TOMOYO_GC_IN_PROGRESS
)
408 /* Same entry found. Share this entry. */
409 atomic_inc(&ptr
->head
.users
);
414 if (tomoyo_memory_ok(entry
)) {
415 atomic_set(&entry
->head
.users
, 1);
416 list_add(&entry
->head
.list
, &tomoyo_condition_list
);
422 mutex_unlock(&tomoyo_policy_lock
);
425 tomoyo_del_condition(&entry
->head
.list
);
433 * tomoyo_get_transit_preference - Parse domain transition preference for execve().
435 * @param: Pointer to "struct tomoyo_acl_param".
436 * @e: Pointer to "struct tomoyo_condition".
438 * Returns the condition string part.
440 static char *tomoyo_get_transit_preference(struct tomoyo_acl_param
*param
,
441 struct tomoyo_condition
*e
)
443 char * const pos
= param
->data
;
446 e
->transit
= tomoyo_get_domainname(param
);
450 char *cp
= strchr(pos
, ' ');
453 flag
= tomoyo_correct_path(pos
) || !strcmp(pos
, "keep") ||
454 !strcmp(pos
, "initialize") || !strcmp(pos
, "reset") ||
455 !strcmp(pos
, "child") || !strcmp(pos
, "parent");
461 e
->transit
= tomoyo_get_name(tomoyo_read_token(param
));
466 * Return a bad read-only condition string that will let
467 * tomoyo_get_condition() return NULL.
473 * tomoyo_get_condition - Parse condition part.
475 * @param: Pointer to "struct tomoyo_acl_param".
477 * Returns pointer to "struct tomoyo_condition" on success, NULL otherwise.
479 struct tomoyo_condition
*tomoyo_get_condition(struct tomoyo_acl_param
*param
)
481 struct tomoyo_condition
*entry
= NULL
;
482 struct tomoyo_condition_element
*condp
= NULL
;
483 struct tomoyo_number_union
*numbers_p
= NULL
;
484 struct tomoyo_name_union
*names_p
= NULL
;
485 struct tomoyo_argv
*argv
= NULL
;
486 struct tomoyo_envp
*envp
= NULL
;
487 struct tomoyo_condition e
= { };
488 char * const start_of_string
=
489 tomoyo_get_transit_preference(param
, &e
);
490 char * const end_of_string
= start_of_string
+ strlen(start_of_string
);
493 pos
= start_of_string
;
497 char *left_word
= pos
;
504 * Since left-hand condition does not allow use of "path_group"
505 * or "number_group" and environment variable's names do not
506 * accept '=', it is guaranteed that the original line consists
507 * of one or more repetition of $left$operator$right blocks
508 * where "$left is free from '=' and ' '" and "$operator is
509 * either '=' or '!='" and "$right is free from ' '".
510 * Therefore, we can reconstruct the original line at the end
511 * of dry run even if we overwrite $operator with '\0'.
513 cp
= strchr(pos
, ' ');
515 *cp
= '\0'; /* Will restore later. */
520 right_word
= strchr(left_word
, '=');
521 if (!right_word
|| right_word
== left_word
)
523 is_not
= *(right_word
- 1) == '!';
525 *(right_word
++ - 1) = '\0'; /* Will restore later. */
526 else if (*(right_word
+ 1) != '=')
527 *right_word
++ = '\0'; /* Will restore later. */
530 dprintk(KERN_WARNING
"%u: <%s>%s=<%s>\n", __LINE__
, left_word
,
531 is_not
? "!" : "", right_word
);
532 if (!strcmp(left_word
, "grant_log")) {
535 entry
->grant_log
!= TOMOYO_GRANTLOG_AUTO
)
537 else if (!strcmp(right_word
, "yes"))
538 entry
->grant_log
= TOMOYO_GRANTLOG_YES
;
539 else if (!strcmp(right_word
, "no"))
540 entry
->grant_log
= TOMOYO_GRANTLOG_NO
;
546 if (!strncmp(left_word
, "exec.argv[", 10)) {
553 left
= TOMOYO_ARGV_ENTRY
;
554 argv
->is_not
= is_not
;
555 if (!tomoyo_parse_argv(left_word
+ 10,
561 if (!strncmp(left_word
, "exec.envp[\"", 11)) {
568 left
= TOMOYO_ENVP_ENTRY
;
569 envp
->is_not
= is_not
;
570 if (!tomoyo_parse_envp(left_word
+ 11,
576 left
= tomoyo_condition_type(left_word
);
577 dprintk(KERN_WARNING
"%u: <%s> left=%u\n", __LINE__
, left_word
,
579 if (left
== TOMOYO_MAX_CONDITION_KEYWORD
) {
584 left
= TOMOYO_NUMBER_UNION
;
585 param
->data
= left_word
;
586 if (*left_word
== '@' ||
587 !tomoyo_parse_number_union(param
,
596 if (left
== TOMOYO_EXEC_REALPATH
||
597 left
== TOMOYO_SYMLINK_TARGET
) {
602 right
= TOMOYO_NAME_UNION
;
603 param
->data
= right_word
;
604 if (!tomoyo_parse_name_union_quoted(param
,
610 right
= tomoyo_condition_type(right_word
);
611 if (right
== TOMOYO_MAX_CONDITION_KEYWORD
) {
616 right
= TOMOYO_NUMBER_UNION
;
617 param
->data
= right_word
;
618 if (!tomoyo_parse_number_union(param
,
625 dprintk(KERN_WARNING
"%u: dry_run left=%u right=%u "
626 "match=%u\n", __LINE__
, left
, right
, !is_not
);
630 condp
->right
= right
;
631 condp
->equals
= !is_not
;
632 dprintk(KERN_WARNING
"%u: left=%u right=%u match=%u\n",
633 __LINE__
, condp
->left
, condp
->right
,
637 dprintk(KERN_INFO
"%u: cond=%u numbers=%u names=%u ac=%u ec=%u\n",
638 __LINE__
, e
.condc
, e
.numbers_count
, e
.names_count
, e
.argc
,
641 BUG_ON(e
.names_count
| e
.numbers_count
| e
.argc
| e
.envc
|
643 return tomoyo_commit_condition(entry
);
645 e
.size
= sizeof(*entry
)
646 + e
.condc
* sizeof(struct tomoyo_condition_element
)
647 + e
.numbers_count
* sizeof(struct tomoyo_number_union
)
648 + e
.names_count
* sizeof(struct tomoyo_name_union
)
649 + e
.argc
* sizeof(struct tomoyo_argv
)
650 + e
.envc
* sizeof(struct tomoyo_envp
);
651 entry
= kzalloc(e
.size
, GFP_NOFS
);
656 condp
= (struct tomoyo_condition_element
*) (entry
+ 1);
657 numbers_p
= (struct tomoyo_number_union
*) (condp
+ e
.condc
);
658 names_p
= (struct tomoyo_name_union
*) (numbers_p
+ e
.numbers_count
);
659 argv
= (struct tomoyo_argv
*) (names_p
+ e
.names_count
);
660 envp
= (struct tomoyo_envp
*) (argv
+ e
.argc
);
663 for (pos
= start_of_string
; pos
< end_of_string
; pos
++) {
666 if (flag
) /* Restore " ". */
668 else if (*(pos
+ 1) == '=') /* Restore "!=". */
670 else /* Restore "=". */
677 dprintk(KERN_WARNING
"%u: %s failed\n", __LINE__
, __func__
);
679 tomoyo_del_condition(&entry
->head
.list
);
683 tomoyo_put_name(e
.transit
);
688 * tomoyo_get_attributes - Revalidate "struct inode".
690 * @obj: Pointer to "struct tomoyo_obj_info".
694 void tomoyo_get_attributes(struct tomoyo_obj_info
*obj
)
697 struct dentry
*dentry
= NULL
;
699 for (i
= 0; i
< TOMOYO_MAX_PATH_STAT
; i
++) {
703 dentry
= obj
->path1
.dentry
;
708 dentry
= obj
->path2
.dentry
;
715 dentry
= dget_parent(dentry
);
718 inode
= d_backing_inode(dentry
);
720 struct tomoyo_mini_stat
*stat
= &obj
->stat
[i
];
721 stat
->uid
= inode
->i_uid
;
722 stat
->gid
= inode
->i_gid
;
723 stat
->ino
= inode
->i_ino
;
724 stat
->mode
= inode
->i_mode
;
725 stat
->dev
= inode
->i_sb
->s_dev
;
726 stat
->rdev
= inode
->i_rdev
;
727 obj
->stat_valid
[i
] = true;
729 if (i
& 1) /* i == TOMOYO_PATH1_PARENT ||
730 i == TOMOYO_PATH2_PARENT */
736 * tomoyo_condition - Check condition part.
738 * @r: Pointer to "struct tomoyo_request_info".
739 * @cond: Pointer to "struct tomoyo_condition". Maybe NULL.
741 * Returns true on success, false otherwise.
743 * Caller holds tomoyo_read_lock().
745 bool tomoyo_condition(struct tomoyo_request_info
*r
,
746 const struct tomoyo_condition
*cond
)
749 unsigned long min_v
[2] = { 0, 0 };
750 unsigned long max_v
[2] = { 0, 0 };
751 const struct tomoyo_condition_element
*condp
;
752 const struct tomoyo_number_union
*numbers_p
;
753 const struct tomoyo_name_union
*names_p
;
754 const struct tomoyo_argv
*argv
;
755 const struct tomoyo_envp
*envp
;
756 struct tomoyo_obj_info
*obj
;
760 struct linux_binprm
*bprm
= NULL
;
769 if (!bprm
&& (argc
|| envc
))
771 condp
= (struct tomoyo_condition_element
*) (cond
+ 1);
772 numbers_p
= (const struct tomoyo_number_union
*) (condp
+ condc
);
773 names_p
= (const struct tomoyo_name_union
*)
774 (numbers_p
+ cond
->numbers_count
);
775 argv
= (const struct tomoyo_argv
*) (names_p
+ cond
->names_count
);
776 envp
= (const struct tomoyo_envp
*) (argv
+ argc
);
777 for (i
= 0; i
< condc
; i
++) {
778 const bool match
= condp
->equals
;
779 const u8 left
= condp
->left
;
780 const u8 right
= condp
->right
;
781 bool is_bitop
[2] = { false, false };
784 /* Check argv[] and envp[] later. */
785 if (left
== TOMOYO_ARGV_ENTRY
|| left
== TOMOYO_ENVP_ENTRY
)
787 /* Check string expressions. */
788 if (right
== TOMOYO_NAME_UNION
) {
789 const struct tomoyo_name_union
*ptr
= names_p
++;
791 struct tomoyo_path_info
*symlink
;
792 struct tomoyo_execve
*ee
;
794 case TOMOYO_SYMLINK_TARGET
:
795 symlink
= obj
? obj
->symlink_target
: NULL
;
797 !tomoyo_compare_name_union(symlink
, ptr
)
801 case TOMOYO_EXEC_REALPATH
:
803 file
= ee
? ee
->bprm
->file
: NULL
;
804 if (!tomoyo_scan_exec_realpath(file
, ptr
,
811 /* Check numeric or bit-op expressions. */
812 for (j
= 0; j
< 2; j
++) {
813 const u8 index
= j
? right
: left
;
814 unsigned long value
= 0;
816 case TOMOYO_TASK_UID
:
817 value
= from_kuid(&init_user_ns
, current_uid());
819 case TOMOYO_TASK_EUID
:
820 value
= from_kuid(&init_user_ns
, current_euid());
822 case TOMOYO_TASK_SUID
:
823 value
= from_kuid(&init_user_ns
, current_suid());
825 case TOMOYO_TASK_FSUID
:
826 value
= from_kuid(&init_user_ns
, current_fsuid());
828 case TOMOYO_TASK_GID
:
829 value
= from_kgid(&init_user_ns
, current_gid());
831 case TOMOYO_TASK_EGID
:
832 value
= from_kgid(&init_user_ns
, current_egid());
834 case TOMOYO_TASK_SGID
:
835 value
= from_kgid(&init_user_ns
, current_sgid());
837 case TOMOYO_TASK_FSGID
:
838 value
= from_kgid(&init_user_ns
, current_fsgid());
840 case TOMOYO_TASK_PID
:
841 value
= tomoyo_sys_getpid();
843 case TOMOYO_TASK_PPID
:
844 value
= tomoyo_sys_getppid();
846 case TOMOYO_TYPE_IS_SOCKET
:
849 case TOMOYO_TYPE_IS_SYMLINK
:
852 case TOMOYO_TYPE_IS_FILE
:
855 case TOMOYO_TYPE_IS_BLOCK_DEV
:
858 case TOMOYO_TYPE_IS_DIRECTORY
:
861 case TOMOYO_TYPE_IS_CHAR_DEV
:
864 case TOMOYO_TYPE_IS_FIFO
:
867 case TOMOYO_MODE_SETUID
:
870 case TOMOYO_MODE_SETGID
:
873 case TOMOYO_MODE_STICKY
:
876 case TOMOYO_MODE_OWNER_READ
:
879 case TOMOYO_MODE_OWNER_WRITE
:
882 case TOMOYO_MODE_OWNER_EXECUTE
:
885 case TOMOYO_MODE_GROUP_READ
:
888 case TOMOYO_MODE_GROUP_WRITE
:
891 case TOMOYO_MODE_GROUP_EXECUTE
:
894 case TOMOYO_MODE_OTHERS_READ
:
897 case TOMOYO_MODE_OTHERS_WRITE
:
900 case TOMOYO_MODE_OTHERS_EXECUTE
:
903 case TOMOYO_EXEC_ARGC
:
908 case TOMOYO_EXEC_ENVC
:
913 case TOMOYO_NUMBER_UNION
:
914 /* Fetch values later. */
919 if (!obj
->validate_done
) {
920 tomoyo_get_attributes(obj
);
921 obj
->validate_done
= true;
925 struct tomoyo_mini_stat
*stat
;
927 case TOMOYO_PATH1_UID
:
928 case TOMOYO_PATH1_GID
:
929 case TOMOYO_PATH1_INO
:
930 case TOMOYO_PATH1_MAJOR
:
931 case TOMOYO_PATH1_MINOR
:
932 case TOMOYO_PATH1_TYPE
:
933 case TOMOYO_PATH1_DEV_MAJOR
:
934 case TOMOYO_PATH1_DEV_MINOR
:
935 case TOMOYO_PATH1_PERM
:
936 stat_index
= TOMOYO_PATH1
;
938 case TOMOYO_PATH2_UID
:
939 case TOMOYO_PATH2_GID
:
940 case TOMOYO_PATH2_INO
:
941 case TOMOYO_PATH2_MAJOR
:
942 case TOMOYO_PATH2_MINOR
:
943 case TOMOYO_PATH2_TYPE
:
944 case TOMOYO_PATH2_DEV_MAJOR
:
945 case TOMOYO_PATH2_DEV_MINOR
:
946 case TOMOYO_PATH2_PERM
:
947 stat_index
= TOMOYO_PATH2
;
949 case TOMOYO_PATH1_PARENT_UID
:
950 case TOMOYO_PATH1_PARENT_GID
:
951 case TOMOYO_PATH1_PARENT_INO
:
952 case TOMOYO_PATH1_PARENT_PERM
:
956 case TOMOYO_PATH2_PARENT_UID
:
957 case TOMOYO_PATH2_PARENT_GID
:
958 case TOMOYO_PATH2_PARENT_INO
:
959 case TOMOYO_PATH2_PARENT_PERM
:
966 if (!obj
->stat_valid
[stat_index
])
968 stat
= &obj
->stat
[stat_index
];
970 case TOMOYO_PATH1_UID
:
971 case TOMOYO_PATH2_UID
:
972 case TOMOYO_PATH1_PARENT_UID
:
973 case TOMOYO_PATH2_PARENT_UID
:
974 value
= from_kuid(&init_user_ns
, stat
->uid
);
976 case TOMOYO_PATH1_GID
:
977 case TOMOYO_PATH2_GID
:
978 case TOMOYO_PATH1_PARENT_GID
:
979 case TOMOYO_PATH2_PARENT_GID
:
980 value
= from_kgid(&init_user_ns
, stat
->gid
);
982 case TOMOYO_PATH1_INO
:
983 case TOMOYO_PATH2_INO
:
984 case TOMOYO_PATH1_PARENT_INO
:
985 case TOMOYO_PATH2_PARENT_INO
:
988 case TOMOYO_PATH1_MAJOR
:
989 case TOMOYO_PATH2_MAJOR
:
990 value
= MAJOR(stat
->dev
);
992 case TOMOYO_PATH1_MINOR
:
993 case TOMOYO_PATH2_MINOR
:
994 value
= MINOR(stat
->dev
);
996 case TOMOYO_PATH1_TYPE
:
997 case TOMOYO_PATH2_TYPE
:
998 value
= stat
->mode
& S_IFMT
;
1000 case TOMOYO_PATH1_DEV_MAJOR
:
1001 case TOMOYO_PATH2_DEV_MAJOR
:
1002 value
= MAJOR(stat
->rdev
);
1004 case TOMOYO_PATH1_DEV_MINOR
:
1005 case TOMOYO_PATH2_DEV_MINOR
:
1006 value
= MINOR(stat
->rdev
);
1008 case TOMOYO_PATH1_PERM
:
1009 case TOMOYO_PATH2_PERM
:
1010 case TOMOYO_PATH1_PARENT_PERM
:
1011 case TOMOYO_PATH2_PARENT_PERM
:
1012 value
= stat
->mode
& S_IALLUGO
;
1021 case TOMOYO_MODE_SETUID
:
1022 case TOMOYO_MODE_SETGID
:
1023 case TOMOYO_MODE_STICKY
:
1024 case TOMOYO_MODE_OWNER_READ
:
1025 case TOMOYO_MODE_OWNER_WRITE
:
1026 case TOMOYO_MODE_OWNER_EXECUTE
:
1027 case TOMOYO_MODE_GROUP_READ
:
1028 case TOMOYO_MODE_GROUP_WRITE
:
1029 case TOMOYO_MODE_GROUP_EXECUTE
:
1030 case TOMOYO_MODE_OTHERS_READ
:
1031 case TOMOYO_MODE_OTHERS_WRITE
:
1032 case TOMOYO_MODE_OTHERS_EXECUTE
:
1036 if (left
== TOMOYO_NUMBER_UNION
) {
1037 /* Fetch values now. */
1038 const struct tomoyo_number_union
*ptr
= numbers_p
++;
1039 min_v
[0] = ptr
->values
[0];
1040 max_v
[0] = ptr
->values
[1];
1042 if (right
== TOMOYO_NUMBER_UNION
) {
1043 /* Fetch values now. */
1044 const struct tomoyo_number_union
*ptr
= numbers_p
++;
1046 if (tomoyo_number_matches_group(min_v
[0],
1052 if ((min_v
[0] <= ptr
->values
[1] &&
1053 max_v
[0] >= ptr
->values
[0]) == match
)
1059 * Bit operation is valid only when counterpart value
1060 * represents permission.
1062 if (is_bitop
[0] && is_bitop
[1]) {
1064 } else if (is_bitop
[0]) {
1066 case TOMOYO_PATH1_PERM
:
1067 case TOMOYO_PATH1_PARENT_PERM
:
1068 case TOMOYO_PATH2_PERM
:
1069 case TOMOYO_PATH2_PARENT_PERM
:
1070 if (!(max_v
[0] & max_v
[1]) == !match
)
1074 } else if (is_bitop
[1]) {
1076 case TOMOYO_PATH1_PERM
:
1077 case TOMOYO_PATH1_PARENT_PERM
:
1078 case TOMOYO_PATH2_PERM
:
1079 case TOMOYO_PATH2_PARENT_PERM
:
1080 if (!(max_v
[0] & max_v
[1]) == !match
)
1085 /* Normal value range comparison. */
1086 if ((min_v
[0] <= max_v
[1] && max_v
[0] >= min_v
[1]) == match
)
1091 /* Check argv[] and envp[] now. */
1092 if (r
->ee
&& (argc
|| envc
))
1093 return tomoyo_scan_bprm(r
->ee
, argc
, argv
, envc
, envp
);