hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/security/tomoyo/condition.c
....@@ -28,9 +28,11 @@
2828 {
2929 int i;
3030 struct tomoyo_path_info arg;
31
+
3132 arg.name = arg_ptr;
3233 for (i = 0; i < argc; argv++, checked++, i++) {
3334 bool result;
35
+
3436 if (index != argv->index)
3537 continue;
3638 *checked = 1;
....@@ -62,12 +64,14 @@
6264 int i;
6365 struct tomoyo_path_info name;
6466 struct tomoyo_path_info value;
67
+
6568 name.name = env_name;
6669 tomoyo_fill_path_info(&name);
6770 value.name = env_value;
6871 tomoyo_fill_path_info(&value);
6972 for (i = 0; i < envc; envp++, checked++, i++) {
7073 bool result;
74
+
7175 if (!tomoyo_path_matches_pattern(&name, envp->name))
7276 continue;
7377 *checked = 1;
....@@ -113,6 +117,7 @@
113117 bool result = true;
114118 u8 local_checked[32];
115119 u8 *checked;
120
+
116121 if (argc + envc <= sizeof(local_checked)) {
117122 checked = local_checked;
118123 memset(local_checked, 0, sizeof(local_checked));
....@@ -131,6 +136,7 @@
131136 /* Read. */
132137 const char *kaddr = dump->data;
133138 const unsigned char c = kaddr[offset++];
139
+
134140 if (c && arg_len < TOMOYO_EXEC_TMPSIZE - 10) {
135141 if (c == '\\') {
136142 arg_ptr[arg_len++] = '\\';
....@@ -160,6 +166,7 @@
160166 argv_count--;
161167 } else if (envp_count) {
162168 char *cp = strchr(arg_ptr, '=');
169
+
163170 if (cp) {
164171 *cp = '\0';
165172 if (!tomoyo_envp(arg_ptr, cp + 1,
....@@ -182,6 +189,7 @@
182189 out:
183190 if (result) {
184191 int i;
192
+
185193 /* Check not-yet-checked entries. */
186194 for (i = 0; i < argc; i++) {
187195 if (checked[i])
....@@ -229,6 +237,7 @@
229237 {
230238 bool result;
231239 struct tomoyo_path_info exe;
240
+
232241 if (!file)
233242 return false;
234243 exe.name = tomoyo_realpath_from_path(&file->f_path);
....@@ -250,6 +259,7 @@
250259 static const struct tomoyo_path_info *tomoyo_get_dqword(char *start)
251260 {
252261 char *cp = start + strlen(start) - 1;
262
+
253263 if (cp == start || *start++ != '"' || *cp != '"')
254264 return NULL;
255265 *cp = '\0';
....@@ -270,6 +280,7 @@
270280 struct tomoyo_name_union *ptr)
271281 {
272282 char *filename = param->data;
283
+
273284 if (*filename == '@')
274285 return tomoyo_parse_name_union(param, ptr);
275286 ptr->filename = tomoyo_get_dqword(filename);
....@@ -310,6 +321,7 @@
310321 const struct tomoyo_path_info *name;
311322 const struct tomoyo_path_info *value;
312323 char *cp = left + strlen(left) - 1;
324
+
313325 if (*cp-- != ']' || *cp != '"')
314326 goto out;
315327 *cp = '\0';
....@@ -364,6 +376,7 @@
364376 static u8 tomoyo_condition_type(const char *word)
365377 {
366378 u8 i;
379
+
367380 for (i = 0; i < TOMOYO_MAX_CONDITION_KEYWORD; i++) {
368381 if (!strcmp(word, tomoyo_condition_keyword[i]))
369382 break;
....@@ -395,6 +408,7 @@
395408 {
396409 struct tomoyo_condition *ptr;
397410 bool found = false;
411
+
398412 if (mutex_lock_interruptible(&tomoyo_policy_lock)) {
399413 dprintk(KERN_WARNING "%u: %s failed\n", __LINE__, __func__);
400414 ptr = NULL;
....@@ -442,12 +456,14 @@
442456 {
443457 char * const pos = param->data;
444458 bool flag;
459
+
445460 if (*pos == '<') {
446461 e->transit = tomoyo_get_domainname(param);
447462 goto done;
448463 }
449464 {
450465 char *cp = strchr(pos, ' ');
466
+
451467 if (cp)
452468 *cp = '\0';
453469 flag = tomoyo_correct_path(pos) || !strcmp(pos, "keep") ||
....@@ -489,6 +505,7 @@
489505 tomoyo_get_transit_preference(param, &e);
490506 char * const end_of_string = start_of_string + strlen(start_of_string);
491507 char *pos;
508
+
492509 rerun:
493510 pos = start_of_string;
494511 while (1) {
....@@ -498,6 +515,7 @@
498515 char *cp;
499516 char *right_word;
500517 bool is_not;
518
+
501519 if (!*left_word)
502520 break;
503521 /*
....@@ -622,8 +640,8 @@
622640 }
623641 store_value:
624642 if (!condp) {
625
- dprintk(KERN_WARNING "%u: dry_run left=%u right=%u "
626
- "match=%u\n", __LINE__, left, right, !is_not);
643
+ dprintk(KERN_WARNING "%u: dry_run left=%u right=%u match=%u\n",
644
+ __LINE__, left, right, !is_not);
627645 continue;
628646 }
629647 condp->left = left;
....@@ -660,6 +678,7 @@
660678 envp = (struct tomoyo_envp *) (argv + e.argc);
661679 {
662680 bool flag = false;
681
+
663682 for (pos = start_of_string; pos < end_of_string; pos++) {
664683 if (*pos)
665684 continue;
....@@ -698,6 +717,7 @@
698717
699718 for (i = 0; i < TOMOYO_MAX_PATH_STAT; i++) {
700719 struct inode *inode;
720
+
701721 switch (i) {
702722 case TOMOYO_PATH1:
703723 dentry = obj->path1.dentry;
....@@ -718,6 +738,7 @@
718738 inode = d_backing_inode(dentry);
719739 if (inode) {
720740 struct tomoyo_mini_stat *stat = &obj->stat[i];
741
+
721742 stat->uid = inode->i_uid;
722743 stat->gid = inode->i_gid;
723744 stat->ino = inode->i_ino;
....@@ -726,8 +747,7 @@
726747 stat->rdev = inode->i_rdev;
727748 obj->stat_valid[i] = true;
728749 }
729
- if (i & 1) /* i == TOMOYO_PATH1_PARENT ||
730
- i == TOMOYO_PATH2_PARENT */
750
+ if (i & 1) /* TOMOYO_PATH1_PARENT or TOMOYO_PATH2_PARENT */
731751 dput(dentry);
732752 }
733753 }
....@@ -758,6 +778,7 @@
758778 u16 argc;
759779 u16 envc;
760780 struct linux_binprm *bprm = NULL;
781
+
761782 if (!cond)
762783 return true;
763784 condc = cond->condc;
....@@ -780,6 +801,7 @@
780801 const u8 right = condp->right;
781802 bool is_bitop[2] = { false, false };
782803 u8 j;
804
+
783805 condp++;
784806 /* Check argv[] and envp[] later. */
785807 if (left == TOMOYO_ARGV_ENTRY || left == TOMOYO_ENVP_ENTRY)
....@@ -787,10 +809,11 @@
787809 /* Check string expressions. */
788810 if (right == TOMOYO_NAME_UNION) {
789811 const struct tomoyo_name_union *ptr = names_p++;
812
+ struct tomoyo_path_info *symlink;
813
+ struct tomoyo_execve *ee;
814
+ struct file *file;
815
+
790816 switch (left) {
791
- struct tomoyo_path_info *symlink;
792
- struct tomoyo_execve *ee;
793
- struct file *file;
794817 case TOMOYO_SYMLINK_TARGET:
795818 symlink = obj ? obj->symlink_target : NULL;
796819 if (!symlink ||
....@@ -812,6 +835,7 @@
812835 for (j = 0; j < 2; j++) {
813836 const u8 index = j ? right : left;
814837 unsigned long value = 0;
838
+
815839 switch (index) {
816840 case TOMOYO_TASK_UID:
817841 value = from_kuid(&init_user_ns, current_uid());
....@@ -874,31 +898,31 @@
874898 value = S_ISVTX;
875899 break;
876900 case TOMOYO_MODE_OWNER_READ:
877
- value = S_IRUSR;
901
+ value = 0400;
878902 break;
879903 case TOMOYO_MODE_OWNER_WRITE:
880
- value = S_IWUSR;
904
+ value = 0200;
881905 break;
882906 case TOMOYO_MODE_OWNER_EXECUTE:
883
- value = S_IXUSR;
907
+ value = 0100;
884908 break;
885909 case TOMOYO_MODE_GROUP_READ:
886
- value = S_IRGRP;
910
+ value = 0040;
887911 break;
888912 case TOMOYO_MODE_GROUP_WRITE:
889
- value = S_IWGRP;
913
+ value = 0020;
890914 break;
891915 case TOMOYO_MODE_GROUP_EXECUTE:
892
- value = S_IXGRP;
916
+ value = 0010;
893917 break;
894918 case TOMOYO_MODE_OTHERS_READ:
895
- value = S_IROTH;
919
+ value = 0004;
896920 break;
897921 case TOMOYO_MODE_OTHERS_WRITE:
898
- value = S_IWOTH;
922
+ value = 0002;
899923 break;
900924 case TOMOYO_MODE_OTHERS_EXECUTE:
901
- value = S_IXOTH;
925
+ value = 0001;
902926 break;
903927 case TOMOYO_EXEC_ARGC:
904928 if (!bprm)
....@@ -923,6 +947,7 @@
923947 {
924948 u8 stat_index;
925949 struct tomoyo_mini_stat *stat;
950
+
926951 switch (index) {
927952 case TOMOYO_PATH1_UID:
928953 case TOMOYO_PATH1_GID:
....@@ -1036,12 +1061,14 @@
10361061 if (left == TOMOYO_NUMBER_UNION) {
10371062 /* Fetch values now. */
10381063 const struct tomoyo_number_union *ptr = numbers_p++;
1064
+
10391065 min_v[0] = ptr->values[0];
10401066 max_v[0] = ptr->values[1];
10411067 }
10421068 if (right == TOMOYO_NUMBER_UNION) {
10431069 /* Fetch values now. */
10441070 const struct tomoyo_number_union *ptr = numbers_p++;
1071
+
10451072 if (ptr->group) {
10461073 if (tomoyo_number_matches_group(min_v[0],
10471074 max_v[0],