blob: f7877fa80f1481c34878d19c7a4cbd4a384d840e [file] [log] [blame]
Kentaro Takedab69a54e2009-02-05 17:18:14 +09001/*
2 * security/tomoyo/file.c
3 *
Tetsuo Handac3ef1502010-05-17 10:12:46 +09004 * Pathname restriction functions.
Kentaro Takedab69a54e2009-02-05 17:18:14 +09005 *
Tetsuo Handac3ef1502010-05-17 10:12:46 +09006 * Copyright (C) 2005-2010 NTT DATA CORPORATION
Kentaro Takedab69a54e2009-02-05 17:18:14 +09007 */
8
9#include "common.h"
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Kentaro Takedab69a54e2009-02-05 17:18:14 +090011
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +090012/* Keyword array for operations with one pathname. */
Tetsuo Handa71c28232010-06-16 16:26:38 +090013const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION] = {
Tetsuo Handa7ef61232010-02-16 08:03:30 +090014 [TOMOYO_TYPE_READ_WRITE] = "read/write",
15 [TOMOYO_TYPE_EXECUTE] = "execute",
16 [TOMOYO_TYPE_READ] = "read",
17 [TOMOYO_TYPE_WRITE] = "write",
Tetsuo Handa7ef61232010-02-16 08:03:30 +090018 [TOMOYO_TYPE_UNLINK] = "unlink",
Tetsuo Handa7ef61232010-02-16 08:03:30 +090019 [TOMOYO_TYPE_RMDIR] = "rmdir",
Tetsuo Handa7ef61232010-02-16 08:03:30 +090020 [TOMOYO_TYPE_TRUNCATE] = "truncate",
21 [TOMOYO_TYPE_SYMLINK] = "symlink",
22 [TOMOYO_TYPE_REWRITE] = "rewrite",
Tetsuo Handa7ef61232010-02-16 08:03:30 +090023 [TOMOYO_TYPE_CHROOT] = "chroot",
Tetsuo Handa7ef61232010-02-16 08:03:30 +090024 [TOMOYO_TYPE_UMOUNT] = "unmount",
Kentaro Takedab69a54e2009-02-05 17:18:14 +090025};
26
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +090027/* Keyword array for operations with one pathname and three numbers. */
Tetsuo Handa71c28232010-06-16 16:26:38 +090028const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION] = {
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +090029 [TOMOYO_TYPE_MKBLOCK] = "mkblock",
30 [TOMOYO_TYPE_MKCHAR] = "mkchar",
31};
32
33/* Keyword array for operations with two pathnames. */
Tetsuo Handa71c28232010-06-16 16:26:38 +090034const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION] = {
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +090035 [TOMOYO_TYPE_LINK] = "link",
36 [TOMOYO_TYPE_RENAME] = "rename",
Tetsuo Handa7ef61232010-02-16 08:03:30 +090037 [TOMOYO_TYPE_PIVOT_ROOT] = "pivot_root",
Kentaro Takedab69a54e2009-02-05 17:18:14 +090038};
39
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +090040/* Keyword array for operations with one pathname and one number. */
Tetsuo Handa71c28232010-06-16 16:26:38 +090041const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION] = {
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +090042 [TOMOYO_TYPE_CREATE] = "create",
43 [TOMOYO_TYPE_MKDIR] = "mkdir",
44 [TOMOYO_TYPE_MKFIFO] = "mkfifo",
45 [TOMOYO_TYPE_MKSOCK] = "mksock",
46 [TOMOYO_TYPE_IOCTL] = "ioctl",
47 [TOMOYO_TYPE_CHMOD] = "chmod",
48 [TOMOYO_TYPE_CHOWN] = "chown",
49 [TOMOYO_TYPE_CHGRP] = "chgrp",
50};
51
Tetsuo Handa57c25902010-06-03 20:38:44 +090052static const u8 tomoyo_p2mac[TOMOYO_MAX_PATH_OPERATION] = {
53 [TOMOYO_TYPE_READ_WRITE] = TOMOYO_MAC_FILE_OPEN,
54 [TOMOYO_TYPE_EXECUTE] = TOMOYO_MAC_FILE_EXECUTE,
55 [TOMOYO_TYPE_READ] = TOMOYO_MAC_FILE_OPEN,
56 [TOMOYO_TYPE_WRITE] = TOMOYO_MAC_FILE_OPEN,
57 [TOMOYO_TYPE_UNLINK] = TOMOYO_MAC_FILE_UNLINK,
58 [TOMOYO_TYPE_RMDIR] = TOMOYO_MAC_FILE_RMDIR,
59 [TOMOYO_TYPE_TRUNCATE] = TOMOYO_MAC_FILE_TRUNCATE,
60 [TOMOYO_TYPE_SYMLINK] = TOMOYO_MAC_FILE_SYMLINK,
61 [TOMOYO_TYPE_REWRITE] = TOMOYO_MAC_FILE_REWRITE,
62 [TOMOYO_TYPE_CHROOT] = TOMOYO_MAC_FILE_CHROOT,
63 [TOMOYO_TYPE_UMOUNT] = TOMOYO_MAC_FILE_UMOUNT,
64};
65
Tetsuo Handa75093152010-06-16 16:23:55 +090066static const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION] = {
Tetsuo Handa57c25902010-06-03 20:38:44 +090067 [TOMOYO_TYPE_MKBLOCK] = TOMOYO_MAC_FILE_MKBLOCK,
68 [TOMOYO_TYPE_MKCHAR] = TOMOYO_MAC_FILE_MKCHAR,
69};
70
71static const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION] = {
72 [TOMOYO_TYPE_LINK] = TOMOYO_MAC_FILE_LINK,
73 [TOMOYO_TYPE_RENAME] = TOMOYO_MAC_FILE_RENAME,
74 [TOMOYO_TYPE_PIVOT_ROOT] = TOMOYO_MAC_FILE_PIVOT_ROOT,
75};
76
77static const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION] = {
78 [TOMOYO_TYPE_CREATE] = TOMOYO_MAC_FILE_CREATE,
79 [TOMOYO_TYPE_MKDIR] = TOMOYO_MAC_FILE_MKDIR,
80 [TOMOYO_TYPE_MKFIFO] = TOMOYO_MAC_FILE_MKFIFO,
81 [TOMOYO_TYPE_MKSOCK] = TOMOYO_MAC_FILE_MKSOCK,
82 [TOMOYO_TYPE_IOCTL] = TOMOYO_MAC_FILE_IOCTL,
83 [TOMOYO_TYPE_CHMOD] = TOMOYO_MAC_FILE_CHMOD,
84 [TOMOYO_TYPE_CHOWN] = TOMOYO_MAC_FILE_CHOWN,
85 [TOMOYO_TYPE_CHGRP] = TOMOYO_MAC_FILE_CHGRP,
86};
87
Tetsuo Handa7762fbf2010-05-10 17:30:26 +090088void tomoyo_put_name_union(struct tomoyo_name_union *ptr)
89{
90 if (!ptr)
91 return;
92 if (ptr->is_group)
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +090093 tomoyo_put_group(ptr->group);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +090094 else
95 tomoyo_put_name(ptr->filename);
96}
97
98bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
99 const struct tomoyo_name_union *ptr)
100{
101 if (ptr->is_group)
Tetsuo Handa3f629632010-06-03 20:37:26 +0900102 return tomoyo_path_matches_group(name, ptr->group);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900103 return tomoyo_path_matches_pattern(name, ptr->filename);
104}
105
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900106void tomoyo_put_number_union(struct tomoyo_number_union *ptr)
107{
108 if (ptr && ptr->is_group)
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900109 tomoyo_put_group(ptr->group);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900110}
111
112bool tomoyo_compare_number_union(const unsigned long value,
113 const struct tomoyo_number_union *ptr)
114{
115 if (ptr->is_group)
116 return tomoyo_number_matches_group(value, value, ptr->group);
117 return value >= ptr->values[0] && value <= ptr->values[1];
118}
119
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900120static void tomoyo_add_slash(struct tomoyo_path_info *buf)
121{
122 if (buf->is_dir)
123 return;
124 /*
125 * This is OK because tomoyo_encode() reserves space for appending "/".
126 */
127 strcat((char *) buf->name, "/");
128 tomoyo_fill_path_info(buf);
129}
130
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900131/**
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900132 * tomoyo_strendswith - Check whether the token ends with the given token.
133 *
134 * @name: The token to check.
135 * @tail: The token to find.
136 *
137 * Returns true if @name ends with @tail, false otherwise.
138 */
139static bool tomoyo_strendswith(const char *name, const char *tail)
140{
141 int len;
142
143 if (!name || !tail)
144 return false;
145 len = strlen(name) - strlen(tail);
146 return len >= 0 && !strcmp(name + len, tail);
147}
148
149/**
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900150 * tomoyo_get_realpath - Get realpath.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900151 *
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900152 * @buf: Pointer to "struct tomoyo_path_info".
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900153 * @path: Pointer to "struct path".
154 *
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900155 * Returns true on success, false otherwise.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900156 */
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900157static bool tomoyo_get_realpath(struct tomoyo_path_info *buf, struct path *path)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900158{
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900159 buf->name = tomoyo_realpath_from_path(path);
160 if (buf->name) {
161 tomoyo_fill_path_info(buf);
162 return true;
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900163 }
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900164 return false;
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900165}
166
Tetsuo Handa99a85252010-06-16 16:22:51 +0900167/**
168 * tomoyo_audit_path_log - Audit path request log.
169 *
170 * @r: Pointer to "struct tomoyo_request_info".
171 *
172 * Returns 0 on success, negative value otherwise.
173 */
174static int tomoyo_audit_path_log(struct tomoyo_request_info *r)
175{
176 const char *operation = tomoyo_path_keyword[r->param.path.operation];
177 const struct tomoyo_path_info *filename = r->param.path.filename;
178 if (r->granted)
179 return 0;
180 tomoyo_warn_log(r, "%s %s", operation, filename->name);
181 return tomoyo_supervisor(r, "allow_%s %s\n", operation,
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900182 tomoyo_pattern(filename));
Tetsuo Handa99a85252010-06-16 16:22:51 +0900183}
184
185/**
186 * tomoyo_audit_path2_log - Audit path/path request log.
187 *
188 * @r: Pointer to "struct tomoyo_request_info".
189 *
190 * Returns 0 on success, negative value otherwise.
191 */
192static int tomoyo_audit_path2_log(struct tomoyo_request_info *r)
193{
194 const char *operation = tomoyo_path2_keyword[r->param.path2.operation];
195 const struct tomoyo_path_info *filename1 = r->param.path2.filename1;
196 const struct tomoyo_path_info *filename2 = r->param.path2.filename2;
197 if (r->granted)
198 return 0;
199 tomoyo_warn_log(r, "%s %s %s", operation, filename1->name,
200 filename2->name);
201 return tomoyo_supervisor(r, "allow_%s %s %s\n", operation,
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900202 tomoyo_pattern(filename1),
203 tomoyo_pattern(filename2));
Tetsuo Handa99a85252010-06-16 16:22:51 +0900204}
205
206/**
207 * tomoyo_audit_mkdev_log - Audit path/number/number/number request log.
208 *
209 * @r: Pointer to "struct tomoyo_request_info".
210 *
211 * Returns 0 on success, negative value otherwise.
212 */
213static int tomoyo_audit_mkdev_log(struct tomoyo_request_info *r)
214{
Tetsuo Handa71c28232010-06-16 16:26:38 +0900215 const char *operation = tomoyo_mkdev_keyword[r->param.mkdev.operation];
Tetsuo Handa99a85252010-06-16 16:22:51 +0900216 const struct tomoyo_path_info *filename = r->param.mkdev.filename;
217 const unsigned int major = r->param.mkdev.major;
218 const unsigned int minor = r->param.mkdev.minor;
219 const unsigned int mode = r->param.mkdev.mode;
220 if (r->granted)
221 return 0;
222 tomoyo_warn_log(r, "%s %s 0%o %u %u", operation, filename->name, mode,
223 major, minor);
224 return tomoyo_supervisor(r, "allow_%s %s 0%o %u %u\n", operation,
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900225 tomoyo_pattern(filename), mode, major, minor);
Tetsuo Handa99a85252010-06-16 16:22:51 +0900226}
227
228/**
229 * tomoyo_audit_path_number_log - Audit path/number request log.
230 *
231 * @r: Pointer to "struct tomoyo_request_info".
232 * @error: Error code.
233 *
234 * Returns 0 on success, negative value otherwise.
235 */
236static int tomoyo_audit_path_number_log(struct tomoyo_request_info *r)
237{
238 const u8 type = r->param.path_number.operation;
239 u8 radix;
240 const struct tomoyo_path_info *filename = r->param.path_number.filename;
241 const char *operation = tomoyo_path_number_keyword[type];
242 char buffer[64];
243 if (r->granted)
244 return 0;
245 switch (type) {
246 case TOMOYO_TYPE_CREATE:
247 case TOMOYO_TYPE_MKDIR:
248 case TOMOYO_TYPE_MKFIFO:
249 case TOMOYO_TYPE_MKSOCK:
250 case TOMOYO_TYPE_CHMOD:
251 radix = TOMOYO_VALUE_TYPE_OCTAL;
252 break;
253 case TOMOYO_TYPE_IOCTL:
254 radix = TOMOYO_VALUE_TYPE_HEXADECIMAL;
255 break;
256 default:
257 radix = TOMOYO_VALUE_TYPE_DECIMAL;
258 break;
259 }
260 tomoyo_print_ulong(buffer, sizeof(buffer), r->param.path_number.number,
261 radix);
262 tomoyo_warn_log(r, "%s %s %s", operation, filename->name, buffer);
263 return tomoyo_supervisor(r, "allow_%s %s %s\n", operation,
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900264 tomoyo_pattern(filename), buffer);
Tetsuo Handa99a85252010-06-16 16:22:51 +0900265}
266
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900267static bool tomoyo_same_globally_readable(const struct tomoyo_acl_head *a,
268 const struct tomoyo_acl_head *b)
269{
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900270 return container_of(a, struct tomoyo_readable_file,
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900271 head)->filename ==
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900272 container_of(b, struct tomoyo_readable_file,
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900273 head)->filename;
274}
275
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900276/**
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900277 * tomoyo_update_globally_readable_entry - Update "struct tomoyo_readable_file" list.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900278 *
279 * @filename: Filename unconditionally permitted to open() for reading.
280 * @is_delete: True if it is a delete request.
281 *
282 * Returns 0 on success, negative value otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900283 *
284 * Caller holds tomoyo_read_lock().
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900285 */
286static int tomoyo_update_globally_readable_entry(const char *filename,
287 const bool is_delete)
288{
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900289 struct tomoyo_readable_file e = { };
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900290 int error;
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900291
Tetsuo Handa75093152010-06-16 16:23:55 +0900292 if (!tomoyo_correct_word(filename))
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900293 return -EINVAL;
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900294 e.filename = tomoyo_get_name(filename);
295 if (!e.filename)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900296 return -ENOMEM;
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900297 error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900298 &tomoyo_policy_list
299 [TOMOYO_ID_GLOBALLY_READABLE],
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900300 tomoyo_same_globally_readable);
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900301 tomoyo_put_name(e.filename);
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900302 return error;
303}
304
305/**
Tetsuo Handa75093152010-06-16 16:23:55 +0900306 * tomoyo_globally_readable_file - Check if the file is unconditionnaly permitted to be open()ed for reading.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900307 *
308 * @filename: The filename to check.
309 *
310 * Returns true if any domain can open @filename for reading, false otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900311 *
312 * Caller holds tomoyo_read_lock().
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900313 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900314static bool tomoyo_globally_readable_file(const struct tomoyo_path_info *
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900315 filename)
316{
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900317 struct tomoyo_readable_file *ptr;
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900318 bool found = false;
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900319
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900320 list_for_each_entry_rcu(ptr, &tomoyo_policy_list
321 [TOMOYO_ID_GLOBALLY_READABLE], head.list) {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900322 if (!ptr->head.is_deleted &&
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900323 tomoyo_path_matches_pattern(filename, ptr->filename)) {
324 found = true;
325 break;
326 }
327 }
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900328 return found;
329}
330
331/**
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900332 * tomoyo_write_globally_readable - Write "struct tomoyo_readable_file" list.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900333 *
334 * @data: String to parse.
335 * @is_delete: True if it is a delete request.
336 *
337 * Returns 0 on success, negative value otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900338 *
339 * Caller holds tomoyo_read_lock().
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900340 */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900341int tomoyo_write_globally_readable(char *data, const bool is_delete)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900342{
343 return tomoyo_update_globally_readable_entry(data, is_delete);
344}
345
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900346static bool tomoyo_same_pattern(const struct tomoyo_acl_head *a,
347 const struct tomoyo_acl_head *b)
348{
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900349 return container_of(a, struct tomoyo_no_pattern, head)->pattern ==
350 container_of(b, struct tomoyo_no_pattern, head)->pattern;
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900351}
352
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900353/**
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900354 * tomoyo_update_file_pattern_entry - Update "struct tomoyo_no_pattern" list.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900355 *
356 * @pattern: Pathname pattern.
357 * @is_delete: True if it is a delete request.
358 *
359 * Returns 0 on success, negative value otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900360 *
361 * Caller holds tomoyo_read_lock().
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900362 */
363static int tomoyo_update_file_pattern_entry(const char *pattern,
364 const bool is_delete)
365{
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900366 struct tomoyo_no_pattern e = { };
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900367 int error;
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900368
Tetsuo Handa75093152010-06-16 16:23:55 +0900369 if (!tomoyo_correct_word(pattern))
Tetsuo Handa3f629632010-06-03 20:37:26 +0900370 return -EINVAL;
371 e.pattern = tomoyo_get_name(pattern);
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900372 if (!e.pattern)
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900373 return -ENOMEM;
374 error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900375 &tomoyo_policy_list[TOMOYO_ID_PATTERN],
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900376 tomoyo_same_pattern);
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900377 tomoyo_put_name(e.pattern);
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900378 return error;
379}
380
381/**
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900382 * tomoyo_pattern - Get patterned pathname.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900383 *
384 * @filename: The filename to find patterned pathname.
385 *
386 * Returns pointer to pathname pattern if matched, @filename otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900387 *
388 * Caller holds tomoyo_read_lock().
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900389 */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900390const char *tomoyo_pattern(const struct tomoyo_path_info *filename)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900391{
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900392 struct tomoyo_no_pattern *ptr;
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900393 const struct tomoyo_path_info *pattern = NULL;
394
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900395 list_for_each_entry_rcu(ptr, &tomoyo_policy_list[TOMOYO_ID_PATTERN],
396 head.list) {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900397 if (ptr->head.is_deleted)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900398 continue;
399 if (!tomoyo_path_matches_pattern(filename, ptr->pattern))
400 continue;
401 pattern = ptr->pattern;
402 if (tomoyo_strendswith(pattern->name, "/\\*")) {
403 /* Do nothing. Try to find the better match. */
404 } else {
405 /* This would be the better match. Use this. */
406 break;
407 }
408 }
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900409 if (pattern)
410 filename = pattern;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900411 return filename->name;
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900412}
413
414/**
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900415 * tomoyo_write_pattern - Write "struct tomoyo_no_pattern" list.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900416 *
417 * @data: String to parse.
418 * @is_delete: True if it is a delete request.
419 *
420 * Returns 0 on success, negative value otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900421 *
422 * Caller holds tomoyo_read_lock().
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900423 */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900424int tomoyo_write_pattern(char *data, const bool is_delete)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900425{
426 return tomoyo_update_file_pattern_entry(data, is_delete);
427}
428
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900429static bool tomoyo_same_no_rewrite(const struct tomoyo_acl_head *a,
430 const struct tomoyo_acl_head *b)
431{
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900432 return container_of(a, struct tomoyo_no_rewrite, head)->pattern
433 == container_of(b, struct tomoyo_no_rewrite, head)
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900434 ->pattern;
435}
436
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900437/**
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900438 * tomoyo_update_no_rewrite_entry - Update "struct tomoyo_no_rewrite" list.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900439 *
440 * @pattern: Pathname pattern that are not rewritable by default.
441 * @is_delete: True if it is a delete request.
442 *
443 * Returns 0 on success, negative value otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900444 *
445 * Caller holds tomoyo_read_lock().
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900446 */
447static int tomoyo_update_no_rewrite_entry(const char *pattern,
448 const bool is_delete)
449{
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900450 struct tomoyo_no_rewrite e = { };
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900451 int error;
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900452
Tetsuo Handa75093152010-06-16 16:23:55 +0900453 if (!tomoyo_correct_word(pattern))
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900454 return -EINVAL;
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900455 e.pattern = tomoyo_get_name(pattern);
456 if (!e.pattern)
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900457 return -ENOMEM;
458 error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900459 &tomoyo_policy_list[TOMOYO_ID_NO_REWRITE],
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900460 tomoyo_same_no_rewrite);
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900461 tomoyo_put_name(e.pattern);
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900462 return error;
463}
464
465/**
Tetsuo Handa75093152010-06-16 16:23:55 +0900466 * tomoyo_no_rewrite_file - Check if the given pathname is not permitted to be rewrited.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900467 *
468 * @filename: Filename to check.
469 *
470 * Returns true if @filename is specified by "deny_rewrite" directive,
471 * false otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900472 *
473 * Caller holds tomoyo_read_lock().
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900474 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900475static bool tomoyo_no_rewrite_file(const struct tomoyo_path_info *filename)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900476{
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900477 struct tomoyo_no_rewrite *ptr;
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900478 bool found = false;
479
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900480 list_for_each_entry_rcu(ptr, &tomoyo_policy_list[TOMOYO_ID_NO_REWRITE],
481 head.list) {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900482 if (ptr->head.is_deleted)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900483 continue;
484 if (!tomoyo_path_matches_pattern(filename, ptr->pattern))
485 continue;
486 found = true;
487 break;
488 }
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900489 return found;
490}
491
492/**
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900493 * tomoyo_write_no_rewrite - Write "struct tomoyo_no_rewrite" list.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900494 *
495 * @data: String to parse.
496 * @is_delete: True if it is a delete request.
497 *
498 * Returns 0 on success, negative value otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900499 *
500 * Caller holds tomoyo_read_lock().
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900501 */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900502int tomoyo_write_no_rewrite(char *data, const bool is_delete)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900503{
504 return tomoyo_update_no_rewrite_entry(data, is_delete);
505}
506
Tetsuo Handa99a85252010-06-16 16:22:51 +0900507static bool tomoyo_check_path_acl(const struct tomoyo_request_info *r,
508 const struct tomoyo_acl_info *ptr)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900509{
Tetsuo Handa99a85252010-06-16 16:22:51 +0900510 const struct tomoyo_path_acl *acl = container_of(ptr, typeof(*acl),
511 head);
512 return (acl->perm & (1 << r->param.path.operation)) &&
513 tomoyo_compare_name_union(r->param.path.filename, &acl->name);
514}
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900515
Tetsuo Handa99a85252010-06-16 16:22:51 +0900516static bool tomoyo_check_path_number_acl(const struct tomoyo_request_info *r,
517 const struct tomoyo_acl_info *ptr)
518{
519 const struct tomoyo_path_number_acl *acl =
520 container_of(ptr, typeof(*acl), head);
521 return (acl->perm & (1 << r->param.path_number.operation)) &&
522 tomoyo_compare_number_union(r->param.path_number.number,
523 &acl->number) &&
524 tomoyo_compare_name_union(r->param.path_number.filename,
525 &acl->name);
526}
527
528static bool tomoyo_check_path2_acl(const struct tomoyo_request_info *r,
529 const struct tomoyo_acl_info *ptr)
530{
531 const struct tomoyo_path2_acl *acl =
532 container_of(ptr, typeof(*acl), head);
533 return (acl->perm & (1 << r->param.path2.operation)) &&
534 tomoyo_compare_name_union(r->param.path2.filename1, &acl->name1)
535 && tomoyo_compare_name_union(r->param.path2.filename2,
536 &acl->name2);
537}
538
539static bool tomoyo_check_mkdev_acl(const struct tomoyo_request_info *r,
540 const struct tomoyo_acl_info *ptr)
541{
Tetsuo Handa75093152010-06-16 16:23:55 +0900542 const struct tomoyo_mkdev_acl *acl =
Tetsuo Handa99a85252010-06-16 16:22:51 +0900543 container_of(ptr, typeof(*acl), head);
544 return (acl->perm & (1 << r->param.mkdev.operation)) &&
545 tomoyo_compare_number_union(r->param.mkdev.mode,
546 &acl->mode) &&
547 tomoyo_compare_number_union(r->param.mkdev.major,
548 &acl->major) &&
549 tomoyo_compare_number_union(r->param.mkdev.minor,
550 &acl->minor) &&
551 tomoyo_compare_name_union(r->param.mkdev.filename,
552 &acl->name);
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900553}
554
Tetsuo Handa237ab452010-06-12 20:46:22 +0900555static bool tomoyo_same_path_acl(const struct tomoyo_acl_info *a,
556 const struct tomoyo_acl_info *b)
557{
558 const struct tomoyo_path_acl *p1 = container_of(a, typeof(*p1), head);
559 const struct tomoyo_path_acl *p2 = container_of(b, typeof(*p2), head);
Tetsuo Handa75093152010-06-16 16:23:55 +0900560 return tomoyo_same_acl_head(&p1->head, &p2->head) &&
561 tomoyo_same_name_union(&p1->name, &p2->name);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900562}
563
564static bool tomoyo_merge_path_acl(struct tomoyo_acl_info *a,
565 struct tomoyo_acl_info *b,
566 const bool is_delete)
567{
568 u16 * const a_perm = &container_of(a, struct tomoyo_path_acl, head)
569 ->perm;
570 u16 perm = *a_perm;
571 const u16 b_perm = container_of(b, struct tomoyo_path_acl, head)->perm;
572 if (is_delete) {
573 perm &= ~b_perm;
574 if ((perm & TOMOYO_RW_MASK) != TOMOYO_RW_MASK)
575 perm &= ~(1 << TOMOYO_TYPE_READ_WRITE);
576 else if (!(perm & (1 << TOMOYO_TYPE_READ_WRITE)))
577 perm &= ~TOMOYO_RW_MASK;
578 } else {
579 perm |= b_perm;
580 if ((perm & TOMOYO_RW_MASK) == TOMOYO_RW_MASK)
581 perm |= (1 << TOMOYO_TYPE_READ_WRITE);
582 else if (perm & (1 << TOMOYO_TYPE_READ_WRITE))
583 perm |= TOMOYO_RW_MASK;
584 }
585 *a_perm = perm;
586 return !perm;
587}
588
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900589/**
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900590 * tomoyo_update_path_acl - Update "struct tomoyo_path_acl" list.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900591 *
592 * @type: Type of operation.
593 * @filename: Filename.
594 * @domain: Pointer to "struct tomoyo_domain_info".
595 * @is_delete: True if it is a delete request.
596 *
597 * Returns 0 on success, negative value otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900598 *
599 * Caller holds tomoyo_read_lock().
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900600 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900601static int tomoyo_update_path_acl(const u8 type, const char *filename,
Tetsuo Handa237ab452010-06-12 20:46:22 +0900602 struct tomoyo_domain_info * const domain,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900603 const bool is_delete)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900604{
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900605 struct tomoyo_path_acl e = {
606 .head.type = TOMOYO_TYPE_PATH_ACL,
Tetsuo Handa237ab452010-06-12 20:46:22 +0900607 .perm = 1 << type
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900608 };
Tetsuo Handa237ab452010-06-12 20:46:22 +0900609 int error;
610 if (e.perm == (1 << TOMOYO_TYPE_READ_WRITE))
611 e.perm |= TOMOYO_RW_MASK;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900612 if (!tomoyo_parse_name_union(filename, &e.name))
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900613 return -EINVAL;
Tetsuo Handa237ab452010-06-12 20:46:22 +0900614 error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
615 tomoyo_same_path_acl,
616 tomoyo_merge_path_acl);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900617 tomoyo_put_name_union(&e.name);
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900618 return error;
619}
620
Tetsuo Handa75093152010-06-16 16:23:55 +0900621static bool tomoyo_same_mkdev_acl(const struct tomoyo_acl_info *a,
Tetsuo Handa237ab452010-06-12 20:46:22 +0900622 const struct tomoyo_acl_info *b)
623{
Tetsuo Handa75093152010-06-16 16:23:55 +0900624 const struct tomoyo_mkdev_acl *p1 = container_of(a, typeof(*p1),
Tetsuo Handa237ab452010-06-12 20:46:22 +0900625 head);
Tetsuo Handa75093152010-06-16 16:23:55 +0900626 const struct tomoyo_mkdev_acl *p2 = container_of(b, typeof(*p2),
Tetsuo Handa237ab452010-06-12 20:46:22 +0900627 head);
Tetsuo Handa75093152010-06-16 16:23:55 +0900628 return tomoyo_same_acl_head(&p1->head, &p2->head)
629 && tomoyo_same_name_union(&p1->name, &p2->name)
630 && tomoyo_same_number_union(&p1->mode, &p2->mode)
631 && tomoyo_same_number_union(&p1->major, &p2->major)
632 && tomoyo_same_number_union(&p1->minor, &p2->minor);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900633}
634
Tetsuo Handa75093152010-06-16 16:23:55 +0900635static bool tomoyo_merge_mkdev_acl(struct tomoyo_acl_info *a,
Tetsuo Handa237ab452010-06-12 20:46:22 +0900636 struct tomoyo_acl_info *b,
637 const bool is_delete)
638{
Tetsuo Handa75093152010-06-16 16:23:55 +0900639 u8 *const a_perm = &container_of(a, struct tomoyo_mkdev_acl,
Tetsuo Handa237ab452010-06-12 20:46:22 +0900640 head)->perm;
641 u8 perm = *a_perm;
Tetsuo Handa75093152010-06-16 16:23:55 +0900642 const u8 b_perm = container_of(b, struct tomoyo_mkdev_acl, head)
Tetsuo Handa237ab452010-06-12 20:46:22 +0900643 ->perm;
644 if (is_delete)
645 perm &= ~b_perm;
646 else
647 perm |= b_perm;
648 *a_perm = perm;
649 return !perm;
650}
651
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900652/**
Tetsuo Handa75093152010-06-16 16:23:55 +0900653 * tomoyo_update_mkdev_acl - Update "struct tomoyo_mkdev_acl" list.
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900654 *
655 * @type: Type of operation.
656 * @filename: Filename.
657 * @mode: Create mode.
658 * @major: Device major number.
659 * @minor: Device minor number.
660 * @domain: Pointer to "struct tomoyo_domain_info".
661 * @is_delete: True if it is a delete request.
662 *
663 * Returns 0 on success, negative value otherwise.
Tetsuo Handa237ab452010-06-12 20:46:22 +0900664 *
665 * Caller holds tomoyo_read_lock().
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900666 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900667static int tomoyo_update_mkdev_acl(const u8 type, const char *filename,
Tetsuo Handa237ab452010-06-12 20:46:22 +0900668 char *mode, char *major, char *minor,
669 struct tomoyo_domain_info * const
670 domain, const bool is_delete)
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900671{
Tetsuo Handa75093152010-06-16 16:23:55 +0900672 struct tomoyo_mkdev_acl e = {
673 .head.type = TOMOYO_TYPE_MKDEV_ACL,
Tetsuo Handa237ab452010-06-12 20:46:22 +0900674 .perm = 1 << type
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900675 };
676 int error = is_delete ? -ENOENT : -ENOMEM;
677 if (!tomoyo_parse_name_union(filename, &e.name) ||
678 !tomoyo_parse_number_union(mode, &e.mode) ||
679 !tomoyo_parse_number_union(major, &e.major) ||
680 !tomoyo_parse_number_union(minor, &e.minor))
681 goto out;
Tetsuo Handa237ab452010-06-12 20:46:22 +0900682 error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
Tetsuo Handa75093152010-06-16 16:23:55 +0900683 tomoyo_same_mkdev_acl,
684 tomoyo_merge_mkdev_acl);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900685 out:
686 tomoyo_put_name_union(&e.name);
687 tomoyo_put_number_union(&e.mode);
688 tomoyo_put_number_union(&e.major);
689 tomoyo_put_number_union(&e.minor);
690 return error;
691}
692
Tetsuo Handa237ab452010-06-12 20:46:22 +0900693static bool tomoyo_same_path2_acl(const struct tomoyo_acl_info *a,
694 const struct tomoyo_acl_info *b)
695{
696 const struct tomoyo_path2_acl *p1 = container_of(a, typeof(*p1), head);
697 const struct tomoyo_path2_acl *p2 = container_of(b, typeof(*p2), head);
Tetsuo Handa75093152010-06-16 16:23:55 +0900698 return tomoyo_same_acl_head(&p1->head, &p2->head)
699 && tomoyo_same_name_union(&p1->name1, &p2->name1)
700 && tomoyo_same_name_union(&p1->name2, &p2->name2);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900701}
702
703static bool tomoyo_merge_path2_acl(struct tomoyo_acl_info *a,
704 struct tomoyo_acl_info *b,
705 const bool is_delete)
706{
707 u8 * const a_perm = &container_of(a, struct tomoyo_path2_acl, head)
708 ->perm;
709 u8 perm = *a_perm;
710 const u8 b_perm = container_of(b, struct tomoyo_path2_acl, head)->perm;
711 if (is_delete)
712 perm &= ~b_perm;
713 else
714 perm |= b_perm;
715 *a_perm = perm;
716 return !perm;
717}
718
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900719/**
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900720 * tomoyo_update_path2_acl - Update "struct tomoyo_path2_acl" list.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900721 *
722 * @type: Type of operation.
723 * @filename1: First filename.
724 * @filename2: Second filename.
725 * @domain: Pointer to "struct tomoyo_domain_info".
726 * @is_delete: True if it is a delete request.
727 *
728 * Returns 0 on success, negative value otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900729 *
730 * Caller holds tomoyo_read_lock().
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900731 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900732static int tomoyo_update_path2_acl(const u8 type, const char *filename1,
733 const char *filename2,
Tetsuo Handa237ab452010-06-12 20:46:22 +0900734 struct tomoyo_domain_info * const domain,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900735 const bool is_delete)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900736{
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900737 struct tomoyo_path2_acl e = {
738 .head.type = TOMOYO_TYPE_PATH2_ACL,
Tetsuo Handa237ab452010-06-12 20:46:22 +0900739 .perm = 1 << type
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900740 };
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900741 int error = is_delete ? -ENOENT : -ENOMEM;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900742 if (!tomoyo_parse_name_union(filename1, &e.name1) ||
743 !tomoyo_parse_name_union(filename2, &e.name2))
Tetsuo Handaca0b7df2010-02-07 20:23:59 +0900744 goto out;
Tetsuo Handa237ab452010-06-12 20:46:22 +0900745 error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
746 tomoyo_same_path2_acl,
747 tomoyo_merge_path2_acl);
Tetsuo Handaca0b7df2010-02-07 20:23:59 +0900748 out:
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900749 tomoyo_put_name_union(&e.name1);
750 tomoyo_put_name_union(&e.name2);
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900751 return error;
752}
753
754/**
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900755 * tomoyo_path_permission - Check permission for single path operation.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900756 *
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900757 * @r: Pointer to "struct tomoyo_request_info".
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900758 * @operation: Type of operation.
759 * @filename: Filename to check.
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900760 *
761 * Returns 0 on success, negative value otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900762 *
763 * Caller holds tomoyo_read_lock().
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900764 */
Tetsuo Handa05336de2010-06-16 16:20:24 +0900765int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
766 const struct tomoyo_path_info *filename)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900767{
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900768 int error;
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900769
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900770 next:
Tetsuo Handa57c25902010-06-03 20:38:44 +0900771 r->type = tomoyo_p2mac[operation];
772 r->mode = tomoyo_get_mode(r->profile, r->type);
773 if (r->mode == TOMOYO_CONFIG_DISABLED)
774 return 0;
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900775 r->param_type = TOMOYO_TYPE_PATH_ACL;
776 r->param.path.filename = filename;
777 r->param.path.operation = operation;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900778 do {
Tetsuo Handa99a85252010-06-16 16:22:51 +0900779 tomoyo_check_acl(r, tomoyo_check_path_acl);
780 if (!r->granted && operation == TOMOYO_TYPE_READ &&
Tetsuo Handa05336de2010-06-16 16:20:24 +0900781 !r->domain->ignore_global_allow_read &&
Tetsuo Handa75093152010-06-16 16:23:55 +0900782 tomoyo_globally_readable_file(filename))
Tetsuo Handa99a85252010-06-16 16:22:51 +0900783 r->granted = true;
784 error = tomoyo_audit_path_log(r);
Tetsuo Handa05336de2010-06-16 16:20:24 +0900785 /*
786 * Do not retry for execute request, for alias may have
787 * changed.
788 */
789 } while (error == TOMOYO_RETRY_REQUEST &&
790 operation != TOMOYO_TYPE_EXECUTE);
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900791 /*
792 * Since "allow_truncate" doesn't imply "allow_rewrite" permission,
793 * we need to check "allow_rewrite" permission if the filename is
794 * specified by "deny_rewrite" keyword.
795 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900796 if (!error && operation == TOMOYO_TYPE_TRUNCATE &&
Tetsuo Handa75093152010-06-16 16:23:55 +0900797 tomoyo_no_rewrite_file(filename)) {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900798 operation = TOMOYO_TYPE_REWRITE;
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900799 goto next;
800 }
801 return error;
802}
803
Tetsuo Handa237ab452010-06-12 20:46:22 +0900804static bool tomoyo_same_path_number_acl(const struct tomoyo_acl_info *a,
805 const struct tomoyo_acl_info *b)
806{
807 const struct tomoyo_path_number_acl *p1 = container_of(a, typeof(*p1),
808 head);
809 const struct tomoyo_path_number_acl *p2 = container_of(b, typeof(*p2),
810 head);
Tetsuo Handa75093152010-06-16 16:23:55 +0900811 return tomoyo_same_acl_head(&p1->head, &p2->head)
812 && tomoyo_same_name_union(&p1->name, &p2->name)
813 && tomoyo_same_number_union(&p1->number, &p2->number);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900814}
815
816static bool tomoyo_merge_path_number_acl(struct tomoyo_acl_info *a,
817 struct tomoyo_acl_info *b,
818 const bool is_delete)
819{
820 u8 * const a_perm = &container_of(a, struct tomoyo_path_number_acl,
821 head)->perm;
822 u8 perm = *a_perm;
823 const u8 b_perm = container_of(b, struct tomoyo_path_number_acl, head)
824 ->perm;
825 if (is_delete)
826 perm &= ~b_perm;
827 else
828 perm |= b_perm;
829 *a_perm = perm;
830 return !perm;
831}
832
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900833/**
834 * tomoyo_update_path_number_acl - Update ioctl/chmod/chown/chgrp ACL.
835 *
836 * @type: Type of operation.
837 * @filename: Filename.
838 * @number: Number.
839 * @domain: Pointer to "struct tomoyo_domain_info".
840 * @is_delete: True if it is a delete request.
841 *
842 * Returns 0 on success, negative value otherwise.
843 */
Tetsuo Handa237ab452010-06-12 20:46:22 +0900844static int tomoyo_update_path_number_acl(const u8 type, const char *filename,
845 char *number,
846 struct tomoyo_domain_info * const
847 domain,
848 const bool is_delete)
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900849{
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900850 struct tomoyo_path_number_acl e = {
851 .head.type = TOMOYO_TYPE_PATH_NUMBER_ACL,
Tetsuo Handa237ab452010-06-12 20:46:22 +0900852 .perm = 1 << type
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900853 };
854 int error = is_delete ? -ENOENT : -ENOMEM;
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900855 if (!tomoyo_parse_name_union(filename, &e.name))
856 return -EINVAL;
857 if (!tomoyo_parse_number_union(number, &e.number))
858 goto out;
Tetsuo Handa237ab452010-06-12 20:46:22 +0900859 error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
860 tomoyo_same_path_number_acl,
861 tomoyo_merge_path_number_acl);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900862 out:
863 tomoyo_put_name_union(&e.name);
864 tomoyo_put_number_union(&e.number);
865 return error;
866}
867
868/**
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900869 * tomoyo_path_number_perm - Check permission for "create", "mkdir", "mkfifo", "mksock", "ioctl", "chmod", "chown", "chgrp".
870 *
871 * @type: Type of operation.
872 * @path: Pointer to "struct path".
873 * @number: Number.
874 *
875 * Returns 0 on success, negative value otherwise.
876 */
877int tomoyo_path_number_perm(const u8 type, struct path *path,
878 unsigned long number)
879{
880 struct tomoyo_request_info r;
881 int error = -ENOMEM;
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900882 struct tomoyo_path_info buf;
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900883 int idx;
884
Tetsuo Handa57c25902010-06-03 20:38:44 +0900885 if (tomoyo_init_request_info(&r, NULL, tomoyo_pn2mac[type])
886 == TOMOYO_CONFIG_DISABLED || !path->mnt || !path->dentry)
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900887 return 0;
888 idx = tomoyo_read_lock();
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900889 if (!tomoyo_get_realpath(&buf, path))
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900890 goto out;
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900891 if (type == TOMOYO_TYPE_MKDIR)
892 tomoyo_add_slash(&buf);
Tetsuo Handacb917cf2010-06-16 16:28:21 +0900893 r.param_type = TOMOYO_TYPE_PATH_NUMBER_ACL;
894 r.param.path_number.operation = type;
895 r.param.path_number.filename = &buf;
896 r.param.path_number.number = number;
897 do {
898 tomoyo_check_acl(&r, tomoyo_check_path_number_acl);
899 error = tomoyo_audit_path_number_log(&r);
900 } while (error == TOMOYO_RETRY_REQUEST);
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900901 kfree(buf.name);
Tetsuo Handacb917cf2010-06-16 16:28:21 +0900902 out:
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900903 tomoyo_read_unlock(idx);
904 if (r.mode != TOMOYO_CONFIG_ENFORCING)
905 error = 0;
906 return error;
907}
908
909/**
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900910 * tomoyo_check_open_permission - Check permission for "read" and "write".
911 *
912 * @domain: Pointer to "struct tomoyo_domain_info".
913 * @path: Pointer to "struct path".
914 * @flag: Flags for open().
915 *
916 * Returns 0 on success, negative value otherwise.
917 */
918int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
919 struct path *path, const int flag)
920{
921 const u8 acc_mode = ACC_MODE(flag);
922 int error = -ENOMEM;
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900923 struct tomoyo_path_info buf;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900924 struct tomoyo_request_info r;
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900925 int idx;
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900926
Tetsuo Handa57c25902010-06-03 20:38:44 +0900927 if (!path->mnt ||
928 (path->dentry->d_inode && S_ISDIR(path->dentry->d_inode->i_mode)))
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900929 return 0;
Tetsuo Handa57c25902010-06-03 20:38:44 +0900930 buf.name = NULL;
931 r.mode = TOMOYO_CONFIG_DISABLED;
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900932 idx = tomoyo_read_lock();
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900933 if (!tomoyo_get_realpath(&buf, path))
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900934 goto out;
935 error = 0;
936 /*
937 * If the filename is specified by "deny_rewrite" keyword,
938 * we need to check "allow_rewrite" permission when the filename is not
939 * opened for append mode or the filename is truncated at open time.
940 */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900941 if ((acc_mode & MAY_WRITE) && !(flag & O_APPEND)
942 && tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_REWRITE)
943 != TOMOYO_CONFIG_DISABLED) {
944 if (!tomoyo_get_realpath(&buf, path)) {
945 error = -ENOMEM;
946 goto out;
947 }
Tetsuo Handa75093152010-06-16 16:23:55 +0900948 if (tomoyo_no_rewrite_file(&buf))
Tetsuo Handa57c25902010-06-03 20:38:44 +0900949 error = tomoyo_path_permission(&r, TOMOYO_TYPE_REWRITE,
950 &buf);
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900951 }
Tetsuo Handa57c25902010-06-03 20:38:44 +0900952 if (!error && acc_mode &&
953 tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_OPEN)
954 != TOMOYO_CONFIG_DISABLED) {
Tetsuo Handa05336de2010-06-16 16:20:24 +0900955 u8 operation;
Tetsuo Handa57c25902010-06-03 20:38:44 +0900956 if (!buf.name && !tomoyo_get_realpath(&buf, path)) {
957 error = -ENOMEM;
958 goto out;
959 }
Tetsuo Handa05336de2010-06-16 16:20:24 +0900960 if (acc_mode == (MAY_READ | MAY_WRITE))
961 operation = TOMOYO_TYPE_READ_WRITE;
962 else if (acc_mode == MAY_READ)
963 operation = TOMOYO_TYPE_READ;
964 else
965 operation = TOMOYO_TYPE_WRITE;
966 error = tomoyo_path_permission(&r, operation, &buf);
Tetsuo Handa57c25902010-06-03 20:38:44 +0900967 }
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900968 out:
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900969 kfree(buf.name);
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900970 tomoyo_read_unlock(idx);
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900971 if (r.mode != TOMOYO_CONFIG_ENFORCING)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900972 error = 0;
973 return error;
974}
975
976/**
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900977 * tomoyo_path_perm - Check permission for "unlink", "rmdir", "truncate", "symlink", "rewrite", "chroot" and "unmount".
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900978 *
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900979 * @operation: Type of operation.
980 * @path: Pointer to "struct path".
981 *
982 * Returns 0 on success, negative value otherwise.
983 */
Tetsuo Handa97d69312010-02-16 09:46:15 +0900984int tomoyo_path_perm(const u8 operation, struct path *path)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900985{
986 int error = -ENOMEM;
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900987 struct tomoyo_path_info buf;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900988 struct tomoyo_request_info r;
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900989 int idx;
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900990
Tetsuo Handa57c25902010-06-03 20:38:44 +0900991 if (!path->mnt)
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900992 return 0;
Tetsuo Handa57c25902010-06-03 20:38:44 +0900993 if (tomoyo_init_request_info(&r, NULL, tomoyo_p2mac[operation])
994 == TOMOYO_CONFIG_DISABLED)
995 return 0;
996 buf.name = NULL;
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900997 idx = tomoyo_read_lock();
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900998 if (!tomoyo_get_realpath(&buf, path))
Kentaro Takedab69a54e2009-02-05 17:18:14 +0900999 goto out;
1000 switch (operation) {
Tetsuo Handacb0abe62010-05-17 10:08:05 +09001001 case TOMOYO_TYPE_REWRITE:
Tetsuo Handa75093152010-06-16 16:23:55 +09001002 if (!tomoyo_no_rewrite_file(&buf)) {
Tetsuo Handacb0abe62010-05-17 10:08:05 +09001003 error = 0;
1004 goto out;
1005 }
1006 break;
Tetsuo Handa7ef61232010-02-16 08:03:30 +09001007 case TOMOYO_TYPE_RMDIR:
1008 case TOMOYO_TYPE_CHROOT:
Tetsuo Handa57c25902010-06-03 20:38:44 +09001009 case TOMOYO_TYPE_UMOUNT:
Tetsuo Handac8c57e82010-06-03 20:36:43 +09001010 tomoyo_add_slash(&buf);
1011 break;
Kentaro Takedab69a54e2009-02-05 17:18:14 +09001012 }
Tetsuo Handac8c57e82010-06-03 20:36:43 +09001013 error = tomoyo_path_permission(&r, operation, &buf);
Kentaro Takedab69a54e2009-02-05 17:18:14 +09001014 out:
Tetsuo Handac8c57e82010-06-03 20:36:43 +09001015 kfree(buf.name);
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +09001016 tomoyo_read_unlock(idx);
Tetsuo Handacb0abe62010-05-17 10:08:05 +09001017 if (r.mode != TOMOYO_CONFIG_ENFORCING)
Kentaro Takedab69a54e2009-02-05 17:18:14 +09001018 error = 0;
1019 return error;
1020}
1021
1022/**
Tetsuo Handa75093152010-06-16 16:23:55 +09001023 * tomoyo_mkdev_perm - Check permission for "mkblock" and "mkchar".
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +09001024 *
1025 * @operation: Type of operation. (TOMOYO_TYPE_MKCHAR or TOMOYO_TYPE_MKBLOCK)
1026 * @path: Pointer to "struct path".
1027 * @mode: Create mode.
1028 * @dev: Device number.
1029 *
1030 * Returns 0 on success, negative value otherwise.
1031 */
Tetsuo Handa75093152010-06-16 16:23:55 +09001032int tomoyo_mkdev_perm(const u8 operation, struct path *path,
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +09001033 const unsigned int mode, unsigned int dev)
1034{
1035 struct tomoyo_request_info r;
1036 int error = -ENOMEM;
Tetsuo Handac8c57e82010-06-03 20:36:43 +09001037 struct tomoyo_path_info buf;
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +09001038 int idx;
1039
Tetsuo Handa57c25902010-06-03 20:38:44 +09001040 if (!path->mnt ||
1041 tomoyo_init_request_info(&r, NULL, tomoyo_pnnn2mac[operation])
1042 == TOMOYO_CONFIG_DISABLED)
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +09001043 return 0;
1044 idx = tomoyo_read_lock();
1045 error = -ENOMEM;
Tetsuo Handac8c57e82010-06-03 20:36:43 +09001046 if (tomoyo_get_realpath(&buf, path)) {
Tetsuo Handacf6e9a62010-06-16 16:21:36 +09001047 dev = new_decode_dev(dev);
Tetsuo Handa75093152010-06-16 16:23:55 +09001048 r.param_type = TOMOYO_TYPE_MKDEV_ACL;
Tetsuo Handacf6e9a62010-06-16 16:21:36 +09001049 r.param.mkdev.filename = &buf;
1050 r.param.mkdev.operation = operation;
1051 r.param.mkdev.mode = mode;
1052 r.param.mkdev.major = MAJOR(dev);
1053 r.param.mkdev.minor = MINOR(dev);
Tetsuo Handa99a85252010-06-16 16:22:51 +09001054 tomoyo_check_acl(&r, tomoyo_check_mkdev_acl);
1055 error = tomoyo_audit_mkdev_log(&r);
Tetsuo Handac8c57e82010-06-03 20:36:43 +09001056 kfree(buf.name);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +09001057 }
1058 tomoyo_read_unlock(idx);
1059 if (r.mode != TOMOYO_CONFIG_ENFORCING)
1060 error = 0;
1061 return error;
1062}
1063
1064/**
Tetsuo Handa7ef61232010-02-16 08:03:30 +09001065 * tomoyo_path2_perm - Check permission for "rename", "link" and "pivot_root".
Kentaro Takedab69a54e2009-02-05 17:18:14 +09001066 *
Kentaro Takedab69a54e2009-02-05 17:18:14 +09001067 * @operation: Type of operation.
1068 * @path1: Pointer to "struct path".
1069 * @path2: Pointer to "struct path".
1070 *
1071 * Returns 0 on success, negative value otherwise.
1072 */
Tetsuo Handa97d69312010-02-16 09:46:15 +09001073int tomoyo_path2_perm(const u8 operation, struct path *path1,
Tetsuo Handa7ef61232010-02-16 08:03:30 +09001074 struct path *path2)
Kentaro Takedab69a54e2009-02-05 17:18:14 +09001075{
1076 int error = -ENOMEM;
Tetsuo Handac8c57e82010-06-03 20:36:43 +09001077 struct tomoyo_path_info buf1;
1078 struct tomoyo_path_info buf2;
Tetsuo Handacb0abe62010-05-17 10:08:05 +09001079 struct tomoyo_request_info r;
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +09001080 int idx;
Kentaro Takedab69a54e2009-02-05 17:18:14 +09001081
Tetsuo Handa57c25902010-06-03 20:38:44 +09001082 if (!path1->mnt || !path2->mnt ||
1083 tomoyo_init_request_info(&r, NULL, tomoyo_pp2mac[operation])
1084 == TOMOYO_CONFIG_DISABLED)
Kentaro Takedab69a54e2009-02-05 17:18:14 +09001085 return 0;
Tetsuo Handac8c57e82010-06-03 20:36:43 +09001086 buf1.name = NULL;
1087 buf2.name = NULL;
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +09001088 idx = tomoyo_read_lock();
Tetsuo Handac8c57e82010-06-03 20:36:43 +09001089 if (!tomoyo_get_realpath(&buf1, path1) ||
1090 !tomoyo_get_realpath(&buf2, path2))
Kentaro Takedab69a54e2009-02-05 17:18:14 +09001091 goto out;
Tetsuo Handa57c25902010-06-03 20:38:44 +09001092 switch (operation) {
1093 struct dentry *dentry;
1094 case TOMOYO_TYPE_RENAME:
1095 case TOMOYO_TYPE_LINK:
1096 dentry = path1->dentry;
1097 if (!dentry->d_inode || !S_ISDIR(dentry->d_inode->i_mode))
1098 break;
1099 /* fall through */
1100 case TOMOYO_TYPE_PIVOT_ROOT:
1101 tomoyo_add_slash(&buf1);
1102 tomoyo_add_slash(&buf2);
1103 break;
1104 }
Tetsuo Handacf6e9a62010-06-16 16:21:36 +09001105 r.param_type = TOMOYO_TYPE_PATH2_ACL;
1106 r.param.path2.operation = operation;
1107 r.param.path2.filename1 = &buf1;
1108 r.param.path2.filename2 = &buf2;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +09001109 do {
Tetsuo Handa99a85252010-06-16 16:22:51 +09001110 tomoyo_check_acl(&r, tomoyo_check_path2_acl);
1111 error = tomoyo_audit_path2_log(&r);
1112 } while (error == TOMOYO_RETRY_REQUEST);
Kentaro Takedab69a54e2009-02-05 17:18:14 +09001113 out:
Tetsuo Handac8c57e82010-06-03 20:36:43 +09001114 kfree(buf1.name);
1115 kfree(buf2.name);
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +09001116 tomoyo_read_unlock(idx);
Tetsuo Handacb0abe62010-05-17 10:08:05 +09001117 if (r.mode != TOMOYO_CONFIG_ENFORCING)
Kentaro Takedab69a54e2009-02-05 17:18:14 +09001118 error = 0;
1119 return error;
1120}
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +09001121
1122/**
Tetsuo Handae2bf6902010-06-25 11:16:00 +09001123 * tomoyo_write_file - Update file related list.
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +09001124 *
1125 * @data: String to parse.
1126 * @domain: Pointer to "struct tomoyo_domain_info".
1127 * @is_delete: True if it is a delete request.
1128 *
1129 * Returns 0 on success, negative value otherwise.
1130 *
1131 * Caller holds tomoyo_read_lock().
1132 */
Tetsuo Handae2bf6902010-06-25 11:16:00 +09001133int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain,
1134 const bool is_delete)
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +09001135{
1136 char *w[5];
1137 u8 type;
1138 if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[1][0])
1139 return -EINVAL;
Tetsuo Handa237ab452010-06-12 20:46:22 +09001140 if (strncmp(w[0], "allow_", 6))
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +09001141 goto out;
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +09001142 w[0] += 6;
1143 for (type = 0; type < TOMOYO_MAX_PATH_OPERATION; type++) {
1144 if (strcmp(w[0], tomoyo_path_keyword[type]))
1145 continue;
1146 return tomoyo_update_path_acl(type, w[1], domain, is_delete);
1147 }
1148 if (!w[2][0])
1149 goto out;
1150 for (type = 0; type < TOMOYO_MAX_PATH2_OPERATION; type++) {
1151 if (strcmp(w[0], tomoyo_path2_keyword[type]))
1152 continue;
1153 return tomoyo_update_path2_acl(type, w[1], w[2], domain,
1154 is_delete);
1155 }
1156 for (type = 0; type < TOMOYO_MAX_PATH_NUMBER_OPERATION; type++) {
1157 if (strcmp(w[0], tomoyo_path_number_keyword[type]))
1158 continue;
1159 return tomoyo_update_path_number_acl(type, w[1], w[2], domain,
1160 is_delete);
1161 }
1162 if (!w[3][0] || !w[4][0])
1163 goto out;
Tetsuo Handa75093152010-06-16 16:23:55 +09001164 for (type = 0; type < TOMOYO_MAX_MKDEV_OPERATION; type++) {
1165 if (strcmp(w[0], tomoyo_mkdev_keyword[type]))
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +09001166 continue;
Tetsuo Handa75093152010-06-16 16:23:55 +09001167 return tomoyo_update_mkdev_acl(type, w[1], w[2], w[3],
1168 w[4], domain, is_delete);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +09001169 }
1170 out:
1171 return -EINVAL;
1172}