Skip to content

Commit f9732ea

Browse files
Tetsuo Handaxjamesmorris
authored andcommitted
TOMOYO: Simplify garbage collector.
When TOMOYO started using garbage collector at commit 847b173 "TOMOYO: Add garbage collector.", we waited for close() before kfree(). Thus, elements to be kfree()d were queued up using tomoyo_gc_list list. But it turned out that tomoyo_element_linked_by_gc() tends to choke garbage collector when certain pattern of entries are queued. Since garbage collector is no longer waiting for close() since commit 2e503bb "TOMOYO: Fix lockdep warning.", we can remove tomoyo_gc_list list and tomoyo_element_linked_by_gc() by doing sequential processing. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: James Morris <jmorris@namei.org>
1 parent 778c4a4 commit f9732ea

5 files changed

Lines changed: 186 additions & 319 deletions

File tree

‎security/tomoyo/common.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252

5353
#define TOMOYO_EXEC_TMPSIZE 4096
5454

55+
/* Garbage collector is trying to kfree() this element. */
56+
#define TOMOYO_GC_IN_PROGRESS -1
57+
5558
/* Profile number is an integer between 0 and 255. */
5659
#define TOMOYO_MAX_PROFILES 256
5760

@@ -398,7 +401,7 @@ enum tomoyo_pref_index {
398401
/* Common header for holding ACL entries. */
399402
struct tomoyo_acl_head {
400403
struct list_head list;
401-
bool is_deleted;
404+
s8 is_deleted; /* true or false or TOMOYO_GC_IN_PROGRESS */
402405
} __packed;
403406

404407
/* Common header for shared entries. */
@@ -665,7 +668,7 @@ struct tomoyo_condition {
665668
struct tomoyo_acl_info {
666669
struct list_head list;
667670
struct tomoyo_condition *cond; /* Maybe NULL. */
668-
bool is_deleted;
671+
s8 is_deleted; /* true or false or TOMOYO_GC_IN_PROGRESS */
669672
u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */
670673
} __packed;
671674

‎security/tomoyo/condition.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,9 @@ static struct tomoyo_condition *tomoyo_commit_condition
400400
found = true;
401401
goto out;
402402
}
403-
list_for_each_entry_rcu(ptr, &tomoyo_condition_list, head.list) {
404-
if (!tomoyo_same_condition(ptr, entry))
403+
list_for_each_entry(ptr, &tomoyo_condition_list, head.list) {
404+
if (!tomoyo_same_condition(ptr, entry) ||
405+
atomic_read(&ptr->head.users) == TOMOYO_GC_IN_PROGRESS)
405406
continue;
406407
/* Same entry found. Share this entry. */
407408
atomic_inc(&ptr->head.users);
@@ -411,8 +412,7 @@ static struct tomoyo_condition *tomoyo_commit_condition
411412
if (!found) {
412413
if (tomoyo_memory_ok(entry)) {
413414
atomic_set(&entry->head.users, 1);
414-
list_add_rcu(&entry->head.list,
415-
&tomoyo_condition_list);
415+
list_add(&entry->head.list, &tomoyo_condition_list);
416416
} else {
417417
found = true;
418418
ptr = NULL;

‎security/tomoyo/domain.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
3939
if (mutex_lock_interruptible(&tomoyo_policy_lock))
4040
return -ENOMEM;
4141
list_for_each_entry_rcu(entry, list, list) {
42+
if (entry->is_deleted == TOMOYO_GC_IN_PROGRESS)
43+
continue;
4244
if (!check_duplicate(entry, new_entry))
4345
continue;
4446
entry->is_deleted = param->is_delete;
@@ -115,6 +117,8 @@ int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
115117
if (mutex_lock_interruptible(&tomoyo_policy_lock))
116118
goto out;
117119
list_for_each_entry_rcu(entry, list, list) {
120+
if (entry->is_deleted == TOMOYO_GC_IN_PROGRESS)
121+
continue;
118122
if (!tomoyo_same_acl_head(entry, new_entry) ||
119123
!check_duplicate(entry, new_entry))
120124
continue;

0 commit comments

Comments
 (0)