Skip to content

Commit a98aa4d

Browse files
Tetsuo Handaxjamesmorris
authored andcommitted
TOMOYO: Merge tomoyo_path_group and tomoyo_number_group
"struct tomoyo_path_group" and "struct tomoyo_number_group" are identical. Rename tomoyo_path_group/tomoyo_number_group to tomoyo_group and tomoyo_path_group_member to tomoyo_path_group and tomoyo_number_group_member to tomoyo_unmber_group. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: James Morris <jmorris@namei.org>
1 parent 5fb4987 commit a98aa4d

5 files changed

Lines changed: 59 additions & 84 deletions

File tree

‎security/tomoyo/common.h‎

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -291,42 +291,34 @@ struct tomoyo_name_entry {
291291

292292
struct tomoyo_name_union {
293293
const struct tomoyo_path_info *filename;
294-
struct tomoyo_path_group *group;
294+
struct tomoyo_group *group;
295295
u8 is_group;
296296
};
297297

298298
struct tomoyo_number_union {
299299
unsigned long values[2];
300-
struct tomoyo_number_group *group;
300+
struct tomoyo_group *group;
301301
u8 min_type;
302302
u8 max_type;
303303
u8 is_group;
304304
};
305305

306-
/* Structure for "path_group" directive. */
307-
struct tomoyo_path_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. */
315-
struct tomoyo_number_group {
306+
/* Structure for "path_group"/"number_group" directive. */
307+
struct tomoyo_group {
316308
struct list_head list;
317309
const struct tomoyo_path_info *group_name;
318310
struct list_head member_list;
319311
atomic_t users;
320312
};
321313

322314
/* Structure for "path_group" directive. */
323-
struct tomoyo_path_group_member {
315+
struct tomoyo_path_group {
324316
struct tomoyo_acl_head head;
325317
const struct tomoyo_path_info *member_name;
326318
};
327319

328320
/* Structure for "number_group" directive. */
329-
struct tomoyo_number_group_member {
321+
struct tomoyo_number_group {
330322
struct tomoyo_acl_head head;
331323
struct tomoyo_number_union number;
332324
};
@@ -766,11 +758,11 @@ bool tomoyo_parse_name_union(const char *filename,
766758
struct tomoyo_name_union *ptr);
767759
/* Check whether the given filename matches the given path_group. */
768760
bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
769-
const struct tomoyo_path_group *group);
761+
const struct tomoyo_group *group);
770762
/* Check whether the given value matches the given number_group. */
771763
bool tomoyo_number_matches_group(const unsigned long min,
772764
const unsigned long max,
773-
const struct tomoyo_number_group *group);
765+
const struct tomoyo_group *group);
774766
/* Check whether the given filename matches the given pattern. */
775767
bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
776768
const struct tomoyo_path_info *pattern);
@@ -858,8 +850,8 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
858850
const u8 profile);
859851
struct tomoyo_profile *tomoyo_profile(const u8 profile);
860852
/* Allocate memory for "struct tomoyo_path_group". */
861-
struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name);
862-
struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name);
853+
struct tomoyo_group *tomoyo_get_path_group(const char *group_name);
854+
struct tomoyo_group *tomoyo_get_number_group(const char *group_name);
863855

864856
/* Check mode for specified functionality. */
865857
unsigned 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)
10391031
}
10401032
}
10411033

1042-
static inline void tomoyo_put_path_group(struct tomoyo_path_group *group)
1043-
{
1044-
if (group)
1045-
atomic_dec(&group->users);
1046-
}
1047-
1048-
static inline void tomoyo_put_number_group(struct tomoyo_number_group *group)
1034+
static inline void tomoyo_put_group(struct tomoyo_group *group)
10491035
{
10501036
if (group)
10511037
atomic_dec(&group->users);

‎security/tomoyo/file.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void tomoyo_put_name_union(struct tomoyo_name_union *ptr)
9090
if (!ptr)
9191
return;
9292
if (ptr->is_group)
93-
tomoyo_put_path_group(ptr->group);
93+
tomoyo_put_group(ptr->group);
9494
else
9595
tomoyo_put_name(ptr->filename);
9696
}
@@ -106,7 +106,7 @@ bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
106106
void tomoyo_put_number_union(struct tomoyo_number_union *ptr)
107107
{
108108
if (ptr && ptr->is_group)
109-
tomoyo_put_number_group(ptr->group);
109+
tomoyo_put_group(ptr->group);
110110
}
111111

112112
bool tomoyo_compare_number_union(const unsigned long value,

‎security/tomoyo/gc.c‎

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
#include <linux/slab.h>
1313

1414
enum tomoyo_policy_id {
15+
TOMOYO_ID_GROUP,
1516
TOMOYO_ID_PATH_GROUP,
16-
TOMOYO_ID_PATH_GROUP_MEMBER,
1717
TOMOYO_ID_NUMBER_GROUP,
18-
TOMOYO_ID_NUMBER_GROUP_MEMBER,
1918
TOMOYO_ID_DOMAIN_INITIALIZER,
2019
TOMOYO_ID_DOMAIN_KEEPER,
2120
TOMOYO_ID_AGGREGATOR,
@@ -207,31 +206,24 @@ static void tomoyo_del_name(struct list_head *element)
207206
container_of(element, typeof(*ptr), list);
208207
}
209208

210-
static void tomoyo_del_path_group_member(struct list_head *element)
209+
static void tomoyo_del_path_group(struct list_head *element)
211210
{
212-
struct tomoyo_path_group_member *member =
211+
struct tomoyo_path_group *member =
213212
container_of(element, typeof(*member), head.list);
214213
tomoyo_put_name(member->member_name);
215214
}
216215

217-
static void tomoyo_del_path_group(struct list_head *element)
216+
static void tomoyo_del_group(struct list_head *element)
218217
{
219-
struct tomoyo_path_group *group =
218+
struct tomoyo_group *group =
220219
container_of(element, typeof(*group), list);
221220
tomoyo_put_name(group->group_name);
222221
}
223222

224-
static 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-
230223
static void tomoyo_del_number_group(struct list_head *element)
231224
{
232-
struct tomoyo_number_group *group =
233-
container_of(element, typeof(*group), list);
234-
tomoyo_put_name(group->group_name);
225+
struct tomoyo_number_group *member =
226+
container_of(element, typeof(*member), head.list);
235227
}
236228

237229
static struct list_head *tomoyo_policy_list[TOMOYO_MAX_POLICY] = {
@@ -305,28 +297,28 @@ static void tomoyo_collect_entry(void)
305297
}
306298
}
307299
{
308-
struct tomoyo_path_group *group;
300+
struct tomoyo_group *group;
309301
list_for_each_entry_rcu(group, &tomoyo_path_group_list, list) {
310302
tomoyo_collect_member(&group->member_list,
311-
TOMOYO_ID_PATH_GROUP_MEMBER);
303+
TOMOYO_ID_PATH_GROUP);
312304
if (!list_empty(&group->member_list) ||
313305
atomic_read(&group->users))
314306
continue;
315-
if (!tomoyo_add_to_gc(TOMOYO_ID_PATH_GROUP,
307+
if (!tomoyo_add_to_gc(TOMOYO_ID_GROUP,
316308
&group->list))
317309
goto unlock;
318310
}
319311
}
320312
{
321-
struct tomoyo_number_group *group;
313+
struct tomoyo_group *group;
322314
list_for_each_entry_rcu(group, &tomoyo_number_group_list,
323315
list) {
324316
tomoyo_collect_member(&group->member_list,
325-
TOMOYO_ID_NUMBER_GROUP_MEMBER);
317+
TOMOYO_ID_NUMBER_GROUP);
326318
if (!list_empty(&group->member_list) ||
327319
atomic_read(&group->users))
328320
continue;
329-
if (!tomoyo_add_to_gc(TOMOYO_ID_NUMBER_GROUP,
321+
if (!tomoyo_add_to_gc(TOMOYO_ID_GROUP,
330322
&group->list))
331323
goto unlock;
332324
}
@@ -377,14 +369,11 @@ static void tomoyo_kfree_entry(void)
377369
if (!tomoyo_del_domain(element))
378370
continue;
379371
break;
380-
case TOMOYO_ID_PATH_GROUP_MEMBER:
381-
tomoyo_del_path_group_member(element);
382-
break;
383372
case TOMOYO_ID_PATH_GROUP:
384373
tomoyo_del_path_group(element);
385374
break;
386-
case TOMOYO_ID_NUMBER_GROUP_MEMBER:
387-
tomoyo_del_number_group_member(element);
375+
case TOMOYO_ID_GROUP:
376+
tomoyo_del_group(element);
388377
break;
389378
case TOMOYO_ID_NUMBER_GROUP:
390379
tomoyo_del_number_group(element);

‎security/tomoyo/number_group.c‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
LIST_HEAD(tomoyo_number_group_list);
1212

1313
/**
14-
* tomoyo_get_number_group - Allocate memory for "struct tomoyo_number_group".
14+
* tomoyo_get_group - Allocate memory for "struct tomoyo_number_group".
1515
*
1616
* @group_name: The name of number group.
1717
*
1818
* Returns pointer to "struct tomoyo_number_group" on success,
1919
* NULL otherwise.
2020
*/
21-
struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name)
21+
struct tomoyo_group *tomoyo_get_number_group(const char *group_name)
2222
{
23-
struct tomoyo_number_group *entry = NULL;
24-
struct tomoyo_number_group *group = NULL;
23+
struct tomoyo_group *entry = NULL;
24+
struct tomoyo_group *group = NULL;
2525
const struct tomoyo_path_info *saved_group_name;
2626
int error = -ENOMEM;
2727
if (!tomoyo_correct_word(group_name))
@@ -59,12 +59,12 @@ struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name)
5959
static bool tomoyo_same_number_group(const struct tomoyo_acl_head *a,
6060
const struct tomoyo_acl_head *b)
6161
{
62-
return !memcmp(&container_of(a, struct tomoyo_number_group_member,
62+
return !memcmp(&container_of(a, struct tomoyo_number_group,
6363
head)->number,
64-
&container_of(b, struct tomoyo_number_group_member,
64+
&container_of(b, struct tomoyo_number_group,
6565
head)->number,
6666
sizeof(container_of(a,
67-
struct tomoyo_number_group_member,
67+
struct tomoyo_number_group,
6868
head)->number));
6969
}
7070

@@ -78,8 +78,8 @@ static bool tomoyo_same_number_group(const struct tomoyo_acl_head *a,
7878
*/
7979
int tomoyo_write_number_group_policy(char *data, const bool is_delete)
8080
{
81-
struct tomoyo_number_group *group;
82-
struct tomoyo_number_group_member e = { };
81+
struct tomoyo_group *group;
82+
struct tomoyo_number_group e = { };
8383
int error;
8484
char *w[2];
8585
if (!tomoyo_tokenize(data, w, sizeof(w)))
@@ -93,7 +93,7 @@ int tomoyo_write_number_group_policy(char *data, const bool is_delete)
9393
error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
9494
&group->member_list,
9595
tomoyo_same_number_group);
96-
tomoyo_put_number_group(group);
96+
tomoyo_put_group(group);
9797
return error;
9898
}
9999

@@ -111,16 +111,16 @@ bool tomoyo_read_number_group_policy(struct tomoyo_io_buffer *head)
111111
struct list_head *gpos;
112112
struct list_head *mpos;
113113
list_for_each_cookie(gpos, head->read_var1, &tomoyo_number_group_list) {
114-
struct tomoyo_number_group *group;
114+
struct tomoyo_group *group;
115115
const char *name;
116-
group = list_entry(gpos, struct tomoyo_number_group, list);
116+
group = list_entry(gpos, struct tomoyo_group, list);
117117
name = group->group_name->name;
118118
list_for_each_cookie(mpos, head->read_var2,
119119
&group->member_list) {
120120
int pos;
121-
const struct tomoyo_number_group_member *member
121+
const struct tomoyo_number_group *member
122122
= list_entry(mpos,
123-
struct tomoyo_number_group_member,
123+
struct tomoyo_number_group,
124124
head.list);
125125
if (member->head.is_deleted)
126126
continue;
@@ -150,9 +150,9 @@ bool tomoyo_read_number_group_policy(struct tomoyo_io_buffer *head)
150150
*/
151151
bool tomoyo_number_matches_group(const unsigned long min,
152152
const unsigned long max,
153-
const struct tomoyo_number_group *group)
153+
const struct tomoyo_group *group)
154154
{
155-
struct tomoyo_number_group_member *member;
155+
struct tomoyo_number_group *member;
156156
bool matched = false;
157157
list_for_each_entry_rcu(member, &group->member_list, head.list) {
158158
if (member->head.is_deleted)

‎security/tomoyo/path_group.c‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
LIST_HEAD(tomoyo_path_group_list);
1111

1212
/**
13-
* tomoyo_get_path_group - Allocate memory for "struct tomoyo_path_group".
13+
* tomoyo_get_group - Allocate memory for "struct tomoyo_path_group".
1414
*
1515
* @group_name: The name of pathname group.
1616
*
1717
* Returns pointer to "struct tomoyo_path_group" on success, NULL otherwise.
1818
*/
19-
struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name)
19+
struct tomoyo_group *tomoyo_get_path_group(const char *group_name)
2020
{
21-
struct tomoyo_path_group *entry = NULL;
22-
struct tomoyo_path_group *group = NULL;
21+
struct tomoyo_group *entry = NULL;
22+
struct tomoyo_group *group = NULL;
2323
const struct tomoyo_path_info *saved_group_name;
2424
int error = -ENOMEM;
2525
if (!tomoyo_correct_word(group_name))
@@ -57,9 +57,9 @@ struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name)
5757
static bool tomoyo_same_path_group(const struct tomoyo_acl_head *a,
5858
const struct tomoyo_acl_head *b)
5959
{
60-
return container_of(a, struct tomoyo_path_group_member, head)
60+
return container_of(a, struct tomoyo_path_group, head)
6161
->member_name ==
62-
container_of(b, struct tomoyo_path_group_member, head)
62+
container_of(b, struct tomoyo_path_group, head)
6363
->member_name;
6464
}
6565

@@ -73,8 +73,8 @@ static bool tomoyo_same_path_group(const struct tomoyo_acl_head *a,
7373
*/
7474
int tomoyo_write_path_group_policy(char *data, const bool is_delete)
7575
{
76-
struct tomoyo_path_group *group;
77-
struct tomoyo_path_group_member e = { };
76+
struct tomoyo_group *group;
77+
struct tomoyo_path_group e = { };
7878
int error = is_delete ? -ENOENT : -ENOMEM;
7979
char *w[2];
8080
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)
9090
tomoyo_same_path_group);
9191
out:
9292
tomoyo_put_name(e.member_name);
93-
tomoyo_put_path_group(group);
93+
tomoyo_put_group(group);
9494
return error;
9595
}
9696

@@ -108,13 +108,13 @@ bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head)
108108
struct list_head *gpos;
109109
struct list_head *mpos;
110110
list_for_each_cookie(gpos, head->read_var1, &tomoyo_path_group_list) {
111-
struct tomoyo_path_group *group;
112-
group = list_entry(gpos, struct tomoyo_path_group, list);
111+
struct tomoyo_group *group;
112+
group = list_entry(gpos, struct tomoyo_group, list);
113113
list_for_each_cookie(mpos, head->read_var2,
114114
&group->member_list) {
115-
struct tomoyo_path_group_member *member;
115+
struct tomoyo_path_group *member;
116116
member = list_entry(mpos,
117-
struct tomoyo_path_group_member,
117+
struct tomoyo_path_group,
118118
head.list);
119119
if (member->head.is_deleted)
120120
continue;
@@ -139,9 +139,9 @@ bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head)
139139
* Caller holds tomoyo_read_lock().
140140
*/
141141
bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
142-
const struct tomoyo_path_group *group)
142+
const struct tomoyo_group *group)
143143
{
144-
struct tomoyo_path_group_member *member;
144+
struct tomoyo_path_group *member;
145145
bool matched = false;
146146
list_for_each_entry_rcu(member, &group->member_list, head.list) {
147147
if (member->head.is_deleted)

0 commit comments

Comments
 (0)