]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - security/tomoyo/gc.c
TOMOYO: Use common structure for list element.
[net-next-2.6.git] / security / tomoyo / gc.c
index b9cc71b04314b0b50b8f301cacb9b9ac432ad963..2dd9665af260596ac58259b98b06b5402723e8f7 100644 (file)
 enum tomoyo_gc_id {
        TOMOYO_ID_PATH_GROUP,
        TOMOYO_ID_PATH_GROUP_MEMBER,
+       TOMOYO_ID_NUMBER_GROUP,
+       TOMOYO_ID_NUMBER_GROUP_MEMBER,
        TOMOYO_ID_DOMAIN_INITIALIZER,
        TOMOYO_ID_DOMAIN_KEEPER,
+       TOMOYO_ID_AGGREGATOR,
        TOMOYO_ID_ALIAS,
        TOMOYO_ID_GLOBALLY_READABLE,
        TOMOYO_ID_PATTERN,
@@ -75,6 +78,12 @@ static void tomoyo_del_domain_keeper(struct tomoyo_domain_keeper_entry *ptr)
        tomoyo_put_name(ptr->program);
 }
 
+static void tomoyo_del_aggregator(struct tomoyo_aggregator_entry *ptr)
+{
+       tomoyo_put_name(ptr->original_name);
+       tomoyo_put_name(ptr->aggregated_name);
+}
+
 static void tomoyo_del_alias(struct tomoyo_alias_entry *ptr)
 {
        tomoyo_put_name(ptr->original_name);
@@ -104,6 +113,34 @@ static void tomoyo_del_acl(struct tomoyo_acl_info *acl)
                        tomoyo_put_name_union(&entry->name2);
                }
                break;
+       case TOMOYO_TYPE_PATH_NUMBER_ACL:
+               {
+                       struct tomoyo_path_number_acl *entry
+                               = container_of(acl, typeof(*entry), head);
+                       tomoyo_put_name_union(&entry->name);
+                       tomoyo_put_number_union(&entry->number);
+               }
+               break;
+       case TOMOYO_TYPE_PATH_NUMBER3_ACL:
+               {
+                       struct tomoyo_path_number3_acl *entry
+                               = container_of(acl, typeof(*entry), head);
+                       tomoyo_put_name_union(&entry->name);
+                       tomoyo_put_number_union(&entry->mode);
+                       tomoyo_put_number_union(&entry->major);
+                       tomoyo_put_number_union(&entry->minor);
+               }
+               break;
+       case TOMOYO_TYPE_MOUNT_ACL:
+               {
+                       struct tomoyo_mount_acl *entry
+                               = container_of(acl, typeof(*entry), head);
+                       tomoyo_put_name_union(&entry->dev_name);
+                       tomoyo_put_name_union(&entry->dir_name);
+                       tomoyo_put_name_union(&entry->fs_type);
+                       tomoyo_put_number_union(&entry->flags);
+               }
+               break;
        default:
                printk(KERN_WARNING "Unknown type\n");
                break;
@@ -162,6 +199,16 @@ static void tomoyo_del_path_group(struct tomoyo_path_group *group)
        tomoyo_put_name(group->group_name);
 }
 
+static void tomoyo_del_number_group_member(struct tomoyo_number_group_member
+                                          *member)
+{
+}
+
+static void tomoyo_del_number_group(struct tomoyo_number_group *group)
+{
+       tomoyo_put_name(group->group_name);
+}
+
 static void tomoyo_collect_entry(void)
 {
        if (mutex_lock_interruptible(&tomoyo_policy_lock))
@@ -169,33 +216,34 @@ static void tomoyo_collect_entry(void)
        {
                struct tomoyo_globally_readable_file_entry *ptr;
                list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list,
-                                       list) {
-                       if (!ptr->is_deleted)
+                                       head.list) {
+                       if (!ptr->head.is_deleted)
                                continue;
                        if (tomoyo_add_to_gc(TOMOYO_ID_GLOBALLY_READABLE, ptr))
-                               list_del_rcu(&ptr->list);
+                               list_del_rcu(&ptr->head.list);
                        else
                                break;
                }
        }
        {
                struct tomoyo_pattern_entry *ptr;
-               list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, list) {
-                       if (!ptr->is_deleted)
+               list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, head.list) {
+                       if (!ptr->head.is_deleted)
                                continue;
                        if (tomoyo_add_to_gc(TOMOYO_ID_PATTERN, ptr))
-                               list_del_rcu(&ptr->list);
+                               list_del_rcu(&ptr->head.list);
                        else
                                break;
                }
        }
        {
                struct tomoyo_no_rewrite_entry *ptr;
-               list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list, list) {
-                       if (!ptr->is_deleted)
+               list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list,
+                                       head.list) {
+                       if (!ptr->head.is_deleted)
                                continue;
                        if (tomoyo_add_to_gc(TOMOYO_ID_NO_REWRITE, ptr))
-                               list_del_rcu(&ptr->list);
+                               list_del_rcu(&ptr->head.list);
                        else
                                break;
                }
@@ -203,33 +251,46 @@ static void tomoyo_collect_entry(void)
        {
                struct tomoyo_domain_initializer_entry *ptr;
                list_for_each_entry_rcu(ptr, &tomoyo_domain_initializer_list,
-                                       list) {
-                       if (!ptr->is_deleted)
+                                       head.list) {
+                       if (!ptr->head.is_deleted)
                                continue;
                        if (tomoyo_add_to_gc(TOMOYO_ID_DOMAIN_INITIALIZER, ptr))
-                               list_del_rcu(&ptr->list);
+                               list_del_rcu(&ptr->head.list);
                        else
                                break;
                }
        }
        {
                struct tomoyo_domain_keeper_entry *ptr;
-               list_for_each_entry_rcu(ptr, &tomoyo_domain_keeper_list, list) {
-                       if (!ptr->is_deleted)
+               list_for_each_entry_rcu(ptr, &tomoyo_domain_keeper_list,
+                                       head.list) {
+                       if (!ptr->head.is_deleted)
                                continue;
                        if (tomoyo_add_to_gc(TOMOYO_ID_DOMAIN_KEEPER, ptr))
-                               list_del_rcu(&ptr->list);
+                               list_del_rcu(&ptr->head.list);
+                       else
+                               break;
+               }
+       }
+       {
+               struct tomoyo_aggregator_entry *ptr;
+               list_for_each_entry_rcu(ptr, &tomoyo_aggregator_list,
+                                       head.list) {
+                       if (!ptr->head.is_deleted)
+                               continue;
+                       if (tomoyo_add_to_gc(TOMOYO_ID_AGGREGATOR, ptr))
+                               list_del_rcu(&ptr->head.list);
                        else
                                break;
                }
        }
        {
                struct tomoyo_alias_entry *ptr;
-               list_for_each_entry_rcu(ptr, &tomoyo_alias_list, list) {
-                       if (!ptr->is_deleted)
+               list_for_each_entry_rcu(ptr, &tomoyo_alias_list, head.list) {
+                       if (!ptr->head.is_deleted)
                                continue;
                        if (tomoyo_add_to_gc(TOMOYO_ID_ALIAS, ptr))
-                               list_del_rcu(&ptr->list);
+                               list_del_rcu(&ptr->head.list);
                        else
                                break;
                }
@@ -237,11 +298,11 @@ static void tomoyo_collect_entry(void)
        {
                struct tomoyo_policy_manager_entry *ptr;
                list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list,
-                                       list) {
-                       if (!ptr->is_deleted)
+                                       head.list) {
+                       if (!ptr->head.is_deleted)
                                continue;
                        if (tomoyo_add_to_gc(TOMOYO_ID_MANAGER, ptr))
-                               list_del_rcu(&ptr->list);
+                               list_del_rcu(&ptr->head.list);
                        else
                                break;
                }
@@ -252,25 +313,8 @@ static void tomoyo_collect_entry(void)
                        struct tomoyo_acl_info *acl;
                        list_for_each_entry_rcu(acl, &domain->acl_info_list,
                                                list) {
-                               switch (acl->type) {
-                               case TOMOYO_TYPE_PATH_ACL:
-                                       if (container_of(acl,
-                                        struct tomoyo_path_acl,
-                                                        head)->perm ||
-                                           container_of(acl,
-                                        struct tomoyo_path_acl,
-                                                        head)->perm_high)
-                                               continue;
-                                       break;
-                               case TOMOYO_TYPE_PATH2_ACL:
-                                       if (container_of(acl,
-                                        struct tomoyo_path2_acl,
-                                                        head)->perm)
-                                               continue;
-                                       break;
-                               default:
+                               if (!acl->is_deleted)
                                        continue;
-                               }
                                if (tomoyo_add_to_gc(TOMOYO_ID_ACL, acl))
                                        list_del_rcu(&acl->list);
                                else
@@ -311,12 +355,12 @@ static void tomoyo_collect_entry(void)
                list_for_each_entry_rcu(group, &tomoyo_path_group_list, list) {
                        struct tomoyo_path_group_member *member;
                        list_for_each_entry_rcu(member, &group->member_list,
-                                               list) {
-                               if (!member->is_deleted)
+                                               head.list) {
+                               if (!member->head.is_deleted)
                                        continue;
                                if (tomoyo_add_to_gc(TOMOYO_ID_PATH_GROUP_MEMBER,
                                                     member))
-                                       list_del_rcu(&member->list);
+                                       list_del_rcu(&member->head.list);
                                else
                                        break;
                        }
@@ -329,6 +373,29 @@ static void tomoyo_collect_entry(void)
                                break;
                }
        }
+       {
+               struct tomoyo_number_group *group;
+               list_for_each_entry_rcu(group, &tomoyo_number_group_list, list) {
+                       struct tomoyo_number_group_member *member;
+                       list_for_each_entry_rcu(member, &group->member_list,
+                                               head.list) {
+                               if (!member->head.is_deleted)
+                                       continue;
+                               if (tomoyo_add_to_gc(TOMOYO_ID_NUMBER_GROUP_MEMBER,
+                                                    member))
+                                       list_del_rcu(&member->head.list);
+                               else
+                                       break;
+                       }
+                       if (!list_empty(&group->member_list) ||
+                           atomic_read(&group->users))
+                               continue;
+                       if (tomoyo_add_to_gc(TOMOYO_ID_NUMBER_GROUP, group))
+                               list_del_rcu(&group->list);
+                       else
+                               break;
+               }
+       }
        mutex_unlock(&tomoyo_policy_lock);
 }
 
@@ -345,6 +412,9 @@ static void tomoyo_kfree_entry(void)
                case TOMOYO_ID_DOMAIN_KEEPER:
                        tomoyo_del_domain_keeper(p->element);
                        break;
+               case TOMOYO_ID_AGGREGATOR:
+                       tomoyo_del_aggregator(p->element);
+                       break;
                case TOMOYO_ID_ALIAS:
                        tomoyo_del_alias(p->element);
                        break;
@@ -376,6 +446,12 @@ static void tomoyo_kfree_entry(void)
                case TOMOYO_ID_PATH_GROUP:
                        tomoyo_del_path_group(p->element);
                        break;
+               case TOMOYO_ID_NUMBER_GROUP_MEMBER:
+                       tomoyo_del_number_group_member(p->element);
+                       break;
+               case TOMOYO_ID_NUMBER_GROUP:
+                       tomoyo_del_number_group(p->element);
+                       break;
                default:
                        printk(KERN_WARNING "Unknown type\n");
                        break;