Skip to content

Commit cb0abe6

Browse files
Tetsuo Handaxjamesmorris
authored andcommitted
TOMOYO: Use structure for passing common arguments.
Use "struct tomoyo_request_info" instead of passing individual arguments. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: James Morris <jmorris@namei.org>
1 parent 4c3e9e2 commit cb0abe6

5 files changed

Lines changed: 162 additions & 206 deletions

File tree

‎security/tomoyo/common.c‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -984,21 +984,6 @@ static const char *tomoyo_get_exe(void)
984984
return cp;
985985
}
986986

987-
/**
988-
* tomoyo_get_msg - Get warning message.
989-
*
990-
* @is_enforce: Is it enforcing mode?
991-
*
992-
* Returns "ERROR" or "WARNING".
993-
*/
994-
const char *tomoyo_get_msg(const bool is_enforce)
995-
{
996-
if (is_enforce)
997-
return "ERROR";
998-
else
999-
return "WARNING";
1000-
}
1001-
1002987
/**
1003988
* tomoyo_check_flags - Check mode for specified functionality.
1004989
*
@@ -1040,17 +1025,20 @@ bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain)
10401025
/**
10411026
* tomoyo_domain_quota_is_ok - Check for domain's quota.
10421027
*
1043-
* @domain: Pointer to "struct tomoyo_domain_info".
1028+
* @r: Pointer to "struct tomoyo_request_info".
10441029
*
10451030
* Returns true if the domain is not exceeded quota, false otherwise.
10461031
*
10471032
* Caller holds tomoyo_read_lock().
10481033
*/
1049-
bool tomoyo_domain_quota_is_ok(struct tomoyo_domain_info * const domain)
1034+
bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r)
10501035
{
10511036
unsigned int count = 0;
1037+
struct tomoyo_domain_info *domain = r->domain;
10521038
struct tomoyo_acl_info *ptr;
10531039

1040+
if (r->mode != TOMOYO_CONFIG_LEARNING)
1041+
return false;
10541042
if (!domain)
10551043
return true;
10561044
list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {

‎security/tomoyo/common.h‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ struct linux_binprm;
4444
/* Profile number is an integer between 0 and 255. */
4545
#define TOMOYO_MAX_PROFILES 256
4646

47+
enum tomoyo_mode_index {
48+
TOMOYO_CONFIG_DISABLED,
49+
TOMOYO_CONFIG_LEARNING,
50+
TOMOYO_CONFIG_PERMISSIVE,
51+
TOMOYO_CONFIG_ENFORCING
52+
};
53+
4754
/* Keywords for ACLs. */
4855
#define TOMOYO_KEYWORD_ALIAS "alias "
4956
#define TOMOYO_KEYWORD_ALLOW_READ "allow_read "
@@ -152,6 +159,17 @@ struct tomoyo_page_buffer {
152159
char buffer[4096];
153160
};
154161

162+
/*
163+
* tomoyo_request_info is a structure which is used for holding
164+
*
165+
* (1) Domain information of current process.
166+
* (2) Access control mode of the profile.
167+
*/
168+
struct tomoyo_request_info {
169+
struct tomoyo_domain_info *domain;
170+
u8 mode; /* One of tomoyo_mode_index . */
171+
};
172+
155173
/*
156174
* tomoyo_path_info is a structure which is used for holding a string data
157175
* used by TOMOYO.
@@ -332,8 +350,8 @@ struct tomoyo_domain_info {
332350
* "allow_read", "allow_write", "allow_create", "allow_unlink", "allow_mkdir",
333351
* "allow_rmdir", "allow_mkfifo", "allow_mksock", "allow_mkblock",
334352
* "allow_mkchar", "allow_truncate", "allow_symlink", "allow_rewrite",
335-
* "allow_chmod", "allow_chown", "allow_chgrp", "allow_chroot", "allow_mount"
336-
* and "allow_unmount".
353+
* "allow_ioctl", "allow_chmod", "allow_chown", "allow_chgrp", "allow_chroot",
354+
* "allow_mount" and "allow_unmount".
337355
*/
338356
struct tomoyo_path_acl {
339357
struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
@@ -567,7 +585,7 @@ struct tomoyo_policy_manager_entry {
567585
bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
568586
const struct tomoyo_name_union *ptr);
569587
/* Check whether the domain has too many ACL entries to hold. */
570-
bool tomoyo_domain_quota_is_ok(struct tomoyo_domain_info * const domain);
588+
bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
571589
/* Transactional sprintf() for policy dump. */
572590
bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
573591
__attribute__ ((format(printf, 2, 3)));
@@ -623,8 +641,6 @@ bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
623641
const char *tomoyo_path22keyword(const u8 operation);
624642
/* Get the last component of the given domainname. */
625643
const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain);
626-
/* Get warning message. */
627-
const char *tomoyo_get_msg(const bool is_enforce);
628644
/* Convert single path operation to operation name. */
629645
const char *tomoyo_path2keyword(const u8 operation);
630646
/* Create "alias" entry in exception policy. */
@@ -723,7 +739,6 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
723739
int tomoyo_path_perm(const u8 operation, struct path *path);
724740
int tomoyo_path2_perm(const u8 operation, struct path *path1,
725741
struct path *path2);
726-
int tomoyo_check_rewrite_permission(struct file *filp);
727742
int tomoyo_find_next_domain(struct linux_binprm *bprm);
728743

729744
/* Drop refcount on tomoyo_name_union. */

‎security/tomoyo/domain.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
691691
char *real_program_name = NULL;
692692
char *symlink_program_name = NULL;
693693
const u8 mode = tomoyo_check_flags(old_domain, TOMOYO_MAC_FOR_FILE);
694-
const bool is_enforce = (mode == 3);
694+
const bool is_enforce = (mode == TOMOYO_CONFIG_ENFORCING);
695695
int retval = -ENOMEM;
696696
struct tomoyo_path_info r; /* real name */
697697
struct tomoyo_path_info s; /* symlink name */

0 commit comments

Comments
 (0)