blob: 446d59f8ae2559c716976ad777d5563fcce70081 [file] [log] [blame]
Tetsuo Handa847b1732010-02-11 09:43:54 +09001/*
2 * security/tomoyo/gc.c
3 *
4 * Implementation of the Domain-Based Mandatory Access Control.
5 *
6 * Copyright (C) 2005-2010 NTT DATA CORPORATION
7 *
8 */
9
10#include "common.h"
11#include <linux/kthread.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Tetsuo Handa847b1732010-02-11 09:43:54 +090013
Tetsuo Handad2f8b232010-06-15 10:10:37 +090014enum tomoyo_policy_id {
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +090015 TOMOYO_ID_GROUP,
Tetsuo Handa7762fbf2010-05-10 17:30:26 +090016 TOMOYO_ID_PATH_GROUP,
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +090017 TOMOYO_ID_NUMBER_GROUP,
Tetsuo Handa847b1732010-02-11 09:43:54 +090018 TOMOYO_ID_DOMAIN_INITIALIZER,
19 TOMOYO_ID_DOMAIN_KEEPER,
Tetsuo Handa10843072010-06-03 20:38:03 +090020 TOMOYO_ID_AGGREGATOR,
Tetsuo Handa847b1732010-02-11 09:43:54 +090021 TOMOYO_ID_ALIAS,
22 TOMOYO_ID_GLOBALLY_READABLE,
23 TOMOYO_ID_PATTERN,
24 TOMOYO_ID_NO_REWRITE,
25 TOMOYO_ID_MANAGER,
26 TOMOYO_ID_NAME,
27 TOMOYO_ID_ACL,
Tetsuo Handad2f8b232010-06-15 10:10:37 +090028 TOMOYO_ID_DOMAIN,
29 TOMOYO_MAX_POLICY
Tetsuo Handa847b1732010-02-11 09:43:54 +090030};
31
32struct tomoyo_gc_entry {
33 struct list_head list;
34 int type;
Tetsuo Handae79acf02010-06-16 16:31:50 +090035 struct list_head *element;
Tetsuo Handa847b1732010-02-11 09:43:54 +090036};
37static LIST_HEAD(tomoyo_gc_queue);
38static DEFINE_MUTEX(tomoyo_gc_mutex);
39
40/* Caller holds tomoyo_policy_lock mutex. */
Tetsuo Handae79acf02010-06-16 16:31:50 +090041static bool tomoyo_add_to_gc(const int type, struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +090042{
43 struct tomoyo_gc_entry *entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
44 if (!entry)
45 return false;
46 entry->type = type;
47 entry->element = element;
48 list_add(&entry->list, &tomoyo_gc_queue);
Tetsuo Handae79acf02010-06-16 16:31:50 +090049 list_del_rcu(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +090050 return true;
51}
52
Tetsuo Handae79acf02010-06-16 16:31:50 +090053static void tomoyo_del_allow_read(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +090054{
Tetsuo Handae79acf02010-06-16 16:31:50 +090055 struct tomoyo_globally_readable_file_entry *ptr =
56 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +090057 tomoyo_put_name(ptr->filename);
58}
59
Tetsuo Handae79acf02010-06-16 16:31:50 +090060static void tomoyo_del_file_pattern(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +090061{
Tetsuo Handae79acf02010-06-16 16:31:50 +090062 struct tomoyo_pattern_entry *ptr =
63 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +090064 tomoyo_put_name(ptr->pattern);
65}
66
Tetsuo Handae79acf02010-06-16 16:31:50 +090067static void tomoyo_del_no_rewrite(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +090068{
Tetsuo Handae79acf02010-06-16 16:31:50 +090069 struct tomoyo_no_rewrite_entry *ptr =
70 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +090071 tomoyo_put_name(ptr->pattern);
72}
73
Tetsuo Handae79acf02010-06-16 16:31:50 +090074static void tomoyo_del_domain_initializer(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +090075{
Tetsuo Handae79acf02010-06-16 16:31:50 +090076 struct tomoyo_domain_initializer_entry *ptr =
77 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +090078 tomoyo_put_name(ptr->domainname);
79 tomoyo_put_name(ptr->program);
80}
81
Tetsuo Handae79acf02010-06-16 16:31:50 +090082static void tomoyo_del_domain_keeper(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +090083{
Tetsuo Handae79acf02010-06-16 16:31:50 +090084 struct tomoyo_domain_keeper_entry *ptr =
85 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +090086 tomoyo_put_name(ptr->domainname);
87 tomoyo_put_name(ptr->program);
88}
89
Tetsuo Handae79acf02010-06-16 16:31:50 +090090static void tomoyo_del_aggregator(struct list_head *element)
Tetsuo Handa10843072010-06-03 20:38:03 +090091{
Tetsuo Handae79acf02010-06-16 16:31:50 +090092 struct tomoyo_aggregator_entry *ptr =
93 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa10843072010-06-03 20:38:03 +090094 tomoyo_put_name(ptr->original_name);
95 tomoyo_put_name(ptr->aggregated_name);
96}
97
Tetsuo Handae79acf02010-06-16 16:31:50 +090098static void tomoyo_del_alias(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +090099{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900100 struct tomoyo_alias_entry *ptr =
101 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900102 tomoyo_put_name(ptr->original_name);
103 tomoyo_put_name(ptr->aliased_name);
104}
105
Tetsuo Handae79acf02010-06-16 16:31:50 +0900106static void tomoyo_del_manager(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +0900107{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900108 struct tomoyo_policy_manager_entry *ptr =
109 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900110 tomoyo_put_name(ptr->manager);
111}
112
Tetsuo Handae79acf02010-06-16 16:31:50 +0900113static void tomoyo_del_acl(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +0900114{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900115 struct tomoyo_acl_info *acl =
116 container_of(element, typeof(*acl), list);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900117 switch (acl->type) {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900118 case TOMOYO_TYPE_PATH_ACL:
Tetsuo Handa847b1732010-02-11 09:43:54 +0900119 {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900120 struct tomoyo_path_acl *entry
Tetsuo Handa847b1732010-02-11 09:43:54 +0900121 = container_of(acl, typeof(*entry), head);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900122 tomoyo_put_name_union(&entry->name);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900123 }
124 break;
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900125 case TOMOYO_TYPE_PATH2_ACL:
Tetsuo Handa847b1732010-02-11 09:43:54 +0900126 {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900127 struct tomoyo_path2_acl *entry
Tetsuo Handa847b1732010-02-11 09:43:54 +0900128 = container_of(acl, typeof(*entry), head);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900129 tomoyo_put_name_union(&entry->name1);
130 tomoyo_put_name_union(&entry->name2);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900131 }
132 break;
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900133 case TOMOYO_TYPE_PATH_NUMBER_ACL:
134 {
135 struct tomoyo_path_number_acl *entry
136 = container_of(acl, typeof(*entry), head);
137 tomoyo_put_name_union(&entry->name);
138 tomoyo_put_number_union(&entry->number);
139 }
140 break;
Tetsuo Handa75093152010-06-16 16:23:55 +0900141 case TOMOYO_TYPE_MKDEV_ACL:
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900142 {
Tetsuo Handa75093152010-06-16 16:23:55 +0900143 struct tomoyo_mkdev_acl *entry
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900144 = container_of(acl, typeof(*entry), head);
145 tomoyo_put_name_union(&entry->name);
146 tomoyo_put_number_union(&entry->mode);
147 tomoyo_put_number_union(&entry->major);
148 tomoyo_put_number_union(&entry->minor);
149 }
150 break;
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900151 case TOMOYO_TYPE_MOUNT_ACL:
152 {
153 struct tomoyo_mount_acl *entry
154 = container_of(acl, typeof(*entry), head);
155 tomoyo_put_name_union(&entry->dev_name);
156 tomoyo_put_name_union(&entry->dir_name);
157 tomoyo_put_name_union(&entry->fs_type);
158 tomoyo_put_number_union(&entry->flags);
159 }
160 break;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900161 }
162}
163
Tetsuo Handae79acf02010-06-16 16:31:50 +0900164static bool tomoyo_del_domain(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +0900165{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900166 struct tomoyo_domain_info *domain =
167 container_of(element, typeof(*domain), list);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900168 struct tomoyo_acl_info *acl;
169 struct tomoyo_acl_info *tmp;
170 /*
171 * Since we don't protect whole execve() operation using SRCU,
172 * we need to recheck domain->users at this point.
173 *
174 * (1) Reader starts SRCU section upon execve().
175 * (2) Reader traverses tomoyo_domain_list and finds this domain.
176 * (3) Writer marks this domain as deleted.
177 * (4) Garbage collector removes this domain from tomoyo_domain_list
178 * because this domain is marked as deleted and used by nobody.
179 * (5) Reader saves reference to this domain into
180 * "struct linux_binprm"->cred->security .
181 * (6) Reader finishes SRCU section, although execve() operation has
182 * not finished yet.
183 * (7) Garbage collector waits for SRCU synchronization.
184 * (8) Garbage collector kfree() this domain because this domain is
185 * used by nobody.
186 * (9) Reader finishes execve() operation and restores this domain from
187 * "struct linux_binprm"->cred->security.
188 *
189 * By updating domain->users at (5), we can solve this race problem
190 * by rechecking domain->users at (8).
191 */
192 if (atomic_read(&domain->users))
193 return false;
194 list_for_each_entry_safe(acl, tmp, &domain->acl_info_list, list) {
Tetsuo Handae79acf02010-06-16 16:31:50 +0900195 tomoyo_del_acl(&acl->list);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900196 tomoyo_memory_free(acl);
197 }
198 tomoyo_put_name(domain->domainname);
199 return true;
200}
201
202
Tetsuo Handae79acf02010-06-16 16:31:50 +0900203static void tomoyo_del_name(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +0900204{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900205 const struct tomoyo_name_entry *ptr =
206 container_of(element, typeof(*ptr), list);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900207}
208
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900209static void tomoyo_del_path_group(struct list_head *element)
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900210{
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900211 struct tomoyo_path_group *member =
Tetsuo Handae79acf02010-06-16 16:31:50 +0900212 container_of(element, typeof(*member), head.list);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900213 tomoyo_put_name(member->member_name);
214}
215
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900216static void tomoyo_del_group(struct list_head *element)
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900217{
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900218 struct tomoyo_group *group =
Tetsuo Handae79acf02010-06-16 16:31:50 +0900219 container_of(element, typeof(*group), list);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900220 tomoyo_put_name(group->group_name);
221}
222
Tetsuo Handae79acf02010-06-16 16:31:50 +0900223static void tomoyo_del_number_group(struct list_head *element)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900224{
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900225 struct tomoyo_number_group *member =
226 container_of(element, typeof(*member), head.list);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900227}
228
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900229static struct list_head *tomoyo_policy_list[TOMOYO_MAX_POLICY] = {
230 [TOMOYO_ID_GLOBALLY_READABLE] = &tomoyo_globally_readable_list,
231 [TOMOYO_ID_PATTERN] = &tomoyo_pattern_list,
232 [TOMOYO_ID_NO_REWRITE] = &tomoyo_no_rewrite_list,
233 [TOMOYO_ID_DOMAIN_INITIALIZER] = &tomoyo_domain_initializer_list,
234 [TOMOYO_ID_DOMAIN_KEEPER] = &tomoyo_domain_keeper_list,
235 [TOMOYO_ID_AGGREGATOR] = &tomoyo_aggregator_list,
236 [TOMOYO_ID_ALIAS] = &tomoyo_alias_list,
237 [TOMOYO_ID_MANAGER] = &tomoyo_policy_manager_list,
238};
239
240static bool tomoyo_collect_member(struct list_head *member_list, int id)
241{
242 struct tomoyo_acl_head *member;
243 list_for_each_entry(member, member_list, list) {
244 if (!member->is_deleted)
245 continue;
246 if (!tomoyo_add_to_gc(id, &member->list))
247 return false;
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900248 }
249 return true;
250}
251
252static bool tomoyo_collect_acl(struct tomoyo_domain_info *domain)
253{
254 struct tomoyo_acl_info *acl;
255 list_for_each_entry(acl, &domain->acl_info_list, list) {
256 if (!acl->is_deleted)
257 continue;
258 if (!tomoyo_add_to_gc(TOMOYO_ID_ACL, &acl->list))
259 return false;
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900260 }
261 return true;
262}
263
Tetsuo Handa847b1732010-02-11 09:43:54 +0900264static void tomoyo_collect_entry(void)
265{
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900266 int i;
Tetsuo Handa29282382010-05-06 00:18:15 +0900267 if (mutex_lock_interruptible(&tomoyo_policy_lock))
268 return;
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900269 for (i = 0; i < TOMOYO_MAX_POLICY; i++) {
270 if (tomoyo_policy_list[i])
271 if (!tomoyo_collect_member(tomoyo_policy_list[i], i))
272 goto unlock;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900273 }
274 {
275 struct tomoyo_domain_info *domain;
276 list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900277 if (!tomoyo_collect_acl(domain))
278 goto unlock;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900279 if (!domain->is_deleted || atomic_read(&domain->users))
280 continue;
281 /*
282 * Nobody is referring this domain. But somebody may
283 * refer this domain after successful execve().
284 * We recheck domain->users after SRCU synchronization.
285 */
Tetsuo Handae79acf02010-06-16 16:31:50 +0900286 if (!tomoyo_add_to_gc(TOMOYO_ID_DOMAIN, &domain->list))
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900287 goto unlock;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900288 }
289 }
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900290 for (i = 0; i < TOMOYO_MAX_HASH; i++) {
291 struct tomoyo_name_entry *ptr;
292 list_for_each_entry_rcu(ptr, &tomoyo_name_list[i], list) {
293 if (atomic_read(&ptr->users))
294 continue;
Tetsuo Handae79acf02010-06-16 16:31:50 +0900295 if (!tomoyo_add_to_gc(TOMOYO_ID_NAME, &ptr->list))
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900296 goto unlock;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900297 }
298 }
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900299 {
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900300 struct tomoyo_group *group;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900301 list_for_each_entry_rcu(group, &tomoyo_path_group_list, list) {
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900302 tomoyo_collect_member(&group->member_list,
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900303 TOMOYO_ID_PATH_GROUP);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900304 if (!list_empty(&group->member_list) ||
305 atomic_read(&group->users))
306 continue;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900307 if (!tomoyo_add_to_gc(TOMOYO_ID_GROUP,
Tetsuo Handae79acf02010-06-16 16:31:50 +0900308 &group->list))
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900309 goto unlock;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900310 }
311 }
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900312 {
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900313 struct tomoyo_group *group;
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900314 list_for_each_entry_rcu(group, &tomoyo_number_group_list,
315 list) {
316 tomoyo_collect_member(&group->member_list,
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900317 TOMOYO_ID_NUMBER_GROUP);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900318 if (!list_empty(&group->member_list) ||
319 atomic_read(&group->users))
320 continue;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900321 if (!tomoyo_add_to_gc(TOMOYO_ID_GROUP,
Tetsuo Handae79acf02010-06-16 16:31:50 +0900322 &group->list))
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900323 goto unlock;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900324 }
325 }
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900326 unlock:
Tetsuo Handa29282382010-05-06 00:18:15 +0900327 mutex_unlock(&tomoyo_policy_lock);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900328}
329
330static void tomoyo_kfree_entry(void)
331{
332 struct tomoyo_gc_entry *p;
333 struct tomoyo_gc_entry *tmp;
334
335 list_for_each_entry_safe(p, tmp, &tomoyo_gc_queue, list) {
Tetsuo Handae79acf02010-06-16 16:31:50 +0900336 struct list_head *element = p->element;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900337 switch (p->type) {
338 case TOMOYO_ID_DOMAIN_INITIALIZER:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900339 tomoyo_del_domain_initializer(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900340 break;
341 case TOMOYO_ID_DOMAIN_KEEPER:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900342 tomoyo_del_domain_keeper(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900343 break;
Tetsuo Handa10843072010-06-03 20:38:03 +0900344 case TOMOYO_ID_AGGREGATOR:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900345 tomoyo_del_aggregator(element);
Tetsuo Handa10843072010-06-03 20:38:03 +0900346 break;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900347 case TOMOYO_ID_ALIAS:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900348 tomoyo_del_alias(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900349 break;
350 case TOMOYO_ID_GLOBALLY_READABLE:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900351 tomoyo_del_allow_read(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900352 break;
353 case TOMOYO_ID_PATTERN:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900354 tomoyo_del_file_pattern(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900355 break;
356 case TOMOYO_ID_NO_REWRITE:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900357 tomoyo_del_no_rewrite(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900358 break;
359 case TOMOYO_ID_MANAGER:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900360 tomoyo_del_manager(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900361 break;
362 case TOMOYO_ID_NAME:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900363 tomoyo_del_name(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900364 break;
365 case TOMOYO_ID_ACL:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900366 tomoyo_del_acl(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900367 break;
368 case TOMOYO_ID_DOMAIN:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900369 if (!tomoyo_del_domain(element))
Tetsuo Handa847b1732010-02-11 09:43:54 +0900370 continue;
371 break;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900372 case TOMOYO_ID_PATH_GROUP:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900373 tomoyo_del_path_group(element);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900374 break;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900375 case TOMOYO_ID_GROUP:
376 tomoyo_del_group(element);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900377 break;
378 case TOMOYO_ID_NUMBER_GROUP:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900379 tomoyo_del_number_group(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900380 break;
381 }
Tetsuo Handae79acf02010-06-16 16:31:50 +0900382 tomoyo_memory_free(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900383 list_del(&p->list);
384 kfree(p);
385 }
386}
387
388static int tomoyo_gc_thread(void *unused)
389{
390 daemonize("GC for TOMOYO");
391 if (mutex_trylock(&tomoyo_gc_mutex)) {
392 int i;
393 for (i = 0; i < 10; i++) {
394 tomoyo_collect_entry();
395 if (list_empty(&tomoyo_gc_queue))
396 break;
397 synchronize_srcu(&tomoyo_ss);
398 tomoyo_kfree_entry();
399 }
400 mutex_unlock(&tomoyo_gc_mutex);
401 }
402 do_exit(0);
403}
404
405void tomoyo_run_gc(void)
406{
407 struct task_struct *task = kthread_create(tomoyo_gc_thread, NULL,
408 "GC for TOMOYO");
409 if (!IS_ERR(task))
410 wake_up_process(task);
411}