diff options
author | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2010-01-04 16:39:37 -0500 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2010-01-10 17:27:40 -0500 |
commit | cd7bec6ad80188394a8ea857ff1aa3512fc2282a (patch) | |
tree | 598e7d59c29966e0d8fa8abf24eb51bbb2f567a6 /security/tomoyo/file.c | |
parent | e41035a996356c257183e53a70abfb46fa84908b (diff) |
TOMOYO: Remove memory pool for list elements.
Currently, TOMOYO allocates memory for list elements from memory pool allocated
by kmalloc(PAGE_SIZE). But that makes it difficult to kfree() when garbage
collector is added. Thus, remove memory pool and use kmalloc(sizeof()).
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security/tomoyo/file.c')
-rw-r--r-- | security/tomoyo/file.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c index 5d1689d6e16c..075392c052b4 100644 --- a/security/tomoyo/file.c +++ b/security/tomoyo/file.c | |||
@@ -225,6 +225,7 @@ static int tomoyo_update_globally_readable_entry(const char *filename, | |||
225 | saved_filename = tomoyo_save_name(filename); | 225 | saved_filename = tomoyo_save_name(filename); |
226 | if (!saved_filename) | 226 | if (!saved_filename) |
227 | return -ENOMEM; | 227 | return -ENOMEM; |
228 | new_entry = kmalloc(sizeof(*new_entry), GFP_KERNEL); | ||
228 | mutex_lock(&tomoyo_policy_lock); | 229 | mutex_lock(&tomoyo_policy_lock); |
229 | list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list, list) { | 230 | list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list, list) { |
230 | if (ptr->filename != saved_filename) | 231 | if (ptr->filename != saved_filename) |
@@ -237,14 +238,15 @@ static int tomoyo_update_globally_readable_entry(const char *filename, | |||
237 | error = -ENOENT; | 238 | error = -ENOENT; |
238 | goto out; | 239 | goto out; |
239 | } | 240 | } |
240 | new_entry = tomoyo_alloc_element(sizeof(*new_entry)); | 241 | if (!tomoyo_memory_ok(new_entry)) |
241 | if (!new_entry) | ||
242 | goto out; | 242 | goto out; |
243 | new_entry->filename = saved_filename; | 243 | new_entry->filename = saved_filename; |
244 | list_add_tail_rcu(&new_entry->list, &tomoyo_globally_readable_list); | 244 | list_add_tail_rcu(&new_entry->list, &tomoyo_globally_readable_list); |
245 | new_entry = NULL; | ||
245 | error = 0; | 246 | error = 0; |
246 | out: | 247 | out: |
247 | mutex_unlock(&tomoyo_policy_lock); | 248 | mutex_unlock(&tomoyo_policy_lock); |
249 | kfree(new_entry); | ||
248 | return error; | 250 | return error; |
249 | } | 251 | } |
250 | 252 | ||
@@ -372,6 +374,7 @@ static int tomoyo_update_file_pattern_entry(const char *pattern, | |||
372 | saved_pattern = tomoyo_save_name(pattern); | 374 | saved_pattern = tomoyo_save_name(pattern); |
373 | if (!saved_pattern) | 375 | if (!saved_pattern) |
374 | return -ENOMEM; | 376 | return -ENOMEM; |
377 | new_entry = kmalloc(sizeof(*new_entry), GFP_KERNEL); | ||
375 | mutex_lock(&tomoyo_policy_lock); | 378 | mutex_lock(&tomoyo_policy_lock); |
376 | list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, list) { | 379 | list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, list) { |
377 | if (saved_pattern != ptr->pattern) | 380 | if (saved_pattern != ptr->pattern) |
@@ -384,14 +387,15 @@ static int tomoyo_update_file_pattern_entry(const char *pattern, | |||
384 | error = -ENOENT; | 387 | error = -ENOENT; |
385 | goto out; | 388 | goto out; |
386 | } | 389 | } |
387 | new_entry = tomoyo_alloc_element(sizeof(*new_entry)); | 390 | if (!tomoyo_memory_ok(new_entry)) |
388 | if (!new_entry) | ||
389 | goto out; | 391 | goto out; |
390 | new_entry->pattern = saved_pattern; | 392 | new_entry->pattern = saved_pattern; |
391 | list_add_tail_rcu(&new_entry->list, &tomoyo_pattern_list); | 393 | list_add_tail_rcu(&new_entry->list, &tomoyo_pattern_list); |
394 | new_entry = NULL; | ||
392 | error = 0; | 395 | error = 0; |
393 | out: | 396 | out: |
394 | mutex_unlock(&tomoyo_policy_lock); | 397 | mutex_unlock(&tomoyo_policy_lock); |
398 | kfree(new_entry); | ||
395 | return error; | 399 | return error; |
396 | } | 400 | } |
397 | 401 | ||
@@ -523,6 +527,7 @@ static int tomoyo_update_no_rewrite_entry(const char *pattern, | |||
523 | saved_pattern = tomoyo_save_name(pattern); | 527 | saved_pattern = tomoyo_save_name(pattern); |
524 | if (!saved_pattern) | 528 | if (!saved_pattern) |
525 | return -ENOMEM; | 529 | return -ENOMEM; |
530 | new_entry = kmalloc(sizeof(*new_entry), GFP_KERNEL); | ||
526 | mutex_lock(&tomoyo_policy_lock); | 531 | mutex_lock(&tomoyo_policy_lock); |
527 | list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list, list) { | 532 | list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list, list) { |
528 | if (ptr->pattern != saved_pattern) | 533 | if (ptr->pattern != saved_pattern) |
@@ -535,14 +540,15 @@ static int tomoyo_update_no_rewrite_entry(const char *pattern, | |||
535 | error = -ENOENT; | 540 | error = -ENOENT; |
536 | goto out; | 541 | goto out; |
537 | } | 542 | } |
538 | new_entry = tomoyo_alloc_element(sizeof(*new_entry)); | 543 | if (!tomoyo_memory_ok(new_entry)) |
539 | if (!new_entry) | ||
540 | goto out; | 544 | goto out; |
541 | new_entry->pattern = saved_pattern; | 545 | new_entry->pattern = saved_pattern; |
542 | list_add_tail_rcu(&new_entry->list, &tomoyo_no_rewrite_list); | 546 | list_add_tail_rcu(&new_entry->list, &tomoyo_no_rewrite_list); |
547 | new_entry = NULL; | ||
543 | error = 0; | 548 | error = 0; |
544 | out: | 549 | out: |
545 | mutex_unlock(&tomoyo_policy_lock); | 550 | mutex_unlock(&tomoyo_policy_lock); |
551 | kfree(new_entry); | ||
546 | return error; | 552 | return error; |
547 | } | 553 | } |
548 | 554 | ||
@@ -901,9 +907,13 @@ static int tomoyo_update_single_path_acl(const u8 type, const char *filename, | |||
901 | goto out; | 907 | goto out; |
902 | } | 908 | } |
903 | /* Not found. Append it to the tail. */ | 909 | /* Not found. Append it to the tail. */ |
904 | acl = tomoyo_alloc_acl_element(TOMOYO_TYPE_SINGLE_PATH_ACL); | 910 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
905 | if (!acl) | 911 | if (!tomoyo_memory_ok(acl)) { |
912 | kfree(acl); | ||
913 | acl = NULL; | ||
906 | goto out; | 914 | goto out; |
915 | } | ||
916 | acl->head.type = TOMOYO_TYPE_SINGLE_PATH_ACL; | ||
907 | if (perm <= 0xFFFF) | 917 | if (perm <= 0xFFFF) |
908 | acl->perm = perm; | 918 | acl->perm = perm; |
909 | else | 919 | else |
@@ -995,9 +1005,13 @@ static int tomoyo_update_double_path_acl(const u8 type, const char *filename1, | |||
995 | goto out; | 1005 | goto out; |
996 | } | 1006 | } |
997 | /* Not found. Append it to the tail. */ | 1007 | /* Not found. Append it to the tail. */ |
998 | acl = tomoyo_alloc_acl_element(TOMOYO_TYPE_DOUBLE_PATH_ACL); | 1008 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
999 | if (!acl) | 1009 | if (!tomoyo_memory_ok(acl)) { |
1010 | kfree(acl); | ||
1011 | acl = NULL; | ||
1000 | goto out; | 1012 | goto out; |
1013 | } | ||
1014 | acl->head.type = TOMOYO_TYPE_DOUBLE_PATH_ACL; | ||
1001 | acl->perm = perm; | 1015 | acl->perm = perm; |
1002 | acl->filename1 = saved_filename1; | 1016 | acl->filename1 = saved_filename1; |
1003 | acl->filename2 = saved_filename2; | 1017 | acl->filename2 = saved_filename2; |