Skip to content

Commit a238cf5

Browse files
Tetsuo Handaxjamesmorris
authored andcommitted
TOMOYO: Use struct for passing ACL line.
Use structure for passing ACL line, in preparation for supporting policy namespace and conditional parameters. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: James Morris <jmorris@namei.org>
1 parent 0df7e8b commit a238cf5

8 files changed

Lines changed: 347 additions & 371 deletions

File tree

‎security/tomoyo/common.c‎

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,11 @@ static int tomoyo_update_manager_entry(const char *manager,
611611
const bool is_delete)
612612
{
613613
struct tomoyo_manager e = { };
614-
int error;
615-
614+
struct tomoyo_acl_param param = {
615+
.is_delete = is_delete,
616+
.list = &tomoyo_policy_list[TOMOYO_ID_MANAGER],
617+
};
618+
int error = is_delete ? -ENOENT : -ENOMEM;
616619
if (tomoyo_domain_def(manager)) {
617620
if (!tomoyo_correct_domain(manager))
618621
return -EINVAL;
@@ -622,12 +625,11 @@ static int tomoyo_update_manager_entry(const char *manager,
622625
return -EINVAL;
623626
}
624627
e.manager = tomoyo_get_name(manager);
625-
if (!e.manager)
626-
return -ENOMEM;
627-
error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
628-
&tomoyo_policy_list[TOMOYO_ID_MANAGER],
629-
tomoyo_same_manager);
630-
tomoyo_put_name(e.manager);
628+
if (e.manager) {
629+
error = tomoyo_update_policy(&e.head, sizeof(e), &param,
630+
tomoyo_same_manager);
631+
tomoyo_put_name(e.manager);
632+
}
631633
return error;
632634
}
633635

@@ -821,18 +823,36 @@ static int tomoyo_delete_domain(char *domainname)
821823
/**
822824
* tomoyo_write_domain2 - Write domain policy.
823825
*
824-
* @head: Pointer to "struct tomoyo_io_buffer".
826+
* @list: Pointer to "struct list_head".
827+
* @data: Policy to be interpreted.
828+
* @is_delete: True if it is a delete request.
825829
*
826830
* Returns 0 on success, negative value otherwise.
827831
*
828832
* Caller holds tomoyo_read_lock().
829833
*/
830-
static int tomoyo_write_domain2(char *data, struct tomoyo_domain_info *domain,
834+
static int tomoyo_write_domain2(struct list_head *list, char *data,
831835
const bool is_delete)
832836
{
833-
if (tomoyo_str_starts(&data, "allow_mount "))
834-
return tomoyo_write_mount(data, domain, is_delete);
835-
return tomoyo_write_file(data, domain, is_delete);
837+
struct tomoyo_acl_param param = {
838+
.list = list,
839+
.data = data,
840+
.is_delete = is_delete,
841+
};
842+
static const struct {
843+
const char *keyword;
844+
int (*write) (struct tomoyo_acl_param *);
845+
} tomoyo_callback[1] = {
846+
{ "file ", tomoyo_write_file },
847+
};
848+
u8 i;
849+
for (i = 0; i < 1; i++) {
850+
if (!tomoyo_str_starts(&param.data,
851+
tomoyo_callback[i].keyword))
852+
continue;
853+
return tomoyo_callback[i].write(&param);
854+
}
855+
return -EINVAL;
836856
}
837857

838858
/**
@@ -889,7 +909,7 @@ static int tomoyo_write_domain(struct tomoyo_io_buffer *head)
889909
domain->transition_failed = !is_delete;
890910
return 0;
891911
}
892-
return tomoyo_write_domain2(data, domain, is_delete);
912+
return tomoyo_write_domain2(&domain->acl_info_list, data, is_delete);
893913
}
894914

895915
/**
@@ -1213,26 +1233,19 @@ static const char *tomoyo_group_name[TOMOYO_MAX_GROUP] = {
12131233
*/
12141234
static int tomoyo_write_exception(struct tomoyo_io_buffer *head)
12151235
{
1216-
char *data = head->write_buf;
1217-
bool is_delete = tomoyo_str_starts(&data, "delete ");
1218-
u8 i;
1219-
static const struct {
1220-
const char *keyword;
1221-
int (*write) (char *, const bool);
1222-
} tomoyo_callback[1] = {
1223-
{ "aggregator ", tomoyo_write_aggregator },
1236+
struct tomoyo_acl_param param = {
1237+
.data = head->write_buf,
12241238
};
1225-
1239+
u8 i;
1240+
param.is_delete = tomoyo_str_starts(&param.data, "delete ");
1241+
if (tomoyo_str_starts(&param.data, "aggregator "))
1242+
return tomoyo_write_aggregator(&param);
12261243
for (i = 0; i < TOMOYO_MAX_TRANSITION_TYPE; i++)
1227-
if (tomoyo_str_starts(&data, tomoyo_transition_type[i]))
1228-
return tomoyo_write_transition_control(data, is_delete,
1229-
i);
1230-
for (i = 0; i < 1; i++)
1231-
if (tomoyo_str_starts(&data, tomoyo_callback[i].keyword))
1232-
return tomoyo_callback[i].write(data, is_delete);
1244+
if (tomoyo_str_starts(&param.data, tomoyo_transition_type[i]))
1245+
return tomoyo_write_transition_control(&param, i);
12331246
for (i = 0; i < TOMOYO_MAX_GROUP; i++)
1234-
if (tomoyo_str_starts(&data, tomoyo_group_name[i]))
1235-
return tomoyo_write_group(data, is_delete, i);
1247+
if (tomoyo_str_starts(&param.data, tomoyo_group_name[i]))
1248+
return tomoyo_write_group(&param, i);
12361249
return -EINVAL;
12371250
}
12381251

@@ -1490,7 +1503,7 @@ int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
14901503
vsnprintf(buffer, len - 1, fmt, args);
14911504
va_end(args);
14921505
tomoyo_normalize_line(buffer);
1493-
tomoyo_write_domain2(buffer, r->domain, false);
1506+
tomoyo_write_domain2(&r->domain->acl_info_list, buffer, false);
14941507
kfree(buffer);
14951508
/* fall through */
14961509
case TOMOYO_CONFIG_PERMISSIVE:

‎security/tomoyo/common.h‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,13 @@ struct tomoyo_mount_acl {
397397
struct tomoyo_number_union flags;
398398
};
399399

400+
/* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
401+
struct tomoyo_acl_param {
402+
char *data;
403+
struct list_head *list;
404+
bool is_delete;
405+
};
406+
400407
#define TOMOYO_MAX_IO_READ_QUEUE 32
401408

402409
/*
@@ -521,7 +528,7 @@ bool tomoyo_correct_domain(const unsigned char *domainname);
521528
bool tomoyo_correct_path(const char *filename);
522529
bool tomoyo_correct_word(const char *string);
523530
bool tomoyo_domain_def(const unsigned char *buffer);
524-
bool tomoyo_parse_name_union(const char *filename,
531+
bool tomoyo_parse_name_union(struct tomoyo_acl_param *param,
525532
struct tomoyo_name_union *ptr);
526533
const struct tomoyo_path_info *
527534
tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
@@ -531,7 +538,8 @@ bool tomoyo_number_matches_group(const unsigned long min,
531538
const struct tomoyo_group *group);
532539
bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
533540
const struct tomoyo_path_info *pattern);
534-
bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num);
541+
bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
542+
struct tomoyo_number_union *ptr);
535543
bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
536544
bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
537545
int tomoyo_init_request_info(struct tomoyo_request_info *r,
@@ -540,21 +548,19 @@ int tomoyo_init_request_info(struct tomoyo_request_info *r,
540548
int tomoyo_mount_permission(char *dev_name, struct path *path,
541549
const char *type, unsigned long flags,
542550
void *data_page);
543-
int tomoyo_write_aggregator(char *data, const bool is_delete);
544-
int tomoyo_write_transition_control(char *data, const bool is_delete,
551+
int tomoyo_write_aggregator(struct tomoyo_acl_param *param);
552+
int tomoyo_write_transition_control(struct tomoyo_acl_param *param,
545553
const u8 type);
546-
int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain,
547-
const bool is_delete);
548-
int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain,
549-
const bool is_delete);
550-
int tomoyo_write_group(char *data, const bool is_delete, const u8 type);
554+
int tomoyo_write_file(struct tomoyo_acl_param *param);
555+
int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type);
551556
int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
552557
__attribute__ ((format(printf, 2, 3)));
553558
struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
554559
struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
555560
const u8 profile);
556561
struct tomoyo_profile *tomoyo_profile(const u8 profile);
557-
struct tomoyo_group *tomoyo_get_group(const char *group_name, const u8 type);
562+
struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param,
563+
const u8 idx);
558564
unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
559565
const u8 index);
560566
void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
@@ -587,7 +593,7 @@ void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
587593
void tomoyo_run_gc(void);
588594
void tomoyo_memory_free(void *ptr);
589595
int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
590-
bool is_delete, struct tomoyo_domain_info *domain,
596+
struct tomoyo_acl_param *param,
591597
bool (*check_duplicate) (const struct tomoyo_acl_info
592598
*,
593599
const struct tomoyo_acl_info
@@ -596,14 +602,16 @@ int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
596602
struct tomoyo_acl_info *,
597603
const bool));
598604
int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
599-
bool is_delete, struct list_head *list,
605+
struct tomoyo_acl_param *param,
600606
bool (*check_duplicate) (const struct tomoyo_acl_head
601607
*,
602608
const struct tomoyo_acl_head
603609
*));
604610
void tomoyo_check_acl(struct tomoyo_request_info *r,
605611
bool (*check_entry) (struct tomoyo_request_info *,
606612
const struct tomoyo_acl_info *));
613+
char *tomoyo_read_token(struct tomoyo_acl_param *param);
614+
bool tomoyo_permstr(const char *string, const char *keyword);
607615

608616
/********** External variable definitions. **********/
609617

0 commit comments

Comments
 (0)