8 #include <linux/slab.h>
31 for (i = 0; i <
argc; argv++, checked++, i++) {
33 if (index != argv->
index)
57 static bool tomoyo_envp(
const char *env_name,
const char *env_value,
66 value.name = env_value;
68 for (i = 0; i < envc; envp++, checked++, i++) {
106 char *arg_ptr = ee->
tmp;
108 unsigned long pos = bprm->
p;
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) {
131 const char *kaddr = dump->
data;
132 const unsigned char c = kaddr[offset++];
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';
160 }
else if (envp_count) {
185 for (i = 0; i <
argc; i++) {
197 for (i = 0; i < envc; envp++, i++) {
198 if (checked[argc + i])
211 if (checked != local_checked)
225 static bool tomoyo_scan_exec_realpath(
struct file *
file,
239 return result ==
match;
251 char *cp = start +
strlen(start) - 1;
252 if (cp == start || *start++ !=
'"' || *cp !=
'"')
272 if (*filename ==
'@')
274 ptr->
filename = tomoyo_get_dqword(filename);
287 static bool tomoyo_parse_argv(
char *
left,
char *
right,
293 argv->
value = tomoyo_get_dqword(right);
306 static bool tomoyo_parse_envp(
char *left,
char *right,
311 char *cp = left +
strlen(left) - 1;
312 if (*cp-- !=
']' || *cp !=
'"')
320 if (!
strcmp(right,
"NULL")) {
323 value = tomoyo_get_dqword(right);
325 tomoyo_put_name(name);
363 static u8 tomoyo_condition_type(
const char *
word)
376 #ifdef DEBUG_CONDITION
377 #define dprintk printk
379 #define dprintk(...) do { } while (0)
404 if (!tomoyo_same_condition(ptr, entry) ||
442 char *
const pos = param->
data;
449 char *cp =
strchr(pos,
' ');
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;
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';
525 else if (*(right_word + 1) !=
'=')
526 *right_word++ =
'\0';
530 is_not ?
"!" :
"", right_word);
531 if (!
strcmp(left_word,
"grant_log")) {
536 else if (!
strcmp(right_word,
"yes"))
538 else if (!
strcmp(right_word,
"no"))
545 if (!
strncmp(left_word,
"exec.argv[", 10)) {
554 if (!tomoyo_parse_argv(left_word + 10,
560 if (!
strncmp(left_word,
"exec.envp[\"", 11)) {
569 if (!tomoyo_parse_envp(left_word + 11,
575 left = tomoyo_condition_type(left_word);
578 if (left == TOMOYO_MAX_CONDITION_KEYWORD) {
584 param->
data = left_word;
585 if (*left_word ==
'@' ||
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) {
616 param->
data = right_word;
625 "match=%u\n", __LINE__, left, right, !is_not);
642 return tomoyo_commit_condition(entry);
644 e.
size =
sizeof(*entry)
658 argv = (
struct tomoyo_argv *) (names_p + e.names_count);
662 for (pos = start_of_string; pos < end_of_string; pos++) {
667 else if (*(pos + 1) ==
'=')
682 tomoyo_put_name(e.transit);
702 dentry = obj->
path1.dentry;
707 dentry = obj->
path2.dentry;
724 stat->
dev = inode->
i_sb->s_dev;
748 unsigned long min_v[2] = { 0, 0 };
749 unsigned long max_v[2] = { 0, 0 };
768 if (!bprm && (argc || envc))
776 for (i = 0; i < condc; i++) {
777 const bool match = condp->
equals;
778 const u8 left = condp->
left;
780 bool is_bitop[2] = {
false,
false };
803 if (!tomoyo_scan_exec_realpath(file, ptr,
811 for (j = 0; j < 2; j++) {
812 const u8 index = j ? right :
left;
813 unsigned long value = 0;
840 value = tomoyo_sys_getpid();
843 value = tomoyo_sys_getppid();
967 stat = &obj->
stat[stat_index];
1038 min_v[0] = ptr->
values[0];
1039 max_v[0] = ptr->
values[1];
1051 if ((min_v[0] <= ptr->
values[1] &&
1052 max_v[0] >= ptr->
values[0]) == match)
1061 if (is_bitop[0] && is_bitop[1]) {
1063 }
else if (is_bitop[0]) {
1069 if (!(max_v[0] & max_v[1]) == !match)
1073 }
else if (is_bitop[1]) {
1079 if (!(max_v[0] & max_v[1]) == !match)
1085 if ((min_v[0] <= max_v[1] && max_v[0] >= min_v[1]) == match)
1091 if (r->
ee && (argc || envc))
1092 return tomoyo_scan_bprm(r->
ee, argc, argv, envc, envp);