Commit 17fcfbd9 authored by Tetsuo Handa's avatar Tetsuo Handa Committed by James Morris

TOMOYO: Add interactive enforcing mode.

Since the behavior of the system is restricted by policy, we may need to update
policy when you update packages.

We need to update policy in the following cases.

    * The pathname of files has changed.
    * The dependency of files has changed.
    * The access permissions required has increased.

The ideal way to update policy is to rebuild from the scratch using learning
mode. But it is not desirable to change from enforcing mode to other mode if
the system has once entered in production state. Suppose MAC could support
per-application enforcing mode, the MAC becomes useless if an application that
is not running in enforcing mode was cracked. For example, the whole system
becomes vulnerable if only HTTP server application is running in learning mode
to rebuild policy for the application. So, in TOMOYO Linux, updating policy is
done while the system is running in enforcing mode.

This patch implements "interactive enforcing mode" which allows administrators
to judge whether to accept policy violation in enforcing mode or not.
A demo movie is available at http://www.youtube.com/watch?v=b9q1Jo25LPA .
Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
parent 2106ccd9
This diff is collapsed.
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/cred.h> #include <linux/cred.h>
#include <linux/poll.h>
struct linux_binprm; struct linux_binprm;
/********** Constants definitions. **********/ /********** Constants definitions. **********/
...@@ -156,9 +157,12 @@ enum tomoyo_securityfs_interface_index { ...@@ -156,9 +157,12 @@ enum tomoyo_securityfs_interface_index {
TOMOYO_SELFDOMAIN, TOMOYO_SELFDOMAIN,
TOMOYO_VERSION, TOMOYO_VERSION,
TOMOYO_PROFILE, TOMOYO_PROFILE,
TOMOYO_QUERY,
TOMOYO_MANAGER TOMOYO_MANAGER
}; };
#define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */
/********** Structure definitions. **********/ /********** Structure definitions. **********/
/* /*
...@@ -176,10 +180,14 @@ struct tomoyo_page_buffer { ...@@ -176,10 +180,14 @@ struct tomoyo_page_buffer {
* tomoyo_request_info is a structure which is used for holding * tomoyo_request_info is a structure which is used for holding
* *
* (1) Domain information of current process. * (1) Domain information of current process.
* (2) Access control mode of the profile. * (2) How many retries are made for this request.
* (3) Profile number used for this request.
* (4) Access control mode of the profile.
*/ */
struct tomoyo_request_info { struct tomoyo_request_info {
struct tomoyo_domain_info *domain; struct tomoyo_domain_info *domain;
u8 retry;
u8 profile;
u8 mode; /* One of tomoyo_mode_index . */ u8 mode; /* One of tomoyo_mode_index . */
}; };
...@@ -484,6 +492,7 @@ struct tomoyo_mount_acl { ...@@ -484,6 +492,7 @@ struct tomoyo_mount_acl {
struct tomoyo_io_buffer { struct tomoyo_io_buffer {
int (*read) (struct tomoyo_io_buffer *); int (*read) (struct tomoyo_io_buffer *);
int (*write) (struct tomoyo_io_buffer *); int (*write) (struct tomoyo_io_buffer *);
int (*poll) (struct file *file, poll_table *wait);
/* Exclusive lock for this structure. */ /* Exclusive lock for this structure. */
struct mutex io_sem; struct mutex io_sem;
/* Index returned by tomoyo_read_lock(). */ /* Index returned by tomoyo_read_lock(). */
...@@ -514,6 +523,8 @@ struct tomoyo_io_buffer { ...@@ -514,6 +523,8 @@ struct tomoyo_io_buffer {
int write_avail; int write_avail;
/* Size of write buffer. */ /* Size of write buffer. */
int writebuf_size; int writebuf_size;
/* Type of this interface. */
u8 type;
}; };
/* /*
...@@ -659,14 +670,15 @@ struct tomoyo_policy_manager_entry { ...@@ -659,14 +670,15 @@ struct tomoyo_policy_manager_entry {
/********** Function prototypes. **********/ /********** Function prototypes. **********/
extern asmlinkage long sys_getpid(void);
extern asmlinkage long sys_getppid(void);
/* Check whether the given name matches the given name_union. */ /* Check whether the given name matches the given name_union. */
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 given number matches the given number_union. */ /* Check whether the given number matches the given number_union. */
bool tomoyo_compare_number_union(const unsigned long value, bool tomoyo_compare_number_union(const unsigned long value,
const struct tomoyo_number_union *ptr); const struct tomoyo_number_union *ptr);
/* Check whether the domain has too many ACL entries to hold. */
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)));
...@@ -763,6 +775,8 @@ int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete); ...@@ -763,6 +775,8 @@ int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete);
int tomoyo_write_pattern_policy(char *data, const bool is_delete); int tomoyo_write_pattern_policy(char *data, const bool is_delete);
/* Create "path_group" entry in exception policy. */ /* Create "path_group" entry in exception policy. */
int tomoyo_write_path_group_policy(char *data, const bool is_delete); int tomoyo_write_path_group_policy(char *data, const bool is_delete);
int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
__attribute__ ((format(printf, 2, 3)));
/* Create "number_group" entry in exception policy. */ /* Create "number_group" entry in exception policy. */
int tomoyo_write_number_group_policy(char *data, const bool is_delete); int tomoyo_write_number_group_policy(char *data, const bool is_delete);
/* Find a domain by the given name. */ /* Find a domain by the given name. */
...@@ -771,9 +785,6 @@ struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); ...@@ -771,9 +785,6 @@ struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char * struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
domainname, domainname,
const u8 profile); const u8 profile);
/* Get patterned pathname. */
const struct tomoyo_path_info *
tomoyo_get_file_pattern(const struct tomoyo_path_info *filename);
/* Allocate memory for "struct tomoyo_path_group". */ /* Allocate memory for "struct tomoyo_path_group". */
struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name); struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name);
struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name); struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name);
...@@ -807,6 +818,8 @@ char *tomoyo_realpath(const char *pathname); ...@@ -807,6 +818,8 @@ char *tomoyo_realpath(const char *pathname);
char *tomoyo_realpath_nofollow(const char *pathname); char *tomoyo_realpath_nofollow(const char *pathname);
/* Same with tomoyo_realpath() except that the pathname is already solved. */ /* Same with tomoyo_realpath() except that the pathname is already solved. */
char *tomoyo_realpath_from_path(struct path *path); char *tomoyo_realpath_from_path(struct path *path);
/* Get patterned pathname. */
const char *tomoyo_file_pattern(const struct tomoyo_path_info *filename);
/* Check memory quota. */ /* Check memory quota. */
bool tomoyo_memory_ok(void *ptr); bool tomoyo_memory_ok(void *ptr);
...@@ -878,6 +891,9 @@ extern bool tomoyo_policy_loaded; ...@@ -878,6 +891,9 @@ extern bool tomoyo_policy_loaded;
/* The kernel's domain. */ /* The kernel's domain. */
extern struct tomoyo_domain_info tomoyo_kernel_domain; extern struct tomoyo_domain_info tomoyo_kernel_domain;
extern unsigned int tomoyo_quota_for_query;
extern unsigned int tomoyo_query_memory_size;
/********** Inlined functions. **********/ /********** Inlined functions. **********/
static inline int tomoyo_read_lock(void) static inline int tomoyo_read_lock(void)
......
...@@ -678,6 +678,7 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char * ...@@ -678,6 +678,7 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
*/ */
int tomoyo_find_next_domain(struct linux_binprm *bprm) int tomoyo_find_next_domain(struct linux_binprm *bprm)
{ {
struct tomoyo_request_info r;
/* /*
* This function assumes that the size of buffer returned by * This function assumes that the size of buffer returned by
* tomoyo_realpath() = TOMOYO_MAX_PATHNAME_LEN. * tomoyo_realpath() = TOMOYO_MAX_PATHNAME_LEN.
...@@ -693,11 +694,12 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm) ...@@ -693,11 +694,12 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
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 == TOMOYO_CONFIG_ENFORCING); 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 rn; /* real name */
struct tomoyo_path_info s; /* symlink name */ struct tomoyo_path_info sn; /* symlink name */
struct tomoyo_path_info l; /* last name */ struct tomoyo_path_info ln; /* last name */
static bool initialized; static bool initialized;
tomoyo_init_request_info(&r, NULL);
if (!tmp) if (!tmp)
goto out; goto out;
...@@ -713,6 +715,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm) ...@@ -713,6 +715,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
initialized = true; initialized = true;
} }
retry:
/* Get tomoyo_realpath of program. */ /* Get tomoyo_realpath of program. */
retval = -ENOENT; retval = -ENOENT;
/* I hope tomoyo_realpath() won't fail with -ENOMEM. */ /* I hope tomoyo_realpath() won't fail with -ENOMEM. */
...@@ -724,37 +727,39 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm) ...@@ -724,37 +727,39 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
if (!symlink_program_name) if (!symlink_program_name)
goto out; goto out;
r.name = real_program_name; rn.name = real_program_name;
tomoyo_fill_path_info(&r); tomoyo_fill_path_info(&rn);
s.name = symlink_program_name; sn.name = symlink_program_name;
tomoyo_fill_path_info(&s); tomoyo_fill_path_info(&sn);
l.name = tomoyo_get_last_name(old_domain); ln.name = tomoyo_get_last_name(old_domain);
tomoyo_fill_path_info(&l); tomoyo_fill_path_info(&ln);
/* Check 'alias' directive. */ /* Check 'alias' directive. */
if (tomoyo_pathcmp(&r, &s)) { if (tomoyo_pathcmp(&rn, &sn)) {
struct tomoyo_alias_entry *ptr; struct tomoyo_alias_entry *ptr;
/* Is this program allowed to be called via symbolic links? */ /* Is this program allowed to be called via symbolic links? */
list_for_each_entry_rcu(ptr, &tomoyo_alias_list, list) { list_for_each_entry_rcu(ptr, &tomoyo_alias_list, list) {
if (ptr->is_deleted || if (ptr->is_deleted ||
tomoyo_pathcmp(&r, ptr->original_name) || tomoyo_pathcmp(&rn, ptr->original_name) ||
tomoyo_pathcmp(&s, ptr->aliased_name)) tomoyo_pathcmp(&sn, ptr->aliased_name))
continue; continue;
memset(real_program_name, 0, TOMOYO_MAX_PATHNAME_LEN); memset(real_program_name, 0, TOMOYO_MAX_PATHNAME_LEN);
strncpy(real_program_name, ptr->aliased_name->name, strncpy(real_program_name, ptr->aliased_name->name,
TOMOYO_MAX_PATHNAME_LEN - 1); TOMOYO_MAX_PATHNAME_LEN - 1);
tomoyo_fill_path_info(&r); tomoyo_fill_path_info(&rn);
break; break;
} }
} }
/* Check execute permission. */ /* Check execute permission. */
retval = tomoyo_check_exec_perm(old_domain, &r); retval = tomoyo_check_exec_perm(old_domain, &rn);
if (retval == TOMOYO_RETRY_REQUEST)
goto retry;
if (retval < 0) if (retval < 0)
goto out; goto out;
new_domain_name = tmp->buffer; new_domain_name = tmp->buffer;
if (tomoyo_is_domain_initializer(old_domain->domainname, &r, &l)) { if (tomoyo_is_domain_initializer(old_domain->domainname, &rn, &ln)) {
/* Transit to the child of tomoyo_kernel_domain domain. */ /* Transit to the child of tomoyo_kernel_domain domain. */
snprintf(new_domain_name, TOMOYO_MAX_PATHNAME_LEN + 1, snprintf(new_domain_name, TOMOYO_MAX_PATHNAME_LEN + 1,
TOMOYO_ROOT_NAME " " "%s", real_program_name); TOMOYO_ROOT_NAME " " "%s", real_program_name);
...@@ -766,7 +771,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm) ...@@ -766,7 +771,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
* initializers because they might start before /sbin/init. * initializers because they might start before /sbin/init.
*/ */
domain = old_domain; domain = old_domain;
} else if (tomoyo_is_domain_keeper(old_domain->domainname, &r, &l)) { } else if (tomoyo_is_domain_keeper(old_domain->domainname, &rn, &ln)) {
/* Keep current domain. */ /* Keep current domain. */
domain = old_domain; domain = old_domain;
} else { } else {
...@@ -779,8 +784,14 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm) ...@@ -779,8 +784,14 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
domain = tomoyo_find_domain(new_domain_name); domain = tomoyo_find_domain(new_domain_name);
if (domain) if (domain)
goto done; goto done;
if (is_enforce) if (is_enforce) {
int error = tomoyo_supervisor(&r, "# wants to create domain\n"
"%s\n", new_domain_name);
if (error == TOMOYO_RETRY_REQUEST)
goto retry;
if (error < 0)
goto done; goto done;
}
domain = tomoyo_find_or_assign_new_domain(new_domain_name, domain = tomoyo_find_or_assign_new_domain(new_domain_name,
old_domain->profile); old_domain->profile);
done: done:
......
...@@ -478,7 +478,7 @@ static int tomoyo_update_file_pattern_entry(const char *pattern, ...@@ -478,7 +478,7 @@ static int tomoyo_update_file_pattern_entry(const char *pattern,
} }
/** /**
* tomoyo_get_file_pattern - Get patterned pathname. * tomoyo_file_pattern - Get patterned pathname.
* *
* @filename: The filename to find patterned pathname. * @filename: The filename to find patterned pathname.
* *
...@@ -486,8 +486,7 @@ static int tomoyo_update_file_pattern_entry(const char *pattern, ...@@ -486,8 +486,7 @@ static int tomoyo_update_file_pattern_entry(const char *pattern,
* *
* Caller holds tomoyo_read_lock(). * Caller holds tomoyo_read_lock().
*/ */
const struct tomoyo_path_info * const char *tomoyo_file_pattern(const struct tomoyo_path_info *filename)
tomoyo_get_file_pattern(const struct tomoyo_path_info *filename)
{ {
struct tomoyo_pattern_entry *ptr; struct tomoyo_pattern_entry *ptr;
const struct tomoyo_path_info *pattern = NULL; const struct tomoyo_path_info *pattern = NULL;
...@@ -507,7 +506,7 @@ tomoyo_get_file_pattern(const struct tomoyo_path_info *filename) ...@@ -507,7 +506,7 @@ tomoyo_get_file_pattern(const struct tomoyo_path_info *filename)
} }
if (pattern) if (pattern)
filename = pattern; filename = pattern;
return filename; return filename->name;
} }
/** /**
...@@ -812,23 +811,25 @@ static int tomoyo_file_perm(struct tomoyo_request_info *r, ...@@ -812,23 +811,25 @@ static int tomoyo_file_perm(struct tomoyo_request_info *r,
perm = 1 << TOMOYO_TYPE_EXECUTE; perm = 1 << TOMOYO_TYPE_EXECUTE;
} else } else
BUG(); BUG();
do {
error = tomoyo_path_acl(r, filename, perm, mode != 1); error = tomoyo_path_acl(r, filename, perm, mode != 1);
if (error && mode == 4 && !r->domain->ignore_global_allow_read if (error && mode == 4 && !r->domain->ignore_global_allow_read
&& tomoyo_is_globally_readable_file(filename)) && tomoyo_is_globally_readable_file(filename))
error = 0; error = 0;
if (!error) if (!error)
return 0; break;
tomoyo_warn_log(r, "%s %s", msg, filename->name); tomoyo_warn_log(r, "%s %s", msg, filename->name);
if (r->mode == TOMOYO_CONFIG_ENFORCING) error = tomoyo_supervisor(r, "allow_%s %s\n", msg,
mode == 1 ? filename->name :
tomoyo_file_pattern(filename));
/*
* Do not retry for execute request, for alias may have
* changed.
*/
} while (error == TOMOYO_RETRY_REQUEST && mode != 1);
if (r->mode != TOMOYO_CONFIG_ENFORCING)
error = 0;
return error; return error;
if (tomoyo_domain_quota_is_ok(r)) {
/* Don't use patterns for execute permission. */
const struct tomoyo_path_info *patterned_file = (mode != 1) ?
tomoyo_get_file_pattern(filename) : filename;
tomoyo_update_file_acl(mode, patterned_file->name, r->domain,
false);
}
return 0;
} }
/** /**
...@@ -1123,21 +1124,21 @@ static int tomoyo_path2_acl(const struct tomoyo_request_info *r, const u8 type, ...@@ -1123,21 +1124,21 @@ static int tomoyo_path2_acl(const struct tomoyo_request_info *r, const u8 type,
static int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, static int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
const struct tomoyo_path_info *filename) const struct tomoyo_path_info *filename)
{ {
const char *msg;
int error; int error;
next: next:
do {
error = tomoyo_path_acl(r, filename, 1 << operation, 1); error = tomoyo_path_acl(r, filename, 1 << operation, 1);
if (!error) if (!error)
goto ok; break;
tomoyo_warn_log(r, "%s %s", tomoyo_path2keyword(operation), msg = tomoyo_path2keyword(operation);
filename->name); tomoyo_warn_log(r, "%s %s", msg, filename->name);
if (tomoyo_domain_quota_is_ok(r)) { error = tomoyo_supervisor(r, "allow_%s %s\n", msg,
const char *name = tomoyo_get_file_pattern(filename)->name; tomoyo_file_pattern(filename));
tomoyo_update_path_acl(operation, name, r->domain, false); } while (error == TOMOYO_RETRY_REQUEST);
}
if (r->mode != TOMOYO_CONFIG_ENFORCING) if (r->mode != TOMOYO_CONFIG_ENFORCING)
error = 0; error = 0;
ok:
/* /*
* Since "allow_truncate" doesn't imply "allow_rewrite" permission, * Since "allow_truncate" doesn't imply "allow_rewrite" permission,
* we need to check "allow_rewrite" permission if the filename is * we need to check "allow_rewrite" permission if the filename is
...@@ -1267,6 +1268,7 @@ static int tomoyo_path_number_perm2(struct tomoyo_request_info *r, ...@@ -1267,6 +1268,7 @@ static int tomoyo_path_number_perm2(struct tomoyo_request_info *r,
char buffer[64]; char buffer[64];
int error; int error;
u8 radix; u8 radix;
const char *msg;
if (!filename) if (!filename)
return 0; return 0;
...@@ -1286,15 +1288,16 @@ static int tomoyo_path_number_perm2(struct tomoyo_request_info *r, ...@@ -1286,15 +1288,16 @@ static int tomoyo_path_number_perm2(struct tomoyo_request_info *r,
break; break;
} }
tomoyo_print_ulong(buffer, sizeof(buffer), number, radix); tomoyo_print_ulong(buffer, sizeof(buffer), number, radix);
do {
error = tomoyo_path_number_acl(r, type, filename, number); error = tomoyo_path_number_acl(r, type, filename, number);
if (!error) if (!error)
return 0; break;
tomoyo_warn_log(r, "%s %s %s", tomoyo_path_number2keyword(type), msg = tomoyo_path_number2keyword(type);
filename->name, buffer); tomoyo_warn_log(r, "%s %s %s", msg, filename->name, buffer);
if (tomoyo_domain_quota_is_ok(r)) error = tomoyo_supervisor(r, "allow_%s %s %s\n", msg,
tomoyo_update_path_number_acl(type, tomoyo_file_pattern(filename),
tomoyo_get_file_pattern(filename) buffer);
->name, buffer, r->domain, false); } while (error == TOMOYO_RETRY_REQUEST);
if (r->mode != TOMOYO_CONFIG_ENFORCING) if (r->mode != TOMOYO_CONFIG_ENFORCING)
error = 0; error = 0;
return error; return error;
...@@ -1484,31 +1487,22 @@ static int tomoyo_path_number3_perm2(struct tomoyo_request_info *r, ...@@ -1484,31 +1487,22 @@ static int tomoyo_path_number3_perm2(struct tomoyo_request_info *r,
const unsigned int dev) const unsigned int dev)
{ {
int error; int error;
const char *msg;
const unsigned int major = MAJOR(dev); const unsigned int major = MAJOR(dev);
const unsigned int minor = MINOR(dev); const unsigned int minor = MINOR(dev);
error = tomoyo_path_number3_acl(r, filename, 1 << operation, mode, do {
major, minor); error = tomoyo_path_number3_acl(r, filename, 1 << operation,
mode, major, minor);
if (!error) if (!error)
return 0; break;
tomoyo_warn_log(r, "%s %s 0%o %u %u", msg = tomoyo_path_number32keyword(operation);
tomoyo_path_number32keyword(operation), tomoyo_warn_log(r, "%s %s 0%o %u %u", msg, filename->name,
filename->name, mode, major, minor); mode, major, minor);
if (tomoyo_domain_quota_is_ok(r)) { error = tomoyo_supervisor(r, "allow_%s %s 0%o %u %u\n", msg,
char mode_buf[64]; tomoyo_file_pattern(filename), mode,
char major_buf[64]; major, minor);
char minor_buf[64]; } while (error == TOMOYO_RETRY_REQUEST);
memset(mode_buf, 0, sizeof(mode_buf));
memset(major_buf, 0, sizeof(major_buf));
memset(minor_buf, 0, sizeof(minor_buf));
snprintf(mode_buf, sizeof(mode_buf) - 1, "0%o", mode);
snprintf(major_buf, sizeof(major_buf) - 1, "%u", major);
snprintf(minor_buf, sizeof(minor_buf) - 1, "%u", minor);
tomoyo_update_path_number3_acl(operation,
tomoyo_get_file_pattern(filename)
->name, mode_buf, major_buf,
minor_buf, r->domain, false);
}
if (r->mode != TOMOYO_CONFIG_ENFORCING) if (r->mode != TOMOYO_CONFIG_ENFORCING)
error = 0; error = 0;
return error; return error;
...@@ -1562,6 +1556,7 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1, ...@@ -1562,6 +1556,7 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
struct path *path2) struct path *path2)
{ {
int error = -ENOMEM; int error = -ENOMEM;
const char *msg;
struct tomoyo_path_info *buf1; struct tomoyo_path_info *buf1;
struct tomoyo_path_info *buf2; struct tomoyo_path_info *buf2;
struct tomoyo_request_info r; struct tomoyo_request_info r;
...@@ -1591,17 +1586,16 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1, ...@@ -1591,17 +1586,16 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
} }
} }
} }
do {
error = tomoyo_path2_acl(&r, operation, buf1, buf2); error = tomoyo_path2_acl(&r, operation, buf1, buf2);
if (!error) if (!error)
goto out; break;
tomoyo_warn_log(&r, "%s %s %s", tomoyo_path22keyword(operation), msg = tomoyo_path22keyword(operation);
buf1->name, buf2->name); tomoyo_warn_log(&r, "%s %s %s", msg, buf1->name, buf2->name);
if (tomoyo_domain_quota_is_ok(&r)) { error = tomoyo_supervisor(&r, "allow_%s %s %s\n", msg,
const char *name1 = tomoyo_get_file_pattern(buf1)->name; tomoyo_file_pattern(buf1),
const char *name2 = tomoyo_get_file_pattern(buf2)->name; tomoyo_file_pattern(buf2));
tomoyo_update_path2_acl(operation, name1, name2, r.domain, } while (error == TOMOYO_RETRY_REQUEST);
false);
}
out: out:
kfree(buf1); kfree(buf1);
kfree(buf2); kfree(buf2);
......
...@@ -178,19 +178,12 @@ static int tomoyo_mount_acl2(struct tomoyo_request_info *r, char *dev_name, ...@@ -178,19 +178,12 @@ static int tomoyo_mount_acl2(struct tomoyo_request_info *r, char *dev_name,
error = 0; error = 0;
break; break;
} }
if (error) { if (error)
const char *dev = tomoyo_get_file_pattern(&rdev)->name; error = tomoyo_supervisor(r, TOMOYO_KEYWORD_ALLOW_MOUNT
const char *dir = tomoyo_get_file_pattern(&rdir)->name; "%s %s %s 0x%lX\n",
int len = strlen(dev) + strlen(dir) + strlen(requested_type) tomoyo_file_pattern(&rdev),
+ 64; tomoyo_file_pattern(&rdir),
char *buf = kzalloc(len, GFP_NOFS); requested_type, flags);
if (buf) {
snprintf(buf, len - 1, "%s %s %s 0x%lX",
dev, dir, requested_type, flags);
tomoyo_write_mount_policy(buf, r->domain, false);
kfree(buf);
}
}
out: out:
kfree(requested_dev_name); kfree(requested_dev_name);
kfree(requested_dir_name); kfree(requested_dir_name);
...@@ -279,7 +272,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name, ...@@ -279,7 +272,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name,
TOMOYO_MOUNT_MAKE_SHARED_KEYWORD, TOMOYO_MOUNT_MAKE_SHARED_KEYWORD,
flags & ~MS_SHARED); flags & ~MS_SHARED);
else else
error = tomoyo_mount_acl2(r, dev_name, dir, type, flags); do {
error = tomoyo_mount_acl2(r, dev_name, dir, type,
flags);
} while (error == TOMOYO_RETRY_REQUEST);
if (r->mode != TOMOYO_CONFIG_ENFORCING) if (r->mode != TOMOYO_CONFIG_ENFORCING)
error = 0; error = 0;
return error; return error;
......
...@@ -333,6 +333,9 @@ void __init tomoyo_realpath_init(void) ...@@ -333,6 +333,9 @@ void __init tomoyo_realpath_init(void)
panic("Can't register tomoyo_kernel_domain"); panic("Can't register tomoyo_kernel_domain");
} }
unsigned int tomoyo_quota_for_query;
unsigned int tomoyo_query_memory_size;
/** /**
* tomoyo_read_memory_counter - Check for memory usage in bytes. * tomoyo_read_memory_counter - Check for memory usage in bytes.
* *
...@@ -345,6 +348,7 @@ int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head) ...@@ -345,6 +348,7 @@ int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head)
if (!head->read_eof) { if (!head->read_eof) {
const unsigned int policy const unsigned int policy
= atomic_read(&tomoyo_policy_memory_size); = atomic_read(&tomoyo_policy_memory_size);
const unsigned int query = tomoyo_query_memory_size;
char buffer[64]; char buffer[64];
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
...@@ -354,8 +358,17 @@ int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head) ...@@ -354,8 +358,17 @@ int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head)
tomoyo_quota_for_policy); tomoyo_quota_for_policy);
else else
buffer[0] = '\0'; buffer[0] = '\0';
tomoyo_io_printf(head, "Policy: %10u%s\n", policy, buffer); tomoyo_io_printf(head, "Policy: %10u%s\n", policy,
tomoyo_io_printf(head, "Total: %10u\n", policy); buffer);
if (tomoyo_quota_for_query)
snprintf(buffer, sizeof(buffer) - 1,
" (Quota: %10u)",
tomoyo_quota_for_query);
else
buffer[0] = '\0';
tomoyo_io_printf(head, "Query lists: %10u%s\n", query,
buffer);
tomoyo_io_printf(head, "Total: %10u\n", policy + query);
head->read_eof = true; head->read_eof = true;
} }
return 0; return 0;
...@@ -375,5 +388,7 @@ int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head) ...@@ -375,5 +388,7 @@ int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head)
if (sscanf(data, "Policy: %u", &size) == 1) if (sscanf(data, "Policy: %u", &size) == 1)
tomoyo_quota_for_policy = size; tomoyo_quota_for_policy = size;
else if (sscanf(data, "Query lists: %u", &size) == 1)
tomoyo_quota_for_query = size;
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