aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>2010-01-04 16:39:37 -0500
committerJames Morris <jmorris@namei.org>2010-01-10 17:27:40 -0500
commitcd7bec6ad80188394a8ea857ff1aa3512fc2282a (patch)
tree598e7d59c29966e0d8fa8abf24eb51bbb2f567a6 /security
parente41035a996356c257183e53a70abfb46fa84908b (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')
-rw-r--r--security/tomoyo/common.c41
-rw-r--r--security/tomoyo/common.h2
-rw-r--r--security/tomoyo/domain.c58
-rw-r--r--security/tomoyo/file.c34
-rw-r--r--security/tomoyo/realpath.c65
-rw-r--r--security/tomoyo/realpath.h7
6 files changed, 73 insertions, 134 deletions
diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c
index 642e0e565dfc..e331e699cf54 100644
--- a/security/tomoyo/common.c
+++ b/security/tomoyo/common.c
@@ -900,9 +900,11 @@ static struct tomoyo_profile *tomoyo_find_or_assign_new_profile(const unsigned
900 ptr = tomoyo_profile_ptr[profile]; 900 ptr = tomoyo_profile_ptr[profile];
901 if (ptr) 901 if (ptr)
902 goto ok; 902 goto ok;
903 ptr = tomoyo_alloc_element(sizeof(*ptr)); 903 ptr = kmalloc(sizeof(*ptr), GFP_KERNEL);
904 if (!ptr) 904 if (!tomoyo_memory_ok(ptr)) {
905 kfree(ptr);
905 goto ok; 906 goto ok;
907 }
906 for (i = 0; i < TOMOYO_MAX_CONTROL_INDEX; i++) 908 for (i = 0; i < TOMOYO_MAX_CONTROL_INDEX; i++)
907 ptr->value[i] = tomoyo_control_array[i].current_value; 909 ptr->value[i] = tomoyo_control_array[i].current_value;
908 mb(); /* Avoid out-of-order execution. */ 910 mb(); /* Avoid out-of-order execution. */
@@ -1120,6 +1122,7 @@ static int tomoyo_update_manager_entry(const char *manager,
1120 saved_manager = tomoyo_save_name(manager); 1122 saved_manager = tomoyo_save_name(manager);
1121 if (!saved_manager) 1123 if (!saved_manager)
1122 return -ENOMEM; 1124 return -ENOMEM;
1125 new_entry = kmalloc(sizeof(*new_entry), GFP_KERNEL);
1123 mutex_lock(&tomoyo_policy_lock); 1126 mutex_lock(&tomoyo_policy_lock);
1124 list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list, list) { 1127 list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list, list) {
1125 if (ptr->manager != saved_manager) 1128 if (ptr->manager != saved_manager)
@@ -1132,15 +1135,16 @@ static int tomoyo_update_manager_entry(const char *manager,
1132 error = -ENOENT; 1135 error = -ENOENT;
1133 goto out; 1136 goto out;
1134 } 1137 }
1135 new_entry = tomoyo_alloc_element(sizeof(*new_entry)); 1138 if (!tomoyo_memory_ok(new_entry))
1136 if (!new_entry)
1137 goto out; 1139 goto out;
1138 new_entry->manager = saved_manager; 1140 new_entry->manager = saved_manager;
1139 new_entry->is_domain = is_domain; 1141 new_entry->is_domain = is_domain;
1140 list_add_tail_rcu(&new_entry->list, &tomoyo_policy_manager_list); 1142 list_add_tail_rcu(&new_entry->list, &tomoyo_policy_manager_list);
1143 new_entry = NULL;
1141 error = 0; 1144 error = 0;
1142 out: 1145 out:
1143 mutex_unlock(&tomoyo_policy_lock); 1146 mutex_unlock(&tomoyo_policy_lock);
1147 kfree(new_entry);
1144 return error; 1148 return error;
1145} 1149}
1146 1150
@@ -2148,35 +2152,6 @@ static int tomoyo_close_control(struct file *file)
2148} 2152}
2149 2153
2150/** 2154/**
2151 * tomoyo_alloc_acl_element - Allocate permanent memory for ACL entry.
2152 *
2153 * @acl_type: Type of ACL entry.
2154 *
2155 * Returns pointer to the ACL entry on success, NULL otherwise.
2156 */
2157void *tomoyo_alloc_acl_element(const u8 acl_type)
2158{
2159 int len;
2160 struct tomoyo_acl_info *ptr;
2161
2162 switch (acl_type) {
2163 case TOMOYO_TYPE_SINGLE_PATH_ACL:
2164 len = sizeof(struct tomoyo_single_path_acl_record);
2165 break;
2166 case TOMOYO_TYPE_DOUBLE_PATH_ACL:
2167 len = sizeof(struct tomoyo_double_path_acl_record);
2168 break;
2169 default:
2170 return NULL;
2171 }
2172 ptr = tomoyo_alloc_element(len);
2173 if (!ptr)
2174 return NULL;
2175 ptr->type = acl_type;
2176 return ptr;
2177}
2178
2179/**
2180 * tomoyo_open - open() for /sys/kernel/security/tomoyo/ interface. 2155 * tomoyo_open - open() for /sys/kernel/security/tomoyo/ interface.
2181 * 2156 *
2182 * @inode: Pointer to "struct inode". 2157 * @inode: Pointer to "struct inode".
diff --git a/security/tomoyo/common.h b/security/tomoyo/common.h
index 874abf8df43e..610a6a056828 100644
--- a/security/tomoyo/common.h
+++ b/security/tomoyo/common.h
@@ -376,8 +376,6 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
376/* Check mode for specified functionality. */ 376/* Check mode for specified functionality. */
377unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, 377unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
378 const u8 index); 378 const u8 index);
379/* Allocate memory for structures. */
380void *tomoyo_alloc_acl_element(const u8 acl_type);
381/* Fill in "struct tomoyo_path_info" members. */ 379/* Fill in "struct tomoyo_path_info" members. */
382void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); 380void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
383/* Run policy loader when /sbin/init starts. */ 381/* Run policy loader when /sbin/init starts. */
diff --git a/security/tomoyo/domain.c b/security/tomoyo/domain.c
index 7d0b0bc48201..a55a1cced58e 100644
--- a/security/tomoyo/domain.c
+++ b/security/tomoyo/domain.c
@@ -245,6 +245,7 @@ static int tomoyo_update_domain_initializer_entry(const char *domainname,
245 saved_program = tomoyo_save_name(program); 245 saved_program = tomoyo_save_name(program);
246 if (!saved_program) 246 if (!saved_program)
247 return -ENOMEM; 247 return -ENOMEM;
248 new_entry = kmalloc(sizeof(*new_entry), GFP_KERNEL);
248 mutex_lock(&tomoyo_policy_lock); 249 mutex_lock(&tomoyo_policy_lock);
249 list_for_each_entry_rcu(ptr, &tomoyo_domain_initializer_list, list) { 250 list_for_each_entry_rcu(ptr, &tomoyo_domain_initializer_list, list) {
250 if (ptr->is_not != is_not || 251 if (ptr->is_not != is_not ||
@@ -259,17 +260,18 @@ static int tomoyo_update_domain_initializer_entry(const char *domainname,
259 error = -ENOENT; 260 error = -ENOENT;
260 goto out; 261 goto out;
261 } 262 }
262 new_entry = tomoyo_alloc_element(sizeof(*new_entry)); 263 if (!tomoyo_memory_ok(new_entry))
263 if (!new_entry)
264 goto out; 264 goto out;
265 new_entry->domainname = saved_domainname; 265 new_entry->domainname = saved_domainname;
266 new_entry->program = saved_program; 266 new_entry->program = saved_program;
267 new_entry->is_not = is_not; 267 new_entry->is_not = is_not;
268 new_entry->is_last_name = is_last_name; 268 new_entry->is_last_name = is_last_name;
269 list_add_tail_rcu(&new_entry->list, &tomoyo_domain_initializer_list); 269 list_add_tail_rcu(&new_entry->list, &tomoyo_domain_initializer_list);
270 new_entry = NULL;
270 error = 0; 271 error = 0;
271 out: 272 out:
272 mutex_unlock(&tomoyo_policy_lock); 273 mutex_unlock(&tomoyo_policy_lock);
274 kfree(new_entry);
273 return error; 275 return error;
274} 276}
275 277
@@ -461,6 +463,7 @@ static int tomoyo_update_domain_keeper_entry(const char *domainname,
461 saved_domainname = tomoyo_save_name(domainname); 463 saved_domainname = tomoyo_save_name(domainname);
462 if (!saved_domainname) 464 if (!saved_domainname)
463 return -ENOMEM; 465 return -ENOMEM;
466 new_entry = kmalloc(sizeof(*new_entry), GFP_KERNEL);
464 mutex_lock(&tomoyo_policy_lock); 467 mutex_lock(&tomoyo_policy_lock);
465 list_for_each_entry_rcu(ptr, &tomoyo_domain_keeper_list, list) { 468 list_for_each_entry_rcu(ptr, &tomoyo_domain_keeper_list, list) {
466 if (ptr->is_not != is_not || 469 if (ptr->is_not != is_not ||
@@ -475,17 +478,18 @@ static int tomoyo_update_domain_keeper_entry(const char *domainname,
475 error = -ENOENT; 478 error = -ENOENT;
476 goto out; 479 goto out;
477 } 480 }
478 new_entry = tomoyo_alloc_element(sizeof(*new_entry)); 481 if (!tomoyo_memory_ok(new_entry))
479 if (!new_entry)
480 goto out; 482 goto out;
481 new_entry->domainname = saved_domainname; 483 new_entry->domainname = saved_domainname;
482 new_entry->program = saved_program; 484 new_entry->program = saved_program;
483 new_entry->is_not = is_not; 485 new_entry->is_not = is_not;
484 new_entry->is_last_name = is_last_name; 486 new_entry->is_last_name = is_last_name;
485 list_add_tail_rcu(&new_entry->list, &tomoyo_domain_keeper_list); 487 list_add_tail_rcu(&new_entry->list, &tomoyo_domain_keeper_list);
488 new_entry = NULL;
486 error = 0; 489 error = 0;
487 out: 490 out:
488 mutex_unlock(&tomoyo_policy_lock); 491 mutex_unlock(&tomoyo_policy_lock);
492 kfree(new_entry);
489 return error; 493 return error;
490} 494}