diff options
author | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2010-02-10 19:41:58 -0500 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2010-02-14 17:00:16 -0500 |
commit | bf24fb016c861b7f52be0c36c4cedd3e89afa2e2 (patch) | |
tree | f485ca2e70d8305d9aaecf45b5fd929b68b971b2 /security/tomoyo/file.c | |
parent | ca0b7df3374c5566468c17f26fa2dfd3fe3c6a37 (diff) |
TOMOYO: Add refcounter on string data.
Add refcounter to "struct tomoyo_name_entry" and replace tomoyo_save_name()
with tomoyo_get_name()/tomoyo_put_name() pair so that we can kfree() when
garbage collector is added.
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security/tomoyo/file.c')
-rw-r--r-- | security/tomoyo/file.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c index f4a27714e077..a49e18cc7bc2 100644 --- a/security/tomoyo/file.c +++ b/security/tomoyo/file.c | |||
@@ -222,7 +222,7 @@ static int tomoyo_update_globally_readable_entry(const char *filename, | |||
222 | 222 | ||
223 | if (!tomoyo_is_correct_path(filename, 1, 0, -1, __func__)) | 223 | if (!tomoyo_is_correct_path(filename, 1, 0, -1, __func__)) |
224 | return -EINVAL; | 224 | return -EINVAL; |
225 | saved_filename = tomoyo_save_name(filename); | 225 | saved_filename = tomoyo_get_name(filename); |
226 | if (!saved_filename) | 226 | if (!saved_filename) |
227 | return -ENOMEM; | 227 | return -ENOMEM; |
228 | if (!is_delete) | 228 | if (!is_delete) |
@@ -237,11 +237,13 @@ static int tomoyo_update_globally_readable_entry(const char *filename, | |||
237 | } | 237 | } |
238 | if (!is_delete && error && tomoyo_memory_ok(entry)) { | 238 | if (!is_delete && error && tomoyo_memory_ok(entry)) { |
239 | entry->filename = saved_filename; | 239 | entry->filename = saved_filename; |
240 | saved_filename = NULL; | ||
240 | list_add_tail_rcu(&entry->list, &tomoyo_globally_readable_list); | 241 | list_add_tail_rcu(&entry->list, &tomoyo_globally_readable_list); |
241 | entry = NULL; | 242 | entry = NULL; |
242 | error = 0; | 243 | error = 0; |
243 | } | 244 | } |
244 | mutex_unlock(&tomoyo_policy_lock); | 245 | mutex_unlock(&tomoyo_policy_lock); |
246 | tomoyo_put_name(saved_filename); | ||
245 | kfree(entry); | 247 | kfree(entry); |
246 | return error; | 248 | return error; |
247 | } | 249 | } |
@@ -365,7 +367,7 @@ static int tomoyo_update_file_pattern_entry(const char *pattern, | |||
365 | const struct tomoyo_path_info *saved_pattern; | 367 | const struct tomoyo_path_info *saved_pattern; |
366 | int error = is_delete ? -ENOENT : -ENOMEM; | 368 | int error = is_delete ? -ENOENT : -ENOMEM; |
367 | 369 | ||
368 | saved_pattern = tomoyo_save_name(pattern); | 370 | saved_pattern = tomoyo_get_name(pattern); |
369 | if (!saved_pattern) | 371 | if (!saved_pattern) |
370 | return error; | 372 | return error; |
371 | if (!saved_pattern->is_patterned) | 373 | if (!saved_pattern->is_patterned) |
@@ -382,6 +384,7 @@ static int tomoyo_update_file_pattern_entry(const char *pattern, | |||
382 | } | 384 | } |
383 | if (!is_delete && error && tomoyo_memory_ok(entry)) { | 385 | if (!is_delete && error && tomoyo_memory_ok(entry)) { |
384 | entry->pattern = saved_pattern; | 386 | entry->pattern = saved_pattern; |
387 | saved_pattern = NULL; | ||
385 | list_add_tail_rcu(&entry->list, &tomoyo_pattern_list); | 388 | list_add_tail_rcu(&entry->list, &tomoyo_pattern_list); |
386 | entry = NULL; | 389 | entry = NULL; |
387 | error = 0; | 390 | error = 0; |
@@ -389,6 +392,7 @@ static int tomoyo_update_file_pattern_entry(const char *pattern, | |||
389 | mutex_unlock(&tomoyo_policy_lock); | 392 | mutex_unlock(&tomoyo_policy_lock); |
390 | out: | 393 | out: |
391 | kfree(entry); | 394 | kfree(entry); |
395 | tomoyo_put_name(saved_pattern); | ||
392 | return error; | 396 | return error; |
393 | } | 397 | } |
394 | 398 | ||
@@ -518,7 +522,7 @@ static int tomoyo_update_no_rewrite_entry(const char *pattern, | |||
518 | 522 | ||
519 | if (!tomoyo_is_correct_path(pattern, 0, 0, 0, __func__)) | 523 | if (!tomoyo_is_correct_path(pattern, 0, 0, 0, __func__)) |
520 | return -EINVAL; | 524 | return -EINVAL; |
521 | saved_pattern = tomoyo_save_name(pattern); | 525 | saved_pattern = tomoyo_get_name(pattern); |
522 | if (!saved_pattern) | 526 | if (!saved_pattern) |
523 | return error; | 527 | return error; |
524 | if (!is_delete) | 528 | if (!is_delete) |
@@ -533,11 +537,13 @@ static int tomoyo_update_no_rewrite_entry(const char *pattern, | |||
533 | } | 537 | } |
534 | if (!is_delete && error && tomoyo_memory_ok(entry)) { | 538 | if (!is_delete && error && tomoyo_memory_ok(entry)) { |
535 | entry->pattern = saved_pattern; | 539 | entry->pattern = saved_pattern; |
540 | saved_pattern = NULL; | ||
536 | list_add_tail_rcu(&entry->list, &tomoyo_no_rewrite_list); | 541 | list_add_tail_rcu(&entry->list, &tomoyo_no_rewrite_list); |
537 | entry = NULL; | 542 | entry = NULL; |
538 | error = 0; | 543 | error = 0; |
539 | } | 544 | } |
540 | mutex_unlock(&tomoyo_policy_lock); | 545 | mutex_unlock(&tomoyo_policy_lock); |
546 | tomoyo_put_name(saved_pattern); | ||
541 | kfree(entry); | 547 | kfree(entry); |
542 | return error; | 548 | return error; |
543 | } | 549 | } |
@@ -867,7 +873,7 @@ static int tomoyo_update_single_path_acl(const u8 type, const char *filename, | |||
867 | return -EINVAL; | 873 | return -EINVAL; |
868 | if (!tomoyo_is_correct_path(filename, 0, 0, 0, __func__)) | 874 | if (!tomoyo_is_correct_path(filename, 0, 0, 0, __func__)) |
869 | return -EINVAL; | 875 | return -EINVAL; |
870 | saved_filename = tomoyo_save_name(filename); | 876 | saved_filename = tomoyo_get_name(filename); |
871 | if (!saved_filename) | 877 | if (!saved_filename) |
872 | return -ENOMEM; | 878 | return -ENOMEM; |
873 | if (!is_delete) | 879 | if (!is_delete) |
@@ -913,12 +919,14 @@ static int tomoyo_update_single_path_acl(const u8 type, const char *filename, | |||
913 | if (perm == (1 << TOMOYO_TYPE_READ_WRITE_ACL)) | 919 | if (perm == (1 << TOMOYO_TYPE_READ_WRITE_ACL)) |
914 | entry->perm |= rw_mask; | 920 | entry->perm |= rw_mask; |
915 | entry->filename = saved_filename; | 921 | entry->filename = saved_filename; |
922 | saved_filename = NULL; | ||
916 | list_add_tail_rcu(&entry->head.list, &domain->acl_info_list); | 923 | list_add_tail_rcu(&entry->head.list, &domain->acl_info_list); |
917 | entry = NULL; | 924 | entry = NULL; |
918 | error = 0; | 925 | error = 0; |
919 | } | 926 | } |
920 | mutex_unlock(&tomoyo_policy_lock); | 927 | mutex_unlock(&tomoyo_policy_lock); |
921 | kfree(entry); | 928 | kfree(entry); |
929 | tomoyo_put_name(saved_filename); | ||
922 | return error; | 930 | return error; |
923 | } | 931 | } |
924 | 932 | ||
@@ -952,8 +960,8 @@ static int tomoyo_update_double_path_acl(const u8 type, const char *filename1, | |||
952 | if (!tomoyo_is_correct_path(filename1, 0, 0, 0, __func__) || | 960 | if (!tomoyo_is_correct_path(filename1, 0, 0, 0, __func__) || |
953 | !tomoyo_is_correct_path(filename2, 0, 0, 0, __func__)) | 961 | !tomoyo_is_correct_path(filename2, 0, 0, 0, __func__)) |
954 | return -EINVAL; | 962 | return -EINVAL; |
955 | saved_filename1 = tomoyo_save_name(filename1); | 963 | saved_filename1 = tomoyo_get_name(filename1); |
956 | saved_filename2 = tomoyo_save_name(filename2); | 964 | saved_filename2 = tomoyo_get_name(filename2); |
957 | if (!saved_filename1 || !saved_filename2) | 965 | if (!saved_filename1 || !saved_filename2) |
958 | goto out; | 966 | goto out; |
959 | if (!is_delete) | 967 | if (!is_delete) |
@@ -979,13 +987,17 @@ static int tomoyo_update_double_path_acl(const u8 type, const char *filename1, | |||
979 | entry->head.type = TOMOYO_TYPE_DOUBLE_PATH_ACL; | 987 | entry->head.type = TOMOYO_TYPE_DOUBLE_PATH_ACL; |
980 | entry->perm = perm; | 988 | entry->perm = perm; |
981 | entry->filename1 = saved_filename1; | 989 | entry->filename1 = saved_filename1; |
990 | saved_filename1 = NULL; | ||
982 | entry->filename2 = saved_filename2; | 991 | entry->filename2 = saved_filename2; |
992 | saved_filename2 = NULL; | ||
983 | list_add_tail_rcu(&entry->head.list, &domain->acl_info_list); | 993 | list_add_tail_rcu(&entry->head.list, &domain->acl_info_list); |
984 | entry = NULL; | 994 | entry = NULL; |
985 | error = 0; | 995 | error = 0; |
986 | } | 996 | } |
987 | mutex_unlock(&tomoyo_policy_lock); | 997 | mutex_unlock(&tomoyo_policy_lock); |
988 | out: | 998 | out: |
999 | tomoyo_put_name(saved_filename1); | ||
1000 | tomoyo_put_name(saved_filename2); | ||
989 | kfree(entry); | 1001 | kfree(entry); |
990 | return error; | 1002 | return error; |
991 | } | 1003 | } |