This is TOMOYO Linux patch for Armadillo-9.

Source code for this patch is https://download.atmark-techno.com/armadillo-9/source/linux-2.6.12.3-a9-17.tar.gz
---
 arch/alpha/kernel/ptrace.c         |    5 +++++
 arch/arm/kernel/ptrace.c           |    5 +++++
 arch/arm26/kernel/ptrace.c         |    5 +++++
 arch/cris/arch-v10/kernel/ptrace.c |    6 ++++++
 arch/frv/kernel/ptrace.c           |    5 +++++
 arch/h8300/kernel/ptrace.c         |    6 ++++++
 arch/i386/kernel/ptrace.c          |    5 +++++
 arch/ia64/ia32/sys_ia32.c          |    3 +++
 arch/ia64/kernel/ptrace.c          |    5 +++++
 arch/m32r/kernel/ptrace.c          |    6 ++++++
 arch/m68k/kernel/ptrace.c          |    6 ++++++
 arch/m68knommu/kernel/ptrace.c     |    6 ++++++
 arch/mips/kernel/ptrace.c          |    5 +++++
 arch/mips/kernel/ptrace32.c        |    5 +++++
 arch/parisc/kernel/ptrace.c        |    5 +++++
 arch/ppc/kernel/ptrace.c           |    5 +++++
 arch/ppc64/kernel/ptrace.c         |    5 +++++
 arch/ppc64/kernel/ptrace32.c       |    5 +++++
 arch/s390/kernel/ptrace.c          |    5 +++++
 arch/sh/kernel/ptrace.c            |    5 +++++
 arch/sh64/kernel/ptrace.c          |    6 ++++++
 arch/sparc/kernel/ptrace.c         |    7 +++++++
 arch/sparc64/kernel/ptrace.c       |    7 +++++++
 arch/um/kernel/ptrace.c            |    5 +++++
 arch/v850/kernel/ptrace.c          |    6 ++++++
 arch/x86_64/ia32/ptrace32.c        |    6 ++++++
 arch/x86_64/kernel/ptrace.c        |    5 +++++
 fs/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                          |   24 ++++++++++++++++++++++++
 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/module.c                    |    5 +++++
 kernel/sched.c                     |    2 ++
 kernel/signal.c                    |    8 ++++++++
 kernel/sys.c                       |   10 ++++++++++
 kernel/sysctl.c                    |   15 +++++++++++++--
 kernel/time.c                      |    6 ++++++
 net/ipv4/raw.c                     |    5 +++++
 net/ipv4/tcp_ipv4.c                |    5 +++++
 net/ipv4/udp.c                     |    9 +++++++++
 net/ipv6/raw.c                     |    5 +++++
 net/ipv6/tcp_ipv6.c                |    5 +++++
 net/ipv6/udp.c                     |    9 +++++++++
 net/socket.c                       |   18 ++++++++++++++++++
 net/unix/af_unix.c                 |    6 ++++++
 security/Kconfig                   |    2 ++
 security/Makefile                  |    3 +++
 57 files changed, 353 insertions(+), 4 deletions(-)

--- linux-2.6.12.3-a9-17.orig/arch/alpha/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/alpha/kernel/ptrace.c
@@ -261,6 +261,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.12.3-a9-17.orig/arch/arm/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/arm/kernel/ptrace.c
@@ -786,6 +786,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.12.3-a9-17.orig/arch/arm26/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/arm26/kernel/ptrace.c
@@ -669,6 +669,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.12.3-a9-17.orig/arch/cris/arch-v10/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/cris/arch-v10/kernel/ptrace.c
@@ -17,6 +17,7 @@
 #include <asm/pgtable.h>
 #include <asm/system.h>
 #include <asm/processor.h>
+#include <linux/ccsecurity.h>
 
 /* 
  * Determines which bits in DCCR the user has access to.
@@ -81,6 +82,11 @@ sys_ptrace(long request, long pid, long 
 	struct task_struct *child;
 	int ret;
 	unsigned long __user *datap = (unsigned long __user *)data;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.12.3-a9-17.orig/arch/frv/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/frv/kernel/ptrace.c
@@ -111,6 +111,11 @@ asmlinkage int sys_ptrace(long request, 
 	struct task_struct *child;
 	unsigned long tmp;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.12.3-a9-17.orig/arch/h8300/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/h8300/kernel/ptrace.c
@@ -32,6 +32,7 @@
 #include <asm/system.h>
 #include <asm/processor.h>
 #include <asm/signal.h>
+#include <linux/ccsecurity.h>
 
 /* cpu depend functions */
 extern long h8300_get_reg(struct task_struct *task, int regno);
@@ -61,6 +62,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.12.3-a9-17.orig/arch/i386/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/i386/kernel/ptrace.c
@@ -358,6 +358,11 @@ asmlinkage int sys_ptrace(long request, 
 	struct user * dummy = NULL;
 	int i, ret;
 	unsigned long __user *datap = (unsigned long __user *)data;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.12.3-a9-17.orig/arch/ia64/ia32/sys_ia32.c
+++ linux-2.6.12.3-a9-17/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"
 
@@ -1757,6 +1758,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.12.3-a9-17.orig/arch/ia64/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/ia64/kernel/ptrace.c
@@ -1404,6 +1404,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.12.3-a9-17.orig/arch/m32r/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/m32r/kernel/ptrace.c
@@ -33,6 +33,7 @@
 #include <asm/system.h>
 #include <asm/processor.h>
 #include <asm/mmu_context.h>
+#include <linux/ccsecurity.h>
 
 /*
  * Get the address of the live pt_regs for the specified task.
@@ -760,6 +761,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.12.3-a9-17.orig/arch/m68k/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/m68k/kernel/ptrace.c
@@ -26,6 +26,7 @@
 #include <asm/pgtable.h>
 #include <asm/system.h>
 #include <asm/processor.h>
+#include <linux/ccsecurity.h>
 
 /*
  * does not yet catch signals sent when the child dies.
@@ -121,6 +122,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.12.3-a9-17.orig/arch/m68knommu/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/m68knommu/kernel/ptrace.c
@@ -26,6 +26,7 @@
 #include <asm/pgtable.h>
 #include <asm/system.h>
 #include <asm/processor.h>
+#include <linux/ccsecurity.h>
 
 /*
  * does not yet catch signals sent when the child dies.
@@ -105,6 +106,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.12.3-a9-17.orig/arch/mips/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/mips/kernel/ptrace.c
@@ -51,6 +51,11 @@ asmlinkage int sys_ptrace(long request, 
 {
 	struct task_struct *child;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 #if 0
 	printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
--- linux-2.6.12.3-a9-17.orig/arch/mips/kernel/ptrace32.c
+++ linux-2.6.12.3-a9-17/arch/mips/kernel/ptrace32.c
@@ -43,6 +43,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.12.3-a9-17.orig/arch/parisc/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/parisc/kernel/ptrace.c
@@ -85,6 +85,11 @@ long sys_ptrace(long request, pid_t pid,
 #ifdef DEBUG_PTRACE
 	long oaddr=addr, odata=data;
 #endif
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.12.3-a9-17.orig/arch/ppc/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/ppc/kernel/ptrace.c
@@ -241,6 +241,11 @@ int sys_ptrace(long request, long pid, l
 {
 	struct task_struct *child;
 	int ret = -EPERM;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
--- linux-2.6.12.3-a9-17.orig/arch/ppc64/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/ppc64/kernel/ptrace.c
@@ -56,6 +56,11 @@ int sys_ptrace(long request, long pid, l
 {
 	struct task_struct *child;
 	int ret = -EPERM;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
--- linux-2.6.12.3-a9-17.orig/arch/ppc64/kernel/ptrace32.c
+++ linux-2.6.12.3-a9-17/arch/ppc64/kernel/ptrace32.c
@@ -43,6 +43,11 @@ int sys32_ptrace(long request, long pid,
 {
 	struct task_struct *child;
 	int ret = -EPERM;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	if (request == PTRACE_TRACEME) {
--- linux-2.6.12.3-a9-17.orig/arch/s390/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/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();
 
--- linux-2.6.12.3-a9-17.orig/arch/sh/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/sh/kernel/ptrace.c
@@ -85,6 +85,11 @@ asmlinkage int sys_ptrace(long request, 
 	struct task_struct *child;
 	struct user * dummy = NULL;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.12.3-a9-17.orig/arch/sh64/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/sh64/kernel/ptrace.c
@@ -35,6 +35,7 @@
 #include <asm/system.h>
 #include <asm/processor.h>
 #include <asm/mmu_context.h>
+#include <linux/ccsecurity.h>
 
 /* This mask defines the bits of the SR which the user is not allowed to
    change, which are everything except S, Q, M, PR, SZ, FR. */
@@ -128,6 +129,11 @@ asmlinkage int sys_ptrace(long request, 
 #define WPC_DBRMODE 0x0d104008
 	static int first_call = 1;
 	int ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 
--- linux-2.6.12.3-a9-17.orig/arch/sparc/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/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.12.3-a9-17.orig/arch/sparc64/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/sparc64/kernel/ptrace.c
@@ -162,6 +162,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.12.3-a9-17.orig/arch/um/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/um/kernel/ptrace.c
@@ -47,6 +47,11 @@ long sys_ptrace(long request, long pid, 
 {
 	struct task_struct *child;
 	int i, ret;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 	ret = -EPERM;
--- linux-2.6.12.3-a9-17.orig/arch/v850/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/v850/kernel/ptrace.c
@@ -29,6 +29,7 @@
 #include <asm/ptrace.h>
 #include <asm/processor.h>
 #include <asm/uaccess.h>
+#include <linux/ccsecurity.h>
 
 /* Returns the address where the register at REG_OFFS in P is stashed away.  */
 static v850_reg_t *reg_save_addr (unsigned reg_offs, struct task_struct *t)
@@ -117,6 +118,11 @@ int sys_ptrace(long request, long pid, l
 {
 	struct task_struct *child;
 	int rval;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	lock_kernel();
 
--- linux-2.6.12.3-a9-17.orig/arch/x86_64/ia32/ptrace32.c
+++ linux-2.6.12.3-a9-17/arch/x86_64/ia32/ptrace32.c
@@ -27,6 +27,7 @@
 #include <asm/debugreg.h>
 #include <asm/i387.h>
 #include <asm/fpu32.h>
+#include <linux/ccsecurity.h>
 
 /* determines which flags the user has access to. */
 /* 1 = access 0 = no access */
@@ -233,6 +234,11 @@ asmlinkage long sys32_ptrace(long reques
 	void __user *datap = compat_ptr(data);
 	int ret;
 	__u32 val;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	switch (request) { 
 	default:
--- linux-2.6.12.3-a9-17.orig/arch/x86_64/kernel/ptrace.c
+++ linux-2.6.12.3-a9-17/arch/x86_64/kernel/ptrace.c
@@ -318,6 +318,11 @@ asmlinkage long sys_ptrace(long request,
 	struct task_struct *child;
 	long i, ret;
 	unsigned ui;
+	{
+		const int rc = ccs_ptrace_permission(request, pid);
+		if (rc)
+			return rc;
+	}
 
 	/* This lock_kernel fixes a subtle race with suid exec */
 	lock_kernel();
--- linux-2.6.12.3-a9-17.orig/fs/compat.c
+++ linux-2.6.12.3-a9-17/fs/compat.c
@@ -50,6 +50,7 @@
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
 #include <asm/ioctls.h>
+#include <linux/ccsecurity.h>
 
 /*
  * Not all architectures have sys_utime, so implement this in terms
@@ -442,6 +443,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;
 
@@ -1557,7 +1560,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.12.3-a9-17.orig/fs/exec.c
+++ linux-2.6.12.3-a9-17/fs/exec.c
@@ -136,6 +136,10 @@ asmlinkage long sys_uselib(const char __
 	if (error)
 		goto exit;
 
+	error = ccs_uselib_permission(nd.dentry, nd.mnt);
+	if (error)
+		goto exit;
+
 	file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
 	error = PTR_ERR(file);
 	if (IS_ERR(file))
@@ -504,6 +508,9 @@ struct file *open_exec(const char *name)
 			int err = permission(inode, MAY_EXEC, &nd);
 			if (!err && !(inode->i_mode & 0111))
 				err = -EACCES;
+			if (!err)
+				err = ccs_open_exec_permission(nd.dentry,
+								     nd.mnt);
 			file = ERR_PTR(err);
 			if (!err) {
 				file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
@@ -1191,7 +1198,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.12.3-a9-17.orig/fs/fcntl.c
+++ linux-2.6.12.3-a9-17/fs/fcntl.c
@@ -340,6 +340,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;
@@ -364,6 +366,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.12.3-a9-17.orig/fs/ioctl.c
+++ linux-2.6.12.3-a9-17/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.12.3-a9-17.orig/fs/namei.c
+++ linux-2.6.12.3-a9-17/fs/namei.c
@@ -1368,6 +1368,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.
 	 */
@@ -1474,6 +1479,8 @@ do_last:
 	if (!path.dentry->d_inode) {
 		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);
 		up(&dir->d_inode->i_sem);
 		dput(nd->dentry);
@@ -1651,6 +1658,8 @@ asmlinkage long sys_mknod(const char __u
 	if (!IS_POSIXACL(nd.dentry->d_inode))
 		mode &= ~current->fs->umask;
 	if (!IS_ERR(dentry)) {
+		error = ccs_mknod_permission(dentry, nd.mnt, mode, dev);
+		if (!error)
 		switch (mode & S_IFMT) {
 		case 0: case S_IFREG:
 			error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
@@ -1721,6 +1730,8 @@ asmlinkage long sys_mkdir(const char __u
 		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);
 		}
@@ -1825,6 +1836,8 @@ asmlinkage long sys_rmdir(const char __u
 	dentry = lookup_hash(&nd.last, nd.dentry);
 	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);
 	}
@@ -1900,6 +1913,8 @@ asmlinkage long sys_unlink(const char __
 		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);
@@ -1963,6 +1978,8 @@ asmlinkage long sys_symlink(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);
 		}
@@ -2047,6 +2064,8 @@ asmlinkage long sys_link(const char __us
 	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);
 	}
@@ -2269,6 +2288,8 @@ static inline int do_rename(const char *
 	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.12.3-a9-17.orig/fs/namespace.c
+++ linux-2.6.12.3-a9-17/fs/namespace.c
@@ -370,6 +370,8 @@ static int do_umount(struct vfsmount *mn
 	int retval;
 
 	retval = security_sb_umount(mnt, flags);
+	if (!retval)
+		retval = ccs_umount_permission(mnt, flags);
 	if (retval)
 		return retval;
 
@@ -1008,6 +1010,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;
@@ -1041,6 +1044,9 @@ long do_mount(char * dev_name, char * di
 		return retval;
 
 	retval = security_sb_mount(dev_name, &nd, type_page, flags, data_page);
+	if (!retval)
+		retval = ccs_mount_permission(dev_name, &nd, type_page,
+					      original_flags, data_page);
 	if (retval)
 		goto dput_out;
 
@@ -1299,6 +1305,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.12.3-a9-17.orig/fs/open.c
+++ linux-2.6.12.3-a9-17/fs/open.c
@@ -257,6 +257,8 @@ static inline long do_sys_truncate(const
 	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);
@@ -310,6 +312,9 @@ static inline long do_sys_ftruncate(unsi
 	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);
@@ -582,6 +587,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;
 
 	set_fs_root(current->fs, nd.mnt, nd.dentry);
 	set_fs_altroot();
@@ -613,6 +620,9 @@ asmlinkage long sys_fchmod(unsigned int 
 	err = -EPERM;
 	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
 		goto out_putf;
+	err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode);
+	if (err)
+		goto out_putf;
 	down(&inode->i_sem);
 	if (mode == (mode_t) -1)
 		mode = inode->i_mode;
@@ -646,6 +656,9 @@ asmlinkage long sys_chmod(const char __u
 	error = -EPERM;
 	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
 		goto dput_and_out;
+	error = ccs_chmod_permission(nd.dentry, nd.mnt, mode);
+	if (error)
+		goto dput_and_out;
 
 	down(&inode->i_sem);
 	if (mode == (mode_t) -1)
@@ -703,6 +716,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);
 	}
@@ -716,6 +731,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);
 	}
@@ -730,6 +747,9 @@ asmlinkage long sys_fchown(unsigned int 
 
 	file = fget(fd);
 	if (file) {
+		error = ccs_chown_permission(file->f_dentry, file->f_vfsmnt,
+					     user, group);
+		if (!error)
 		error = chown_common(file->f_dentry, user, group);
 		fput(file);
 	}
@@ -761,7 +781,9 @@ struct file *filp_open(const char * file
 	if (namei_flags & O_TRUNC)
 		namei_flags |= 2;
 
+	ccs_save_open_mode(flags);
 	error = open_namei(filename, namei_flags, mode, &nd);
+	ccs_clear_open_mode();
 	if (!error)
 		return dentry_open(nd.dentry, nd.mnt, flags);
 
@@ -1041,6 +1063,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.12.3-a9-17.orig/fs/proc/proc_misc.c
+++ linux-2.6.12.3-a9-17/fs/proc/proc_misc.c
@@ -617,4 +617,5 @@ void __init proc_misc_init(void)
 			entry->proc_fops = &ppc_htab_operations;
 	}
 #endif
+	printk(KERN_INFO "Hook version: 2.6.12.3-a9-17 2012/03/08\n");
 }
--- linux-2.6.12.3-a9-17.orig/fs/stat.c
+++ linux-2.6.12.3-a9-17/fs/stat.c
@@ -44,6 +44,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.12.3-a9-17.orig/include/linux/init_task.h
+++ linux-2.6.12.3-a9-17/include/linux/init_task.h
@@ -63,6 +63,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)
@@ -111,6 +119,7 @@ extern struct group_info init_groups;
 	.switch_lock	= SPIN_LOCK_UNLOCKED,				\
 	.journal_info	= NULL,						\
 	.cpu_timers	= INIT_CPU_TIMERS(tsk.cpu_timers),		\
+	INIT_CCSECURITY                                                 \
 }
 
 
--- linux-2.6.12.3-a9-17.orig/include/linux/sched.h
+++ linux-2.6.12.3-a9-17/include/linux/sched.h
@@ -139,6 +139,8 @@ struct sched_param {
 
 #ifdef __KERNEL__
 
+struct ccs_domain_info;
+
 #include <linux/spinlock.h>
 
 /*
@@ -740,6 +742,10 @@ struct task_struct {
 	nodemask_t mems_allowed;
 	int cpuset_mems_generation;
 #endif
+#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.12.3-a9-17.orig/include/linux/security.h
+++ linux-2.6.12.3-a9-17/include/linux/security.h
@@ -30,6 +30,7 @@
 #include <linux/shm.h>
 #include <linux/msg.h>
 #include <linux/sched.h>
+#include <linux/ccsecurity.h>
 
 struct ctl_table;
 
--- linux-2.6.12.3-a9-17.orig/kernel/compat.c
+++ linux-2.6.12.3-a9-17/kernel/compat.c
@@ -852,6 +852,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.12.3-a9-17.orig/kernel/fork.c
+++ linux-2.6.12.3-a9-17/kernel/fork.c
@@ -117,6 +117,7 @@ void __put_task_struct(struct task_struc
 	free_uid(tsk->user);
 	put_group_info(tsk->group_info);
 
+	ccs_free_task_security(tsk);
 	if (!profile_handoff_task(tsk))
 		free_task(tsk);
 }
@@ -957,6 +958,9 @@ static task_t *copy_process(unsigned lon
 		goto bad_fork_cleanup_policy;
 	if ((retval = audit_alloc(p)))
 		goto bad_fork_cleanup_security;
+	retval = ccs_alloc_task_security(p);
+	if (retval)
+		goto bad_fork_cleanup_audit;
 	/* copy all the process information */
 	if ((retval = copy_semundo(clone_flags, p)))
 		goto bad_fork_cleanup_audit;
@@ -1128,6 +1132,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.12.3-a9-17.orig/kernel/module.c
+++ linux-2.6.12.3-a9-17/kernel/module.c
@@ -38,6 +38,7 @@
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
 #include <asm/cacheflush.h>
+#include <linux/ccsecurity.h>
 
 #if 0
 #define DEBUGP printk
@@ -531,6 +532,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;
@@ -1764,6 +1767,8 @@ sys_init_module(void __user *umod,
 	/* Must have permission */
 	if (!capable(CAP_SYS_MODULE))
 		return -EPERM;
+	if (!ccs_capable(CCS_USE_KERNEL_MODULE))
+		return -EPERM;
 
 	/* Only one module load at a time, please */
 	if (down_interruptible(&module_mutex) != 0)
--- linux-2.6.12.3-a9-17.orig/kernel/sched.c
+++ linux-2.6.12.3-a9-17/kernel/sched.c
@@ -3250,6 +3250,8 @@ asmlinkage long sys_nice(int increment)
 {
 	int retval;
 	long nice;
+	if (!ccs_capable(CCS_SYS_NICE))
+		return -EPERM;
 
 	/*
 	 * Setpriority might change our priority at the same moment.
--- linux-2.6.12.3-a9-17.orig/kernel/signal.c
+++ linux-2.6.12.3-a9-17/kernel/signal.c
@@ -2255,6 +2255,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;
@@ -2284,6 +2286,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;
 
 	info.si_signo = sig;
 	info.si_errno = 0;
@@ -2324,6 +2328,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;
 
 	info.si_signo = sig;
 	info.si_errno = 0;
@@ -2364,6 +2370,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.12.3-a9-17.orig/kernel/sys.c
+++ linux-2.6.12.3-a9-17/kernel/sys.c
@@ -252,6 +252,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;
@@ -383,6 +387,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;
 
 	lock_kernel();
 	switch (cmd) {
@@ -1385,6 +1391,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)) {
@@ -1430,6 +1438,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.12.3-a9-17.orig/kernel/sysctl.c
+++ linux-2.6.12.3-a9-17/kernel/sysctl.c
@@ -988,7 +988,11 @@ int do_sysctl(int __user *name, int nlen
 		struct ctl_table_header *head =
 			list_entry(tmp, struct ctl_table_header, ctl_entry);
 		void *context = NULL;
-		int error = parse_table(name, nlen, oldval, oldlenp, 
+		int error;
+		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);
 		if (context)
@@ -1058,6 +1062,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,
@@ -2116,7 +2127,7 @@ int sysctl_string(ctl_table *table, int 
 			len--;
 		((char *) table->data)[len] = 0;
 	}
-	return 0;
+	return 1;
 }
 
 /*
--- linux-2.6.12.3-a9-17.orig/kernel/time.c
+++ linux-2.6.12.3-a9-17/kernel/time.c
@@ -90,6 +90,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;
@@ -157,6 +159,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. */
@@ -235,6 +239,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.12.3-a9-17.orig/net/ipv4/raw.c
+++ linux-2.6.12.3-a9-17/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);
@@ -585,6 +586,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.12.3-a9-17.orig/net/ipv4/tcp_ipv4.c
+++ linux-2.6.12.3-a9-17/net/ipv4/tcp_ipv4.c
@@ -74,6 +74,7 @@
 #include <linux/stddef.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/ccsecurity.h>
 
 extern int sysctl_ip_dynaddr;
 int sysctl_tcp_tw_reuse;
@@ -232,6 +233,8 @@ static int tcp_v4_get_port(struct sock *
 				rover = low;
 			head = &tcp_bhash[tcp_bhashfn(rover)];
 			spin_lock(&head->lock);
+			if (ccs_lport_reserved(rover))
+				goto next;
 			tb_for_each(tb, node, &head->chain)
 				if (tb->port == rover)
 					goto next;
@@ -671,6 +674,8 @@ static inline int tcp_v4_hash_connect(st
  		local_bh_disable();
 		for (i = 1; i <= range; i++) {
 			port = low + (i + offset) % range;
+			if (ccs_lport_reserved(port))
+				continue;
  			head = &tcp_bhash[tcp_bhashfn(port)];
  			spin_lock(&head->lock);
 
--- linux-2.6.12.3-a9-17.orig/net/ipv4/udp.c
+++ linux-2.6.12.3-a9-17/net/ipv4/udp.c
@@ -107,6 +107,7 @@
 #include <net/inet_common.h>
 #include <net/checksum.h>
 #include <net/xfrm.h>
+#include <linux/ccsecurity.h>
 
 /*
  *	Snmp MIB for the UDP layer
@@ -145,6 +146,8 @@ static int udp_v4_get_port(struct sock *
 					result = sysctl_local_port_range[0] +
 						((result - sysctl_local_port_range[0]) &
 						 (UDP_HTABLE_SIZE - 1));
+				if (ccs_lport_reserved(result))
+					continue;
 				goto gotit;
 			}
 			size = 0;
@@ -161,6 +164,8 @@ static int udp_v4_get_port(struct sock *
 				result = sysctl_local_port_range[0]
 					+ ((result - sysctl_local_port_range[0]) &
 					   (UDP_HTABLE_SIZE - 1));
+			if (ccs_lport_reserved(result))
+				continue;
 			if (!udp_lport_inuse(result))
 				break;
 		}
@@ -795,6 +800,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.12.3-a9-17.orig/net/ipv6/raw.c
+++ linux-2.6.12.3-a9-17/net/ipv6/raw.c
@@ -63,6 +63,7 @@
 #ifdef CONFIG_IPV6_MROUTE
 #include <linux/mroute6.h>
 #endif
+#include <linux/ccsecurity.h>
 
 struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE];
 DEFINE_RWLOCK(raw_v6_lock);
@@ -411,6 +412,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.12.3-a9-17.orig/net/ipv6/tcp_ipv6.c
+++ linux-2.6.12.3-a9-17/net/ipv6/tcp_ipv6.c
@@ -63,6 +63,7 @@
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/ccsecurity.h>
 
 static void	tcp_v6_send_reset(struct sk_buff *skb);
 static void	tcp_v6_or_send_ack(struct sk_buff *skb, struct open_request *req);
@@ -148,6 +149,8 @@ static int tcp_v6_get_port(struct sock *
 				rover = low;
 			head = &tcp_bhash[tcp_bhashfn(rover)];
 			spin_lock(&head->lock);
+			if (ccs_lport_reserved(rover))
+				goto next;
 			tb_for_each(tb, node, &head->chain)
 				if (tb->port == rover)
 					goto next;
@@ -551,6 +554,8 @@ static int tcp_v6_hash_connect(struct so
  		local_bh_disable();
 		for (i = 1; i <= range; i++) {
 			port = low + (i + offset) % range;
+			if (ccs_lport_reserved(port))
+				continue;
  			head = &tcp_bhash[tcp_bhashfn(port)];
  			spin_lock(&head->lock);
 
--- linux-2.6.12.3-a9-17.orig/net/ipv6/udp.c
+++ linux-2.6.12.3-a9-17/net/ipv6/udp.c
@@ -57,6 +57,7 @@
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/ccsecurity.h>
 
 DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6);
 
@@ -87,6 +88,8 @@ static int udp_v6_get_port(struct sock *
 					result = sysctl_local_port_range[0] +
 						((result - sysctl_local_port_range[0]) &
 						 (UDP_HTABLE_SIZE - 1));
+				if (ccs_lport_reserved(result))
+					continue;
 				goto gotit;
 			}
 			size = 0;
@@ -103,6 +106,8 @@ static int udp_v6_get_port(struct sock *
 				result = sysctl_local_port_range[0]
 					+ ((result - sysctl_local_port_range[0]) &
 					   (UDP_HTABLE_SIZE - 1));
+			if (ccs_lport_reserved(result))
+				continue;
 			if (!udp_lport_inuse(result))
 				break;
 		}
@@ -240,6 +245,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.12.3-a9-17.orig/net/socket.c
+++ linux-2.6.12.3-a9-17/net/socket.c
@@ -538,6 +538,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;
 
@@ -1094,6 +1096,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;
 		
@@ -1287,6 +1291,11 @@ asmlinkage long sys_bind(int fd, struct 
 				sockfd_put(sock);
 				return err;
 			}
+
+			err = ccs_socket_bind_permission(sock,
+							 (struct sockaddr *)
+							 address, addrlen);
+			if (!err)
 			err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);
 		}
 		sockfd_put(sock);
@@ -1318,6 +1327,8 @@ asmlinkage long sys_listen(int fd, int b
 			return err;
 		}
 
+		err = ccs_socket_listen_permission(sock);
+		if (!err)
 		err=sock->ops->listen(sock, backlog);
 		sockfd_put(sock);
 	}
@@ -1368,6 +1379,10 @@ asmlinkage long sys_accept(int fd, struc
 	if (err < 0)
 		goto out_release;
 
+	if (ccs_socket_post_accept_permission(sock, newsock)) {
+		err = -EAGAIN; /* Hope less harmful than -EPERM. */
+		goto out_release;
+	}
 	if (upeer_sockaddr) {
 		if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {
 			err = -ECONNABORTED;
@@ -1421,6 +1436,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.12.3-a9-17.orig/net/unix/af_unix.c
+++ linux-2.6.12.3-a9-17/net/unix/af_unix.c
@@ -781,6 +781,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;
@@ -1554,6 +1556,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.12.3-a9-17.orig/security/Kconfig
+++ linux-2.6.12.3-a9-17/security/Kconfig
@@ -87,5 +87,7 @@ config SECURITY_SECLVL
 
 source security/selinux/Kconfig
 
+source security/ccsecurity/Kconfig
+
 endmenu
 
--- linux-2.6.12.3-a9-17.orig/security/Makefile
+++ linux-2.6.12.3-a9-17/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
