2009-02-05 08:18:15 +00:00
|
|
|
/*
|
|
|
|
* security/tomoyo/domain.c
|
|
|
|
*
|
2010-05-17 01:12:46 +00:00
|
|
|
* Domain transition functions for TOMOYO.
|
2009-02-05 08:18:15 +00:00
|
|
|
*
|
2010-05-17 01:12:46 +00:00
|
|
|
* Copyright (C) 2005-2010 NTT DATA CORPORATION
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include <linux/binfmts.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2009-02-05 08:18:15 +00:00
|
|
|
|
|
|
|
/* Variables definitions.*/
|
|
|
|
|
|
|
|
/* The initial domain. */
|
|
|
|
struct tomoyo_domain_info tomoyo_kernel_domain;
|
|
|
|
|
2010-06-15 00:23:26 +00:00
|
|
|
/**
|
|
|
|
* tomoyo_update_policy - Update an entry for exception policy.
|
|
|
|
*
|
|
|
|
* @new_entry: Pointer to "struct tomoyo_acl_info".
|
|
|
|
* @size: Size of @new_entry in bytes.
|
|
|
|
* @is_delete: True if it is a delete request.
|
|
|
|
* @list: Pointer to "struct list_head".
|
|
|
|
* @check_duplicate: Callback function to find duplicated entry.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, negative value otherwise.
|
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
|
|
|
*/
|
|
|
|
int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
|
|
|
|
bool is_delete, struct list_head *list,
|
|
|
|
bool (*check_duplicate) (const struct tomoyo_acl_head
|
|
|
|
*,
|
|
|
|
const struct tomoyo_acl_head
|
|
|
|
*))
|
|
|
|
{
|
|
|
|
int error = is_delete ? -ENOENT : -ENOMEM;
|
|
|
|
struct tomoyo_acl_head *entry;
|
|
|
|
|
|
|
|
if (mutex_lock_interruptible(&tomoyo_policy_lock))
|
|
|
|
return -ENOMEM;
|
|
|
|
list_for_each_entry_rcu(entry, list, list) {
|
|
|
|
if (!check_duplicate(entry, new_entry))
|
|
|
|
continue;
|
|
|
|
entry->is_deleted = is_delete;
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (error && !is_delete) {
|
|
|
|
entry = tomoyo_commit_ok(new_entry, size);
|
|
|
|
if (entry) {
|
|
|
|
list_add_tail_rcu(&entry->list, list);
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&tomoyo_policy_lock);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2010-06-12 11:46:22 +00:00
|
|
|
/**
|
|
|
|
* tomoyo_update_domain - Update an entry for domain policy.
|
|
|
|
*
|
|
|
|
* @new_entry: Pointer to "struct tomoyo_acl_info".
|
|
|
|
* @size: Size of @new_entry in bytes.
|
|
|
|
* @is_delete: True if it is a delete request.
|
|
|
|
* @domain: Pointer to "struct tomoyo_domain_info".
|
|
|
|
* @check_duplicate: Callback function to find duplicated entry.
|
|
|
|
* @merge_duplicate: Callback function to merge duplicated entry.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, negative value otherwise.
|
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
|
|
|
*/
|
|
|
|
int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
|
|
|
|
bool is_delete, struct tomoyo_domain_info *domain,
|
|
|
|
bool (*check_duplicate) (const struct tomoyo_acl_info
|
|
|
|
*,
|
|
|
|
const struct tomoyo_acl_info
|
|
|
|
*),
|
|
|
|
bool (*merge_duplicate) (struct tomoyo_acl_info *,
|
|
|
|
struct tomoyo_acl_info *,
|
|
|
|
const bool))
|
|
|
|
{
|
|
|
|
int error = is_delete ? -ENOENT : -ENOMEM;
|
|
|
|
struct tomoyo_acl_info *entry;
|
|
|
|
|
|
|
|
if (mutex_lock_interruptible(&tomoyo_policy_lock))
|
|
|
|
return error;
|
|
|
|
list_for_each_entry_rcu(entry, &domain->acl_info_list, list) {
|
|
|
|
if (!check_duplicate(entry, new_entry))
|
|
|
|
continue;
|
|
|
|
if (merge_duplicate)
|
|
|
|
entry->is_deleted = merge_duplicate(entry, new_entry,
|
|
|
|
is_delete);
|
|
|
|
else
|
|
|
|
entry->is_deleted = is_delete;
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (error && !is_delete) {
|
|
|
|
entry = tomoyo_commit_ok(new_entry, size);
|
|
|
|
if (entry) {
|
|
|
|
list_add_tail_rcu(&entry->list, &domain->acl_info_list);
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&tomoyo_policy_lock);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2010-06-16 07:22:51 +00:00
|
|
|
void tomoyo_check_acl(struct tomoyo_request_info *r,
|
|
|
|
bool (*check_entry) (const struct tomoyo_request_info *,
|
|
|
|
const struct tomoyo_acl_info *))
|
|
|
|
{
|
|
|
|
const struct tomoyo_domain_info *domain = r->domain;
|
|
|
|
struct tomoyo_acl_info *ptr;
|
|
|
|
|
|
|
|
list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
|
|
|
|
if (ptr->is_deleted || ptr->type != r->param_type)
|
|
|
|
continue;
|
|
|
|
if (check_entry(r, ptr)) {
|
|
|
|
r->granted = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r->granted = false;
|
|
|
|
}
|
|
|
|
|
2009-06-08 03:37:39 +00:00
|
|
|
/*
|
|
|
|
* tomoyo_domain_list is used for holding list of domains.
|
|
|
|
* The ->acl_info_list of "struct tomoyo_domain_info" is used for holding
|
|
|
|
* permissions (e.g. "allow_read /lib/libc-2.5.so") given to each domain.
|
|
|
|
*
|
|
|
|
* An entry is added by
|
|
|
|
*
|
|
|
|
* # ( echo "<kernel>"; echo "allow_execute /sbin/init" ) > \
|
|
|
|
* /sys/kernel/security/tomoyo/domain_policy
|
|
|
|
*
|
|
|
|
* and is deleted by
|
|
|
|
*
|
|
|
|
* # ( echo "<kernel>"; echo "delete allow_execute /sbin/init" ) > \
|
|
|
|
* /sys/kernel/security/tomoyo/domain_policy
|
|
|
|
*
|
|
|
|
* and all entries are retrieved by
|
|
|
|
*
|
|
|
|
* # cat /sys/kernel/security/tomoyo/domain_policy
|
|
|
|
*
|
|
|
|
* A domain is added by
|
|
|
|
*
|
|
|
|
* # echo "<kernel>" > /sys/kernel/security/tomoyo/domain_policy
|
|
|
|
*
|
|
|
|
* and is deleted by
|
|
|
|
*
|
|
|
|
* # echo "delete <kernel>" > /sys/kernel/security/tomoyo/domain_policy
|
|
|
|
*
|
|
|
|
* and all domains are retrieved by
|
|
|
|
*
|
|
|
|
* # grep '^<kernel>' /sys/kernel/security/tomoyo/domain_policy
|
|
|
|
*
|
|
|
|
* Normally, a domainname is monotonically getting longer because a domainname
|
|
|
|
* which the process will belong to if an execve() operation succeeds is
|
|
|
|
* defined as a concatenation of "current domainname" + "pathname passed to
|
|
|
|
* execve()".
|
|
|
|
* See tomoyo_domain_initializer_list and tomoyo_domain_keeper_list for
|
|
|
|
* exceptions.
|
|
|
|
*/
|
2009-02-05 08:18:15 +00:00
|
|
|
LIST_HEAD(tomoyo_domain_list);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_get_last_name - Get last component of a domainname.
|
|
|
|
*
|
|
|
|
* @domain: Pointer to "struct tomoyo_domain_info".
|
|
|
|
*
|
|
|
|
* Returns the last component of the domainname.
|
|
|
|
*/
|
|
|
|
const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain)
|
|
|
|
{
|
|
|
|
const char *cp0 = domain->domainname->name;
|
|
|
|
const char *cp1 = strrchr(cp0, ' ');
|
|
|
|
|
|
|
|
if (cp1)
|
|
|
|
return cp1 + 1;
|
|
|
|
return cp0;
|
|
|
|
}
|
|
|
|
|
2009-06-08 03:37:39 +00:00
|
|
|
/*
|
|
|
|
* tomoyo_domain_initializer_list is used for holding list of programs which
|
|
|
|
* triggers reinitialization of domainname. Normally, a domainname is
|
|
|
|
* monotonically getting longer. But sometimes, we restart daemon programs.
|
|
|
|
* It would be convenient for us that "a daemon started upon system boot" and
|
|
|
|
* "the daemon restarted from console" belong to the same domain. Thus, TOMOYO
|
|
|
|
* provides a way to shorten domainnames.
|
|
|
|
*
|
|
|
|
* An entry is added by
|
|
|
|
*
|
|
|
|
* # echo 'initialize_domain /usr/sbin/httpd' > \
|
|
|
|
* /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
*
|
|
|
|
* and is deleted by
|
|
|
|
*
|
|
|
|
* # echo 'delete initialize_domain /usr/sbin/httpd' > \
|
|
|
|
* /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
*
|
|
|
|
* and all entries are retrieved by
|
|
|
|
*
|
|
|
|
* # grep ^initialize_domain /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
*
|
|
|
|
* In the example above, /usr/sbin/httpd will belong to
|
|
|
|
* "<kernel> /usr/sbin/httpd" domain.
|
|
|
|
*
|
|
|
|
* You may specify a domainname using "from" keyword.
|
|
|
|
* "initialize_domain /usr/sbin/httpd from <kernel> /etc/rc.d/init.d/httpd"
|
|
|
|
* will cause "/usr/sbin/httpd" executed from "<kernel> /etc/rc.d/init.d/httpd"
|
|
|
|
* domain to belong to "<kernel> /usr/sbin/httpd" domain.
|
|
|
|
*
|
|
|
|
* You may add "no_" prefix to "initialize_domain".
|
|
|
|
* "initialize_domain /usr/sbin/httpd" and
|
|
|
|
* "no_initialize_domain /usr/sbin/httpd from <kernel> /etc/rc.d/init.d/httpd"
|
|
|
|
* will cause "/usr/sbin/httpd" to belong to "<kernel> /usr/sbin/httpd" domain
|
|
|
|
* unless executed from "<kernel> /etc/rc.d/init.d/httpd" domain.
|
|
|
|
*/
|
2010-02-11 00:43:54 +00:00
|
|
|
LIST_HEAD(tomoyo_domain_initializer_list);
|
2009-02-05 08:18:15 +00:00
|
|
|
|
2010-06-15 00:23:26 +00:00
|
|
|
static bool tomoyo_same_domain_initializer_entry(const struct tomoyo_acl_head *
|
|
|
|
a,
|
|
|
|
const struct tomoyo_acl_head *
|
|
|
|
b)
|
|
|
|
{
|
|
|
|
const struct tomoyo_domain_initializer_entry *p1 =
|
|
|
|
container_of(a, typeof(*p1), head);
|
|
|
|
const struct tomoyo_domain_initializer_entry *p2 =
|
|
|
|
container_of(b, typeof(*p2), head);
|
|
|
|
return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name
|
|
|
|
&& p1->domainname == p2->domainname
|
|
|
|
&& p1->program == p2->program;
|
|
|
|
}
|
|
|
|
|
2009-02-05 08:18:15 +00:00
|
|
|
/**
|
|
|
|
* tomoyo_update_domain_initializer_entry - Update "struct tomoyo_domain_initializer_entry" list.
|
|
|
|
*
|
|
|
|
* @domainname: The name of domain. May be NULL.
|
|
|
|
* @program: The name of program.
|
|
|
|
* @is_not: True if it is "no_initialize_domain" entry.
|
|
|
|
* @is_delete: True if it is a delete request.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, negative value otherwise.
|
2009-12-08 00:34:43 +00:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
|
|
|
static int tomoyo_update_domain_initializer_entry(const char *domainname,
|
|
|
|
const char *program,
|
|
|
|
const bool is_not,
|
|
|
|
const bool is_delete)
|
|
|
|
{
|
2010-05-06 03:40:02 +00:00
|
|
|
struct tomoyo_domain_initializer_entry e = { .is_not = is_not };
|
2010-02-07 11:23:59 +00:00
|
|
|
int error = is_delete ? -ENOENT : -ENOMEM;
|
2009-02-05 08:18:15 +00:00
|
|
|
|
2010-06-03 11:37:26 +00:00
|
|
|
if (!tomoyo_is_correct_path(program))
|
|
|
|
return -EINVAL;
|
2009-02-05 08:18:15 +00:00
|
|
|
if (domainname) {
|
|
|
|
if (!tomoyo_is_domain_def(domainname) &&
|
2010-06-03 11:37:26 +00:00
|
|
|
tomoyo_is_correct_path(domainname))
|
2010-05-06 03:40:02 +00:00
|
|
|
e.is_last_name = true;
|
2010-02-16 12:14:48 +00:00
|
|
|
else if (!tomoyo_is_correct_domain(domainname))
|
2009-02-05 08:18:15 +00:00
|
|
|
return -EINVAL;
|
2010-05-06 03:40:02 +00:00
|
|
|
e.domainname = tomoyo_get_name(domainname);
|
|
|
|
if (!e.domainname)
|
2010-02-07 11:23:59 +00:00
|
|
|
goto out;
|
2009-02-05 08:18:15 +00:00
|
|
|
}
|
2010-05-06 03:40:02 +00:00
|
|
|
e.program = tomoyo_get_name(program);
|
|
|
|
if (!e.program)
|
2010-02-07 11:23:59 +00:00
|
|
|
goto out;
|
2010-06-15 00:23:26 +00:00
|
|
|
error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
|
|
|
|
&tomoyo_domain_initializer_list,
|
|
|
|
tomoyo_same_domain_initializer_entry);
|
2010-02-07 11:23:59 +00:00
|
|
|
out:
|
2010-05-06 03:40:02 +00:00
|
|
|
tomoyo_put_name(e.domainname);
|
|
|
|
tomoyo_put_name(e.program);
|
2009-02-05 08:18:15 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_read_domain_initializer_policy - Read "struct tomoyo_domain_initializer_entry" list.
|
|
|
|
*
|
|
|
|
* @head: Pointer to "struct tomoyo_io_buffer".
|
|
|
|
*
|
|
|
|
* Returns true on success, false otherwise.
|
2009-12-08 00:34:43 +00:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
|
|
|
bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head)
|
|
|
|
{
|
|
|
|
struct list_head *pos;
|
|
|
|
bool done = true;
|
|
|
|
|
|
|
|
list_for_each_cookie(pos, head->read_var2,
|
|
|
|
&tomoyo_domain_initializer_list) {
|
|
|
|
const char *no;
|
|
|
|
const char *from = "";
|
|
|
|
const char *domain = "";
|
|
|
|
struct tomoyo_domain_initializer_entry *ptr;
|
|
|
|
ptr = list_entry(pos, struct tomoyo_domain_initializer_entry,
|
2010-06-15 00:22:42 +00:00
|
|
|
head.list);
|
|
|
|
if (ptr->head.is_deleted)
|
2009-02-05 08:18:15 +00:00
|
|
|
continue;
|
|
|
|
no = ptr->is_not ? "no_" : "";
|
|
|
|
if (ptr->domainname) {
|
|
|
|
from = " from ";
|
|
|
|
domain = ptr->domainname->name;
|
|
|
|
}
|
2009-06-02 11:42:24 +00:00
|
|
|
done = tomoyo_io_printf(head,
|
|
|
|
"%s" TOMOYO_KEYWORD_INITIALIZE_DOMAIN
|
|
|
|
"%s%s%s\n", no, ptr->program->name,
|
|
|
|
from, domain);
|
|
|
|
if (!done)
|
2009-02-05 08:18:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_write_domain_initializer_policy - Write "struct tomoyo_domain_initializer_entry" list.
|
|
|
|
*
|
|
|
|
* @data: String to parse.
|
|
|
|
* @is_not: True if it is "no_initialize_domain" entry.
|
|
|
|
* @is_delete: True if it is a delete request.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, negative value otherwise.
|
2009-12-08 00:34:43 +00:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
|
|
|
int tomoyo_write_domain_initializer_policy(char *data, const bool is_not,
|
|
|
|
const bool is_delete)
|
|
|
|
{
|
|
|
|
char *cp = strstr(data, " from ");
|
|
|
|
|
|
|
|
if (cp) {
|
|
|
|
*cp = '\0';
|
|
|
|
return tomoyo_update_domain_initializer_entry(cp + 6, data,
|
|
|
|
is_not,
|
|
|
|
is_delete);
|
|
|
|
}
|
|
|
|
return tomoyo_update_domain_initializer_entry(NULL, data, is_not,
|
|
|
|
is_delete);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_is_domain_initializer - Check whether the given program causes domainname reinitialization.
|
|
|
|
*
|
|
|
|
* @domainname: The name of domain.
|
|
|
|
* @program: The name of program.
|
|
|
|
* @last_name: The last component of @domainname.
|
|
|
|
*
|
|
|
|
* Returns true if executing @program reinitializes domain transition,
|
|
|
|
* false otherwise.
|
2009-12-08 00:34:43 +00:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
|
|
|
static bool tomoyo_is_domain_initializer(const struct tomoyo_path_info *
|
|
|
|
domainname,
|
|
|
|
const struct tomoyo_path_info *program,
|
|
|
|
const struct tomoyo_path_info *
|
|
|
|
last_name)
|
|
|
|
{
|
|
|
|
struct tomoyo_domain_initializer_entry *ptr;
|
|
|
|
bool flag = false;
|
|
|
|
|
2010-06-15 00:22:42 +00:00
|
|
|
list_for_each_entry_rcu(ptr, &tomoyo_domain_initializer_list,
|
|
|
|
head.list) {
|
|
|
|
if (ptr->head.is_deleted)
|
2009-02-05 08:18:15 +00:00
|
|
|
continue;
|
|
|
|
if (ptr->domainname) {
|
|
|
|
if (!ptr->is_last_name) {
|
|
|
|
if (ptr->domainname != domainname)
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
if (tomoyo_pathcmp(ptr->domainname, last_name))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tomoyo_pathcmp(ptr->program, program))
|
|
|
|
continue;
|
|
|
|
if (ptr->is_not) {
|
|
|
|
flag = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2009-06-08 03:37:39 +00:00
|
|
|
/*
|
|
|
|
* tomoyo_domain_keeper_list is used for holding list of domainnames which
|
|
|
|
* suppresses domain transition. Normally, a domainname is monotonically
|
|
|
|
* getting longer. But sometimes, we want to suppress domain transition.
|
|
|
|
* It would be convenient for us that programs executed from a login session
|
|
|
|
* belong to the same domain. Thus, TOMOYO provides a way to suppress domain
|
|
|
|
* transition.
|
|
|
|
*
|
|
|
|
* An entry is added by
|
|
|
|
*
|
|
|
|
* # echo 'keep_domain <kernel> /usr/sbin/sshd /bin/bash' > \
|
|
|
|
* /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
*
|
|
|
|
* and is deleted by
|
|
|
|
*
|
|
|
|
* # echo 'delete keep_domain <kernel> /usr/sbin/sshd /bin/bash' > \
|
|
|
|
* /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
*
|
|
|
|
* and all entries are retrieved by
|
|
|
|
*
|
|
|
|
* # grep ^keep_domain /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
*
|
|
|
|
* In the example above, any process which belongs to
|
|
|
|
* "<kernel> /usr/sbin/sshd /bin/bash" domain will remain in that domain,
|
|
|
|
* unless explicitly specified by "initialize_domain" or "no_keep_domain".
|
|
|
|
*
|
|
|
|
* You may specify a program using "from" keyword.
|
|
|
|
* "keep_domain /bin/pwd from <kernel> /usr/sbin/sshd /bin/bash"
|
|
|
|
* will cause "/bin/pwd" executed from "<kernel> /usr/sbin/sshd /bin/bash"
|
|
|
|
* domain to remain in "<kernel> /usr/sbin/sshd /bin/bash" domain.
|
|
|
|
*
|
|
|
|
* You may add "no_" prefix to "keep_domain".
|
|
|
|
* "keep_domain <kernel> /usr/sbin/sshd /bin/bash" and
|
|
|
|
* "no_keep_domain /usr/bin/passwd from <kernel> /usr/sbin/sshd /bin/bash" will
|
|
|
|
* cause "/usr/bin/passwd" to belong to
|
|
|
|
* "<kernel> /usr/sbin/sshd /bin/bash /usr/bin/passwd" domain, unless
|
|
|
|
* explicitly specified by "initialize_domain".
|
|
|
|
*/
|
2010-02-11 00:43:54 +00:00
|
|
|
LIST_HEAD(tomoyo_domain_keeper_list);
|
2009-02-05 08:18:15 +00:00
|
|
|
|
2010-06-15 00:23:26 +00:00
|
|
|
static bool tomoyo_same_domain_keeper_entry(const struct tomoyo_acl_head *a,
|
|
|
|
const struct tomoyo_acl_head *b)
|
|
|
|
{
|
|
|
|
const struct tomoyo_domain_keeper_entry *p1 =
|
|
|
|
container_of(a, typeof(*p1), head);
|
|
|
|
const struct tomoyo_domain_keeper_entry *p2 =
|
|
|
|
container_of(b, typeof(*p2), head);
|
|
|
|
return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name
|
|
|
|
&& p1->domainname == p2->domainname
|
|
|
|
&& p1->program == p2->program;
|
|
|
|
}
|
|
|
|
|
2009-02-05 08:18:15 +00:00
|
|
|
/**
|
|
|
|
* tomoyo_update_domain_keeper_entry - Update "struct tomoyo_domain_keeper_entry" list.
|
|
|
|
*
|
|
|
|
* @domainname: The name of domain.
|
|
|
|
* @program: The name of program. May be NULL.
|
|
|
|
* @is_not: True if it is "no_keep_domain" entry.
|
|
|
|
* @is_delete: True if it is a delete request.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, negative value otherwise.
|
2009-12-08 00:34:43 +00:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
|
|
|
static int tomoyo_update_domain_keeper_entry(const char *domainname,
|
|
|
|
const char *program,
|
|
|
|
const bool is_not,
|
|
|
|
const bool is_delete)
|
|
|
|
{
|
2010-05-06 03:40:02 +00:00
|
|
|
struct tomoyo_domain_keeper_entry e = { .is_not = is_not };
|
2010-02-07 11:23:59 +00:00
|
|
|
int error = is_delete ? -ENOENT : -ENOMEM;
|
2009-02-05 08:18:15 +00:00
|
|
|
|
|
|
|
if (!tomoyo_is_domain_def(domainname) &&
|
2010-06-03 11:37:26 +00:00
|
|
|
tomoyo_is_correct_path(domainname))
|
2010-05-06 03:40:02 +00:00
|
|
|
e.is_last_name = true;
|
2010-02-16 12:14:48 +00:00
|
|
|
else if (!tomoyo_is_correct_domain(domainname))
|
2009-02-05 08:18:15 +00:00
|
|
|
return -EINVAL;
|
|
|
|
if (program) {
|
2010-06-03 11:37:26 +00:00
|
|
|
if (!tomoyo_is_correct_path(program))
|
2009-02-05 08:18:15 +00:00
|
|
|
return -EINVAL;
|
2010-05-06 03:40:02 +00:00
|
|
|
e.program = tomoyo_get_name(program);
|
|
|
|
if (!e.program)
|
2010-02-07 11:23:59 +00:00
|
|
|
goto out;
|
2009-02-05 08:18:15 +00:00
|
|
|
}
|
2010-05-06 03:40:02 +00:00
|
|
|
e.domainname = tomoyo_get_name(domainname);
|
|
|
|
if (!e.domainname)
|
2010-02-07 11:23:59 +00:00
|
|
|
goto out;
|
2010-06-15 00:23:26 +00:00
|
|
|
error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
|
|
|
|
&tomoyo_domain_keeper_list,
|
|
|
|
tomoyo_same_domain_keeper_entry);
|
2010-02-07 11:23:59 +00:00
|
|
|
out:
|
2010-05-06 03:40:02 +00:00
|
|
|
tomoyo_put_name(e.domainname);
|
|
|
|
tomoyo_put_name(e.program);
|
2009-02-05 08:18:15 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_write_domain_keeper_policy - Write "struct tomoyo_domain_keeper_entry" list.
|
|
|
|
*
|
|
|
|
* @data: String to parse.
|
|
|
|
* @is_not: True if it is "no_keep_domain" entry.
|
|
|
|
* @is_delete: True if it is a delete request.
|
|
|
|
*
|
2009-12-08 00:34:43 +00:00
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
|
|
|
int tomoyo_write_domain_keeper_policy(char *data, const bool is_not,
|
|
|
|
const bool is_delete)
|
|
|
|
{
|
|
|
|
char *cp = strstr(data, " from ");
|
|
|
|
|
|
|
|
if (cp) {
|
|
|
|
*cp = '\0';
|
|
|
|
return tomoyo_update_domain_keeper_entry(cp + 6, data, is_not,
|
|
|
|
is_delete);
|
|
|
|
}
|
|
|
|
return tomoyo_update_domain_keeper_entry(data, NULL, is_not, is_delete);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_read_domain_keeper_policy - Read "struct tomoyo_domain_keeper_entry" list.
|
|
|
|
*
|
|
|
|
* @head: Pointer to "struct tomoyo_io_buffer".
|
|
|
|
*
|
|
|
|
* Returns true on success, false otherwise.
|
2009-12-08 00:34:43 +00:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
|
|
|
bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head)
|
|
|
|
{
|
|
|
|
struct list_head *pos;
|
2009-02-13 07:00:58 +00:00
|
|
|
bool done = true;
|
2009-02-05 08:18:15 +00:00
|
|
|
|
|
|
|
list_for_each_cookie(pos, head->read_var2,
|
|
|
|
&tomoyo_domain_keeper_list) {
|
|
|
|
struct tomoyo_domain_keeper_entry *ptr;
|
|
|
|
const char *no;
|
|
|
|
const char *from = "";
|
|
|
|
const char *program = "";
|
|
|
|
|
2010-06-15 00:22:42 +00:00
|
|
|
ptr = list_entry(pos, struct tomoyo_domain_keeper_entry,
|
|
|
|
head.list);
|
|
|
|
if (ptr->head.is_deleted)
|
2009-02-05 08:18:15 +00:00
|
|
|
continue;
|
|
|
|
no = ptr->is_not ? "no_" : "";
|
|
|
|
if (ptr->program) {
|
|
|
|
from = " from ";
|
|
|
|
program = ptr->program->name;
|
|
|
|
}
|
2009-06-02 11:42:24 +00:00
|
|
|
done = tomoyo_io_printf(head,
|
|
|
|
"%s" TOMOYO_KEYWORD_KEEP_DOMAIN
|
|
|
|
"%s%s%s\n", no, program, from,
|
|
|
|
ptr->domainname->name);
|
|
|
|
if (!done)
|
2009-02-05 08:18:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_is_domain_keeper - Check whether the given program causes domain transition suppression.
|
|
|
|
*
|
|
|
|
* @domainname: The name of domain.
|
|
|
|
* @program: The name of program.
|
|
|
|
* @last_name: The last component of @domainname.
|
|
|
|
*
|
|
|
|
* Returns true if executing @program supresses domain transition,
|
|
|
|
* false otherwise.
|
2009-12-08 00:34:43 +00:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
|
|
|
static bool tomoyo_is_domain_keeper(const struct tomoyo_path_info *domainname,
|
|
|
|
const struct tomoyo_path_info *program,
|
|
|
|
const struct tomoyo_path_info *last_name)
|
|
|
|
{
|
|
|
|
struct tomoyo_domain_keeper_entry *ptr;
|
|
|
|
bool flag = false;
|
|
|
|
|
2010-06-15 00:22:42 +00:00
|
|
|
list_for_each_entry_rcu(ptr, &tomoyo_domain_keeper_list, head.list) {
|
|
|
|
if (ptr->head.is_deleted)
|
2009-02-05 08:18:15 +00:00
|
|
|
continue;
|
|
|
|
if (!ptr->is_last_name) {
|
|
|
|
if (ptr->domainname != domainname)
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
if (tomoyo_pathcmp(ptr->domainname, last_name))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ptr->program && tomoyo_pathcmp(ptr->program, program))
|
|
|
|
continue;
|
|
|
|
if (ptr->is_not) {
|
|
|
|
flag = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2010-06-03 11:38:03 +00:00
|
|
|
/*
|
|
|
|
* tomoyo_aggregator_list is used for holding list of rewrite table for
|
|
|
|
* execve() request. Some programs provides similar functionality. This keyword
|
|
|
|
* allows users to aggregate such programs.
|
|
|
|
*
|
|
|
|
* Entries are added by
|
|
|
|
*
|
|
|
|
* # echo 'aggregator /usr/bin/vi /./editor' > \
|
|
|
|
* /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
* # echo 'aggregator /usr/bin/emacs /./editor' > \
|
|
|
|
* /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
*
|
|
|
|
* and are deleted by
|
|
|
|
*
|
|
|
|
* # echo 'delete aggregator /usr/bin/vi /./editor' > \
|
|
|
|
* /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
* # echo 'delete aggregator /usr/bin/emacs /./editor' > \
|
|
|
|
* /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
*
|
|
|
|
* and all entries are retrieved by
|
|
|
|
*
|
|
|
|
* # grep ^aggregator /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
*
|
|
|
|
* In the example above, if /usr/bin/vi or /usr/bin/emacs are executed,
|
|
|
|
* permission is checked for /./editor and domainname which the current process
|
|
|
|
* will belong to after execve() succeeds is calculated using /./editor .
|
|
|
|
*/
|
|
|
|
LIST_HEAD(tomoyo_aggregator_list);
|
|
|
|
|
2010-06-15 00:23:26 +00:00
|
|
|
static bool tomoyo_same_aggregator_entry(const struct tomoyo_acl_head *a,
|
|
|
|
const struct tomoyo_acl_head *b)
|
|
|
|
{
|
|
|
|
const struct tomoyo_aggregator_entry *p1 = container_of(a, typeof(*p1),
|
|
|
|
head);
|
|
|
|
const struct tomoyo_aggregator_entry *p2 = container_of(b, typeof(*p2),
|
|
|
|
head);
|
|
|
|
return p1->original_name == p2->original_name &&
|
|
|
|
p1->aggregated_name == p2->aggregated_name;
|
|
|
|
}
|
|
|
|
|
2010-06-03 11:38:03 +00:00
|
|
|
/**
|
|
|
|
* tomoyo_update_aggregator_entry - Update "struct tomoyo_aggregator_entry" list.
|
|
|
|
*
|
|
|
|
* @original_name: The original program's name.
|
|
|
|
* @aggregated_name: The program name to use.
|
|
|
|
* @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_aggregator_entry(const char *original_name,
|
|
|
|
const char *aggregated_name,
|
|
|
|
const bool is_delete)
|
|
|
|
{
|
|
|
|
struct tomoyo_aggregator_entry e = { };
|
|
|
|
int error = is_delete ? -ENOENT : -ENOMEM;
|
|
|
|
|
|
|
|
if (!tomoyo_is_correct_path(original_name) ||
|
|
|
|
!tomoyo_is_correct_path(aggregated_name))
|
|
|
|
return -EINVAL;
|
|
|
|
e.original_name = tomoyo_get_name(original_name);
|
|
|
|
e.aggregated_name = tomoyo_get_name(aggregated_name);
|
|
|
|
if (!e.original_name || !e.aggregated_name ||
|
|
|
|
e.aggregated_name->is_patterned) /* No patterns allowed. */
|
|
|
|
goto out;
|
2010-06-15 00:23:26 +00:00
|
|
|
error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
|
|
|
|
&tomoyo_aggregator_list,
|
|
|
|
tomoyo_same_aggregator_entry);
|
2010-06-03 11:38:03 +00:00
|
|
|
out:
|
|
|
|
tomoyo_put_name(e.original_name);
|
|
|
|
tomoyo_put_name(e.aggregated_name);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_read_aggregator_policy - Read "struct tomoyo_aggregator_entry" list.
|
|
|
|
*
|
|
|
|
* @head: Pointer to "struct tomoyo_io_buffer".
|
|
|
|
*
|
|
|
|
* Returns true on success, false otherwise.
|
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
|
|
|
*/
|
|
|
|
bool tomoyo_read_aggregator_policy(struct tomoyo_io_buffer *head)
|
|
|
|
{
|
|
|
|
struct list_head *pos;
|
|
|
|
bool done = true;
|
|
|
|
|
|
|
|
list_for_each_cookie(pos, head->read_var2, &tomoyo_aggregator_list) {
|
|
|
|
struct tomoyo_aggregator_entry *ptr;
|
|
|
|
|
2010-06-15 00:22:42 +00:00
|
|
|
ptr = list_entry(pos, struct tomoyo_aggregator_entry,
|
|
|
|
head.list);
|
|
|
|
if (ptr->head.is_deleted)
|
2010-06-03 11:38:03 +00:00
|
|
|
continue;
|
|
|
|
done = tomoyo_io_printf(head, TOMOYO_KEYWORD_AGGREGATOR
|
|
|
|
"%s %s\n", ptr->original_name->name,
|
|
|
|
ptr->aggregated_name->name);
|
|
|
|
if (!done)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_write_aggregator_policy - Write "struct tomoyo_aggregator_entry" 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_aggregator_policy(char *data, const bool is_delete)
|
|
|
|
{
|
|
|
|
char *cp = strchr(data, ' ');
|
|
|
|
|
|
|
|
if (!cp)
|
|
|
|
return -EINVAL;
|
|
|
|
*cp++ = '\0';
|
|
|
|
return tomoyo_update_aggregator_entry(data, cp, is_delete);
|
|
|
|
}
|
|
|
|
|
2009-06-08 03:37:39 +00:00
|
|
|
/*
|
|
|
|
* tomoyo_alias_list is used for holding list of symlink's pathnames which are
|
|
|
|
* allowed to be passed to an execve() request. Normally, the domainname which
|
|
|
|
* the current process will belong to after execve() succeeds is calculated
|
|
|
|
* using dereferenced pathnames. But some programs behave differently depending
|
|
|
|
* on the name passed to argv[0]. For busybox, calculating domainname using
|
|
|
|
* dereferenced pathnames will cause all programs in the busybox to belong to
|
|
|
|
* the same domain. Thus, TOMOYO provides a way to allow use of symlink's
|
|
|
|
* pathname for checking execve()'s permission and calculating domainname which
|
|
|
|
* the current process will belong to after execve() succeeds.
|
|
|
|
*
|
|
|
|
* An entry is added by
|
|
|
|
*
|
|
|
|
* # echo 'alias /bin/busybox /bin/cat' > \
|
|
|
|
* /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
*
|
|
|
|
* and is deleted by
|
|
|
|
*
|
|
|
|
* # echo 'delete alias /bin/busybox /bin/cat' > \
|
|
|
|
* /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
*
|
|
|
|
* and all entries are retrieved by
|
|
|
|
*
|
|
|
|
* # grep ^alias /sys/kernel/security/tomoyo/exception_policy
|
|
|
|
*
|
|
|
|
* In the example above, if /bin/cat is a symlink to /bin/busybox and execution
|
|
|
|
* of /bin/cat is requested, permission is checked for /bin/cat rather than
|
|
|
|
* /bin/busybox and domainname which the current process will belong to after
|
|
|
|
* execve() succeeds is calculated using /bin/cat rather than /bin/busybox .
|
|
|
|
*/
|
2010-02-11 00:43:54 +00:00
|
|
|
LIST_HEAD(tomoyo_alias_list);
|
2009-02-05 08:18:15 +00:00
|
|
|
|
2010-06-15 00:23:26 +00:00
|
|
|
static bool tomoyo_same_alias_entry(const struct tomoyo_acl_head *a,
|
|
|
|
const struct tomoyo_acl_head *b)
|
|
|
|
{
|
|
|
|
const struct tomoyo_alias_entry *p1 = container_of(a, typeof(*p1),
|
|
|
|
head);
|
|
|
|
const struct tomoyo_alias_entry *p2 = container_of(b, typeof(*p2),
|
|
|
|
head);
|
|
|
|
return p1->original_name == p2->original_name &&
|
|
|
|
p1->aliased_name == p2->aliased_name;
|
|
|
|
}
|
|
|
|
|
2009-02-05 08:18:15 +00:00
|
|
|
/**
|
|
|
|
* tomoyo_update_alias_entry - Update "struct tomoyo_alias_entry" list.
|
|
|
|
*
|
|
|
|
* @original_name: The original program's real name.
|
|
|
|
* @aliased_name: The symbolic program's symbolic link's name.
|
|
|
|
* @is_delete: True if it is a delete request.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, negative value otherwise.
|
2009-12-08 00:34:43 +00:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
|
|
|
static int tomoyo_update_alias_entry(const char *original_name,
|
|
|
|
const char *aliased_name,
|
|
|
|
const bool is_delete)
|
|
|
|
{
|
2010-05-06 03:40:02 +00:00
|
|
|
struct tomoyo_alias_entry e = { };
|
2010-02-07 11:23:59 +00:00
|
|
|
int error = is_delete ? -ENOENT : -ENOMEM;
|
2009-02-05 08:18:15 +00:00
|
|
|
|
2010-06-03 11:37:26 +00:00
|
|
|
if (!tomoyo_is_correct_path(original_name) ||
|
|
|
|
!tomoyo_is_correct_path(aliased_name))
|
|
|
|
return -EINVAL;
|
2010-05-06 03:40:02 +00:00
|
|
|
e.original_name = tomoyo_get_name(original_name);
|
|
|
|
e.aliased_name = tomoyo_get_name(aliased_name);
|
2010-06-03 11:37:26 +00:00
|
|
|
if (!e.original_name || !e.aliased_name ||
|
|
|
|
e.original_name->is_patterned || e.aliased_name->is_patterned)
|
|
|
|
goto out; /* No patterns allowed. */
|
2010-06-15 00:23:26 +00:00
|
|
|
error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
|
|
|
|
&tomoyo_alias_list,
|
|
|
|
tomoyo_same_alias_entry);
|
2010-02-07 11:23:59 +00:00
|
|
|
out:
|
2010-05-06 03:40:02 +00:00
|
|
|
tomoyo_put_name(e.original_name);
|
|
|
|
tomoyo_put_name(e.aliased_name);
|
2009-02-05 08:18:15 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_read_alias_policy - Read "struct tomoyo_alias_entry" list.
|
|
|
|
*
|
|
|
|
* @head: Pointer to "struct tomoyo_io_buffer".
|
|
|
|
*
|
|
|
|
* Returns true on success, false otherwise.
|
2009-12-08 00:34:43 +00:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
|
|
|
bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head)
|
|
|
|
{
|
|
|
|
struct list_head *pos;
|
|
|
|
bool done = true;
|
|
|
|
|
|
|
|
list_for_each_cookie(pos, head->read_var2, &tomoyo_alias_list) {
|
|
|
|
struct tomoyo_alias_entry *ptr;
|
|
|
|
|
2010-06-15 00:22:42 +00:00
|
|
|
ptr = list_entry(pos, struct tomoyo_alias_entry, head.list);
|
|
|
|
if (ptr->head.is_deleted)
|
2009-02-05 08:18:15 +00:00
|
|
|
continue;
|
2009-06-02 11:42:24 +00:00
|
|
|
done = tomoyo_io_printf(head, TOMOYO_KEYWORD_ALIAS "%s %s\n",
|
|
|
|
ptr->original_name->name,
|
|
|
|
ptr->aliased_name->name);
|
|
|
|
if (!done)
|
2009-02-05 08:18:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_write_alias_policy - Write "struct tomoyo_alias_entry" list.
|
|
|
|
*
|
|
|
|
* @data: String to parse.
|
|
|
|
* @is_delete: True if it is a delete request.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, negative value otherwise.
|
2009-12-08 00:34:43 +00:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
|
|
|
int tomoyo_write_alias_policy(char *data, const bool is_delete)
|
|
|
|
{
|
|
|
|
char *cp = strchr(data, ' ');
|
|
|
|
|
|
|
|
if (!cp)
|
|
|
|
return -EINVAL;
|
|
|
|
*cp++ = '\0';
|
|
|
|
return tomoyo_update_alias_entry(data, cp, is_delete);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_find_or_assign_new_domain - Create a domain.
|
|
|
|
*
|
|
|
|
* @domainname: The name of domain.
|
|
|
|
* @profile: Profile number to assign if the domain was newly created.
|
|
|
|
*
|
|
|
|
* Returns pointer to "struct tomoyo_domain_info" on success, NULL otherwise.
|
2009-12-08 00:34:43 +00:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
|
|
|
struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
|
|
|
|
domainname,
|
|
|
|
const u8 profile)
|
|
|
|
{
|
2010-02-07 11:23:59 +00:00
|
|
|
struct tomoyo_domain_info *entry;
|
2010-05-05 15:18:15 +00:00
|
|
|
struct tomoyo_domain_info *domain = NULL;
|
2009-02-05 08:18:15 +00:00
|
|
|
const struct tomoyo_path_info *saved_domainname;
|
2010-02-07 11:23:59 +00:00
|
|
|
bool found = false;
|
2009-02-05 08:18:15 +00:00
|
|
|
|
2010-02-16 12:14:48 +00:00
|
|
|
if (!tomoyo_is_correct_domain(domainname))
|
2010-02-07 11:23:59 +00:00
|
|
|
return NULL;
|
2010-02-11 00:41:58 +00:00
|
|
|
saved_domainname = tomoyo_get_name(domainname);
|
2009-02-05 08:18:15 +00:00
|
|
|
if (!saved_domainname)
|
2010-02-07 11:23:59 +00:00
|
|
|
return NULL;
|
2010-04-28 05:17:42 +00:00
|
|
|
entry = kzalloc(sizeof(*entry), GFP_NOFS);
|
2010-05-05 15:18:15 +00:00
|
|
|
if (mutex_lock_interruptible(&tomoyo_policy_lock))
|
|
|
|
goto out;
|
2010-02-07 11:23:59 +00:00
|
|
|
list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
|
|
|
|
if (domain->is_deleted ||
|
|
|
|
tomoyo_pathcmp(saved_domainname, domain->domainname))
|
|
|
|
continue;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!found && tomoyo_memory_ok(entry)) {
|
|
|
|
INIT_LIST_HEAD(&entry->acl_info_list);
|
|
|
|
entry->domainname = saved_domainname;
|
2010-02-11 00:41:58 +00:00
|
|
|
saved_domainname = NULL;
|
2010-02-07 11:23:59 +00:00
|
|
|
entry->profile = profile;
|
|
|
|
list_add_tail_rcu(&entry->list, &tomoyo_domain_list);
|
|
|
|
domain = entry;
|
|
|
|
entry = NULL;
|
|
|
|
found = true;
|
2009-02-05 08:18:15 +00:00
|
|
|
}
|
2010-01-03 12:16:32 +00:00
|
|
|
mutex_unlock(&tomoyo_policy_lock);
|
2010-05-05 15:18:15 +00:00
|
|
|
out:
|
2010-02-11 00:41:58 +00:00
|
|
|
tomoyo_put_name(saved_domainname);
|
2010-02-07 11:23:59 +00:00
|
|
|
kfree(entry);
|
|
|
|
return found ? domain : NULL;
|
2009-02-05 08:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_find_next_domain - Find a domain.
|
|
|
|
*
|
2009-06-19 05:13:27 +00:00
|
|
|
* @bprm: Pointer to "struct linux_binprm".
|
2009-02-05 08:18:15 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success, negative value otherwise.
|
2009-12-08 00:34:43 +00:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 08:18:15 +00:00
|
|
|
*/
|
2009-06-19 05:13:27 +00:00
|
|
|
int tomoyo_find_next_domain(struct linux_binprm *bprm)
|
2009-02-05 08:18:15 +00:00
|
|
|
{
|
2010-05-17 01:11:36 +00:00
|
|
|
struct tomoyo_request_info r;
|
2010-06-03 11:36:43 +00:00
|
|
|
char *tmp = kzalloc(TOMOYO_EXEC_TMPSIZE, GFP_NOFS);
|
2009-02-05 08:18:15 +00:00
|
|
|
struct tomoyo_domain_info *old_domain = tomoyo_domain();
|
|
|
|
struct tomoyo_domain_info *domain = NULL;
|
|
|
|
const char *old_domain_name = old_domain->domainname->name;
|
|
|
|
const char *original_name = bprm->filename;
|
2010-06-03 11:38:44 +00:00
|
|
|
u8 mode;
|
|
|
|
bool is_enforce;
|
2009-02-05 08:18:15 +00:00
|
|
|
int retval = -ENOMEM;
|
2010-06-03 11:36:43 +00:00
|
|
|
bool need_kfree = false;
|
|
|
|
struct tomoyo_path_info rn = { }; /* real name */
|
|
|
|
struct tomoyo_path_info sn = { }; /* symlink name */
|
2010-05-17 01:11:36 +00:00
|
|
|
struct tomoyo_path_info ln; /* last name */
|
2009-02-05 08:18:15 +00:00
|
|
|
|
2010-06-03 11:36:43 +00:00
|
|
|
ln.name = tomoyo_get_last_name(old_domain);
|
|
|
|
tomoyo_fill_path_info(&ln);
|
2010-06-03 11:38:44 +00:00
|
|
|
mode = tomoyo_init_request_info(&r, NULL, TOMOYO_MAC_FILE_EXECUTE);
|
|
|
|
is_enforce = (mode == TOMOYO_CONFIG_ENFORCING);
|
2009-02-05 08:18:15 +00:00
|
|
|
if (!tmp)
|
|
|
|
goto out;
|
|
|
|
|
2010-05-17 01:11:36 +00:00
|
|
|
retry:
|
2010-06-03 11:36:43 +00:00
|
|
|
if (need_kfree) {
|
|
|
|
kfree(rn.name);
|
|
|
|
need_kfree = false;
|
|
|
|
}
|
2009-02-05 08:18:15 +00:00
|
|
|
/* Get tomoyo_realpath of program. */
|
|
|
|
retval = -ENOENT;
|
2010-06-03 11:36:43 +00:00
|
|
|
rn.name = tomoyo_realpath(original_name);
|
|
|
|
if (!rn.name)
|
2009-02-05 08:18:15 +00:00
|
|
|
goto out;
|
2010-06-03 11:36:43 +00:00
|
|
|
tomoyo_fill_path_info(&rn);
|
|
|
|
need_kfree = true;
|
|
|
|
|
2009-02-05 08:18:15 +00:00
|
|
|
/* Get tomoyo_realpath of symbolic link. */
|
2010-06-03 11:36:43 +00:00
|
|
|
sn.name = tomoyo_realpath_nofollow(original_name);
|
|
|
|
if (!sn.name)
|
2009-02-05 08:18:15 +00:00
|
|
|
goto out;
|
2010-05-17 01:11:36 +00:00
|
|
|
tomoyo_fill_path_info(&sn);
|
2009-02-05 08:18:15 +00:00
|
|
|
|
|
|
|
/* Check 'alias' directive. */
|
2010-05-17 01:11:36 +00:00
|
|
|
if (tomoyo_pathcmp(&rn, &sn)) {
|
2009-02-05 08:18:15 +00:00
|
|
|
struct tomoyo_alias_entry *ptr;
|
|
|
|
/* Is this program allowed to be called via symbolic links? */
|
2010-06-15 00:22:42 +00:00
|
|
|
list_for_each_entry_rcu(ptr, &tomoyo_alias_list, head.list) {
|
|
|
|
if (ptr->head.is_deleted ||
|
2010-05-17 01:11:36 +00:00
|
|
|
tomoyo_pathcmp(&rn, ptr->original_name) ||
|
|
|
|
tomoyo_pathcmp(&sn, ptr->aliased_name))
|
2009-02-05 08:18:15 +00:00
|
|
|
continue;
|
2010-06-03 11:36:43 +00:00
|
|
|
kfree(rn.name);
|
|
|
|
need_kfree = false;
|
|
|
|
/* This is OK because it is read only. */
|
|
|
|
rn = *ptr->aliased_name;
|
2009-02-05 08:18:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-03 11:38:03 +00:00
|
|
|
/* Check 'aggregator' directive. */
|
|
|
|
{
|
|
|
|
struct tomoyo_aggregator_entry *ptr;
|
2010-06-15 00:22:42 +00:00
|
|
|
list_for_each_entry_rcu(ptr, &tomoyo_aggregator_list,
|
|
|
|
head.list) {
|
|
|
|
if (ptr->head.is_deleted ||
|
2010-06-03 11:38:03 +00:00
|
|
|
!tomoyo_path_matches_pattern(&rn,
|
|
|
|
ptr->original_name))
|
|
|
|
continue;
|
|
|
|
if (need_kfree)
|
|
|
|
kfree(rn.name);
|
|
|
|
need_kfree = false;
|
|
|
|
/* This is OK because it is read only. */
|
|
|
|
rn = *ptr->aggregated_name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-05 08:18:15 +00:00
|
|
|
/* Check execute permission. */
|
2010-06-16 07:20:24 +00:00
|
|
|
retval = tomoyo_path_permission(&r, TOMOYO_TYPE_EXECUTE, &rn);
|
2010-05-17 01:11:36 +00:00
|
|
|
if (retval == TOMOYO_RETRY_REQUEST)
|
|
|
|
goto retry;
|
2009-02-05 08:18:15 +00:00
|
|
|
if (retval < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-05-17 01:11:36 +00:00
|
|
|
if (tomoyo_is_domain_initializer(old_domain->domainname, &rn, &ln)) {
|
2009-02-05 08:18:15 +00:00
|
|
|
/* Transit to the child of tomoyo_kernel_domain domain. */
|
2010-06-03 11:36:43 +00:00
|
|
|
snprintf(tmp, TOMOYO_EXEC_TMPSIZE - 1,
|
|
|
|
TOMOYO_ROOT_NAME " " "%s", rn.name);
|
2009-02-05 08:18:15 +00:00
|
|
|
} else if (old_domain == &tomoyo_kernel_domain &&
|
|
|
|
!tomoyo_policy_loaded) {
|
|
|
|
/*
|
|
|
|
* Needn't to transit from kernel domain before starting
|
|
|
|
* /sbin/init. But transit from kernel domain if executing
|
|
|
|
* initializers because they might start before /sbin/init.
|
|
|
|
*/
|
|
|
|
domain = old_domain;
|
2010-05-17 01:11:36 +00:00
|
|
|
} else if (tomoyo_is_domain_keeper(old_domain->domainname, &rn, &ln)) {
|
2009-02-05 08:18:15 +00:00
|
|
|
/* Keep current domain. */
|
|
|
|
domain = old_domain;
|
|
|
|
} else {
|
|
|
|
/* Normal domain transition. */
|
2010-06-03 11:36:43 +00:00
|
|
|
snprintf(tmp, TOMOYO_EXEC_TMPSIZE - 1,
|
|
|
|
"%s %s", old_domain_name, rn.name);
|
2009-02-05 08:18:15 +00:00
|
|
|
}
|
2010-06-03 11:36:43 +00:00
|
|
|
if (domain || strlen(tmp) >= TOMOYO_EXEC_TMPSIZE - 10)
|
2009-02-05 08:18:15 +00:00
|
|
|
goto done;
|
2010-06-03 11:36:43 +00:00
|
|
|
domain = tomoyo_find_domain(tmp);
|
2009-02-05 08:18:15 +00:00
|
|
|
if (domain)
|
|
|
|
goto done;
|
2010-05-17 01:11:36 +00:00
|
|
|
if (is_enforce) {
|
|
|
|
int error = tomoyo_supervisor(&r, "# wants to create domain\n"
|
2010-06-03 11:36:43 +00:00
|
|
|
"%s\n", tmp);
|
2010-05-17 01:11:36 +00:00
|
|
|
if (error == TOMOYO_RETRY_REQUEST)
|
|
|
|
goto retry;
|
|
|
|
if (error < 0)
|
|
|
|
goto done;
|
|
|
|
}
|
2010-06-03 11:36:43 +00:00
|
|
|
domain = tomoyo_find_or_assign_new_domain(tmp, old_domain->profile);
|
2009-02-05 08:18:15 +00:00
|
|
|
done:
|
|
|
|
if (domain)
|
|
|
|
goto out;
|
2010-06-03 11:36:43 +00:00
|
|
|
printk(KERN_WARNING "TOMOYO-ERROR: Domain '%s' not defined.\n", tmp);
|
2009-02-05 08:18:15 +00:00
|
|
|
if (is_enforce)
|
|
|
|
retval = -EPERM;
|
|
|
|
else
|
2010-02-02 21:43:06 +00:00
|
|
|
old_domain->transition_failed = true;
|
2009-02-05 08:18:15 +00:00
|
|
|
out:
|
2009-06-19 05:13:27 +00:00
|
|
|
if (!domain)
|
|
|
|
domain = old_domain;
|
2010-02-11 00:43:20 +00:00
|
|
|
/* Update reference count on "struct tomoyo_domain_info". */
|
|
|
|
atomic_inc(&domain->users);
|
2009-06-19 05:13:27 +00:00
|
|
|
bprm->cred->security = domain;
|
2010-06-03 11:36:43 +00:00
|
|
|
if (need_kfree)
|
|
|
|
kfree(rn.name);
|
|
|
|
kfree(sn.name);
|
2010-01-26 11:45:27 +00:00
|
|
|
kfree(tmp);
|
2009-02-05 08:18:15 +00:00
|
|
|
return retval;
|
|
|
|
}
|