aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--security/tomoyo/common.h36
-rw-r--r--security/tomoyo/file.c4
-rw-r--r--security/tomoyo/gc.c41
-rw-r--r--security/tomoyo/number_group.c32
-rw-r--r--security/tomoyo/path_group.c30
5 files changed, 59 insertions, 84 deletions
diff --git a/security/tomoyo/common.h b/security/tomoyo/common.h
index e0c4ae11bf6c..9f289e412a63 100644
--- a/security/tomoyo/common.h
+++ b/security/tomoyo/common.h
@@ -291,28 +291,20 @@ struct tomoyo_name_entry {
291 291
292struct tomoyo_name_union { 292struct tomoyo_name_union {
293 const struct tomoyo_path_info *filename; 293 const struct tomoyo_path_info *filename;
294 struct tomoyo_path_group *group; 294 struct tomoyo_group *group;
295 u8 is_group; 295 u8 is_group;
296}; 296};
297 297
298struct tomoyo_number_union { 298struct tomoyo_number_union {
299 unsigned long values[2]; 299 unsigned long values[2];
300 struct tomoyo_number_group *group; 300 struct tomoyo_group *group;
301 u8 min_type; 301 u8 min_type;
302 u8 max_type; 302 u8 max_type;
303 u8 is_group; 303 u8 is_group;
304}; 304};
305 305
306/* Structure for "path_group" directive. */ 306/* Structure for "path_group"/"number_group" directive. */
307struct tomoyo_path_group { 307struct tomoyo_group {
308 struct list_head list;
309 const struct tomoyo_path_info *group_name;
310 struct list_head member_list;
311 atomic_t users;
312};
313
314/* Structure for "number_group" directive. */
315struct tomoyo_number_group {
316 struct list_head list; 308 struct list_head list;
317 const struct tomoyo_path_info *group_name; 309 const struct tomoyo_path_info *group_name;
318 struct list_head member_list; 310 struct list_head member_list;
@@ -320,13 +312,13 @@ struct tomoyo_number_group {
320}; 312};
321 313
322/* Structure for "path_group" directive. */ 314/* Structure for "path_group" directive. */
323struct tomoyo_path_group_member { 315struct tomoyo_path_group {
324 struct tomoyo_acl_head head; 316 struct tomoyo_acl_head head;
325 const struct tomoyo_path_info *member_name; 317 const struct tomoyo_path_info *member_name;
326}; 318};
327 319
328/* Structure for "number_group" directive. */ 320/* Structure for "number_group" directive. */
329struct tomoyo_number_group_member { 321struct tomoyo_number_group {
330 struct tomoyo_acl_head head; 322 struct tomoyo_acl_head head;
331 struct tomoyo_number_union number; 323 struct tomoyo_number_union number;
332}; 324};
@@ -766,11 +758,11 @@ bool tomoyo_parse_name_union(const char *filename,
766 struct tomoyo_name_union *ptr); 758 struct tomoyo_name_union *ptr);
767/* Check whether the given filename matches the given path_group. */ 759/* Check whether the given filename matches the given path_group. */
768bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, 760bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
769 const struct tomoyo_path_group *group); 761 const struct tomoyo_group *group);
770/* Check whether the given value matches the given number_group. */ 762/* Check whether the given value matches the given number_group. */
771bool tomoyo_number_matches_group(const unsigned long min, 763bool tomoyo_number_matches_group(const unsigned long min,
772 const unsigned long max, 764 const unsigned long max,
773 const struct tomoyo_number_group *group); 765 const struct tomoyo_group *group);
774/* Check whether the given filename matches the given pattern. */ 766/* Check whether the given filename matches the given pattern. */
775bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, 767bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
776 const struct tomoyo_path_info *pattern); 768 const struct tomoyo_path_info *pattern);
@@ -858,8 +850,8 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
858 const u8 profile); 850 const u8 profile);
859struct tomoyo_profile *tomoyo_profile(const u8 profile); 851struct tomoyo_profile *tomoyo_profile(const u8 profile);
860/* Allocate memory for "struct tomoyo_path_group". */ 852/* Allocate memory for "struct tomoyo_path_group". */
861struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name); 853struct tomoyo_group *tomoyo_get_path_group(const char *group_name);
862struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name); 854struct tomoyo_group *tomoyo_get_number_group(const char *group_name);
863 855
864/* Check mode for specified functionality. */ 856/* Check mode for specified functionality. */
865unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, 857unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
@@ -1039,13 +1031,7 @@ static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
1039 } 1031 }
1040} 1032}
1041 1033
1042static inline void tomoyo_put_path_group(struct tomoyo_path_group *group) 1034static inline void tomoyo_put_group(struct tomoyo_group *group)
1043{
1044 if (group)
1045 atomic_dec(&group->users);
1046}
1047
1048static inline void tomoyo_put_number_group(struct tomoyo_number_group *group)
1049{ 1035{
1050 if (group) 1036 if (group)
1051 atomic_dec(&group->users); 1037 atomic_dec(&group->users);
diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
index de87c45ba9d0..6c2ba69fc89e 100644
--- a/security/tomoyo/file.c
+++ b/security/tomoyo/file.c
@@ -90,7 +90,7 @@ void tomoyo_put_name_union(struct tomoyo_name_union *ptr)
90 if (!ptr) 90 if (!ptr)
91 return; 91 return;
92 if (ptr->is_group) 92 if (ptr->is_group)
93 tomoyo_put_path_group(ptr->group); 93 tomoyo_put_group(ptr->group);
94 else 94 else
95 tomoyo_put_name(ptr->filename); 95 tomoyo_put_name(ptr->filename);
96} 96}
@@ -106,7 +106,7 @@ bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
106void tomoyo_put_number_union(struct tomoyo_number_union *ptr) 106void tomoyo_put_number_union(struct tomoyo_number_union *ptr)
107{ 107{
108 if (ptr && ptr->is_group) 108 if (ptr && ptr->is_group)
109 tomoyo_put_number_group(ptr->group); 109 tomoyo_put_group(ptr->group);
110} 110}
111 111
112bool tomoyo_compare_number_union(const unsigned long value, 112bool tomoyo_compare_number_union(const unsigned long value,
diff --git a/security/tomoyo/gc.c b/security/tomoyo/gc.c
index a54bd823fcd5..446d59f8ae25 100644
--- a/security/tomoyo/gc.c
+++ b/security/tomoyo/gc.c
@@ -12,10 +12,9 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13 13
14enum tomoyo_policy_id { 14enum tomoyo_policy_id {
15 TOMOYO_ID_GROUP,
15 TOMOYO_ID_PATH_GROUP, 16 TOMOYO_ID_PATH_GROUP,
16 TOMOYO_ID_PATH_GROUP_MEMBER,
17 TOMOYO_ID_NUMBER_GROUP, 17 TOMOYO_ID_NUMBER_GROUP,
18 TOMOYO_ID_NUMBER_GROUP_MEMBER,
19 TOMOYO_ID_DOMAIN_INITIALIZER, 18 TOMOYO_ID_DOMAIN_INITIALIZER,
20 TOMOYO_ID_DOMAIN_KEEPER, 19 TOMOYO_ID_DOMAIN_KEEPER,
21 TOMOYO_ID_AGGREGATOR, 20 TOMOYO_ID_AGGREGATOR,
@@ -207,31 +206,24 @@ static void tomoyo_del_name(struct list_head *element)
207 container_of(element, typeof(*ptr), list); 206 container_of(element, typeof(*ptr), list);
208} 207}
209 208
210static void tomoyo_del_path_group_member(struct list_head *element) 209static void tomoyo_del_path_group(struct list_head *element)
211{ 210{
212 struct tomoyo_path_group_member *member = 211 struct tomoyo_path_group *member =
213 container_of(element, typeof(*member), head.list); 212 container_of(element, typeof(*member), head.list);
214 tomoyo_put_name(member->member_name); 213 tomoyo_put_name(member->member_name);
215} 214}
216 215
217static void tomoyo_del_path_group(struct list_head *element) 216static void tomoyo_del_group(struct list_head *element)
218{ 217{
219 struct tomoyo_path_group *group = 218 struct tomoyo_group *group =
220 container_of(element, typeof(*group), list); 219 container_of(element, typeof(*group), list);
221 tomoyo_put_name(group->group_name); 220 tomoyo_put_name(group->group_name);
222} 221}
223 222
224static void tomoyo_del_number_group_member(struct list_head *element)
225{
226 struct tomoyo_number_group_member *member =
227 container_of(element, typeof(*member), head.list);
228}
229
230static void tomoyo_del_number_group(struct list_head *element) 223static void tomoyo_del_number_group(struct list_head *element)
231{ 224{
232 struct tomoyo_number_group *group = 225 struct tomoyo_number_group *member =
233 container_of(element, typeof(*group), list); 226 container_of(element, typeof(*member), head.list);
234 tomoyo_put_name(group->group_name);
235} 227}
236 228
237static struct list_head *tomoyo_policy_list[TOMOYO_MAX_POLICY] = { 229static struct list_head *tomoyo_policy_list[TOMOYO_MAX_POLICY] = {
@@ -305,28 +297,28 @@ static void tomoyo_collect_entry(void)
305 } 297 }
306 } 298 }
307 { 299 {
308 struct tomoyo_path_group *group; 300 struct tomoyo_group *group;
309 list_for_each_entry_rcu(group, &tomoyo_path_group_list, list) { 301 list_for_each_entry_rcu(group, &tomoyo_path_group_list, list) {
310 tomoyo_collect_member(&group->member_list, 302 tomoyo_collect_member(&group->member_list,
311 TOMOYO_ID_PATH_GROUP_MEMBER); 303 TOMOYO_ID_PATH_GROUP);
312 if (!list_empty(&group->member_list) || 304 if (!list_empty(&group->member_list) ||
313 atomic_read(&group->users)) 305 atomic_read(&group->users))
314 continue; 306 continue;
315 if (!tomoyo_add_to_gc(TOMOYO_ID_PATH_GROUP, 307 if (!tomoyo_add_to_gc(TOMOYO_ID_GROUP,
316 &group->list)) 308 &group->list))
317 goto unlock; 309 goto unlock;
318 } 310 }
319 } 311 }
320 { 312 {
321 struct tomoyo_number_group *group; 313 struct tomoyo_group *group;
322 list_for_each_entry_rcu(group, &tomoyo_number_group_list, 314 list_for_each_entry_rcu(group, &tomoyo_number_group_list,
323 list) { 315 list) {
324 tomoyo_collect_member(&group->member_list, 316 tomoyo_collect_member(&group->member_list,
325 TOMOYO_ID_NUMBER_GROUP_MEMBER); 317 TOMOYO_ID_NUMBER_GROUP);
326 if (!list_empty(&group->member_list) || 318 if (!list_empty(&group->member_list) ||
327 atomic_read(&group->users)) 319 atomic_read(&group->users))
328 continue; 320 continue;
329 if (!tomoyo_add_to_gc(TOMOYO_ID_NUMBER_GROUP, 321 if (!tomoyo_add_to_gc(TOMOYO_ID_GROUP,
330 &group->list)) 322 &group->list))
331 goto unlock; 323 goto unlock;
332 } 324 }
@@ -377,14 +369,11 @@ static void tomoyo_kfree_entry(void)
377 if (!tomoyo_del_domain(element)) 369 if (!tomoyo_del_domain(element))
378 continue; 370 continue;
379 break; 371 break;
380 case TOMOYO_ID_PATH_GROUP_MEMBER:
381 tomoyo_del_path_group_member(element);
382 break;
383 case TOMOYO_ID_PATH_GROUP: 372 case TOMOYO_ID_PATH_GROUP:
384 tomoyo_del_path_group(element); 373 tomoyo_del_path_group(element);
385 break; 374 break;
386 case TOMOYO_ID_NUMBER_GROUP_MEMBER: 375 case TOMOYO_ID_GROUP:
387 tomoyo_del_number_group_member(element); 376 tomoyo_del_group(element);
388 break; 377 break;
389 case TOMOYO_ID_NUMBER_GROUP: 378 case TOMOYO_ID_NUMBER_GROUP:
390 tomoyo_del_number_group(element); 379 tomoyo_del_number_group(element);
diff --git a/security/tomoyo/number_group.c b/security/tomoyo/number_group.c
index 8779309c5b44..eca20d6f4e8b 100644
--- a/security/tomoyo/number_group.c
+++ b/security/tomoyo/number_group.c
@@ -11,17 +11,17 @@
11LIST_HEAD(tomoyo_number_group_list); 11LIST_HEAD(tomoyo_number_group_list);
12 12
13/** 13/**
14 * tomoyo_get_number_group - Allocate memory for "struct tomoyo_number_group". 14 * tomoyo_get_group - Allocate memory for "struct tomoyo_number_group".
15 * 15 *
16 * @group_name: The name of number group. 16 * @group_name: The name of number group.
17 * 17 *
18 * Returns pointer to "struct tomoyo_number_group" on success, 18 * Returns pointer to "struct tomoyo_number_group" on success,
19 * NULL otherwise. 19 * NULL otherwise.
20 */ 20 */
21struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name) 21struct tomoyo_group *tomoyo_get_number_group(const char *group_name)
22{ 22{
23 struct tomoyo_number_group *entry = NULL; 23 struct tomoyo_group *entry = NULL;
24 struct tomoyo_number_group *group = NULL; 24 struct tomoyo_group *group = NULL;
25 const struct tomoyo_path_info *saved_group_name; 25 const struct tomoyo_path_info *saved_group_name;
26 int error = -ENOMEM; 26 int error = -ENOMEM;
27 if (!tomoyo_correct_word(group_name)) 27 if (!tomoyo_correct_word(group_name))
@@ -59,12 +59,12 @@ struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name)
59static bool tomoyo_same_number_group(const struct tomoyo_acl_head *a, 59static bool tomoyo_same_number_group(const struct tomoyo_acl_head *a,
60 const struct tomoyo_acl_head *b) 60 const struct tomoyo_acl_head *b)
61{ 61{
62 return !memcmp(&container_of(a, struct tomoyo_number_group_member, 62 return !memcmp(&container_of(a, struct tomoyo_number_group,
63 head)->number, 63 head)->number,
64 &container_of(b, struct tomoyo_number_group_member, 64 &container_of(b, struct tomoyo_number_group,
65 head)->number, 65 head)->number,
66 sizeof(container_of(a, 66 sizeof(container_of(a,
67 struct tomoyo_number_group_member, 67 struct tomoyo_number_group,
68 head)->number)); 68 head)->number));
69} 69}
70 70
@@ -78,8 +78,8 @@ static bool tomoyo_same_number_group(const struct tomoyo_acl_head *a,
78 */ 78 */
79int tomoyo_write_number_group_policy(char *data, const bool is_delete) 79int tomoyo_write_number_group_policy(char *data, const bool is_delete)
80{ 80{
81 struct tomoyo_number_group *group; 81 struct tomoyo_group *group;
82 struct tomoyo_number_group_member e = { }; 82 struct tomoyo_number_group e = { };
83 int error; 83 int error;
84 char *w[2]; 84 char *w[2];
85 if (!tomoyo_tokenize(data, w, sizeof(w))) 85 if (!tomoyo_tokenize(data, w, sizeof(w)))
@@ -93,7 +93,7 @@ int tomoyo_write_number_group_policy(char *data, const bool is_delete)
93 error = tomoyo_update_policy(&e.head, sizeof(e), is_delete, 93 error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
94 &group->member_list, 94 &group->member_list,
95 tomoyo_same_number_group); 95 tomoyo_same_number_group);
96 tomoyo_put_number_group(group); 96 tomoyo_put_group(group);
97 return error; 97 return error;
98} 98}
99 99
@@ -111,16 +111,16 @@ bool tomoyo_read_number_group_policy(struct tomoyo_io_buffer *head)
111 struct list_head *gpos; 111 struct list_head *gpos;
112 struct list_head *mpos; 112 struct list_head *mpos;
113 list_for_each_cookie(gpos, head->read_var1, &tomoyo_number_group_list) { 113 list_for_each_cookie(gpos, head->read_var1, &tomoyo_number_group_list) {
114 struct tomoyo_number_group *group; 114 struct tomoyo_group *group;
115 const char *name; 115 const char *name;
116 group = list_entry(gpos, struct tomoyo_number_group, list); 116 group = list_entry(gpos, struct tomoyo_group, list);
117 name = group->group_name->name; 117 name = group->group_name->name;
118 list_for_each_cookie(mpos, head->read_var2, 118 list_for_each_cookie(mpos, head->read_var2,
119 &group->member_list) { 119 &group->member_list) {
120 int pos; 120 int pos;
121 const struct tomoyo_number_group_member *member 121 const struct tomoyo_number_group *member
122 = list_entry(mpos, 122 = list_entry(mpos,
123 struct tomoyo_number_group_member, 123 struct tomoyo_number_group,
124 head.list); 124 head.list);
125 if (member->head.is_deleted) 125 if (member->head.is_deleted)
126 continue; 126 continue;
@@ -150,9 +150,9 @@ bool tomoyo_read_number_group_policy(struct tomoyo_io_buffer *head)
150 */ 150 */
151bool tomoyo_number_matches_group(const unsigned long min, 151bool tomoyo_number_matches_group(const unsigned long min,
152 const unsigned long max, 152 const unsigned long max,
153 const struct tomoyo_number_group *group) 153 const struct tomoyo_group *group)
154{ 154{
155 struct tomoyo_number_group_member *member; 155 struct tomoyo_number_group *member;
156 bool matched = false; 156 bool matched = false;
157 list_for_each_entry_rcu(member, &group->member_list, head.list) { 157 list_for_each_entry_rcu(member, &group->member_list, head.list) {
158 if (member->head.is_deleted) 158 if (member->head.is_deleted)
diff --git a/security/tomoyo/path_group.c b/security/tomoyo/path_group.c
index c78c57cd94ee..bce2524402fa 100644
--- a/security/tomoyo/path_group.c
+++ b/security/tomoyo/path_group.c
@@ -10,16 +10,16 @@
10LIST_HEAD(tomoyo_path_group_list); 10LIST_HEAD(tomoyo_path_group_list);
11 11
12/** 12/**
13 * tomoyo_get_path_group - Allocate memory for "struct tomoyo_path_group". 13 * tomoyo_get_group - Allocate memory for "struct tomoyo_path_group".
14 * 14 *
15 * @group_name: The name of pathname group. 15 * @group_name: The name of pathname group.
16 * 16 *
17 * Returns pointer to "struct tomoyo_path_group" on success, NULL otherwise. 17 * Returns pointer to "struct tomoyo_path_group" on success, NULL otherwise.
18 */ 18 */
19struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name) 19struct tomoyo_group *tomoyo_get_path_group(const char *group_name)
20{ 20{
21 struct tomoyo_path_group *entry = NULL; 21 struct tomoyo_group *entry = NULL;
22 struct tomoyo_path_group *group = NULL; 22 struct tomoyo_group *group = NULL;
23 const struct tomoyo_path_info *saved_group_name; 23 const struct tomoyo_path_info *saved_group_name;
24 int error = -ENOMEM; 24 int error = -ENOMEM;
25 if (!tomoyo_correct_word(group_name)) 25 if (!tomoyo_correct_word(group_name))
@@ -57,9 +57,9 @@ struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name)
57static bool tomoyo_same_path_group(const struct tomoyo_acl_head *a, 57static bool tomoyo_same_path_group(const struct tomoyo_acl_head *a,
58 const struct tomoyo_acl_head *b) 58 const struct tomoyo_acl_head *b)
59{ 59{
60 return container_of(a, struct tomoyo_path_group_member, head) 60 return container_of(a, struct tomoyo_path_group, head)
61 ->member_name == 61 ->member_name ==
62 container_of(b, struct tomoyo_path_group_member, head) 62 container_of(b, struct tomoyo_path_group, head)
63 ->member_name; 63 ->member_name;
64} 64}
65 65
@@ -73,8 +73,8 @@ static bool tomoyo_same_path_group(const struct tomoyo_acl_head *a,
73 */ 73 */
74int tomoyo_write_path_group_policy(char *data, const bool is_delete) 74int tomoyo_write_path_group_policy(char *data, const bool is_delete)
75{ 75{
76 struct tomoyo_path_group *group; 76 struct tomoyo_group *group;
77 struct tomoyo_path_group_member e = { }; 77 struct tomoyo_path_group e = { };
78 int error = is_delete ? -ENOENT : -ENOMEM; 78 int error = is_delete ? -ENOENT : -ENOMEM;
79 char *w[2]; 79 char *w[2];
80 if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[1][0]) 80 if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[1][0])
@@ -90,7 +90,7 @@ int tomoyo_write_path_group_policy(char *data, const bool is_delete)
90 tomoyo_same_path_group); 90 tomoyo_same_path_group);
91 out: 91 out:
92 tomoyo_put_name(e.member_name); 92 tomoyo_put_name(e.member_name);
93 tomoyo_put_path_group(group); 93 tomoyo_put_group(group);
94 return error; 94 return error;
95} 95}
96 96
@@ -108,13 +108,13 @@ bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head)
108 struct list_head *gpos; 108 struct list_head *gpos;
109 struct list_head *mpos; 109 struct list_head *mpos;
110 list_for_each_cookie(gpos, head->read_var1, &tomoyo_path_group_list) { 110 list_for_each_cookie(gpos, head->read_var1, &tomoyo_path_group_list) {
111 struct tomoyo_path_group *group; 111 struct tomoyo_group *group;
112 group = list_entry(gpos, struct tomoyo_path_group, list); 112 group = list_entry(gpos, struct tomoyo_group, list);
113 list_for_each_cookie(mpos, head->read_var2, 113 list_for_each_cookie(mpos, head->read_var2,
114 &group->member_list) { 114 &group->member_list) {
115 struct tomoyo_path_group_member *member; 115 struct tomoyo_path_group *member;
116 member = list_entry(mpos, 116 member = list_entry(mpos,
117 struct tomoyo_path_group_member, 117 struct tomoyo_path_group,
118 head.list); 118 head.list);
119 if (member->head.is_deleted) 119 if (member->head.is_deleted)
120 continue; 120 continue;
@@ -139,9 +139,9 @@ bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head)
139 * Caller holds tomoyo_read_lock(). 139 * Caller holds tomoyo_read_lock().
140 */ 140 */
141bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, 141bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
142 const struct tomoyo_path_group *group) 142 const struct tomoyo_group *group)
143{ 143{
144 struct tomoyo_path_group_member *member; 144 struct tomoyo_path_group *member;
145 bool matched = false; 145 bool matched = false;
146 list_for_each_entry_rcu(member, &group->member_list, head.list) { 146 list_for_each_entry_rcu(member, &group->member_list, head.list) {
147 if (member->head.is_deleted) 147 if (member->head.is_deleted)