2 * security/tomoyo/file.c
4 * Pathname restriction functions.
6 * Copyright (C) 2005-2010 NTT DATA CORPORATION
10 #include <linux/slab.h>
12 /* Keyword array for operations with one pathname. */
13 static const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION] = {
14 [TOMOYO_TYPE_READ_WRITE] = "read/write",
15 [TOMOYO_TYPE_EXECUTE] = "execute",
16 [TOMOYO_TYPE_READ] = "read",
17 [TOMOYO_TYPE_WRITE] = "write",
18 [TOMOYO_TYPE_UNLINK] = "unlink",
19 [TOMOYO_TYPE_RMDIR] = "rmdir",
20 [TOMOYO_TYPE_TRUNCATE] = "truncate",
21 [TOMOYO_TYPE_SYMLINK] = "symlink",
22 [TOMOYO_TYPE_REWRITE] = "rewrite",
23 [TOMOYO_TYPE_CHROOT] = "chroot",
24 [TOMOYO_TYPE_UMOUNT] = "unmount",
27 /* Keyword array for operations with one pathname and three numbers. */
28 static const char *tomoyo_path_number3_keyword
29 [TOMOYO_MAX_PATH_NUMBER3_OPERATION] = {
30 [TOMOYO_TYPE_MKBLOCK] = "mkblock",
31 [TOMOYO_TYPE_MKCHAR] = "mkchar",
34 /* Keyword array for operations with two pathnames. */
35 static const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION] = {
36 [TOMOYO_TYPE_LINK] = "link",
37 [TOMOYO_TYPE_RENAME] = "rename",
38 [TOMOYO_TYPE_PIVOT_ROOT] = "pivot_root",
41 /* Keyword array for operations with one pathname and one number. */
42 static const char *tomoyo_path_number_keyword
43 [TOMOYO_MAX_PATH_NUMBER_OPERATION] = {
44 [TOMOYO_TYPE_CREATE] = "create",
45 [TOMOYO_TYPE_MKDIR] = "mkdir",
46 [TOMOYO_TYPE_MKFIFO] = "mkfifo",
47 [TOMOYO_TYPE_MKSOCK] = "mksock",
48 [TOMOYO_TYPE_IOCTL] = "ioctl",
49 [TOMOYO_TYPE_CHMOD] = "chmod",
50 [TOMOYO_TYPE_CHOWN] = "chown",
51 [TOMOYO_TYPE_CHGRP] = "chgrp",
54 static const u8 tomoyo_p2mac[TOMOYO_MAX_PATH_OPERATION] = {
55 [TOMOYO_TYPE_READ_WRITE] = TOMOYO_MAC_FILE_OPEN,
56 [TOMOYO_TYPE_EXECUTE] = TOMOYO_MAC_FILE_EXECUTE,
57 [TOMOYO_TYPE_READ] = TOMOYO_MAC_FILE_OPEN,
58 [TOMOYO_TYPE_WRITE] = TOMOYO_MAC_FILE_OPEN,
59 [TOMOYO_TYPE_UNLINK] = TOMOYO_MAC_FILE_UNLINK,
60 [TOMOYO_TYPE_RMDIR] = TOMOYO_MAC_FILE_RMDIR,
61 [TOMOYO_TYPE_TRUNCATE] = TOMOYO_MAC_FILE_TRUNCATE,
62 [TOMOYO_TYPE_SYMLINK] = TOMOYO_MAC_FILE_SYMLINK,
63 [TOMOYO_TYPE_REWRITE] = TOMOYO_MAC_FILE_REWRITE,
64 [TOMOYO_TYPE_CHROOT] = TOMOYO_MAC_FILE_CHROOT,
65 [TOMOYO_TYPE_UMOUNT] = TOMOYO_MAC_FILE_UMOUNT,
68 static const u8 tomoyo_pnnn2mac[TOMOYO_MAX_PATH_NUMBER3_OPERATION] = {
69 [TOMOYO_TYPE_MKBLOCK] = TOMOYO_MAC_FILE_MKBLOCK,
70 [TOMOYO_TYPE_MKCHAR] = TOMOYO_MAC_FILE_MKCHAR,
73 static const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION] = {
74 [TOMOYO_TYPE_LINK] = TOMOYO_MAC_FILE_LINK,
75 [TOMOYO_TYPE_RENAME] = TOMOYO_MAC_FILE_RENAME,
76 [TOMOYO_TYPE_PIVOT_ROOT] = TOMOYO_MAC_FILE_PIVOT_ROOT,
79 static const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION] = {
80 [TOMOYO_TYPE_CREATE] = TOMOYO_MAC_FILE_CREATE,
81 [TOMOYO_TYPE_MKDIR] = TOMOYO_MAC_FILE_MKDIR,
82 [TOMOYO_TYPE_MKFIFO] = TOMOYO_MAC_FILE_MKFIFO,
83 [TOMOYO_TYPE_MKSOCK] = TOMOYO_MAC_FILE_MKSOCK,
84 [TOMOYO_TYPE_IOCTL] = TOMOYO_MAC_FILE_IOCTL,
85 [TOMOYO_TYPE_CHMOD] = TOMOYO_MAC_FILE_CHMOD,
86 [TOMOYO_TYPE_CHOWN] = TOMOYO_MAC_FILE_CHOWN,
87 [TOMOYO_TYPE_CHGRP] = TOMOYO_MAC_FILE_CHGRP,
90 void tomoyo_put_name_union(struct tomoyo_name_union *ptr)
95 tomoyo_put_path_group(ptr->group);
97 tomoyo_put_name(ptr->filename);
100 bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
101 const struct tomoyo_name_union *ptr)
104 return tomoyo_path_matches_group(name, ptr->group);
105 return tomoyo_path_matches_pattern(name, ptr->filename);
108 void tomoyo_put_number_union(struct tomoyo_number_union *ptr)
110 if (ptr && ptr->is_group)
111 tomoyo_put_number_group(ptr->group);
114 bool tomoyo_compare_number_union(const unsigned long value,
115 const struct tomoyo_number_union *ptr)
118 return tomoyo_number_matches_group(value, value, ptr->group);
119 return value >= ptr->values[0] && value <= ptr->values[1];
123 * tomoyo_path2keyword - Get the name of single path operation.
125 * @operation: Type of operation.
127 * Returns the name of single path operation.
129 const char *tomoyo_path2keyword(const u8 operation)
131 return (operation < TOMOYO_MAX_PATH_OPERATION)
132 ? tomoyo_path_keyword[operation] : NULL;
136 * tomoyo_path_number32keyword - Get the name of path/number/number/number operations.
138 * @operation: Type of operation.
140 * Returns the name of path/number/number/number operation.
142 const char *tomoyo_path_number32keyword(const u8 operation)
144 return (operation < TOMOYO_MAX_PATH_NUMBER3_OPERATION)
145 ? tomoyo_path_number3_keyword[operation] : NULL;
149 * tomoyo_path22keyword - Get the name of double path operation.
151 * @operation: Type of operation.
153 * Returns the name of double path operation.
155 const char *tomoyo_path22keyword(const u8 operation)
157 return (operation < TOMOYO_MAX_PATH2_OPERATION)
158 ? tomoyo_path2_keyword[operation] : NULL;
162 * tomoyo_path_number2keyword - Get the name of path/number operations.
164 * @operation: Type of operation.
166 * Returns the name of path/number operation.
168 const char *tomoyo_path_number2keyword(const u8 operation)
170 return (operation < TOMOYO_MAX_PATH_NUMBER_OPERATION)
171 ? tomoyo_path_number_keyword[operation] : NULL;
174 static void tomoyo_add_slash(struct tomoyo_path_info *buf)
179 * This is OK because tomoyo_encode() reserves space for appending "/".
181 strcat((char *) buf->name, "/");
182 tomoyo_fill_path_info(buf);
186 * tomoyo_strendswith - Check whether the token ends with the given token.
188 * @name: The token to check.
189 * @tail: The token to find.
191 * Returns true if @name ends with @tail, false otherwise.
193 static bool tomoyo_strendswith(const char *name, const char *tail)
199 len = strlen(name) - strlen(tail);
200 return len >= 0 && !strcmp(name + len, tail);
204 * tomoyo_get_realpath - Get realpath.
206 * @buf: Pointer to "struct tomoyo_path_info".
207 * @path: Pointer to "struct path".
209 * Returns true on success, false otherwise.
211 static bool tomoyo_get_realpath(struct tomoyo_path_info *buf, struct path *path)
213 buf->name = tomoyo_realpath_from_path(path);
215 tomoyo_fill_path_info(buf);
221 static int tomoyo_update_path2_acl(const u8 type, const char *filename1,
222 const char *filename2,
223 struct tomoyo_domain_info *const domain,
224 const bool is_delete);
225 static int tomoyo_update_path_acl(const u8 type, const char *filename,
226 struct tomoyo_domain_info *const domain,
227 const bool is_delete);
230 * tomoyo_globally_readable_list is used for holding list of pathnames which
231 * are by default allowed to be open()ed for reading by any process.
233 * An entry is added by
235 * # echo 'allow_read /lib/libc-2.5.so' > \
236 * /sys/kernel/security/tomoyo/exception_policy
240 * # echo 'delete allow_read /lib/libc-2.5.so' > \
241 * /sys/kernel/security/tomoyo/exception_policy
243 * and all entries are retrieved by
245 * # grep ^allow_read /sys/kernel/security/tomoyo/exception_policy
247 * In the example above, any process is allowed to
248 * open("/lib/libc-2.5.so", O_RDONLY).
249 * One exception is, if the domain which current process belongs to is marked
250 * as "ignore_global_allow_read", current process can't do so unless explicitly
251 * given "allow_read /lib/libc-2.5.so" to the domain which current process
254 LIST_HEAD(tomoyo_globally_readable_list);
257 * tomoyo_update_globally_readable_entry - Update "struct tomoyo_globally_readable_file_entry" list.
259 * @filename: Filename unconditionally permitted to open() for reading.
260 * @is_delete: True if it is a delete request.
262 * Returns 0 on success, negative value otherwise.
264 * Caller holds tomoyo_read_lock().
266 static int tomoyo_update_globally_readable_entry(const char *filename,
267 const bool is_delete)
269 struct tomoyo_globally_readable_file_entry *ptr;
270 struct tomoyo_globally_readable_file_entry e = { };
271 int error = is_delete ? -ENOENT : -ENOMEM;
273 if (!tomoyo_is_correct_word(filename))
275 e.filename = tomoyo_get_name(filename);
278 if (mutex_lock_interruptible(&tomoyo_policy_lock))
280 list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list,
282 if (ptr->filename != e.filename)
284 ptr->head.is_deleted = is_delete;
288 if (!is_delete && error) {
289 struct tomoyo_globally_readable_file_entry *entry =
290 tomoyo_commit_ok(&e, sizeof(e));
292 list_add_tail_rcu(&entry->head.list,
293 &tomoyo_globally_readable_list);
297 mutex_unlock(&tomoyo_policy_lock);
299 tomoyo_put_name(e.filename);
304 * tomoyo_is_globally_readable_file - Check if the file is unconditionnaly permitted to be open()ed for reading.
306 * @filename: The filename to check.
308 * Returns true if any domain can open @filename for reading, false otherwise.
310 * Caller holds tomoyo_read_lock().
312 static bool tomoyo_is_globally_readable_file(const struct tomoyo_path_info *
315 struct tomoyo_globally_readable_file_entry *ptr;
318 list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list,
320 if (!ptr->head.is_deleted &&
321 tomoyo_path_matches_pattern(filename, ptr->filename)) {
330 * tomoyo_write_globally_readable_policy - Write "struct tomoyo_globally_readable_file_entry" list.
332 * @data: String to parse.
333 * @is_delete: True if it is a delete request.
335 * Returns 0 on success, negative value otherwise.
337 * Caller holds tomoyo_read_lock().
339 int tomoyo_write_globally_readable_policy(char *data, const bool is_delete)
341 return tomoyo_update_globally_readable_entry(data, is_delete);
345 * tomoyo_read_globally_readable_policy - Read "struct tomoyo_globally_readable_file_entry" list.
347 * @head: Pointer to "struct tomoyo_io_buffer".
349 * Returns true on success, false otherwise.
351 * Caller holds tomoyo_read_lock().
353 bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head)
355 struct list_head *pos;
358 list_for_each_cookie(pos, head->read_var2,
359 &tomoyo_globally_readable_list) {
360 struct tomoyo_globally_readable_file_entry *ptr;
361 ptr = list_entry(pos,
362 struct tomoyo_globally_readable_file_entry,
364 if (ptr->head.is_deleted)
366 done = tomoyo_io_printf(head, TOMOYO_KEYWORD_ALLOW_READ "%s\n",
367 ptr->filename->name);
374 /* tomoyo_pattern_list is used for holding list of pathnames which are used for
375 * converting pathnames to pathname patterns during learning mode.
377 * An entry is added by
379 * # echo 'file_pattern /proc/\$/mounts' > \
380 * /sys/kernel/security/tomoyo/exception_policy
384 * # echo 'delete file_pattern /proc/\$/mounts' > \
385 * /sys/kernel/security/tomoyo/exception_policy
387 * and all entries are retrieved by
389 * # grep ^file_pattern /sys/kernel/security/tomoyo/exception_policy
391 * In the example above, if a process which belongs to a domain which is in
392 * learning mode requested open("/proc/1/mounts", O_RDONLY),
393 * "allow_read /proc/\$/mounts" is automatically added to the domain which that
394 * process belongs to.
396 * It is not a desirable behavior that we have to use /proc/\$/ instead of
397 * /proc/self/ when current process needs to access only current process's
398 * information. As of now, LSM version of TOMOYO is using __d_path() for
399 * calculating pathname. Non LSM version of TOMOYO is using its own function
400 * which pretends as if /proc/self/ is not a symlink; so that we can forbid
401 * current process from accessing other process's information.
403 LIST_HEAD(tomoyo_pattern_list);
406 * tomoyo_update_file_pattern_entry - Update "struct tomoyo_pattern_entry" list.
408 * @pattern: Pathname pattern.
409 * @is_delete: True if it is a delete request.
411 * Returns 0 on success, negative value otherwise.
413 * Caller holds tomoyo_read_lock().
415 static int tomoyo_update_file_pattern_entry(const char *pattern,
416 const bool is_delete)
418 struct tomoyo_pattern_entry *ptr;
419 struct tomoyo_pattern_entry e = { };
420 int error = is_delete ? -ENOENT : -ENOMEM;
422 if (!tomoyo_is_correct_word(pattern))
424 e.pattern = tomoyo_get_name(pattern);
427 if (mutex_lock_interruptible(&tomoyo_policy_lock))
429 list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, head.list) {
430 if (e.pattern != ptr->pattern)
432 ptr->head.is_deleted = is_delete;
436 if (!is_delete && error) {
437 struct tomoyo_pattern_entry *entry =
438 tomoyo_commit_ok(&e, sizeof(e));
440 list_add_tail_rcu(&entry->head.list,
441 &tomoyo_pattern_list);
445 mutex_unlock(&tomoyo_policy_lock);
447 tomoyo_put_name(e.pattern);
452 * tomoyo_file_pattern - Get patterned pathname.
454 * @filename: The filename to find patterned pathname.
456 * Returns pointer to pathname pattern if matched, @filename otherwise.
458 * Caller holds tomoyo_read_lock().
460 const char *tomoyo_file_pattern(const struct tomoyo_path_info *filename)
462 struct tomoyo_pattern_entry *ptr;
463 const struct tomoyo_path_info *pattern = NULL;
465 list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, head.list) {
466 if (ptr->head.is_deleted)
468 if (!tomoyo_path_matches_pattern(filename, ptr->pattern))
470 pattern = ptr->pattern;
471 if (tomoyo_strendswith(pattern->name, "/\\*")) {
472 /* Do nothing. Try to find the better match. */
474 /* This would be the better match. Use this. */
480 return filename->name;
484 * tomoyo_write_pattern_policy - Write "struct tomoyo_pattern_entry" list.
486 * @data: String to parse.
487 * @is_delete: True if it is a delete request.
489 * Returns 0 on success, negative value otherwise.
491 * Caller holds tomoyo_read_lock().
493 int tomoyo_write_pattern_policy(char *data, const bool is_delete)
495 return tomoyo_update_file_pattern_entry(data, is_delete);
499 * tomoyo_read_file_pattern - Read "struct tomoyo_pattern_entry" list.
501 * @head: Pointer to "struct tomoyo_io_buffer".
503 * Returns true on success, false otherwise.
505 * Caller holds tomoyo_read_lock().
507 bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head)
509 struct list_head *pos;
512 list_for_each_cookie(pos, head->read_var2, &tomoyo_pattern_list) {
513 struct tomoyo_pattern_entry *ptr;
514 ptr = list_entry(pos, struct tomoyo_pattern_entry, head.list);
515 if (ptr->head.is_deleted)
517 done = tomoyo_io_printf(head, TOMOYO_KEYWORD_FILE_PATTERN
518 "%s\n", ptr->pattern->name);
526 * tomoyo_no_rewrite_list is used for holding list of pathnames which are by
527 * default forbidden to modify already written content of a file.
529 * An entry is added by
531 * # echo 'deny_rewrite /var/log/messages' > \
532 * /sys/kernel/security/tomoyo/exception_policy
536 * # echo 'delete deny_rewrite /var/log/messages' > \
537 * /sys/kernel/security/tomoyo/exception_policy
539 * and all entries are retrieved by
541 * # grep ^deny_rewrite /sys/kernel/security/tomoyo/exception_policy
543 * In the example above, if a process requested to rewrite /var/log/messages ,
544 * the process can't rewrite unless the domain which that process belongs to
545 * has "allow_rewrite /var/log/messages" entry.
547 * It is not a desirable behavior that we have to add "\040(deleted)" suffix
548 * when we want to allow rewriting already unlink()ed file. As of now,
549 * LSM version of TOMOYO is using __d_path() for calculating pathname.
550 * Non LSM version of TOMOYO is using its own function which doesn't append
551 * " (deleted)" suffix if the file is already unlink()ed; so that we don't
552 * need to worry whether the file is already unlink()ed or not.
554 LIST_HEAD(tomoyo_no_rewrite_list);
557 * tomoyo_update_no_rewrite_entry - Update "struct tomoyo_no_rewrite_entry" list.
559 * @pattern: Pathname pattern that are not rewritable by default.
560 * @is_delete: True if it is a delete request.
562 * Returns 0 on success, negative value otherwise.
564 * Caller holds tomoyo_read_lock().
566 static int tomoyo_update_no_rewrite_entry(const char *pattern,
567 const bool is_delete)
569 struct tomoyo_no_rewrite_entry *ptr;
570 struct tomoyo_no_rewrite_entry e = { };
571 int error = is_delete ? -ENOENT : -ENOMEM;
573 if (!tomoyo_is_correct_word(pattern))
575 e.pattern = tomoyo_get_name(pattern);
578 if (mutex_lock_interruptible(&tomoyo_policy_lock))
580 list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list, head.list) {
581 if (ptr->pattern != e.pattern)
583 ptr->head.is_deleted = is_delete;
587 if (!is_delete && error) {
588 struct tomoyo_no_rewrite_entry *entry =
589 tomoyo_commit_ok(&e, sizeof(e));
591 list_add_tail_rcu(&entry->head.list,
592 &tomoyo_no_rewrite_list);
596 mutex_unlock(&tomoyo_policy_lock);
598 tomoyo_put_name(e.pattern);
603 * tomoyo_is_no_rewrite_file - Check if the given pathname is not permitted to be rewrited.
605 * @filename: Filename to check.
607 * Returns true if @filename is specified by "deny_rewrite" directive,
610 * Caller holds tomoyo_read_lock().
612 static bool tomoyo_is_no_rewrite_file(const struct tomoyo_path_info *filename)
614 struct tomoyo_no_rewrite_entry *ptr;
617 list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list, head.list) {
618 if (ptr->head.is_deleted)
620 if (!tomoyo_path_matches_pattern(filename, ptr->pattern))
629 * tomoyo_write_no_rewrite_policy - Write "struct tomoyo_no_rewrite_entry" list.
631 * @data: String to parse.
632 * @is_delete: True if it is a delete request.
634 * Returns 0 on success, negative value otherwise.
636 * Caller holds tomoyo_read_lock().
638 int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete)
640 return tomoyo_update_no_rewrite_entry(data, is_delete);
644 * tomoyo_read_no_rewrite_policy - Read "struct tomoyo_no_rewrite_entry" list.
646 * @head: Pointer to "struct tomoyo_io_buffer".
648 * Returns true on success, false otherwise.
650 * Caller holds tomoyo_read_lock().
652 bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head)
654 struct list_head *pos;
657 list_for_each_cookie(pos, head->read_var2, &tomoyo_no_rewrite_list) {
658 struct tomoyo_no_rewrite_entry *ptr;
659 ptr = list_entry(pos, struct tomoyo_no_rewrite_entry,
661 if (ptr->head.is_deleted)
663 done = tomoyo_io_printf(head, TOMOYO_KEYWORD_DENY_REWRITE
664 "%s\n", ptr->pattern->name);
672 * tomoyo_path_acl - Check permission for single path operation.
674 * @r: Pointer to "struct tomoyo_request_info".
675 * @filename: Filename to check.
678 * Returns 0 on success, -EPERM otherwise.
680 * Caller holds tomoyo_read_lock().
682 static int tomoyo_path_acl(const struct tomoyo_request_info *r,
683 const struct tomoyo_path_info *filename,
686 struct tomoyo_domain_info *domain = r->domain;
687 struct tomoyo_acl_info *ptr;
690 list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
691 struct tomoyo_path_acl *acl;
692 if (ptr->type != TOMOYO_TYPE_PATH_ACL)
694 acl = container_of(ptr, struct tomoyo_path_acl, head);
695 if (!(acl->perm & perm) ||
696 !tomoyo_compare_name_union(filename, &acl->name))
705 * tomoyo_file_perm - Check permission for opening files.
707 * @r: Pointer to "struct tomoyo_request_info".
708 * @filename: Filename to check.
709 * @mode: Mode ("read" or "write" or "read/write" or "execute").
711 * Returns 0 on success, negative value otherwise.
713 * Caller holds tomoyo_read_lock().
715 static int tomoyo_file_perm(struct tomoyo_request_info *r,
716 const struct tomoyo_path_info *filename,
719 const char *msg = "<unknown>";
727 msg = tomoyo_path2keyword(TOMOYO_TYPE_READ_WRITE);
728 perm = 1 << TOMOYO_TYPE_READ_WRITE;
729 } else if (mode == 4) {
730 msg = tomoyo_path2keyword(TOMOYO_TYPE_READ);
731 perm = 1 << TOMOYO_TYPE_READ;
732 } else if (mode == 2) {
733 msg = tomoyo_path2keyword(TOMOYO_TYPE_WRITE);
734 perm = 1 << TOMOYO_TYPE_WRITE;
735 } else if (mode == 1) {
736 msg = tomoyo_path2keyword(TOMOYO_TYPE_EXECUTE);
737 perm = 1 << TOMOYO_TYPE_EXECUTE;
741 error = tomoyo_path_acl(r, filename, perm);
742 if (error && mode == 4 && !r->domain->ignore_global_allow_read
743 && tomoyo_is_globally_readable_file(filename))
747 tomoyo_warn_log(r, "%s %s", msg, filename->name);
748 error = tomoyo_supervisor(r, "allow_%s %s\n", msg,
749 tomoyo_file_pattern(filename));
751 * Do not retry for execute request, for alias may have
754 } while (error == TOMOYO_RETRY_REQUEST && mode != 1);
755 if (r->mode != TOMOYO_CONFIG_ENFORCING)
760 static bool tomoyo_same_path_acl(const struct tomoyo_acl_info *a,
761 const struct tomoyo_acl_info *b)
763 const struct tomoyo_path_acl *p1 = container_of(a, typeof(*p1), head);
764 const struct tomoyo_path_acl *p2 = container_of(b, typeof(*p2), head);
765 return tomoyo_is_same_acl_head(&p1->head, &p2->head) &&
766 tomoyo_is_same_name_union(&p1->name, &p2->name);
769 static bool tomoyo_merge_path_acl(struct tomoyo_acl_info *a,
770 struct tomoyo_acl_info *b,
771 const bool is_delete)
773 u16 * const a_perm = &container_of(a, struct tomoyo_path_acl, head)
776 const u16 b_perm = container_of(b, struct tomoyo_path_acl, head)->perm;
779 if ((perm & TOMOYO_RW_MASK) != TOMOYO_RW_MASK)
780 perm &= ~(1 << TOMOYO_TYPE_READ_WRITE);
781 else if (!(perm & (1 << TOMOYO_TYPE_READ_WRITE)))
782 perm &= ~TOMOYO_RW_MASK;
785 if ((perm & TOMOYO_RW_MASK) == TOMOYO_RW_MASK)
786 perm |= (1 << TOMOYO_TYPE_READ_WRITE);
787 else if (perm & (1 << TOMOYO_TYPE_READ_WRITE))
788 perm |= TOMOYO_RW_MASK;
795 * tomoyo_update_path_acl - Update "struct tomoyo_path_acl" list.
797 * @type: Type of operation.
798 * @filename: Filename.
799 * @domain: Pointer to "struct tomoyo_domain_info".
800 * @is_delete: True if it is a delete request.
802 * Returns 0 on success, negative value otherwise.
804 * Caller holds tomoyo_read_lock().
806 static int tomoyo_update_path_acl(const u8 type, const char *filename,
807 struct tomoyo_domain_info * const domain,
808 const bool is_delete)
810 struct tomoyo_path_acl e = {
811 .head.type = TOMOYO_TYPE_PATH_ACL,
815 if (e.perm == (1 << TOMOYO_TYPE_READ_WRITE))
816 e.perm |= TOMOYO_RW_MASK;
817 if (!tomoyo_parse_name_union(filename, &e.name))
819 error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
820 tomoyo_same_path_acl,
821 tomoyo_merge_path_acl);
822 tomoyo_put_name_union(&e.name);
826 static bool tomoyo_same_path_number3_acl(const struct tomoyo_acl_info *a,
827 const struct tomoyo_acl_info *b)
829 const struct tomoyo_path_number3_acl *p1 = container_of(a, typeof(*p1),
831 const struct tomoyo_path_number3_acl *p2 = container_of(b, typeof(*p2),
833 return tomoyo_is_same_acl_head(&p1->head, &p2->head)
834 && tomoyo_is_same_name_union(&p1->name, &p2->name)
835 && tomoyo_is_same_number_union(&p1->mode, &p2->mode)
836 && tomoyo_is_same_number_union(&p1->major, &p2->major)
837 && tomoyo_is_same_number_union(&p1->minor, &p2->minor);
840 static bool tomoyo_merge_path_number3_acl(struct tomoyo_acl_info *a,
841 struct tomoyo_acl_info *b,
842 const bool is_delete)
844 u8 *const a_perm = &container_of(a, struct tomoyo_path_number3_acl,
847 const u8 b_perm = container_of(b, struct tomoyo_path_number3_acl, head)
858 * tomoyo_update_path_number3_acl - Update "struct tomoyo_path_number3_acl" list.
860 * @type: Type of operation.
861 * @filename: Filename.
862 * @mode: Create mode.
863 * @major: Device major number.
864 * @minor: Device minor number.
865 * @domain: Pointer to "struct tomoyo_domain_info".
866 * @is_delete: True if it is a delete request.
868 * Returns 0 on success, negative value otherwise.
870 * Caller holds tomoyo_read_lock().
872 static int tomoyo_update_path_number3_acl(const u8 type, const char *filename,
873 char *mode, char *major, char *minor,
874 struct tomoyo_domain_info * const
875 domain, const bool is_delete)
877 struct tomoyo_path_number3_acl e = {
878 .head.type = TOMOYO_TYPE_PATH_NUMBER3_ACL,
881 int error = is_delete ? -ENOENT : -ENOMEM;
882 if (!tomoyo_parse_name_union(filename, &e.name) ||
883 !tomoyo_parse_number_union(mode, &e.mode) ||
884 !tomoyo_parse_number_union(major, &e.major) ||
885 !tomoyo_parse_number_union(minor, &e.minor))
887 error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
888 tomoyo_same_path_number3_acl,
889 tomoyo_merge_path_number3_acl);
891 tomoyo_put_name_union(&e.name);
892 tomoyo_put_number_union(&e.mode);
893 tomoyo_put_number_union(&e.major);
894 tomoyo_put_number_union(&e.minor);
898 static bool tomoyo_same_path2_acl(const struct tomoyo_acl_info *a,
899 const struct tomoyo_acl_info *b)
901 const struct tomoyo_path2_acl *p1 = container_of(a, typeof(*p1), head);
902 const struct tomoyo_path2_acl *p2 = container_of(b, typeof(*p2), head);
903 return tomoyo_is_same_acl_head(&p1->head, &p2->head)
904 && tomoyo_is_same_name_union(&p1->name1, &p2->name1)
905 && tomoyo_is_same_name_union(&p1->name2, &p2->name2);
908 static bool tomoyo_merge_path2_acl(struct tomoyo_acl_info *a,
909 struct tomoyo_acl_info *b,
910 const bool is_delete)
912 u8 * const a_perm = &container_of(a, struct tomoyo_path2_acl, head)
915 const u8 b_perm = container_of(b, struct tomoyo_path2_acl, head)->perm;
925 * tomoyo_update_path2_acl - Update "struct tomoyo_path2_acl" list.
927 * @type: Type of operation.
928 * @filename1: First filename.
929 * @filename2: Second filename.
930 * @domain: Pointer to "struct tomoyo_domain_info".
931 * @is_delete: True if it is a delete request.
933 * Returns 0 on success, negative value otherwise.
935 * Caller holds tomoyo_read_lock().
937 static int tomoyo_update_path2_acl(const u8 type, const char *filename1,
938 const char *filename2,
939 struct tomoyo_domain_info * const domain,
940 const bool is_delete)
942 struct tomoyo_path2_acl e = {
943 .head.type = TOMOYO_TYPE_PATH2_ACL,
946 int error = is_delete ? -ENOENT : -ENOMEM;
947 if (!tomoyo_parse_name_union(filename1, &e.name1) ||
948 !tomoyo_parse_name_union(filename2, &e.name2))
950 error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
951 tomoyo_same_path2_acl,
952 tomoyo_merge_path2_acl);
954 tomoyo_put_name_union(&e.name1);
955 tomoyo_put_name_union(&e.name2);
960 * tomoyo_path_number3_acl - Check permission for path/number/number/number operation.
962 * @r: Pointer to "struct tomoyo_request_info".
963 * @filename: Filename to check.
965 * @mode: Create mode.
966 * @major: Device major number.
967 * @minor: Device minor number.
969 * Returns 0 on success, -EPERM otherwise.
971 * Caller holds tomoyo_read_lock().
973 static int tomoyo_path_number3_acl(struct tomoyo_request_info *r,
974 const struct tomoyo_path_info *filename,
975 const u16 perm, const unsigned int mode,
976 const unsigned int major,
977 const unsigned int minor)
979 struct tomoyo_domain_info *domain = r->domain;
980 struct tomoyo_acl_info *ptr;
982 list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
983 struct tomoyo_path_number3_acl *acl;
984 if (ptr->type != TOMOYO_TYPE_PATH_NUMBER3_ACL)
986 acl = container_of(ptr, struct tomoyo_path_number3_acl, head);
987 if (!tomoyo_compare_number_union(mode, &acl->mode))
989 if (!tomoyo_compare_number_union(major, &acl->major))
991 if (!tomoyo_compare_number_union(minor, &acl->minor))
993 if (!(acl->perm & perm))
995 if (!tomoyo_compare_name_union(filename, &acl->name))
1004 * tomoyo_path2_acl - Check permission for double path operation.
1006 * @r: Pointer to "struct tomoyo_request_info".
1007 * @type: Type of operation.
1008 * @filename1: First filename to check.
1009 * @filename2: Second filename to check.
1011 * Returns 0 on success, -EPERM otherwise.
1013 * Caller holds tomoyo_read_lock().
1015 static int tomoyo_path2_acl(const struct tomoyo_request_info *r, const u8 type,
1016 const struct tomoyo_path_info *filename1,
1017 const struct tomoyo_path_info *filename2)
1019 const struct tomoyo_domain_info *domain = r->domain;
1020 struct tomoyo_acl_info *ptr;
1021 const u8 perm = 1 << type;
1024 list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
1025 struct tomoyo_path2_acl *acl;
1026 if (ptr->type != TOMOYO_TYPE_PATH2_ACL)
1028 acl = container_of(ptr, struct tomoyo_path2_acl, head);
1029 if (!(acl->perm & perm))
1031 if (!tomoyo_compare_name_union(filename1, &acl->name1))
1033 if (!tomoyo_compare_name_union(filename2, &acl->name2))
1042 * tomoyo_path_permission - Check permission for single path operation.
1044 * @r: Pointer to "struct tomoyo_request_info".
1045 * @operation: Type of operation.
1046 * @filename: Filename to check.
1048 * Returns 0 on success, negative value otherwise.
1050 * Caller holds tomoyo_read_lock().
1052 static int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
1053 const struct tomoyo_path_info *filename)
1059 r->type = tomoyo_p2mac[operation];
1060 r->mode = tomoyo_get_mode(r->profile, r->type);
1061 if (r->mode == TOMOYO_CONFIG_DISABLED)
1064 error = tomoyo_path_acl(r, filename, 1 << operation);
1067 msg = tomoyo_path2keyword(operation);
1068 tomoyo_warn_log(r, "%s %s", msg, filename->name);
1069 error = tomoyo_supervisor(r, "allow_%s %s\n", msg,
1070 tomoyo_file_pattern(filename));
1071 } while (error == TOMOYO_RETRY_REQUEST);
1072 if (r->mode != TOMOYO_CONFIG_ENFORCING)
1075 * Since "allow_truncate" doesn't imply "allow_rewrite" permission,
1076 * we need to check "allow_rewrite" permission if the filename is
1077 * specified by "deny_rewrite" keyword.
1079 if (!error && operation == TOMOYO_TYPE_TRUNCATE &&
1080 tomoyo_is_no_rewrite_file(filename)) {
1081 operation = TOMOYO_TYPE_REWRITE;
1088 * tomoyo_path_number_acl - Check permission for ioctl/chmod/chown/chgrp operation.
1090 * @r: Pointer to "struct tomoyo_request_info".
1092 * @filename: Filename to check.
1095 * Returns 0 on success, -EPERM otherwise.
1097 * Caller holds tomoyo_read_lock().
1099 static int tomoyo_path_number_acl(struct tomoyo_request_info *r, const u8 type,
1100 const struct tomoyo_path_info *filename,
1101 const unsigned long number)
1103 struct tomoyo_domain_info *domain = r->domain;
1104 struct tomoyo_acl_info *ptr;
1105 const u8 perm = 1 << type;
1107 list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
1108 struct tomoyo_path_number_acl *acl;
1109 if (ptr->type != TOMOYO_TYPE_PATH_NUMBER_ACL)
1111 acl = container_of(ptr, struct tomoyo_path_number_acl,
1113 if (!(acl->perm & perm) ||
1114 !tomoyo_compare_number_union(number, &acl->number) ||
1115 !tomoyo_compare_name_union(filename, &acl->name))
1123 static bool tomoyo_same_path_number_acl(const struct tomoyo_acl_info *a,
1124 const struct tomoyo_acl_info *b)
1126 const struct tomoyo_path_number_acl *p1 = container_of(a, typeof(*p1),
1128 const struct tomoyo_path_number_acl *p2 = container_of(b, typeof(*p2),
1130 return tomoyo_is_same_acl_head(&p1->head, &p2->head)
1131 && tomoyo_is_same_name_union(&p1->name, &p2->name)
1132 && tomoyo_is_same_number_union(&p1->number, &p2->number);
1135 static bool tomoyo_merge_path_number_acl(struct tomoyo_acl_info *a,
1136 struct tomoyo_acl_info *b,
1137 const bool is_delete)
1139 u8 * const a_perm = &container_of(a, struct tomoyo_path_number_acl,
1142 const u8 b_perm = container_of(b, struct tomoyo_path_number_acl, head)
1153 * tomoyo_update_path_number_acl - Update ioctl/chmod/chown/chgrp ACL.
1155 * @type: Type of operation.
1156 * @filename: Filename.
1158 * @domain: Pointer to "struct tomoyo_domain_info".
1159 * @is_delete: True if it is a delete request.
1161 * Returns 0 on success, negative value otherwise.
1163 static int tomoyo_update_path_number_acl(const u8 type, const char *filename,
1165 struct tomoyo_domain_info * const
1167 const bool is_delete)
1169 struct tomoyo_path_number_acl e = {
1170 .head.type = TOMOYO_TYPE_PATH_NUMBER_ACL,
1173 int error = is_delete ? -ENOENT : -ENOMEM;
1174 if (!tomoyo_parse_name_union(filename, &e.name))
1176 if (!tomoyo_parse_number_union(number, &e.number))
1178 error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
1179 tomoyo_same_path_number_acl,
1180 tomoyo_merge_path_number_acl);
1182 tomoyo_put_name_union(&e.name);
1183 tomoyo_put_number_union(&e.number);
1188 * tomoyo_path_number_perm2 - Check permission for "create", "mkdir", "mkfifo", "mksock", "ioctl", "chmod", "chown", "chgrp".
1190 * @r: Pointer to "strct tomoyo_request_info".
1191 * @filename: Filename to check.
1194 * Returns 0 on success, negative value otherwise.
1196 * Caller holds tomoyo_read_lock().
1198 static int tomoyo_path_number_perm2(struct tomoyo_request_info *r,
1200 const struct tomoyo_path_info *filename,
1201 const unsigned long number)
1211 case TOMOYO_TYPE_CREATE:
1212 case TOMOYO_TYPE_MKDIR:
1213 case TOMOYO_TYPE_MKFIFO:
1214 case TOMOYO_TYPE_MKSOCK:
1215 case TOMOYO_TYPE_CHMOD:
1216 radix = TOMOYO_VALUE_TYPE_OCTAL;
1218 case TOMOYO_TYPE_IOCTL:
1219 radix = TOMOYO_VALUE_TYPE_HEXADECIMAL;
1222 radix = TOMOYO_VALUE_TYPE_DECIMAL;
1225 tomoyo_print_ulong(buffer, sizeof(buffer), number, radix);
1227 error = tomoyo_path_number_acl(r, type, filename, number);
1230 msg = tomoyo_path_number2keyword(type);
1231 tomoyo_warn_log(r, "%s %s %s", msg, filename->name, buffer);
1232 error = tomoyo_supervisor(r, "allow_%s %s %s\n", msg,
1233 tomoyo_file_pattern(filename),
1235 } while (error == TOMOYO_RETRY_REQUEST);
1236 if (r->mode != TOMOYO_CONFIG_ENFORCING)
1242 * tomoyo_path_number_perm - Check permission for "create", "mkdir", "mkfifo", "mksock", "ioctl", "chmod", "chown", "chgrp".
1244 * @type: Type of operation.
1245 * @path: Pointer to "struct path".
1248 * Returns 0 on success, negative value otherwise.
1250 int tomoyo_path_number_perm(const u8 type, struct path *path,
1251 unsigned long number)
1253 struct tomoyo_request_info r;
1254 int error = -ENOMEM;
1255 struct tomoyo_path_info buf;
1258 if (tomoyo_init_request_info(&r, NULL, tomoyo_pn2mac[type])
1259 == TOMOYO_CONFIG_DISABLED || !path->mnt || !path->dentry)
1261 idx = tomoyo_read_lock();
1262 if (!tomoyo_get_realpath(&buf, path))
1264 if (type == TOMOYO_TYPE_MKDIR)
1265 tomoyo_add_slash(&buf);
1266 error = tomoyo_path_number_perm2(&r, type, &buf, number);
1269 tomoyo_read_unlock(idx);
1270 if (r.mode != TOMOYO_CONFIG_ENFORCING)
1276 * tomoyo_check_exec_perm - Check permission for "execute".
1278 * @r: Pointer to "struct tomoyo_request_info".
1279 * @filename: Check permission for "execute".
1281 * Returns 0 on success, negativevalue otherwise.
1283 * Caller holds tomoyo_read_lock().
1285 int tomoyo_check_exec_perm(struct tomoyo_request_info *r,
1286 const struct tomoyo_path_info *filename)
1288 if (r->mode == TOMOYO_CONFIG_DISABLED)
1290 return tomoyo_file_perm(r, filename, 1);
1294 * tomoyo_check_open_permission - Check permission for "read" and "write".
1296 * @domain: Pointer to "struct tomoyo_domain_info".
1297 * @path: Pointer to "struct path".
1298 * @flag: Flags for open().
1300 * Returns 0 on success, negative value otherwise.
1302 int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
1303 struct path *path, const int flag)
1305 const u8 acc_mode = ACC_MODE(flag);
1306 int error = -ENOMEM;
1307 struct tomoyo_path_info buf;
1308 struct tomoyo_request_info r;
1312 (path->dentry->d_inode && S_ISDIR(path->dentry->d_inode->i_mode)))
1315 r.mode = TOMOYO_CONFIG_DISABLED;
1316 idx = tomoyo_read_lock();
1317 if (!tomoyo_get_realpath(&buf, path))
1321 * If the filename is specified by "deny_rewrite" keyword,
1322 * we need to check "allow_rewrite" permission when the filename is not
1323 * opened for append mode or the filename is truncated at open time.
1325 if ((acc_mode & MAY_WRITE) && !(flag & O_APPEND)
1326 && tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_REWRITE)
1327 != TOMOYO_CONFIG_DISABLED) {
1328 if (!tomoyo_get_realpath(&buf, path)) {
1332 if (tomoyo_is_no_rewrite_file(&buf))
1333 error = tomoyo_path_permission(&r, TOMOYO_TYPE_REWRITE,
1336 if (!error && acc_mode &&
1337 tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_OPEN)
1338 != TOMOYO_CONFIG_DISABLED) {
1339 if (!buf.name && !tomoyo_get_realpath(&buf, path)) {
1343 error = tomoyo_file_perm(&r, &buf, acc_mode);
1347 tomoyo_read_unlock(idx);
1348 if (r.mode != TOMOYO_CONFIG_ENFORCING)
1354 * tomoyo_path_perm - Check permission for "unlink", "rmdir", "truncate", "symlink", "rewrite", "chroot" and "unmount".
1356 * @operation: Type of operation.
1357 * @path: Pointer to "struct path".
1359 * Returns 0 on success, negative value otherwise.
1361 int tomoyo_path_perm(const u8 operation, struct path *path)
1363 int error = -ENOMEM;
1364 struct tomoyo_path_info buf;
1365 struct tomoyo_request_info r;
1370 if (tomoyo_init_request_info(&r, NULL, tomoyo_p2mac[operation])
1371 == TOMOYO_CONFIG_DISABLED)
1374 idx = tomoyo_read_lock();
1375 if (!tomoyo_get_realpath(&buf, path))
1377 switch (operation) {
1378 case TOMOYO_TYPE_REWRITE:
1379 if (!tomoyo_is_no_rewrite_file(&buf)) {
1384 case TOMOYO_TYPE_RMDIR:
1385 case TOMOYO_TYPE_CHROOT:
1386 case TOMOYO_TYPE_UMOUNT:
1387 tomoyo_add_slash(&buf);
1390 error = tomoyo_path_permission(&r, operation, &buf);
1393 tomoyo_read_unlock(idx);
1394 if (r.mode != TOMOYO_CONFIG_ENFORCING)
1400 * tomoyo_path_number3_perm2 - Check permission for path/number/number/number operation.
1402 * @r: Pointer to "struct tomoyo_request_info".
1403 * @operation: Type of operation.
1404 * @filename: Filename to check.
1405 * @mode: Create mode.
1406 * @dev: Device number.
1408 * Returns 0 on success, negative value otherwise.
1410 * Caller holds tomoyo_read_lock().
1412 static int tomoyo_path_number3_perm2(struct tomoyo_request_info *r,
1414 const struct tomoyo_path_info *filename,
1415 const unsigned int mode,
1416 const unsigned int dev)
1420 const unsigned int major = MAJOR(dev);
1421 const unsigned int minor = MINOR(dev);
1424 error = tomoyo_path_number3_acl(r, filename, 1 << operation,
1425 mode, major, minor);
1428 msg = tomoyo_path_number32keyword(operation);
1429 tomoyo_warn_log(r, "%s %s 0%o %u %u", msg, filename->name,
1430 mode, major, minor);
1431 error = tomoyo_supervisor(r, "allow_%s %s 0%o %u %u\n", msg,
1432 tomoyo_file_pattern(filename), mode,
1434 } while (error == TOMOYO_RETRY_REQUEST);
1435 if (r->mode != TOMOYO_CONFIG_ENFORCING)
1441 * tomoyo_path_number3_perm - Check permission for "mkblock" and "mkchar".
1443 * @operation: Type of operation. (TOMOYO_TYPE_MKCHAR or TOMOYO_TYPE_MKBLOCK)
1444 * @path: Pointer to "struct path".
1445 * @mode: Create mode.
1446 * @dev: Device number.
1448 * Returns 0 on success, negative value otherwise.
1450 int tomoyo_path_number3_perm(const u8 operation, struct path *path,
1451 const unsigned int mode, unsigned int dev)
1453 struct tomoyo_request_info r;
1454 int error = -ENOMEM;
1455 struct tomoyo_path_info buf;
1459 tomoyo_init_request_info(&r, NULL, tomoyo_pnnn2mac[operation])
1460 == TOMOYO_CONFIG_DISABLED)
1462 idx = tomoyo_read_lock();
1464 if (tomoyo_get_realpath(&buf, path)) {
1465 error = tomoyo_path_number3_perm2(&r, operation, &buf, mode,
1466 new_decode_dev(dev));
1469 tomoyo_read_unlock(idx);
1470 if (r.mode != TOMOYO_CONFIG_ENFORCING)
1476 * tomoyo_path2_perm - Check permission for "rename", "link" and "pivot_root".
1478 * @operation: Type of operation.
1479 * @path1: Pointer to "struct path".
1480 * @path2: Pointer to "struct path".
1482 * Returns 0 on success, negative value otherwise.
1484 int tomoyo_path2_perm(const u8 operation, struct path *path1,
1487 int error = -ENOMEM;
1489 struct tomoyo_path_info buf1;
1490 struct tomoyo_path_info buf2;
1491 struct tomoyo_request_info r;
1494 if (!path1->mnt || !path2->mnt ||
1495 tomoyo_init_request_info(&r, NULL, tomoyo_pp2mac[operation])
1496 == TOMOYO_CONFIG_DISABLED)
1500 idx = tomoyo_read_lock();
1501 if (!tomoyo_get_realpath(&buf1, path1) ||
1502 !tomoyo_get_realpath(&buf2, path2))
1504 switch (operation) {
1505 struct dentry *dentry;
1506 case TOMOYO_TYPE_RENAME:
1507 case TOMOYO_TYPE_LINK:
1508 dentry = path1->dentry;
1509 if (!dentry->d_inode || !S_ISDIR(dentry->d_inode->i_mode))
1512 case TOMOYO_TYPE_PIVOT_ROOT:
1513 tomoyo_add_slash(&buf1);
1514 tomoyo_add_slash(&buf2);
1518 error = tomoyo_path2_acl(&r, operation, &buf1, &buf2);
1521 msg = tomoyo_path22keyword(operation);
1522 tomoyo_warn_log(&r, "%s %s %s", msg, buf1.name, buf2.name);
1523 error = tomoyo_supervisor(&r, "allow_%s %s %s\n", msg,
1524 tomoyo_file_pattern(&buf1),
1525 tomoyo_file_pattern(&buf2));
1526 } while (error == TOMOYO_RETRY_REQUEST);
1530 tomoyo_read_unlock(idx);
1531 if (r.mode != TOMOYO_CONFIG_ENFORCING)
1537 * tomoyo_write_file_policy - Update file related list.
1539 * @data: String to parse.
1540 * @domain: Pointer to "struct tomoyo_domain_info".
1541 * @is_delete: True if it is a delete request.
1543 * Returns 0 on success, negative value otherwise.
1545 * Caller holds tomoyo_read_lock().
1547 int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain,
1548 const bool is_delete)
1552 if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[1][0])
1554 if (strncmp(w[0], "allow_", 6))
1557 for (type = 0; type < TOMOYO_MAX_PATH_OPERATION; type++) {
1558 if (strcmp(w[0], tomoyo_path_keyword[type]))
1560 return tomoyo_update_path_acl(type, w[1], domain, is_delete);
1564 for (type = 0; type < TOMOYO_MAX_PATH2_OPERATION; type++) {
1565 if (strcmp(w[0], tomoyo_path2_keyword[type]))
1567 return tomoyo_update_path2_acl(type, w[1], w[2], domain,
1570 for (type = 0; type < TOMOYO_MAX_PATH_NUMBER_OPERATION; type++) {
1571 if (strcmp(w[0], tomoyo_path_number_keyword[type]))
1573 return tomoyo_update_path_number_acl(type, w[1], w[2], domain,
1576 if (!w[3][0] || !w[4][0])
1578 for (type = 0; type < TOMOYO_MAX_PATH_NUMBER3_OPERATION; type++) {
1579 if (strcmp(w[0], tomoyo_path_number3_keyword[type]))
1581 return tomoyo_update_path_number3_acl(type, w[1], w[2], w[3],
1582 w[4], domain, is_delete);