[PATCH 2/3] TOMOYO: Replace tomoyo_save_name() with tomoyo_get_name()/tomoyo_put_name().

From: Tetsuo Handa
Date: Wed Jun 17 2009 - 07:22:38 EST


Replace tomoyo_save_name() with tomoyo_get_name() and tomoyo_put_name().
This is preparation for implementing GC support.
Since refcounter is not added yet, tomoyo_put_name() is a no-op.

Signed-off-by: Kentaro Takeda <takedakn@xxxxxxxxxxxxx>
Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>
---
security/tomoyo/common.c | 11 +++++++++--
security/tomoyo/domain.c | 41 +++++++++++++++++++++++++++++++----------
security/tomoyo/file.c | 29 ++++++++++++++++++++++-------
security/tomoyo/realpath.c | 6 +++---
security/tomoyo/realpath.h | 6 +++++-
5 files changed, 70 insertions(+), 23 deletions(-)

--- security-testing-2.6.git.orig/security/tomoyo/common.c
+++ security-testing-2.6.git/security/tomoyo/common.c
@@ -929,7 +929,12 @@ static int tomoyo_write_profile(struct t
return -EINVAL;
*cp = '\0';
if (!strcmp(data, "COMMENT")) {
- profile->comment = tomoyo_save_name(cp + 1);
+ const struct tomoyo_path_info *new_comment
+ = tomoyo_get_name(cp + 1);
+ const struct tomoyo_path_info *old_comment;
+ old_comment = profile->comment;
+ profile->comment = new_comment;
+ tomoyo_put_name(old_comment);
return 0;
}
for (i = 0; i < TOMOYO_MAX_CONTROL_INDEX; i++) {
@@ -1102,7 +1107,7 @@ static int tomoyo_update_manager_entry(c
if (!tomoyo_is_correct_path(manager, 1, -1, -1, __func__))
return -EINVAL;
}
- saved_manager = tomoyo_save_name(manager);
+ saved_manager = tomoyo_get_name(manager);
if (!saved_manager)
return -ENOMEM;
if (!is_delete)
@@ -1117,12 +1122,14 @@ static int tomoyo_update_manager_entry(c
}
if (!is_delete && error && tomoyo_memory_ok(new_entry)) {
new_entry->manager = saved_manager;
+ saved_manager = NULL;
new_entry->is_domain = is_domain;
list_add_tail(&new_entry->list, &tomoyo_policy_manager_list);
new_entry = NULL;
error = 0;
}
up_write(&tomoyo_policy_manager_list_lock);
+ tomoyo_put_name(saved_manager);
kfree(new_entry);
return error;
}
--- security-testing-2.6.git.orig/security/tomoyo/domain.c
+++ security-testing-2.6.git/security/tomoyo/domain.c
@@ -216,13 +216,15 @@ static int tomoyo_update_domain_initiali
is_last_name = true;
else if (!tomoyo_is_correct_domain(domainname, __func__))
return -EINVAL;
- saved_domainname = tomoyo_save_name(domainname);
+ saved_domainname = tomoyo_get_name(domainname);
if (!saved_domainname)
return -ENOMEM;
}
- saved_program = tomoyo_save_name(program);
- if (!saved_program)
+ saved_program = tomoyo_get_name(program);
+ if (!saved_program) {
+ tomoyo_put_name(saved_domainname);
return -ENOMEM;
+ }
if (!is_delete)
new_entry = kmalloc(sizeof(*new_entry), GFP_KERNEL);
down_write(&tomoyo_domain_initializer_list_lock);
@@ -237,7 +239,9 @@ static int tomoyo_update_domain_initiali
}
if (!is_delete && error && tomoyo_memory_ok(new_entry)) {
new_entry->domainname = saved_domainname;
+ saved_domainname = NULL;
new_entry->program = saved_program;
+ saved_program = NULL;
new_entry->is_not = is_not;
new_entry->is_last_name = is_last_name;
list_add_tail(&new_entry->list,
@@ -246,6 +250,8 @@ static int tomoyo_update_domain_initiali
error = 0;
}
up_write(&tomoyo_domain_initializer_list_lock);
+ tomoyo_put_name(saved_domainname);
+ tomoyo_put_name(saved_program);
kfree(new_entry);
return error;
}
@@ -428,13 +434,15 @@ static int tomoyo_update_domain_keeper_e
if (program) {
if (!tomoyo_is_correct_path(program, 1, -1, -1, __func__))
return -EINVAL;
- saved_program = tomoyo_save_name(program);
+ saved_program = tomoyo_get_name(program);
if (!saved_program)
return -ENOMEM;
}
- saved_domainname = tomoyo_save_name(domainname);
- if (!saved_domainname)
+ saved_domainname = tomoyo_get_name(domainname);
+ if (!saved_domainname) {
+ tomoyo_put_name(saved_program);
return -ENOMEM;
+ }
if (!is_delete)
new_entry = kmalloc(sizeof(*new_entry), GFP_KERNEL);
down_write(&tomoyo_domain_keeper_list_lock);
@@ -449,7 +457,9 @@ static int tomoyo_update_domain_keeper_e
}
if (!is_delete && error && tomoyo_memory_ok(new_entry)) {
new_entry->domainname = saved_domainname;
+ saved_domainname = NULL;
new_entry->program = saved_program;
+ saved_program = NULL;
new_entry->is_not = is_not;
new_entry->is_last_name = is_last_name;
list_add_tail(&new_entry->list, &tomoyo_domain_keeper_list);
@@ -457,6 +467,8 @@ static int tomoyo_update_domain_keeper_e
error = 0;
}
up_write(&tomoyo_domain_keeper_list_lock);
+ tomoyo_put_name(saved_domainname);
+ tomoyo_put_name(saved_program);
kfree(new_entry);
return error;
}
@@ -616,10 +628,13 @@ static int tomoyo_update_alias_entry(con
if (!tomoyo_is_correct_path(original_name, 1, -1, -1, __func__) ||
!tomoyo_is_correct_path(aliased_name, 1, -1, -1, __func__))
return -EINVAL; /* No patterns allowed. */
- saved_original_name = tomoyo_save_name(original_name);
- saved_aliased_name = tomoyo_save_name(aliased_name);
- if (!saved_original_name || !saved_aliased_name)
+ saved_original_name = tomoyo_get_name(original_name);
+ saved_aliased_name = tomoyo_get_name(aliased_name);
+ if (!saved_original_name || !saved_aliased_name) {
+ tomoyo_put_name(saved_original_name);
+ tomoyo_put_name(saved_aliased_name);
return -ENOMEM;
+ }
if (!is_delete)
new_entry = kmalloc(sizeof(*new_entry), GFP_KERNEL);
down_write(&tomoyo_alias_list_lock);
@@ -633,12 +648,16 @@ static int tomoyo_update_alias_entry(con
}
if (!is_delete && error && tomoyo_memory_ok(new_entry)) {
new_entry->original_name = saved_original_name;
+ saved_original_name = NULL;
new_entry->aliased_name = saved_aliased_name;
+ saved_aliased_name = NULL;
list_add_tail(&new_entry->list, &tomoyo_alias_list);
new_entry = NULL;
error = 0;
}
up_write(&tomoyo_alias_list_lock);
+ tomoyo_put_name(saved_original_name);
+ tomoyo_put_name(saved_aliased_name);
kfree(new_entry);
return error;
}
@@ -708,7 +727,7 @@ struct tomoyo_domain_info *tomoyo_find_o

if (!tomoyo_is_correct_domain(domainname, __func__))
return NULL;
- saved_domainname = tomoyo_save_name(domainname);
+ saved_domainname = tomoyo_get_name(domainname);
if (!saved_domainname)
return NULL;
new_domain = kmalloc(sizeof(*new_domain), GFP_KERNEL);
@@ -752,11 +771,13 @@ struct tomoyo_domain_info *tomoyo_find_o
new_domain = NULL;
INIT_LIST_HEAD(&domain->acl_info_list);
domain->domainname = saved_domainname;
+ saved_domainname = NULL;
domain->profile = profile;
list_add_tail(&domain->list, &tomoyo_domain_list);
}
out:
up_write(&tomoyo_domain_list_lock);
+ tomoyo_put_name(saved_domainname);
kfree(new_domain);
return domain;
}
--- security-testing-2.6.git.orig/security/tomoyo/file.c
+++ security-testing-2.6.git/security/tomoyo/file.c
@@ -216,7 +216,7 @@ static int tomoyo_update_globally_readab

if (!tomoyo_is_correct_path(filename, 1, 0, -1, __func__))
return -EINVAL;
- saved_filename = tomoyo_save_name(filename);
+ saved_filename = tomoyo_get_name(filename);
if (!saved_filename)
return -ENOMEM;
if (!is_delete)
@@ -231,11 +231,13 @@ static int tomoyo_update_globally_readab
}
if (!is_delete && error && tomoyo_memory_ok(new_entry)) {
new_entry->filename = saved_filename;
+ saved_filename = NULL;
list_add_tail(&new_entry->list, &tomoyo_globally_readable_list);
new_entry = NULL;
error = 0;
}
up_write(&tomoyo_globally_readable_list_lock);
+ tomoyo_put_name(saved_filename);
kfree(new_entry);
return error;
}
@@ -357,7 +359,7 @@ static int tomoyo_update_file_pattern_en

if (!tomoyo_is_correct_path(pattern, 0, 1, 0, __func__))
return -EINVAL;
- saved_pattern = tomoyo_save_name(pattern);
+ saved_pattern = tomoyo_get_name(pattern);
if (!saved_pattern)
return -ENOMEM;
if (!is_delete)
@@ -372,11 +374,13 @@ static int tomoyo_update_file_pattern_en
}
if (!is_delete && error && tomoyo_memory_ok(new_entry)) {
new_entry->pattern = saved_pattern;
+ saved_pattern = NULL;
list_add_tail(&new_entry->list, &tomoyo_pattern_list);
new_entry = NULL;
error = 0;
}
up_write(&tomoyo_pattern_list_lock);
+ tomoyo_put_name(saved_pattern);
kfree(new_entry);
return error;
}
@@ -504,7 +508,7 @@ static int tomoyo_update_no_rewrite_entr

if (!tomoyo_is_correct_path(pattern, 0, 0, 0, __func__))
return -EINVAL;
- saved_pattern = tomoyo_save_name(pattern);
+ saved_pattern = tomoyo_get_name(pattern);
if (!saved_pattern)
return -ENOMEM;
if (!is_delete)
@@ -519,11 +523,13 @@ static int tomoyo_update_no_rewrite_entr
}
if (!is_delete && error && tomoyo_memory_ok(new_entry)) {
new_entry->pattern = saved_pattern;
+ saved_pattern = NULL;
list_add_tail(&new_entry->list, &tomoyo_no_rewrite_list);
new_entry = NULL;
error = 0;
}
up_write(&tomoyo_no_rewrite_list_lock);
+ tomoyo_put_name(saved_pattern);
return error;
}

@@ -835,7 +841,7 @@ static int tomoyo_update_single_path_acl
return -EINVAL;
if (!tomoyo_is_correct_path(filename, 0, 0, 0, __func__))
return -EINVAL;
- saved_filename = tomoyo_save_name(filename);
+ saved_filename = tomoyo_get_name(filename);
if (!saved_filename)
return -ENOMEM;
if (!is_delete)
@@ -870,6 +876,7 @@ static int tomoyo_update_single_path_acl
if (perm == (1 << TOMOYO_TYPE_READ_WRITE_ACL))
new_entry->perm |= rw_mask;
new_entry->filename = saved_filename;
+ saved_filename = NULL;
list_add_tail(&new_entry->head.list, &domain->acl_info_list);
new_entry = NULL;
error = 0;
@@ -896,6 +903,7 @@ static int tomoyo_update_single_path_acl
}
out:
up_write(&tomoyo_domain_acl_info_list_lock);
+ tomoyo_put_name(saved_filename);
kfree(new_entry);
return error;
}
@@ -928,10 +936,13 @@ static int tomoyo_update_double_path_acl
if (!tomoyo_is_correct_path(filename1, 0, 0, 0, __func__) ||
!tomoyo_is_correct_path(filename2, 0, 0, 0, __func__))
return -EINVAL;
- saved_filename1 = tomoyo_save_name(filename1);
- saved_filename2 = tomoyo_save_name(filename2);
- if (!saved_filename1 || !saved_filename2)
+ saved_filename1 = tomoyo_get_name(filename1);
+ saved_filename2 = tomoyo_get_name(filename2);
+ if (!saved_filename1 || !saved_filename2) {
+ tomoyo_put_name(saved_filename1);
+ tomoyo_put_name(saved_filename2);
return -ENOMEM;
+ }
if (!is_delete)
new_entry = kmalloc(sizeof(*new_entry), GFP_KERNEL);
down_write(&tomoyo_domain_acl_info_list_lock);
@@ -959,7 +970,9 @@ static int tomoyo_update_double_path_acl
new_entry->head.type = TOMOYO_TYPE_DOUBLE_PATH_ACL;
new_entry->perm = perm;
new_entry->filename1 = saved_filename1;
+ saved_filename1 = NULL;
new_entry->filename2 = saved_filename2;
+ saved_filename2 = NULL;
list_add_tail(&new_entry->head.list, &domain->acl_info_list);
new_entry = NULL;
error = 0;
@@ -983,6 +996,8 @@ static int tomoyo_update_double_path_acl
}
out:
up_write(&tomoyo_domain_acl_info_list_lock);
+ tomoyo_put_name(saved_filename1);
+ tomoyo_put_name(saved_filename2);
kfree(new_entry);
return error;
}
--- security-testing-2.6.git.orig/security/tomoyo/realpath.c
+++ security-testing-2.6.git/security/tomoyo/realpath.c
@@ -260,7 +260,7 @@ static struct list_head tomoyo_name_list
static DEFINE_MUTEX(tomoyo_name_list_lock);

/**
- * tomoyo_save_name - Allocate permanent memory for string data.
+ * tomoyo_get_name - Allocate permanent memory for string data.
*
* @name: The string to store into the permernent memory.
*
@@ -268,7 +268,7 @@ static DEFINE_MUTEX(tomoyo_name_list_loc
*
* The RAM is shared, so NEVER try to modify or kfree() the returned name.
*/
-const struct tomoyo_path_info *tomoyo_save_name(const char *name)
+const struct tomoyo_path_info *tomoyo_get_name(const char *name)
{
struct tomoyo_name_entry *entry;
struct tomoyo_name_entry *ptr;
@@ -331,7 +331,7 @@ void __init tomoyo_realpath_init(void)
for (i = 0; i < TOMOYO_MAX_HASH; i++)
INIT_LIST_HEAD(&tomoyo_name_list[i]);
INIT_LIST_HEAD(&tomoyo_kernel_domain.acl_info_list);
- tomoyo_kernel_domain.domainname = tomoyo_save_name(TOMOYO_ROOT_NAME);
+ tomoyo_kernel_domain.domainname = tomoyo_get_name(TOMOYO_ROOT_NAME);
list_add_tail(&tomoyo_kernel_domain.list, &tomoyo_domain_list);
down_read(&tomoyo_domain_list_lock);
if (tomoyo_find_domain(TOMOYO_ROOT_NAME) != &tomoyo_kernel_domain)
--- security-testing-2.6.git.orig/security/tomoyo/realpath.h
+++ security-testing-2.6.git/security/tomoyo/realpath.h
@@ -43,7 +43,11 @@ bool tomoyo_memory_ok(void *ptr);
* Keep the given name on the RAM.
* The RAM is shared, so NEVER try to modify or kfree() the returned name.
*/
-const struct tomoyo_path_info *tomoyo_save_name(const char *name);
+const struct tomoyo_path_info *tomoyo_get_name(const char *name);
+static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
+{
+ /* It's a dummy so far. */
+}

/* Allocate memory for temporary use (e.g. permission checks). */
void *tomoyo_alloc(const size_t size);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/