This is TOMOYO Linux patch for Turbolinux 11 Server.
---
 arch/alpha/kernel/ptrace.c      |   13 ++----
 arch/ia64/ia32/sys_ia32.c       |   11 +----
 arch/ia64/kernel/ptrace.c       |   13 ++----
 arch/m32r/kernel/ptrace.c       |   14 ++----
 arch/mips/kernel/ptrace32.c     |   13 ++----
 arch/powerpc/kernel/ptrace32.c  |   13 ++----
 arch/s390/kernel/ptrace.c       |   13 ++----
 arch/sh64/kernel/ptrace.c       |    8 ---
 arch/sparc/kernel/ptrace.c      |   16 ++-----
 arch/sparc64/kernel/ptrace.c    |   16 ++-----
 arch/x86_64/ia32/ptrace32.c     |   14 ++----
 fs/Kconfig                      |    2 
 fs/Makefile                     |    2 
 fs/attr.c                       |   11 -----
 fs/compat.c                     |    5 --
 fs/compat_ioctl.c               |    9 +---
 fs/exec.c                       |   19 +++------
 fs/fcntl.c                      |   11 +----
 fs/ioctl.c                      |    8 ---
 fs/namei.c                      |   79 +++++++++----------------------------
 fs/namespace.c                  |   46 +++------------------
 fs/open.c                       |   47 ++++++++++++----------
 fs/proc/Makefile                |    3 -
 fs/proc/proc_misc.c             |   10 ----
 fs/stat.c                       |    2 
 include/linux/init_task.h       |   13 ++++--
 include/linux/sched.h           |   15 ++-----
 include/linux/security.h        |    1 
 kernel/compat.c                 |    8 ---
 kernel/fork.c                   |    5 ++
 kernel/kexec.c                  |    9 +---
 kernel/kmod.c                   |    5 --
 kernel/module.c                 |   14 ++----
 kernel/ptrace.c                 |   13 ++----
 kernel/sched.c                  |    8 ---
 kernel/signal.c                 |   23 +++-------
 kernel/sys.c                    |   25 ++++-------
 kernel/sysctl.c                 |   84 +---------------------------------------
 kernel/time.c                   |   13 +-----
 kernel/time/ntp.c               |    9 +---
 net/core/datagram.c             |    9 ----
 net/ipv4/inet_connection_sock.c |    9 +---
 net/ipv4/inet_hashtables.c      |    9 +---
 net/ipv4/raw.c                  |    5 ++
 net/ipv4/udp.c                  |   18 ++++----
 net/ipv6/inet6_hashtables.c     |    9 +---
 net/ipv6/raw.c                  |    5 ++
 net/ipv6/udp.c                  |    5 ++
 net/socket.c                    |   42 +++++++-------------
 net/unix/af_unix.c              |   16 ++-----
 security/Kconfig                |    2 
 security/Makefile               |    3 +
 52 files changed, 252 insertions(+), 523 deletions(-)

--- linux-2.6.23-12.orig/arch/alpha/kernel/ptrace.c
+++ linux-2.6.23-12/arch/alpha/kernel/ptrace.c
@@ -20,9 +20,6 @@
 #include <asm/pgtable.h>
 #include <asm/system.h>
 #include <asm/fpu.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 #include "proto.h"
 
@@ -271,11 +268,11 @@ do_sys_ptrace(long request, long pid, lo
 	unsigned long tmp;
 	size_t copied;
 	long ret;
-	/***** TOMOYO Linux start. *****/
-#ifdef TOMOYO_SYS_PTRACE
-	if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;
-#endif
-	/***** TOMOYO Linux end. *****/
+	{
+		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.23-12.orig/arch/ia64/ia32/sys_ia32.c
+++ linux-2.6.23-12/arch/ia64/ia32/sys_ia32.c
@@ -55,9 +55,7 @@
 #include <asm/types.h>
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
+#include <linux/ccsecurity.h>
 
 #include "ia32priv.h"
 
@@ -1761,11 +1759,8 @@ sys32_ptrace (int request, pid_t pid, un
 	struct task_struct *child;
 	unsigned int value, tmp;
 	long i, ret;
-	/***** TOMOYO Linux start. *****/
-#ifdef TOMOYO_SYS_PTRACE
-	if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;
-#endif
-	/***** TOMOYO Linux end. *****/
+	if (ccs_ptrace_permission(request, pid))
+		return -EPERM;
 
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
--- linux-2.6.23-12.orig/arch/ia64/kernel/ptrace.c
+++ linux-2.6.23-12/arch/ia64/kernel/ptrace.c
@@ -28,9 +28,6 @@
 #ifdef CONFIG_PERFMON
 #include <asm/perfmon.h>
 #endif
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 #include "entry.h"
 
@@ -1425,11 +1422,11 @@ sys_ptrace (long request, pid_t pid, uns
 	struct task_struct *child;
 	struct switch_stack *sw;
 	long ret;
-	/***** TOMOYO Linux start. *****/
-#ifdef TOMOYO_SYS_PTRACE
-	if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;
-#endif
-	/***** TOMOYO Linux end. *****/
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.23-12.orig/arch/m32r/kernel/ptrace.c
+++ linux-2.6.23-12/arch/m32r/kernel/ptrace.c
@@ -33,9 +33,7 @@
 #include <asm/system.h>
 #include <asm/processor.h>
 #include <asm/mmu_context.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
+#include <linux/ccsecurity.h>
 
 /*
  * This routine will get a word off of the process kernel stack.
@@ -735,11 +733,11 @@ asmlinkage long sys_ptrace(long request,
 {
 	struct task_struct *child;
 	int ret;
-	/***** TOMOYO Linux start. *****/
-#ifdef TOMOYO_SYS_PTRACE
-	if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;
-#endif
-	/***** TOMOYO Linux end. *****/
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
--- linux-2.6.23-12.orig/arch/mips/kernel/ptrace32.c
+++ linux-2.6.23-12/arch/mips/kernel/ptrace32.c
@@ -35,9 +35,6 @@
 #include <asm/system.h>
 #include <asm/uaccess.h>
 #include <asm/bootinfo.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 int ptrace_getregs (struct task_struct *child, __s64 __user *data);
 int ptrace_setregs (struct task_struct *child, __s64 __user *data);
@@ -53,11 +50,11 @@ asmlinkage int sys32_ptrace(int request,
 {
 	struct task_struct *child;
 	int ret;
-	/***** TOMOYO Linux start. *****/
-#ifdef TOMOYO_SYS_PTRACE
-	if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;
-#endif
-	/***** TOMOYO Linux end. *****/
+	{
+		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.23-12.orig/arch/powerpc/kernel/ptrace32.c
+++ linux-2.6.23-12/arch/powerpc/kernel/ptrace32.c
@@ -32,9 +32,6 @@
 #include <asm/page.h>
 #include <asm/pgtable.h>
 #include <asm/system.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 /*
  * does not yet catch signals sent when the child dies.
@@ -90,11 +87,11 @@ long compat_sys_ptrace(int request, int 
 {
 	struct task_struct *child;
 	int ret;
-	/***** TOMOYO Linux start. *****/
-#ifdef TOMOYO_SYS_PTRACE
-	if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;
-#endif
-	/***** TOMOYO Linux end. *****/
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
--- linux-2.6.23-12.orig/arch/s390/kernel/ptrace.c
+++ linux-2.6.23-12/arch/s390/kernel/ptrace.c
@@ -41,9 +41,6 @@
 #include <asm/system.h>
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 #ifdef CONFIG_COMPAT
 #include "compat_ptrace.h"
@@ -708,12 +705,12 @@ 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;
+	}
 
-	/***** TOMOYO Linux start. *****/
-#ifdef TOMOYO_SYS_PTRACE
-	if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;
-#endif
-	/***** TOMOYO Linux end. *****/
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
 		 ret = ptrace_traceme();
--- linux-2.6.23-12.orig/arch/sh64/kernel/ptrace.c
+++ linux-2.6.23-12/arch/sh64/kernel/ptrace.c
@@ -35,9 +35,6 @@
 #include <asm/system.h>
 #include <asm/processor.h>
 #include <asm/mmu_context.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 /* 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. */
@@ -263,11 +260,6 @@ asmlinkage int sh64_ptrace(long request,
 	extern void poke_real_address_q(unsigned long long addr, unsigned long long data);
 #define WPC_DBRMODE 0x0d104008
 	static int first_call = 1;
-	/***** TOMOYO Linux start. *****/
-#ifdef TOMOYO_SYS_PTRACE
-	if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;
-#endif
-	/***** TOMOYO Linux end. *****/
 
 	lock_kernel();
 	if (first_call) {
--- linux-2.6.23-12.orig/arch/sparc/kernel/ptrace.c
+++ linux-2.6.23-12/arch/sparc/kernel/ptrace.c
@@ -23,9 +23,6 @@
 #include <asm/pgtable.h>
 #include <asm/system.h>
 #include <asm/uaccess.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 #define MAGIC_CONSTANT 0x80000000
 
@@ -270,14 +267,13 @@ asmlinkage void do_ptrace(struct pt_regs
 	unsigned long addr2 = regs->u_regs[UREG_I4];
 	struct task_struct *child;
 	int ret;
-	/***** TOMOYO Linux start. *****/
-#ifdef TOMOYO_SYS_PTRACE
-	if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) {
-		pt_error_return(regs, EPERM);
-		return;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc) {
+			pt_error_return(regs, -rc);
+			return;
+		}
 	}
-#endif
-	/***** TOMOYO Linux end. *****/
 
 	lock_kernel();
 #ifdef DEBUG_PTRACE
--- linux-2.6.23-12.orig/arch/sparc64/kernel/ptrace.c
+++ linux-2.6.23-12/arch/sparc64/kernel/ptrace.c
@@ -32,9 +32,6 @@
 #include <asm/spitfire.h>
 #include <asm/page.h>
 #include <asm/cpudata.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 /* Returning from ptrace is a bit tricky because the syscall return
  * low level code assumes any value returned which is negative and
@@ -179,14 +176,13 @@ asmlinkage void do_ptrace(struct pt_regs
 	unsigned long addr2 = regs->u_regs[UREG_I4];
 	struct task_struct *child;
 	int ret;
-	/***** TOMOYO Linux start. *****/
-#ifdef TOMOYO_SYS_PTRACE
-	if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) {
-		pt_error_return(regs, EPERM);
-		return;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc) {
+			pt_error_return(regs, -rc);
+			return;
+		}
 	}
-#endif
-	/***** TOMOYO Linux end. *****/
 
 	if (test_thread_flag(TIF_32BIT)) {
 		addr &= 0xffffffffUL;
--- linux-2.6.23-12.orig/arch/x86_64/ia32/ptrace32.c
+++ linux-2.6.23-12/arch/x86_64/ia32/ptrace32.c
@@ -27,9 +27,7 @@
 #include <asm/i387.h>
 #include <asm/fpu32.h>
 #include <asm/ia32.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
+#include <linux/ccsecurity.h>
 
 /*
  * Determines which flags the user has access to [1 = access, 0 = no access].
@@ -238,11 +236,11 @@ asmlinkage long sys32_ptrace(long reques
 	void __user *datap = compat_ptr(data);
 	int ret;
 	__u32 val;
-	/***** TOMOYO Linux start. *****/
-#ifdef TOMOYO_SYS_PTRACE
-	if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;
-#endif
-	/***** TOMOYO Linux end. *****/
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	switch (request) { 
 	case PTRACE_TRACEME:
--- linux-2.6.23-12.orig/fs/Kconfig
+++ linux-2.6.23-12/fs/Kconfig
@@ -2143,7 +2143,5 @@ endif
 source "fs/nls/Kconfig"
 source "fs/dlm/Kconfig"
 
-source "fs/Kconfig.ccs"
-
 endmenu
 
--- linux-2.6.23-12.orig/fs/Makefile
+++ linux-2.6.23-12/fs/Makefile
@@ -123,5 +123,3 @@ obj-$(CONFIG_GFS2_FS)           += gfs2/
 obj-$(CONFIG_UNION_FS)		+= unionfs/
 obj-m                           += vmblock/
 obj-m                           += vmhgfs/
-
-include $(srctree)/fs/Makefile-2.6.ccs
--- linux-2.6.23-12.orig/fs/attr.c
+++ linux-2.6.23-12/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... */
 
@@ -147,20 +144,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.23-12.orig/fs/compat.c
+++ linux-2.6.23-12/fs/compat.c
@@ -55,9 +55,6 @@
 #include <asm/mmu_context.h>
 #include <asm/ioctls.h>
 #include "internal.h"
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 int compat_log = 1;
 
@@ -1409,7 +1406,7 @@ int compat_do_execve(char * filename,
 	if (retval < 0)
 		goto out;
 
-	retval = search_binary_handler_with_transition(bprm, regs);
+	retval = ccs_search_binary_handler(bprm, regs);
 	if (retval >= 0) {
 		/* execve success */
 		security_bprm_free(bprm);
--- linux-2.6.23-12.orig/fs/compat_ioctl.c
+++ linux-2.6.23-12/fs/compat_ioctl.c
@@ -114,9 +114,7 @@
 #include <linux/dvb/frontend.h>
 #include <linux/dvb/video.h>
 #include <linux/lp.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
+#include <linux/ccsecurity.h>
 
 #ifdef CONFIG_SPARC
 #include <asm/fbio.h>
@@ -3582,6 +3580,8 @@ asmlinkage long compat_sys_ioctl(unsigne
 
 	/* RED-PEN how should LSM module know it's handling 32bit? */
 	error = security_file_ioctl(filp, cmd, arg);
+	if (!error)
+		error = ccs_ioctl_permission(filp, cmd, arg);
 	if (error)
 		goto out_fput;
 
@@ -3606,9 +3606,6 @@ asmlinkage long compat_sys_ioctl(unsigne
 		/*FALL THROUGH*/
 
 	default:
-		/***** TOMOYO Linux start. *****/
-		if ((error = CheckCapabilityACL(TOMOYO_SYS_IOCTL)) < 0) goto out_fput;
-		/***** TOMOYO Linux end. *****/
 		if (filp->f_op && filp->f_op->compat_ioctl) {
 			error = filp->f_op->compat_ioctl(filp, cmd, arg);
 			if (error != -ENOIOCTLCMD)
--- linux-2.6.23-12.orig/fs/exec.c
+++ linux-2.6.23-12/fs/exec.c
@@ -59,10 +59,6 @@
 #include <linux/kmod.h>
 #endif
 
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
-
 int core_uses_pid;
 char core_pattern[CORENAME_MAX_SIZE] = "core";
 int suid_dumpable = 0;
@@ -149,10 +145,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 = nameidata_to_filp(&nd, O_RDONLY);
 	error = PTR_ERR(file);
@@ -692,9 +687,9 @@ struct file *open_exec(const char *name)
 		if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&
 		    S_ISREG(inode->i_mode)) {
 			int err = vfs_permission(&nd, MAY_EXEC);
-			/***** TOMOYO Linux start. *****/
-			if (!err && (current->tomoyo_flags & TOMOYO_CHECK_READ_FOR_OPEN_EXEC)) err = CheckOpenPermission(nd.dentry, nd.mnt, 01); /* 01 means "read". */
-			/***** TOMOYO Linux end. *****/
+			if (!err)
+				err = ccs_open_exec_permission(nd.dentry,
+								     nd.mnt);
 			file = ERR_PTR(err);
 			if (!err) {
 				file = nameidata_to_filp(&nd, O_RDONLY);
@@ -1407,7 +1402,7 @@ int do_execve(char * filename,
 		goto out;
 	bprm->argv_len = env_p - bprm->p;
 
-	retval = search_binary_handler_with_transition(bprm,regs);
+	retval = ccs_search_binary_handler(bprm, regs);
 	if (retval >= 0) {
 		/* execve success */
 		free_arg_pages(bprm);
--- linux-2.6.23-12.orig/fs/fcntl.c
+++ linux-2.6.23-12/fs/fcntl.c
@@ -22,9 +22,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)
 {
@@ -216,10 +213,6 @@ static int setfl(int fd, struct file * f
 	if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode))
 		return -EPERM;
 
-	/***** TOMOYO Linux start. *****/
-	if (((arg ^ filp->f_flags) & 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 (!is_owner_or_cap(inode))
@@ -399,6 +392,8 @@ asmlinkage long sys_fcntl(unsigned int f
 		goto out;
 
 	err = security_file_fcntl(filp, cmd, arg);
+	if (!err)
+		err = ccs_fcntl_permission(filp, cmd, arg);
 	if (err) {
 		fput(filp);
 		return err;
@@ -423,6 +418,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.23-12.orig/fs/ioctl.c
+++ linux-2.6.23-12/fs/ioctl.c
@@ -15,9 +15,6 @@
 
 #include <asm/uaccess.h>
 #include <asm/ioctls.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 static long do_ioctl(struct file *filp, unsigned int cmd,
 		unsigned long arg)
@@ -26,9 +23,6 @@ static long do_ioctl(struct file *filp, 
 
 	if (!filp->f_op)
 		goto out;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_IOCTL) < 0) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 
 	if (filp->f_op->unlocked_ioctl) {
 		error = filp->f_op->unlocked_ioctl(filp, cmd, arg);
@@ -171,6 +165,8 @@ asmlinkage long sys_ioctl(unsigned int f
 		goto out;
 
 	error = security_file_ioctl(filp, cmd, arg);
+	if (!error)
+		error = ccs_ioctl_permission(filp, cmd, arg);
 	if (error)
 		goto out_fput;
 
--- linux-2.6.23-12.orig/fs/namei.c
+++ linux-2.6.23-12/fs/namei.c
@@ -36,10 +36,6 @@
 
 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
 
-/***** 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
@@ -1562,9 +1558,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)
@@ -1620,10 +1613,10 @@ int may_open(struct nameidata *nd, int a
 		if (!is_owner_or_cap(inode))
 			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.
@@ -1664,6 +1657,8 @@ static int open_namei_create(struct name
 
 	if (!IS_POSIXACL(dir->d_inode))
 		mode &= ~current->fs->umask;
+	error = ccs_mknod_permission(path->dentry, nd->mnt, mode, 0);
+	if (!error)
 	error = vfs_create(dir->d_inode, path->dentry, mode, nd);
 	mutex_unlock(&dir->d_inode->i_mutex);
 	dput(nd->dentry);
@@ -1674,9 +1669,6 @@ static int open_namei_create(struct name
 	return may_open(nd, 0, flag & ~O_TRUNC);
 }
 
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo_vfs.h>
-/***** TOMOYO Linux end. *****/
 /*
  *	open_namei()
  *
@@ -1937,12 +1929,6 @@ asmlinkage long sys_mknodat(int dfd, con
 
 	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);
@@ -1956,21 +1942,17 @@ asmlinkage long sys_mknodat(int dfd, con
 	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:
@@ -2038,9 +2020,8 @@ asmlinkage long sys_mkdirat(int dfd, con
 
 	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);
 	dput(dentry);
 out_unlock:
@@ -2148,9 +2129,8 @@ static long do_rmdir(int dfd, const char
 	error = PTR_ERR(dentry);
 	if (IS_ERR(dentry))
 		goto exit2;
-	/***** 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);
 	dput(dentry);
 exit2:
@@ -2210,9 +2190,6 @@ static long do_unlinkat(int dfd, const c
 	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))
@@ -2234,9 +2211,8 @@ static long do_unlinkat(int dfd, const c
 		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);
 	exit2:
 		dput(dentry);
@@ -2301,9 +2277,6 @@ asmlinkage long sys_symlinkat(const char
 	char * to;
 	struct dentry *dentry;
 	struct nameidata nd;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_SYMLINK)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 
 	from = getname(oldname);
 	if(IS_ERR(from))
@@ -2321,9 +2294,8 @@ asmlinkage long sys_symlinkat(const char
 	if (IS_ERR(dentry))
 		goto out_unlock;
 
-	/***** 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);
 	dput(dentry);
 out_unlock:
@@ -2396,9 +2368,6 @@ asmlinkage long sys_linkat(int olddfd, c
 	struct nameidata nd, old_nd;
 	int error;
 	char * to;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_LINK)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 
 	if ((flags & ~AT_SYMLINK_FOLLOW) != 0)
 		return -EINVAL;
@@ -2422,9 +2391,8 @@ asmlinkage long sys_linkat(int olddfd, c
 	error = PTR_ERR(new_dentry);
 	if (IS_ERR(new_dentry))
 		goto out_unlock;
-	/***** 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);
 	dput(new_dentry);
 out_unlock:
@@ -2650,13 +2618,9 @@ static int do_rename(int olddfd, const c
 	error = -ENOTEMPTY;
 	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:
@@ -2679,9 +2643,6 @@ asmlinkage long sys_renameat(int olddfd,
 	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.23-12.orig/fs/namespace.c
+++ linux-2.6.23-12/fs/namespace.c
@@ -29,12 +29,6 @@
 #include <asm/unistd.h>
 #include "pnode.h"
 #include "internal.h"
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 /* spinlock for vfsmount related operations, inplace of dcache_lock */
 __cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);
@@ -547,13 +541,11 @@ static int do_umount(struct vfsmount *mn
 	LIST_HEAD(umount_list);
 
 	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:
@@ -642,9 +634,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)
@@ -932,10 +921,6 @@ static int do_loopback(struct nameidata 
 
 	if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
 		goto out;
-	/***** SAKURA Linux start. *****/
-	err = -EPERM;
-	if (SAKURA_MayMount(nd) < 0) goto out;
-	/***** SAKURA Linux end. *****/
 
 	err = -ENOMEM;
 	if (recurse)
@@ -1021,10 +1006,6 @@ static int do_move_mount(struct nameidat
 	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) goto out;
-	/***** SAKURA Linux end. *****/
 	err = -ENOENT;
 	mutex_lock(&nd->dentry->d_inode->i_mutex);
 	if (IS_DEADDIR(nd->dentry->d_inode))
@@ -1126,10 +1107,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) goto unlock;
-	/***** SAKURA Linux end. *****/
 
 	newmnt->mnt_flags = mnt_flags;
 	if ((err = graft_tree(newmnt, nd)))
@@ -1403,6 +1380,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;
@@ -1421,13 +1399,6 @@ long do_mount(char *dev_name, char *dir_
 	if (data_page)
 		((char *)data_page)[PAGE_SIZE - 1] = 0;
 
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_MOUNT)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
-	/***** SAKURA Linux start. *****/
-	if ((retval = CheckMountPermission(dev_name, dir_name, type_page, &flags)) < 0) return retval;
-	/***** SAKURA Linux end. *****/
-
 	/* Separate the per-mountpoint flags */
 	if (flags & MS_NOSUID)
 		mnt_flags |= MNT_NOSUID;
@@ -1451,6 +1422,9 @@ long do_mount(char *dev_name, char *dir_
 		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;
 
@@ -1704,9 +1678,6 @@ asmlinkage long sys_pivot_root(const cha
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_PIVOT_ROOT)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
 
 	lock_kernel();
 
@@ -1723,9 +1694,8 @@ asmlinkage long sys_pivot_root(const cha
 		goto out1;
 
 	error = security_sb_pivotroot(&old_nd, &new_nd);
-	/***** SAKURA Linux start. *****/
-	if (!error) error = CheckPivotRootPermission(&old_nd, &new_nd);
-	/***** SAKURA Linux end. *****/
+	if (!error)
+		error = ccs_pivot_root_permission(&old_nd, &new_nd);
 	if (error) {
 		path_release(&old_nd);
 		goto out1;
--- linux-2.6.23-12.orig/fs/open.c
+++ linux-2.6.23-12/fs/open.c
@@ -27,12 +27,6 @@
 #include <linux/rcupdate.h>
 #include <linux/audit.h>
 #include <linux/falloc.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 dentry *dentry, struct kstatfs *buf)
 {
@@ -274,9 +268,9 @@ static long do_sys_truncate(const char _
 	if (error)
 		goto put_write_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)
+		goto put_write_and_out;
 	error = locks_verify_truncate(inode, NULL, length);
 	if (!error) {
 		DQUOT_INIT(inode);
@@ -331,9 +325,9 @@ static long do_sys_ftruncate(unsigned in
 	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, ATTR_MTIME|ATTR_CTIME, file);
@@ -556,12 +550,8 @@ asmlinkage long sys_chroot(const char __
 	error = -EPERM;
 	if (!capable(CAP_SYS_CHROOT))
 		goto dput_and_out;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_CHROOT)) goto dput_and_out;
-	/***** TOMOYO Linux end. *****/
-	/***** SAKURA Linux start. *****/
-	if (CheckChRootPermission(&nd)) 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();
@@ -595,6 +585,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;
 	mutex_lock(&inode->i_mutex);
 	if (mode == (mode_t) -1)
 		mode = inode->i_mode;
@@ -629,6 +622,9 @@ asmlinkage long sys_fchmodat(int dfd, co
 	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;
 
 	mutex_lock(&inode->i_mutex);
 	if (mode == (mode_t) -1)
@@ -692,6 +688,8 @@ asmlinkage long sys_chown(const char __u
 	error = user_path_walk(filename, &nd);
 	if (error)
 		goto out;
+	error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
+	if (!error)
 	error = chown_common(nd.dentry, user, group);
 	path_release(&nd);
 out:
@@ -712,6 +710,8 @@ asmlinkage long sys_fchownat(int dfd, co
 	error = __user_walk_fd(dfd, filename, follow, &nd);
 	if (error)
 		goto out;
+	error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
+	if (!error)
 	error = chown_common(nd.dentry, user, group);
 	path_release(&nd);
 out:
@@ -726,6 +726,8 @@ asmlinkage long sys_lchown(const char __
 	error = user_path_walk_link(filename, &nd);
 	if (error)
 		goto out;
+	error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
+	if (!error)
 	error = chown_common(nd.dentry, user, group);
 	path_release(&nd);
 out:
@@ -745,6 +747,8 @@ asmlinkage long sys_fchown(unsigned int 
 
 	dentry = file->f_path.dentry;
 	audit_inode(NULL, dentry->d_inode);
+	error = ccs_chown_permission(dentry, file->f_vfsmnt, user, group);
+	if (!error)
 	error = chown_common(dentry, user, group);
 	fput(file);
 out:
@@ -837,7 +841,9 @@ static struct file *do_filp_open(int dfd
 	if ((namei_flags+1) & O_ACCMODE)
 		namei_flags++;
 
+	ccs_save_open_mode(flags);
 	error = open_namei(dfd, filename, namei_flags, mode, &nd);
+	ccs_clear_open_mode();
 	if (!error)
 		return nameidata_to_filp(&nd, flags);
 
@@ -1174,9 +1180,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)) {
 		/* XXX: this needs locking */
 		tty_vhangup(current->signal->tty);
--- linux-2.6.23-12.orig/fs/proc/Makefile
+++ linux-2.6.23-12/fs/proc/Makefile
@@ -15,6 +15,3 @@ proc-$(CONFIG_PROC_KCORE)	+= kcore.o
 proc-$(CONFIG_PROC_VMCORE)	+= vmcore.o
 proc-$(CONFIG_PROC_DEVICETREE)	+= proc_devtree.o
 proc-$(CONFIG_PRINTK)	+= kmsg.o
-
-proc-$(CONFIG_SAKURA) += ccs_proc.o
-proc-$(CONFIG_TOMOYO) += ccs_proc.o
--- linux-2.6.23-12.orig/fs/proc/proc_misc.c
+++ linux-2.6.23-12/fs/proc/proc_misc.c
@@ -748,13 +748,5 @@ void __init proc_misc_init(void)
 			entry->proc_fops = &proc_sysrq_trigger_operations;
 	}
 #endif
-	/***** CCS start. *****/
-#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO)
-	{
-		extern void __init CCSProc_Init(void);
-		CCSProc_Init();
-		printk("Hook version: 2.6.23 2008/01/05\n");
-	}
-#endif
-	/***** CCS end. *****/
+	printk(KERN_INFO "Hook version: 2.6.23-12 2012/03/08\n");
 }
--- linux-2.6.23-12.orig/fs/stat.c
+++ linux-2.6.23-12/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.23-12.orig/include/linux/init_task.h
+++ linux-2.6.23-12/include/linux/init_task.h
@@ -113,6 +113,14 @@ extern struct group_info init_groups;
 	.pid = &init_struct_pid,				\
 }
 
+#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)
@@ -171,10 +179,7 @@ extern struct group_info init_groups;
 	},								\
 	INIT_TRACE_IRQFLAGS						\
 	INIT_LOCKDEP							\
-	/***** TOMOYO Linux start. *****/        \
-	.domain_info = &KERNEL_DOMAIN,           \
-	.tomoyo_flags = 0,                       \
-	/***** TOMOYO Linux end. *****/          \
+	INIT_CCSECURITY                                                 \
 }
 
 
--- linux-2.6.23-12.orig/include/linux/sched.h
+++ linux-2.6.23-12/include/linux/sched.h
@@ -28,11 +28,6 @@
 #define CLONE_NEWIPC		0x08000000	/* New ipcs */
 #define CLONE_NEWUSER		0x10000000	/* New user namespace */
 
-/***** TOMOYO Linux start. *****/
-struct domain_info;
-extern struct domain_info KERNEL_DOMAIN;
-/***** TOMOYO Linux end. *****/
-
 /*
  * Scheduling policies
  */
@@ -45,6 +40,8 @@ extern struct domain_info KERNEL_DOMAIN;
 
 #ifdef __KERNEL__
 
+struct ccs_domain_info;
+
 struct sched_param {
 	int sched_priority;
 };
@@ -1201,12 +1198,12 @@ struct task_struct {
 #ifdef CONFIG_FAULT_INJECTION
 	int make_it_fail;
 #endif
-	/***** TOMOYO Linux start. *****/
-	struct domain_info *domain_info;
-	u32 tomoyo_flags;
-	/***** TOMOYO Linux end. *****/
 
 	struct list_head        *scm_work_list;
+#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY)
+	struct ccs_domain_info *ccs_domain_info;
+	u32 ccs_flags;
+#endif
 };
 
 /*
--- linux-2.6.23-12.orig/include/linux/security.h
+++ linux-2.6.23-12/include/linux/security.h
@@ -33,6 +33,7 @@
 #include <linux/key.h>
 #include <linux/xfrm.h>
 #include <net/flow.h>
+#include <linux/ccsecurity.h>
 
 struct ctl_table;
 
--- linux-2.6.23-12.orig/kernel/compat.c
+++ linux-2.6.23-12/kernel/compat.c
@@ -25,9 +25,6 @@
 #include <linux/posix-timers.h>
 
 #include <asm/uaccess.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts)
 {
@@ -872,9 +869,8 @@ asmlinkage long compat_sys_stime(compat_
 	err = security_settime(&tv, NULL);
 	if (err)
 		return err;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (!ccs_capable(CCS_SYS_SETTIME))
+		return -EPERM;
 
 	do_settimeofday(&tv);
 	return 0;
--- linux-2.6.23-12.orig/kernel/fork.c
+++ linux-2.6.23-12/kernel/fork.c
@@ -124,6 +124,7 @@ void __put_task_struct(struct task_struc
 	put_group_info(tsk->group_info);
 	delayacct_tsk_free(tsk);
 
+	ccs_free_task_security(tsk);
 	if (!profile_handoff_task(tsk))
 		free_task(tsk);
 }
@@ -1119,6 +1120,9 @@ static struct task_struct *copy_process(
 		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;
@@ -1297,6 +1301,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.23-12.orig/kernel/kexec.c
+++ linux-2.6.23-12/kernel/kexec.c
@@ -28,9 +28,7 @@
 #include <asm/io.h>
 #include <asm/system.h>
 #include <asm/semaphore.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
+#include <linux/ccsecurity.h>
 
 /* Per cpu memory for storing cpu states in case of system crash. */
 note_buf_t* crash_notes;
@@ -927,9 +925,8 @@ asmlinkage long sys_kexec_load(unsigned 
 	/* We only trust the superuser with rebooting the system. */
 	if (!capable(CAP_SYS_BOOT))
 		return -EPERM;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_KEXEC_LOAD)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
+		return -EPERM;
 
 	/*
 	 * Verify we have a legal set of flags
--- linux-2.6.23-12.orig/kernel/kmod.c
+++ linux-2.6.23-12/kernel/kmod.c
@@ -173,11 +173,6 @@ static int ____call_usermodehelper(void 
 	 */
 	set_user_nice(current, 0);
 
-	/***** TOMOYO Linux start. *****/
-	current->domain_info = &KERNEL_DOMAIN;
-	current->tomoyo_flags = 0;
-	/***** TOMOYO Linux end. *****/
-
 	retval = -EPERM;
 	if (current->fs->root)
 		retval = kernel_execve(sub_info->path,
--- linux-2.6.23-12.orig/kernel/module.c
+++ linux-2.6.23-12/kernel/module.c
@@ -45,9 +45,7 @@
 #include <asm/semaphore.h>
 #include <asm/cacheflush.h>
 #include <linux/license.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
+#include <linux/ccsecurity.h>
 
 extern int module_sysfs_initialized;
 
@@ -665,9 +663,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;
@@ -1987,9 +1984,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 (mutex_lock_interruptible(&module_mutex) != 0)
--- linux-2.6.23-12.orig/kernel/ptrace.c
+++ linux-2.6.23-12/kernel/ptrace.c
@@ -22,9 +22,6 @@
 
 #include <asm/pgtable.h>
 #include <asm/uaccess.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 /*
  * ptrace a task: make the debugger its new parent and
@@ -458,15 +455,15 @@ asmlinkage long sys_ptrace(long request,
 {
 	struct task_struct *child;
 	long ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	/*
 	 * This lock_kernel fixes a subtle race with suid exec
 	 */
-	/***** TOMOYO Linux start. *****/
-#ifdef TOMOYO_SYS_PTRACE
-	if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;
-#endif
-	/***** TOMOYO Linux end. *****/
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
 		ret = ptrace_traceme();
--- linux-2.6.23-12.orig/kernel/sched.c
+++ linux-2.6.23-12/kernel/sched.c
@@ -63,9 +63,6 @@
 #include <linux/unistd.h>
 
 #include <asm/tlb.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 /*
  * Scheduler clock - returns current time in nanosec units.
@@ -4066,9 +4063,8 @@ int can_nice(const struct task_struct *p
 asmlinkage long sys_nice(int increment)
 {
 	long nice, retval;
-	/***** 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.23-12.orig/kernel/signal.c
+++ linux-2.6.23-12/kernel/signal.c
@@ -32,9 +32,6 @@
 #include <asm/unistd.h>
 #include <asm/siginfo.h>
 #include "audit.h"	/* audit_signal_info() */
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 /*
  * SLAB caches for signal bits.
@@ -2199,10 +2196,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;
@@ -2261,10 +2256,8 @@ asmlinkage long sys_tgkill(int tgid, int
 	/* This is only valid for single tasks */
 	if (pid <= 0 || tgid <= 0)
 		return -EINVAL;
-	/***** 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_tgkill_permission(tgid, pid, sig))
+		return -EPERM;
 
 	return do_tkill(tgid, pid, sig);
 }
@@ -2278,10 +2271,8 @@ sys_tkill(int pid, int sig)
 	/* This is only valid for single tasks */
 	if (pid <= 0)
 		return -EINVAL;
-	/***** 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_tkill_permission(pid, sig))
+		return -EPERM;
 
 	return do_tkill(0, pid, sig);
 }
@@ -2299,6 +2290,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.23-12.orig/kernel/sys.c
+++ linux-2.6.23-12/kernel/sys.c
@@ -42,9 +42,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)
@@ -675,9 +672,10 @@ asmlinkage long sys_setpriority(int whic
 
 	if (which > PRIO_USER || which < PRIO_PROCESS)
 		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;
@@ -915,9 +913,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;
 
 	/* Instead of trying to make the power_off code look like
 	 * halt when pm_power_off is not set do it the easy way.
@@ -1893,9 +1890,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)) {
@@ -1941,9 +1937,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.23-12.orig/kernel/sysctl.c
+++ linux-2.6.23-12/kernel/sysctl.c
@@ -49,9 +49,6 @@
 
 #include <asm/uaccess.h>
 #include <asm/processor.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 #ifdef CONFIG_X86
 #include <asm/nmi.h>
@@ -1319,81 +1316,6 @@ struct ctl_table_header *sysctl_head_nex
 }
 
 #ifdef CONFIG_SYSCTL_SYSCALL
-
-/***** 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->procname; table++) {
-		if (n == table->ctl_name && n) {
-			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=", n);
-				if (memchr(buffer, '\0', PAGE_SIZE - 2) == NULL) goto out;
-			}
-			if (table->child) {
-				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)
 {
@@ -1410,9 +1332,9 @@ int do_sysctl(int __user *name, int nlen
 
 	for (head = sysctl_head_next(NULL); head;
 			head = sysctl_head_next(head)) {
-		/***** 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);
 		if (error != -ENOTDIR) {
--- linux-2.6.23-12.orig/kernel/time.c
+++ linux-2.6.23-12/kernel/time.c
@@ -38,9 +38,6 @@
 
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 /* 
  * The timezone where the local system is located.  Used as a default by some
@@ -93,9 +90,8 @@ asmlinkage long sys_stime(time_t __user 
 	err = security_settime(&tv, NULL);
 	if (err)
 		return err;
-	/***** TOMOYO Linux start. *****/
-	if (CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;
-	/***** TOMOYO Linux end. *****/
+	if (!ccs_capable(CCS_SYS_SETTIME))
+		return -EPERM;
 
 	do_settimeofday(&tv);
 	return 0;
@@ -165,9 +161,8 @@ int do_sys_settimeofday(struct timespec 
 	error = security_settime(tv, tz);
 	if (error)
 		return error;
-	/***** 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. */
--- linux-2.6.23-12.orig/kernel/time/ntp.c
+++ linux-2.6.23-12/kernel/time/ntp.c
@@ -17,9 +17,7 @@
 #include <linux/capability.h>
 #include <asm/div64.h>
 #include <asm/timex.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
+#include <linux/ccsecurity.h>
 
 /*
  * Timekeeping variables
@@ -249,9 +247,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.23-12.orig/net/core/datagram.c
+++ linux-2.6.23-12/net/core/datagram.c
@@ -56,11 +56,6 @@
 #include <net/sock.h>
 #include <net/tcp_states.h>
 
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-#include <linux/tomoyo_socket.h>
-/***** TOMOYO Linux end. *****/
-
 /*
  *	Is a socket 'connection oriented' ?
  */
@@ -183,10 +178,6 @@ struct sk_buff *skb_recv_datagram(struct
 		} else
 			skb = skb_dequeue(&sk->sk_receive_queue);
 
-		/***** TOMOYO Linux start. *****/
-		if ((error = CheckSocketRecvDatagramPermission(sk, skb, flags)) < 0) goto no_packet;
-		/***** TOMOYO Linux end. *****/
-
 		if (skb)
 			return skb;
 
--- linux-2.6.23-12.orig/net/ipv4/inet_connection_sock.c
+++ linux-2.6.23-12/net/ipv4/inet_connection_sock.c
@@ -23,9 +23,7 @@
 #include <net/route.h>
 #include <net/tcp_states.h>
 #include <net/xfrm.h>
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
+#include <linux/ccsecurity.h>
 
 #ifdef INET_CSK_DEBUG
 const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
@@ -88,9 +86,8 @@ int inet_csk_get_port(struct inet_hashin
 		do {
 			head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
 			spin_lock(&head->lock);
-			/***** SAKURA Linux start. *****/
-			if (SAKURA_MayAutobind(rover) < 0) goto next;
-			/***** SAKURA Linux end. *****/
+			if (ccs_lport_reserved(rover))
+				goto next;
 			inet_bind_bucket_for_each(tb, node, &head->chain)
 				if (tb->port == rover)
 					goto next;
--- linux-2.6.23-12.orig/net/ipv4/inet_hashtables.c
+++ linux-2.6.23-12/net/ipv4/inet_hashtables.c
@@ -22,9 +22,7 @@
 #include <net/inet_connection_sock.h>
 #include <net/inet_hashtables.h>
 #include <net/ip.h>
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
+#include <linux/ccsecurity.h>
 
 /*
  * Allocate and initialize a new local port bind bucket.
@@ -295,9 +293,8 @@ int inet_hash_connect(struct inet_timewa
 		local_bh_disable();
 		for (i = 1; i <= range; i++) {
 			port = low + (i + offset) % range;
-			/***** SAKURA Linux start. *****/
-			if (SAKURA_MayAutobind(port) < 0) continue;
-			/***** SAKURA Linux end. *****/
+			if (ccs_lport_reserved(port))
+				continue;
 			head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
 			spin_lock(&head->lock);
 
--- linux-2.6.23-12.orig/net/ipv4/raw.c
+++ linux-2.6.23-12/net/ipv4/raw.c
@@ -78,6 +78,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];
 DEFINE_RWLOCK(raw_v4_lock);
@@ -601,6 +602,10 @@ static int raw_recvmsg(struct kiocb *ioc
 	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.23-12.orig/net/ipv4/udp.c
+++ linux-2.6.23-12/net/ipv4/udp.c
@@ -103,9 +103,7 @@
 #include <net/checksum.h>
 #include <net/xfrm.h>
 #include "udp_impl.h"
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
+#include <linux/ccsecurity.h>
 
 /*
  *	Snmp MIB for the UDP layer
@@ -166,9 +164,8 @@ int __udp_lib_get_port(struct sock *sk, 
 					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;
 				goto gotit;
 			}
 			size = 0;
@@ -188,9 +185,8 @@ int __udp_lib_get_port(struct sock *sk, 
 				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_lib_lport_inuse(result, udptable))
 				break;
 		}
@@ -842,6 +838,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;
+	}
 
 	ulen = skb->len - sizeof(struct udphdr);
 	copied = len;
--- linux-2.6.23-12.orig/net/ipv6/inet6_hashtables.c
+++ linux-2.6.23-12/net/ipv6/inet6_hashtables.c
@@ -21,9 +21,7 @@
 #include <net/inet_hashtables.h>
 #include <net/inet6_hashtables.h>
 #include <net/ip.h>
-/***** SAKURA Linux start. *****/
-#include <linux/sakura.h>
-/***** SAKURA Linux end. *****/
+#include <linux/ccsecurity.h>
 
 void __inet6_hash(struct inet_hashinfo *hashinfo,
 				struct sock *sk)
@@ -269,9 +267,8 @@ int inet6_hash_connect(struct inet_timew
 		local_bh_disable();
 		for (i = 1; i <= range; i++) {
 			port = low + (i + offset) % range;
-			/***** SAKURA Linux start. *****/
-			if (SAKURA_MayAutobind(port) < 0) continue;
-			/***** SAKURA Linux end. *****/
+			if (ccs_lport_reserved(port))
+				continue;
 			head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
 			spin_lock(&head->lock);
 
--- linux-2.6.23-12.orig/net/ipv6/raw.c
+++ linux-2.6.23-12/net/ipv6/raw.c
@@ -58,6 +58,7 @@
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/ccsecurity.h>
 
 struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE];
 DEFINE_RWLOCK(raw_v6_lock);
@@ -442,6 +443,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.23-12.orig/net/ipv6/udp.c
+++ linux-2.6.23-12/net/ipv6/udp.c
@@ -49,6 +49,7 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include "udp_impl.h"
+#include <linux/ccsecurity.h>
 
 DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
 
@@ -134,6 +135,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;
+	}
 
 	ulen = skb->len - sizeof(struct udphdr);
 	copied = len;
--- linux-2.6.23-12.orig/net/socket.c
+++ linux-2.6.23-12/net/socket.c
@@ -93,11 +93,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, const struct iovec *iov,
 			 unsigned long nr_segs, loff_t pos);
@@ -555,11 +550,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 end. *****/
 
 	return sock->ops->sendmsg(iocb, sock, msg, size);
 }
@@ -1109,11 +1103,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;
 
@@ -1344,9 +1336,11 @@ asmlinkage long sys_bind(int fd, struct 
 			err = security_socket_bind(sock,
 						   (struct sockaddr *)address,
 						   addrlen);
-			/***** TOMOYO Linux start. *****/
-			if (!err) err = CheckSocketBindPermission(sock, (struct sockaddr *) address, addrlen);
-			/***** TOMOYO Linux end. *****/
+			if (!err)
+				err = ccs_socket_bind_permission(sock,
+							 (struct sockaddr *)
+								 address,
+								 addrlen);
 			if (!err)
 				err = sock->ops->bind(sock,
 						      (struct sockaddr *)
@@ -1376,9 +1370,8 @@ asmlinkage long sys_listen(int fd, int b
 			backlog = sysctl_somaxconn;
 
 		err = security_socket_listen(sock, backlog);
-		/***** TOMOYO Linux start. *****/
-		if (!err) err = CheckSocketListenPermission(sock);
-		/***** TOMOYO Linux end. *****/
+		if (!err)
+			err = ccs_socket_listen_permission(sock);
 		if (!err)
 			err = sock->ops->listen(sock, backlog);
 
@@ -1443,12 +1436,10 @@ asmlinkage long sys_accept(int fd, struc
 	if (err < 0)
 		goto out_fd;
 
-	/***** 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_fd;
 	}
-	/***** TOMOYO Linux end. *****/
 	if (upeer_sockaddr) {
 		if (newsock->ops->getname(newsock, (struct sockaddr *)address,
 					  &len, 2) < 0) {
@@ -1511,12 +1502,11 @@ asmlinkage long sys_connect(int fd, stru
 
 	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. *****/
-	err = CheckSocketConnectPermission(sock, (struct sockaddr *) address, addrlen);
-	if (err) goto out_put;
-	/***** TOMOYO Linux end. *****/
 
 	err = sock->ops->connect(sock, (struct sockaddr *)address, addrlen,
 				 sock->file->f_flags);
--- linux-2.6.23-12.orig/net/unix/af_unix.c
+++ linux-2.6.23-12/net/unix/af_unix.c
@@ -115,9 +115,6 @@
 #include <linux/mount.h>
 #include <net/checksum.h>
 #include <linux/security.h>
-/***** TOMOYO Linux start. *****/
-#include <linux/tomoyo.h>
-/***** TOMOYO Linux end. *****/
 
 int sysctl_unix_max_dgram_qlen __read_mostly = 10;
 
@@ -794,10 +791,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)
@@ -841,9 +834,8 @@ 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)
 			goto out_mknod_dput;
@@ -1673,6 +1665,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.23-12.orig/security/Kconfig
+++ linux-2.6.23-12/security/Kconfig
@@ -95,5 +95,7 @@ config SECURITY_ROOTPLUG
 
 source security/selinux/Kconfig
 
+source security/ccsecurity/Kconfig
+
 endmenu
 
--- linux-2.6.23-12.orig/security/Makefile
+++ linux-2.6.23-12/security/Makefile
@@ -16,3 +16,6 @@ obj-$(CONFIG_SECURITY)			+= security.o d
 obj-$(CONFIG_SECURITY_SELINUX)		+= selinux/built-in.o
 obj-$(CONFIG_SECURITY_CAPABILITIES)	+= commoncap.o capability.o
 obj-$(CONFIG_SECURITY_ROOTPLUG)		+= commoncap.o root_plug.o
+
+subdir-$(CONFIG_CCSECURITY)+= ccsecurity
+obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o
