Skip to content

Commit

Permalink
TOMOYO: Use structure for passing common arguments.
Browse files Browse the repository at this point in the history
Use "struct tomoyo_request_info" instead of passing individual arguments.

Signed-off-by: Tetsuo Handa <[email protected]>
Signed-off-by: James Morris <[email protected]>
  • Loading branch information
Tetsuo Handa authored and James Morris committed Aug 2, 2010
1 parent 4c3e9e2 commit cb0abe6
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 206 deletions.
22 changes: 5 additions & 17 deletions security/tomoyo/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,21 +984,6 @@ static const char *tomoyo_get_exe(void)
return cp;
}

/**
* tomoyo_get_msg - Get warning message.
*
* @is_enforce: Is it enforcing mode?
*
* Returns "ERROR" or "WARNING".
*/
const char *tomoyo_get_msg(const bool is_enforce)
{
if (is_enforce)
return "ERROR";
else
return "WARNING";
}

/**
* tomoyo_check_flags - Check mode for specified functionality.
*
Expand Down Expand Up @@ -1040,17 +1025,20 @@ bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain)
/**
* tomoyo_domain_quota_is_ok - Check for domain's quota.
*
* @domain: Pointer to "struct tomoyo_domain_info".
* @r: Pointer to "struct tomoyo_request_info".
*
* Returns true if the domain is not exceeded quota, false otherwise.
*
* Caller holds tomoyo_read_lock().
*/
bool tomoyo_domain_quota_is_ok(struct tomoyo_domain_info * const domain)
bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r)
{
unsigned int count = 0;
struct tomoyo_domain_info *domain = r->domain;
struct tomoyo_acl_info *ptr;

if (r->mode != TOMOYO_CONFIG_LEARNING)
return false;
if (!domain)
return true;
list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
Expand Down
27 changes: 21 additions & 6 deletions security/tomoyo/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ struct linux_binprm;
/* Profile number is an integer between 0 and 255. */
#define TOMOYO_MAX_PROFILES 256

enum tomoyo_mode_index {
TOMOYO_CONFIG_DISABLED,
TOMOYO_CONFIG_LEARNING,
TOMOYO_CONFIG_PERMISSIVE,
TOMOYO_CONFIG_ENFORCING
};

/* Keywords for ACLs. */
#define TOMOYO_KEYWORD_ALIAS "alias "
#define TOMOYO_KEYWORD_ALLOW_READ "allow_read "
Expand Down Expand Up @@ -152,6 +159,17 @@ struct tomoyo_page_buffer {
char buffer[4096];
};

/*
* tomoyo_request_info is a structure which is used for holding
*
* (1) Domain information of current process.
* (2) Access control mode of the profile.
*/
struct tomoyo_request_info {
struct tomoyo_domain_info *domain;
u8 mode; /* One of tomoyo_mode_index . */
};

/*
* tomoyo_path_info is a structure which is used for holding a string data
* used by TOMOYO.
Expand Down Expand Up @@ -332,8 +350,8 @@ struct tomoyo_domain_info {
* "allow_read", "allow_write", "allow_create", "allow_unlink", "allow_mkdir",
* "allow_rmdir", "allow_mkfifo", "allow_mksock", "allow_mkblock",
* "allow_mkchar", "allow_truncate", "allow_symlink", "allow_rewrite",
* "allow_chmod", "allow_chown", "allow_chgrp", "allow_chroot", "allow_mount"
* and "allow_unmount".
* "allow_ioctl", "allow_chmod", "allow_chown", "allow_chgrp", "allow_chroot",
* "allow_mount" and "allow_unmount".
*/
struct tomoyo_path_acl {
struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
Expand Down Expand Up @@ -567,7 +585,7 @@ struct tomoyo_policy_manager_entry {
bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
const struct tomoyo_name_union *ptr);
/* Check whether the domain has too many ACL entries to hold. */
bool tomoyo_domain_quota_is_ok(struct tomoyo_domain_info * const domain);
bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
/* Transactional sprintf() for policy dump. */
bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
__attribute__ ((format(printf, 2, 3)));
Expand Down Expand Up @@ -623,8 +641,6 @@ bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
const char *tomoyo_path22keyword(const u8 operation);
/* Get the last component of the given domainname. */
const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain);
/* Get warning message. */
const char *tomoyo_get_msg(const bool is_enforce);
/* Convert single path operation to operation name. */
const char *tomoyo_path2keyword(const u8 operation);
/* Create "alias" entry in exception policy. */
Expand Down Expand Up @@ -723,7 +739,6 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
int tomoyo_path_perm(const u8 operation, struct path *path);
int tomoyo_path2_perm(const u8 operation, struct path *path1,
struct path *path2);
int tomoyo_check_rewrite_permission(struct file *filp);
int tomoyo_find_next_domain(struct linux_binprm *bprm);

/* Drop refcount on tomoyo_name_union. */
Expand Down
2 changes: 1 addition & 1 deletion security/tomoyo/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
char *real_program_name = NULL;
char *symlink_program_name = NULL;
const u8 mode = tomoyo_check_flags(old_domain, TOMOYO_MAC_FOR_FILE);
const bool is_enforce = (mode == 3);
const bool is_enforce = (mode == TOMOYO_CONFIG_ENFORCING);
int retval = -ENOMEM;
struct tomoyo_path_info r; /* real name */
struct tomoyo_path_info s; /* symlink name */
Expand Down
Loading

0 comments on commit cb0abe6

Please sign in to comment.