hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/security/tomoyo/gc.c
....@@ -77,11 +77,13 @@
7777 spin_lock(&tomoyo_io_buffer_list_lock);
7878 list_for_each_entry(head, &tomoyo_io_buffer_list, list) {
7979 int i;
80
+
8081 head->users++;
8182 spin_unlock(&tomoyo_io_buffer_list_lock);
8283 mutex_lock(&head->io_sem);
8384 for (i = 0; i < TOMOYO_MAX_IO_READ_QUEUE; i++) {
8485 const char *w = head->r.w[i];
86
+
8587 if (w < string || w > string + size)
8688 continue;
8789 in_use = true;
....@@ -108,6 +110,7 @@
108110 {
109111 struct tomoyo_transition_control *ptr =
110112 container_of(element, typeof(*ptr), head.list);
113
+
111114 tomoyo_put_name(ptr->domainname);
112115 tomoyo_put_name(ptr->program);
113116 }
....@@ -123,6 +126,7 @@
123126 {
124127 struct tomoyo_aggregator *ptr =
125128 container_of(element, typeof(*ptr), head.list);
129
+
126130 tomoyo_put_name(ptr->original_name);
127131 tomoyo_put_name(ptr->aggregated_name);
128132 }
....@@ -138,6 +142,7 @@
138142 {
139143 struct tomoyo_manager *ptr =
140144 container_of(element, typeof(*ptr), head.list);
145
+
141146 tomoyo_put_name(ptr->manager);
142147 }
143148
....@@ -152,6 +157,7 @@
152157 {
153158 struct tomoyo_acl_info *acl =
154159 container_of(element, typeof(*acl), list);
160
+
155161 tomoyo_put_condition(acl->cond);
156162 switch (acl->type) {
157163 case TOMOYO_TYPE_PATH_ACL:
....@@ -226,6 +232,7 @@
226232 {
227233 struct tomoyo_task_acl *entry =
228234 container_of(acl, typeof(*entry), head);
235
+
229236 tomoyo_put_name(entry->domainname);
230237 }
231238 break;
....@@ -247,6 +254,7 @@
247254 container_of(element, typeof(*domain), list);
248255 struct tomoyo_acl_info *acl;
249256 struct tomoyo_acl_info *tmp;
257
+
250258 /*
251259 * Since this domain is referenced from neither
252260 * "struct tomoyo_io_buffer" nor "struct cred"->security, we can delete
....@@ -286,6 +294,7 @@
286294 = (const struct tomoyo_argv *) (names_p + names_count);
287295 const struct tomoyo_envp *envp
288296 = (const struct tomoyo_envp *) (argv + argc);
297
+
289298 for (i = 0; i < numbers_count; i++)
290299 tomoyo_put_number_union(numbers_p++);
291300 for (i = 0; i < names_count; i++)
....@@ -321,6 +330,7 @@
321330 {
322331 struct tomoyo_path_group *member =
323332 container_of(element, typeof(*member), head.list);
333
+
324334 tomoyo_put_name(member->member_name);
325335 }
326336
....@@ -335,6 +345,7 @@
335345 {
336346 struct tomoyo_group *group =
337347 container_of(element, typeof(*group), head.list);
348
+
338349 tomoyo_put_name(group->group_name);
339350 }
340351
....@@ -476,6 +487,7 @@
476487 {
477488 struct tomoyo_acl_head *member;
478489 struct tomoyo_acl_head *tmp;
490
+
479491 list_for_each_entry_safe(member, tmp, member_list, list) {
480492 if (!member->is_deleted)
481493 continue;
....@@ -495,6 +507,7 @@
495507 {
496508 struct tomoyo_acl_info *acl;
497509 struct tomoyo_acl_info *tmp;
510
+
498511 list_for_each_entry_safe(acl, tmp, list, list) {
499512 if (!acl->is_deleted)
500513 continue;
....@@ -513,10 +526,12 @@
513526 int i;
514527 enum tomoyo_policy_id id;
515528 struct tomoyo_policy_namespace *ns;
529
+
516530 mutex_lock(&tomoyo_policy_lock);
517531 {
518532 struct tomoyo_domain_info *domain;
519533 struct tomoyo_domain_info *tmp;
534
+
520535 list_for_each_entry_safe(domain, tmp, &tomoyo_domain_list,
521536 list) {
522537 tomoyo_collect_acl(&domain->acl_info_list);
....@@ -534,6 +549,7 @@
534549 {
535550 struct tomoyo_shared_acl_head *ptr;
536551 struct tomoyo_shared_acl_head *tmp;
552
+
537553 list_for_each_entry_safe(ptr, tmp, &tomoyo_condition_list,
538554 list) {
539555 if (atomic_read(&ptr->users) > 0)
....@@ -547,6 +563,7 @@
547563 struct list_head *list = &ns->group_list[i];
548564 struct tomoyo_group *group;
549565 struct tomoyo_group *tmp;
566
+
550567 switch (i) {
551568 case 0:
552569 id = TOMOYO_ID_PATH_GROUP;
....@@ -574,6 +591,7 @@
574591 struct list_head *list = &tomoyo_name_list[i];
575592 struct tomoyo_shared_acl_head *ptr;
576593 struct tomoyo_shared_acl_head *tmp;
594
+
577595 list_for_each_entry_safe(ptr, tmp, list, list) {
578596 if (atomic_read(&ptr->users) > 0)
579597 continue;
....@@ -595,6 +613,7 @@
595613 {
596614 /* Garbage collector thread is exclusive. */
597615 static DEFINE_MUTEX(tomoyo_gc_mutex);
616
+
598617 if (!mutex_trylock(&tomoyo_gc_mutex))
599618 goto out;
600619 tomoyo_collect_entry();