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
;
33 for (i
= 0; i
< argc
; argv
++, checked
++, i
++) {
36 if (index
!= argv
->index
)
39 tomoyo_fill_path_info(&arg
);
40 result
= tomoyo_path_matches_pattern(&arg
, argv
->value
);
50 * tomoyo_envp - Check envp[] in "struct linux_binbrm".
52 * @env_name: The name of environment variable.
53 * @env_value: The value of environment variable.
54 * @envc: Length of @envp.
55 * @envp: Pointer to "struct tomoyo_envp".
56 * @checked: Set to true if @envp[@env_name] was found.
58 * Returns true on success, false otherwise.
60 static bool tomoyo_envp(const char *env_name
, const char *env_value
,
61 const int envc
, const struct tomoyo_envp
*envp
,
65 struct tomoyo_path_info name
;
66 struct tomoyo_path_info value
;
69 tomoyo_fill_path_info(&name
);
70 value
.name
= env_value
;
71 tomoyo_fill_path_info(&value
);
72 for (i
= 0; i
< envc
; envp
++, checked
++, i
++) {
75 if (!tomoyo_path_matches_pattern(&name
, envp
->name
))
79 result
= tomoyo_path_matches_pattern(&value
,
95 * tomoyo_scan_bprm - Scan "struct linux_binprm".
97 * @ee: Pointer to "struct tomoyo_execve".
98 * @argc: Length of @argc.
99 * @argv: Pointer to "struct tomoyo_argv".
100 * @envc: Length of @envp.
101 * @envp: Pointer to "struct tomoyo_envp".
103 * Returns true on success, false otherwise.
105 static bool tomoyo_scan_bprm(struct tomoyo_execve
*ee
,
106 const u16 argc
, const struct tomoyo_argv
*argv
,
107 const u16 envc
, const struct tomoyo_envp
*envp
)
109 struct linux_binprm
*bprm
= ee
->bprm
;
110 struct tomoyo_page_dump
*dump
= &ee
->dump
;
111 char *arg_ptr
= ee
->tmp
;
113 unsigned long pos
= bprm
->p
;
114 int offset
= pos
% PAGE_SIZE
;
115 int argv_count
= bprm
->argc
;
116 int envp_count
= bprm
->envc
;
118 u8 local_checked
[32];
121 if (argc
+ envc
<= sizeof(local_checked
)) {
122 checked
= local_checked
;
123 memset(local_checked
, 0, sizeof(local_checked
));
125 checked
= kzalloc(argc
+ envc
, GFP_NOFS
);
129 while (argv_count
|| envp_count
) {
130 if (!tomoyo_dump_page(bprm
, pos
, dump
)) {
134 pos
+= PAGE_SIZE
- offset
;
135 while (offset
< PAGE_SIZE
) {
137 const char *kaddr
= dump
->data
;
138 const unsigned char c
= kaddr
[offset
++];
140 if (c
&& arg_len
< TOMOYO_EXEC_TMPSIZE
- 10) {
142 arg_ptr
[arg_len
++] = '\\';
143 arg_ptr
[arg_len
++] = '\\';
144 } else if (c
> ' ' && c
< 127) {
145 arg_ptr
[arg_len
++] = c
;
147 arg_ptr
[arg_len
++] = '\\';
148 arg_ptr
[arg_len
++] = (c
>> 6) + '0';
150 ((c
>> 3) & 7) + '0';
151 arg_ptr
[arg_len
++] = (c
& 7) + '0';
154 arg_ptr
[arg_len
] = '\0';
160 if (!tomoyo_argv(bprm
->argc
- argv_count
,
167 } else if (envp_count
) {
168 char *cp
= strchr(arg_ptr
, '=');
172 if (!tomoyo_envp(arg_ptr
, cp
+ 1,
193 /* Check not-yet-checked entries. */
194 for (i
= 0; i
< argc
; i
++) {
198 * Return true only if all unchecked indexes in
199 * bprm->argv[] are not matched.
206 for (i
= 0; i
< envc
; envp
++, i
++) {
207 if (checked
[argc
+ i
])
210 * Return true only if all unchecked environ variables
211 * in bprm->envp[] are either undefined or not matched.
213 if ((!envp
->value
&& !envp
->is_not
) ||
214 (envp
->value
&& envp
->is_not
))
220 if (checked
!= local_checked
)
226 * tomoyo_scan_exec_realpath - Check "exec.realpath" parameter of "struct tomoyo_condition".
228 * @file: Pointer to "struct file".
229 * @ptr: Pointer to "struct tomoyo_name_union".
230 * @match: True if "exec.realpath=", false if "exec.realpath!=".
232 * Returns true on success, false otherwise.
234 static bool tomoyo_scan_exec_realpath(struct file
*file
,
235 const struct tomoyo_name_union
*ptr
,
239 struct tomoyo_path_info exe
;
243 exe
.name
= tomoyo_realpath_from_path(&file
->f_path
);
246 tomoyo_fill_path_info(&exe
);
247 result
= tomoyo_compare_name_union(&exe
, ptr
);
249 return result
== match
;
253 * tomoyo_get_dqword - tomoyo_get_name() for a quoted string.
255 * @start: String to save.
257 * Returns pointer to "struct tomoyo_path_info" on success, NULL otherwise.
259 static const struct tomoyo_path_info
*tomoyo_get_dqword(char *start
)
261 char *cp
= start
+ strlen(start
) - 1;
263 if (cp
== start
|| *start
++ != '"' || *cp
!= '"')
266 if (*start
&& !tomoyo_correct_word(start
))
268 return tomoyo_get_name(start
);
272 * tomoyo_parse_name_union_quoted - Parse a quoted word.
274 * @param: Pointer to "struct tomoyo_acl_param".
275 * @ptr: Pointer to "struct tomoyo_name_union".
277 * Returns true on success, false otherwise.
279 static bool tomoyo_parse_name_union_quoted(struct tomoyo_acl_param
*param
,
280 struct tomoyo_name_union
*ptr
)
282 char *filename
= param
->data
;
284 if (*filename
== '@')
285 return tomoyo_parse_name_union(param
, ptr
);
286 ptr
->filename
= tomoyo_get_dqword(filename
);
287 return ptr
->filename
!= NULL
;
291 * tomoyo_parse_argv - Parse an argv[] condition part.
293 * @left: Lefthand value.
294 * @right: Righthand value.
295 * @argv: Pointer to "struct tomoyo_argv".
297 * Returns true on success, false otherwise.
299 static bool tomoyo_parse_argv(char *left
, char *right
,
300 struct tomoyo_argv
*argv
)
302 if (tomoyo_parse_ulong(&argv
->index
, &left
) !=
303 TOMOYO_VALUE_TYPE_DECIMAL
|| *left
++ != ']' || *left
)
305 argv
->value
= tomoyo_get_dqword(right
);
306 return argv
->value
!= NULL
;
310 * tomoyo_parse_envp - Parse an envp[] condition part.
312 * @left: Lefthand value.
313 * @right: Righthand value.
314 * @envp: Pointer to "struct tomoyo_envp".
316 * Returns true on success, false otherwise.
318 static bool tomoyo_parse_envp(char *left
, char *right
,
319 struct tomoyo_envp
*envp
)
321 const struct tomoyo_path_info
*name
;
322 const struct tomoyo_path_info
*value
;
323 char *cp
= left
+ strlen(left
) - 1;
325 if (*cp
-- != ']' || *cp
!= '"')
328 if (!tomoyo_correct_word(left
))
330 name
= tomoyo_get_name(left
);
333 if (!strcmp(right
, "NULL")) {
336 value
= tomoyo_get_dqword(right
);
338 tomoyo_put_name(name
);
350 * tomoyo_same_condition - Check for duplicated "struct tomoyo_condition" entry.
352 * @a: Pointer to "struct tomoyo_condition".
353 * @b: Pointer to "struct tomoyo_condition".
355 * Returns true if @a == @b, false otherwise.
357 static inline bool tomoyo_same_condition(const struct tomoyo_condition
*a
,
358 const struct tomoyo_condition
*b
)
360 return a
->size
== b
->size
&& a
->condc
== b
->condc
&&
361 a
->numbers_count
== b
->numbers_count
&&
362 a
->names_count
== b
->names_count
&&
363 a
->argc
== b
->argc
&& a
->envc
== b
->envc
&&
364 a
->grant_log
== b
->grant_log
&& a
->transit
== b
->transit
&&
365 !memcmp(a
+ 1, b
+ 1, a
->size
- sizeof(*a
));
369 * tomoyo_condition_type - Get condition type.
371 * @word: Keyword string.
373 * Returns one of values in "enum tomoyo_conditions_index" on success,
374 * TOMOYO_MAX_CONDITION_KEYWORD otherwise.
376 static u8
tomoyo_condition_type(const char *word
)
380 for (i
= 0; i
< TOMOYO_MAX_CONDITION_KEYWORD
; i
++) {
381 if (!strcmp(word
, tomoyo_condition_keyword
[i
]))
387 /* Define this to enable debug mode. */
388 /* #define DEBUG_CONDITION */
390 #ifdef DEBUG_CONDITION
391 #define dprintk printk
393 #define dprintk(...) do { } while (0)
397 * tomoyo_commit_condition - Commit "struct tomoyo_condition".
399 * @entry: Pointer to "struct tomoyo_condition".
401 * Returns pointer to "struct tomoyo_condition" on success, NULL otherwise.
403 * This function merges duplicated entries. This function returns NULL if
404 * @entry is not duplicated but memory quota for policy has exceeded.
406 static struct tomoyo_condition
*tomoyo_commit_condition
407 (struct tomoyo_condition
*entry
)
409 struct tomoyo_condition
*ptr
;
412 if (mutex_lock_interruptible(&tomoyo_policy_lock
)) {
413 dprintk(KERN_WARNING
"%u: %s failed\n", __LINE__
, __func__
);
418 list_for_each_entry(ptr
, &tomoyo_condition_list
, head
.list
) {
419 if (!tomoyo_same_condition(ptr
, entry
) ||
420 atomic_read(&ptr
->head
.users
) == TOMOYO_GC_IN_PROGRESS
)
422 /* Same entry found. Share this entry. */
423 atomic_inc(&ptr
->head
.users
);
428 if (tomoyo_memory_ok(entry
)) {
429 atomic_set(&entry
->head
.users
, 1);
430 list_add(&entry
->head
.list
, &tomoyo_condition_list
);
436 mutex_unlock(&tomoyo_policy_lock
);
439 tomoyo_del_condition(&entry
->head
.list
);
447 * tomoyo_get_transit_preference - Parse domain transition preference for execve().
449 * @param: Pointer to "struct tomoyo_acl_param".
450 * @e: Pointer to "struct tomoyo_condition".
452 * Returns the condition string part.
454 static char *tomoyo_get_transit_preference(struct tomoyo_acl_param
*param
,
455 struct tomoyo_condition
*e
)
457 char * const pos
= param
->data
;
461 e
->transit
= tomoyo_get_domainname(param
);
465 char *cp
= strchr(pos
, ' ');
469 flag
= tomoyo_correct_path(pos
) || !strcmp(pos
, "keep") ||
470 !strcmp(pos
, "initialize") || !strcmp(pos
, "reset") ||
471 !strcmp(pos
, "child") || !strcmp(pos
, "parent");
477 e
->transit
= tomoyo_get_name(tomoyo_read_token(param
));
482 * Return a bad read-only condition string that will let
483 * tomoyo_get_condition() return NULL.
489 * tomoyo_get_condition - Parse condition part.
491 * @param: Pointer to "struct tomoyo_acl_param".
493 * Returns pointer to "struct tomoyo_condition" on success, NULL otherwise.
495 struct tomoyo_condition
*tomoyo_get_condition(struct tomoyo_acl_param
*param
)
497 struct tomoyo_condition
*entry
= NULL
;
498 struct tomoyo_condition_element
*condp
= NULL
;
499 struct tomoyo_number_union
*numbers_p
= NULL
;
500 struct tomoyo_name_union
*names_p
= NULL
;
501 struct tomoyo_argv
*argv
= NULL
;
502 struct tomoyo_envp
*envp
= NULL
;
503 struct tomoyo_condition e
= { };
504 char * const start_of_string
=
505 tomoyo_get_transit_preference(param
, &e
);
506 char * const end_of_string
= start_of_string
+ strlen(start_of_string
);
510 pos
= start_of_string
;
514 char *left_word
= pos
;
522 * Since left-hand condition does not allow use of "path_group"
523 * or "number_group" and environment variable's names do not
524 * accept '=', it is guaranteed that the original line consists
525 * of one or more repetition of $left$operator$right blocks
526 * where "$left is free from '=' and ' '" and "$operator is
527 * either '=' or '!='" and "$right is free from ' '".
528 * Therefore, we can reconstruct the original line at the end
529 * of dry run even if we overwrite $operator with '\0'.
531 cp
= strchr(pos
, ' ');
533 *cp
= '\0'; /* Will restore later. */
538 right_word
= strchr(left_word
, '=');
539 if (!right_word
|| right_word
== left_word
)
541 is_not
= *(right_word
- 1) == '!';
543 *(right_word
++ - 1) = '\0'; /* Will restore later. */
544 else if (*(right_word
+ 1) != '=')
545 *right_word
++ = '\0'; /* Will restore later. */
548 dprintk(KERN_WARNING
"%u: <%s>%s=<%s>\n", __LINE__
, left_word
,
549 is_not
? "!" : "", right_word
);
550 if (!strcmp(left_word
, "grant_log")) {
553 entry
->grant_log
!= TOMOYO_GRANTLOG_AUTO
)
555 else if (!strcmp(right_word
, "yes"))
556 entry
->grant_log
= TOMOYO_GRANTLOG_YES
;
557 else if (!strcmp(right_word
, "no"))
558 entry
->grant_log
= TOMOYO_GRANTLOG_NO
;
564 if (!strncmp(left_word
, "exec.argv[", 10)) {
571 left
= TOMOYO_ARGV_ENTRY
;
572 argv
->is_not
= is_not
;
573 if (!tomoyo_parse_argv(left_word
+ 10,
579 if (!strncmp(left_word
, "exec.envp[\"", 11)) {
586 left
= TOMOYO_ENVP_ENTRY
;
587 envp
->is_not
= is_not
;
588 if (!tomoyo_parse_envp(left_word
+ 11,
594 left
= tomoyo_condition_type(left_word
);
595 dprintk(KERN_WARNING
"%u: <%s> left=%u\n", __LINE__
, left_word
,
597 if (left
== TOMOYO_MAX_CONDITION_KEYWORD
) {
602 left
= TOMOYO_NUMBER_UNION
;
603 param
->data
= left_word
;
604 if (*left_word
== '@' ||
605 !tomoyo_parse_number_union(param
,
614 if (left
== TOMOYO_EXEC_REALPATH
||
615 left
== TOMOYO_SYMLINK_TARGET
) {
620 right
= TOMOYO_NAME_UNION
;
621 param
->data
= right_word
;
622 if (!tomoyo_parse_name_union_quoted(param
,
628 right
= tomoyo_condition_type(right_word
);
629 if (right
== TOMOYO_MAX_CONDITION_KEYWORD
) {
634 right
= TOMOYO_NUMBER_UNION
;
635 param
->data
= right_word
;
636 if (!tomoyo_parse_number_union(param
,
643 dprintk(KERN_WARNING
"%u: dry_run left=%u right=%u match=%u\n",
644 __LINE__
, left
, right
, !is_not
);
648 condp
->right
= right
;
649 condp
->equals
= !is_not
;
650 dprintk(KERN_WARNING
"%u: left=%u right=%u match=%u\n",
651 __LINE__
, condp
->left
, condp
->right
,
655 dprintk(KERN_INFO
"%u: cond=%u numbers=%u names=%u ac=%u ec=%u\n",
656 __LINE__
, e
.condc
, e
.numbers_count
, e
.names_count
, e
.argc
,
659 BUG_ON(e
.names_count
| e
.numbers_count
| e
.argc
| e
.envc
|
661 return tomoyo_commit_condition(entry
);
663 e
.size
= sizeof(*entry
)
664 + e
.condc
* sizeof(struct tomoyo_condition_element
)
665 + e
.numbers_count
* sizeof(struct tomoyo_number_union
)
666 + e
.names_count
* sizeof(struct tomoyo_name_union
)
667 + e
.argc
* sizeof(struct tomoyo_argv
)
668 + e
.envc
* sizeof(struct tomoyo_envp
);
669 entry
= kzalloc(e
.size
, GFP_NOFS
);
674 condp
= (struct tomoyo_condition_element
*) (entry
+ 1);
675 numbers_p
= (struct tomoyo_number_union
*) (condp
+ e
.condc
);
676 names_p
= (struct tomoyo_name_union
*) (numbers_p
+ e
.numbers_count
);
677 argv
= (struct tomoyo_argv
*) (names_p
+ e
.names_count
);
678 envp
= (struct tomoyo_envp
*) (argv
+ e
.argc
);
682 for (pos
= start_of_string
; pos
< end_of_string
; pos
++) {
685 if (flag
) /* Restore " ". */
687 else if (*(pos
+ 1) == '=') /* Restore "!=". */
689 else /* Restore "=". */
696 dprintk(KERN_WARNING
"%u: %s failed\n", __LINE__
, __func__
);
698 tomoyo_del_condition(&entry
->head
.list
);
702 tomoyo_put_name(e
.transit
);
707 * tomoyo_get_attributes - Revalidate "struct inode".
709 * @obj: Pointer to "struct tomoyo_obj_info".
713 void tomoyo_get_attributes(struct tomoyo_obj_info
*obj
)
716 struct dentry
*dentry
= NULL
;
718 for (i
= 0; i
< TOMOYO_MAX_PATH_STAT
; i
++) {
723 dentry
= obj
->path1
.dentry
;
728 dentry
= obj
->path2
.dentry
;
735 dentry
= dget_parent(dentry
);
738 inode
= d_backing_inode(dentry
);
740 struct tomoyo_mini_stat
*stat
= &obj
->stat
[i
];
742 stat
->uid
= inode
->i_uid
;
743 stat
->gid
= inode
->i_gid
;
744 stat
->ino
= inode
->i_ino
;
745 stat
->mode
= inode
->i_mode
;
746 stat
->dev
= inode
->i_sb
->s_dev
;
747 stat
->rdev
= inode
->i_rdev
;
748 obj
->stat_valid
[i
] = true;
750 if (i
& 1) /* TOMOYO_PATH1_PARENT or TOMOYO_PATH2_PARENT */
756 * tomoyo_condition - Check condition part.
758 * @r: Pointer to "struct tomoyo_request_info".
759 * @cond: Pointer to "struct tomoyo_condition". Maybe NULL.
761 * Returns true on success, false otherwise.
763 * Caller holds tomoyo_read_lock().
765 bool tomoyo_condition(struct tomoyo_request_info
*r
,
766 const struct tomoyo_condition
*cond
)
769 unsigned long min_v
[2] = { 0, 0 };
770 unsigned long max_v
[2] = { 0, 0 };
771 const struct tomoyo_condition_element
*condp
;
772 const struct tomoyo_number_union
*numbers_p
;
773 const struct tomoyo_name_union
*names_p
;
774 const struct tomoyo_argv
*argv
;
775 const struct tomoyo_envp
*envp
;
776 struct tomoyo_obj_info
*obj
;
780 struct linux_binprm
*bprm
= NULL
;
790 if (!bprm
&& (argc
|| envc
))
792 condp
= (struct tomoyo_condition_element
*) (cond
+ 1);
793 numbers_p
= (const struct tomoyo_number_union
*) (condp
+ condc
);
794 names_p
= (const struct tomoyo_name_union
*)
795 (numbers_p
+ cond
->numbers_count
);
796 argv
= (const struct tomoyo_argv
*) (names_p
+ cond
->names_count
);
797 envp
= (const struct tomoyo_envp
*) (argv
+ argc
);
798 for (i
= 0; i
< condc
; i
++) {
799 const bool match
= condp
->equals
;
800 const u8 left
= condp
->left
;
801 const u8 right
= condp
->right
;
802 bool is_bitop
[2] = { false, false };
806 /* Check argv[] and envp[] later. */
807 if (left
== TOMOYO_ARGV_ENTRY
|| left
== TOMOYO_ENVP_ENTRY
)
809 /* Check string expressions. */
810 if (right
== TOMOYO_NAME_UNION
) {
811 const struct tomoyo_name_union
*ptr
= names_p
++;
812 struct tomoyo_path_info
*symlink
;
813 struct tomoyo_execve
*ee
;
817 case TOMOYO_SYMLINK_TARGET
:
818 symlink
= obj
? obj
->symlink_target
: NULL
;
820 !tomoyo_compare_name_union(symlink
, ptr
)
824 case TOMOYO_EXEC_REALPATH
:
826 file
= ee
? ee
->bprm
->file
: NULL
;
827 if (!tomoyo_scan_exec_realpath(file
, ptr
,
834 /* Check numeric or bit-op expressions. */
835 for (j
= 0; j
< 2; j
++) {
836 const u8 index
= j
? right
: left
;
837 unsigned long value
= 0;
840 case TOMOYO_TASK_UID
:
841 value
= from_kuid(&init_user_ns
, current_uid());
843 case TOMOYO_TASK_EUID
:
844 value
= from_kuid(&init_user_ns
, current_euid());
846 case TOMOYO_TASK_SUID
:
847 value
= from_kuid(&init_user_ns
, current_suid());
849 case TOMOYO_TASK_FSUID
:
850 value
= from_kuid(&init_user_ns
, current_fsuid());
852 case TOMOYO_TASK_GID
:
853 value
= from_kgid(&init_user_ns
, current_gid());
855 case TOMOYO_TASK_EGID
:
856 value
= from_kgid(&init_user_ns
, current_egid());
858 case TOMOYO_TASK_SGID
:
859 value
= from_kgid(&init_user_ns
, current_sgid());
861 case TOMOYO_TASK_FSGID
:
862 value
= from_kgid(&init_user_ns
, current_fsgid());
864 case TOMOYO_TASK_PID
:
865 value
= tomoyo_sys_getpid();
867 case TOMOYO_TASK_PPID
:
868 value
= tomoyo_sys_getppid();
870 case TOMOYO_TYPE_IS_SOCKET
:
873 case TOMOYO_TYPE_IS_SYMLINK
:
876 case TOMOYO_TYPE_IS_FILE
:
879 case TOMOYO_TYPE_IS_BLOCK_DEV
:
882 case TOMOYO_TYPE_IS_DIRECTORY
:
885 case TOMOYO_TYPE_IS_CHAR_DEV
:
888 case TOMOYO_TYPE_IS_FIFO
:
891 case TOMOYO_MODE_SETUID
:
894 case TOMOYO_MODE_SETGID
:
897 case TOMOYO_MODE_STICKY
:
900 case TOMOYO_MODE_OWNER_READ
:
903 case TOMOYO_MODE_OWNER_WRITE
:
906 case TOMOYO_MODE_OWNER_EXECUTE
:
909 case TOMOYO_MODE_GROUP_READ
:
912 case TOMOYO_MODE_GROUP_WRITE
:
915 case TOMOYO_MODE_GROUP_EXECUTE
:
918 case TOMOYO_MODE_OTHERS_READ
:
921 case TOMOYO_MODE_OTHERS_WRITE
:
924 case TOMOYO_MODE_OTHERS_EXECUTE
:
927 case TOMOYO_EXEC_ARGC
:
932 case TOMOYO_EXEC_ENVC
:
937 case TOMOYO_NUMBER_UNION
:
938 /* Fetch values later. */
943 if (!obj
->validate_done
) {
944 tomoyo_get_attributes(obj
);
945 obj
->validate_done
= true;
949 struct tomoyo_mini_stat
*stat
;
952 case TOMOYO_PATH1_UID
:
953 case TOMOYO_PATH1_GID
:
954 case TOMOYO_PATH1_INO
:
955 case TOMOYO_PATH1_MAJOR
:
956 case TOMOYO_PATH1_MINOR
:
957 case TOMOYO_PATH1_TYPE
:
958 case TOMOYO_PATH1_DEV_MAJOR
:
959 case TOMOYO_PATH1_DEV_MINOR
:
960 case TOMOYO_PATH1_PERM
:
961 stat_index
= TOMOYO_PATH1
;
963 case TOMOYO_PATH2_UID
:
964 case TOMOYO_PATH2_GID
:
965 case TOMOYO_PATH2_INO
:
966 case TOMOYO_PATH2_MAJOR
:
967 case TOMOYO_PATH2_MINOR
:
968 case TOMOYO_PATH2_TYPE
:
969 case TOMOYO_PATH2_DEV_MAJOR
:
970 case TOMOYO_PATH2_DEV_MINOR
:
971 case TOMOYO_PATH2_PERM
:
972 stat_index
= TOMOYO_PATH2
;
974 case TOMOYO_PATH1_PARENT_UID
:
975 case TOMOYO_PATH1_PARENT_GID
:
976 case TOMOYO_PATH1_PARENT_INO
:
977 case TOMOYO_PATH1_PARENT_PERM
:
981 case TOMOYO_PATH2_PARENT_UID
:
982 case TOMOYO_PATH2_PARENT_GID
:
983 case TOMOYO_PATH2_PARENT_INO
:
984 case TOMOYO_PATH2_PARENT_PERM
:
991 if (!obj
->stat_valid
[stat_index
])
993 stat
= &obj
->stat
[stat_index
];
995 case TOMOYO_PATH1_UID
:
996 case TOMOYO_PATH2_UID
:
997 case TOMOYO_PATH1_PARENT_UID
:
998 case TOMOYO_PATH2_PARENT_UID
:
999 value
= from_kuid(&init_user_ns
, stat
->uid
);
1001 case TOMOYO_PATH1_GID
:
1002 case TOMOYO_PATH2_GID
:
1003 case TOMOYO_PATH1_PARENT_GID
:
1004 case TOMOYO_PATH2_PARENT_GID
:
1005 value
= from_kgid(&init_user_ns
, stat
->gid
);
1007 case TOMOYO_PATH1_INO
:
1008 case TOMOYO_PATH2_INO
:
1009 case TOMOYO_PATH1_PARENT_INO
:
1010 case TOMOYO_PATH2_PARENT_INO
:
1013 case TOMOYO_PATH1_MAJOR
:
1014 case TOMOYO_PATH2_MAJOR
:
1015 value
= MAJOR(stat
->dev
);
1017 case TOMOYO_PATH1_MINOR
:
1018 case TOMOYO_PATH2_MINOR
:
1019 value
= MINOR(stat
->dev
);
1021 case TOMOYO_PATH1_TYPE
:
1022 case TOMOYO_PATH2_TYPE
:
1023 value
= stat
->mode
& S_IFMT
;
1025 case TOMOYO_PATH1_DEV_MAJOR
:
1026 case TOMOYO_PATH2_DEV_MAJOR
:
1027 value
= MAJOR(stat
->rdev
);
1029 case TOMOYO_PATH1_DEV_MINOR
:
1030 case TOMOYO_PATH2_DEV_MINOR
:
1031 value
= MINOR(stat
->rdev
);
1033 case TOMOYO_PATH1_PERM
:
1034 case TOMOYO_PATH2_PERM
:
1035 case TOMOYO_PATH1_PARENT_PERM
:
1036 case TOMOYO_PATH2_PARENT_PERM
:
1037 value
= stat
->mode
& S_IALLUGO
;
1046 case TOMOYO_MODE_SETUID
:
1047 case TOMOYO_MODE_SETGID
:
1048 case TOMOYO_MODE_STICKY
:
1049 case TOMOYO_MODE_OWNER_READ
:
1050 case TOMOYO_MODE_OWNER_WRITE
:
1051 case TOMOYO_MODE_OWNER_EXECUTE
:
1052 case TOMOYO_MODE_GROUP_READ
:
1053 case TOMOYO_MODE_GROUP_WRITE
:
1054 case TOMOYO_MODE_GROUP_EXECUTE
:
1055 case TOMOYO_MODE_OTHERS_READ
:
1056 case TOMOYO_MODE_OTHERS_WRITE
:
1057 case TOMOYO_MODE_OTHERS_EXECUTE
:
1061 if (left
== TOMOYO_NUMBER_UNION
) {
1062 /* Fetch values now. */
1063 const struct tomoyo_number_union
*ptr
= numbers_p
++;
1065 min_v
[0] = ptr
->values
[0];
1066 max_v
[0] = ptr
->values
[1];
1068 if (right
== TOMOYO_NUMBER_UNION
) {
1069 /* Fetch values now. */
1070 const struct tomoyo_number_union
*ptr
= numbers_p
++;
1073 if (tomoyo_number_matches_group(min_v
[0],
1079 if ((min_v
[0] <= ptr
->values
[1] &&
1080 max_v
[0] >= ptr
->values
[0]) == match
)
1086 * Bit operation is valid only when counterpart value
1087 * represents permission.
1089 if (is_bitop
[0] && is_bitop
[1]) {
1091 } else if (is_bitop
[0]) {
1093 case TOMOYO_PATH1_PERM
:
1094 case TOMOYO_PATH1_PARENT_PERM
:
1095 case TOMOYO_PATH2_PERM
:
1096 case TOMOYO_PATH2_PARENT_PERM
:
1097 if (!(max_v
[0] & max_v
[1]) == !match
)
1101 } else if (is_bitop
[1]) {
1103 case TOMOYO_PATH1_PERM
:
1104 case TOMOYO_PATH1_PARENT_PERM
:
1105 case TOMOYO_PATH2_PERM
:
1106 case TOMOYO_PATH2_PARENT_PERM
:
1107 if (!(max_v
[0] & max_v
[1]) == !match
)
1112 /* Normal value range comparison. */
1113 if ((min_v
[0] <= max_v
[1] && max_v
[0] >= min_v
[1]) == match
)
1118 /* Check argv[] and envp[] now. */
1119 if (r
->ee
&& (argc
|| envc
))
1120 return tomoyo_scan_bprm(r
->ee
, argc
, argv
, envc
, envp
);