3 |
* |
* |
4 |
* Copyright (C) 2005-2010 NTT DATA CORPORATION |
* Copyright (C) 2005-2010 NTT DATA CORPORATION |
5 |
* |
* |
6 |
* Version: 1.7.2-pre 2010/03/02 |
* Version: 1.7.2-pre 2010/03/21 |
7 |
* |
* |
8 |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
9 |
* See README.ccs for ChangeLog. |
* See README.ccs for ChangeLog. |
262 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
263 |
if (ptr) |
if (ptr) |
264 |
return ptr; |
return ptr; |
265 |
entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
entry = kzalloc(sizeof(*entry), CCS_GFP_FLAGS); |
266 |
mutex_lock(&ccs_policy_lock); |
mutex_lock(&ccs_policy_lock); |
267 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
268 |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
287 |
/** |
/** |
288 |
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
289 |
*/ |
*/ |
290 |
void ccs_check_profile(void) |
static void ccs_check_profile(void) |
291 |
{ |
{ |
292 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain; |
293 |
ccs_policy_loaded = true; |
ccs_policy_loaded = true; |
301 |
if (ccs_profile_version != 20090903) |
if (ccs_profile_version != 20090903) |
302 |
panic("Profile version %u is not supported.\n", |
panic("Profile version %u is not supported.\n", |
303 |
ccs_profile_version); |
ccs_profile_version); |
304 |
|
printk(KERN_INFO "CCSecurity: 1.7.2-pre 2010/03/21\n"); |
305 |
|
printk(KERN_INFO "Mandatory Access Control activated.\n"); |
306 |
} |
} |
307 |
|
|
308 |
/** |
/** |
669 |
*/ |
*/ |
670 |
static int ccs_update_manager_entry(const char *manager, const bool is_delete) |
static int ccs_update_manager_entry(const char *manager, const bool is_delete) |
671 |
{ |
{ |
|
struct ccs_policy_manager_entry *entry = NULL; |
|
672 |
struct ccs_policy_manager_entry *ptr; |
struct ccs_policy_manager_entry *ptr; |
673 |
struct ccs_policy_manager_entry e = { }; |
struct ccs_policy_manager_entry e = { }; |
674 |
int error = is_delete ? -ENOENT : -ENOMEM; |
int error = is_delete ? -ENOENT : -ENOMEM; |
683 |
e.manager = ccs_get_name(manager); |
e.manager = ccs_get_name(manager); |
684 |
if (!e.manager) |
if (!e.manager) |
685 |
return -ENOMEM; |
return -ENOMEM; |
|
if (!is_delete) |
|
|
entry = kmalloc(sizeof(e), GFP_KERNEL); |
|
686 |
mutex_lock(&ccs_policy_lock); |
mutex_lock(&ccs_policy_lock); |
687 |
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
688 |
if (ptr->manager != e.manager) |
if (ptr->manager != e.manager) |
691 |
error = 0; |
error = 0; |
692 |
break; |
break; |
693 |
} |
} |
694 |
if (!is_delete && error && ccs_commit_ok(entry, &e, sizeof(e))) { |
if (!is_delete && error) { |
695 |
list_add_tail_rcu(&entry->list, &ccs_policy_manager_list); |
struct ccs_policy_manager_entry *entry = |
696 |
entry = NULL; |
ccs_commit_ok(&e, sizeof(e)); |
697 |
error = 0; |
if (entry) { |
698 |
|
list_add_tail_rcu(&entry->list, |
699 |
|
&ccs_policy_manager_list); |
700 |
|
error = 0; |
701 |
|
} |
702 |
} |
} |
703 |
mutex_unlock(&ccs_policy_lock); |
mutex_unlock(&ccs_policy_lock); |
704 |
ccs_put_name(e.manager); |
ccs_put_name(e.manager); |
|
kfree(entry); |
|
705 |
return error; |
return error; |
706 |
} |
} |
707 |
|
|
853 |
ccs_tasklist_lock(); |
ccs_tasklist_lock(); |
854 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
855 |
if (global_pid) |
if (global_pid) |
856 |
p = find_task_by_pid_ns(pid, &init_pid_ns); |
p = ccsecurity_exports.find_task_by_pid_ns(pid, |
857 |
|
&init_pid_ns); |
858 |
else |
else |
859 |
p = find_task_by_vpid(pid); |
p = ccsecurity_exports.find_task_by_vpid(pid); |
860 |
#else |
#else |
861 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
862 |
#endif |
#endif |
1824 |
ccs_tasklist_lock(); |
ccs_tasklist_lock(); |
1825 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
1826 |
if (global_pid) |
if (global_pid) |
1827 |
p = find_task_by_pid_ns(pid, &init_pid_ns); |
p = ccsecurity_exports.find_task_by_pid_ns(pid, &init_pid_ns); |
1828 |
else |
else |
1829 |
p = find_task_by_vpid(pid); |
p = ccsecurity_exports.find_task_by_vpid(pid); |
1830 |
#else |
#else |
1831 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
1832 |
#endif |
#endif |
2054 |
len += strlen(argv0) + 16; |
len += strlen(argv0) + 16; |
2055 |
} |
} |
2056 |
} |
} |
2057 |
buf = kmalloc(len, GFP_KERNEL); |
buf = kmalloc(len, CCS_GFP_FLAGS); |
2058 |
if (!buf) { |
if (!buf) { |
2059 |
kfree(realpath); |
kfree(realpath); |
2060 |
return NULL; |
return NULL; |
2100 |
symlink = r->obj->symlink_target->name; |
symlink = r->obj->symlink_target->name; |
2101 |
len += strlen(symlink) + 18; |
len += strlen(symlink) + 18; |
2102 |
} |
} |
2103 |
buf = kmalloc(len, GFP_KERNEL); |
buf = kmalloc(len, CCS_GFP_FLAGS); |
2104 |
if (!buf) |
if (!buf) |
2105 |
return NULL; |
return NULL; |
2106 |
snprintf(buf, len - 1, "if"); |
snprintf(buf, len - 1, "if"); |
2148 |
* @fmt: The printf()'s format string, followed by parameters. |
* @fmt: The printf()'s format string, followed by parameters. |
2149 |
* |
* |
2150 |
* Returns 0 if the supervisor decided to permit the access request which |
* Returns 0 if the supervisor decided to permit the access request which |
2151 |
* violated the policy in enforcing mode, 1 if the supervisor decided to |
* violated the policy in enforcing mode, CCS_RETRY_REQUEST if the supervisor |
2152 |
* retry the access request which violated the policy in enforcing mode, |
* decided to retry the access request which violated the policy in enforcing |
2153 |
* 0 if it is not in enforcing mode, -EPERM otherwise. |
* mode, 0 if it is not in enforcing mode, -EPERM otherwise. |
2154 |
*/ |
*/ |
2155 |
int ccs_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
int ccs_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
2156 |
{ |
{ |
2173 |
va_start(args, fmt); |
va_start(args, fmt); |
2174 |
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 4; |
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 4; |
2175 |
va_end(args); |
va_end(args); |
2176 |
buffer = kmalloc(len, GFP_KERNEL); |
buffer = kmalloc(len, CCS_GFP_FLAGS); |
2177 |
if (!buffer) |
if (!buffer) |
2178 |
return 0; |
return 0; |
2179 |
va_start(args, fmt); |
va_start(args, fmt); |
2213 |
header = ccs_init_audit_log(&len, r); |
header = ccs_init_audit_log(&len, r); |
2214 |
if (!header) |
if (!header) |
2215 |
goto out; |
goto out; |
2216 |
ccs_query_entry = kzalloc(sizeof(*ccs_query_entry), GFP_KERNEL); |
ccs_query_entry = kzalloc(sizeof(*ccs_query_entry), CCS_GFP_FLAGS); |
2217 |
if (!ccs_query_entry) |
if (!ccs_query_entry) |
2218 |
goto out; |
goto out; |
2219 |
len = ccs_round2(len); |
len = ccs_round2(len); |
2220 |
ccs_query_entry->query = kzalloc(len, GFP_KERNEL); |
ccs_query_entry->query = kzalloc(len, CCS_GFP_FLAGS); |
2221 |
if (!ccs_query_entry->query) |
if (!ccs_query_entry->query) |
2222 |
goto out; |
goto out; |
2223 |
INIT_LIST_HEAD(&ccs_query_entry->list); |
INIT_LIST_HEAD(&ccs_query_entry->list); |
2259 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2260 |
switch (ccs_query_entry->answer) { |
switch (ccs_query_entry->answer) { |
2261 |
case 3: /* Asked to retry by administrator. */ |
case 3: /* Asked to retry by administrator. */ |
2262 |
error = 1; |
error = CCS_RETRY_REQUEST; |
2263 |
r->retry++; |
r->retry++; |
2264 |
break; |
break; |
2265 |
case 1: |
case 1: |
2350 |
head->read_step = 0; |
head->read_step = 0; |
2351 |
return; |
return; |
2352 |
} |
} |
2353 |
buf = kzalloc(len, GFP_KERNEL); |
buf = kzalloc(len, CCS_GFP_FLAGS); |
2354 |
if (!buf) |
if (!buf) |
2355 |
return; |
return; |
2356 |
pos = 0; |
pos = 0; |
2457 |
*/ |
*/ |
2458 |
int ccs_open_control(const u8 type, struct file *file) |
int ccs_open_control(const u8 type, struct file *file) |
2459 |
{ |
{ |
2460 |
struct ccs_io_buffer *head = kzalloc(sizeof(*head), GFP_KERNEL); |
struct ccs_io_buffer *head = kzalloc(sizeof(*head), CCS_GFP_FLAGS); |
2461 |
if (!head) |
if (!head) |
2462 |
return -ENOMEM; |
return -ENOMEM; |
2463 |
mutex_init(&head->io_sem); |
mutex_init(&head->io_sem); |
2530 |
/* Don't allocate read_buf for poll() access. */ |
/* Don't allocate read_buf for poll() access. */ |
2531 |
if (!head->readbuf_size) |
if (!head->readbuf_size) |
2532 |
head->readbuf_size = 4096; |
head->readbuf_size = 4096; |
2533 |
head->read_buf = kzalloc(head->readbuf_size, GFP_KERNEL); |
head->read_buf = kzalloc(head->readbuf_size, CCS_GFP_FLAGS); |
2534 |
if (!head->read_buf) { |
if (!head->read_buf) { |
2535 |
kfree(head); |
kfree(head); |
2536 |
return -ENOMEM; |
return -ENOMEM; |
2544 |
head->write = NULL; |
head->write = NULL; |
2545 |
} else if (head->write) { |
} else if (head->write) { |
2546 |
head->writebuf_size = 4096; |
head->writebuf_size = 4096; |
2547 |
head->write_buf = kzalloc(head->writebuf_size, GFP_KERNEL); |
head->write_buf = kzalloc(head->writebuf_size, CCS_GFP_FLAGS); |
2548 |
if (!head->write_buf) { |
if (!head->write_buf) { |
2549 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2550 |
kfree(head); |
kfree(head); |
2552 |
} |
} |
2553 |
} |
} |
2554 |
if (type != CCS_QUERY && |
if (type != CCS_QUERY && |
2555 |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) { |
2556 |
head->reader_idx = ccs_read_lock(); |
spin_lock(&ccs_io_buffer_list_lock); |
2557 |
|
list_add(&head->list, &ccs_io_buffer_list); |
2558 |
|
spin_unlock(&ccs_io_buffer_list_lock); |
2559 |
|
} |
2560 |
file->private_data = head; |
file->private_data = head; |
2561 |
/* |
/* |
2562 |
* Call the handler now if the file is /proc/ccs/self_domain |
* Call the handler now if the file is /proc/ccs/self_domain |
2609 |
int len = 0; |
int len = 0; |
2610 |
struct ccs_io_buffer *head = file->private_data; |
struct ccs_io_buffer *head = file->private_data; |
2611 |
char *cp; |
char *cp; |
2612 |
|
int idx; |
2613 |
if (!head->read) |
if (!head->read) |
2614 |
return -ENOSYS; |
return -ENOSYS; |
2615 |
if (!access_ok(VERIFY_WRITE, buffer, buffer_len)) |
if (!access_ok(VERIFY_WRITE, buffer, buffer_len)) |
2616 |
return -EFAULT; |
return -EFAULT; |
2617 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2618 |
return -EINTR; |
return -EINTR; |
2619 |
|
idx = ccs_read_lock(); |
2620 |
while (1) { |
while (1) { |
2621 |
/* Call the policy handler. */ |
/* Call the policy handler. */ |
2622 |
head->read(head); |
head->read(head); |
2625 |
if (len || head->poll || head->read_eof) |
if (len || head->poll || head->read_eof) |
2626 |
break; |
break; |
2627 |
len = head->readbuf_size * 2; |
len = head->readbuf_size * 2; |
2628 |
cp = kzalloc(len, GFP_KERNEL); |
cp = kzalloc(len, CCS_GFP_FLAGS); |
2629 |
if (!cp) { |
if (!cp) { |
2630 |
len = -ENOMEM; |
len = -ENOMEM; |
2631 |
goto out; |
goto out; |
2647 |
head->read_avail -= len; |
head->read_avail -= len; |
2648 |
memmove(cp, cp + len, head->read_avail); |
memmove(cp, cp + len, head->read_avail); |
2649 |
out: |
out: |
2650 |
|
ccs_read_unlock(idx); |
2651 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
2652 |
return len; |
return len; |
2653 |
} |
} |
2668 |
int error = buffer_len; |
int error = buffer_len; |
2669 |
int avail_len = buffer_len; |
int avail_len = buffer_len; |
2670 |
char *cp0 = head->write_buf; |
char *cp0 = head->write_buf; |
2671 |
|
int idx; |
2672 |
if (!head->write) |
if (!head->write) |
2673 |
return -ENOSYS; |
return -ENOSYS; |
2674 |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) |
2680 |
return -EPERM; |
return -EPERM; |
2681 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2682 |
return -EINTR; |
return -EINTR; |
2683 |
|
idx = ccs_read_lock(); |
2684 |
/* Read a line and dispatch it to the policy handler. */ |
/* Read a line and dispatch it to the policy handler. */ |
2685 |
while (avail_len > 0) { |
while (avail_len > 0) { |
2686 |
char c; |
char c; |
2687 |
if (head->write_avail >= head->writebuf_size - 1) { |
if (head->write_avail >= head->writebuf_size - 1) { |
2688 |
const int len = head->writebuf_size * 2; |
const int len = head->writebuf_size * 2; |
2689 |
char *cp = kzalloc(len, GFP_KERNEL); |
char *cp = kzalloc(len, CCS_GFP_FLAGS); |
2690 |
if (!cp) { |
if (!cp) { |
2691 |
error = -ENOMEM; |
error = -ENOMEM; |
2692 |
break; |
break; |
2711 |
ccs_normalize_line(cp0); |
ccs_normalize_line(cp0); |
2712 |
head->write(head); |
head->write(head); |
2713 |
} |
} |
2714 |
|
ccs_read_unlock(idx); |
2715 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
2716 |
return error; |
return error; |
2717 |
} |
} |
2734 |
if (type == CCS_QUERY) |
if (type == CCS_QUERY) |
2735 |
atomic_dec(&ccs_query_observers); |
atomic_dec(&ccs_query_observers); |
2736 |
if (type != CCS_QUERY && |
if (type != CCS_QUERY && |
2737 |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) { |
2738 |
ccs_read_unlock(head->reader_idx); |
spin_lock(&ccs_io_buffer_list_lock); |
2739 |
|
list_del(&head->list); |
2740 |
|
spin_unlock(&ccs_io_buffer_list_lock); |
2741 |
|
} |
2742 |
/* Release memory used for policy I/O. */ |
/* Release memory used for policy I/O. */ |
2743 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2744 |
head->read_buf = NULL; |
head->read_buf = NULL; |
2747 |
kfree(head); |
kfree(head); |
2748 |
head = NULL; |
head = NULL; |
2749 |
file->private_data = NULL; |
file->private_data = NULL; |
2750 |
if (is_write) |
if (is_write) { |
2751 |
ccs_run_gc(); |
ccs_need_gc = 1; |
2752 |
|
wake_up(&ccs_gc_queue); |
2753 |
|
} |
2754 |
return 0; |
return 0; |
2755 |
} |
} |
2756 |
|
|
2757 |
|
void __init ccs_policy_io_init(void) |
2758 |
|
{ |
2759 |
|
ccsecurity_ops.check_profile = ccs_check_profile; |
2760 |
|
} |