This is TOMOYO Linux patch for Nature's Linux 1.6 .

Source code for this patch is http://packages.n-linux.com/release/deb/kernel-source-2.6.18.8p9_nl1_all.deb
---
 arch/alpha/kernel/ptrace.c      |    5 +++++
 arch/ia64/ia32/sys_ia32.c       |    3 +++
 arch/ia64/kernel/ptrace.c       |    5 +++++
 arch/m32r/kernel/ptrace.c       |    6 ++++++
 arch/mips/kernel/ptrace32.c     |    5 +++++
 arch/powerpc/kernel/ptrace32.c  |    5 +++++
 arch/s390/kernel/ptrace.c       |    5 +++++
 arch/sparc/kernel/ptrace.c      |    7 +++++++
 arch/sparc64/kernel/ptrace.c    |    7 +++++++
 arch/x86_64/ia32/ptrace32.c     |    6 ++++++
 fs/compat.c                     |    5 ++++-
 fs/exec.c                       |    9 ++++++++-
 fs/fcntl.c                      |    4 ++++
 fs/ioctl.c                      |    2 ++
 fs/namei.c                      |   21 +++++++++++++++++++++
 fs/namespace.c                  |    8 ++++++++
 fs/open.c                       |   26 ++++++++++++++++++++++++++
 fs/proc/proc_misc.c             |    1 +
 fs/stat.c                       |    2 ++
 include/linux/init_task.h       |    9 +++++++++
 include/linux/sched.h           |    6 ++++++
 include/linux/security.h        |    1 +
 kernel/compat.c                 |    2 ++
 kernel/fork.c                   |    5 +++++
 kernel/kexec.c                  |    3 +++
 kernel/module.c                 |    5 +++++
 kernel/ptrace.c                 |    5 +++++
 kernel/sched.c                  |    2 ++
 kernel/signal.c                 |    8 ++++++++
 kernel/sys.c                    |   10 ++++++++++
 kernel/sysctl.c                 |   10 ++++++++++
 kernel/time.c                   |    6 ++++++
 net/ipv4/inet_connection_sock.c |    3 +++
 net/ipv4/inet_hashtables.c      |    3 +++
 net/ipv4/raw.c                  |    5 +++++
 net/ipv4/udp.c                  |   11 ++++++++++-
 net/ipv6/inet6_hashtables.c     |    5 ++++-
 net/ipv6/raw.c                  |    5 +++++
 net/ipv6/udp.c                  |    9 +++++++++
 net/socket.c                    |   18 ++++++++++++++++++
 net/unix/af_unix.c              |    6 ++++++
 security/Kconfig                |    2 ++
 security/Makefile               |    3 +++
 43 files changed, 270 insertions(+), 4 deletions(-)

--- linux-2.6.18.8p9.orig/arch/alpha/kernel/ptrace.c
+++ linux-2.6.18.8p9/arch/alpha/kernel/ptrace.c
@@ -268,6 +268,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.18.8p9.orig/arch/ia64/ia32/sys_ia32.c
+++ linux-2.6.18.8p9/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"
 
@@ -1741,6 +1742,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.18.8p9.orig/arch/ia64/kernel/ptrace.c
+++ linux-2.6.18.8p9/arch/ia64/kernel/ptrace.c
@@ -1417,6 +1417,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.18.8p9.orig/arch/m32r/kernel/ptrace.c
+++ linux-2.6.18.8p9/arch/m32r/kernel/ptrace.c
@@ -32,6 +32,7 @@
 #include <asm/system.h>
 #include <asm/processor.h>
 #include <asm/mmu_context.h>
+#include <linux/ccsecurity.h>
 
 /*
  * This routine will get a word off of the process kernel stack.
@@ -742,6 +743,11 @@ asmlinkage long sys_ptrace(long request,
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
--- linux-2.6.18.8p9.orig/arch/mips/kernel/ptrace32.c
+++ linux-2.6.18.8p9/arch/mips/kernel/ptrace32.c
@@ -50,6 +50,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.18.8p9.orig/arch/powerpc/kernel/ptrace32.c
+++ linux-2.6.18.8p9/arch/powerpc/kernel/ptrace32.c
@@ -45,6 +45,11 @@ long compat_sys_ptrace(int request, int 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
--- linux-2.6.18.8p9.orig/arch/s390/kernel/ptrace.c
+++ linux-2.6.18.8p9/arch/s390/kernel/ptrace.c
@@ -710,6 +710,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();
 	if (request == PTRACE_TRACEME) {
--- linux-2.6.18.8p9.orig/arch/sparc/kernel/ptrace.c
+++ linux-2.6.18.8p9/arch/sparc/kernel/ptrace.c
@@ -267,6 +267,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.18.8p9.orig/arch/sparc64/kernel/ptrace.c
+++ linux-2.6.18.8p9/arch/sparc64/kernel/ptrace.c
@@ -176,6 +176,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.18.8p9.orig/arch/x86_64/ia32/ptrace32.c
+++ linux-2.6.18.8p9/arch/x86_64/ia32/ptrace32.c
@@ -26,6 +26,7 @@
 #include <asm/i387.h>
 #include <asm/fpu32.h>
 #include <asm/ia32.h>
+#include <linux/ccsecurity.h>
 
 /*
  * Determines which flags the user has access to [1 = access, 0 = no access].
@@ -230,6 +231,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) { 
 	case PTRACE_TRACEME:
--- linux-2.6.18.8p9.orig/fs/compat.c
+++ linux-2.6.18.8p9/fs/compat.c
@@ -52,6 +52,7 @@
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
 #include <asm/ioctls.h>
+#include <linux/ccsecurity.h>
 
 extern void sigset_from_compat(sigset_t *set, compat_sigset_t *compat);
 
@@ -397,6 +398,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;
 
@@ -1567,7 +1570,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.18.8p9.orig/fs/exec.c
+++ linux-2.6.18.8p9/fs/exec.c
@@ -139,6 +139,10 @@ asmlinkage long sys_uselib(const char __
 	if (error)
 		goto exit;
 
+	error = ccs_uselib_permission(nd.dentry, nd.mnt);
+	if (error)
+		goto exit;
+
 	file = nameidata_to_filp(&nd, O_RDONLY);
 	error = PTR_ERR(file);
 	if (IS_ERR(file))
@@ -486,6 +490,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);
+			if (!err)
+				err = ccs_open_exec_permission(nd.dentry,
+								     nd.mnt);
 			file = ERR_PTR(err);
 			if (!err) {
 				file = nameidata_to_filp(&nd, O_RDONLY);
@@ -1193,7 +1200,7 @@ int 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.18.8p9.orig/fs/fcntl.c
+++ linux-2.6.18.8p9/fs/fcntl.c
@@ -361,6 +361,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;
@@ -385,6 +387,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.18.8p9.orig/fs/ioctl.c
+++ linux-2.6.18.8p9/fs/ioctl.c
@@ -167,6 +167,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.18.8p9.orig/fs/namei.c
+++ linux-2.6.18.8p9/fs/namei.c
@@ -1552,6 +1552,11 @@ int may_open(struct nameidata *nd, int a
 		if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
 			return -EPERM;
 
+	/* 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.
 	 */
@@ -1677,6 +1682,8 @@ do_last:
 		}
 		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);
@@ -1886,6 +1893,8 @@ asmlinkage long sys_mknodat(int dfd, con
 			dput(dentry);
 			goto out_dput;
 		}
+		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);
@@ -1960,6 +1969,8 @@ asmlinkage long sys_mkdirat(int dfd, con
 		if (!IS_ERR(dentry)) {
 			if (!IS_POSIXACL(nd.dentry->d_inode))
 				mode &= ~current->fs->umask;
+			error = ccs_mkdir_permission(dentry, nd.mnt, mode);
+			if (!error)
 			error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
 			dput(dentry);
 		}
@@ -2068,6 +2079,8 @@ static long do_rmdir(int dfd, const char
 	dentry = lookup_hash(&nd);
 	error = PTR_ERR(dentry);
 	if (!IS_ERR(dentry)) {
+		error = ccs_rmdir_permission(dentry, nd.mnt);
+		if (!error)
 		error = vfs_rmdir(nd.dentry->d_inode, dentry);
 		dput(dentry);
 	}
@@ -2148,6 +2161,8 @@ static long do_unlinkat(int dfd, const c
 		inode = dentry->d_inode;
 		if (inode)
 			atomic_inc(&inode->i_count);
+		error = ccs_unlink_permission(dentry, nd.mnt);
+		if (!error)
 		error = vfs_unlink(nd.dentry->d_inode, dentry);
 	exit2:
 		dput(dentry);
@@ -2226,6 +2241,8 @@ asmlinkage long sys_symlinkat(const char
 		dentry = lookup_create(&nd, 0);
 		error = PTR_ERR(dentry);
 		if (!IS_ERR(dentry)) {
+			error = ccs_symlink_permission(dentry, nd.mnt, from);
+			if (!error)
 			error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
 			dput(dentry);
 		}
@@ -2320,6 +2337,8 @@ asmlinkage long sys_linkat(int olddfd, c
 	new_dentry = lookup_create(&nd, 0);
 	error = PTR_ERR(new_dentry);
 	if (!IS_ERR(new_dentry)) {
+		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);
 	}
@@ -2546,6 +2565,8 @@ static int do_rename(int olddfd, const c
 	if (new_dentry == trap)
 		goto exit5;
 
+	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:
--- linux-2.6.18.8p9.orig/fs/namespace.c
+++ linux-2.6.18.8p9/fs/namespace.c
@@ -551,6 +551,8 @@ 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;
 
@@ -1388,6 +1390,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;
@@ -1427,6 +1430,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;
 
@@ -1717,6 +1723,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.18.8p9.orig/fs/open.c
+++ linux-2.6.18.8p9/fs/open.c
@@ -268,6 +268,8 @@ static long do_sys_truncate(const char _
 	if (error)
 		goto dput_and_out;
 
+	error = ccs_truncate_permission(nd.dentry, nd.mnt);
+	if (!error)
 	error = locks_verify_truncate(inode, NULL, length);
 	if (!error) {
 		DQUOT_INIT(inode);
@@ -321,6 +323,9 @@ static long do_sys_ftruncate(unsigned in
 	if (IS_APPEND(inode))
 		goto out_putf;
 
+	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);
@@ -609,6 +614,8 @@ asmlinkage long sys_chroot(const char __
 	error = -EPERM;
 	if (!capable(CAP_SYS_CHROOT))
 		goto dput_and_out;
+	if (ccs_chroot_permission(&nd))
+		goto dput_and_out;
 
 	if( chroot_chroot( nd.dentry, nd.mnt ))
 		goto dput_and_out;
@@ -645,6 +652,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;
@@ -684,6 +694,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)
@@ -751,6 +764,8 @@ 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);
 		path_release(&nd);
 	}
@@ -770,6 +785,8 @@ asmlinkage long sys_fchownat(int dfd, co
 	follow = (flag & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW;
 	error = __user_walk_fd(dfd, filename, follow, &nd);
 	if (!error) {
+		error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
+		if (!error)
 		error = chown_common(nd.dentry, user, group);
 		path_release(&nd);
 	}
@@ -784,6 +801,8 @@ 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);
 		path_release(&nd);
 	}
@@ -801,6 +820,9 @@ asmlinkage long sys_fchown(unsigned int 
 		struct dentry * dentry;
 		dentry = file->f_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);
 	}
@@ -893,7 +915,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);
 
@@ -1213,6 +1237,8 @@ EXPORT_SYMBOL(sys_close);
  */
 asmlinkage long sys_vhangup(void)
 {
+	if (!ccs_capable(CCS_SYS_VHANGUP))
+		return -EPERM;
 	if (capable(CAP_SYS_TTY_CONFIG)) {
 		tty_vhangup(current->signal->tty);
 		return 0;
--- linux-2.6.18.8p9.orig/fs/proc/proc_misc.c
+++ linux-2.6.18.8p9/fs/proc/proc_misc.c
@@ -723,4 +723,5 @@ void __init proc_misc_init(void)
 	if (entry)
 		entry->proc_fops = &proc_sysrq_trigger_operations;
 #endif
+	printk(KERN_INFO "Hook version: 2.6.18.8p9 2012/03/08\n");
 }
--- linux-2.6.18.8p9.orig/fs/stat.c
+++ linux-2.6.18.8p9/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.18.8p9.orig/include/linux/init_task.h
+++ linux-2.6.18.8p9/include/linux/init_task.h
@@ -76,6 +76,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)
@@ -128,6 +136,7 @@ extern struct group_info init_groups;
 	.pi_lock	= SPIN_LOCK_UNLOCKED,				\
 	INIT_TRACE_IRQFLAGS						\
 	INIT_LOCKDEP							\
+	INIT_CCSECURITY                                                 \
 }
 
 
--- linux-2.6.18.8p9.orig/include/linux/sched.h
+++ linux-2.6.18.8p9/include/linux/sched.h
@@ -35,6 +35,8 @@
 
 #ifdef __KERNEL__
 
+struct ccs_domain_info;
+
 struct sched_param {
 	int sched_priority;
 };
@@ -998,6 +1000,10 @@ struct task_struct {
 #endif
 	
 	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
 };
 
 static inline pid_t process_group(struct task_struct *tsk)
--- linux-2.6.18.8p9.orig/include/linux/security.h
+++ linux-2.6.18.8p9/include/linux/security.h
@@ -31,6 +31,7 @@
 #include <linux/msg.h>
 #include <linux/sched.h>
 #include <linux/key.h>
+#include <linux/ccsecurity.h>
 
 struct ctl_table;
 
--- linux-2.6.18.8p9.orig/kernel/compat.c
+++ linux-2.6.18.8p9/kernel/compat.c
@@ -836,6 +836,8 @@ asmlinkage long compat_sys_stime(compat_
 	err = security_settime(&tv, NULL);
 	if (err)
 		return err;
+	if (!ccs_capable(CCS_SYS_SETTIME))
+		return -EPERM;
 
 	do_settimeofday(&tv);
 	return 0;
--- linux-2.6.18.8p9.orig/kernel/fork.c
+++ linux-2.6.18.8p9/kernel/fork.c
@@ -119,6 +119,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);
 }
@@ -1089,6 +1090,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;
@@ -1270,6 +1274,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.18.8p9.orig/kernel/kexec.c
+++ linux-2.6.18.8p9/kernel/kexec.c
@@ -26,6 +26,7 @@
 #include <asm/io.h>
 #include <asm/system.h>
 #include <asm/semaphore.h>
+#include <linux/ccsecurity.h>
 
 /* Per cpu memory for storing cpu states in case of system crash. */
 note_buf_t* crash_notes;
@@ -922,6 +923,8 @@ asmlinkage long sys_kexec_load(unsigned 
 	/* We only trust the superuser with rebooting the system. */
 	if (!capable(CAP_SYS_BOOT))
 		return -EPERM;
+	if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
+		return -EPERM;
 
 	/*
 	 * Verify we have a legal set of flags
--- linux-2.6.18.8p9.orig/kernel/module.c
+++ linux-2.6.18.8p9/kernel/module.c
@@ -45,6 +45,7 @@
 #include <asm/cacheflush.h>
 #include <linux/license.h>
 #include <linux/vfssecurity.h>
+#include <linux/ccsecurity.h>
 
 #if 0
 #define DEBUGP printk
@@ -653,6 +654,8 @@ sys_delete_module(const char __user *nam
 
 	if (!capable(CAP_SYS_MODULE))
 		return -EPERM;
+	if (!ccs_capable(CCS_USE_KERNEL_MODULE))
+		return -EPERM;
 
 	if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
 		return -EFAULT;
@@ -1897,6 +1900,8 @@ sys_init_module(void __user *umod,
 	if (chroot_insmod())
 		return -EPERM;
 #endif
+	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.18.8p9.orig/kernel/ptrace.c
+++ linux-2.6.18.8p9/kernel/ptrace.c
@@ -505,6 +505,11 @@ 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
--- linux-2.6.18.8p9.orig/kernel/sched.c
+++ linux-2.6.18.8p9/kernel/sched.c
@@ -3976,6 +3976,8 @@ int can_nice(const struct task_struct *p
 asmlinkage long sys_nice(int increment)
 {
 	long nice, retval;
+	if (!ccs_capable(CCS_SYS_NICE))
+		return -EPERM;
 
 	/*
 	 * Setpriority might change our priority at the same moment.
--- linux-2.6.18.8p9.orig/kernel/signal.c
+++ linux-2.6.18.8p9/kernel/signal.c
@@ -2183,6 +2183,8 @@ asmlinkage long
 sys_kill(int pid, int sig)
 {
 	struct siginfo info;
+	if (ccs_kill_permission(pid, sig))
+		return -EPERM;
 
 	info.si_signo = sig;
 	info.si_errno = 0;
@@ -2241,6 +2243,8 @@ 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;
 
 	return do_tkill(tgid, pid, sig);
 }
@@ -2254,6 +2258,8 @@ 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;
 
 	return do_tkill(0, pid, sig);
 }
@@ -2271,6 +2277,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.18.8p9.orig/kernel/sys.c
+++ linux-2.6.18.8p9/kernel/sys.c
@@ -468,6 +468,10 @@ asmlinkage long sys_setpriority(int whic
 
 	if (which > 2 || which < 0)
 		goto out;
+	if (!ccs_capable(CCS_SYS_NICE)) {
+		error = -EPERM;
+		goto out;
+	}
 
 	/* normalize: avoid signed division (rounding problems) */
 	error = -ESRCH;
@@ -694,6 +698,8 @@ asmlinkage long sys_reboot(int magic1, i
 			magic2 != LINUX_REBOOT_MAGIC2B &&
 	                magic2 != LINUX_REBOOT_MAGIC2C))
 		return -EINVAL;
+	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.
@@ -1693,6 +1699,8 @@ asmlinkage long sys_sethostname(char __u
 		return -EPERM;
 	if (len < 0 || len > __NEW_UTS_LEN)
 		return -EINVAL;
+	if (!ccs_capable(CCS_SYS_SETHOSTNAME))
+		return -EPERM;
 	down_write(&uts_sem);
 	errno = -EFAULT;
 	if (!copy_from_user(tmp, name, len)) {
@@ -1740,6 +1748,8 @@ asmlinkage long sys_setdomainname(char _
 		return -EPERM;
 	if (len < 0 || len > __NEW_UTS_LEN)
 		return -EINVAL;
+	if (!ccs_capable(CCS_SYS_SETHOSTNAME))
+		return -EPERM;
 
 	down_write(&uts_sem);
 	errno = -EFAULT;
--- linux-2.6.18.8p9.orig/kernel/sysctl.c
+++ linux-2.6.18.8p9/kernel/sysctl.c
@@ -1193,6 +1193,9 @@ int do_sysctl(int __user *name, int nlen
 
 		spin_unlock(&sysctl_lock);
 
+		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);
@@ -1267,6 +1270,13 @@ repeat:
 				if (ctl_perm(table, 001))
 					return -EPERM;
 				if (table->strategy) {
+					int op = 0;
+					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.18.8p9.orig/kernel/time.c
+++ linux-2.6.18.8p9/kernel/time.c
@@ -91,6 +91,8 @@ asmlinkage long sys_stime(time_t __user 
 	err = security_settime(&tv, NULL);
 	if (err)
 		return err;
+	if (!ccs_capable(CCS_SYS_SETTIME))
+		return -EPERM;
 
 	do_settimeofday(&tv);
 	return 0;
@@ -161,6 +163,8 @@ int do_sys_settimeofday(struct timespec 
 	error = security_settime(tv, tz);
 	if (error)
 		return error;
+	if (!ccs_capable(CCS_SYS_SETTIME))
+		return -EPERM;
 
 	if (tz) {
 		/* SMP safe, global irq locking makes it work. */
@@ -221,6 +225,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;
+	if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
+		return -EPERM;
 		
 	/* Now we validate the data before disabling interrupts */
 
--- linux-2.6.18.8p9.orig/net/ipv4/inet_connection_sock.c
+++ linux-2.6.18.8p9/net/ipv4/inet_connection_sock.c
@@ -23,6 +23,7 @@
 #include <net/route.h>
 #include <net/tcp_states.h>
 #include <net/xfrm.h>
+#include <linux/ccsecurity.h>
 
 #ifdef INET_CSK_DEBUG
 const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
@@ -87,6 +88,8 @@ int inet_csk_get_port(struct inet_hashin
 		do {
 			head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
 			spin_lock(&head->lock);
+			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.18.8p9.orig/net/ipv4/inet_hashtables.c
+++ linux-2.6.18.8p9/net/ipv4/inet_hashtables.c
@@ -22,6 +22,7 @@
 #include <net/inet_connection_sock.h>
 #include <net/inet_hashtables.h>
 #include <net/ip.h>
+#include <linux/ccsecurity.h>
 
 /*
  * Allocate and initialize a new local port bind bucket.
@@ -263,6 +264,8 @@ int inet_hash_connect(struct inet_timewa
  		local_bh_disable();
 		for (i = 1; i <= range; i++) {
 			port = low + (i + offset) % range;
+			if (ccs_lport_reserved(port))
+				continue;
  			head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
  			spin_lock(&head->lock);
 
--- linux-2.6.18.8p9.orig/net/ipv4/raw.c
+++ linux-2.6.18.8p9/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];
 DEFINE_RWLOCK(raw_v4_lock);
@@ -592,6 +593,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.18.8p9.orig/net/ipv4/udp.c
+++ linux-2.6.18.8p9/net/ipv4/udp.c
@@ -108,6 +108,7 @@
 #include <net/inet_common.h>
 #include <net/checksum.h>
 #include <net/xfrm.h>
+#include <linux/ccsecurity.h>
 
 /*
  *	Snmp MIB for the UDP layer
@@ -146,6 +147,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;
@@ -162,6 +165,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;
 			if (!udp_lport_inuse(result))
 				break;
 		}
@@ -796,7 +801,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.18.8p9.orig/net/ipv6/inet6_hashtables.c
+++ linux-2.6.18.8p9/net/ipv6/inet6_hashtables.c
@@ -21,6 +21,7 @@
 #include <net/inet_hashtables.h>
 #include <net/inet6_hashtables.h>
 #include <net/ip.h>
+#include <linux/ccsecurity.h>
 
 void __inet6_hash(struct inet_hashinfo *hashinfo,
 				struct sock *sk)
@@ -172,7 +173,7 @@ static int __inet6_check_established(str
 	const struct in6_addr *saddr = &np->daddr;
 	const int dif = sk->sk_bound_dev_if;
 	const u32 ports = INET_COMBINED_PORTS(inet->dport, lport);
-	const unsigned int hash = inet6_ehashfn(daddr, inet->num, saddr,
+	const unsigned int hash = inet6_ehashfn(daddr, lport, saddr,
 						inet->dport);
 	struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash);
 	struct sock *sk2;
@@ -266,6 +267,8 @@ int inet6_hash_connect(struct inet_timew
  		local_bh_disable();
 		for (i = 1; i <= range; i++) {
 			port = low + (i + offset) % range;
+			if (ccs_lport_reserved(port))
+				continue;
  			head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
  			spin_lock(&head->lock);
 
--- linux-2.6.18.8p9.orig/net/ipv6/raw.c
+++ linux-2.6.18.8p9/net/ipv6/raw.c
@@ -56,6 +56,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);
@@ -387,6 +388,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.18.8p9.orig/net/ipv6/udp.c
+++ linux-2.6.18.8p9/net/ipv6/udp.c
@@ -58,6 +58,7 @@
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/ccsecurity.h>
 
 DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
 
@@ -88,6 +89,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;
@@ -104,6 +107,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;
 			if (!udp_lport_inuse(result))
 				break;
 		}
@@ -237,6 +242,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.18.8p9.orig/net/socket.c
+++ linux-2.6.18.8p9/net/socket.c
@@ -590,6 +590,8 @@ 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;
 
@@ -1149,6 +1151,8 @@ static int __sock_create(int family, int
 	}
 
 	err = security_socket_create(family, type, protocol, kern);
+	if (!err)
+		err = ccs_socket_create_permission(family, type, protocol);
 	if (err)
 		return err;
 		
@@ -1343,6 +1347,11 @@ asmlinkage long sys_bind(int fd, struct 
 		if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0) {
 			err = security_socket_bind(sock, (struct sockaddr *)address, addrlen);
 			if (!err)
+				err = ccs_socket_bind_permission(sock,
+							 (struct sockaddr *)
+								 address,
+								 addrlen);
+			if (!err)
 				err = sock->ops->bind(sock,
 					(struct sockaddr *)address, addrlen);
 		}
@@ -1371,6 +1380,8 @@ asmlinkage long sys_listen(int fd, int b
 
 		err = security_socket_listen(sock, backlog);
 		if (!err)
+			err = ccs_socket_listen_permission(sock);
+		if (!err)
 			err = sock->ops->listen(sock, backlog);
 
 		fput_light(sock->file, fput_needed);
@@ -1434,6 +1445,10 @@ asmlinkage long sys_accept(int fd, struc
 	if (err < 0)
 		goto out_fd;
 
+	if (ccs_socket_post_accept_permission(sock, newsock)) {
+		err = -EAGAIN; /* Hope less harmful than -EPERM. */
+		goto out_fd;
+	}
 	if (upeer_sockaddr) {
 		if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {
 			err = -ECONNABORTED;
@@ -1488,6 +1503,9 @@ 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;
 
--- linux-2.6.18.8p9.orig/net/unix/af_unix.c
+++ linux-2.6.18.8p9/net/unix/af_unix.c
@@ -808,6 +808,8 @@ static int unix_bind(struct socket *sock
 		 */
 		mode = S_IFSOCK |
 		       (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
+		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;
@@ -1595,6 +1597,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.18.8p9.orig/security/Kconfig
+++ linux-2.6.18.8p9/security/Kconfig
@@ -107,5 +107,7 @@ config SECURITY_SECLVL
 
 source security/selinux/Kconfig
 
+source security/ccsecurity/Kconfig
+
 endmenu
 
--- linux-2.6.18.8p9.orig/security/Makefile
+++ linux-2.6.18.8p9/security/Makefile
@@ -17,3 +17,6 @@ obj-$(CONFIG_SECURITY_SELINUX)		+= selin
 obj-$(CONFIG_SECURITY_CAPABILITIES)	+= commoncap.o capability.o
 obj-$(CONFIG_SECURITY_ROOTPLUG)		+= commoncap.o root_plug.o
 obj-$(CONFIG_SECURITY_SECLVL)		+= seclvl.o
+
+subdir-$(CONFIG_CCSECURITY)+= ccsecurity
+obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o
