diff options
author | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2011-09-10 02:22:48 -0400 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2011-09-13 18:27:05 -0400 |
commit | d58e0da854376841ac99defeb117a83f086715c6 (patch) | |
tree | b6e37d1030180680a7801ecb295d8d3990930375 /security/tomoyo/common.c | |
parent | 5dbe3040c74eef18e66951347eda05b153e69328 (diff) |
TOMOYO: Add environment variable name restriction support.
This patch adds support for checking environment variable's names.
Although TOMOYO already provides ability to check argv[]/envp[] passed to
execve() requests,
file execute /bin/sh exec.envp["LD_LIBRARY_PATH"]="bar"
will reject execution of /bin/sh if environment variable LD_LIBRARY_PATH is not
defined. To grant execution of /bin/sh if LD_LIBRARY_PATH is not defined,
administrators have to specify like
file execute /bin/sh exec.envp["LD_LIBRARY_PATH"]="/system/lib"
file execute /bin/sh exec.envp["LD_LIBRARY_PATH"]=NULL
. Since there are many environment variables whereas conditional checks are
applied as "&&", it is difficult to cover all combinations. Therefore, this
patch supports conditional checks that are applied as "||", by specifying like
file execute /bin/sh
misc env LD_LIBRARY_PATH exec.envp["LD_LIBRARY_PATH"]="/system/lib"
which means "grant execution of /bin/sh if environment variable is not defined
or is defined and its value is /system/lib".
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security/tomoyo/common.c')
-rw-r--r-- | security/tomoyo/common.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c index c8439cf2a448..d116e1ece3e6 100644 --- a/security/tomoyo/common.c +++ b/security/tomoyo/common.c | |||
@@ -20,6 +20,7 @@ const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE] = { | |||
20 | /* String table for /sys/kernel/security/tomoyo/profile */ | 20 | /* String table for /sys/kernel/security/tomoyo/profile */ |
21 | const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX | 21 | const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX |
22 | + TOMOYO_MAX_MAC_CATEGORY_INDEX] = { | 22 | + TOMOYO_MAX_MAC_CATEGORY_INDEX] = { |
23 | /* CONFIG::file group */ | ||
23 | [TOMOYO_MAC_FILE_EXECUTE] = "execute", | 24 | [TOMOYO_MAC_FILE_EXECUTE] = "execute", |
24 | [TOMOYO_MAC_FILE_OPEN] = "open", | 25 | [TOMOYO_MAC_FILE_OPEN] = "open", |
25 | [TOMOYO_MAC_FILE_CREATE] = "create", | 26 | [TOMOYO_MAC_FILE_CREATE] = "create", |
@@ -43,7 +44,11 @@ const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX | |||
43 | [TOMOYO_MAC_FILE_MOUNT] = "mount", | 44 | [TOMOYO_MAC_FILE_MOUNT] = "mount", |
44 | [TOMOYO_MAC_FILE_UMOUNT] = "unmount", | 45 | [TOMOYO_MAC_FILE_UMOUNT] = "unmount", |
45 | [TOMOYO_MAC_FILE_PIVOT_ROOT] = "pivot_root", | 46 | [TOMOYO_MAC_FILE_PIVOT_ROOT] = "pivot_root", |
47 | /* CONFIG::misc group */ | ||
48 | [TOMOYO_MAC_ENVIRON] = "env", | ||
49 | /* CONFIG group */ | ||
46 | [TOMOYO_MAX_MAC_INDEX + TOMOYO_MAC_CATEGORY_FILE] = "file", | 50 | [TOMOYO_MAX_MAC_INDEX + TOMOYO_MAC_CATEGORY_FILE] = "file", |
51 | [TOMOYO_MAX_MAC_INDEX + TOMOYO_MAC_CATEGORY_MISC] = "misc", | ||
47 | }; | 52 | }; |
48 | 53 | ||
49 | /* String table for conditions. */ | 54 | /* String table for conditions. */ |
@@ -133,7 +138,8 @@ const char * const tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION] = { | |||
133 | /* String table for categories. */ | 138 | /* String table for categories. */ |
134 | static const char * const tomoyo_category_keywords | 139 | static const char * const tomoyo_category_keywords |
135 | [TOMOYO_MAX_MAC_CATEGORY_INDEX] = { | 140 | [TOMOYO_MAX_MAC_CATEGORY_INDEX] = { |
136 | [TOMOYO_MAC_CATEGORY_FILE] = "file", | 141 | [TOMOYO_MAC_CATEGORY_FILE] = "file", |
142 | [TOMOYO_MAC_CATEGORY_MISC] = "misc", | ||
137 | }; | 143 | }; |
138 | 144 | ||
139 | /* Permit policy management by non-root user? */ | 145 | /* Permit policy management by non-root user? */ |
@@ -1036,11 +1042,13 @@ static int tomoyo_write_domain2(struct tomoyo_policy_namespace *ns, | |||
1036 | static const struct { | 1042 | static const struct { |
1037 | const char *keyword; | 1043 | const char *keyword; |
1038 | int (*write) (struct tomoyo_acl_param *); | 1044 | int (*write) (struct tomoyo_acl_param *); |
1039 | } tomoyo_callback[1] = { | 1045 | } tomoyo_callback[2] = { |
1040 | { "file ", tomoyo_write_file }, | 1046 | { "file ", tomoyo_write_file }, |
1047 | { "misc ", tomoyo_write_misc }, | ||
1041 | }; | 1048 | }; |
1042 | u8 i; | 1049 | u8 i; |
1043 | for (i = 0; i < 1; i++) { | 1050 | |
1051 | for (i = 0; i < ARRAY_SIZE(tomoyo_callback); i++) { | ||
1044 | if (!tomoyo_str_starts(¶m.data, | 1052 | if (!tomoyo_str_starts(¶m.data, |
1045 | tomoyo_callback[i].keyword)) | 1053 | tomoyo_callback[i].keyword)) |
1046 | continue; | 1054 | continue; |
@@ -1375,6 +1383,12 @@ static bool tomoyo_print_entry(struct tomoyo_io_buffer *head, | |||
1375 | tomoyo_print_name_union(head, &ptr->dir_name); | 1383 | tomoyo_print_name_union(head, &ptr->dir_name); |
1376 | tomoyo_print_name_union(head, &ptr->fs_type); | 1384 | tomoyo_print_name_union(head, &ptr->fs_type); |
1377 | tomoyo_print_number_union(head, &ptr->flags); | 1385 | tomoyo_print_number_union(head, &ptr->flags); |
1386 | } else if (acl_type == TOMOYO_TYPE_ENV_ACL) { | ||
1387 | struct tomoyo_env_acl *ptr = | ||
1388 | container_of(acl, typeof(*ptr), head); | ||
1389 | |||
1390 | tomoyo_set_group(head, "misc env "); | ||
1391 | tomoyo_set_string(head, ptr->env->name); | ||
1378 | } | 1392 | } |
1379 | if (acl->cond) { | 1393 | if (acl->cond) { |
1380 | head->r.print_cond_part = true; | 1394 | head->r.print_cond_part = true; |