Commit cb0abe6a authored by Tetsuo Handa's avatar Tetsuo Handa Committed by James Morris

TOMOYO: Use structure for passing common arguments.

Use "struct tomoyo_request_info" instead of passing individual arguments.
Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
parent 4c3e9e2d
...@@ -984,21 +984,6 @@ static const char *tomoyo_get_exe(void) ...@@ -984,21 +984,6 @@ static const char *tomoyo_get_exe(void)
return cp; 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. * tomoyo_check_flags - Check mode for specified functionality.
* *
...@@ -1040,17 +1025,20 @@ bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain) ...@@ -1040,17 +1025,20 @@ bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain)
/** /**
* tomoyo_domain_quota_is_ok - Check for domain's quota. * 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. * Returns true if the domain is not exceeded quota, false otherwise.
* *
* Caller holds tomoyo_read_lock(). * 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; unsigned int count = 0;
struct tomoyo_domain_info *domain = r->domain;
struct tomoyo_acl_info *ptr; struct tomoyo_acl_info *ptr;
if (r->mode != TOMOYO_CONFIG_LEARNING)
return false;
if (!domain) if (!domain)
return true; return true;
list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) { list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
......
...@@ -44,6 +44,13 @@ struct linux_binprm; ...@@ -44,6 +44,13 @@ struct linux_binprm;
/* Profile number is an integer between 0 and 255. */ /* Profile number is an integer between 0 and 255. */
#define TOMOYO_MAX_PROFILES 256 #define TOMOYO_MAX_PROFILES 256
enum tomoyo_mode_index {
TOMOYO_CONFIG_DISABLED,
TOMOYO_CONFIG_LEARNING,
TOMOYO_CONFIG_PERMISSIVE,
TOMOYO_CONFIG_ENFORCING
};
/* Keywords for ACLs. */ /* Keywords for ACLs. */
#define TOMOYO_KEYWORD_ALIAS "alias " #define TOMOYO_KEYWORD_ALIAS "alias "
#define TOMOYO_KEYWORD_ALLOW_READ "allow_read " #define TOMOYO_KEYWORD_ALLOW_READ "allow_read "
...@@ -152,6 +159,17 @@ struct tomoyo_page_buffer { ...@@ -152,6 +159,17 @@ struct tomoyo_page_buffer {
char buffer[4096]; 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 * tomoyo_path_info is a structure which is used for holding a string data
* used by TOMOYO. * used by TOMOYO.
...@@ -332,8 +350,8 @@ struct tomoyo_domain_info { ...@@ -332,8 +350,8 @@ struct tomoyo_domain_info {
* "allow_read", "allow_write", "allow_create", "allow_unlink", "allow_mkdir", * "allow_read", "allow_write", "allow_create", "allow_unlink", "allow_mkdir",
* "allow_rmdir", "allow_mkfifo", "allow_mksock", "allow_mkblock", * "allow_rmdir", "allow_mkfifo", "allow_mksock", "allow_mkblock",
* "allow_mkchar", "allow_truncate", "allow_symlink", "allow_rewrite", * "allow_mkchar", "allow_truncate", "allow_symlink", "allow_rewrite",
* "allow_chmod", "allow_chown", "allow_chgrp", "allow_chroot", "allow_mount" * "allow_ioctl", "allow_chmod", "allow_chown", "allow_chgrp", "allow_chroot",
* and "allow_unmount". * "allow_mount" and "allow_unmount".
*/ */
struct tomoyo_path_acl { struct tomoyo_path_acl {
struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
...@@ -567,7 +585,7 @@ struct tomoyo_policy_manager_entry { ...@@ -567,7 +585,7 @@ struct tomoyo_policy_manager_entry {
bool tomoyo_compare_name_union(const struct tomoyo_path_info *name, bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
const struct tomoyo_name_union *ptr); const struct tomoyo_name_union *ptr);
/* Check whether the domain has too many ACL entries to hold. */ /* 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. */ /* Transactional sprintf() for policy dump. */
bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
__attribute__ ((format(printf, 2, 3))); __attribute__ ((format(printf, 2, 3)));
...@@ -623,8 +641,6 @@ bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); ...@@ -623,8 +641,6 @@ bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
const char *tomoyo_path22keyword(const u8 operation); const char *tomoyo_path22keyword(const u8 operation);
/* Get the last component of the given domainname. */ /* Get the last component of the given domainname. */
const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain); 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. */ /* Convert single path operation to operation name. */
const char *tomoyo_path2keyword(const u8 operation); const char *tomoyo_path2keyword(const u8 operation);
/* Create "alias" entry in exception policy. */ /* Create "alias" entry in exception policy. */
...@@ -723,7 +739,6 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, ...@@ -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_path_perm(const u8 operation, struct path *path);
int tomoyo_path2_perm(const u8 operation, struct path *path1, int tomoyo_path2_perm(const u8 operation, struct path *path1,
struct path *path2); struct path *path2);
int tomoyo_check_rewrite_permission(struct file *filp);
int tomoyo_find_next_domain(struct linux_binprm *bprm); int tomoyo_find_next_domain(struct linux_binprm *bprm);
/* Drop refcount on tomoyo_name_union. */ /* Drop refcount on tomoyo_name_union. */
......
...@@ -691,7 +691,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm) ...@@ -691,7 +691,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
char *real_program_name = NULL; char *real_program_name = NULL;
char *symlink_program_name = NULL; char *symlink_program_name = NULL;
const u8 mode = tomoyo_check_flags(old_domain, TOMOYO_MAC_FOR_FILE); 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; int retval = -ENOMEM;
struct tomoyo_path_info r; /* real name */ struct tomoyo_path_info r; /* real name */
struct tomoyo_path_info s; /* symlink name */ struct tomoyo_path_info s; /* symlink name */
......
This diff is collapsed.
...@@ -173,7 +173,7 @@ static int tomoyo_file_fcntl(struct file *file, unsigned int cmd, ...@@ -173,7 +173,7 @@ static int tomoyo_file_fcntl(struct file *file, unsigned int cmd,
unsigned long arg) unsigned long arg)
{ {
if (cmd == F_SETFL && ((arg ^ file->f_flags) & O_APPEND)) if (cmd == F_SETFL && ((arg ^ file->f_flags) & O_APPEND))
return tomoyo_check_rewrite_permission(file); return tomoyo_path_perm(TOMOYO_TYPE_REWRITE, &file->f_path);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment