diff options
author | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2010-06-24 22:16:00 -0400 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2010-08-02 01:34:54 -0400 |
commit | e2bf69077acefee5247bb661faac2552d29ba7ba (patch) | |
tree | 946adb588df8647f2476fb2f66996e6231521687 /security/tomoyo/common.c | |
parent | 8e5686874bcb882f69d5c04e6b38dc92b97facea (diff) |
TOMOYO: Rename symbols.
Use shorter name in order to make it easier to fit 80 columns limit.
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security/tomoyo/common.c')
-rw-r--r-- | security/tomoyo/common.c | 226 |
1 files changed, 100 insertions, 126 deletions
diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c index 30e4b08905e3..65c18af3ffe5 100644 --- a/security/tomoyo/common.c +++ b/security/tomoyo/common.c | |||
@@ -248,14 +248,13 @@ static void tomoyo_print_number_union(struct tomoyo_io_buffer *head, | |||
248 | } | 248 | } |
249 | 249 | ||
250 | /** | 250 | /** |
251 | * tomoyo_find_or_assign_new_profile - Create a new profile. | 251 | * tomoyo_assign_profile - Create a new profile. |
252 | * | 252 | * |
253 | * @profile: Profile number to create. | 253 | * @profile: Profile number to create. |
254 | * | 254 | * |
255 | * Returns pointer to "struct tomoyo_profile" on success, NULL otherwise. | 255 | * Returns pointer to "struct tomoyo_profile" on success, NULL otherwise. |
256 | */ | 256 | */ |
257 | static struct tomoyo_profile *tomoyo_find_or_assign_new_profile | 257 | static struct tomoyo_profile *tomoyo_assign_profile(const unsigned int profile) |
258 | (const unsigned int profile) | ||
259 | { | 258 | { |
260 | struct tomoyo_profile *ptr; | 259 | struct tomoyo_profile *ptr; |
261 | struct tomoyo_profile *entry; | 260 | struct tomoyo_profile *entry; |
@@ -443,7 +442,7 @@ static int tomoyo_write_profile(struct tomoyo_io_buffer *head) | |||
443 | if (*cp != '-') | 442 | if (*cp != '-') |
444 | return -EINVAL; | 443 | return -EINVAL; |
445 | data = cp + 1; | 444 | data = cp + 1; |
446 | profile = tomoyo_find_or_assign_new_profile(i); | 445 | profile = tomoyo_assign_profile(i); |
447 | if (!profile) | 446 | if (!profile) |
448 | return -EINVAL; | 447 | return -EINVAL; |
449 | } | 448 | } |
@@ -584,13 +583,11 @@ static void tomoyo_read_profile(struct tomoyo_io_buffer *head) | |||
584 | goto next; | 583 | goto next; |
585 | } | 584 | } |
586 | 585 | ||
587 | static bool tomoyo_same_manager_entry(const struct tomoyo_acl_head *a, | 586 | static bool tomoyo_same_manager(const struct tomoyo_acl_head *a, |
588 | const struct tomoyo_acl_head *b) | 587 | const struct tomoyo_acl_head *b) |
589 | { | 588 | { |
590 | return container_of(a, struct tomoyo_policy_manager_entry, head) | 589 | return container_of(a, struct tomoyo_manager, head)->manager == |
591 | ->manager == | 590 | container_of(b, struct tomoyo_manager, head)->manager; |
592 | container_of(b, struct tomoyo_policy_manager_entry, head) | ||
593 | ->manager; | ||
594 | } | 591 | } |
595 | 592 | ||
596 | /** | 593 | /** |
@@ -606,7 +603,7 @@ static bool tomoyo_same_manager_entry(const struct tomoyo_acl_head *a, | |||
606 | static int tomoyo_update_manager_entry(const char *manager, | 603 | static int tomoyo_update_manager_entry(const char *manager, |
607 | const bool is_delete) | 604 | const bool is_delete) |
608 | { | 605 | { |
609 | struct tomoyo_policy_manager_entry e = { }; | 606 | struct tomoyo_manager e = { }; |
610 | int error; | 607 | int error; |
611 | 608 | ||
612 | if (tomoyo_domain_def(manager)) { | 609 | if (tomoyo_domain_def(manager)) { |
@@ -622,13 +619,13 @@ static int tomoyo_update_manager_entry(const char *manager, | |||
622 | return -ENOMEM; | 619 | return -ENOMEM; |
623 | error = tomoyo_update_policy(&e.head, sizeof(e), is_delete, | 620 | error = tomoyo_update_policy(&e.head, sizeof(e), is_delete, |
624 | &tomoyo_policy_list[TOMOYO_ID_MANAGER], | 621 | &tomoyo_policy_list[TOMOYO_ID_MANAGER], |
625 | tomoyo_same_manager_entry); | 622 | tomoyo_same_manager); |
626 | tomoyo_put_name(e.manager); | 623 | tomoyo_put_name(e.manager); |
627 | return error; | 624 | return error; |
628 | } | 625 | } |
629 | 626 | ||
630 | /** | 627 | /** |
631 | * tomoyo_write_manager_policy - Write manager policy. | 628 | * tomoyo_write_manager - Write manager policy. |
632 | * | 629 | * |
633 | * @head: Pointer to "struct tomoyo_io_buffer". | 630 | * @head: Pointer to "struct tomoyo_io_buffer". |
634 | * | 631 | * |
@@ -636,7 +633,7 @@ static int tomoyo_update_manager_entry(const char *manager, | |||
636 | * | 633 | * |
637 | * Caller holds tomoyo_read_lock(). | 634 | * Caller holds tomoyo_read_lock(). |
638 | */ | 635 | */ |
639 | static int tomoyo_write_manager_policy(struct tomoyo_io_buffer *head) | 636 | static int tomoyo_write_manager(struct tomoyo_io_buffer *head) |
640 | { | 637 | { |
641 | char *data = head->write_buf; | 638 | char *data = head->write_buf; |
642 | bool is_delete = tomoyo_str_starts(&data, TOMOYO_KEYWORD_DELETE); | 639 | bool is_delete = tomoyo_str_starts(&data, TOMOYO_KEYWORD_DELETE); |
@@ -649,19 +646,19 @@ static int tomoyo_write_manager_policy(struct tomoyo_io_buffer *head) | |||
649 | } | 646 | } |
650 | 647 | ||
651 | /** | 648 | /** |
652 | * tomoyo_read_manager_policy - Read manager policy. | 649 | * tomoyo_read_manager - Read manager policy. |
653 | * | 650 | * |
654 | * @head: Pointer to "struct tomoyo_io_buffer". | 651 | * @head: Pointer to "struct tomoyo_io_buffer". |
655 | * | 652 | * |
656 | * Caller holds tomoyo_read_lock(). | 653 | * Caller holds tomoyo_read_lock(). |
657 | */ | 654 | */ |
658 | static void tomoyo_read_manager_policy(struct tomoyo_io_buffer *head) | 655 | static void tomoyo_read_manager(struct tomoyo_io_buffer *head) |
659 | { | 656 | { |
660 | if (head->r.eof) | 657 | if (head->r.eof) |
661 | return; | 658 | return; |
662 | list_for_each_cookie(head->r.acl, | 659 | list_for_each_cookie(head->r.acl, |
663 | &tomoyo_policy_list[TOMOYO_ID_MANAGER]) { | 660 | &tomoyo_policy_list[TOMOYO_ID_MANAGER]) { |
664 | struct tomoyo_policy_manager_entry *ptr = | 661 | struct tomoyo_manager *ptr = |
665 | list_entry(head->r.acl, typeof(*ptr), head.list); | 662 | list_entry(head->r.acl, typeof(*ptr), head.list); |
666 | if (ptr->head.is_deleted) | 663 | if (ptr->head.is_deleted) |
667 | continue; | 664 | continue; |
@@ -674,16 +671,16 @@ static void tomoyo_read_manager_policy(struct tomoyo_io_buffer *head) | |||
674 | } | 671 | } |
675 | 672 | ||
676 | /** | 673 | /** |
677 | * tomoyo_policy_manager - Check whether the current process is a policy manager. | 674 | * tomoyo_manager - Check whether the current process is a policy manager. |
678 | * | 675 | * |
679 | * Returns true if the current process is permitted to modify policy | 676 | * Returns true if the current process is permitted to modify policy |
680 | * via /sys/kernel/security/tomoyo/ interface. | 677 | * via /sys/kernel/security/tomoyo/ interface. |
681 | * | 678 | * |
682 | * Caller holds tomoyo_read_lock(). | 679 | * Caller holds tomoyo_read_lock(). |
683 | */ | 680 | */ |
684 | static bool tomoyo_policy_manager(void) | 681 | static bool tomoyo_manager(void) |
685 | { | 682 | { |
686 | struct tomoyo_policy_manager_entry *ptr; | 683 | struct tomoyo_manager *ptr; |
687 | const char *exe; | 684 | const char *exe; |
688 | const struct task_struct *task = current; | 685 | const struct task_struct *task = current; |
689 | const struct tomoyo_path_info *domainname = tomoyo_domain()->domainname; | 686 | const struct tomoyo_path_info *domainname = tomoyo_domain()->domainname; |
@@ -813,7 +810,7 @@ static int tomoyo_delete_domain(char *domainname) | |||
813 | } | 810 | } |
814 | 811 | ||
815 | /** | 812 | /** |
816 | * tomoyo_write_domain_policy2 - Write domain policy. | 813 | * tomoyo_write_domain2 - Write domain policy. |
817 | * | 814 | * |
818 | * @head: Pointer to "struct tomoyo_io_buffer". | 815 | * @head: Pointer to "struct tomoyo_io_buffer". |
819 | * | 816 | * |
@@ -821,17 +818,16 @@ static int tomoyo_delete_domain(char *domainname) | |||
821 | * | 818 | * |
822 | * Caller holds tomoyo_read_lock(). | 819 | * Caller holds tomoyo_read_lock(). |
823 | */ | 820 | */ |
824 | static int tomoyo_write_domain_policy2(char *data, | 821 | static int tomoyo_write_domain2(char *data, struct tomoyo_domain_info *domain, |
825 | struct tomoyo_domain_info *domain, | 822 | const bool is_delete) |
826 | const bool is_delete) | ||
827 | { | 823 | { |
828 | if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_ALLOW_MOUNT)) | 824 | if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_ALLOW_MOUNT)) |
829 | return tomoyo_write_mount_policy(data, domain, is_delete); | 825 | return tomoyo_write_mount(data, domain, is_delete); |
830 | return tomoyo_write_file_policy(data, domain, is_delete); | 826 | return tomoyo_write_file(data, domain, is_delete); |
831 | } | 827 | } |
832 | 828 | ||
833 | /** | 829 | /** |
834 | * tomoyo_write_domain_policy - Write domain policy. | 830 | * tomoyo_write_domain - Write domain policy. |
835 | * | 831 | * |
836 | * @head: Pointer to "struct tomoyo_io_buffer". | 832 | * @head: Pointer to "struct tomoyo_io_buffer". |
837 | * | 833 | * |
@@ -839,7 +835,7 @@ static int tomoyo_write_domain_policy2(char *data, | |||
839 | * | 835 | * |
840 | * Caller holds tomoyo_read_lock(). | 836 | * Caller holds tomoyo_read_lock(). |
841 | */ | 837 | */ |
842 | static int tomoyo_write_domain_policy(struct tomoyo_io_buffer *head) | 838 | static int tomoyo_write_domain(struct tomoyo_io_buffer *head) |
843 | { | 839 | { |
844 | char *data = head->write_buf; | 840 | char *data = head->write_buf; |
845 | struct tomoyo_domain_info *domain = head->write_var1; | 841 | struct tomoyo_domain_info *domain = head->write_var1; |
@@ -854,7 +850,7 @@ static int tomoyo_write_domain_policy(struct tomoyo_io_buffer *head) | |||
854 | if (is_select && tomoyo_select_one(head, data)) | 850 | if (is_select && tomoyo_select_one(head, data)) |
855 | return 0; | 851 | return 0; |
856 | /* Don't allow updating policies by non manager programs. */ | 852 | /* Don't allow updating policies by non manager programs. */ |
857 | if (!tomoyo_policy_manager()) | 853 | if (!tomoyo_manager()) |
858 | return -EPERM; | 854 | return -EPERM; |
859 | if (tomoyo_domain_def(data)) { | 855 | if (tomoyo_domain_def(data)) { |
860 | domain = NULL; | 856 | domain = NULL; |
@@ -863,7 +859,7 @@ static int tomoyo_write_domain_policy(struct tomoyo_io_buffer *head) | |||
863 | else if (is_select) | 859 | else if (is_select) |
864 | domain = tomoyo_find_domain(data); | 860 | domain = tomoyo_find_domain(data); |
865 | else | 861 | else |
866 | domain = tomoyo_find_or_assign_new_domain(data, 0); | 862 | domain = tomoyo_assign_domain(data, 0); |
867 | head->write_var1 = domain; | 863 | head->write_var1 = domain; |
868 | return 0; | 864 | return 0; |
869 | } | 865 | } |
@@ -888,7 +884,7 @@ static int tomoyo_write_domain_policy(struct tomoyo_io_buffer *head) | |||
888 | domain->transition_failed = !is_delete; | 884 | domain->transition_failed = !is_delete; |
889 | return 0; | 885 | return 0; |
890 | } | 886 | } |
891 | return tomoyo_write_domain_policy2(data, domain, is_delete); | 887 | return tomoyo_write_domain2(data, domain, is_delete); |
892 | } | 888 | } |
893 | 889 | ||
894 | /** | 890 | /** |
@@ -1022,13 +1018,13 @@ static bool tomoyo_read_domain2(struct tomoyo_io_buffer *head, | |||
1022 | } | 1018 | } |
1023 | 1019 | ||
1024 | /** | 1020 | /** |
1025 | * tomoyo_read_domain_policy - Read domain policy. | 1021 | * tomoyo_read_domain - Read domain policy. |
1026 | * | 1022 | * |
1027 | * @head: Pointer to "struct tomoyo_io_buffer". | 1023 | * @head: Pointer to "struct tomoyo_io_buffer". |
1028 | * | 1024 | * |
1029 | * Caller holds tomoyo_read_lock(). | 1025 | * Caller holds tomoyo_read_lock(). |
1030 | */ | 1026 | */ |
1031 | static void tomoyo_read_domain_policy(struct tomoyo_io_buffer *head) | 1027 | static void tomoyo_read_domain(struct tomoyo_io_buffer *head) |
1032 | { | 1028 | { |
1033 | if (head->r.eof) | 1029 | if (head->r.eof) |
1034 | return; | 1030 | return; |
@@ -1208,8 +1204,13 @@ static const char *tomoyo_transition_type[TOMOYO_MAX_TRANSITION_TYPE] = { | |||
1208 | [TOMOYO_TRANSITION_CONTROL_KEEP] = TOMOYO_KEYWORD_KEEP_DOMAIN | 1204 | [TOMOYO_TRANSITION_CONTROL_KEEP] = TOMOYO_KEYWORD_KEEP_DOMAIN |
1209 | }; | 1205 | }; |
1210 | 1206 | ||
1207 | static const char *tomoyo_group_name[TOMOYO_MAX_GROUP] = { | ||
1208 | [TOMOYO_PATH_GROUP] = TOMOYO_KEYWORD_PATH_GROUP, | ||
1209 | [TOMOYO_NUMBER_GROUP] = TOMOYO_KEYWORD_NUMBER_GROUP | ||
1210 | }; | ||
1211 | |||
1211 | /** | 1212 | /** |
1212 | * tomoyo_write_exception_policy - Write exception policy. | 1213 | * tomoyo_write_exception - Write exception policy. |
1213 | * | 1214 | * |
1214 | * @head: Pointer to "struct tomoyo_io_buffer". | 1215 | * @head: Pointer to "struct tomoyo_io_buffer". |
1215 | * | 1216 | * |
@@ -1217,37 +1218,34 @@ static const char *tomoyo_transition_type[TOMOYO_MAX_TRANSITION_TYPE] = { | |||
1217 | * | 1218 | * |
1218 | * Caller holds tomoyo_read_lock(). | 1219 | * Caller holds tomoyo_read_lock(). |
1219 | */ | 1220 | */ |
1220 | static int tomoyo_write_exception_policy(struct tomoyo_io_buffer *head) | 1221 | static int tomoyo_write_exception(struct tomoyo_io_buffer *head) |
1221 | { | 1222 | { |
1222 | char *data = head->write_buf; | 1223 | char *data = head->write_buf; |
1223 | bool is_delete = tomoyo_str_starts(&data, TOMOYO_KEYWORD_DELETE); | 1224 | bool is_delete = tomoyo_str_starts(&data, TOMOYO_KEYWORD_DELETE); |
1224 | u8 i; | 1225 | u8 i; |
1225 | 1226 | static const struct { | |
1226 | for (i = 0; i < TOMOYO_MAX_TRANSITION_TYPE; i++) { | 1227 | const char *keyword; |
1228 | int (*write) (char *, const bool); | ||
1229 | } tomoyo_callback[4] = { | ||
1230 | { TOMOYO_KEYWORD_AGGREGATOR, tomoyo_write_aggregator }, | ||
1231 | { TOMOYO_KEYWORD_FILE_PATTERN, tomoyo_write_pattern }, | ||
1232 | { TOMOYO_KEYWORD_DENY_REWRITE, tomoyo_write_no_rewrite }, | ||
1233 | { TOMOYO_KEYWORD_ALLOW_READ, tomoyo_write_globally_readable }, | ||
1234 | }; | ||
1235 | |||
1236 | for (i = 0; i < TOMOYO_MAX_TRANSITION_TYPE; i++) | ||
1227 | if (tomoyo_str_starts(&data, tomoyo_transition_type[i])) | 1237 | if (tomoyo_str_starts(&data, tomoyo_transition_type[i])) |
1228 | return tomoyo_write_transition_control(data, is_delete, | 1238 | return tomoyo_write_transition_control(data, is_delete, |
1229 | i); | 1239 | i); |
1230 | } | 1240 | for (i = 0; i < 4; i++) |
1231 | if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_AGGREGATOR)) | 1241 | if (tomoyo_str_starts(&data, tomoyo_callback[i].keyword)) |
1232 | return tomoyo_write_aggregator_policy(data, is_delete); | 1242 | return tomoyo_callback[i].write(data, is_delete); |
1233 | if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_ALLOW_READ)) | 1243 | for (i = 0; i < TOMOYO_MAX_GROUP; i++) |
1234 | return tomoyo_write_globally_readable_policy(data, is_delete); | 1244 | if (tomoyo_str_starts(&data, tomoyo_group_name[i])) |
1235 | if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_FILE_PATTERN)) | 1245 | return tomoyo_write_group(data, is_delete, i); |
1236 | return tomoyo_write_pattern_policy(data, is_delete); | ||
1237 | if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_DENY_REWRITE)) | ||
1238 | return tomoyo_write_no_rewrite_policy(data, is_delete); | ||
1239 | if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_PATH_GROUP)) | ||
1240 | return tomoyo_write_group(data, is_delete, TOMOYO_PATH_GROUP); | ||
1241 | if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_NUMBER_GROUP)) | ||
1242 | return tomoyo_write_group(data, is_delete, TOMOYO_NUMBER_GROUP); | ||
1243 | return -EINVAL; | 1246 | return -EINVAL; |
1244 | } | 1247 | } |
1245 | 1248 | ||
1246 | static const char *tomoyo_group_name[TOMOYO_MAX_GROUP] = { | ||
1247 | [TOMOYO_PATH_GROUP] = TOMOYO_KEYWORD_PATH_GROUP, | ||
1248 | [TOMOYO_NUMBER_GROUP] = TOMOYO_KEYWORD_NUMBER_GROUP | ||
1249 | }; | ||
1250 | |||
1251 | /** | 1249 | /** |
1252 | * tomoyo_read_group - Read "struct tomoyo_path_group"/"struct tomoyo_number_group" list. | 1250 | * tomoyo_read_group - Read "struct tomoyo_path_group"/"struct tomoyo_number_group" list. |
1253 | * | 1251 | * |
@@ -1331,8 +1329,8 @@ static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx) | |||
1331 | break; | 1329 | break; |
1332 | case TOMOYO_ID_GLOBALLY_READABLE: | 1330 | case TOMOYO_ID_GLOBALLY_READABLE: |
1333 | { | 1331 | { |
1334 | struct tomoyo_globally_readable_file_entry *ptr | 1332 | struct tomoyo_readable_file *ptr = |
1335 | = container_of(acl, typeof(*ptr), head); | 1333 | container_of(acl, typeof(*ptr), head); |
1336 | tomoyo_set_string(head, | 1334 | tomoyo_set_string(head, |
1337 | TOMOYO_KEYWORD_ALLOW_READ); | 1335 | TOMOYO_KEYWORD_ALLOW_READ); |
1338 | tomoyo_set_string(head, ptr->filename->name); | 1336 | tomoyo_set_string(head, ptr->filename->name); |
@@ -1340,7 +1338,7 @@ static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx) | |||
1340 | break; | 1338 | break; |
1341 | case TOMOYO_ID_AGGREGATOR: | 1339 | case TOMOYO_ID_AGGREGATOR: |
1342 | { | 1340 | { |
1343 | struct tomoyo_aggregator_entry *ptr = | 1341 | struct tomoyo_aggregator *ptr = |
1344 | container_of(acl, typeof(*ptr), head); | 1342 | container_of(acl, typeof(*ptr), head); |
1345 | tomoyo_set_string(head, | 1343 | tomoyo_set_string(head, |
1346 | TOMOYO_KEYWORD_AGGREGATOR); | 1344 | TOMOYO_KEYWORD_AGGREGATOR); |
@@ -1353,7 +1351,7 @@ static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx) | |||
1353 | break; | 1351 | break; |
1354 | case TOMOYO_ID_PATTERN: | 1352 | case TOMOYO_ID_PATTERN: |
1355 | { | 1353 | { |
1356 | struct tomoyo_pattern_entry *ptr = | 1354 | struct tomoyo_no_pattern *ptr = |
1357 | container_of(acl, typeof(*ptr), head); | 1355 | container_of(acl, typeof(*ptr), head); |
1358 | tomoyo_set_string(head, | 1356 | tomoyo_set_string(head, |
1359 | TOMOYO_KEYWORD_FILE_PATTERN); | 1357 | TOMOYO_KEYWORD_FILE_PATTERN); |
@@ -1362,7 +1360,7 @@ static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx) | |||
1362 | break; | 1360 | break; |
1363 | case TOMOYO_ID_NO_REWRITE: | 1361 | case TOMOYO_ID_NO_REWRITE: |
1364 | { | 1362 | { |
1365 | struct tomoyo_no_rewrite_entry *ptr = | 1363 | struct tomoyo_no_rewrite *ptr = |
1366 | container_of(acl, typeof(*ptr), head); | 1364 | container_of(acl, typeof(*ptr), head); |
1367 | tomoyo_set_string(head, | 1365 | tomoyo_set_string(head, |
1368 | TOMOYO_KEYWORD_DENY_REWRITE); | 1366 | TOMOYO_KEYWORD_DENY_REWRITE); |
@@ -1379,13 +1377,13 @@ static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx) | |||
1379 | } | 1377 | } |
1380 | 1378 | ||
1381 | /** | 1379 | /** |
1382 | * tomoyo_read_exception_policy - Read exception policy. | 1380 | * tomoyo_read_exception - Read exception policy. |
1383 | * | 1381 | * |
1384 | * @head: Pointer to "struct tomoyo_io_buffer". | 1382 | * @head: Pointer to "struct tomoyo_io_buffer". |
1385 | * | 1383 | * |
1386 | * Caller holds tomoyo_read_lock(). | 1384 | * Caller holds tomoyo_read_lock(). |
1387 | */ | 1385 | */ |
1388 | static void tomoyo_read_exception_policy(struct tomoyo_io_buffer *head) | 1386 | static void tomoyo_read_exception(struct tomoyo_io_buffer *head) |
1389 | { | 1387 | { |
1390 | if (head->r.eof) | 1388 | if (head->r.eof) |
1391 | return; | 1389 | return; |
@@ -1472,7 +1470,7 @@ static DECLARE_WAIT_QUEUE_HEAD(tomoyo_query_wait); | |||
1472 | static DEFINE_SPINLOCK(tomoyo_query_list_lock); | 1470 | static DEFINE_SPINLOCK(tomoyo_query_list_lock); |
1473 | 1471 | ||
1474 | /* Structure for query. */ | 1472 | /* Structure for query. */ |
1475 | struct tomoyo_query_entry { | 1473 | struct tomoyo_query { |
1476 | struct list_head list; | 1474 | struct list_head list; |
1477 | char *query; | 1475 | char *query; |
1478 | int query_len; | 1476 | int query_len; |
@@ -1481,7 +1479,7 @@ struct tomoyo_query_entry { | |||
1481 | int answer; | 1479 | int answer; |
1482 | }; | 1480 | }; |
1483 | 1481 | ||
1484 | /* The list for "struct tomoyo_query_entry". */ | 1482 | /* The list for "struct tomoyo_query". */ |
1485 | static LIST_HEAD(tomoyo_query_list); | 1483 | static LIST_HEAD(tomoyo_query_list); |
1486 | 1484 | ||
1487 | /* | 1485 | /* |
@@ -1508,7 +1506,7 @@ int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) | |||
1508 | int pos; | 1506 | int pos; |
1509 | int len; | 1507 | int len; |
1510 | static unsigned int tomoyo_serial; | 1508 | static unsigned int tomoyo_serial; |
1511 | struct tomoyo_query_entry *tomoyo_query_entry = NULL; | 1509 | struct tomoyo_query *entry = NULL; |
1512 | bool quota_exceeded = false; | 1510 | bool quota_exceeded = false; |
1513 | char *header; | 1511 | char *header; |
1514 | switch (r->mode) { | 1512 | switch (r->mode) { |
@@ -1526,7 +1524,7 @@ int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) | |||
1526 | vsnprintf(buffer, len - 1, fmt, args); | 1524 | vsnprintf(buffer, len - 1, fmt, args); |
1527 | va_end(args); | 1525 | va_end(args); |
1528 | tomoyo_normalize_line(buffer); | 1526 | tomoyo_normalize_line(buffer); |
1529 | tomoyo_write_domain_policy2(buffer, r->domain, false); | 1527 | tomoyo_write_domain2(buffer, r->domain, false); |
1530 | kfree(buffer); | 1528 | kfree(buffer); |
1531 | /* fall through */ | 1529 | /* fall through */ |
1532 | case TOMOYO_CONFIG_PERMISSIVE: | 1530 | case TOMOYO_CONFIG_PERMISSIVE: |
@@ -1542,51 +1540,50 @@ int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) | |||
1542 | header = tomoyo_init_audit_log(&len, r); | 1540 | header = tomoyo_init_audit_log(&len, r); |
1543 | if (!header) | 1541 | if (!header) |
1544 | goto out; | 1542 | goto out; |
1545 | tomoyo_query_entry = kzalloc(sizeof(*tomoyo_query_entry), GFP_NOFS); | 1543 | entry = kzalloc(sizeof(*entry), GFP_NOFS); |
1546 | if (!tomoyo_query_entry) | 1544 | if (!entry) |
1547 | goto out; | 1545 | goto out; |
1548 | tomoyo_query_entry->query = kzalloc(len, GFP_NOFS); | 1546 | entry->query = kzalloc(len, GFP_NOFS); |
1549 | if (!tomoyo_query_entry->query) | 1547 | if (!entry->query) |
1550 | goto out; | 1548 | goto out; |
1551 | len = ksize(tomoyo_query_entry->query); | 1549 | len = ksize(entry->query); |
1552 | INIT_LIST_HEAD(&tomoyo_query_entry->list); | ||
1553 | spin_lock(&tomoyo_query_list_lock); | 1550 | spin_lock(&tomoyo_query_list_lock); |
1554 | if (tomoyo_quota_for_query && tomoyo_query_memory_size + len + | 1551 | if (tomoyo_quota_for_query && tomoyo_query_memory_size + len + |
1555 | sizeof(*tomoyo_query_entry) >= tomoyo_quota_for_query) { | 1552 | sizeof(*entry) >= tomoyo_quota_for_query) { |
1556 | quota_exceeded = true; | 1553 | quota_exceeded = true; |
1557 | } else { | 1554 | } else { |
1558 | tomoyo_query_memory_size += len + sizeof(*tomoyo_query_entry); | 1555 | tomoyo_query_memory_size += len + sizeof(*entry); |
1559 | tomoyo_query_entry->serial = tomoyo_serial++; | 1556 | entry->serial = tomoyo_serial++; |
1560 | } | 1557 | } |
1561 | spin_unlock(&tomoyo_query_list_lock); | 1558 | spin_unlock(&tomoyo_query_list_lock); |
1562 | if (quota_exceeded) | 1559 | if (quota_exceeded) |
1563 | goto out; | 1560 | goto out; |
1564 | pos = snprintf(tomoyo_query_entry->query, len - 1, "Q%u-%hu\n%s", | 1561 | pos = snprintf(entry->query, len - 1, "Q%u-%hu\n%s", |
1565 | tomoyo_query_entry->serial, r->retry, header); | 1562 | entry->serial, r->retry, header); |
1566 | kfree(header); | 1563 | kfree(header); |
1567 | header = NULL; | 1564 | header = NULL; |
1568 | va_start(args, fmt); | 1565 | va_start(args, fmt); |
1569 | vsnprintf(tomoyo_query_entry->query + pos, len - 1 - pos, fmt, args); | 1566 | vsnprintf(entry->query + pos, len - 1 - pos, fmt, args); |
1570 | tomoyo_query_entry->query_len = strlen(tomoyo_query_entry->query) + 1; | 1567 | entry->query_len = strlen(entry->query) + 1; |
1571 | va_end(args); | 1568 | va_end(args); |
1572 | spin_lock(&tomoyo_query_list_lock); | 1569 | spin_lock(&tomoyo_query_list_lock); |
1573 | list_add_tail(&tomoyo_query_entry->list, &tomoyo_query_list); | 1570 | list_add_tail(&entry->list, &tomoyo_query_list); |
1574 | spin_unlock(&tomoyo_query_list_lock); | 1571 | spin_unlock(&tomoyo_query_list_lock); |
1575 | /* Give 10 seconds for supervisor's opinion. */ | 1572 | /* Give 10 seconds for supervisor's opinion. */ |
1576 | for (tomoyo_query_entry->timer = 0; | 1573 | for (entry->timer = 0; |
1577 | atomic_read(&tomoyo_query_observers) && tomoyo_query_entry->timer < 100; | 1574 | atomic_read(&tomoyo_query_observers) && entry->timer < 100; |
1578 | tomoyo_query_entry->timer++) { | 1575 | entry->timer++) { |
1579 | wake_up(&tomoyo_query_wait); | 1576 | wake_up(&tomoyo_query_wait); |
1580 | set_current_state(TASK_INTERRUPTIBLE); | 1577 | set_current_state(TASK_INTERRUPTIBLE); |
1581 | schedule_timeout(HZ / 10); | 1578 | schedule_timeout(HZ / 10); |
1582 | if (tomoyo_query_entry->answer) | 1579 | if (entry->answer) |
1583 | break; | 1580 | break; |
1584 | } | 1581 | } |
1585 | spin_lock(&tomoyo_query_list_lock); | 1582 | spin_lock(&tomoyo_query_list_lock); |
1586 | list_del(&tomoyo_query_entry->list); | 1583 | list_del(&entry->list); |
1587 | tomoyo_query_memory_size -= len + sizeof(*tomoyo_query_entry); | 1584 | tomoyo_query_memory_size -= len + sizeof(*entry); |
1588 | spin_unlock(&tomoyo_query_list_lock); | 1585 | spin_unlock(&tomoyo_query_list_lock); |
1589 | switch (tomoyo_query_entry->answer) { | 1586 | switch (entry->answer) { |
1590 | case 3: /* Asked to retry by administrator. */ | 1587 | case 3: /* Asked to retry by administrator. */ |
1591 | error = TOMOYO_RETRY_REQUEST; | 1588 | error = TOMOYO_RETRY_REQUEST; |
1592 | r->retry++; | 1589 | r->retry++; |
@@ -1603,9 +1600,9 @@ int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) | |||
1603 | break; | 1600 | break; |
1604 | } | 1601 | } |
1605 | out: | 1602 | out: |
1606 | if (tomoyo_query_entry) | 1603 | if (entry) |
1607 | kfree(tomoyo_query_entry->query); | 1604 | kfree(entry->query); |
1608 | kfree(tomoyo_query_entry); | 1605 | kfree(entry); |
1609 | kfree(header); | 1606 | kfree(header); |
1610 | return error; | 1607 | return error; |
1611 | } | 1608 | } |
@@ -1628,9 +1625,8 @@ static int tomoyo_poll_query(struct file *file, poll_table *wait) | |||
1628 | for (i = 0; i < 2; i++) { | 1625 | for (i = 0; i < 2; i++) { |
1629 | spin_lock(&tomoyo_query_list_lock); | 1626 | spin_lock(&tomoyo_query_list_lock); |
1630 | list_for_each(tmp, &tomoyo_query_list) { | 1627 | list_for_each(tmp, &tomoyo_query_list) { |
1631 | struct tomoyo_query_entry *ptr | 1628 | struct tomoyo_query *ptr = |
1632 | = list_entry(tmp, struct tomoyo_query_entry, | 1629 | list_entry(tmp, typeof(*ptr), list); |
1633 | list); | ||
1634 | if (ptr->answer) | 1630 | if (ptr->answer) |
1635 | continue; | 1631 | continue; |
1636 | found = true; | 1632 | found = true; |
@@ -1665,8 +1661,7 @@ static void tomoyo_read_query(struct tomoyo_io_buffer *head) | |||
1665 | } | 1661 | } |
1666 | spin_lock(&tomoyo_query_list_lock); | 1662 | spin_lock(&tomoyo_query_list_lock); |
1667 | list_for_each(tmp, &tomoyo_query_list) { | 1663 | list_for_each(tmp, &tomoyo_query_list) { |
1668 | struct tomoyo_query_entry *ptr = | 1664 | struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list); |
1669 | list_entry(tmp, typeof(*ptr), list); | ||
1670 | if (ptr->answer) | 1665 | if (ptr->answer) |
1671 | continue; | 1666 | continue; |
1672 | if (pos++ != head->r.query_index) | 1667 | if (pos++ != head->r.query_index) |
@@ -1685,8 +1680,7 @@ static void tomoyo_read_query(struct tomoyo_io_buffer *head) | |||
1685 | pos = 0; | 1680 | pos = 0; |
1686 | spin_lock(&tomoyo_query_list_lock); | 1681 | spin_lock(&tomoyo_query_list_lock); |
1687 | list_for_each(tmp, &tomoyo_query_list) { | 1682 | list_for_each(tmp, &tomoyo_query_list) { |
1688 | struct tomoyo_query_entry *ptr = | 1683 | struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list); |
1689 | list_entry(tmp, typeof(*ptr), list); | ||
1690 | if (ptr->answer) | 1684 | if (ptr->answer) |
1691 | continue; | 1685 | continue; |
1692 | if (pos++ != head->r.query_index) | 1686 | if (pos++ != head->r.query_index) |
@@ -1724,8 +1718,7 @@ static int tomoyo_write_answer(struct tomoyo_io_buffer *head) | |||
1724 | unsigned int answer; | 1718 | unsigned int answer; |
1725 | spin_lock(&tomoyo_query_list_lock); | 1719 | spin_lock(&tomoyo_query_list_lock); |
1726 | list_for_each(tmp, &tomoyo_query_list) { | 1720 | list_for_each(tmp, &tomoyo_query_list) { |
1727 | struct tomoyo_query_entry *ptr | 1721 | struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list); |
1728 | = list_entry(tmp, struct tomoyo_query_entry, list); | ||
1729 | ptr->timer = 0; | 1722 | ptr->timer = 0; |
1730 | } | 1723 | } |
1731 | spin_unlock(&tomoyo_query_list_lock); | 1724 | spin_unlock(&tomoyo_query_list_lock); |
@@ -1733,8 +1726,7 @@ static int tomoyo_write_answer(struct tomoyo_io_buffer *head) | |||
1733 | return -EINVAL; | 1726 | return -EINVAL; |
1734 | spin_lock(&tomoyo_query_list_lock); | 1727 | spin_lock(&tomoyo_query_list_lock); |
1735 | list_for_each(tmp, &tomoyo_query_list) { | 1728 | list_for_each(tmp, &tomoyo_query_list) { |
1736 | struct tomoyo_query_entry *ptr | 1729 | struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list); |
1737 | = list_entry(tmp, struct tomoyo_query_entry, list); | ||
1738 | if (ptr->serial != serial) | 1730 | if (ptr->serial != serial) |
1739 | continue; | 1731 | continue; |
1740 | if (!ptr->answer) | 1732 | if (!ptr->answer) |
@@ -1801,13 +1793,13 @@ int tomoyo_open_control(const u8 type, struct file *file) | |||
1801 | switch (type) { | 1793 | switch (type) { |
1802 | case TOMOYO_DOMAINPOLICY: | 1794 | case TOMOYO_DOMAINPOLICY: |
1803 | /* /sys/kernel/security/tomoyo/domain_policy */ | 1795 | /* /sys/kernel/security/tomoyo/domain_policy */ |
1804 | head->write = tomoyo_write_domain_policy; | 1796 | head->write = tomoyo_write_domain; |
1805 | head->read = tomoyo_read_domain_policy; | 1797 | head->read = tomoyo_read_domain; |
1806 | break; | 1798 | break; |
1807 | case TOMOYO_EXCEPTIONPOLICY: | 1799 | case TOMOYO_EXCEPTIONPOLICY: |
1808 | /* /sys/kernel/security/tomoyo/exception_policy */ | 1800 | /* /sys/kernel/security/tomoyo/exception_policy */ |
1809 | head->write = tomoyo_write_exception_policy; | 1801 | head->write = tomoyo_write_exception; |
1810 | head->read = tomoyo_read_exception_policy; | 1802 | head->read = tomoyo_read_exception; |
1811 | break; | 1803 | break; |
1812 | case TOMOYO_SELFDOMAIN: | 1804 | case TOMOYO_SELFDOMAIN: |
1813 | /* /sys/kernel/security/tomoyo/self_domain */ | 1805 | /* /sys/kernel/security/tomoyo/self_domain */ |
@@ -1846,8 +1838,8 @@ int tomoyo_open_control(const u8 type, struct file *file) | |||
1846 | break; | 1838 | break; |
1847 | case TOMOYO_MANAGER: | 1839 | case TOMOYO_MANAGER: |
1848 | /* /sys/kernel/security/tomoyo/manager */ | 1840 | /* /sys/kernel/security/tomoyo/manager */ |
1849 | head->write = tomoyo_write_manager_policy; | 1841 | head->write = tomoyo_write_manager; |
1850 | head->read = tomoyo_read_manager_policy; | 1842 | head->read = tomoyo_read_manager; |
1851 | break; | 1843 | break; |
1852 | } | 1844 | } |
1853 | if (!(file->f_mode & FMODE_READ)) { | 1845 | if (!(file->f_mode & FMODE_READ)) { |
@@ -1906,23 +1898,6 @@ int tomoyo_open_control(const u8 type, struct file *file) | |||
1906 | } | 1898 | } |
1907 | 1899 | ||
1908 | /** | 1900 | /** |
1909 | * tomoyo_poll_control - poll() for /sys/kernel/security/tomoyo/ interface. | ||
1910 | * | ||
1911 | * @file: Pointer to "struct file". | ||
1912 | * @wait: Pointer to "poll_table". | ||
1913 | * | ||
1914 | * Waits for read readiness. | ||
1915 | * /sys/kernel/security/tomoyo/query is handled by /usr/sbin/tomoyo-queryd . | ||
1916 | */ | ||
1917 | int tomoyo_poll_control(struct file *file, poll_table *wait) | ||
1918 | { | ||
1919 | struct tomoyo_io_buffer *head = file->private_data; | ||
1920 | if (!head->poll) | ||
1921 | return -ENOSYS; | ||
1922 | return head->poll(file, wait); | ||
1923 | } | ||
1924 | |||
1925 | /** | ||
1926 | * tomoyo_read_control - read() for /sys/kernel/security/tomoyo/ interface. | 1901 | * tomoyo_read_control - read() for /sys/kernel/security/tomoyo/ interface. |
1927 | * | 1902 | * |
1928 | * @file: Pointer to "struct file". | 1903 | * @file: Pointer to "struct file". |
@@ -1979,8 +1954,7 @@ int tomoyo_write_control(struct file *file, const char __user *buffer, | |||
1979 | return -EFAULT; | 1954 | return -EFAULT; |
1980 | /* Don't allow updating policies by non manager programs. */ | 1955 | /* Don't allow updating policies by non manager programs. */ |
1981 | if (head->write != tomoyo_write_pid && | 1956 | if (head->write != tomoyo_write_pid && |
1982 | head->write != tomoyo_write_domain_policy && | 1957 | head->write != tomoyo_write_domain && !tomoyo_manager()) |
1983 | !tomoyo_policy_manager()) | ||
1984 | return -EPERM; | 1958 | return -EPERM; |
1985 | if (mutex_lock_interruptible(&head->io_sem)) | 1959 | if (mutex_lock_interruptible(&head->io_sem)) |
1986 | return -EINTR; | 1960 | return -EINTR; |