2009-02-05 16:18:15 +08:00
|
|
|
/*
|
|
|
|
* security/tomoyo/domain.c
|
|
|
|
*
|
2010-05-17 09:12:46 +08:00
|
|
|
* Domain transition functions for TOMOYO.
|
2009-02-05 16:18:15 +08:00
|
|
|
*
|
2010-05-17 09:12:46 +08:00
|
|
|
* Copyright (C) 2005-2010 NTT DATA CORPORATION
|
2009-02-05 16:18:15 +08: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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-02-05 16:18:15 +08:00
|
|
|
|
|
|
|
/* Variables definitions.*/
|
|
|
|
|
|
|
|
/* The initial domain. */
|
|
|
|
struct tomoyo_domain_info tomoyo_kernel_domain;
|
|
|
|
|
2010-06-15 08:23:26 +08: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.
|
2011-06-26 22:17:10 +08:00
|
|
|
* @param: Pointer to "struct tomoyo_acl_param".
|
2010-06-15 08:23:26 +08:00
|
|
|
* @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,
|
2011-06-26 22:17:10 +08:00
|
|
|
struct tomoyo_acl_param *param,
|
2010-06-15 08:23:26 +08:00
|
|
|
bool (*check_duplicate) (const struct tomoyo_acl_head
|
|
|
|
*,
|
|
|
|
const struct tomoyo_acl_head
|
|
|
|
*))
|
|
|
|
{
|
2011-06-26 22:17:10 +08:00
|
|
|
int error = param->is_delete ? -ENOENT : -ENOMEM;
|
2010-06-15 08:23:26 +08:00
|
|
|
struct tomoyo_acl_head *entry;
|
2011-06-26 22:17:10 +08:00
|
|
|
struct list_head *list = param->list;
|
2010-06-15 08:23:26 +08:00
|
|
|
|
|
|
|
if (mutex_lock_interruptible(&tomoyo_policy_lock))
|
|
|
|
return -ENOMEM;
|
|
|
|
list_for_each_entry_rcu(entry, list, list) {
|
|
|
|
if (!check_duplicate(entry, new_entry))
|
|
|
|
continue;
|
2011-06-26 22:17:10 +08:00
|
|
|
entry->is_deleted = param->is_delete;
|
2010-06-15 08:23:26 +08:00
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
}
|
2011-06-26 22:17:10 +08:00
|
|
|
if (error && !param->is_delete) {
|
2010-06-15 08:23:26 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-06-26 22:16:36 +08:00
|
|
|
/**
|
|
|
|
* tomoyo_same_acl_head - Check for duplicated "struct tomoyo_acl_info" entry.
|
|
|
|
*
|
|
|
|
* @a: Pointer to "struct tomoyo_acl_info".
|
|
|
|
* @b: Pointer to "struct tomoyo_acl_info".
|
|
|
|
*
|
|
|
|
* Returns true if @a == @b, false otherwise.
|
|
|
|
*/
|
|
|
|
static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info *a,
|
|
|
|
const struct tomoyo_acl_info *b)
|
|
|
|
{
|
|
|
|
return a->type == b->type;
|
|
|
|
}
|
|
|
|
|
2010-06-12 19:46:22 +08: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.
|
2011-06-26 22:17:10 +08:00
|
|
|
* @param: Pointer to "struct tomoyo_acl_param".
|
2010-06-12 19:46:22 +08:00
|
|
|
* @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,
|
2011-06-26 22:17:10 +08:00
|
|
|
struct tomoyo_acl_param *param,
|
2010-06-12 19:46:22 +08:00
|
|
|
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))
|
|
|
|
{
|
2011-06-26 22:17:10 +08:00
|
|
|
const bool is_delete = param->is_delete;
|
2010-06-12 19:46:22 +08:00
|
|
|
int error = is_delete ? -ENOENT : -ENOMEM;
|
|
|
|
struct tomoyo_acl_info *entry;
|
2011-06-26 22:17:10 +08:00
|
|
|
struct list_head * const list = param->list;
|
2010-06-12 19:46:22 +08:00
|
|
|
|
|
|
|
if (mutex_lock_interruptible(&tomoyo_policy_lock))
|
|
|
|
return error;
|
2011-06-26 22:17:10 +08:00
|
|
|
list_for_each_entry_rcu(entry, list, list) {
|
2011-06-26 22:16:36 +08:00
|
|
|
if (!tomoyo_same_acl_head(entry, new_entry) ||
|
|
|
|
!check_duplicate(entry, new_entry))
|
2010-06-12 19:46:22 +08:00
|
|
|
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) {
|
2011-06-26 22:17:10 +08:00
|
|
|
list_add_tail_rcu(&entry->list, list);
|
2010-06-12 19:46:22 +08:00
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&tomoyo_policy_lock);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2010-06-16 15:22:51 +08:00
|
|
|
void tomoyo_check_acl(struct tomoyo_request_info *r,
|
2010-07-29 13:29:55 +08:00
|
|
|
bool (*check_entry) (struct tomoyo_request_info *,
|
2010-06-16 15:22:51 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-06-17 15:53:24 +08:00
|
|
|
/* The list for "struct tomoyo_domain_info". */
|
2009-02-05 16:18:15 +08:00
|
|
|
LIST_HEAD(tomoyo_domain_list);
|
|
|
|
|
2010-06-17 15:53:24 +08:00
|
|
|
struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY];
|
|
|
|
struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP];
|
|
|
|
|
2009-02-05 16:18:15 +08:00
|
|
|
/**
|
2010-06-25 10:16:00 +08:00
|
|
|
* tomoyo_last_word - Get last component of a domainname.
|
2009-02-05 16:18:15 +08:00
|
|
|
*
|
2010-06-25 10:16:00 +08:00
|
|
|
* @domainname: Domainname to check.
|
2009-02-05 16:18:15 +08:00
|
|
|
*
|
2010-06-25 10:16:00 +08:00
|
|
|
* Returns the last word of @domainname.
|
2009-02-05 16:18:15 +08:00
|
|
|
*/
|
2010-06-25 10:16:00 +08:00
|
|
|
static const char *tomoyo_last_word(const char *name)
|
2009-02-05 16:18:15 +08:00
|
|
|
{
|
2010-06-25 10:16:00 +08:00
|
|
|
const char *cp = strrchr(name, ' ');
|
|
|
|
if (cp)
|
|
|
|
return cp + 1;
|
|
|
|
return name;
|
2009-02-05 16:18:15 +08:00
|
|
|
}
|
|
|
|
|
2011-06-26 22:17:10 +08:00
|
|
|
/**
|
|
|
|
* tomoyo_same_transition_control - Check for duplicated "struct tomoyo_transition_control" entry.
|
|
|
|
*
|
|
|
|
* @a: Pointer to "struct tomoyo_acl_head".
|
|
|
|
* @b: Pointer to "struct tomoyo_acl_head".
|
|
|
|
*
|
|
|
|
* Returns true if @a == @b, false otherwise.
|
|
|
|
*/
|
2010-06-25 10:16:00 +08:00
|
|
|
static bool tomoyo_same_transition_control(const struct tomoyo_acl_head *a,
|
|
|
|
const struct tomoyo_acl_head *b)
|
2010-06-15 08:23:26 +08:00
|
|
|
{
|
2010-06-21 10:14:39 +08:00
|
|
|
const struct tomoyo_transition_control *p1 = container_of(a,
|
|
|
|
typeof(*p1),
|
|
|
|
head);
|
|
|
|
const struct tomoyo_transition_control *p2 = container_of(b,
|
|
|
|
typeof(*p2),
|
|
|
|
head);
|
|
|
|
return p1->type == p2->type && p1->is_last_name == p2->is_last_name
|
2010-06-15 08:23:26 +08:00
|
|
|
&& p1->domainname == p2->domainname
|
|
|
|
&& p1->program == p2->program;
|
|
|
|
}
|
|
|
|
|
2009-02-05 16:18:15 +08:00
|
|
|
/**
|
2011-06-26 22:17:10 +08:00
|
|
|
* tomoyo_write_transition_control - Write "struct tomoyo_transition_control" list.
|
2009-02-05 16:18:15 +08:00
|
|
|
*
|
2011-06-26 22:17:10 +08:00
|
|
|
* @param: Pointer to "struct tomoyo_acl_param".
|
|
|
|
* @type: Type of this entry.
|
2009-02-05 16:18:15 +08:00
|
|
|
*
|
|
|
|
* Returns 0 on success, negative value otherwise.
|
|
|
|
*/
|
2011-06-26 22:17:10 +08:00
|
|
|
int tomoyo_write_transition_control(struct tomoyo_acl_param *param,
|
|
|
|
const u8 type)
|
2009-02-05 16:18:15 +08:00
|
|
|
{
|
2010-06-21 10:14:39 +08:00
|
|
|
struct tomoyo_transition_control e = { .type = type };
|
2011-06-26 22:17:10 +08:00
|
|
|
int error = param->is_delete ? -ENOENT : -ENOMEM;
|
|
|
|
char *program = param->data;
|
|
|
|
char *domainname = strstr(program, " from ");
|
|
|
|
if (domainname) {
|
|
|
|
*domainname = '\0';
|
|
|
|
domainname += 6;
|
|
|
|
} else if (type == TOMOYO_TRANSITION_CONTROL_NO_KEEP ||
|
|
|
|
type == TOMOYO_TRANSITION_CONTROL_KEEP) {
|
|
|
|
domainname = program;
|
|
|
|
program = NULL;
|
|
|
|
}
|
2010-06-21 10:14:39 +08:00
|
|
|
if (program) {
|
|
|
|
if (!tomoyo_correct_path(program))
|
|
|
|
return -EINVAL;
|
|
|
|
e.program = tomoyo_get_name(program);
|
|
|
|
if (!e.program)
|
|
|
|
goto out;
|
|
|
|
}
|
2009-02-05 16:18:15 +08:00
|
|
|
if (domainname) {
|
2010-06-21 10:14:39 +08:00
|
|
|
if (!tomoyo_correct_domain(domainname)) {
|
|
|
|
if (!tomoyo_correct_path(domainname))
|
|
|
|
goto out;
|
2010-05-06 11:40:02 +08:00
|
|
|
e.is_last_name = true;
|
2010-06-21 10:14:39 +08:00
|
|
|
}
|
2010-05-06 11:40:02 +08:00
|
|
|
e.domainname = tomoyo_get_name(domainname);
|
|
|
|
if (!e.domainname)
|
2010-02-07 19:23:59 +08:00
|
|
|
goto out;
|
2009-02-05 16:18:15 +08:00
|
|
|
}
|
2011-06-26 22:17:10 +08:00
|
|
|
param->list = &tomoyo_policy_list[TOMOYO_ID_TRANSITION_CONTROL];
|
|
|
|
error = tomoyo_update_policy(&e.head, sizeof(e), param,
|
2010-06-25 10:16:00 +08:00
|
|
|
tomoyo_same_transition_control);
|
2011-06-26 22:17:10 +08:00
|
|
|
out:
|
2010-05-06 11:40:02 +08:00
|
|
|
tomoyo_put_name(e.domainname);
|
|
|
|
tomoyo_put_name(e.program);
|
2009-02-05 16:18:15 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-21 10:14:39 +08:00
|
|
|
* tomoyo_transition_type - Get domain transition type.
|
2009-02-05 16:18:15 +08:00
|
|
|
*
|
|
|
|
* @domainname: The name of domain.
|
|
|
|
* @program: The name of program.
|
|
|
|
*
|
2010-06-21 10:14:39 +08:00
|
|
|
* Returns TOMOYO_TRANSITION_CONTROL_INITIALIZE if executing @program
|
|
|
|
* reinitializes domain transition, TOMOYO_TRANSITION_CONTROL_KEEP if executing
|
|
|
|
* @program suppresses domain transition, others otherwise.
|
2009-12-08 08:34:43 +08:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 16:18:15 +08:00
|
|
|
*/
|
2010-06-21 10:14:39 +08:00
|
|
|
static u8 tomoyo_transition_type(const struct tomoyo_path_info *domainname,
|
|
|
|
const struct tomoyo_path_info *program)
|
2009-02-05 16:18:15 +08:00
|
|
|
{
|
2010-06-21 10:14:39 +08:00
|
|
|
const struct tomoyo_transition_control *ptr;
|
|
|
|
const char *last_name = tomoyo_last_word(domainname->name);
|
|
|
|
u8 type;
|
|
|
|
for (type = 0; type < TOMOYO_MAX_TRANSITION_TYPE; type++) {
|
|
|
|
next:
|
|
|
|
list_for_each_entry_rcu(ptr, &tomoyo_policy_list
|
|
|
|
[TOMOYO_ID_TRANSITION_CONTROL],
|
|
|
|
head.list) {
|
|
|
|
if (ptr->head.is_deleted || ptr->type != type)
|
2009-02-05 16:18:15 +08:00
|
|
|
continue;
|
2010-06-21 10:14:39 +08:00
|
|
|
if (ptr->domainname) {
|
|
|
|
if (!ptr->is_last_name) {
|
|
|
|
if (ptr->domainname != domainname)
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Use direct strcmp() since this is
|
|
|
|
* unlikely used.
|
|
|
|
*/
|
|
|
|
if (strcmp(ptr->domainname->name,
|
|
|
|
last_name))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ptr->program &&
|
|
|
|
tomoyo_pathcmp(ptr->program, program))
|
2009-02-05 16:18:15 +08:00
|
|
|
continue;
|
2010-06-21 10:14:39 +08:00
|
|
|
if (type == TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE) {
|
|
|
|
/*
|
|
|
|
* Do not check for initialize_domain if
|
|
|
|
* no_initialize_domain matched.
|
|
|
|
*/
|
|
|
|
type = TOMOYO_TRANSITION_CONTROL_NO_KEEP;
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
goto done;
|
2009-02-05 16:18:15 +08:00
|
|
|
}
|
|
|
|
}
|
2010-06-21 10:14:39 +08:00
|
|
|
done:
|
|
|
|
return type;
|
2009-02-05 16:18:15 +08:00
|
|
|
}
|
|
|
|
|
2011-06-26 22:17:10 +08:00
|
|
|
/**
|
|
|
|
* tomoyo_same_aggregator - Check for duplicated "struct tomoyo_aggregator" entry.
|
|
|
|
*
|
|
|
|
* @a: Pointer to "struct tomoyo_acl_head".
|
|
|
|
* @b: Pointer to "struct tomoyo_acl_head".
|
|
|
|
*
|
|
|
|
* Returns true if @a == @b, false otherwise.
|
|
|
|
*/
|
2010-06-25 10:16:00 +08:00
|
|
|
static bool tomoyo_same_aggregator(const struct tomoyo_acl_head *a,
|
|
|
|
const struct tomoyo_acl_head *b)
|
2010-06-15 08:23:26 +08:00
|
|
|
{
|
2011-06-26 22:17:10 +08:00
|
|
|
const struct tomoyo_aggregator *p1 = container_of(a, typeof(*p1),
|
|
|
|
head);
|
|
|
|
const struct tomoyo_aggregator *p2 = container_of(b, typeof(*p2),
|
|
|
|
head);
|
2010-06-15 08:23:26 +08:00
|
|
|
return p1->original_name == p2->original_name &&
|
|
|
|
p1->aggregated_name == p2->aggregated_name;
|
|
|
|
}
|
|
|
|
|
2010-06-03 19:38:03 +08:00
|
|
|
/**
|
2011-06-26 22:17:10 +08:00
|
|
|
* tomoyo_write_aggregator - Write "struct tomoyo_aggregator" list.
|
2010-06-03 19:38:03 +08:00
|
|
|
*
|
2011-06-26 22:17:10 +08:00
|
|
|
* @param: Pointer to "struct tomoyo_acl_param".
|
2010-06-03 19:38:03 +08:00
|
|
|
*
|
|
|
|
* Returns 0 on success, negative value otherwise.
|
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
|
|
|
*/
|
2011-06-26 22:17:10 +08:00
|
|
|
int tomoyo_write_aggregator(struct tomoyo_acl_param *param)
|
2010-06-03 19:38:03 +08:00
|
|
|
{
|
2010-06-25 10:16:00 +08:00
|
|
|
struct tomoyo_aggregator e = { };
|
2011-06-26 22:17:10 +08:00
|
|
|
int error = param->is_delete ? -ENOENT : -ENOMEM;
|
|
|
|
const char *original_name = tomoyo_read_token(param);
|
|
|
|
const char *aggregated_name = tomoyo_read_token(param);
|
|
|
|
if (!tomoyo_correct_word(original_name) ||
|
2010-06-16 15:23:55 +08:00
|
|
|
!tomoyo_correct_path(aggregated_name))
|
2010-06-03 19:38:03 +08:00
|
|
|
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;
|
2011-06-26 22:17:10 +08:00
|
|
|
param->list = &tomoyo_policy_list[TOMOYO_ID_AGGREGATOR];
|
|
|
|
error = tomoyo_update_policy(&e.head, sizeof(e), param,
|
2010-06-25 10:16:00 +08:00
|
|
|
tomoyo_same_aggregator);
|
2011-06-26 22:17:10 +08:00
|
|
|
out:
|
2010-06-03 19:38:03 +08:00
|
|
|
tomoyo_put_name(e.original_name);
|
|
|
|
tomoyo_put_name(e.aggregated_name);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2009-02-05 16:18:15 +08:00
|
|
|
/**
|
2010-06-25 10:16:00 +08:00
|
|
|
* tomoyo_assign_domain - Create a domain.
|
2009-02-05 16:18:15 +08:00
|
|
|
*
|
|
|
|
* @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 08:34:43 +08:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 16:18:15 +08:00
|
|
|
*/
|
2010-06-25 10:16:00 +08:00
|
|
|
struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
|
|
|
|
const u8 profile)
|
2009-02-05 16:18:15 +08:00
|
|
|
{
|
2010-02-07 19:23:59 +08:00
|
|
|
struct tomoyo_domain_info *entry;
|
2010-05-05 23:18:15 +08:00
|
|
|
struct tomoyo_domain_info *domain = NULL;
|
2009-02-05 16:18:15 +08:00
|
|
|
const struct tomoyo_path_info *saved_domainname;
|
2010-02-07 19:23:59 +08:00
|
|
|
bool found = false;
|
2009-02-05 16:18:15 +08:00
|
|
|
|
2010-06-16 15:23:55 +08:00
|
|
|
if (!tomoyo_correct_domain(domainname))
|
2010-02-07 19:23:59 +08:00
|
|
|
return NULL;
|
2010-02-11 08:41:58 +08:00
|
|
|
saved_domainname = tomoyo_get_name(domainname);
|
2009-02-05 16:18:15 +08:00
|
|
|
if (!saved_domainname)
|
2010-02-07 19:23:59 +08:00
|
|
|
return NULL;
|
2010-04-28 13:17:42 +08:00
|
|
|
entry = kzalloc(sizeof(*entry), GFP_NOFS);
|
2010-05-05 23:18:15 +08:00
|
|
|
if (mutex_lock_interruptible(&tomoyo_policy_lock))
|
|
|
|
goto out;
|
2010-02-07 19:23:59 +08: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 08:41:58 +08:00
|
|
|
saved_domainname = NULL;
|
2010-02-07 19:23:59 +08:00
|
|
|
entry->profile = profile;
|
|
|
|
list_add_tail_rcu(&entry->list, &tomoyo_domain_list);
|
|
|
|
domain = entry;
|
|
|
|
entry = NULL;
|
|
|
|
found = true;
|
2009-02-05 16:18:15 +08:00
|
|
|
}
|
2010-01-03 20:16:32 +08:00
|
|
|
mutex_unlock(&tomoyo_policy_lock);
|
2010-05-05 23:18:15 +08:00
|
|
|
out:
|
2010-02-11 08:41:58 +08:00
|
|
|
tomoyo_put_name(saved_domainname);
|
2010-02-07 19:23:59 +08:00
|
|
|
kfree(entry);
|
|
|
|
return found ? domain : NULL;
|
2009-02-05 16:18:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tomoyo_find_next_domain - Find a domain.
|
|
|
|
*
|
2009-06-19 13:13:27 +08:00
|
|
|
* @bprm: Pointer to "struct linux_binprm".
|
2009-02-05 16:18:15 +08:00
|
|
|
*
|
|
|
|
* Returns 0 on success, negative value otherwise.
|
2009-12-08 08:34:43 +08:00
|
|
|
*
|
|
|
|
* Caller holds tomoyo_read_lock().
|
2009-02-05 16:18:15 +08:00
|
|
|
*/
|
2009-06-19 13:13:27 +08:00
|
|
|
int tomoyo_find_next_domain(struct linux_binprm *bprm)
|
2009-02-05 16:18:15 +08:00
|
|
|
{
|
2010-05-17 09:11:36 +08:00
|
|
|
struct tomoyo_request_info r;
|
2010-06-03 19:36:43 +08:00
|
|
|
char *tmp = kzalloc(TOMOYO_EXEC_TMPSIZE, GFP_NOFS);
|
2009-02-05 16:18:15 +08:00
|
|
|
struct tomoyo_domain_info *old_domain = tomoyo_domain();
|
|
|
|
struct tomoyo_domain_info *domain = NULL;
|
|
|
|
const char *original_name = bprm->filename;
|
2010-06-03 19:38:44 +08:00
|
|
|
u8 mode;
|
|
|
|
bool is_enforce;
|
2009-02-05 16:18:15 +08:00
|
|
|
int retval = -ENOMEM;
|
2010-06-03 19:36:43 +08:00
|
|
|
bool need_kfree = false;
|
|
|
|
struct tomoyo_path_info rn = { }; /* real name */
|
2009-02-05 16:18:15 +08:00
|
|
|
|
2010-06-03 19:38:44 +08:00
|
|
|
mode = tomoyo_init_request_info(&r, NULL, TOMOYO_MAC_FILE_EXECUTE);
|
|
|
|
is_enforce = (mode == TOMOYO_CONFIG_ENFORCING);
|
2009-02-05 16:18:15 +08:00
|
|
|
if (!tmp)
|
|
|
|
goto out;
|
|
|
|
|
2010-05-17 09:11:36 +08:00
|
|
|
retry:
|
2010-06-03 19:36:43 +08:00
|
|
|
if (need_kfree) {
|
|
|
|
kfree(rn.name);
|
|
|
|
need_kfree = false;
|
|
|
|
}
|
2010-06-21 08:58:53 +08:00
|
|
|
/* Get symlink's pathname of program. */
|
2009-02-05 16:18:15 +08:00
|
|
|
retval = -ENOENT;
|
2010-06-21 08:58:53 +08:00
|
|
|
rn.name = tomoyo_realpath_nofollow(original_name);
|
2010-06-03 19:36:43 +08:00
|
|
|
if (!rn.name)
|
2009-02-05 16:18:15 +08:00
|
|
|
goto out;
|
2010-06-03 19:36:43 +08:00
|
|
|
tomoyo_fill_path_info(&rn);
|
|
|
|
need_kfree = true;
|
|
|
|
|
2010-06-03 19:38:03 +08:00
|
|
|
/* Check 'aggregator' directive. */
|
|
|
|
{
|
2010-06-25 10:16:00 +08:00
|
|
|
struct tomoyo_aggregator *ptr;
|
2010-06-17 15:53:24 +08:00
|
|
|
list_for_each_entry_rcu(ptr, &tomoyo_policy_list
|
|
|
|
[TOMOYO_ID_AGGREGATOR], head.list) {
|
2010-06-15 08:22:42 +08:00
|
|
|
if (ptr->head.is_deleted ||
|
2010-06-03 19:38:03 +08:00
|
|
|
!tomoyo_path_matches_pattern(&rn,
|
|
|
|
ptr->original_name))
|
|
|
|
continue;
|
2010-06-21 08:58:53 +08:00
|
|
|
kfree(rn.name);
|
2010-06-03 19:38:03 +08:00
|
|
|
need_kfree = false;
|
|
|
|
/* This is OK because it is read only. */
|
|
|
|
rn = *ptr->aggregated_name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-05 16:18:15 +08:00
|
|
|
/* Check execute permission. */
|
2010-06-16 15:20:24 +08:00
|
|
|
retval = tomoyo_path_permission(&r, TOMOYO_TYPE_EXECUTE, &rn);
|
2010-05-17 09:11:36 +08:00
|
|
|
if (retval == TOMOYO_RETRY_REQUEST)
|
|
|
|
goto retry;
|
2009-02-05 16:18:15 +08:00
|
|
|
if (retval < 0)
|
|
|
|
goto out;
|
2010-07-29 13:29:55 +08:00
|
|
|
/*
|
|
|
|
* To be able to specify domainnames with wildcards, use the
|
|
|
|
* pathname specified in the policy (which may contain
|
|
|
|
* wildcard) rather than the pathname passed to execve()
|
|
|
|
* (which never contains wildcard).
|
|
|
|
*/
|
|
|
|
if (r.param.path.matched_path) {
|
|
|
|
if (need_kfree)
|
|
|
|
kfree(rn.name);
|
|
|
|
need_kfree = false;
|
|
|
|
/* This is OK because it is read only. */
|
|
|
|
rn = *r.param.path.matched_path;
|
|
|
|
}
|
2009-02-05 16:18:15 +08:00
|
|
|
|
2010-06-21 10:14:39 +08:00
|
|
|
/* Calculate domain to transit to. */
|
|
|
|
switch (tomoyo_transition_type(old_domain->domainname, &rn)) {
|
|
|
|
case TOMOYO_TRANSITION_CONTROL_INITIALIZE:
|
2009-02-05 16:18:15 +08:00
|
|
|
/* Transit to the child of tomoyo_kernel_domain domain. */
|
2010-06-21 10:14:39 +08:00
|
|
|
snprintf(tmp, TOMOYO_EXEC_TMPSIZE - 1, TOMOYO_ROOT_NAME " "
|
|
|
|
"%s", rn.name);
|
|
|
|
break;
|
|
|
|
case TOMOYO_TRANSITION_CONTROL_KEEP:
|
2009-02-05 16:18:15 +08:00
|
|
|
/* Keep current domain. */
|
|
|
|
domain = old_domain;
|
2010-06-21 10:14:39 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
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;
|
|
|
|
} else {
|
|
|
|
/* Normal domain transition. */
|
|
|
|
snprintf(tmp, TOMOYO_EXEC_TMPSIZE - 1, "%s %s",
|
|
|
|
old_domain->domainname->name, rn.name);
|
|
|
|
}
|
|
|
|
break;
|
2009-02-05 16:18:15 +08:00
|
|
|
}
|
2010-06-03 19:36:43 +08:00
|
|
|
if (domain || strlen(tmp) >= TOMOYO_EXEC_TMPSIZE - 10)
|
2009-02-05 16:18:15 +08:00
|
|
|
goto done;
|
2010-06-03 19:36:43 +08:00
|
|
|
domain = tomoyo_find_domain(tmp);
|
2011-06-26 22:15:31 +08:00
|
|
|
if (!domain)
|
|
|
|
domain = tomoyo_assign_domain(tmp, old_domain->profile);
|
2009-02-05 16:18:15 +08:00
|
|
|
done:
|
|
|
|
if (domain)
|
|
|
|
goto out;
|
2010-06-03 19:36:43 +08:00
|
|
|
printk(KERN_WARNING "TOMOYO-ERROR: Domain '%s' not defined.\n", tmp);
|
2009-02-05 16:18:15 +08:00
|
|
|
if (is_enforce)
|
|
|
|
retval = -EPERM;
|
|
|
|
else
|
2010-02-03 05:43:06 +08:00
|
|
|
old_domain->transition_failed = true;
|
2009-02-05 16:18:15 +08:00
|
|
|
out:
|
2009-06-19 13:13:27 +08:00
|
|
|
if (!domain)
|
|
|
|
domain = old_domain;
|
2010-02-11 08:43:20 +08:00
|
|
|
/* Update reference count on "struct tomoyo_domain_info". */
|
|
|
|
atomic_inc(&domain->users);
|
2009-06-19 13:13:27 +08:00
|
|
|
bprm->cred->security = domain;
|
2010-06-03 19:36:43 +08:00
|
|
|
if (need_kfree)
|
|
|
|
kfree(rn.name);
|
2010-01-26 19:45:27 +08:00
|
|
|
kfree(tmp);
|
2009-02-05 16:18:15 +08:00
|
|
|
return retval;
|
|
|
|
}
|