提交 7c75964f 编写于 作者: T Tetsuo Handa 提交者: James Morris

TOMOYO: Cleanup part 1.

In order to synchronize with TOMOYO 1.8's syntax,

(1) Remove special handling for allow_read/write permission.
(2) Replace deny_rewrite/allow_rewrite permission with allow_append permission.
(3) Remove file_pattern keyword.
(4) Remove allow_read permission from exception policy.
(5) Allow creating domains in enforcing mode without calling supervisor.
(6) Add permission check for opening directory for reading.
(7) Add permission check for stat() operation.
(8) Make "cat < /sys/kernel/security/tomoyo/self_domain" behave as if
    "cat /sys/kernel/security/tomoyo/self_domain".
Signed-off-by: NTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: NJames Morris <jmorris@namei.org>
上级 1252cc3b
...@@ -39,13 +39,13 @@ static const char *tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX ...@@ -39,13 +39,13 @@ static const char *tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX
[TOMOYO_MAC_FILE_OPEN] = "file::open", [TOMOYO_MAC_FILE_OPEN] = "file::open",
[TOMOYO_MAC_FILE_CREATE] = "file::create", [TOMOYO_MAC_FILE_CREATE] = "file::create",
[TOMOYO_MAC_FILE_UNLINK] = "file::unlink", [TOMOYO_MAC_FILE_UNLINK] = "file::unlink",
[TOMOYO_MAC_FILE_GETATTR] = "file::getattr",
[TOMOYO_MAC_FILE_MKDIR] = "file::mkdir", [TOMOYO_MAC_FILE_MKDIR] = "file::mkdir",
[TOMOYO_MAC_FILE_RMDIR] = "file::rmdir", [TOMOYO_MAC_FILE_RMDIR] = "file::rmdir",
[TOMOYO_MAC_FILE_MKFIFO] = "file::mkfifo", [TOMOYO_MAC_FILE_MKFIFO] = "file::mkfifo",
[TOMOYO_MAC_FILE_MKSOCK] = "file::mksock", [TOMOYO_MAC_FILE_MKSOCK] = "file::mksock",
[TOMOYO_MAC_FILE_TRUNCATE] = "file::truncate", [TOMOYO_MAC_FILE_TRUNCATE] = "file::truncate",
[TOMOYO_MAC_FILE_SYMLINK] = "file::symlink", [TOMOYO_MAC_FILE_SYMLINK] = "file::symlink",
[TOMOYO_MAC_FILE_REWRITE] = "file::rewrite",
[TOMOYO_MAC_FILE_MKBLOCK] = "file::mkblock", [TOMOYO_MAC_FILE_MKBLOCK] = "file::mkblock",
[TOMOYO_MAC_FILE_MKCHAR] = "file::mkchar", [TOMOYO_MAC_FILE_MKCHAR] = "file::mkchar",
[TOMOYO_MAC_FILE_LINK] = "file::link", [TOMOYO_MAC_FILE_LINK] = "file::link",
...@@ -881,10 +881,6 @@ static int tomoyo_write_domain(struct tomoyo_io_buffer *head) ...@@ -881,10 +881,6 @@ static int tomoyo_write_domain(struct tomoyo_io_buffer *head)
domain->profile = (u8) profile; domain->profile = (u8) profile;
return 0; return 0;
} }
if (!strcmp(data, TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ)) {
domain->ignore_global_allow_read = !is_delete;
return 0;
}
if (!strcmp(data, TOMOYO_KEYWORD_QUOTA_EXCEEDED)) { if (!strcmp(data, TOMOYO_KEYWORD_QUOTA_EXCEEDED)) {
domain->quota_warned = !is_delete; domain->quota_warned = !is_delete;
return 0; return 0;
...@@ -942,11 +938,6 @@ static bool tomoyo_print_entry(struct tomoyo_io_buffer *head, ...@@ -942,11 +938,6 @@ static bool tomoyo_print_entry(struct tomoyo_io_buffer *head,
if (head->r.print_execute_only && if (head->r.print_execute_only &&
bit != TOMOYO_TYPE_EXECUTE) bit != TOMOYO_TYPE_EXECUTE)
continue; continue;
/* Print "read/write" instead of "read" and "write". */
if ((bit == TOMOYO_TYPE_READ ||
bit == TOMOYO_TYPE_WRITE)
&& (perm & (1 << TOMOYO_TYPE_READ_WRITE)))
continue;
break; break;
} }
if (bit >= TOMOYO_MAX_PATH_OPERATION) if (bit >= TOMOYO_MAX_PATH_OPERATION)
...@@ -1055,10 +1046,6 @@ static void tomoyo_read_domain(struct tomoyo_io_buffer *head) ...@@ -1055,10 +1046,6 @@ static void tomoyo_read_domain(struct tomoyo_io_buffer *head)
tomoyo_set_string(head, "quota_exceeded\n"); tomoyo_set_string(head, "quota_exceeded\n");
if (domain->transition_failed) if (domain->transition_failed)
tomoyo_set_string(head, "transition_failed\n"); tomoyo_set_string(head, "transition_failed\n");
if (domain->ignore_global_allow_read)
tomoyo_set_string(head,
TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ
"\n");
head->r.step++; head->r.step++;
tomoyo_set_lf(head); tomoyo_set_lf(head);
/* fall through */ /* fall through */
...@@ -1235,18 +1222,15 @@ static int tomoyo_write_exception(struct tomoyo_io_buffer *head) ...@@ -1235,18 +1222,15 @@ static int tomoyo_write_exception(struct tomoyo_io_buffer *head)
static const struct { static const struct {
const char *keyword; const char *keyword;
int (*write) (char *, const bool); int (*write) (char *, const bool);
} tomoyo_callback[4] = { } tomoyo_callback[1] = {
{ TOMOYO_KEYWORD_AGGREGATOR, tomoyo_write_aggregator }, { TOMOYO_KEYWORD_AGGREGATOR, tomoyo_write_aggregator },
{ TOMOYO_KEYWORD_FILE_PATTERN, tomoyo_write_pattern },
{ TOMOYO_KEYWORD_DENY_REWRITE, tomoyo_write_no_rewrite },
{ TOMOYO_KEYWORD_ALLOW_READ, tomoyo_write_globally_readable },
}; };
for (i = 0; i < TOMOYO_MAX_TRANSITION_TYPE; i++) for (i = 0; i < TOMOYO_MAX_TRANSITION_TYPE; i++)
if (tomoyo_str_starts(&data, tomoyo_transition_type[i])) if (tomoyo_str_starts(&data, tomoyo_transition_type[i]))
return tomoyo_write_transition_control(data, is_delete, return tomoyo_write_transition_control(data, is_delete,
i); i);
for (i = 0; i < 4; i++) for (i = 0; i < 1; i++)
if (tomoyo_str_starts(&data, tomoyo_callback[i].keyword)) if (tomoyo_str_starts(&data, tomoyo_callback[i].keyword))
return tomoyo_callback[i].write(data, is_delete); return tomoyo_callback[i].write(data, is_delete);
for (i = 0; i < TOMOYO_MAX_GROUP; i++) for (i = 0; i < TOMOYO_MAX_GROUP; i++)
...@@ -1336,15 +1320,6 @@ static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx) ...@@ -1336,15 +1320,6 @@ static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx)
name); name);
} }
break; break;
case TOMOYO_ID_GLOBALLY_READABLE:
{
struct tomoyo_readable_file *ptr =
container_of(acl, typeof(*ptr), head);
tomoyo_set_string(head,
TOMOYO_KEYWORD_ALLOW_READ);
tomoyo_set_string(head, ptr->filename->name);
}
break;
case TOMOYO_ID_AGGREGATOR: case TOMOYO_ID_AGGREGATOR:
{ {
struct tomoyo_aggregator *ptr = struct tomoyo_aggregator *ptr =
...@@ -1358,24 +1333,6 @@ static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx) ...@@ -1358,24 +1333,6 @@ static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx)
ptr->aggregated_name->name); ptr->aggregated_name->name);
} }
break; break;
case TOMOYO_ID_PATTERN:
{
struct tomoyo_no_pattern *ptr =
container_of(acl, typeof(*ptr), head);
tomoyo_set_string(head,
TOMOYO_KEYWORD_FILE_PATTERN);
tomoyo_set_string(head, ptr->pattern->name);
}
break;
case TOMOYO_ID_NO_REWRITE:
{
struct tomoyo_no_rewrite *ptr =
container_of(acl, typeof(*ptr), head);
tomoyo_set_string(head,
TOMOYO_KEYWORD_DENY_REWRITE);
tomoyo_set_string(head, ptr->pattern->name);
}
break;
default: default:
continue; continue;
} }
...@@ -1890,22 +1847,13 @@ int tomoyo_open_control(const u8 type, struct file *file) ...@@ -1890,22 +1847,13 @@ int tomoyo_open_control(const u8 type, struct file *file)
if (type != TOMOYO_QUERY) if (type != TOMOYO_QUERY)
head->reader_idx = tomoyo_read_lock(); head->reader_idx = tomoyo_read_lock();
file->private_data = head; file->private_data = head;
/*
* Call the handler now if the file is
* /sys/kernel/security/tomoyo/self_domain
* so that the user can use
* cat < /sys/kernel/security/tomoyo/self_domain"
* to know the current process's domainname.
*/
if (type == TOMOYO_SELFDOMAIN)
tomoyo_read_control(file, NULL, 0);
/* /*
* If the file is /sys/kernel/security/tomoyo/query , increment the * If the file is /sys/kernel/security/tomoyo/query , increment the
* observer counter. * observer counter.
* The obserber counter is used by tomoyo_supervisor() to see if * The obserber counter is used by tomoyo_supervisor() to see if
* there is some process monitoring /sys/kernel/security/tomoyo/query. * there is some process monitoring /sys/kernel/security/tomoyo/query.
*/ */
else if (type == TOMOYO_QUERY) if (type == TOMOYO_QUERY)
atomic_inc(&tomoyo_query_observers); atomic_inc(&tomoyo_query_observers);
return 0; return 0;
} }
......
...@@ -52,9 +52,6 @@ enum tomoyo_policy_id { ...@@ -52,9 +52,6 @@ enum tomoyo_policy_id {
TOMOYO_ID_NUMBER_GROUP, TOMOYO_ID_NUMBER_GROUP,
TOMOYO_ID_TRANSITION_CONTROL, TOMOYO_ID_TRANSITION_CONTROL,
TOMOYO_ID_AGGREGATOR, TOMOYO_ID_AGGREGATOR,
TOMOYO_ID_GLOBALLY_READABLE,
TOMOYO_ID_PATTERN,
TOMOYO_ID_NO_REWRITE,
TOMOYO_ID_MANAGER, TOMOYO_ID_MANAGER,
TOMOYO_ID_NAME, TOMOYO_ID_NAME,
TOMOYO_ID_ACL, TOMOYO_ID_ACL,
...@@ -73,8 +70,6 @@ enum tomoyo_group_id { ...@@ -73,8 +70,6 @@ enum tomoyo_group_id {
#define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount " #define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount "
#define TOMOYO_KEYWORD_ALLOW_READ "allow_read " #define TOMOYO_KEYWORD_ALLOW_READ "allow_read "
#define TOMOYO_KEYWORD_DELETE "delete " #define TOMOYO_KEYWORD_DELETE "delete "
#define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite "
#define TOMOYO_KEYWORD_FILE_PATTERN "file_pattern "
#define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain " #define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain "
#define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain " #define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain "
#define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain " #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain "
...@@ -83,7 +78,6 @@ enum tomoyo_group_id { ...@@ -83,7 +78,6 @@ enum tomoyo_group_id {
#define TOMOYO_KEYWORD_NUMBER_GROUP "number_group " #define TOMOYO_KEYWORD_NUMBER_GROUP "number_group "
#define TOMOYO_KEYWORD_SELECT "select " #define TOMOYO_KEYWORD_SELECT "select "
#define TOMOYO_KEYWORD_USE_PROFILE "use_profile " #define TOMOYO_KEYWORD_USE_PROFILE "use_profile "
#define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read"
#define TOMOYO_KEYWORD_QUOTA_EXCEEDED "quota_exceeded" #define TOMOYO_KEYWORD_QUOTA_EXCEEDED "quota_exceeded"
#define TOMOYO_KEYWORD_TRANSITION_FAILED "transition_failed" #define TOMOYO_KEYWORD_TRANSITION_FAILED "transition_failed"
/* A domain definition starts with <kernel>. */ /* A domain definition starts with <kernel>. */
...@@ -115,35 +109,21 @@ enum tomoyo_acl_entry_type_index { ...@@ -115,35 +109,21 @@ enum tomoyo_acl_entry_type_index {
}; };
/* Index numbers for File Controls. */ /* Index numbers for File Controls. */
/*
* TOMOYO_TYPE_READ_WRITE is special. TOMOYO_TYPE_READ_WRITE is automatically
* set if both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are set.
* Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically set if
* TOMOYO_TYPE_READ_WRITE is set.
* TOMOYO_TYPE_READ_WRITE is automatically cleared if either TOMOYO_TYPE_READ
* or TOMOYO_TYPE_WRITE is cleared.
* Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically cleared if
* TOMOYO_TYPE_READ_WRITE is cleared.
*/
enum tomoyo_path_acl_index { enum tomoyo_path_acl_index {
TOMOYO_TYPE_READ_WRITE,
TOMOYO_TYPE_EXECUTE, TOMOYO_TYPE_EXECUTE,
TOMOYO_TYPE_READ, TOMOYO_TYPE_READ,
TOMOYO_TYPE_WRITE, TOMOYO_TYPE_WRITE,
TOMOYO_TYPE_APPEND,
TOMOYO_TYPE_UNLINK, TOMOYO_TYPE_UNLINK,
TOMOYO_TYPE_GETATTR,
TOMOYO_TYPE_RMDIR, TOMOYO_TYPE_RMDIR,
TOMOYO_TYPE_TRUNCATE, TOMOYO_TYPE_TRUNCATE,
TOMOYO_TYPE_SYMLINK, TOMOYO_TYPE_SYMLINK,
TOMOYO_TYPE_REWRITE,
TOMOYO_TYPE_CHROOT, TOMOYO_TYPE_CHROOT,
TOMOYO_TYPE_UMOUNT, TOMOYO_TYPE_UMOUNT,
TOMOYO_MAX_PATH_OPERATION TOMOYO_MAX_PATH_OPERATION
}; };
#define TOMOYO_RW_MASK ((1 << TOMOYO_TYPE_READ) | (1 << TOMOYO_TYPE_WRITE))
enum tomoyo_mkdev_acl_index { enum tomoyo_mkdev_acl_index {
TOMOYO_TYPE_MKBLOCK, TOMOYO_TYPE_MKBLOCK,
TOMOYO_TYPE_MKCHAR, TOMOYO_TYPE_MKCHAR,
...@@ -187,13 +167,13 @@ enum tomoyo_mac_index { ...@@ -187,13 +167,13 @@ enum tomoyo_mac_index {
TOMOYO_MAC_FILE_OPEN, TOMOYO_MAC_FILE_OPEN,
TOMOYO_MAC_FILE_CREATE, TOMOYO_MAC_FILE_CREATE,
TOMOYO_MAC_FILE_UNLINK, TOMOYO_MAC_FILE_UNLINK,
TOMOYO_MAC_FILE_GETATTR,
TOMOYO_MAC_FILE_MKDIR, TOMOYO_MAC_FILE_MKDIR,
TOMOYO_MAC_FILE_RMDIR, TOMOYO_MAC_FILE_RMDIR,
TOMOYO_MAC_FILE_MKFIFO, TOMOYO_MAC_FILE_MKFIFO,
TOMOYO_MAC_FILE_MKSOCK, TOMOYO_MAC_FILE_MKSOCK,
TOMOYO_MAC_FILE_TRUNCATE, TOMOYO_MAC_FILE_TRUNCATE,
TOMOYO_MAC_FILE_SYMLINK, TOMOYO_MAC_FILE_SYMLINK,
TOMOYO_MAC_FILE_REWRITE,
TOMOYO_MAC_FILE_MKBLOCK, TOMOYO_MAC_FILE_MKBLOCK,
TOMOYO_MAC_FILE_MKCHAR, TOMOYO_MAC_FILE_MKCHAR,
TOMOYO_MAC_FILE_LINK, TOMOYO_MAC_FILE_LINK,
...@@ -388,9 +368,7 @@ struct tomoyo_acl_info { ...@@ -388,9 +368,7 @@ struct tomoyo_acl_info {
* "deleted", false otherwise. * "deleted", false otherwise.
* (6) "quota_warned" is a bool which is used for suppressing warning message * (6) "quota_warned" is a bool which is used for suppressing warning message
* when learning mode learned too much entries. * when learning mode learned too much entries.
* (7) "ignore_global_allow_read" is a bool which is true if this domain * (7) "transition_failed" is a bool which is set to true when this domain was
* should ignore "allow_read" directive in exception policy.
* (8) "transition_failed" is a bool which is set to true when this domain was
* unable to create a new domain at tomoyo_find_next_domain() because the * unable to create a new domain at tomoyo_find_next_domain() because the
* name of the domain to be created was too long or it could not allocate * name of the domain to be created was too long or it could not allocate
* memory. If set to true, more than one process continued execve() * memory. If set to true, more than one process continued execve()
...@@ -415,7 +393,6 @@ struct tomoyo_domain_info { ...@@ -415,7 +393,6 @@ struct tomoyo_domain_info {
u8 profile; /* Profile number to use. */ u8 profile; /* Profile number to use. */
bool is_deleted; /* Delete flag. */ bool is_deleted; /* Delete flag. */
bool quota_warned; /* Quota warnning flag. */ bool quota_warned; /* Quota warnning flag. */
bool ignore_global_allow_read; /* Ignore "allow_read" flag. */
bool transition_failed; /* Domain transition failed flag. */ bool transition_failed; /* Domain transition failed flag. */
atomic_t users; /* Number of referring credentials. */ atomic_t users; /* Number of referring credentials. */
}; };
...@@ -429,10 +406,9 @@ struct tomoyo_domain_info { ...@@ -429,10 +406,9 @@ struct tomoyo_domain_info {
* (2) "perm" which is a bitmask of permitted operations. * (2) "perm" which is a bitmask of permitted operations.
* (3) "name" is the pathname. * (3) "name" is the pathname.
* *
* Directives held by this structure are "allow_read/write", "allow_execute", * Directives held by this structure are "allow_execute", "allow_read",
* "allow_read", "allow_write", "allow_unlink", "allow_rmdir", * "allow_write", "allow_append", "allow_unlink", "allow_rmdir",
* "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot" and * "allow_truncate", "allow_symlink", "allow_chroot" and "allow_unmount".
* "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 */
...@@ -573,47 +549,6 @@ struct tomoyo_io_buffer { ...@@ -573,47 +549,6 @@ struct tomoyo_io_buffer {
u8 type; u8 type;
}; };
/*
* tomoyo_readable_file is a structure which is used for holding
* "allow_read" entries.
* It has following fields.
*
* (1) "head" is "struct tomoyo_acl_head".
* (2) "filename" is a pathname which is allowed to open(O_RDONLY).
*/
struct tomoyo_readable_file {
struct tomoyo_acl_head head;
const struct tomoyo_path_info *filename;
};
/*
* tomoyo_no_pattern is a structure which is used for holding
* "file_pattern" entries.
* It has following fields.
*
* (1) "head" is "struct tomoyo_acl_head".
* (2) "pattern" is a pathname pattern which is used for converting pathnames
* to pathname patterns during learning mode.
*/
struct tomoyo_no_pattern {
struct tomoyo_acl_head head;
const struct tomoyo_path_info *pattern;
};
/*
* tomoyo_no_rewrite is a structure which is used for holding
* "deny_rewrite" entries.
* It has following fields.
*
* (1) "head" is "struct tomoyo_acl_head".
* (2) "pattern" is a pathname which is by default not permitted to modify
* already existing content.
*/
struct tomoyo_no_rewrite {
struct tomoyo_acl_head head;
const struct tomoyo_path_info *pattern;
};
/* /*
* tomoyo_transition_control is a structure which is used for holding * tomoyo_transition_control is a structure which is used for holding
* "initialize_domain"/"no_initialize_domain"/"keep_domain"/"no_keep_domain" * "initialize_domain"/"no_initialize_domain"/"keep_domain"/"no_keep_domain"
...@@ -764,23 +699,17 @@ int tomoyo_write_aggregator(char *data, const bool is_delete); ...@@ -764,23 +699,17 @@ int tomoyo_write_aggregator(char *data, const bool is_delete);
int tomoyo_write_transition_control(char *data, const bool is_delete, int tomoyo_write_transition_control(char *data, const bool is_delete,
const u8 type); const u8 type);
/* /*
* Create "allow_read/write", "allow_execute", "allow_read", "allow_write", * Create "allow_execute", "allow_read", "allow_write", "allow_append",
* "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir", * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir",
* "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar", * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar",
* "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and * "allow_truncate", "allow_symlink", "allow_rename" and "allow_link" entry
* "allow_link" entry in domain policy. * in domain policy.
*/ */
int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain, int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain,
const bool is_delete); const bool is_delete);
/* Create "allow_read" entry in exception policy. */
int tomoyo_write_globally_readable(char *data, const bool is_delete);
/* Create "allow_mount" entry in domain policy. */ /* Create "allow_mount" entry in domain policy. */
int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain, int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain,
const bool is_delete); const bool is_delete);
/* Create "deny_rewrite" entry in exception policy. */
int tomoyo_write_no_rewrite(char *data, const bool is_delete);
/* Create "file_pattern" entry in exception policy. */
int tomoyo_write_pattern(char *data, const bool is_delete);
/* Create "path_group"/"number_group" entry in exception policy. */ /* Create "path_group"/"number_group" entry in exception policy. */
int tomoyo_write_group(char *data, const bool is_delete, const u8 type); int tomoyo_write_group(char *data, const bool is_delete, const u8 type);
int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
...@@ -819,8 +748,6 @@ char *tomoyo_realpath_nofollow(const char *pathname); ...@@ -819,8 +748,6 @@ char *tomoyo_realpath_nofollow(const char *pathname);
* ignores chroot'ed root and the pathname is already solved. * ignores chroot'ed root and 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_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);
......
...@@ -510,16 +510,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm) ...@@ -510,16 +510,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
if (domain || strlen(tmp) >= TOMOYO_EXEC_TMPSIZE - 10) if (domain || strlen(tmp) >= TOMOYO_EXEC_TMPSIZE - 10)
goto done; goto done;
domain = tomoyo_find_domain(tmp); domain = tomoyo_find_domain(tmp);
if (domain) if (!domain)
goto done;
if (is_enforce) {
int error = tomoyo_supervisor(&r, "# wants to create domain\n"
"%s\n", tmp);
if (error == TOMOYO_RETRY_REQUEST)
goto retry;
if (error < 0)
goto done;
}
domain = tomoyo_assign_domain(tmp, old_domain->profile); domain = tomoyo_assign_domain(tmp, old_domain->profile);
done: done:
if (domain) if (domain)
......
...@@ -11,15 +11,15 @@ ...@@ -11,15 +11,15 @@
/* Keyword array for operations with one pathname. */ /* Keyword array for operations with one pathname. */
const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION] = { const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION] = {
[TOMOYO_TYPE_READ_WRITE] = "read/write",
[TOMOYO_TYPE_EXECUTE] = "execute", [TOMOYO_TYPE_EXECUTE] = "execute",
[TOMOYO_TYPE_READ] = "read", [TOMOYO_TYPE_READ] = "read",
[TOMOYO_TYPE_WRITE] = "write", [TOMOYO_TYPE_WRITE] = "write",
[TOMOYO_TYPE_APPEND] = "append",
[TOMOYO_TYPE_UNLINK] = "unlink", [TOMOYO_TYPE_UNLINK] = "unlink",
[TOMOYO_TYPE_GETATTR] = "getattr",
[TOMOYO_TYPE_RMDIR] = "rmdir", [TOMOYO_TYPE_RMDIR] = "rmdir",
[TOMOYO_TYPE_TRUNCATE] = "truncate", [TOMOYO_TYPE_TRUNCATE] = "truncate",
[TOMOYO_TYPE_SYMLINK] = "symlink", [TOMOYO_TYPE_SYMLINK] = "symlink",
[TOMOYO_TYPE_REWRITE] = "rewrite",
[TOMOYO_TYPE_CHROOT] = "chroot", [TOMOYO_TYPE_CHROOT] = "chroot",
[TOMOYO_TYPE_UMOUNT] = "unmount", [TOMOYO_TYPE_UMOUNT] = "unmount",
}; };
...@@ -50,15 +50,15 @@ const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION] = { ...@@ -50,15 +50,15 @@ const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION] = {
}; };
static const u8 tomoyo_p2mac[TOMOYO_MAX_PATH_OPERATION] = { static const u8 tomoyo_p2mac[TOMOYO_MAX_PATH_OPERATION] = {
[TOMOYO_TYPE_READ_WRITE] = TOMOYO_MAC_FILE_OPEN,
[TOMOYO_TYPE_EXECUTE] = TOMOYO_MAC_FILE_EXECUTE, [TOMOYO_TYPE_EXECUTE] = TOMOYO_MAC_FILE_EXECUTE,
[TOMOYO_TYPE_READ] = TOMOYO_MAC_FILE_OPEN, [TOMOYO_TYPE_READ] = TOMOYO_MAC_FILE_OPEN,
[TOMOYO_TYPE_WRITE] = TOMOYO_MAC_FILE_OPEN, [TOMOYO_TYPE_WRITE] = TOMOYO_MAC_FILE_OPEN,
[TOMOYO_TYPE_APPEND] = TOMOYO_MAC_FILE_OPEN,
[TOMOYO_TYPE_UNLINK] = TOMOYO_MAC_FILE_UNLINK, [TOMOYO_TYPE_UNLINK] = TOMOYO_MAC_FILE_UNLINK,
[TOMOYO_TYPE_GETATTR] = TOMOYO_MAC_FILE_GETATTR,
[TOMOYO_TYPE_RMDIR] = TOMOYO_MAC_FILE_RMDIR, [TOMOYO_TYPE_RMDIR] = TOMOYO_MAC_FILE_RMDIR,
[TOMOYO_TYPE_TRUNCATE] = TOMOYO_MAC_FILE_TRUNCATE, [TOMOYO_TYPE_TRUNCATE] = TOMOYO_MAC_FILE_TRUNCATE,
[TOMOYO_TYPE_SYMLINK] = TOMOYO_MAC_FILE_SYMLINK, [TOMOYO_TYPE_SYMLINK] = TOMOYO_MAC_FILE_SYMLINK,
[TOMOYO_TYPE_REWRITE] = TOMOYO_MAC_FILE_REWRITE,
[TOMOYO_TYPE_CHROOT] = TOMOYO_MAC_FILE_CHROOT, [TOMOYO_TYPE_CHROOT] = TOMOYO_MAC_FILE_CHROOT,
[TOMOYO_TYPE_UMOUNT] = TOMOYO_MAC_FILE_UMOUNT, [TOMOYO_TYPE_UMOUNT] = TOMOYO_MAC_FILE_UMOUNT,
}; };
...@@ -131,24 +131,6 @@ static void tomoyo_add_slash(struct tomoyo_path_info *buf) ...@@ -131,24 +131,6 @@ static void tomoyo_add_slash(struct tomoyo_path_info *buf)
tomoyo_fill_path_info(buf); tomoyo_fill_path_info(buf);
} }
/**
* tomoyo_strendswith - Check whether the token ends with the given token.
*
* @name: The token to check.
* @tail: The token to find.
*
* Returns true if @name ends with @tail, false otherwise.
*/
static bool tomoyo_strendswith(const char *name, const char *tail)
{
int len;
if (!name || !tail)
return false;
len = strlen(name) - strlen(tail);
return len >= 0 && !strcmp(name + len, tail);
}
/** /**
* tomoyo_get_realpath - Get realpath. * tomoyo_get_realpath - Get realpath.
* *
...@@ -182,7 +164,7 @@ static int tomoyo_audit_path_log(struct tomoyo_request_info *r) ...@@ -182,7 +164,7 @@ static int tomoyo_audit_path_log(struct tomoyo_request_info *r)
return 0; return 0;
tomoyo_warn_log(r, "%s %s", operation, filename->name); tomoyo_warn_log(r, "%s %s", operation, filename->name);
return tomoyo_supervisor(r, "allow_%s %s\n", operation, return tomoyo_supervisor(r, "allow_%s %s\n", operation,
tomoyo_pattern(filename)); filename->name);
} }
/** /**
...@@ -202,8 +184,7 @@ static int tomoyo_audit_path2_log(struct tomoyo_request_info *r) ...@@ -202,8 +184,7 @@ static int tomoyo_audit_path2_log(struct tomoyo_request_info *r)
tomoyo_warn_log(r, "%s %s %s", operation, filename1->name, tomoyo_warn_log(r, "%s %s %s", operation, filename1->name,
filename2->name); filename2->name);
return tomoyo_supervisor(r, "allow_%s %s %s\n", operation, return tomoyo_supervisor(r, "allow_%s %s %s\n", operation,
tomoyo_pattern(filename1), filename1->name, filename2->name);
tomoyo_pattern(filename2));
} }
/** /**
...@@ -225,7 +206,7 @@ static int tomoyo_audit_mkdev_log(struct tomoyo_request_info *r) ...@@ -225,7 +206,7 @@ static int tomoyo_audit_mkdev_log(struct tomoyo_request_info *r)
tomoyo_warn_log(r, "%s %s 0%o %u %u", operation, filename->name, mode, tomoyo_warn_log(r, "%s %s 0%o %u %u", operation, filename->name, mode,
major, minor); major, minor);
return tomoyo_supervisor(r, "allow_%s %s 0%o %u %u\n", operation, return tomoyo_supervisor(r, "allow_%s %s 0%o %u %u\n", operation,
tomoyo_pattern(filename), mode, major, minor); filename->name, mode, major, minor);
} }
/** /**
...@@ -264,247 +245,7 @@ static int tomoyo_audit_path_number_log(struct tomoyo_request_info *r) ...@@ -264,247 +245,7 @@ static int tomoyo_audit_path_number_log(struct tomoyo_request_info *r)
radix); radix);
tomoyo_warn_log(r, "%s %s %s", operation, filename->name, buffer); tomoyo_warn_log(r, "%s %s %s", operation, filename->name, buffer);
return tomoyo_supervisor(r, "allow_%s %s %s\n", operation, return tomoyo_supervisor(r, "allow_%s %s %s\n", operation,
tomoyo_pattern(filename), buffer); filename->name, buffer);
}
static bool tomoyo_same_globally_readable(const struct tomoyo_acl_head *a,
const struct tomoyo_acl_head *b)
{
return container_of(a, struct tomoyo_readable_file,
head)->filename ==
container_of(b, struct tomoyo_readable_file,
head)->filename;
}
/**
* tomoyo_update_globally_readable_entry - Update "struct tomoyo_readable_file" list.
*
* @filename: Filename unconditionally permitted to open() for reading.
* @is_delete: True if it is a delete request.
*
* Returns 0 on success, negative value otherwise.
*
* Caller holds tomoyo_read_lock().
*/
static int tomoyo_update_globally_readable_entry(const char *filename,
const bool is_delete)
{
struct tomoyo_readable_file e = { };
int error;
if (!tomoyo_correct_word(filename))
return -EINVAL;
e.filename = tomoyo_get_name(filename);
if (!e.filename)
return -ENOMEM;
error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
&tomoyo_policy_list
[TOMOYO_ID_GLOBALLY_READABLE],
tomoyo_same_globally_readable);
tomoyo_put_name(e.filename);
return error;
}
/**
* tomoyo_globally_readable_file - Check if the file is unconditionnaly permitted to be open()ed for reading.
*
* @filename: The filename to check.
*
* Returns true if any domain can open @filename for reading, false otherwise.
*
* Caller holds tomoyo_read_lock().
*/
static bool tomoyo_globally_readable_file(const struct tomoyo_path_info *
filename)
{
struct tomoyo_readable_file *ptr;
bool found = false;
list_for_each_entry_rcu(ptr, &tomoyo_policy_list
[TOMOYO_ID_GLOBALLY_READABLE], head.list) {
if (!ptr->head.is_deleted &&
tomoyo_path_matches_pattern(filename, ptr->filename)) {
found = true;
break;
}
}
return found;
}
/**
* tomoyo_write_globally_readable - Write "struct tomoyo_readable_file" list.
*
* @data: String to parse.
* @is_delete: True if it is a delete request.
*
* Returns 0 on success, negative value otherwise.
*
* Caller holds tomoyo_read_lock().
*/
int tomoyo_write_globally_readable(char *data, const bool is_delete)
{
return tomoyo_update_globally_readable_entry(data, is_delete);
}
static bool tomoyo_same_pattern(const struct tomoyo_acl_head *a,
const struct tomoyo_acl_head *b)
{
return container_of(a, struct tomoyo_no_pattern, head)->pattern ==
container_of(b, struct tomoyo_no_pattern, head)->pattern;
}
/**
* tomoyo_update_file_pattern_entry - Update "struct tomoyo_no_pattern" list.
*
* @pattern: Pathname pattern.
* @is_delete: True if it is a delete request.
*
* Returns 0 on success, negative value otherwise.
*
* Caller holds tomoyo_read_lock().
*/
static int tomoyo_update_file_pattern_entry(const char *pattern,
const bool is_delete)
{
struct tomoyo_no_pattern e = { };
int error;
if (!tomoyo_correct_word(pattern))
return -EINVAL;
e.pattern = tomoyo_get_name(pattern);
if (!e.pattern)
return -ENOMEM;
error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
&tomoyo_policy_list[TOMOYO_ID_PATTERN],
tomoyo_same_pattern);
tomoyo_put_name(e.pattern);
return error;
}
/**
* tomoyo_pattern - Get patterned pathname.
*
* @filename: The filename to find patterned pathname.
*
* Returns pointer to pathname pattern if matched, @filename otherwise.
*
* Caller holds tomoyo_read_lock().
*/
const char *tomoyo_pattern(const struct tomoyo_path_info *filename)
{
struct tomoyo_no_pattern *ptr;
const struct tomoyo_path_info *pattern = NULL;
list_for_each_entry_rcu(ptr, &tomoyo_policy_list[TOMOYO_ID_PATTERN],
head.list) {
if (ptr->head.is_deleted)
continue;
if (!tomoyo_path_matches_pattern(filename, ptr->pattern))
continue;
pattern = ptr->pattern;
if (tomoyo_strendswith(pattern->name, "/\\*")) {
/* Do nothing. Try to find the better match. */
} else {
/* This would be the better match. Use this. */
break;
}
}
if (pattern)
filename = pattern;
return filename->name;
}
/**
* tomoyo_write_pattern - Write "struct tomoyo_no_pattern" list.
*
* @data: String to parse.
* @is_delete: True if it is a delete request.
*
* Returns 0 on success, negative value otherwise.
*
* Caller holds tomoyo_read_lock().
*/
int tomoyo_write_pattern(char *data, const bool is_delete)
{
return tomoyo_update_file_pattern_entry(data, is_delete);
}
static bool tomoyo_same_no_rewrite(const struct tomoyo_acl_head *a,
const struct tomoyo_acl_head *b)
{
return container_of(a, struct tomoyo_no_rewrite, head)->pattern
== container_of(b, struct tomoyo_no_rewrite, head)
->pattern;
}
/**
* tomoyo_update_no_rewrite_entry - Update "struct tomoyo_no_rewrite" list.
*
* @pattern: Pathname pattern that are not rewritable by default.
* @is_delete: True if it is a delete request.
*
* Returns 0 on success, negative value otherwise.
*
* Caller holds tomoyo_read_lock().
*/
static int tomoyo_update_no_rewrite_entry(const char *pattern,
const bool is_delete)
{
struct tomoyo_no_rewrite e = { };
int error;
if (!tomoyo_correct_word(pattern))
return -EINVAL;
e.pattern = tomoyo_get_name(pattern);
if (!e.pattern)
return -ENOMEM;
error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
&tomoyo_policy_list[TOMOYO_ID_NO_REWRITE],
tomoyo_same_no_rewrite);
tomoyo_put_name(e.pattern);
return error;
}
/**
* tomoyo_no_rewrite_file - Check if the given pathname is not permitted to be rewrited.
*
* @filename: Filename to check.
*
* Returns true if @filename is specified by "deny_rewrite" directive,
* false otherwise.
*
* Caller holds tomoyo_read_lock().
*/
static bool tomoyo_no_rewrite_file(const struct tomoyo_path_info *filename)
{
struct tomoyo_no_rewrite *ptr;
bool found = false;
list_for_each_entry_rcu(ptr, &tomoyo_policy_list[TOMOYO_ID_NO_REWRITE],
head.list) {
if (ptr->head.is_deleted)
continue;
if (!tomoyo_path_matches_pattern(filename, ptr->pattern))
continue;
found = true;
break;
}
return found;
}
/**
* tomoyo_write_no_rewrite - Write "struct tomoyo_no_rewrite" list.
*
* @data: String to parse.
* @is_delete: True if it is a delete request.
*
* Returns 0 on success, negative value otherwise.
*
* Caller holds tomoyo_read_lock().
*/
int tomoyo_write_no_rewrite(char *data, const bool is_delete)
{
return tomoyo_update_no_rewrite_entry(data, is_delete);
} }
static bool tomoyo_check_path_acl(struct tomoyo_request_info *r, static bool tomoyo_check_path_acl(struct tomoyo_request_info *r,
...@@ -569,6 +310,15 @@ static bool tomoyo_same_path_acl(const struct tomoyo_acl_info *a, ...@@ -569,6 +310,15 @@ static bool tomoyo_same_path_acl(const struct tomoyo_acl_info *a,
tomoyo_same_name_union(&p1->name, &p2->name); tomoyo_same_name_union(&p1->name, &p2->name);
} }
/**
* tomoyo_merge_path_acl - Merge duplicated "struct tomoyo_path_acl" entry.
*
* @a: Pointer to "struct tomoyo_acl_info".
* @b: Pointer to "struct tomoyo_acl_info".
* @is_delete: True for @a &= ~@b, false for @a |= @b.
*
* Returns true if @a is empty, false otherwise.
*/
static bool tomoyo_merge_path_acl(struct tomoyo_acl_info *a, static bool tomoyo_merge_path_acl(struct tomoyo_acl_info *a,
struct tomoyo_acl_info *b, struct tomoyo_acl_info *b,
const bool is_delete) const bool is_delete)
...@@ -577,19 +327,10 @@ static bool tomoyo_merge_path_acl(struct tomoyo_acl_info *a, ...@@ -577,19 +327,10 @@ static bool tomoyo_merge_path_acl(struct tomoyo_acl_info *a,
->perm; ->perm;
u16 perm = *a_perm; u16 perm = *a_perm;
const u16 b_perm = container_of(b, struct tomoyo_path_acl, head)->perm; const u16 b_perm = container_of(b, struct tomoyo_path_acl, head)->perm;
if (is_delete) { if (is_delete)
perm &= ~b_perm; perm &= ~b_perm;
if ((perm & TOMOYO_RW_MASK) != TOMOYO_RW_MASK) else
perm &= ~(1 << TOMOYO_TYPE_READ_WRITE);
else if (!(perm & (1 << TOMOYO_TYPE_READ_WRITE)))
perm &= ~TOMOYO_RW_MASK;
} else {
perm |= b_perm; perm |= b_perm;
if ((perm & TOMOYO_RW_MASK) == TOMOYO_RW_MASK)
perm |= (1 << TOMOYO_TYPE_READ_WRITE);
else if (perm & (1 << TOMOYO_TYPE_READ_WRITE))
perm |= TOMOYO_RW_MASK;
}
*a_perm = perm; *a_perm = perm;
return !perm; return !perm;
} }
...@@ -615,8 +356,6 @@ static int tomoyo_update_path_acl(const u8 type, const char *filename, ...@@ -615,8 +356,6 @@ static int tomoyo_update_path_acl(const u8 type, const char *filename,
.perm = 1 << type .perm = 1 << type
}; };
int error; int error;
if (e.perm == (1 << TOMOYO_TYPE_READ_WRITE))
e.perm |= TOMOYO_RW_MASK;
if (!tomoyo_parse_name_union(filename, &e.name)) if (!tomoyo_parse_name_union(filename, &e.name))
return -EINVAL; return -EINVAL;
error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
...@@ -775,7 +514,6 @@ int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, ...@@ -775,7 +514,6 @@ int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
{ {
int error; int error;
next:
r->type = tomoyo_p2mac[operation]; r->type = tomoyo_p2mac[operation];
r->mode = tomoyo_get_mode(r->profile, r->type); r->mode = tomoyo_get_mode(r->profile, r->type);
if (r->mode == TOMOYO_CONFIG_DISABLED) if (r->mode == TOMOYO_CONFIG_DISABLED)
...@@ -785,10 +523,6 @@ int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, ...@@ -785,10 +523,6 @@ int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
r->param.path.operation = operation; r->param.path.operation = operation;
do { do {
tomoyo_check_acl(r, tomoyo_check_path_acl); tomoyo_check_acl(r, tomoyo_check_path_acl);
if (!r->granted && operation == TOMOYO_TYPE_READ &&
!r->domain->ignore_global_allow_read &&
tomoyo_globally_readable_file(filename))
r->granted = true;
error = tomoyo_audit_path_log(r); error = tomoyo_audit_path_log(r);
/* /*
* Do not retry for execute request, for alias may have * Do not retry for execute request, for alias may have
...@@ -796,16 +530,6 @@ int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, ...@@ -796,16 +530,6 @@ int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
*/ */
} while (error == TOMOYO_RETRY_REQUEST && } while (error == TOMOYO_RETRY_REQUEST &&
operation != TOMOYO_TYPE_EXECUTE); operation != TOMOYO_TYPE_EXECUTE);
/*
* Since "allow_truncate" doesn't imply "allow_rewrite" permission,
* we need to check "allow_rewrite" permission if the filename is
* specified by "deny_rewrite" keyword.
*/
if (!error && operation == TOMOYO_TYPE_TRUNCATE &&
tomoyo_no_rewrite_file(filename)) {
operation = TOMOYO_TYPE_REWRITE;
goto next;
}
return error; return error;
} }
...@@ -932,43 +656,26 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, ...@@ -932,43 +656,26 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
struct tomoyo_request_info r; struct tomoyo_request_info r;
int idx; int idx;
if (!path->mnt || if (!path->mnt)
(path->dentry->d_inode && S_ISDIR(path->dentry->d_inode->i_mode)))
return 0; return 0;
buf.name = NULL; buf.name = NULL;
r.mode = TOMOYO_CONFIG_DISABLED; r.mode = TOMOYO_CONFIG_DISABLED;
idx = tomoyo_read_lock(); idx = tomoyo_read_lock();
/* if (acc_mode &&
* If the filename is specified by "deny_rewrite" keyword, tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_OPEN)
* we need to check "allow_rewrite" permission when the filename is not
* opened for append mode or the filename is truncated at open time.
*/
if ((acc_mode & MAY_WRITE) && !(flag & O_APPEND)
&& tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_REWRITE)
!= TOMOYO_CONFIG_DISABLED) { != TOMOYO_CONFIG_DISABLED) {
if (!tomoyo_get_realpath(&buf, path)) { if (!tomoyo_get_realpath(&buf, path)) {
error = -ENOMEM; error = -ENOMEM;
goto out; goto out;
} }
if (tomoyo_no_rewrite_file(&buf)) if (acc_mode & MAY_READ)
error = tomoyo_path_permission(&r, TOMOYO_TYPE_REWRITE, error = tomoyo_path_permission(&r, TOMOYO_TYPE_READ,
&buf);
if (!error && (acc_mode & MAY_WRITE))
error = tomoyo_path_permission(&r, (flag & O_APPEND) ?
TOMOYO_TYPE_APPEND :
TOMOYO_TYPE_WRITE,
&buf); &buf);
}
if (!error && acc_mode &&
tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_OPEN)
!= TOMOYO_CONFIG_DISABLED) {
u8 operation;
if (!buf.name && !tomoyo_get_realpath(&buf, path)) {
error = -ENOMEM;
goto out;
}
if (acc_mode == (MAY_READ | MAY_WRITE))
operation = TOMOYO_TYPE_READ_WRITE;
else if (acc_mode == MAY_READ)
operation = TOMOYO_TYPE_READ;
else
operation = TOMOYO_TYPE_WRITE;
error = tomoyo_path_permission(&r, operation, &buf);
} }
out: out:
kfree(buf.name); kfree(buf.name);
...@@ -979,7 +686,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, ...@@ -979,7 +686,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
} }
/** /**
* tomoyo_path_perm - Check permission for "unlink", "rmdir", "truncate", "symlink", "rewrite", "chroot" and "unmount". * tomoyo_path_perm - Check permission for "unlink", "rmdir", "truncate", "symlink", "append", "chroot" and "unmount".
* *
* @operation: Type of operation. * @operation: Type of operation.
* @path: Pointer to "struct path". * @path: Pointer to "struct path".
...@@ -988,9 +695,10 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, ...@@ -988,9 +695,10 @@ 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 error = -ENOMEM;
struct tomoyo_path_info buf;
struct tomoyo_request_info r; struct tomoyo_request_info r;
int error;
struct tomoyo_path_info buf;
bool is_enforce;
int idx; int idx;
if (!path->mnt) if (!path->mnt)
...@@ -998,17 +706,13 @@ int tomoyo_path_perm(const u8 operation, struct path *path) ...@@ -998,17 +706,13 @@ int tomoyo_path_perm(const u8 operation, struct path *path)
if (tomoyo_init_request_info(&r, NULL, tomoyo_p2mac[operation]) if (tomoyo_init_request_info(&r, NULL, tomoyo_p2mac[operation])
== TOMOYO_CONFIG_DISABLED) == TOMOYO_CONFIG_DISABLED)
return 0; return 0;
is_enforce = (r.mode == TOMOYO_CONFIG_ENFORCING);
error = -ENOMEM;
buf.name = NULL; buf.name = NULL;
idx = tomoyo_read_lock(); idx = tomoyo_read_lock();
if (!tomoyo_get_realpath(&buf, path)) if (!tomoyo_get_realpath(&buf, path))
goto out; goto out;
switch (operation) { switch (operation) {
case TOMOYO_TYPE_REWRITE:
if (!tomoyo_no_rewrite_file(&buf)) {
error = 0;
goto out;
}
break;
case TOMOYO_TYPE_RMDIR: case TOMOYO_TYPE_RMDIR:
case TOMOYO_TYPE_CHROOT: case TOMOYO_TYPE_CHROOT:
tomoyo_add_slash(&buf); tomoyo_add_slash(&buf);
...@@ -1018,7 +722,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path) ...@@ -1018,7 +722,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path)
out: out:
kfree(buf.name); kfree(buf.name);
tomoyo_read_unlock(idx); tomoyo_read_unlock(idx);
if (r.mode != TOMOYO_CONFIG_ENFORCING) if (!is_enforce)
error = 0; error = 0;
return error; return error;
} }
......
...@@ -32,27 +32,6 @@ static bool tomoyo_add_to_gc(const int type, struct list_head *element) ...@@ -32,27 +32,6 @@ static bool tomoyo_add_to_gc(const int type, struct list_head *element)
return true; return true;
} }
static void tomoyo_del_allow_read(struct list_head *element)
{
struct tomoyo_readable_file *ptr =
container_of(element, typeof(*ptr), head.list);
tomoyo_put_name(ptr->filename);
}
static void tomoyo_del_file_pattern(struct list_head *element)
{
struct tomoyo_no_pattern *ptr =
container_of(element, typeof(*ptr), head.list);
tomoyo_put_name(ptr->pattern);
}
static void tomoyo_del_no_rewrite(struct list_head *element)
{
struct tomoyo_no_rewrite *ptr =
container_of(element, typeof(*ptr), head.list);
tomoyo_put_name(ptr->pattern);
}
static void tomoyo_del_transition_control(struct list_head *element) static void tomoyo_del_transition_control(struct list_head *element)
{ {
struct tomoyo_transition_control *ptr = struct tomoyo_transition_control *ptr =
...@@ -290,15 +269,6 @@ static void tomoyo_kfree_entry(void) ...@@ -290,15 +269,6 @@ static void tomoyo_kfree_entry(void)
case TOMOYO_ID_AGGREGATOR: case TOMOYO_ID_AGGREGATOR:
tomoyo_del_aggregator(element); tomoyo_del_aggregator(element);
break; break;
case TOMOYO_ID_GLOBALLY_READABLE:
tomoyo_del_allow_read(element);
break;
case TOMOYO_ID_PATTERN:
tomoyo_del_file_pattern(element);
break;
case TOMOYO_ID_NO_REWRITE:
tomoyo_del_no_rewrite(element);
break;
case TOMOYO_ID_MANAGER: case TOMOYO_ID_MANAGER:
tomoyo_del_manager(element); tomoyo_del_manager(element);
break; break;
......
...@@ -55,9 +55,8 @@ static int tomoyo_audit_mount_log(struct tomoyo_request_info *r) ...@@ -55,9 +55,8 @@ static int tomoyo_audit_mount_log(struct tomoyo_request_info *r)
flags); flags);
return tomoyo_supervisor(r, return tomoyo_supervisor(r,
TOMOYO_KEYWORD_ALLOW_MOUNT "%s %s %s 0x%lX\n", TOMOYO_KEYWORD_ALLOW_MOUNT "%s %s %s 0x%lX\n",
tomoyo_pattern(r->param.mount.dev), r->param.mount.dev->name,
tomoyo_pattern(r->param.mount.dir), type, r->param.mount.dir->name, type, flags);
flags);
} }
static bool tomoyo_check_mount_acl(struct tomoyo_request_info *r, static bool tomoyo_check_mount_acl(struct tomoyo_request_info *r,
......
...@@ -93,6 +93,12 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm) ...@@ -93,6 +93,12 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
return tomoyo_check_open_permission(domain, &bprm->file->f_path, O_RDONLY); return tomoyo_check_open_permission(domain, &bprm->file->f_path, O_RDONLY);
} }
static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
{
struct path path = { mnt, dentry };
return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path);
}
static int tomoyo_path_truncate(struct path *path) static int tomoyo_path_truncate(struct path *path)
{ {
return tomoyo_path_perm(TOMOYO_TYPE_TRUNCATE, path); return tomoyo_path_perm(TOMOYO_TYPE_TRUNCATE, path);
...@@ -176,9 +182,10 @@ static int tomoyo_path_rename(struct path *old_parent, ...@@ -176,9 +182,10 @@ static int tomoyo_path_rename(struct path *old_parent,
static int tomoyo_file_fcntl(struct file *file, unsigned int cmd, 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_path_perm(TOMOYO_TYPE_REWRITE, &file->f_path);
return 0; return 0;
return tomoyo_check_open_permission(tomoyo_domain(), &file->f_path,
O_WRONLY | (arg & O_APPEND));
} }
static int tomoyo_dentry_open(struct file *f, const struct cred *cred) static int tomoyo_dentry_open(struct file *f, const struct cred *cred)
...@@ -258,6 +265,7 @@ static struct security_operations tomoyo_security_ops = { ...@@ -258,6 +265,7 @@ static struct security_operations tomoyo_security_ops = {
.path_mknod = tomoyo_path_mknod, .path_mknod = tomoyo_path_mknod,
.path_link = tomoyo_path_link, .path_link = tomoyo_path_link,
.path_rename = tomoyo_path_rename, .path_rename = tomoyo_path_rename,
.inode_getattr = tomoyo_inode_getattr,
.file_ioctl = tomoyo_file_ioctl, .file_ioctl = tomoyo_file_ioctl,
.path_chmod = tomoyo_path_chmod, .path_chmod = tomoyo_path_chmod,
.path_chown = tomoyo_path_chown, .path_chown = tomoyo_path_chown,
......
...@@ -911,44 +911,33 @@ bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r) ...@@ -911,44 +911,33 @@ bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r)
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) {
u16 perm;
u8 i;
if (ptr->is_deleted) if (ptr->is_deleted)
continue; continue;
switch (ptr->type) { switch (ptr->type) {
u16 perm;
u8 i;
case TOMOYO_TYPE_PATH_ACL: case TOMOYO_TYPE_PATH_ACL:
perm = container_of(ptr, struct tomoyo_path_acl, head) perm = container_of(ptr, struct tomoyo_path_acl, head)
->perm; ->perm;
for (i = 0; i < TOMOYO_MAX_PATH_OPERATION; i++)
if (perm & (1 << i))
count++;
if (perm & (1 << TOMOYO_TYPE_READ_WRITE))
count -= 2;
break; break;
case TOMOYO_TYPE_PATH2_ACL: case TOMOYO_TYPE_PATH2_ACL:
perm = container_of(ptr, struct tomoyo_path2_acl, head) perm = container_of(ptr, struct tomoyo_path2_acl, head)
->perm; ->perm;
for (i = 0; i < TOMOYO_MAX_PATH2_OPERATION; i++)
if (perm & (1 << i))
count++;
break; break;
case TOMOYO_TYPE_PATH_NUMBER_ACL: case TOMOYO_TYPE_PATH_NUMBER_ACL:
perm = container_of(ptr, struct tomoyo_path_number_acl, perm = container_of(ptr, struct tomoyo_path_number_acl,
head)->perm; head)->perm;
for (i = 0; i < TOMOYO_MAX_PATH_NUMBER_OPERATION; i++)
if (perm & (1 << i))
count++;
break; break;
case TOMOYO_TYPE_MKDEV_ACL: case TOMOYO_TYPE_MKDEV_ACL:
perm = container_of(ptr, struct tomoyo_mkdev_acl, perm = container_of(ptr, struct tomoyo_mkdev_acl,
head)->perm; head)->perm;
for (i = 0; i < TOMOYO_MAX_MKDEV_OPERATION; i++)
if (perm & (1 << i))
count++;
break; break;
default: default:
count++; perm = 1;
} }
for (i = 0; i < 16; i++)
if (perm & (1 << i))
count++;
} }
if (count < tomoyo_profile(domain->profile)->learning-> if (count < tomoyo_profile(domain->profile)->learning->
learning_max_entry) learning_max_entry)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册