aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>2010-02-10 19:41:58 -0500
committerJames Morris <jmorris@namei.org>2010-02-14 17:00:16 -0500
commitbf24fb016c861b7f52be0c36c4cedd3e89afa2e2 (patch)
treef485ca2e70d8305d9aaecf45b5fd929b68b971b2 /security
parentca0b7df3374c5566468c17f26fa2dfd3fe3c6a37 (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')
-rw-r--r--security/tomoyo/common.c10
-rw-r--r--security/tomoyo/domain.c32
-rw-r--r--security/tomoyo/file.c24
-rw-r--r--security/tomoyo/realpath.c30
-rw-r--r--security/tomoyo/realpath.h21
5 files changed, 77 insertions, 40 deletions
diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c
index a53ee059da48..0c7ea51e7a45 100644
--- a/security/tomoyo/common.c
+++ b/security/tomoyo/common.c
@@ -12,8 +12,8 @@
12#include <linux/uaccess.h> 12#include <linux/uaccess.h>
13#include <linux/security.h> 13#include <linux/security.h>
14#include <linux/hardirq.h> 14#include <linux/hardirq.h>
15#include "realpath.h"
16#include "common.h" 15#include "common.h"
16#include "realpath.h"
17#include "tomoyo.h" 17#include "tomoyo.h"
18 18
19/* Lock for protecting policy. */ 19/* Lock for protecting policy. */
@@ -943,7 +943,9 @@ static int tomoyo_write_profile(struct tomoyo_io_buffer *head)
943 return -EINVAL; 943 return -EINVAL;
944 *cp = '\0'; 944 *cp = '\0';
945 if (!strcmp(data, "COMMENT")) { 945 if (!strcmp(data, "COMMENT")) {
946 profile->comment = tomoyo_save_name(cp + 1); 946 const struct tomoyo_path_info *old_comment = profile->comment;
947 profile->comment = tomoyo_get_name(cp + 1);
948 tomoyo_put_name(old_comment);
947 return 0; 949 return 0;
948 } 950 }
949 for (i = 0; i < TOMOYO_MAX_CONTROL_INDEX; i++) { 951 for (i = 0; i < TOMOYO_MAX_CONTROL_INDEX; i++) {
@@ -1117,7 +1119,7 @@ static int tomoyo_update_manager_entry(const char *manager,
1117 if (!tomoyo_is_correct_path(manager, 1, -1, -1, __func__)) 1119 if (!tomoyo_is_correct_path(manager, 1, -1, -1, __func__))
1118 return -EINVAL; 1120 return -EINVAL;
1119 } 1121 }
1120 saved_manager = tomoyo_save_name(manager); 1122 saved_manager = tomoyo_get_name(manager);
1121 if (!saved_manager) 1123 if (!saved_manager)
1122 return -ENOMEM; 1124 return -ENOMEM;
1123 if (!is_delete) 1125 if (!is_delete)
@@ -1132,12 +1134,14 @@ static int tomoyo_update_manager_entry(const char *manager,
1132 } 1134 }
1133 if (!is_delete && error && tomoyo_memory_ok(entry)) { 1135 if (!is_delete && error && tomoyo_memory_ok(entry)) {
1134 entry->manager = saved_manager; 1136 entry->manager = saved_manager;
1137 saved_manager = NULL;
1135 entry->is_domain = is_domain; 1138 entry->is_domain = is_domain;
1136 list_add_tail_rcu(&entry->list, &tomoyo_policy_manager_list); 1139 list_add_tail_rcu(&entry->list, &tomoyo_policy_manager_list);
1137 entry = NULL; 1140 entry = NULL;
1138 error = 0; 1141 error = 0;
1139 } 1142 }
1140 mutex_unlock(&tomoyo_policy_lock); 1143 mutex_unlock(&tomoyo_policy_lock);
1144 tomoyo_put_name(saved_manager);
1141 kfree(entry); 1145 kfree(entry);
1142 return error; 1146 return error;
1143} 1147}
diff --git a/security/tomoyo/domain.c b/security/tomoyo/domain.c
index 229de1e71a38..0b8262567809 100644
--- a/security/tomoyo/domain.c
+++ b/security/tomoyo/domain.c
@@ -203,7 +203,7 @@ static int tomoyo_update_domain_initializer_entry(const char *domainname,
203{ 203{
204 struct tomoyo_domain_initializer_entry *entry = NULL; 204 struct tomoyo_domain_initializer_entry *entry = NULL;
205 struct tomoyo_domain_initializer_entry *ptr; 205 struct tomoyo_domain_initializer_entry *ptr;
206 const struct tomoyo_path_info *saved_program; 206 const struct tomoyo_path_info *saved_program = NULL;
207 const struct tomoyo_path_info *saved_domainname = NULL; 207 const struct tomoyo_path_info *saved_domainname = NULL;
208 int error = is_delete ? -ENOENT : -ENOMEM; 208 int error = is_delete ? -ENOENT : -ENOMEM;
209 bool is_last_name = false; 209 bool is_last_name = false;
@@ -216,11 +216,11 @@ static int tomoyo_update_domain_initializer_entry(const char *domainname,
216 is_last_name = true; 216 is_last_name = true;
217 else if (!tomoyo_is_correct_domain(domainname, __func__)) 217 else if (!tomoyo_is_correct_domain(domainname, __func__))
218 return -EINVAL; 218 return -EINVAL;
219 saved_domainname = tomoyo_save_name(domainname); 219 saved_domainname = tomoyo_get_name(domainname);
220 if (!saved_domainname) 220 if (!saved_domainname)
221 goto out; 221 goto out;
222 } 222 }
223 saved_program = tomoyo_save_name(program); 223 saved_program = tomoyo_get_name(program);
224 if (!saved_program) 224 if (!saved_program)
225 goto out; 225 goto out;
226 if (!is_delete) 226 if (!is_delete)
@@ -237,7 +237,9 @@ static int tomoyo_update_domain_initializer_entry(const char *domainname,
237 } 237 }
238 if (!is_delete && error && tomoyo_memory_ok(entry)) { 238 if (!is_delete && error && tomoyo_memory_ok(entry)) {
239 entry->domainname = saved_domainname; 239 entry->domainname = saved_domainname;
240 saved_domainname = NULL;
240 entry->program = saved_program; 241 entry->program = saved_program;
242 saved_program = NULL;
241 entry->is_not = is_not; 243 entry->is_not = is_not;
242 entry->is_last_name = is_last_name; 244 entry->is_last_name = is_last_name;
243 list_add_tail_rcu(&entry->list, 245 list_add_tail_rcu(&entry->list,
@@ -247,6 +249,8 @@ static int tomoyo_update_domain_initializer_entry(const char *domainname,
247 } 249 }
248 mutex_unlock(&tomoyo_policy_lock); 250 mutex_unlock(&tomoyo_policy_lock);
249 out: 251 out:
252 tomoyo_put_name(saved_domainname);
253 tomoyo_put_name(saved_program);
250 kfree(entry); 254 kfree(entry);
251 return error; 255 return error;
252} 256}
@@ -419,7 +423,7 @@ static int tomoyo_update_domain_keeper_entry(const char *domainname,
419{ 423{
420 struct tomoyo_domain_keeper_entry *entry = NULL; 424 struct tomoyo_domain_keeper_entry *entry = NULL;
421 struct tomoyo_domain_keeper_entry *ptr; 425 struct tomoyo_domain_keeper_entry *ptr;
422 const struct tomoyo_path_info *saved_domainname; 426 const struct tomoyo_path_info *saved_domainname = NULL;
423 const struct tomoyo_path_info *saved_program = NULL; 427 const struct tomoyo_path_info *saved_program = NULL;
424 int error = is_delete ? -ENOENT : -ENOMEM; 428 int error = is_delete ? -ENOENT : -ENOMEM;
425 bool is_last_name = false; 429 bool is_last_name = false;
@@ -432,11 +436,11 @@ static int tomoyo_update_domain_keeper_entry(const char *domainname,
432 if (program) { 436 if (program) {
433 if (!tomoyo_is_correct_path(program, 1, -1, -1, __func__)) 437 if (!tomoyo_is_correct_path(program, 1, -1, -1, __func__))
434 return -EINVAL; 438 return -EINVAL;
435 saved_program = tomoyo_save_name(program); 439 saved_program = tomoyo_get_name(program);
436 if (!saved_program) 440 if (!saved_program)
437 goto out; 441 goto out;
438 } 442 }
439 saved_domainname = tomoyo_save_name(domainname); 443 saved_domainname = tomoyo_get_name(domainname);
440 if (!saved_domainname) 444 if (!saved_domainname)
441 goto out; 445 goto out;
442 if (!is_delete) 446 if (!is_delete)
@@ -453,7 +457,9 @@ static int tomoyo_update_domain_keeper_entry(const char *domainname,
453 } 457 }
454 if (!is_delete && error && tomoyo_memory_ok(entry)) { 458 if (!is_delete && error && tomoyo_memory_ok(entry)) {
455 entry->domainname = saved_domainname; 459 entry->domainname = saved_domainname;
460 saved_domainname = NULL;
456 entry->program = saved_program; 461 entry->program = saved_program;
462 saved_program = NULL;
457 entry->is_not = is_not; 463 entry->is_not = is_not;
458 entry->is_last_name = is_last_name; 464 entry->is_last_name = is_last_name;
459 list_add_tail_rcu(&entry->list, &tomoyo_domain_keeper_list); 465 list_add_tail_rcu(&entry->list, &tomoyo_domain_keeper_list);
@@ -462,6 +468,8 @@ static int tomoyo_update_domain_keeper_entry(const char *domainname,
462 } 468 }
463 mutex_unlock(&tomoyo_policy_lock); 469 mutex_unlock(&tomoyo_policy_lock);
464 out: 470 out:
471 tomoyo_put_name(saved_domainname);
472 tomoyo_put_name(saved_program);
465 kfree(entry); 473 kfree(entry);
466 return error; 474 return error;
467} 475}
@@ -623,8 +631,8 @@ static int tomoyo_update_alias_entry(const char *original_name,
623 if (!tomoyo_is_correct_path(original_name, 1, -1, -1, __func__) || 631 if (!tomoyo_is_correct_path(original_name, 1, -1, -1, __func__) ||
624 !tomoyo_is_correct_path(aliased_name, 1, -1, -1, __func__)) 632 !tomoyo_is_correct_path(aliased_name, 1, -1, -1, __func__))
625 return -EINVAL; /* No patterns allowed. */ 633 return -EINVAL; /* No patterns allowed. */
626 saved_original_name = tomoyo_save_name(original_name); 634 saved_original_name = tomoyo_get_name(original_name);
627 saved_aliased_name = tomoyo_save_name(aliased_name); 635 saved_aliased_name = tomoyo_get_name(aliased_name);
628 if (!saved_original_name || !saved_aliased_name) 636 if (!saved_original_name || !saved_aliased_name)
629 goto out; 637 goto out;