diff options
Diffstat (limited to 'security/tomoyo/common.c')
-rw-r--r-- | security/tomoyo/common.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c index ae3ed7313ee0..a53ee059da48 100644 --- a/security/tomoyo/common.c +++ b/security/tomoyo/common.c | |||
@@ -1103,10 +1103,10 @@ static LIST_HEAD(tomoyo_policy_manager_list); | |||
1103 | static int tomoyo_update_manager_entry(const char *manager, | 1103 | static int tomoyo_update_manager_entry(const char *manager, |
1104 | const bool is_delete) | 1104 | const bool is_delete) |
1105 | { | 1105 | { |
1106 | struct tomoyo_policy_manager_entry *new_entry; | 1106 | struct tomoyo_policy_manager_entry *entry = NULL; |
1107 | struct tomoyo_policy_manager_entry *ptr; | 1107 | struct tomoyo_policy_manager_entry *ptr; |
1108 | const struct tomoyo_path_info *saved_manager; | 1108 | const struct tomoyo_path_info *saved_manager; |
1109 | int error = -ENOMEM; | 1109 | int error = is_delete ? -ENOENT : -ENOMEM; |
1110 | bool is_domain = false; | 1110 | bool is_domain = false; |
1111 | 1111 | ||
1112 | if (tomoyo_is_domain_def(manager)) { | 1112 | if (tomoyo_is_domain_def(manager)) { |
@@ -1120,29 +1120,25 @@ static int tomoyo_update_manager_entry(const char *manager, | |||
1120 | saved_manager = tomoyo_save_name(manager); | 1120 | saved_manager = tomoyo_save_name(manager); |
1121 | if (!saved_manager) | 1121 | if (!saved_manager) |
1122 | return -ENOMEM; | 1122 | return -ENOMEM; |
1123 | new_entry = kmalloc(sizeof(*new_entry), GFP_KERNEL); | 1123 | if (!is_delete) |
1124 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); | ||
1124 | mutex_lock(&tomoyo_policy_lock); | 1125 | mutex_lock(&tomoyo_policy_lock); |
1125 | list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list, list) { | 1126 | list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list, list) { |
1126 | if (ptr->manager != saved_manager) | 1127 | if (ptr->manager != saved_manager) |
1127 | continue; | 1128 | continue; |
1128 | ptr->is_deleted = is_delete; | 1129 | ptr->is_deleted = is_delete; |
1129 | error = 0; | 1130 | error = 0; |
1130 | goto out; | 1131 | break; |
1131 | } | 1132 | } |
1132 | if (is_delete) { | 1133 | if (!is_delete && error && tomoyo_memory_ok(entry)) { |
1133 | error = -ENOENT; | 1134 | entry->manager = saved_manager; |
1134 | goto out; | 1135 | entry->is_domain = is_domain; |
1136 | list_add_tail_rcu(&entry->list, &tomoyo_policy_manager_list); | ||
1137 | entry = NULL; | ||
1138 | error = 0; | ||
1135 | } | 1139 | } |
1136 | if (!tomoyo_memory_ok(new_entry)) | ||
1137 | goto out; | ||
1138 | new_entry->manager = saved_manager; | ||
1139 | new_entry->is_domain = is_domain; | ||
1140 | list_add_tail_rcu(&new_entry->list, &tomoyo_policy_manager_list); | ||
1141 | new_entry = NULL; | ||
1142 | error = 0; | ||
1143 | out: | ||
1144 | mutex_unlock(&tomoyo_policy_lock); | 1140 | mutex_unlock(&tomoyo_policy_lock); |
1145 | kfree(new_entry); | 1141 | kfree(entry); |
1146 | return error; | 1142 | return error; |
1147 | } | 1143 | } |
1148 | 1144 | ||