This is TOMOYO Linux patch for Turbolinux 10 Server.
---
 arch/alpha/kernel/ptrace.c         |    5 +
 arch/arm/kernel/ptrace.c           |    5 +
 arch/arm26/kernel/ptrace.c         |    5 +
 arch/cris/arch-v10/kernel/ptrace.c |    6 ++
 arch/h8300/kernel/ptrace.c         |    6 ++
 arch/i386/kernel/ptrace.c          |    5 +
 arch/ia64/ia32/sys_ia32.c          |    3 +
 arch/ia64/kernel/ptrace.c          |    5 +
 arch/m68k/kernel/ptrace.c          |    6 ++
 arch/m68knommu/kernel/ptrace.c     |    6 ++
 arch/mips/kernel/ptrace.c          |    5 +
 arch/mips/kernel/ptrace32.c        |    5 +
 arch/parisc/kernel/ptrace.c        |    5 +
 arch/ppc/kernel/ptrace.c           |    5 +
 arch/ppc64/kernel/ptrace.c         |    5 +
 arch/ppc64/kernel/ptrace32.c       |    5 +
 arch/s390/kernel/ptrace.c          |    5 +
 arch/sh/kernel/ptrace.c            |    5 +
 arch/sh64/kernel/ptrace.c          |    6 ++
 arch/sparc/kernel/ptrace.c         |    7 ++
 arch/sparc64/kernel/ptrace.c       |    7 ++
 arch/um/kernel/ptrace.c            |    5 +
 arch/v850/kernel/ptrace.c          |    6 ++
 arch/x86_64/ia32/ptrace32.c        |    6 ++
 arch/x86_64/kernel/ptrace.c        |    5 +
 fs/Kconfig                         |    2 
 fs/Makefile                        |    2 
 fs/attr.c                          |   11 ----
 fs/compat.c                        |    9 ---
 fs/exec.c                          |   58 ++-------------------
 fs/fcntl.c                         |   11 +---
 fs/ioctl.c                         |    8 --
 fs/namei.c                         |  100 +++++++-----------------------------
 fs/namespace.c                     |   53 +++----------------
 fs/open.c                          |   68 ++++++++----------------
 fs/proc/Makefile                   |    3 -
 fs/proc/proc_misc.c                |   10 ---
 fs/stat.c                          |    2 
 include/linux/init_task.h          |   15 +++--
 include/linux/sched.h              |   17 ++----
 include/linux/security.h           |    1 
 kernel/fork.c                      |    5 +
 kernel/kmod.c                      |    7 --
 kernel/module.c                    |   14 +----
 kernel/sched.c                     |    8 --
 kernel/signal.c                    |   24 ++------
 kernel/sys.c                       |   25 +++------
 kernel/sysctl.c                    |  101 +++----------------------------------
 kernel/time.c                      |   19 ++----
 net/ipv4/raw.c                     |    5 +
 net/ipv4/tcp_ipv4.c                |   14 +----
 net/ipv4/udp.c                     |   20 +++----
 net/ipv6/raw.c                     |    5 +
 net/ipv6/tcp_ipv6.c                |    9 +--
 net/ipv6/udp.c                     |   18 +++---
 net/socket.c                       |   47 ++++++-----------
 net/unix/af_unix.c                 |   20 ++-----
 security/Kconfig                   |    2 
 security/Makefile                  |    3 +
 59 files changed, 333 insertions(+), 517 deletions(-)

--- linux-2.6.8-22.orig/arch/alpha/kernel/ptrace.c
+++ linux-2.6.8-22/arch/alpha/kernel/ptrace.c
@@ -259,6 +259,11 @@ do_sys_ptrace(long request, long pid, lo
 	unsigned long tmp;
 	size_t copied;
 	long ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	DBG(DBG_MEM, ("request=%ld pid=%ld addr=0x%lx data=0x%lx\n",
--- linux-2.6.8-22.orig/arch/arm/kernel/ptrace.c
+++ linux-2.6.8-22/arch/arm/kernel/ptrace.c
@@ -731,6 +731,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.8-22.orig/arch/arm26/kernel/ptrace.c
+++ linux-2.6.8-22/arch/arm26/kernel/ptrace.c
@@ -668,6 +668,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.8-22.orig/arch/cris/arch-v10/kernel/ptrace.c
+++ linux-2.6.8-22/arch/cris/arch-v10/kernel/ptrace.c
@@ -16,6 +16,7 @@
 #include <asm/pgtable.h>
 #include <asm/system.h>
 #include <asm/processor.h>
+#include <linux/ccsecurity.h>
 
 /* 
  * Determines which bits in DCCR the user has access to.
@@ -50,6 +51,11 @@ sys_ptrace(long request, long pid, long 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.8-22.orig/arch/h8300/kernel/ptrace.c
+++ linux-2.6.8-22/arch/h8300/kernel/ptrace.c
@@ -31,6 +31,7 @@
 #include <asm/system.h>
 #include <asm/processor.h>
 #include <asm/signal.h>
+#include <linux/ccsecurity.h>
 
 /* cpu depend functions */
 extern long h8300_get_reg(struct task_struct *task, int regno);
@@ -60,6 +61,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.8-22.orig/arch/i386/kernel/ptrace.c
+++ linux-2.6.8-22/arch/i386/kernel/ptrace.c
@@ -237,6 +237,11 @@ asmlinkage int sys_ptrace(long request, 
 	struct user * dummy = NULL;
 	int i, ret;
 	unsigned long __user *datap = (unsigned long __user *)data;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.8-22.orig/arch/ia64/ia32/sys_ia32.c
+++ linux-2.6.8-22/arch/ia64/ia32/sys_ia32.c
@@ -56,6 +56,7 @@
 #include <asm/types.h>
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
+#include <linux/ccsecurity.h>
 
 #include "ia32priv.h"
 
@@ -1790,6 +1791,8 @@ sys32_ptrace (int request, pid_t pid, un
 	struct task_struct *child;
 	unsigned int value, tmp;
 	long i, ret;
+	if (ccs_ptrace_permission(request, pid))
+		return -EPERM;
 
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
--- linux-2.6.8-22.orig/arch/ia64/kernel/ptrace.c
+++ linux-2.6.8-22/arch/ia64/kernel/ptrace.c
@@ -1280,6 +1280,11 @@ sys_ptrace (long request, pid_t pid, uns
 	struct task_struct *child;
 	struct switch_stack *sw;
 	long ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.8-22.orig/arch/m68k/kernel/ptrace.c
+++ linux-2.6.8-22/arch/m68k/kernel/ptrace.c
@@ -25,6 +25,7 @@
 #include <asm/pgtable.h>
 #include <asm/system.h>
 #include <asm/processor.h>
+#include <linux/ccsecurity.h>
 
 /*
  * does not yet catch signals sent when the child dies.
@@ -120,6 +121,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.8-22.orig/arch/m68knommu/kernel/ptrace.c
+++ linux-2.6.8-22/arch/m68knommu/kernel/ptrace.c
@@ -25,6 +25,7 @@
 #include <asm/pgtable.h>
 #include <asm/system.h>
 #include <asm/processor.h>
+#include <linux/ccsecurity.h>
 
 /*
  * does not yet catch signals sent when the child dies.
@@ -104,6 +105,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.8-22.orig/arch/mips/kernel/ptrace.c
+++ linux-2.6.8-22/arch/mips/kernel/ptrace.c
@@ -49,6 +49,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 #if 0
 	printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
--- linux-2.6.8-22.orig/arch/mips/kernel/ptrace32.c
+++ linux-2.6.8-22/arch/mips/kernel/ptrace32.c
@@ -42,6 +42,11 @@ asmlinkage int sys32_ptrace(int request,
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 #if 0
 	printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
--- linux-2.6.8-22.orig/arch/parisc/kernel/ptrace.c
+++ linux-2.6.8-22/arch/parisc/kernel/ptrace.c
@@ -84,6 +84,11 @@ long sys_ptrace(long request, pid_t pid,
 #ifdef DEBUG_PTRACE
 	long oaddr=addr, odata=data;
 #endif
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.8-22.orig/arch/ppc/kernel/ptrace.c
+++ linux-2.6.8-22/arch/ppc/kernel/ptrace.c
@@ -239,6 +239,11 @@ int sys_ptrace(long request, long pid, l
 {
 	struct task_struct *child;
 	int ret = -EPERM;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
--- linux-2.6.8-22.orig/arch/ppc64/kernel/ptrace.c
+++ linux-2.6.8-22/arch/ppc64/kernel/ptrace.c
@@ -54,6 +54,11 @@ int sys_ptrace(long request, long pid, l
 {
 	struct task_struct *child;
 	int ret = -EPERM;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
--- linux-2.6.8-22.orig/arch/ppc64/kernel/ptrace32.c
+++ linux-2.6.8-22/arch/ppc64/kernel/ptrace32.c
@@ -42,6 +42,11 @@ int sys32_ptrace(long request, long pid,
 {
 	struct task_struct *child;
 	int ret = -EPERM;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
--- linux-2.6.8-22.orig/arch/s390/kernel/ptrace.c
+++ linux-2.6.8-22/arch/s390/kernel/ptrace.c
@@ -667,6 +667,11 @@ sys_ptrace(long request, long pid, long 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 
--- linux-2.6.8-22.orig/arch/sh/kernel/ptrace.c
+++ linux-2.6.8-22/arch/sh/kernel/ptrace.c
@@ -85,6 +85,11 @@ asmlinkage int sys_ptrace(long request, 
 	struct task_struct *child;
 	struct user * dummy = NULL;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.8-22.orig/arch/sh64/kernel/ptrace.c
+++ linux-2.6.8-22/arch/sh64/kernel/ptrace.c
@@ -34,6 +34,7 @@
 #include <asm/system.h>
 #include <asm/processor.h>
 #include <asm/mmu_context.h>
+#include <linux/ccsecurity.h>
 
 /* This mask defines the bits of the SR which the user is not allowed to
    change, which are everything except S, Q, M, PR, SZ, FR. */
@@ -124,6 +125,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.8-22.orig/arch/sparc/kernel/ptrace.c
+++ linux-2.6.8-22/arch/sparc/kernel/ptrace.c
@@ -266,6 +266,13 @@ asmlinkage void do_ptrace(struct pt_regs
 	unsigned long addr2 = regs->u_regs[UREG_I4];
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc) {
+			pt_error_return(regs, -rc);
+			return;
+		}
+	}
 
 	lock_kernel();
 #ifdef DEBUG_PTRACE
--- linux-2.6.8-22.orig/arch/sparc64/kernel/ptrace.c
+++ linux-2.6.8-22/arch/sparc64/kernel/ptrace.c
@@ -112,6 +112,13 @@ asmlinkage void do_ptrace(struct pt_regs
 	unsigned long addr2 = regs->u_regs[UREG_I4];
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc) {
+			pt_error_return(regs, -rc);
+			return;
+		}
+	}
 
 	if (test_thread_flag(TIF_32BIT)) {
 		addr &= 0xffffffffUL;
--- linux-2.6.8-22.orig/arch/um/kernel/ptrace.c
+++ linux-2.6.8-22/arch/um/kernel/ptrace.c
@@ -28,6 +28,11 @@ int sys_ptrace(long request, long pid, l
 {
 	struct task_struct *child;
 	int i, ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.8-22.orig/arch/v850/kernel/ptrace.c
+++ linux-2.6.8-22/arch/v850/kernel/ptrace.c
@@ -28,6 +28,7 @@
 #include <asm/ptrace.h>
 #include <asm/processor.h>
 #include <asm/uaccess.h>
+#include <linux/ccsecurity.h>
 
 /* Returns the address where the register at REG_OFFS in P is stashed away.  */
 static v850_reg_t *reg_save_addr (unsigned reg_offs, struct task_struct *t)
@@ -116,6 +117,11 @@ int sys_ptrace(long request, long pid, l
 {
 	struct task_struct *child;
 	int rval;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 
--- linux-2.6.8-22.orig/arch/x86_64/ia32/ptrace32.c
+++ linux-2.6.8-22/arch/x86_64/ia32/ptrace32.c
@@ -27,6 +27,7 @@
 #include <asm/debugreg.h>
 #include <asm/i387.h>
 #include <asm/fpu32.h>
+#include <linux/ccsecurity.h>
 
 /* determines which flags the user has access to. */
 /* 1 = access 0 = no access */
@@ -232,6 +233,11 @@ asmlinkage long sys32_ptrace(long reques
 	void __user *datap = compat_ptr(data);
 	int ret;
 	__u32 val;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	switch (request) { 
 	default:
--- linux-2.6.8-22.orig/arch/x86_64/kernel/ptrace.c
+++ linux-2.6.8-22/arch/x86_64/kernel/ptrace.c
@@ -185,6 +185,11 @@ asmlinkage long sys_ptrace(long request,
 	struct task_struct *child;
 	long i, ret;
 	unsigned ui;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	/* This lock_kernel fixes a subtle race with suid exec */
 	lock_kernel();
--- linux-2.6.8-22.orig/fs/Kconfig
+++ linux-2.6.8-22/fs/Kconfig
@@ -1817,7 +1817,5 @@ endmenu
 
 source "fs/nls/Kconfig"
 
-source "fs/Kconfig.ccs"
-
 endmenu
 
--- linux-2.6.8-22.orig/fs/Makefile
+++ linux-2.6.8-22/fs/Makefile
@@ -96,5 +96,3 @@ obj-$(CONFIG_GFS_FS)		+= gfs/
 obj-$(CONFIG_SUPERMOUNT)	+= supermount/
 obj-$(CONFIG_HOSTFS)		+= hostfs/
 obj-$(CONFIG_HPPFS)		+= hppfs/
-
-include $(srctree)/fs/Makefile-2.6.ccs
--- linux-2.6.8-22.orig/fs/attr.c
+++ linux-2.6.8-22/fs/attr.c
@@ -14,9 +14,6 @@
 #include <linux/fcntl.h>
 #include <linux/quotaops.h>
 #include <linux/security.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 /* Taken over from the old code... */
 
@@ -172,20 +169,12 @@ int notify_change(struct dentry * dentry
 
 	if (inode->i_op && inode->i_op->setattr) {
 		error = security_inode_setattr(dentry, attr);
-		/***** TOMOYO Linux start. *****/
-		if (!error && (ia_valid & ATTR_MODE)) error = CheckCapabilityACL(TOMOYO_SYS_CHMOD);
-		if (!error && (ia_valid & (ATTR_UID | ATTR_GID))) error = CheckCapabilityACL(TOMOYO_SYS_CHOWN);
-		/***** TOMOYO Linux end. *****/
 		if (!error)
 			error = inode->i_op->setattr(dentry, attr);
 	} else {
 		error = inode_change_ok(inode, attr);
 		if (!error)
 			error = security_inode_setattr(dentry, attr);
-		/***** TOMOYO Linux start. *****/
-		if (!error && (ia_valid & ATTR_MODE)) error = CheckCapabilityACL(TOMOYO_SYS_CHMOD);
-		if (!error && (ia_valid & (ATTR_UID | ATTR_GID))) error = CheckCapabilityACL(TOMOYO_SYS_CHOWN);
-		/***** TOMOYO Linux end. *****/
 		if (!error) {
 			if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 			    (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
--- linux-2.6.8-22.orig/fs/compat.c
+++ linux-2.6.8-22/fs/compat.c
@@ -46,9 +46,7 @@
 
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
+#include <linux/ccsecurity.h>
 
 /*
  * Not all architectures have sys_utime, so implement this in terms
@@ -399,9 +397,6 @@ asmlinkage long compat_sys_ioctl(unsigne
 		error = sys_ioctl (fd, cmd, arg);
 		goto out;
 	}
-	/***** TOMOYO Linux start. *****/
-	if ((error = CheckCapabilityACL(TOMOYO_SYS_IOCTL)) < 0) goto out;
-	/***** TOMOYO Linux end. *****/
 
 	lock_kernel();
 
@@ -1433,7 +1428,7 @@ int compat_do_execve(char * filename,
 	if (retval < 0)
 		goto out;
 
-	retval = search_binary_handler(&bprm,regs);
+	retval = ccs_search_binary_handler(&bprm, regs);
 	if (retval >= 0) {
 		free_arg_pages(&bprm);
 
--- linux-2.6.8-22.orig/fs/exec.c
+++ linux-2.6.8-22/fs/exec.c
@@ -54,13 +54,6 @@
 #include <linux/kmod.h>
 #endif
 
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
-
 int core_uses_pid;
 char core_pattern[65] = "core";
 /* The maximal length of core_pattern is also specified in sysctl.c */
@@ -141,10 +134,9 @@ asmlinkage long sys_uselib(const char __
 	if (error)
 		goto exit;
 
-	/***** TOMOYO Linux start. *****/
-	error = CheckOpenPermission(nd.dentry, nd.mnt, 01); /* 01 means "read". */
-	if (error) goto exit;
-	/***** TOMOYO Linux end. *****/
+	error = ccs_uselib_permission(nd.dentry, nd.mnt);
+	if (error)
+		goto exit;
 
 	file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
 	error = PTR_ERR(file);
@@ -506,6 +498,9 @@ struct file *open_exec(const char *name)
 			int err = permission(inode, MAY_EXEC, &nd);
 			if (!err && !(inode->i_mode & 0111))
 				err = -EACCES;
+			if (!err)
+				err = ccs_open_exec_permission(nd.dentry,
+								     nd.mnt);
 			file = ERR_PTR(err);
 			if (!err) {
 				file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
@@ -1116,25 +1111,6 @@ int do_execve(char * filename,
 	struct file *file;
 	int retval;
 	int i;
-	/***** TOMOYO Linux start. *****/
-#ifdef CONFIG_TOMOYO
-	struct domain_info *next_domain = NULL;
-#endif
-	/***** TOMOYO Linux end. *****/
-
-	/***** CCS Start. *****/
-#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO)
-	extern void CCS_LoadPolicy(const char *filename);
-	CCS_LoadPolicy(filename);
-#endif
-	/***** CCS end. *****/
-
-	/***** SAKURA Linux start. *****/
-#ifdef CONFIG_SAKURA_DROP_CAPABILITY_API
-	if (strcmp(filename, "\\\\disable") == 0) return DropTaskCapability(argv);
-	if (CheckTaskCapability(SAKURA_DISABLE_EXECVE) < 0) return -EPERM;
-#endif
-	/***** SAKURA Linux end. *****/
 
 	file = open_exec(filename);
 
@@ -1142,15 +1118,6 @@ int do_execve(char * filename,
 	if (IS_ERR(file))
 		return retval;
 
-  	/***** TOMOYO Linux start. *****/
-#ifdef CONFIG_TOMOYO
-	retval = FindNextDomain(filename, file, &next_domain, argv);
-	if (retval < 0) {
-		allow_write_access(file); fput(file); return retval;
-	}
-#endif
-	/***** TOMOYO Linux end. *****/
-
 	sched_exec();
 
 	bprm.p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
@@ -1203,18 +1170,7 @@ int do_execve(char * filename,
 	if (retval < 0)
 		goto out;
 
-	retval = search_binary_handler(&bprm,regs);
-	/***** TOMOYO Linux start. *****/
-#ifdef CONFIG_TOMOYO
-	if (retval >= 0) current->domain_info = next_domain;
-#endif
-	/***** TOMOYO Linux end. *****/
-
-	/***** SAKURA Linux start. *****/
-#ifdef CONFIG_SAKURA_DROP_CAPABILITY_API
-	if (retval >= 0) RestoreTaskCapability();
-#endif
-	/***** SAKURA Linux end. *****/
+	retval = ccs_search_binary_handler(&bprm, regs);
 	if (retval >= 0) {
 		free_arg_pages(&bprm);
 
--- linux-2.6.8-22.orig/fs/fcntl.c
+++ linux-2.6.8-22/fs/fcntl.c
@@ -18,9 +18,6 @@
 #include <asm/poll.h>
 #include <asm/siginfo.h>
 #include <asm/uaccess.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 void fastcall set_close_on_exec(unsigned int fd, int flag)
 {
@@ -228,10 +225,6 @@ static int setfl(int fd, struct file * f
 	if (!(arg & O_APPEND) && IS_APPEND(inode))
 		return -EPERM;
 
-	/***** TOMOYO Linux start. *****/
-	if (!(arg & O_APPEND) && CheckReWritePermission(filp)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
-
 	/* O_NOATIME can only be set by the owner or superuser */
 	if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))
 		if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
@@ -381,6 +374,8 @@ asmlinkage long sys_fcntl(int fd, unsign
 		goto out;
 
 	err = security_file_fcntl(filp, cmd, arg);
+	if (!err)
+		err = ccs_fcntl_permission(filp, cmd, arg);
 	if (err) {
 		fput(filp);
 		return err;
@@ -405,6 +400,8 @@ asmlinkage long sys_fcntl64(unsigned int
 		goto out;
 
 	err = security_file_fcntl(filp, cmd, arg);
+	if (!err)
+		err = ccs_fcntl_permission(filp, cmd, arg);
 	if (err) {
 		fput(filp);
 		return err;
--- linux-2.6.8-22.orig/fs/ioctl.c
+++ linux-2.6.8-22/fs/ioctl.c
@@ -14,9 +14,6 @@
 
 #include <asm/uaccess.h>
 #include <asm/ioctls.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
 {
@@ -63,11 +60,10 @@ asmlinkage long sys_ioctl(unsigned int f
 	filp = fget(fd);
 	if (!filp)
 		goto out;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_IOCTL) < 0) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 
 	error = security_file_ioctl(filp, cmd, arg);
+	if (!error)
+		error = ccs_ioctl_permission(filp, cmd, arg);
 	if (error) {
                 fput(filp);
                 goto out;
--- linux-2.6.8-22.orig/fs/namei.c
+++ linux-2.6.8-22/fs/namei.c
@@ -32,13 +32,6 @@
 
 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
 
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
-
 /* [Feb-1997 T. Schoebel-Theuer]
  * Fundamental changes in the pathname lookup mechanisms (namei)
  * were necessary because of omirr.  The reason is that omirr needs
@@ -670,13 +663,6 @@ int fastcall link_path_walk(const char *
 
 	atomic = (lookup_flags & LOOKUP_ATOMIC);
 
-	/***** SAKURA Linux start. *****/
-	if (CheckEUID() < 0) {
-		path_release(nd);
-		return -EPERM;
-	}
-	/***** SAKURA Linux end. *****/
-
 	while (*name=='/')
 		name++;
 	if (!*name)
@@ -1245,9 +1231,6 @@ int vfs_create(struct inode *dir, struct
 	error = security_inode_create(dir, dentry, mode);
 	if (error)
 		return error;
-	/***** TOMOYO Linux start. *****/
-	if (nd && (error = CheckSingleWritePermission(TYPE_CREATE_ACL, dentry, nd->mnt)) < 0) return error;
-	/***** TOMOYO Linux end. *****/
 	DQUOT_INIT(dir);
 	error = dir->i_op->create(dir, dentry, mode, nd);
 	if (!error) {
@@ -1289,7 +1272,7 @@ int may_open(struct nameidata *nd, int a
 
 		flag &= ~O_TRUNC;
 	} else if (IS_RDONLY(inode) && (flag & FMODE_WRITE))
-		{ ROFS_Log_from_dentry(nd->dentry, nd->mnt, "may_open"); return -EROFS; } /***** ReadOnly Tracer *****/
+		return -EROFS;
 	/*
 	 * An append-only file must be opened in append mode for writing.
 	 */
@@ -1305,10 +1288,10 @@ int may_open(struct nameidata *nd, int a
 		if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
 			return -EPERM;
 
-	/***** TOMOYO Linux start. *****/
-	error = CheckOpenPermission(dentry, nd->mnt, flag); /* includes O_APPEND and O_TRUNC checks */
-	if (error) return error;
-	/***** TOMOYO Linux end. *****/
+	/* includes O_APPEND and O_TRUNC checks */
+	error = ccs_open_permission(dentry, nd->mnt, flag);
+	if (error)
+		return error;
 
 	/*
 	 * Ensure there are no outstanding leases on the file.
@@ -1341,9 +1324,6 @@ int may_open(struct nameidata *nd, int a
 	return 0;
 }
 
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo_vfs.h>
-/***** TOMOYO Linux end. *****/
 /*
  *	open_namei()
  *
@@ -1418,6 +1398,8 @@ do_last:
 	if (!dentry->d_inode) {
 		if (!IS_POSIXACL(dir->d_inode))
 			mode &= ~current->fs->umask;
+		error = ccs_mknod_permission(dentry, nd->mnt, mode, 0);
+		if (!error)
 		error = vfs_create(dir->d_inode, dentry, mode, nd);
 		up(&dir->d_inode->i_sem);
 		dput(nd->dentry);
@@ -1465,7 +1447,6 @@ ok:
 exit_dput:
 	dput(dentry);
 exit:
-	if (error == -EROFS) ROFS_Log_from_dentry(nd->dentry, nd->mnt, "open_namei"); /***** ReadOnly Tracer *****/
 	path_release(nd);
 	return error;
 
@@ -1589,12 +1570,6 @@ asmlinkage long sys_mknod(const char __u
 
 	if (S_ISDIR(mode))
 		return -EPERM;
-	/***** TOMOYO Linux start. *****/
-	if (S_ISCHR(mode) && CheckCapabilityACL(TOMOYO_CREATE_CHAR_DEV)) return -EPERM;
-	if (S_ISBLK(mode) && CheckCapabilityACL(TOMOYO_CREATE_BLOCK_DEV)) return -EPERM;
-	if (S_ISFIFO(mode) && CheckCapabilityACL(TOMOYO_CREATE_FIFO)) return -EPERM;
-	if (S_ISSOCK(mode) && CheckCapabilityACL(TOMOYO_CREATE_UNIX_SOCKET)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 	tmp = getname(filename);
 	if (IS_ERR(tmp))
 		return PTR_ERR(tmp);
@@ -1608,21 +1583,17 @@ asmlinkage long sys_mknod(const char __u
 	if (!IS_POSIXACL(nd.dentry->d_inode))
 		mode &= ~current->fs->umask;
 	if (!IS_ERR(dentry)) {
+		error = ccs_mknod_permission(dentry, nd.mnt, mode, dev);
+		if (!error)
 		switch (mode & S_IFMT) {
 		case 0: case S_IFREG:
 			error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
 			break;
 		case S_IFCHR: case S_IFBLK:
-			/***** TOMOYO Linux start. *****/
- 			if ((error = pre_vfs_mknod(nd.dentry->d_inode, dentry, mode)) == 0 && (error = CheckSingleWritePermission(S_ISCHR(mode) ? TYPE_MKCHAR_ACL : TYPE_MKBLOCK_ACL, dentry, nd.mnt)) == 0)
- 			/***** TOMOYO Linux end. *****/
 			error = vfs_mknod(nd.dentry->d_inode,dentry,mode,
 					new_decode_dev(dev));
 			break;
 		case S_IFIFO: case S_IFSOCK:
-			/***** TOMOYO Linux start. *****/
- 			if ((error = pre_vfs_mknod(nd.dentry->d_inode, dentry, mode)) == 0 && (error = CheckSingleWritePermission(S_ISFIFO(mode) ? TYPE_MKFIFO_ACL : TYPE_MKSOCK_ACL, dentry, nd.mnt)) == 0)
- 			/***** TOMOYO Linux end. *****/
 			error = vfs_mknod(nd.dentry->d_inode,dentry,mode,0);
 			break;
 		case S_IFDIR:
@@ -1631,7 +1602,6 @@ asmlinkage long sys_mknod(const char __u
 		default:
 			error = -EINVAL;
 		}
-		if (error == -EROFS) ROFS_Log_from_dentry(dentry, nd.mnt, "sys_mknod"); /***** ReadOnly Tracer *****/
 		dput(dentry);
 	}
 	up(&nd.dentry->d_inode->i_sem);
@@ -1685,11 +1655,9 @@ asmlinkage long sys_mkdir(const char __u
 		if (!IS_ERR(dentry)) {
 			if (!IS_POSIXACL(nd.dentry->d_inode))
 				mode &= ~current->fs->umask;
- 			/***** TOMOYO Linux start. *****/
- 			if ((error = pre_vfs_mkdir(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_MKDIR_ACL, dentry, nd.mnt)) == 0)
- 			/***** TOMOYO Linux end. *****/
+			error = ccs_mkdir_permission(dentry, nd.mnt, mode);
+			if (!error)
 			error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
-			if (error == -EROFS) ROFS_Log_from_dentry(dentry, nd.mnt, "sys_mkdir"); /***** ReadOnly Tracer *****/
 			dput(dentry);
 		}
 		up(&nd.dentry->d_inode->i_sem);
@@ -1797,11 +1765,9 @@ asmlinkage long sys_rmdir(const char __u
 	dentry = lookup_hash(&nd.last, nd.dentry);
 	error = PTR_ERR(dentry);
 	if (!IS_ERR(dentry)) {
-		/***** TOMOYO Linux start. *****/
-		if ((error = pre_vfs_rmdir(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_RMDIR_ACL, dentry, nd.mnt)) == 0)
-		/***** TOMOYO Linux end. *****/
+		error = ccs_rmdir_permission(dentry, nd.mnt);
+		if (!error)
 		error = vfs_rmdir(nd.dentry->d_inode, dentry);
-		if (error == -EROFS) ROFS_Log_from_dentry(dentry, nd.mnt, "sys_rmdir"); /***** ReadOnly Tracer *****/
 		dput(dentry);
 	}
 	up(&nd.dentry->d_inode->i_sem);
@@ -1855,9 +1821,6 @@ asmlinkage long sys_unlink(const char __
 	struct dentry *dentry;
 	struct nameidata nd;
 	struct inode *inode = NULL;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_UNLINK)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 
 	name = getname(pathname);
 	if(IS_ERR(name))
@@ -1879,11 +1842,9 @@ asmlinkage long sys_unlink(const char __
 		inode = dentry->d_inode;
 		if (inode)
 			atomic_inc(&inode->i_count);
-		/***** TOMOYO Linux start. *****/
- 		if ((error = pre_vfs_unlink(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_UNLINK_ACL, dentry, nd.mnt)) == 0)
- 		/***** TOMOYO Linux end. *****/
+		error = ccs_unlink_permission(dentry, nd.mnt);
+		if (!error)
 		error = vfs_unlink(nd.dentry->d_inode, dentry);
-		if (error == -EROFS) ROFS_Log_from_dentry(dentry, nd.mnt, "sys_unlink"); /***** ReadOnly Tracer *****/
 	exit2:
 		dput(dentry);
 	}
@@ -1931,9 +1892,6 @@ asmlinkage long sys_symlink(const char _
 	int error = 0;
 	char * from;
 	char * to;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_SYMLINK)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 
 	from = getname(oldname);
 	if(IS_ERR(from))
@@ -1950,11 +1908,9 @@ asmlinkage long sys_symlink(const char _
 		dentry = lookup_create(&nd, 0);
 		error = PTR_ERR(dentry);
 		if (!IS_ERR(dentry)) {
-			/***** TOMOYO Linux start. *****/
- 			if ((error = pre_vfs_symlink(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_SYMLINK_ACL, dentry, nd.mnt)) == 0)
- 			/***** TOMOYO Linux end. *****/
+			error = ccs_symlink_permission(dentry, nd.mnt, from);
+			if (!error)
 			error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
-			if (error == -EROFS) ROFS_Log_from_dentry(dentry, nd.mnt, "vfs_symlink"); /***** ReadOnly Tracer *****/
 			dput(dentry);
 		}
 		up(&nd.dentry->d_inode->i_sem);
@@ -2021,9 +1977,6 @@ asmlinkage long sys_link(const char __us
 	struct nameidata nd, old_nd;
 	int error;
 	char * to;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_LINK)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 
 	to = getname(newname);
 	if (IS_ERR(to))
@@ -2041,11 +1994,9 @@ asmlinkage long sys_link(const char __us
 	new_dentry = lookup_create(&nd, 0);
 	error = PTR_ERR(new_dentry);
 	if (!IS_ERR(new_dentry)) {
-		/***** TOMOYO Linux start. *****/
-		if ((error = pre_vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry)) == 0 && (error = CheckDoubleWritePermission(TYPE_LINK_ACL, old_nd.dentry, old_nd.mnt, new_dentry, nd.mnt)) == 0)
-		/***** TOMOYO Linux end. *****/
+		error = ccs_link_permission(old_nd.dentry, new_dentry, nd.mnt);
+		if (!error)
 		error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
-		if (error == -EROFS) ROFS_Log_from_dentry(new_dentry, nd.mnt, "vfs_link"); /***** ReadOnly Tracer *****/
 		dput(new_dentry);
 	}
 	up(&nd.dentry->d_inode->i_sem);
@@ -2267,13 +2218,8 @@ static inline int do_rename(const char *
 	if (new_dentry == trap)
 		goto exit5;
 
-	/***** TOMOYO Linux start. *****/
- 	if ((error = pre_vfs_rename(old_dir->d_inode, old_dentry, new_dir->d_inode, new_dentry)) < 0 ||
- 		(error = CheckDoubleWritePermission(TYPE_RENAME_ACL, old_dentry, oldnd.mnt, new_dentry, newnd.mnt)) < 0) {
- 		goto exit5;
- 	}
- 	/***** TOMOYO Linux end. *****/
- 
+	error = ccs_rename_permission(old_dentry, new_dentry, newnd.mnt);
+	if (!error)
 	error = vfs_rename(old_dir->d_inode, old_dentry,
 				   new_dir->d_inode, new_dentry);
 exit5:
@@ -2287,7 +2233,6 @@ exit2:
 exit1:
 	path_release(&oldnd);
 exit:
-	if (error == -EROFS) ROFS_Log(oldname, "do_rename"); /***** ReadOnly Tracer *****/
 	return error;
 }
 
@@ -2296,9 +2241,6 @@ asmlinkage long sys_rename(const char __
 	int error;
 	char * from;
 	char * to;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_RENAME)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 
 	from = getname(oldname);
 	if(IS_ERR(from))
--- linux-2.6.8-22.orig/fs/namespace.c
+++ linux-2.6.8-22/fs/namespace.c
@@ -23,12 +23,6 @@
 #include <linux/mount.h>
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 extern int __init init_rootfs(void);
 
@@ -377,13 +371,11 @@ static int do_umount(struct vfsmount *mn
 	int retval;
 
 	retval = security_sb_umount(mnt, flags);
+	if (!retval)
+		retval = ccs_umount_permission(mnt, flags);
 	if (retval)
 		return retval;
 
-	/***** SAKURA Linux start. *****/
-	if (SAKURA_MayUmount(mnt) < 0) return -EPERM;
-	/***** SAKURA Linux end. *****/
-
 	/*
 	 * Allow userspace to request a mountpoint be expired rather than
 	 * unmounting unconditionally. Unmount only happens if:
@@ -479,9 +471,6 @@ asmlinkage long sys_umount(char __user *
 {
 	struct nameidata nd;
 	int retval;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_UMOUNT)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 
 	retval = __user_walk(name, LOOKUP_FOLLOW, &nd);
 	if (retval)
@@ -647,10 +636,6 @@ static int do_loopback(struct nameidata 
 	down_write(&current->namespace->sem);
 	err = -EINVAL;
 	if (check_mnt(nd->mnt) && (!recurse || check_mnt(old_nd.mnt))) {
-		/***** SAKURA Linux start. *****/
-		err = -EPERM;
-		if (SAKURA_MayMount(nd) < 0 || CheckTaskCapability(SAKURA_DISABLE_MOUNT) < 0) goto out;
-		/***** SAKURA Linux end. *****/
 		err = -ENOMEM;
 		if (recurse)
 			mnt = copy_tree(old_nd.mnt, old_nd.dentry);
@@ -672,9 +657,6 @@ static int do_loopback(struct nameidata 
 		} else
 			mntput(mnt);
 	}
-	/***** SAKURA Linux start. *****/
- out:
-	/***** SAKURA Linux end. *****/
 	up_write(&current->namespace->sem);
 	path_release(&old_nd);
 	return err;
@@ -730,10 +712,7 @@ static int do_move_mount(struct nameidat
 	err = -EINVAL;
 	if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
 		goto out;
-	/***** SAKURA Linux start. *****/
-	err = -EPERM;
-	if (SAKURA_MayUmount(old_nd.mnt) < 0 || SAKURA_MayMount(nd) < 0 || CheckTaskCapability(SAKURA_DISABLE_MOUNT) < 0) goto out;
-	/***** SAKURA Linux end. *****/
+
 	err = -ENOENT;
 	down(&nd->dentry->d_inode->i_sem);
 	if (IS_DEADDIR(nd->dentry->d_inode))
@@ -827,10 +806,6 @@ int do_add_mount(struct vfsmount *newmnt
 	err = -EINVAL;
 	if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
 		goto unlock;
-	/***** SAKURA Linux start. *****/
-	err = -EPERM;
-	if (SAKURA_MayMount(nd) < 0 || CheckTaskCapability(SAKURA_DISABLE_MOUNT) < 0) goto unlock;
-	/***** SAKURA Linux end. *****/
 
 	newmnt->mnt_flags = mnt_flags;
 	err = graft_tree(newmnt, nd);
@@ -1034,6 +1009,7 @@ int copy_mount_options(const void __user
 long do_mount(char * dev_name, char * dir_name, char *type_page,
 		  unsigned long flags, void *data_page)
 {
+	const unsigned long original_flags = flags;
 	struct nameidata nd;
 	int retval = 0;
 	int mnt_flags = 0;
@@ -1067,6 +1043,9 @@ long do_mount(char * dev_name, char * di
 		return retval;
 
 	retval = security_sb_mount(dev_name, &nd, type_page, flags, data_page);
+	if (!retval)
+		retval = ccs_mount_permission(dev_name, &nd, type_page,
+					      original_flags, data_page);
 	if (retval)
 		goto dput_out;
 
@@ -1189,9 +1168,6 @@ asmlinkage long sys_mount(char __user * 
 	unsigned long type_page;
 	unsigned long dev_page;
 	char *dir_page;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_MOUNT)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 
 	retval = copy_mount_options (type, &type_page);
 	if (retval < 0)
@@ -1210,15 +1186,6 @@ asmlinkage long sys_mount(char __user * 
 	if (retval < 0)
 		goto out3;
 
-	/***** SAKURA Linux start. *****/
-	retval = -EPERM;
-	if (CheckMountPermission((char *) dev_page, dir_page, (char *) type_page, &flags) < 0 ||
- 		CheckTaskCapability(SAKURA_DISABLE_MOUNT) < 0) {
-		free_page(data_page);
-		goto out3;
-	}
-	/***** SAKURA Linux end. *****/
-
 	lock_kernel();
 	retval = do_mount((char*)dev_page, dir_page, (char*)type_page,
 			  flags, (void*)data_page);
@@ -1327,10 +1294,6 @@ asmlinkage long sys_pivot_root(const cha
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
 
-	/***** SAKURA Linux start. *****/
-	if (CheckPivotRootPermission() < 0 || CheckTaskCapability(SAKURA_DISABLE_PIVOTROOT) < 0) return -EPERM;
-	/***** SAKURA Linux end. *****/
-
 	lock_kernel();
 
 	error = __user_walk(new_root, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &new_nd);
@@ -1345,6 +1308,8 @@ asmlinkage long sys_pivot_root(const cha
 		goto out1;
 
 	error = security_sb_pivotroot(&old_nd, &new_nd);
+	if (!error)
+		error = ccs_pivot_root_permission(&old_nd, &new_nd);
 	if (error) {
 		path_release(&old_nd);
 		goto out1;
--- linux-2.6.8-22.orig/fs/open.c
+++ linux-2.6.8-22/fs/open.c
@@ -25,13 +25,6 @@
 
 #include <asm/unistd.h>
 
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
-
 int vfs_statfs(struct super_block *sb, struct kstatfs *buf)
 {
 	int retval = -ENODEV;
@@ -264,9 +257,8 @@ static inline long do_sys_truncate(const
 	if (error)
 		goto dput_and_out;
 
-	/***** TOMOYO Linux start. *****/
-	if ((error = CheckSingleWritePermission(TYPE_TRUNCATE_ACL, nd.dentry, nd.mnt)) == 0)
-	/***** TOMOYO Linux end. *****/
+	error = ccs_truncate_permission(nd.dentry, nd.mnt);
+	if (!error)
 	error = locks_verify_truncate(inode, NULL, length);
 	if (!error) {
 		DQUOT_INIT(inode);
@@ -275,7 +267,6 @@ static inline long do_sys_truncate(const
 	put_write_access(inode);
 
 dput_and_out:
-	if (error == -EROFS) ROFS_Log_from_dentry(nd.dentry, nd.mnt, "do_sys_truncate"); /***** ReadOnly Tracer *****/
 	path_release(&nd);
 out:
 	return error;
@@ -321,14 +312,13 @@ static inline long do_sys_ftruncate(unsi
 	if (IS_APPEND(inode))
 		goto out_putf;
 
-	/***** TOMOYO Linux start. *****/
-	if ((error = CheckSingleWritePermission(TYPE_TRUNCATE_ACL, dentry, file->f_vfsmnt)) == 0)
-	/***** TOMOYO Linux end. *****/
+	error = ccs_truncate_permission(dentry, file->f_vfsmnt);
+	if (error)
+		goto out_putf;
 	error = locks_verify_truncate(inode, file, length);
 	if (!error)
 		error = do_truncate(dentry, length);
 out_putf:
-	if (error == -EROFS) ROFS_Log_from_dentry(file->f_dentry, file->f_vfsmnt, "do_sys_ftruncate"); /***** ReadOnly Tracer *****/
 	fput(file);
 out:
 	return error;
@@ -410,7 +400,6 @@ asmlinkage long sys_utime(char __user * 
 	error = notify_change(nd.dentry, &newattrs);
 	up(&inode->i_sem);
 dput_and_out:
-	if (error == -EROFS) ROFS_Log_from_dentry(nd.dentry, nd.mnt, "sys_utime"); /***** ReadOnly Tracer *****/
 	path_release(&nd);
 out:
 	return error;
@@ -464,7 +453,6 @@ long do_utimes(char __user * filename, s
 	error = notify_change(nd.dentry, &newattrs);
 	up(&inode->i_sem);
 dput_and_out:
-	if (error == -EROFS) ROFS_Log_from_dentry(nd.dentry, nd.mnt, "sys_utimes"); /***** ReadOnly Tracer *****/
 	path_release(&nd);
 out:
 	return error;
@@ -522,9 +510,6 @@ asmlinkage long sys_access(const char __
 		if(!res && (mode & S_IWOTH) && IS_RDONLY(nd.dentry->d_inode)
 		   && !special_file(nd.dentry->d_inode->i_mode))
 			res = -EROFS;
-#if 0
-		if (res == -EROFS) ROFS_Log_from_dentry(nd.dentry, nd.mnt, "sys_access"); /***** ReadOnly Tracer *****/
-#endif
 		path_release(&nd);
 	}
 
@@ -590,9 +575,6 @@ asmlinkage long sys_chroot(const char __
 {
 	struct nameidata nd;
 	int error;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_CHROOT)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 
 	error = __user_walk(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd);
 	if (error)
@@ -605,19 +587,8 @@ asmlinkage long sys_chroot(const char __
 	error = -EPERM;
 	if (!capable(CAP_SYS_CHROOT))
 		goto dput_and_out;
-
-	/***** SAKURA Linux start. *****/
-    {
-        char *name = getname(filename);
-        if (!IS_ERR(name)) {
-            error = CheckChRootPermission(name) | CheckTaskCapability(SAKURA_DISABLE_CHROOT);
-            putname(name);
-        } else {
-            error = PTR_ERR(name);
-        }
-        if (error < 0) goto dput_and_out;
-    }
-	/***** SAKURA Linux end. *****/
+	if (ccs_chroot_permission(&nd))
+		goto dput_and_out;
 
 	set_fs_root(current->fs, nd.mnt, nd.dentry);
 	set_fs_altroot();
@@ -649,6 +620,9 @@ asmlinkage long sys_fchmod(unsigned int 
 	err = -EPERM;
 	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
 		goto out_putf;
+	err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode);
+	if (err)
+		goto out_putf;
 	down(&inode->i_sem);
 	if (mode == (mode_t) -1)
 		mode = inode->i_mode;
@@ -658,7 +632,6 @@ asmlinkage long sys_fchmod(unsigned int 
 	up(&inode->i_sem);
 
 out_putf:
-	if (err == -EROFS) ROFS_Log_from_dentry(file->f_dentry, file->f_vfsmnt, "sys_fchmod"); /***** ReadOnly Tracer *****/
 	fput(file);
 out:
 	return err;
@@ -683,6 +656,9 @@ asmlinkage long sys_chmod(const char __u
 	error = -EPERM;
 	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
 		goto dput_and_out;
+	error = ccs_chmod_permission(nd.dentry, nd.mnt, mode);
+	if (error)
+		goto dput_and_out;
 
 	down(&inode->i_sem);
 	if (mode == (mode_t) -1)
@@ -693,7 +669,6 @@ asmlinkage long sys_chmod(const char __u
 	up(&inode->i_sem);
 
 dput_and_out:
-	if (error == -EROFS) ROFS_Log_from_dentry(nd.dentry, nd.mnt, "sys_chmod"); /***** ReadOnly Tracer *****/
 	path_release(&nd);
 out:
 	return error;
@@ -741,8 +716,9 @@ asmlinkage long sys_chown(const char __u
 
 	error = user_path_walk(filename, &nd);
 	if (!error) {
+		error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
+		if (!error)
 		error = chown_common(nd.dentry, user, group);
-		if (error == -EROFS) ROFS_Log_from_dentry(nd.dentry, nd.mnt, "sys_chown"); /***** ReadOnly Tracer *****/
 		path_release(&nd);
 	}
 	return error;
@@ -755,8 +731,9 @@ asmlinkage long sys_lchown(const char __
 
 	error = user_path_walk_link(filename, &nd);
 	if (!error) {
+		error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
+		if (!error)
 		error = chown_common(nd.dentry, user, group);
-		if (error == -EROFS) ROFS_Log_from_dentry(nd.dentry, nd.mnt, "sys_lchown"); /***** ReadOnly Tracer *****/
 		path_release(&nd);
 	}
 	return error;
@@ -770,8 +747,10 @@ asmlinkage long sys_fchown(unsigned int 
 
 	file = fget(fd);
 	if (file) {
+		error = ccs_chown_permission(file->f_dentry, file->f_vfsmnt,
+					     user, group);
+		if (!error)
 		error = chown_common(file->f_dentry, user, group);
-		if (error == -EROFS) ROFS_Log_from_dentry(file->f_dentry, file->f_vfsmnt, "sys_fchown"); /***** ReadOnly Tracer *****/
 		fput(file);
 	}
 	return error;
@@ -802,7 +781,9 @@ struct file *filp_open(const char * file
 	if (namei_flags & O_TRUNC)
 		namei_flags |= 2;
 
+	ccs_save_open_mode(flags);
 	error = open_namei(filename, namei_flags, mode, &nd);
+	ccs_clear_open_mode();
 	if (!error)
 		return dentry_open(nd.dentry, nd.mnt, flags);
 
@@ -1090,9 +1071,8 @@ EXPORT_SYMBOL(sys_close);
  */
 asmlinkage long sys_vhangup(void)
 {
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_VHANGUP) == 0)
-	/***** TOMOYO Linux end. *****/
+	if (!ccs_capable(CCS_SYS_VHANGUP))
+		return -EPERM;
 	if (capable(CAP_SYS_TTY_CONFIG)) {
 		tty_vhangup(current->signal->tty);
 		return 0;
--- linux-2.6.8-22.orig/fs/proc/Makefile
+++ linux-2.6.8-22/fs/proc/Makefile
@@ -12,6 +12,3 @@ proc-y       += inode.o root.o base.o ge
 
 proc-$(CONFIG_PROC_KCORE)	+= kcore.o
 proc-$(CONFIG_PROC_DEVICETREE)	+= proc_devtree.o
-
-proc-$(CONFIG_SAKURA) += ccs_proc.o
-proc-$(CONFIG_TOMOYO) += ccs_proc.o
--- linux-2.6.8-22.orig/fs/proc/proc_misc.c
+++ linux-2.6.8-22/fs/proc/proc_misc.c
@@ -641,13 +641,5 @@ void __init proc_misc_init(void)
 			entry->proc_fops = &ppc_htab_operations;
 	}
 #endif
-	/***** CCS start. *****/
-#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO)
-	{
-		extern void CCSProc_Init(void);
-		CCSProc_Init();
-		printk("Hook version: 2.6.8-12 2006/12/25\n");
-	}
-#endif
-	/***** CCS end. *****/
+	printk(KERN_INFO "Hook version: 2.6.8-22 2012/03/08\n");
 }
--- linux-2.6.8-22.orig/fs/stat.c
+++ linux-2.6.8-22/fs/stat.c
@@ -43,6 +43,8 @@ int vfs_getattr(struct vfsmount *mnt, st
 	int retval;
 
 	retval = security_inode_getattr(mnt, dentry);
+	if (!retval)
+		retval = ccs_getattr_permission(mnt, dentry);
 	if (retval)
 		return retval;
 
--- linux-2.6.8-22.orig/include/linux/init_task.h
+++ linux-2.6.8-22/include/linux/init_task.h
@@ -60,6 +60,14 @@
 
 extern struct group_info init_groups;
 
+#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY)
+#define INIT_CCSECURITY          \
+	.ccs_domain_info = NULL, \
+	.ccs_flags = 0,
+#else
+#define INIT_CCSECURITY
+#endif
+
 /*
  *  INIT_TASK is used to set up the first task table, touch at
  * your own risk!. Base=0, limit=0x1fffff (=2MB)
@@ -112,12 +120,7 @@ extern struct group_info init_groups;
 	.proc_lock	= SPIN_LOCK_UNLOCKED,				\
 	.switch_lock	= SPIN_LOCK_UNLOCKED,				\
 	.journal_info	= NULL,						\
- 	/***** TOMOYO Linux start. *****/        \
- 	.domain_info = &KERNEL_DOMAIN,           \
- 	/***** TOMOYO Linux end. *****/          \
- 	/***** SAKURA Linux start. *****/        \
- 	.dropped_capability = 0,                 \
- 	/***** SAKURA Linux end. *****/          \
+	INIT_CCSECURITY                                                 \
 }
 
 
--- linux-2.6.8-22.orig/include/linux/sched.h
+++ linux-2.6.8-22/include/linux/sched.h
@@ -32,11 +32,6 @@
 
 struct exec_domain;
 
-/***** TOMOYO Linux start. *****/
-struct domain_info;
-extern struct domain_info KERNEL_DOMAIN;
-/***** TOMOYO Linux end. *****/
-
 /*
  * cloning flags:
  */
@@ -138,6 +133,8 @@ struct sched_param {
 
 #ifdef __KERNEL__
 
+struct ccs_domain_info;
+
 #include <linux/spinlock.h>
 
 /*
@@ -595,12 +592,10 @@ struct task_struct {
   	struct mempolicy *mempolicy;
   	short il_next;		/* could be shared with used_math */
 #endif
-	/***** TOMOYO Linux start. *****/
-	struct domain_info *domain_info;
-	/***** TOMOYO Linux end. *****/
-	/***** SAKURA Linux start. *****/
-	unsigned int dropped_capability;
-	/***** SAKURA Linux end. *****/
+#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY)
+	struct ccs_domain_info *ccs_domain_info;
+	u32 ccs_flags;
+#endif
 
 	struct list_head        *scm_work_list;
 };
--- linux-2.6.8-22.orig/include/linux/security.h
+++ linux-2.6.8-22/include/linux/security.h
@@ -33,6 +33,7 @@
 #include <linux/sched.h>
 #include <linux/skbuff.h>
 #include <linux/netlink.h>
+#include <linux/ccsecurity.h>
 
 /*
  * These functions are in security/capability.c and are used
--- linux-2.6.8-22.orig/kernel/fork.c
+++ linux-2.6.8-22/kernel/fork.c
@@ -96,6 +96,7 @@ void __put_task_struct(struct task_struc
 	free_uid(tsk->user);
 	put_group_info(tsk->group_info);
 
+	ccs_free_task_security(tsk);
 	if (!profile_handoff_task(tsk))
 		free_task(tsk);
 }
@@ -888,6 +889,9 @@ static task_t *copy_process(unsigned lon
 		goto bad_fork_cleanup_policy;
 	if ((retval = audit_alloc(p)))
 		goto bad_fork_cleanup_security;
+	retval = ccs_alloc_task_security(p);
+	if (retval)
+		goto bad_fork_cleanup_audit;
 	/* copy all the process information */
 	if ((retval = copy_semundo(clone_flags, p)))
 		goto bad_fork_cleanup_audit;
@@ -1040,6 +1044,7 @@ bad_fork_cleanup_semundo:
 	exit_sem(p);
 bad_fork_cleanup_audit:
 	audit_free(p);
+	ccs_free_task_security(p);
 bad_fork_cleanup_security:
 	security_task_free(p);
 bad_fork_cleanup_policy:
--- linux-2.6.8-22.orig/kernel/kmod.c
+++ linux-2.6.8-22/kernel/kmod.c
@@ -166,13 +166,6 @@ static int ____call_usermodehelper(void 
 	/* We can run anywhere, unlike our parent keventd(). */
 	set_cpus_allowed(current, CPU_MASK_ALL);
 
-	/***** TOMOYO Linux start. *****/
-	current->domain_info = &KERNEL_DOMAIN;
-	/***** TOMOYO Linux start. *****/
-	/***** SAKURA Linux start. *****/
-	current->dropped_capability = 0;
-	/***** SAKURA Linux end. *****/
-
 	retval = -EPERM;
 	if (current->fs->root)
 		retval = execve(sub_info->path, sub_info->argv,sub_info->envp);
--- linux-2.6.8-22.orig/kernel/module.c
+++ linux-2.6.8-22/kernel/module.c
@@ -37,9 +37,7 @@
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
 #include <asm/cacheflush.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
+#include <linux/ccsecurity.h>
 
 #if 0
 #define DEBUGP printk
@@ -562,9 +560,8 @@ sys_delete_module(const char __user *nam
 
 	if (!capable(CAP_SYS_MODULE))
 		return -EPERM;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_USE_KERNEL_MODULE)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (!ccs_capable(CCS_USE_KERNEL_MODULE))
+		return -EPERM;
 	if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
 		return -EFAULT;
 	name[MODULE_NAME_LEN-1] = '\0';
@@ -1850,9 +1847,8 @@ sys_init_module(void __user *umod,
 	/* Must have permission */
 	if (!capable(CAP_SYS_MODULE))
 		return -EPERM;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_USE_KERNEL_MODULE)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (!ccs_capable(CCS_USE_KERNEL_MODULE))
+		return -EPERM;
 	/* Only one module load at a time, please */
 	if (down_interruptible(&module_mutex) != 0)
 		return -EINTR;
--- linux-2.6.8-22.orig/kernel/sched.c
+++ linux-2.6.8-22/kernel/sched.c
@@ -46,9 +46,6 @@
 #include <asm/tlb.h>
 
 #include <asm/unistd.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 #ifdef CONFIG_NUMA
 #define cpu_to_node_mask(cpu) node_to_cpumask(cpu_to_node(cpu))
@@ -3126,9 +3123,8 @@ asmlinkage long sys_nice(int increment)
 {
 	int retval;
 	long nice;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_NICE)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (!ccs_capable(CCS_SYS_NICE))
+		return -EPERM;
 
 	/*
 	 * Setpriority might change our priority at the same moment.
--- linux-2.6.8-22.orig/kernel/signal.c
+++ linux-2.6.8-22/kernel/signal.c
@@ -25,9 +25,6 @@
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
 #include <asm/siginfo.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 extern void k_getrusage(struct task_struct *, int, struct rusage *);
 
@@ -2250,10 +2247,8 @@ asmlinkage long
 sys_kill(int pid, int sig)
 {
 	struct siginfo info;
-	/***** TOMOYO Linux start. *****/
-	if (sig && CheckCapabilityACL(TOMOYO_SYS_KILL) < 0) return -EPERM;
-	if (sig && CheckSignalACL(sig, pid) < 0) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (ccs_kill_permission(pid, sig))
+		return -EPERM;
 
 	info.si_signo = sig;
 	info.si_errno = 0;
@@ -2283,12 +2278,9 @@ asmlinkage long sys_tgkill(int tgid, int
 	/* This is only valid for single tasks */
 	if (pid <= 0 || tgid <= 0)
 		return -EINVAL;
+	if (ccs_tgkill_permission(tgid, pid, sig))
+		return -EPERM;
 
-	/***** TOMOYO Linux start. *****/
-	if (sig && CheckCapabilityACL(TOMOYO_SYS_KILL) < 0) return -EPERM;
-	if (sig && CheckSignalACL(sig, pid) < 0) return -EPERM;
-	/***** TOMOYO Linux end. *****/
-	
 	info.si_signo = sig;
 	info.si_errno = 0;
 	info.si_code = SI_TKILL;
@@ -2328,11 +2320,9 @@ sys_tkill(int pid, int sig)
 	/* This is only valid for single tasks */
 	if (pid <= 0)
 		return -EINVAL;
+	if (ccs_tkill_permission(pid, sig))
+		return -EPERM;
 
-	/***** TOMOYO Linux start. *****/
-	if (sig && CheckCapabilityACL(TOMOYO_SYS_KILL) < 0) return -EPERM;
-	if (sig && CheckSignalACL(sig, pid) < 0) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 	info.si_signo = sig;
 	info.si_errno = 0;
 	info.si_code = SI_TKILL;
@@ -2372,6 +2362,8 @@ sys_rt_sigqueueinfo(int pid, int sig, si
 	if (info.si_code >= 0)
 		return -EPERM;
 	info.si_signo = sig;
+	if (ccs_sigqueue_permission(pid, sig))
+		return -EPERM;
 
 	/* POSIX.1b doesn't mention process groups.  */
 	return kill_proc_info(sig, &info, pid);
--- linux-2.6.8-22.orig/kernel/sys.c
+++ linux-2.6.8-22/kernel/sys.c
@@ -28,9 +28,6 @@
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <asm/unistd.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 #ifndef SET_UNALIGN_CTL
 # define SET_UNALIGN_CTL(a,b)	(-EINVAL)
@@ -320,9 +317,10 @@ asmlinkage long sys_setpriority(int whic
 
 	if (which > 2 || which < 0)
 		goto out;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_NICE)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (!ccs_capable(CCS_SYS_NICE)) {
+		error = -EPERM;
+		goto out;
+	}
 
 	/* normalize: avoid signed division (rounding problems) */
 	error = -ESRCH;
@@ -457,9 +455,8 @@ asmlinkage long sys_reboot(int magic1, i
 			magic2 != LINUX_REBOOT_MAGIC2B &&
 	                magic2 != LINUX_REBOOT_MAGIC2C))
 		return -EINVAL;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_REBOOT)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (!ccs_capable(CCS_SYS_REBOOT))
+		return -EPERM;
 
 	lock_kernel();
 	switch (cmd) {
@@ -1449,9 +1446,8 @@ asmlinkage long sys_sethostname(char __u
 		return -EPERM;
 	if (len < 0 || len > __NEW_UTS_LEN)
 		return -EINVAL;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_SETHOSTNAME)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (!ccs_capable(CCS_SYS_SETHOSTNAME))
+		return -EPERM;
 	down_write(&uts_sem);
 	errno = -EFAULT;
 	if (!copy_from_user(tmp, name, len)) {
@@ -1497,9 +1493,8 @@ asmlinkage long sys_setdomainname(char _
 		return -EPERM;
 	if (len < 0 || len > __NEW_UTS_LEN)
 		return -EINVAL;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_SETHOSTNAME)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (!ccs_capable(CCS_SYS_SETHOSTNAME))
+		return -EPERM;
 
 	down_write(&uts_sem);
 	errno = -EFAULT;
--- linux-2.6.8-22.orig/kernel/sysctl.c
+++ linux-2.6.8-22/kernel/sysctl.c
@@ -43,9 +43,6 @@
 
 #include <asm/uaccess.h>
 #include <asm/processor.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 #ifdef CONFIG_ROOT_NFS
 #include <linux/nfs_fs.h>
@@ -985,87 +982,6 @@ void __init sysctl_init(void)
 #endif
 }
 
-/***** TOMOYO Linux start. *****/
-static int try_parse_table(int __user *name, int nlen, void __user *oldval, void __user *newval, ctl_table *table)
-{
-	int n;
-	int error = -ENOMEM;
-	int op = 0;
-	char *buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
-	if (oldval) op |= 004;
-	if (newval) op |= 002;
-	if (!op) { /* Neither read nor write */
-		error = 0;
-		goto out;
-	}
-	if (!buffer) goto out;
-	memset(buffer, 0, PAGE_SIZE);
-	snprintf(buffer, PAGE_SIZE - 1, "/proc/sys");
- repeat:
-	if (!nlen) {
-		error = -ENOTDIR;
-		goto out;
-	}
-	if (get_user(n, name)) {
-		error = -EFAULT;
-		goto out;
-	}
-	for ( ; table->ctl_name; table++) {
-		if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
-			int pos = strlen(buffer);
-			const char *cp = table->procname;
-			error = -ENOMEM;
-			if (cp) {
-				if (pos + 1 >= PAGE_SIZE - 1) goto out;
-				buffer[pos++] = '/';
-				while (*cp) {
-					const unsigned char c = * (const unsigned char *) cp;
-					if (c == '\\') {
-						if (pos + 2 >= PAGE_SIZE - 1) goto out;
-						buffer[pos++] = '\\';
-						buffer[pos++] = '\\';
-					} else if (c > ' ' && c < 127) {
-						if (pos + 1 >= PAGE_SIZE - 1) goto out;
-						buffer[pos++] = c;
-					} else {
-						if (pos + 4 >= PAGE_SIZE - 1) goto out;
-						buffer[pos++] = '\\';
-						buffer[pos++] = (c >> 6) + '0';
-						buffer[pos++] = ((c >> 3) & 7) + '0';
-						buffer[pos++] = (c & 7) + '0';
-					}
-					cp++;
-				}
-			} else {
-				/* Assume nobody assigns "=\$=" for procname. */
-				snprintf(buffer + pos, PAGE_SIZE - pos - 1, "/=%d=", table->ctl_name);
-				if (memchr(buffer, '\0', PAGE_SIZE - 2) == NULL) goto out;
-			}
-			if (table->child) {
-				if (table->strategy) {
-					/* printk("sysctl='%s'\n", buffer); */
-					if (CheckFilePerm(buffer, op, "sysctl")) {
-						error = -EPERM;
-						goto out;
-					}
-				}
-				name++;
-				nlen--;
-				table = table->child;
-				goto repeat;
-			}
-			/* printk("sysctl='%s'\n", buffer); */
-			error = CheckFilePerm(buffer, op, "sysctl");
-			goto out;
-		}
-	}
-	error = -ENOTDIR;
- out:
-	kfree(buffer);
-	return error;
-}
-/***** TOMOYO Linux end. *****/
-
 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
 	       void __user *newval, size_t newlen)
 {
@@ -1091,9 +1007,9 @@ int do_sysctl(int __user *name, int nlen
 
 		spin_unlock(&sysctl_lock);
 
-		/***** TOMOYO Linux start. *****/
-		if ((error = try_parse_table(name, nlen, oldval, newval, head->ctl_table)) == 0)
-		/***** TOMOYO Linux end. *****/
+		error = ccs_parse_table(name, nlen, oldval, newval,
+					head->ctl_table);
+		if (!error)
 		error = parse_table(name, nlen, oldval, oldlenp, 
 					newval, newlen, head->ctl_table,
 					&context);
@@ -1167,12 +1083,13 @@ repeat:
 				if (ctl_perm(table, 001))
 					return -EPERM;
 				if (table->strategy) {
-					/***** TOMOYO Linux start. *****/
 					int op = 0;
-					if (oldval) op |= 004;
-					if (newval) op |= 002;
-					if (ctl_perm(table, op)) return -EPERM;
-					/***** TOMOYO Linux end. *****/
+					if (oldval)
+						op |= 004;
+					if (newval)
+						op |= 002;
+					if (ctl_perm(table, op))
+						return -EPERM;
 					error = table->strategy(
 						table, name, nlen,
 						oldval, oldlenp,
--- linux-2.6.8-22.orig/kernel/time.c
+++ linux-2.6.8-22/kernel/time.c
@@ -33,9 +33,7 @@
 #include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
+#include <linux/ccsecurity.h>
 
 /* 
  * The timezone where the local system is located.  Used as a default by some
@@ -85,9 +83,8 @@ asmlinkage long sys_stime(time_t __user 
 		return -EPERM;
 	if (get_user(tv.tv_sec, tptr))
 		return -EFAULT;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (!ccs_capable(CCS_SYS_SETTIME))
+		return -EPERM;
 
 	tv.tv_nsec = 0;
 	do_settimeofday(&tv);
@@ -154,9 +151,8 @@ int do_sys_settimeofday(struct timespec 
 
 	if (!capable(CAP_SYS_TIME))
 		return -EPERM;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (!ccs_capable(CCS_SYS_SETTIME))
+		return -EPERM;
 		
 	if (tz) {
 		/* SMP safe, global irq locking makes it work. */
@@ -227,9 +223,8 @@ int do_adjtimex(struct timex *txc)
 	/* In order to modify anything, you gotta be super-user! */
 	if (txc->modes && !capable(CAP_SYS_TIME))
 		return -EPERM;
-	/***** TOMOYO Linux start. *****/
-	if (txc->modes && CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
+		return -EPERM;
 		
 	/* Now we validate the data before disabling interrupts */
 
--- linux-2.6.8-22.orig/net/ipv4/raw.c
+++ linux-2.6.8-22/net/ipv4/raw.c
@@ -79,6 +79,7 @@
 #include <linux/seq_file.h>
 #include <linux/netfilter.h>
 #include <linux/netfilter_ipv4.h>
+#include <linux/ccsecurity.h>
 
 struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE];
 rwlock_t raw_v4_lock = RW_LOCK_UNLOCKED;
@@ -582,6 +583,10 @@ int raw_recvmsg(struct kiocb *iocb, stru
 	skb = skb_recv_datagram(sk, flags, noblock, &err);
 	if (!skb)
 		goto out;
+	if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
+		err = -EAGAIN; /* Hope less harmful than -EPERM. */
+		goto out;
+	}
 
 	copied = skb->len;
 	if (len < copied) {
--- linux-2.6.8-22.orig/net/ipv4/tcp_ipv4.c
+++ linux-2.6.8-22/net/ipv4/tcp_ipv4.c
@@ -74,9 +74,7 @@
 #include <linux/stddef.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
+#include <linux/ccsecurity.h>
 
 extern int sysctl_ip_dynaddr;
 int sysctl_tcp_tw_reuse;
@@ -232,9 +230,8 @@ static int tcp_v4_get_port(struct sock *
 				rover = low;
 			head = &tcp_bhash[tcp_bhashfn(rover)];
 			spin_lock(&head->lock);
-			/***** SAKURA Linux start. *****/
-			if (SAKURA_MayAutobind(rover) < 0) goto next;
-			/***** SAKURA Linux end. *****/
+			if (ccs_lport_reserved(rover))
+				goto next;
 			tb_for_each(tb, node, &head->chain)
 				if (tb->port == rover)
 					goto next;
@@ -692,9 +689,8 @@ static int tcp_v4_hash_connect(struct so
  				rover = low;
  			head = &tcp_bhash[tcp_bhashfn(rover)];
  			spin_lock(&head->lock);
-			/***** SAKURA Linux start. *****/
-			if (SAKURA_MayAutobind(rover) < 0) goto next_port;
-			/***** SAKURA Linux end. *****/
+			if (ccs_lport_reserved(rover))
+				goto next_port;
 
  			/* Does not bother with rcv_saddr checks,
  			 * because the established check is already
--- linux-2.6.8-22.orig/net/ipv4/udp.c
+++ linux-2.6.8-22/net/ipv4/udp.c
@@ -107,9 +107,7 @@
 #include <net/inet_common.h>
 #include <net/checksum.h>
 #include <net/xfrm.h>
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
+#include <linux/ccsecurity.h>
 
 /*
  *	Snmp MIB for the UDP layer
@@ -141,9 +139,6 @@ static int udp_v4_get_port(struct sock *
 		for (i = 0; i < UDP_HTABLE_SIZE; i++, result++) {
 			struct hlist_head *list;
 			int size;
-			/***** SAKURA Linux start. *****/
-			if (SAKURA_MayAutobind(result) < 0) continue;
-			/***** SAKURA Linux end. *****/
 
 			list = &udp_hash[result & (UDP_HTABLE_SIZE - 1)];
 			if (hlist_empty(list)) {
@@ -151,6 +146,8 @@ static int udp_v4_get_port(struct sock *
 					result = sysctl_local_port_range[0] +
 						((result - sysctl_local_port_range[0]) &
 						 (UDP_HTABLE_SIZE - 1));
+				if (ccs_lport_reserved(result))
+					continue;
 				goto gotit;
 			}
 			size = 0;
@@ -167,9 +164,8 @@ static int udp_v4_get_port(struct sock *
 				result = sysctl_local_port_range[0]
 					+ ((result - sysctl_local_port_range[0]) &
 					   (UDP_HTABLE_SIZE - 1));
-			/***** SAKURA Linux start. *****/
-			if (SAKURA_MayAutobind(result) < 0) continue;
-			/***** SAKURA Linux end. *****/
+			if (ccs_lport_reserved(result))
+				continue;
 			if (!udp_lport_inuse(result))
 				break;
 		}
@@ -812,7 +808,11 @@ try_again:
 	skb = skb_recv_datagram(sk, flags, noblock, &err);
 	if (!skb)
 		goto out;
-  
+	if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
+		err = -EAGAIN; /* Hope less harmful than -EPERM. */
+		goto out;
+	}
+
   	copied = skb->len - sizeof(struct udphdr);
 	if (copied > len) {
 		copied = len;
--- linux-2.6.8-22.orig/net/ipv6/raw.c
+++ linux-2.6.8-22/net/ipv6/raw.c
@@ -54,6 +54,7 @@
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/ccsecurity.h>
 
 struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE];
 rwlock_t raw_v6_lock = RW_LOCK_UNLOCKED;
@@ -384,6 +385,10 @@ static int rawv6_recvmsg(struct kiocb *i
 	skb = skb_recv_datagram(sk, flags, noblock, &err);
 	if (!skb)
 		goto out;
+	if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
+		err = -EAGAIN; /* Hope less harmful than -EPERM. */
+		goto out;
+	}
 
 	copied = skb->len;
   	if (copied > len) {
--- linux-2.6.8-22.orig/net/ipv6/tcp_ipv6.c
+++ linux-2.6.8-22/net/ipv6/tcp_ipv6.c
@@ -62,9 +62,7 @@
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
+#include <linux/ccsecurity.h>
 
 static void	tcp_v6_send_reset(struct sk_buff *skb);
 static void	tcp_v6_or_send_ack(struct sk_buff *skb, struct open_request *req);
@@ -147,9 +145,8 @@ static int tcp_v6_get_port(struct sock *
 				rover = low;
 			head = &tcp_bhash[tcp_bhashfn(rover)];
 			spin_lock(&head->lock);
-			/***** SAKURA Linux start. *****/
-			if (SAKURA_MayAutobind(rover) < 0) goto next;
-			/***** SAKURA Linux end. *****/
+			if (ccs_lport_reserved(rover))
+				goto next;
 			tb_for_each(tb, node, &head->chain)
 				if (tb->port == rover)
 					goto next;
--- linux-2.6.8-22.orig/net/ipv6/udp.c
+++ linux-2.6.8-22/net/ipv6/udp.c
@@ -57,9 +57,7 @@
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
+#include <linux/ccsecurity.h>
 
 DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6);
 
@@ -83,9 +81,6 @@ static int udp_v6_get_port(struct sock *
 		for (i = 0; i < UDP_HTABLE_SIZE; i++, result++) {
 			int size;
 			struct hlist_head *list;
-			/***** SAKURA Linux start. *****/
-			if (SAKURA_MayAutobind(result) < 0) continue;
-			/***** SAKURA Linux end. *****/
 
 			list = &udp_hash[result & (UDP_HTABLE_SIZE - 1)];
 			if (hlist_empty(list)) {
@@ -93,6 +88,8 @@ static int udp_v6_get_port(struct sock *
 					result = sysctl_local_port_range[0] +
 						((result - sysctl_local_port_range[0]) &
 						 (UDP_HTABLE_SIZE - 1));
+				if (ccs_lport_reserved(result))
+					continue;
 				goto gotit;
 			}
 			size = 0;
@@ -109,9 +106,8 @@ static int udp_v6_get_port(struct sock *
 				result = sysctl_local_port_range[0]
 					+ ((result - sysctl_local_port_range[0]) &
 					   (UDP_HTABLE_SIZE - 1));
-			/***** SAKURA Linux start. *****/
-			if (SAKURA_MayAutobind(result) < 0) continue;
-			/***** SAKURA Linux end. *****/
+			if (ccs_lport_reserved(result))
+				continue;
 			if (!udp_lport_inuse(result))
 				break;
 		}
@@ -244,6 +240,10 @@ try_again:
 	skb = skb_recv_datagram(sk, flags, noblock, &err);
 	if (!skb)
 		goto out;
+	if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
+		err = -EAGAIN; /* Hope less harmful than -EPERM. */
+		goto out;
+	}
 
  	copied = skb->len - sizeof(struct udphdr);
   	if (copied > len) {
--- linux-2.6.8-22.orig/net/socket.c
+++ linux-2.6.8-22/net/socket.c
@@ -95,11 +95,6 @@
 #include <net/sock.h>
 #include <linux/netfilter.h>
 
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-#include <linux/tomoyo_socket.h>
-/***** TOMOYO Linux end. *****/
-
 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
 static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf,
 			 size_t size, loff_t pos);
@@ -556,11 +551,10 @@ static inline int __sock_sendmsg(struct 
 	si->size = size;
 
 	err = security_socket_sendmsg(sock, msg, size);
+	if (!err)
+		err = ccs_socket_sendmsg_permission(sock, msg, size);
 	if (err)
 		return err;
-	/***** TOMOYO Linux start. *****/
-	if (CheckSocketSendMsgPermission(sock, (struct sockaddr *) msg->msg_name, msg->msg_namelen)) return -EPERM;
-	/***** TOMOYO Linux start. *****/
 	return sock->ops->sendmsg(iocb, sock, msg, size);
 }
 
@@ -627,11 +621,6 @@ int sock_recvmsg(struct socket *sock, st
 	ret = __sock_recvmsg(&iocb, sock, msg, size, flags);
 	if (-EIOCBQUEUED == ret)
 		ret = wait_on_sync_kiocb(&iocb);
-	/***** TOMOYO Linux start. *****/
-	if (ret >= 0 && CheckSocketRecvMsgPermission(sock, (struct sockaddr *) msg->msg_name, msg->msg_namelen)) {
-		ret = -EAGAIN; /* Hope less harmful than -EPERM. */
-	}
-	/***** TOMOYO Linux end. *****/
 	return ret;
 }
 
@@ -1128,11 +1117,9 @@ static int __sock_create(int family, int
 		family = PF_PACKET;
 	}
 
-	/***** TOMOYO Linux start. *****/
-	if ((err = CheckSocketCreatePermission(family, type, protocol)) < 0) return err;
-	/***** TOMOYO Linux end. *****/
-
 	err = security_socket_create(family, type, protocol, kern);
+	if (!err)
+		err = ccs_socket_create_permission(family, type, protocol);
 	if (err)
 		return err;
 		
@@ -1329,9 +1316,11 @@ asmlinkage long sys_bind(int fd, struct 
 				sockfd_put(sock);
 				return err;
 			}
-			/***** TOMOYO Linux start. *****/
-			if ((err = CheckSocketBindPermission(sock, (struct sockaddr *) address, addrlen)) == 0)
-			/***** TOMOYO Linux end. *****/
+
+			err = ccs_socket_bind_permission(sock,
+							 (struct sockaddr *)
+							 address, addrlen);
+			if (!err)
 			err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);
 		}
 		sockfd_put(sock);
@@ -1362,9 +1351,9 @@ asmlinkage long sys_listen(int fd, int b
 			sockfd_put(sock);
 			return err;
 		}
-		/***** TOMOYO Linux start. *****/
-		if ((err = CheckSocketListenPermission(sock)) == 0)
-		/***** TOMOYO Linux end. *****/
+
+		err = ccs_socket_listen_permission(sock);
+		if (!err)
 		err=sock->ops->listen(sock, backlog);
 		sockfd_put(sock);
 	}
@@ -1415,12 +1404,10 @@ asmlinkage long sys_accept(int fd, struc
 	if (err < 0)
 		goto out_release;
 
-	/***** TOMOYO Linux start. *****/
-	if (CheckSocketAcceptPermission(newsock, (struct sockaddr *) address)) {
-		err = -ECONNABORTED; /* Hope less harmful than -EPERM. */
+	if (ccs_socket_post_accept_permission(sock, newsock)) {
+		err = -EAGAIN; /* Hope less harmful than -EPERM. */
 		goto out_release;
 	}
-	/***** TOMOYO Linux end. *****/
 	if (upeer_sockaddr) {
 		if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {
 			err = -ECONNABORTED;
@@ -1474,11 +1461,11 @@ asmlinkage long sys_connect(int fd, stru
 		goto out_put;
 
 	err = security_socket_connect(sock, (struct sockaddr *)address, addrlen);
+	if (!err)
+		err = ccs_socket_connect_permission(sock, (struct sockaddr *)
+						    address, addrlen);
 	if (err)
 		goto out_put;
-	/***** TOMOYO Linux start. *****/
-	if ((err = CheckSocketConnectPermission(sock, (struct sockaddr *) address, addrlen)) == 0)
-	/***** TOMOYO Linux end. *****/
 	err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,
 				 sock->file->f_flags);
 out_put:
--- linux-2.6.8-22.orig/net/unix/af_unix.c
+++ linux-2.6.8-22/net/unix/af_unix.c
@@ -118,12 +118,6 @@
 #include <linux/mount.h>
 #include <net/checksum.h>
 #include <linux/security.h>
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 int sysctl_unix_max_dgram_qlen = 10;
 
@@ -737,10 +731,6 @@ static int unix_bind(struct socket *sock
 		err = unix_autobind(sock);
 		goto out;
 	}
-	/***** TOMOYO Linux start. *****/
-	err = -EPERM;
-	if (sunaddr->sun_path[0] && CheckCapabilityACL(TOMOYO_CREATE_UNIX_SOCKET)) goto out;
-	/***** TOMOYO Linux end. *****/
 
 	err = unix_mkname(sunaddr, addr_len, &hash);
 	if (err < 0)
@@ -805,11 +795,9 @@ static int unix_bind(struct socket *sock
 		 */
 		mode = S_IFSOCK |
 		       (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
-		/***** TOMOYO Linux start. *****/
-		if ((err = pre_vfs_mknod(nd.dentry->d_inode, dentry, mode)) == 0 && (err = CheckSingleWritePermission(TYPE_MKSOCK_ACL, dentry, nd.mnt)) == 0)
-		/***** TOMOYO Linux end. *****/
+		err = ccs_mknod_permission(dentry, nd.mnt, mode, 0);
+		if (!err)
 		err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
-		if (err == -EROFS) ROFS_Log_from_dentry(dentry, nd.mnt, "unix_bind"); /***** ReadOnly Tracer *****/
 		if (err)
 			goto out_mknod_dput;
 		up(&nd.dentry->d_inode->i_sem);
@@ -1597,6 +1585,10 @@ static int unix_dgram_recvmsg(struct kio
 
 	wake_up_interruptible(&u->peer_wait);
 
+	if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
+		err = -EAGAIN; /* Hope less harmful than -EPERM. */
+		goto out_unlock;
+	}
 	if (msg->msg_name)
 		unix_copy_addr(msg, skb->sk);
 
--- linux-2.6.8-22.orig/security/Kconfig
+++ linux-2.6.8-22/security/Kconfig
@@ -39,5 +39,7 @@ config SECURITY_ROOTPLUG
 
 source security/selinux/Kconfig
 
+source security/ccsecurity/Kconfig
+
 endmenu
 
--- linux-2.6.8-22.orig/security/Makefile
+++ linux-2.6.8-22/security/Makefile
@@ -14,3 +14,6 @@ obj-$(CONFIG_SECURITY)			+= security.o d
 # Must precede capability.o in order to stack properly.
 obj-$(CONFIG_SECURITY_SELINUX)		+= selinux/built-in.o
 obj-$(CONFIG_SECURITY_ROOTPLUG)		+= root_plug.o
+
+subdir-$(CONFIG_CCSECURITY)+= ccsecurity
+obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o
