Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

Contents of /trunk/1.6.x/ccs-patch/fs/tomoyo_exec.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1135 - (show annotations) (download) (as text)
Thu Apr 24 07:34:11 2008 UTC (16 years, 1 month ago) by kumaneko
File MIME type: text/x-csrc
File size: 6037 byte(s)


1 /*
2 * fs/tomoyo_exec.c
3 *
4 * Implementation of the Domain-Based Mandatory Access Control.
5 *
6 * Copyright (C) 2005-2008 NTT DATA CORPORATION
7 *
8 * Version: 1.6.1-rc 2008/04/24
9 *
10 * This file is applicable to both 2.4.30 and 2.6.11 and later.
11 * See README.ccs for ChangeLog.
12 *
13 */
14
15 #include <linux/ccs_common.h>
16 #include <linux/tomoyo.h>
17 #include <linux/realpath.h>
18
19 /**
20 * audit_argv0_log - Audit argv[0] log.
21 *
22 * @filename: The fullpath of program.
23 * @argv0: The basename of argv[0].
24 * @is_granted: True if this is a granted log.
25 * @profile: Profile number used.
26 * @mode: Access control mode used.
27 *
28 * Returns 0 on success, negative value otherwise.
29 */
30 static int audit_argv0_log(const struct path_info *filename, const char *argv0,
31 const bool is_granted, const u8 profile,
32 const u8 mode)
33 {
34 char *buf;
35 int len;
36 int len2;
37 if (ccs_can_save_audit_log(is_granted) < 0)
38 return -ENOMEM;
39 len = filename->total_len + strlen(argv0) + 64;
40 buf = ccs_init_audit_log(&len, profile, mode, NULL);
41 if (!buf)
42 return -ENOMEM;
43 len2 = strlen(buf);
44 snprintf(buf + len2, len - len2 - 1,
45 KEYWORD_ALLOW_ARGV0 "%s %s\n", filename->name, argv0);
46 return ccs_write_audit_log(buf, is_granted);
47 }
48
49 /**
50 * update_argv0_entry - Update "struct argv0_acl_record" list.
51 *
52 * @filename: The fullpath of the program.
53 * @argv0: The basename of argv[0].
54 * @domain: Pointer to "struct domain_info".
55 * @condition: Pointer to "struct condition_list". May be NULL.
56 * @is_delete: True if it is a delete request.
57 *
58 * Returns 0 on success, negative value otherwise.
59 */
60 static int update_argv0_entry(const char *filename, const char *argv0,
61 struct domain_info *domain,
62 const struct condition_list *condition,
63 const bool is_delete)
64 {
65 struct acl_info *ptr;
66 struct argv0_acl_record *acl;
67 const struct path_info *saved_filename;
68 const struct path_info *saved_argv0;
69 int error = -ENOMEM;
70 if (!ccs_is_correct_path(filename, 1, 0, -1, __func__) ||
71 !ccs_is_correct_path(argv0, -1, 0, -1, __func__) ||
72 strchr(argv0, '/'))
73 return -EINVAL;
74 saved_filename = ccs_save_name(filename);
75 saved_argv0 = ccs_save_name(argv0);
76 if (!saved_filename || !saved_argv0)
77 return -ENOMEM;
78 mutex_lock(&domain_acl_lock);
79 if (is_delete)
80 goto delete;
81 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
82 if (ccs_acl_type1(ptr) != TYPE_ARGV0_ACL)
83 continue;
84 if (ccs_get_condition_part(ptr) != condition)
85 continue;
86 acl = container_of(ptr, struct argv0_acl_record, head);
87 if (acl->filename != saved_filename ||
88 acl->argv0 != saved_argv0)
89 continue;
90 error = ccs_add_domain_acl(NULL, ptr);
91 goto out;
92 }
93 /* Not found. Append it to the tail. */
94 acl = ccs_alloc_acl_element(TYPE_ARGV0_ACL, condition);
95 if (!acl)
96 goto out;
97 acl->filename = saved_filename;
98 acl->argv0 = saved_argv0;
99 error = ccs_add_domain_acl(domain, &acl->head);
100 goto out;
101 delete:
102 error = -ENOENT;
103 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
104 if (ccs_acl_type2(ptr) != TYPE_ARGV0_ACL)
105 continue;
106 if (ccs_get_condition_part(ptr) != condition)
107 continue;
108 acl = container_of(ptr, struct argv0_acl_record, head);
109 if (acl->filename != saved_filename ||
110 acl->argv0 != saved_argv0)
111 continue;
112 error = ccs_del_domain_acl(ptr);
113 break;
114 }
115 out:
116 mutex_unlock(&domain_acl_lock);
117 return error;
118 }
119
120 /**
121 * check_argv0_acl - Check permission for argv[0].
122 *
123 * @filename: The fullpath of the program.
124 * @argv0: The basename of argv[0].
125 *
126 * Returns 0 on success, -EPERM otherwise.
127 */
128 static int check_argv0_acl(const struct path_info *filename, const char *argv0)
129 {
130 const struct domain_info *domain = current->domain_info;
131 int error = -EPERM;
132 struct acl_info *ptr;
133 struct path_info argv_0;
134 argv_0.name = argv0;
135 ccs_fill_path_info(&argv_0);
136 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
137 struct argv0_acl_record *acl;
138 if (ccs_acl_type2(ptr) != TYPE_ARGV0_ACL)
139 continue;
140 acl = container_of(ptr, struct argv0_acl_record, head);
141 if (!ccs_check_condition(ptr, NULL) ||
142 !ccs_path_matches_pattern(filename, acl->filename) ||
143 !ccs_path_matches_pattern(&argv_0, acl->argv0))
144 continue;
145 ccs_update_condition(ptr);
146 error = 0;
147 break;
148 }
149 return error;
150 }
151
152 /**
153 * ccs_check_argv0_perm - Check permission for argv[0].
154 *
155 * @filename: The fullpath of the program.
156 * @argv0: The basename of argv[0].
157 *
158 * Returns 0 on success, negative value otherwise.
159 */
160 int ccs_check_argv0_perm(const struct path_info *filename, const char *argv0)
161 {
162 int error = 0;
163 struct domain_info * const domain = current->domain_info;
164 const u8 profile = domain->profile;
165 const u8 mode = ccs_check_flags(CCS_TOMOYO_MAC_FOR_ARGV0);
166 const bool is_enforce = (mode == 3);
167 if (!filename || !argv0 || !*argv0)
168 return 0;
169 error = check_argv0_acl(filename, argv0);
170 audit_argv0_log(filename, argv0, !error, profile, mode);
171 if (!error)
172 return 0;
173 if (ccs_verbose_mode())
174 printk(KERN_WARNING "TOMOYO-%s: Run %s as %s denied for %s\n",
175 ccs_get_msg(is_enforce), filename->name, argv0,
176 ccs_get_last_name(domain));
177 if (is_enforce)
178 return ccs_check_supervisor("%s\n"
179 KEYWORD_ALLOW_ARGV0 "%s %s\n",
180 domain->domainname->name,
181 filename->name, argv0);
182 if (mode == 1 && ccs_check_domain_quota(domain))
183 update_argv0_entry(filename->name, argv0, domain, NULL, false);
184 return 0;
185 }
186
187 /**
188 * ccs_write_argv0_policy - Write "struct argv0_acl_record" list.
189 *
190 * @data: String to parse.
191 * @domain: Pointer to "struct domain_info".
192 * @condition: Pointer to "struct condition_list". May be NULL.
193 * @is_delete: True if it is a delete request.
194 *
195 * Returns 0 on success, negative value otherwise.
196 */
197 int ccs_write_argv0_policy(char *data, struct domain_info *domain,
198 const struct condition_list *condition,
199 const bool is_delete)
200 {
201 char *argv0 = strchr(data, ' ');
202 if (!argv0)
203 return -EINVAL;
204 *argv0++ = '\0';
205 return update_argv0_entry(data, argv0, domain, condition, is_delete);
206 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26