blob: a54bd823fcd5a9ada71365e11e197dce596dff38 [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 Handa7762fbf2010-05-10 17:30:26 +090015 TOMOYO_ID_PATH_GROUP,
16 TOMOYO_ID_PATH_GROUP_MEMBER,
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +090017 TOMOYO_ID_NUMBER_GROUP,
18 TOMOYO_ID_NUMBER_GROUP_MEMBER,
Tetsuo Handa847b1732010-02-11 09:43:54 +090019 TOMOYO_ID_DOMAIN_INITIALIZER,
20 TOMOYO_ID_DOMAIN_KEEPER,
Tetsuo Handa10843072010-06-03 20:38:03 +090021 TOMOYO_ID_AGGREGATOR,
Tetsuo Handa847b1732010-02-11 09:43:54 +090022 TOMOYO_ID_ALIAS,
23 TOMOYO_ID_GLOBALLY_READABLE,
24 TOMOYO_ID_PATTERN,
25 TOMOYO_ID_NO_REWRITE,
26 TOMOYO_ID_MANAGER,
27 TOMOYO_ID_NAME,
28 TOMOYO_ID_ACL,
Tetsuo Handad2f8b232010-06-15 10:10:37 +090029 TOMOYO_ID_DOMAIN,
30 TOMOYO_MAX_POLICY
Tetsuo Handa847b1732010-02-11 09:43:54 +090031};
32
33struct tomoyo_gc_entry {
34 struct list_head list;
35 int type;
Tetsuo Handae79acf02010-06-16 16:31:50 +090036 struct list_head *element;
Tetsuo Handa847b1732010-02-11 09:43:54 +090037};
38static LIST_HEAD(tomoyo_gc_queue);
39static DEFINE_MUTEX(tomoyo_gc_mutex);
40
41/* Caller holds tomoyo_policy_lock mutex. */
Tetsuo Handae79acf02010-06-16 16:31:50 +090042static bool tomoyo_add_to_gc(const int type, struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +090043{
44 struct tomoyo_gc_entry *entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
45 if (!entry)
46 return false;
47 entry->type = type;
48 entry->element = element;
49 list_add(&entry->list, &tomoyo_gc_queue);
Tetsuo Handae79acf02010-06-16 16:31:50 +090050 list_del_rcu(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +090051 return true;
52}
53
Tetsuo Handae79acf02010-06-16 16:31:50 +090054static void tomoyo_del_allow_read(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +090055{
Tetsuo Handae79acf02010-06-16 16:31:50 +090056 struct tomoyo_globally_readable_file_entry *ptr =
57 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +090058 tomoyo_put_name(ptr->filename);
59}
60
Tetsuo Handae79acf02010-06-16 16:31:50 +090061static void tomoyo_del_file_pattern(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +090062{
Tetsuo Handae79acf02010-06-16 16:31:50 +090063 struct tomoyo_pattern_entry *ptr =
64 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +090065 tomoyo_put_name(ptr->pattern);
66}
67
Tetsuo Handae79acf02010-06-16 16:31:50 +090068static void tomoyo_del_no_rewrite(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +090069{
Tetsuo Handae79acf02010-06-16 16:31:50 +090070 struct tomoyo_no_rewrite_entry *ptr =
71 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +090072 tomoyo_put_name(ptr->pattern);
73}
74
Tetsuo Handae79acf02010-06-16 16:31:50 +090075static void tomoyo_del_domain_initializer(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +090076{
Tetsuo Handae79acf02010-06-16 16:31:50 +090077 struct tomoyo_domain_initializer_entry *ptr =
78 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +090079 tomoyo_put_name(ptr->domainname);
80 tomoyo_put_name(ptr->program);
81}
82
Tetsuo Handae79acf02010-06-16 16:31:50 +090083static void tomoyo_del_domain_keeper(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +090084{
Tetsuo Handae79acf02010-06-16 16:31:50 +090085 struct tomoyo_domain_keeper_entry *ptr =
86 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +090087 tomoyo_put_name(ptr->domainname);
88 tomoyo_put_name(ptr->program);
89}
90
Tetsuo Handae79acf02010-06-16 16:31:50 +090091static void tomoyo_del_aggregator(struct list_head *element)
Tetsuo Handa10843072010-06-03 20:38:03 +090092{
Tetsuo Handae79acf02010-06-16 16:31:50 +090093 struct tomoyo_aggregator_entry *ptr =
94 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa10843072010-06-03 20:38:03 +090095 tomoyo_put_name(ptr->original_name);
96 tomoyo_put_name(ptr->aggregated_name);
97}
98
Tetsuo Handae79acf02010-06-16 16:31:50 +090099static void tomoyo_del_alias(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +0900100{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900101 struct tomoyo_alias_entry *ptr =
102 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900103 tomoyo_put_name(ptr->original_name);
104 tomoyo_put_name(ptr->aliased_name);
105}
106
Tetsuo Handae79acf02010-06-16 16:31:50 +0900107static void tomoyo_del_manager(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +0900108{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900109 struct tomoyo_policy_manager_entry *ptr =
110 container_of(element, typeof(*ptr), head.list);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900111 tomoyo_put_name(ptr->manager);
112}
113
Tetsuo Handae79acf02010-06-16 16:31:50 +0900114static void tomoyo_del_acl(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +0900115{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900116 struct tomoyo_acl_info *acl =
117 container_of(element, typeof(*acl), list);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900118 switch (acl->type) {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900119 case TOMOYO_TYPE_PATH_ACL:
Tetsuo Handa847b1732010-02-11 09:43:54 +0900120 {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900121 struct tomoyo_path_acl *entry
Tetsuo Handa847b1732010-02-11 09:43:54 +0900122 = container_of(acl, typeof(*entry), head);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900123 tomoyo_put_name_union(&entry->name);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900124 }
125 break;
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900126 case TOMOYO_TYPE_PATH2_ACL:
Tetsuo Handa847b1732010-02-11 09:43:54 +0900127 {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900128 struct tomoyo_path2_acl *entry
Tetsuo Handa847b1732010-02-11 09:43:54 +0900129 = container_of(acl, typeof(*entry), head);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900130 tomoyo_put_name_union(&entry->name1);
131 tomoyo_put_name_union(&entry->name2);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900132 }
133 break;
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900134 case TOMOYO_TYPE_PATH_NUMBER_ACL:
135 {
136 struct tomoyo_path_number_acl *entry
137 = container_of(acl, typeof(*entry), head);
138 tomoyo_put_name_union(&entry->name);
139 tomoyo_put_number_union(&entry->number);
140 }
141 break;
Tetsuo Handa75093152010-06-16 16:23:55 +0900142 case TOMOYO_TYPE_MKDEV_ACL:
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900143 {
Tetsuo Handa75093152010-06-16 16:23:55 +0900144 struct tomoyo_mkdev_acl *entry
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900145 = container_of(acl, typeof(*entry), head);
146 tomoyo_put_name_union(&entry->name);
147 tomoyo_put_number_union(&entry->mode);
148 tomoyo_put_number_union(&entry->major);
149 tomoyo_put_number_union(&entry->minor);
150 }
151 break;
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900152 case TOMOYO_TYPE_MOUNT_ACL:
153 {
154 struct tomoyo_mount_acl *entry
155 = container_of(acl, typeof(*entry), head);
156 tomoyo_put_name_union(&entry->dev_name);
157 tomoyo_put_name_union(&entry->dir_name);
158 tomoyo_put_name_union(&entry->fs_type);
159 tomoyo_put_number_union(&entry->flags);
160 }
161 break;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900162 }
163}
164
Tetsuo Handae79acf02010-06-16 16:31:50 +0900165static bool tomoyo_del_domain(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +0900166{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900167 struct tomoyo_domain_info *domain =
168 container_of(element, typeof(*domain), list);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900169 struct tomoyo_acl_info *acl;
170 struct tomoyo_acl_info *tmp;
171 /*
172 * Since we don't protect whole execve() operation using SRCU,
173 * we need to recheck domain->users at this point.
174 *
175 * (1) Reader starts SRCU section upon execve().
176 * (2) Reader traverses tomoyo_domain_list and finds this domain.
177 * (3) Writer marks this domain as deleted.
178 * (4) Garbage collector removes this domain from tomoyo_domain_list
179 * because this domain is marked as deleted and used by nobody.
180 * (5) Reader saves reference to this domain into
181 * "struct linux_binprm"->cred->security .
182 * (6) Reader finishes SRCU section, although execve() operation has
183 * not finished yet.
184 * (7) Garbage collector waits for SRCU synchronization.
185 * (8) Garbage collector kfree() this domain because this domain is
186 * used by nobody.
187 * (9) Reader finishes execve() operation and restores this domain from
188 * "struct linux_binprm"->cred->security.
189 *
190 * By updating domain->users at (5), we can solve this race problem
191 * by rechecking domain->users at (8).
192 */
193 if (atomic_read(&domain->users))
194 return false;
195 list_for_each_entry_safe(acl, tmp, &domain->acl_info_list, list) {
Tetsuo Handae79acf02010-06-16 16:31:50 +0900196 tomoyo_del_acl(&acl->list);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900197 tomoyo_memory_free(acl);
198 }
199 tomoyo_put_name(domain->domainname);
200 return true;
201}
202
203
Tetsuo Handae79acf02010-06-16 16:31:50 +0900204static void tomoyo_del_name(struct list_head *element)
Tetsuo Handa847b1732010-02-11 09:43:54 +0900205{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900206 const struct tomoyo_name_entry *ptr =
207 container_of(element, typeof(*ptr), list);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900208}
209
Tetsuo Handae79acf02010-06-16 16:31:50 +0900210static void tomoyo_del_path_group_member(struct list_head *element)
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900211{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900212 struct tomoyo_path_group_member *member =
213 container_of(element, typeof(*member), head.list);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900214 tomoyo_put_name(member->member_name);
215}
216
Tetsuo Handae79acf02010-06-16 16:31:50 +0900217static void tomoyo_del_path_group(struct list_head *element)
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900218{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900219 struct tomoyo_path_group *group =
220 container_of(element, typeof(*group), list);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900221 tomoyo_put_name(group->group_name);
222}
223
Tetsuo Handae79acf02010-06-16 16:31:50 +0900224static void tomoyo_del_number_group_member(struct list_head *element)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900225{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900226 struct tomoyo_number_group_member *member =
227 container_of(element, typeof(*member), head.list);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900228}
229
Tetsuo Handae79acf02010-06-16 16:31:50 +0900230static void tomoyo_del_number_group(struct list_head *element)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900231{
Tetsuo Handae79acf02010-06-16 16:31:50 +0900232 struct tomoyo_number_group *group =
233 container_of(element, typeof(*group), list);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900234 tomoyo_put_name(group->group_name);
235}
236
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900237static struct list_head *tomoyo_policy_list[TOMOYO_MAX_POLICY] = {
238 [TOMOYO_ID_GLOBALLY_READABLE] = &tomoyo_globally_readable_list,
239 [TOMOYO_ID_PATTERN] = &tomoyo_pattern_list,
240 [TOMOYO_ID_NO_REWRITE] = &tomoyo_no_rewrite_list,
241 [TOMOYO_ID_DOMAIN_INITIALIZER] = &tomoyo_domain_initializer_list,
242 [TOMOYO_ID_DOMAIN_KEEPER] = &tomoyo_domain_keeper_list,
243 [TOMOYO_ID_AGGREGATOR] = &tomoyo_aggregator_list,
244 [TOMOYO_ID_ALIAS] = &tomoyo_alias_list,
245 [TOMOYO_ID_MANAGER] = &tomoyo_policy_manager_list,
246};
247
248static bool tomoyo_collect_member(struct list_head *member_list, int id)
249{
250 struct tomoyo_acl_head *member;
251 list_for_each_entry(member, member_list, list) {
252 if (!member->is_deleted)
253 continue;
254 if (!tomoyo_add_to_gc(id, &member->list))
255 return false;
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900256 }
257 return true;
258}
259
260static bool tomoyo_collect_acl(struct tomoyo_domain_info *domain)
261{
262 struct tomoyo_acl_info *acl;
263 list_for_each_entry(acl, &domain->acl_info_list, list) {
264 if (!acl->is_deleted)
265 continue;
266 if (!tomoyo_add_to_gc(TOMOYO_ID_ACL, &acl->list))
267 return false;
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900268 }
269 return true;
270}
271
Tetsuo Handa847b1732010-02-11 09:43:54 +0900272static void tomoyo_collect_entry(void)
273{
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900274 int i;
Tetsuo Handa29282382010-05-06 00:18:15 +0900275 if (mutex_lock_interruptible(&tomoyo_policy_lock))
276 return;
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900277 for (i = 0; i < TOMOYO_MAX_POLICY; i++) {
278 if (tomoyo_policy_list[i])
279 if (!tomoyo_collect_member(tomoyo_policy_list[i], i))
280 goto unlock;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900281 }
282 {
283 struct tomoyo_domain_info *domain;
284 list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900285 if (!tomoyo_collect_acl(domain))
286 goto unlock;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900287 if (!domain->is_deleted || atomic_read(&domain->users))
288 continue;
289 /*
290 * Nobody is referring this domain. But somebody may
291 * refer this domain after successful execve().
292 * We recheck domain->users after SRCU synchronization.
293 */
Tetsuo Handae79acf02010-06-16 16:31:50 +0900294 if (!tomoyo_add_to_gc(TOMOYO_ID_DOMAIN, &domain->list))
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900295 goto unlock;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900296 }
297 }
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900298 for (i = 0; i < TOMOYO_MAX_HASH; i++) {
299 struct tomoyo_name_entry *ptr;
300 list_for_each_entry_rcu(ptr, &tomoyo_name_list[i], list) {
301 if (atomic_read(&ptr->users))
302 continue;
Tetsuo Handae79acf02010-06-16 16:31:50 +0900303 if (!tomoyo_add_to_gc(TOMOYO_ID_NAME, &ptr->list))
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900304 goto unlock;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900305 }
306 }
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900307 {
308 struct tomoyo_path_group *group;
309 list_for_each_entry_rcu(group, &tomoyo_path_group_list, list) {
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900310 tomoyo_collect_member(&group->member_list,
311 TOMOYO_ID_PATH_GROUP_MEMBER);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900312 if (!list_empty(&group->member_list) ||
313 atomic_read(&group->users))
314 continue;
Tetsuo Handae79acf02010-06-16 16:31:50 +0900315 if (!tomoyo_add_to_gc(TOMOYO_ID_PATH_GROUP,
316 &group->list))
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900317 goto unlock;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900318 }
319 }
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900320 {
321 struct tomoyo_number_group *group;
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900322 list_for_each_entry_rcu(group, &tomoyo_number_group_list,
323 list) {
324 tomoyo_collect_member(&group->member_list,
325 TOMOYO_ID_NUMBER_GROUP_MEMBER);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900326 if (!list_empty(&group->member_list) ||
327 atomic_read(&group->users))
328 continue;
Tetsuo Handae79acf02010-06-16 16:31:50 +0900329 if (!tomoyo_add_to_gc(TOMOYO_ID_NUMBER_GROUP,
330 &group->list))
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900331 goto unlock;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900332 }
333 }
Tetsuo Handad2f8b232010-06-15 10:10:37 +0900334 unlock:
Tetsuo Handa29282382010-05-06 00:18:15 +0900335 mutex_unlock(&tomoyo_policy_lock);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900336}
337
338static void tomoyo_kfree_entry(void)
339{
340 struct tomoyo_gc_entry *p;
341 struct tomoyo_gc_entry *tmp;
342
343 list_for_each_entry_safe(p, tmp, &tomoyo_gc_queue, list) {
Tetsuo Handae79acf02010-06-16 16:31:50 +0900344 struct list_head *element = p->element;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900345 switch (p->type) {
346 case TOMOYO_ID_DOMAIN_INITIALIZER:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900347 tomoyo_del_domain_initializer(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900348 break;
349 case TOMOYO_ID_DOMAIN_KEEPER:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900350 tomoyo_del_domain_keeper(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900351 break;
Tetsuo Handa10843072010-06-03 20:38:03 +0900352 case TOMOYO_ID_AGGREGATOR:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900353 tomoyo_del_aggregator(element);
Tetsuo Handa10843072010-06-03 20:38:03 +0900354 break;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900355 case TOMOYO_ID_ALIAS:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900356 tomoyo_del_alias(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900357 break;
358 case TOMOYO_ID_GLOBALLY_READABLE:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900359 tomoyo_del_allow_read(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900360 break;
361 case TOMOYO_ID_PATTERN:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900362 tomoyo_del_file_pattern(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900363 break;
364 case TOMOYO_ID_NO_REWRITE:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900365 tomoyo_del_no_rewrite(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900366 break;
367 case TOMOYO_ID_MANAGER:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900368 tomoyo_del_manager(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900369 break;
370 case TOMOYO_ID_NAME:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900371 tomoyo_del_name(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900372 break;
373 case TOMOYO_ID_ACL:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900374 tomoyo_del_acl(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900375 break;
376 case TOMOYO_ID_DOMAIN:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900377 if (!tomoyo_del_domain(element))
Tetsuo Handa847b1732010-02-11 09:43:54 +0900378 continue;
379 break;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900380 case TOMOYO_ID_PATH_GROUP_MEMBER:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900381 tomoyo_del_path_group_member(element);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900382 break;
383 case TOMOYO_ID_PATH_GROUP:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900384 tomoyo_del_path_group(element);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900385 break;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900386 case TOMOYO_ID_NUMBER_GROUP_MEMBER:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900387 tomoyo_del_number_group_member(element);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900388 break;
389 case TOMOYO_ID_NUMBER_GROUP:
Tetsuo Handae79acf02010-06-16 16:31:50 +0900390 tomoyo_del_number_group(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900391 break;
392 }
Tetsuo Handae79acf02010-06-16 16:31:50 +0900393 tomoyo_memory_free(element);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900394 list_del(&p->list);
395 kfree(p);
396 }
397}
398
399static int tomoyo_gc_thread(void *unused)
400{
401 daemonize("GC for TOMOYO");
402 if (mutex_trylock(&tomoyo_gc_mutex)) {
403 int i;
404 for (i = 0; i < 10; i++) {
405 tomoyo_collect_entry();
406 if (list_empty(&tomoyo_gc_queue))
407 break;
408 synchronize_srcu(&tomoyo_ss);
409 tomoyo_kfree_entry();
410 }
411 mutex_unlock(&tomoyo_gc_mutex);
412 }
413 do_exit(0);
414}
415
416void tomoyo_run_gc(void)
417{
418 struct task_struct *task = kthread_create(tomoyo_gc_thread, NULL,
419 "GC for TOMOYO");
420 if (!IS_ERR(task))
421 wake_up_process(task);
422}