This is TOMOYO Linux patch for kernel 2.6.30.10.

Source code for this patch is https://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.30.10.tar.xz
---
 fs/compat.c                     |    2 +-
 fs/compat_ioctl.c               |    3 +++
 fs/exec.c                       |    2 +-
 fs/fcntl.c                      |    4 ++++
 fs/ioctl.c                      |    2 ++
 fs/namei.c                      |   28 ++++++++++++++++++++++++++++
 fs/namespace.c                  |    8 ++++++++
 fs/open.c                       |   24 ++++++++++++++++++++++++
 fs/proc/version.c               |    7 +++++++
 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                 |   10 ++++++++++
 kernel/sched.c                  |    2 ++
 kernel/signal.c                 |    8 ++++++++
 kernel/sys.c                    |   10 ++++++++++
 kernel/sysctl.c                 |    3 +++
 kernel/time.c                   |    4 ++++
 kernel/time/ntp.c               |    6 ++++++
 net/ipv4/inet_connection_sock.c |    3 +++
 net/ipv4/inet_hashtables.c      |    3 +++
 net/ipv4/raw.c                  |    5 +++++
 net/ipv4/udp.c                  |    8 +++++++-
 net/ipv6/raw.c                  |    5 +++++
 net/ipv6/udp.c                  |    5 +++++
 net/socket.c                    |   18 ++++++++++++++++++
 net/unix/af_unix.c              |    7 +++++++
 security/Kconfig                |    2 ++
 security/Makefile               |    3 +++
 34 files changed, 212 insertions(+), 3 deletions(-)

--- linux-2.6.30.10.orig/fs/compat.c
+++ linux-2.6.30.10/fs/compat.c
@@ -1543,7 +1543,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)
 		goto out;
 
--- linux-2.6.30.10.orig/fs/compat_ioctl.c
+++ linux-2.6.30.10/fs/compat_ioctl.c
@@ -113,6 +113,7 @@
 #ifdef CONFIG_SPARC
 #include <asm/fbio.h>
 #endif
+#include <linux/ccsecurity.h>
 
 static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
 			      unsigned long arg, struct file *f)
@@ -2799,6 +2800,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;
 
--- linux-2.6.30.10.orig/fs/exec.c
+++ linux-2.6.30.10/fs/exec.c
@@ -1324,7 +1324,7 @@ int do_execve(char * filename,
 		goto out;
 
 	current->flags &= ~PF_KTHREAD;
-	retval = search_binary_handler(bprm,regs);
+	retval = ccs_search_binary_handler(bprm, regs);
 	if (retval < 0)
 		goto out;
 
--- linux-2.6.30.10.orig/fs/fcntl.c
+++ linux-2.6.30.10/fs/fcntl.c
@@ -347,6 +347,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
 		goto out;
 
 	err = security_file_fcntl(filp, cmd, arg);
+	if (!err)
+		err = ccs_fcntl_permission(filp, cmd, arg);
 	if (err) {
 		fput(filp);
 		return err;
@@ -372,6 +374,8 @@ SYSCALL_DEFINE3(fcntl64, 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;
--- linux-2.6.30.10.orig/fs/ioctl.c
+++ linux-2.6.30.10/fs/ioctl.c
@@ -578,6 +578,8 @@ SYSCALL_DEFINE3(ioctl, unsigned int, fd,
 		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.30.10.orig/fs/namei.c
+++ linux-2.6.30.10/fs/namei.c
@@ -1533,6 +1533,11 @@ int may_open(struct path *path, int acc_
 		if (!is_owner_or_cap(inode))
 			return -EPERM;
 
+	/* includes O_APPEND and O_TRUNC checks */
+	error = ccs_open_permission(dentry, path->mnt, flag);
+	if (error)
+		return error;
+
 	/*
 	 * Ensure there are no outstanding leases on the file.
 	 */
@@ -1583,6 +1588,9 @@ static int __open_namei_create(struct na
 	if (!IS_POSIXACL(dir->d_inode))
 		mode &= ~current_umask();
 	error = security_path_mknod(&nd->path, path->dentry, mode, 0);
+	if (!error)
+		error = ccs_mknod_permission(path->dentry, nd->path.mnt, mode,
+					     0);
 	if (error)
 		goto out_unlock;
 	error = vfs_create(dir->d_inode, path->dentry, mode, nd);
@@ -1727,7 +1735,9 @@ do_last:
 		error = mnt_want_write(nd.path.mnt);
 		if (error)
 			goto exit_mutex_unlock;
+		ccs_save_open_mode(open_flag);
 		error = __open_namei_create(&nd, &path, flag, mode);
+		ccs_clear_open_mode();
 		if (error) {
 			mnt_drop_write(nd.path.mnt);
 			goto exit;
@@ -1780,7 +1790,9 @@ ok:
 		if (error)
 			goto exit;
 	}
+	ccs_save_open_mode(open_flag);
 	error = may_open(&nd.path, acc_mode, flag);
+	ccs_clear_open_mode();
 	if (error) {
 		if (will_write)
 			mnt_drop_write(nd.path.mnt);
@@ -2001,6 +2013,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
 	if (error)
 		goto out_dput;
 	error = security_path_mknod(&nd.path, dentry, mode, dev);
+	if (!error)
+		error = ccs_mknod_permission(dentry, nd.path.mnt, mode, dev);
 	if (error)
 		goto out_drop_write;
 	switch (mode & S_IFMT) {
@@ -2076,6 +2090,8 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
 	if (error)
 		goto out_dput;
 	error = security_path_mkdir(&nd.path, dentry, mode);
+	if (!error)
+		error = ccs_mkdir_permission(dentry, nd.path.mnt, mode);
 	if (error)
 		goto out_drop_write;
 	error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
@@ -2190,6 +2206,8 @@ static long do_rmdir(int dfd, const char
 	if (error)
 		goto exit3;
 	error = security_path_rmdir(&nd.path, dentry);
+	if (!error)
+		error = ccs_rmdir_permission(dentry, nd.path.mnt);
 	if (error)
 		goto exit4;
 	error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
@@ -2279,6 +2297,8 @@ static long do_unlinkat(int dfd, const c
 		if (error)
 			goto exit2;
 		error = security_path_unlink(&nd.path, dentry);
+		if (!error)
+			error = ccs_unlink_permission(dentry, nd.path.mnt);
 		if (error)
 			goto exit3;
 		error = vfs_unlink(nd.path.dentry->d_inode, dentry);
@@ -2364,6 +2384,8 @@ SYSCALL_DEFINE3(symlinkat, const char __
 	if (error)
 		goto out_dput;
 	error = security_path_symlink(&nd.path, dentry, from);
+	if (!error)
+		error = ccs_symlink_permission(dentry, nd.path.mnt, from);
 	if (error)
 		goto out_drop_write;
 	error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
@@ -2464,6 +2486,9 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
 	if (error)
 		goto out_dput;
 	error = security_path_link(old_path.dentry, &nd.path, new_dentry);
+	if (!error)
+		error = ccs_link_permission(old_path.dentry, new_dentry,
+					    nd.path.mnt);
 	if (error)
 		goto out_drop_write;
 	error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
@@ -2705,6 +2730,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
 		goto exit5;
 	error = security_path_rename(&oldnd.path, old_dentry,
 				     &newnd.path, new_dentry);
+	if (!error)
+		error = ccs_rename_permission(old_dentry, new_dentry,
+					      newnd.path.mnt);
 	if (error)
 		goto exit6;
 	error = vfs_rename(old_dir->d_inode, old_dentry,
--- linux-2.6.30.10.orig/fs/namespace.c
+++ linux-2.6.30.10/fs/namespace.c
@@ -1056,6 +1056,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;
 
@@ -1915,6 +1917,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 path path;
 	int retval = 0;
 	int mnt_flags = 0;
@@ -1964,6 +1967,9 @@ long do_mount(char *dev_name, char *dir_
 
 	retval = security_sb_mount(dev_name, &path,
 				   type_page, flags, data_page);
+	if (!retval)
+		retval = ccs_mount_permission(dev_name, &path, type_page,
+					      original_flags, data_page);
 	if (retval)
 		goto dput_out;
 
@@ -2154,6 +2160,8 @@ SYSCALL_DEFINE2(pivot_root, const char _
 		goto out1;
 
 	error = security_sb_pivotroot(&old, &new);
+	if (!error)
+		error = ccs_pivot_root_permission(&old, &new);
 	if (error) {
 		path_put(&old);
 		goto out1;
--- linux-2.6.30.10.orig/fs/open.c
+++ linux-2.6.30.10/fs/open.c
@@ -273,6 +273,8 @@ static long do_sys_truncate(const char _
 	error = locks_verify_truncate(inode, NULL, length);
 	if (!error)
 		error = security_path_truncate(&path, length, 0);
+	if (!error)
+		error = ccs_truncate_permission(path.dentry, path.mnt);
 	if (!error) {
 		vfs_dq_init(inode);
 		error = do_truncate(path.dentry, length, 0, NULL);
@@ -333,6 +335,8 @@ static long do_sys_ftruncate(unsigned in
 		error = security_path_truncate(&file->f_path, length,
 					       ATTR_MTIME|ATTR_CTIME);
 	if (!error)
+		error = ccs_truncate_permission(dentry, file->f_vfsmnt);
+	if (!error)
 		error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);
 out_putf:
 	fput(file);
@@ -586,6 +590,8 @@ SYSCALL_DEFINE1(chroot, const char __use
 	error = -EPERM;
 	if (!capable(CAP_SYS_CHROOT))
 		goto dput_and_out;
+	if (ccs_chroot_permission(&path))
+		goto dput_and_out;
 
 	set_fs_root(current->fs, &path);
 	error = 0;
@@ -615,6 +621,9 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
 	err = mnt_want_write(file->f_path.mnt);
 	if (err)
 		goto out_putf;
+	err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode);
+	if (err)
+		goto out_drop_write;
 	mutex_lock(&inode->i_mutex);
 	if (mode == (mode_t) -1)
 		mode = inode->i_mode;
@@ -622,6 +631,7 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
 	newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
 	err = notify_change(dentry, &newattrs);
 	mutex_unlock(&inode->i_mutex);
+out_drop_write:
 	mnt_drop_write(file->f_path.mnt);
 out_putf:
 	fput(file);
@@ -644,6 +654,9 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
 	error = mnt_want_write(path.mnt);
 	if (error)
 		goto dput_and_out;
+	error = ccs_chmod_permission(path.dentry, path.mnt, mode);
+	if (error)
+		goto out_drop_write;
 	mutex_lock(&inode->i_mutex);
 	if (mode == (mode_t) -1)
 		mode = inode->i_mode;
@@ -651,6 +664,7 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
 	newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
 	error = notify_change(path.dentry, &newattrs);
 	mutex_unlock(&inode->i_mutex);
+out_drop_write:
 	mnt_drop_write(path.mnt);
 dput_and_out:
 	path_put(&path);
@@ -699,6 +713,8 @@ SYSCALL_DEFINE3(chown, const char __user
 	error = mnt_want_write(path.mnt);
 	if (error)
 		goto out_release;
+	error = ccs_chown_permission(path.dentry, path.mnt, user, group);
+	if (!error)
 	error = chown_common(path.dentry, user, group);
 	mnt_drop_write(path.mnt);
 out_release:
@@ -724,6 +740,8 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
 	error = mnt_want_write(path.mnt);
 	if (error)
 		goto out_release;
+	error = ccs_chown_permission(path.dentry, path.mnt, user, group);
+	if (!error)
 	error = chown_common(path.dentry, user, group);
 	mnt_drop_write(path.mnt);
 out_release:
@@ -743,6 +761,8 @@ SYSCALL_DEFINE3(lchown, const char __use
 	error = mnt_want_write(path.mnt);
 	if (error)
 		goto out_release;
+	error = ccs_chown_permission(path.dentry, path.mnt, user, group);
+	if (!error)
 	error = chown_common(path.dentry, user, group);
 	mnt_drop_write(path.mnt);
 out_release:
@@ -766,6 +786,8 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd
 		goto out_fput;
 	dentry = file->f_path.dentry;
 	audit_inode(NULL, dentry);
+	error = ccs_chown_permission(dentry, file->f_vfsmnt, user, group);
+	if (!error)
 	error = chown_common(dentry, user, group);
 	mnt_drop_write(file->f_path.mnt);
 out_fput:
@@ -1157,6 +1179,8 @@ EXPORT_SYMBOL(sys_close);
  */
 SYSCALL_DEFINE0(vhangup)
 {
+	if (!ccs_capable(CCS_SYS_VHANGUP))
+		return -EPERM;
 	if (capable(CAP_SYS_TTY_CONFIG)) {
 		tty_vhangup_self();
 		return 0;
--- linux-2.6.30.10.orig/fs/proc/version.c
+++ linux-2.6.30.10/fs/proc/version.c
@@ -32,3 +32,10 @@ static int __init proc_version_init(void
 	return 0;
 }
 module_init(proc_version_init);
+
+static int __init ccs_show_version(void)
+{
+	printk(KERN_INFO "Hook version: 2.6.30.10 2012/03/08\n");
+	return 0;
+}
+module_init(ccs_show_version);
--- linux-2.6.30.10.orig/fs/stat.c
+++ linux-2.6.30.10/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.30.10.orig/include/linux/init_task.h
+++ linux-2.6.30.10/include/linux/init_task.h
@@ -108,6 +108,14 @@ extern struct group_info init_groups;
 
 extern struct cred init_cred;
 
+#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)
@@ -174,6 +182,7 @@ extern struct cred init_cred;
 	INIT_TRACE_IRQFLAGS						\
 	INIT_LOCKDEP							\
 	INIT_FTRACE_GRAPH						\
+	INIT_CCSECURITY                                                 \
 }
 
 
--- linux-2.6.30.10.orig/include/linux/sched.h
+++ linux-2.6.30.10/include/linux/sched.h
@@ -41,6 +41,8 @@
 
 #ifdef __KERNEL__
 
+struct ccs_domain_info;
+
 struct sched_param {
 	int sched_priority;
 };
@@ -1429,6 +1431,10 @@ struct task_struct {
 	/* state flags for use by tracers */
 	unsigned long trace;
 #endif
+#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY)
+	struct ccs_domain_info *ccs_domain_info;
+	u32 ccs_flags;
+#endif
 };
 
 /* Future-safe accessor for struct task_struct's cpus_allowed. */
--- linux-2.6.30.10.orig/include/linux/security.h
+++ linux-2.6.30.10/include/linux/security.h
@@ -34,6 +34,7 @@
 #include <linux/xfrm.h>
 #include <linux/gfp.h>
 #include <net/flow.h>
+#include <linux/ccsecurity.h>
 
 /* Maximum number of letters for an LSM name string */
 #define SECURITY_NAME_MAX	10
--- linux-2.6.30.10.orig/kernel/compat.c
+++ linux-2.6.30.10/kernel/compat.c
@@ -915,6 +915,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.30.10.orig/kernel/fork.c
+++ linux-2.6.30.10/kernel/fork.c
@@ -157,6 +157,7 @@ void __put_task_struct(struct task_struc
 	put_cred(tsk->cred);
 	delayacct_tsk_free(tsk);
 
+	ccs_free_task_security(tsk);
 	if (!profile_handoff_task(tsk))
 		free_task(tsk);
 }
@@ -1084,6 +1085,9 @@ static struct task_struct *copy_process(
 
 	if ((retval = audit_alloc(p)))
 		goto bad_fork_cleanup_policy;
+	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;
@@ -1282,6 +1286,7 @@ bad_fork_cleanup_semundo:
 	exit_sem(p);
 bad_fork_cleanup_audit:
 	audit_free(p);
+	ccs_free_task_security(p);
 bad_fork_cleanup_policy:
 #ifdef CONFIG_NUMA
 	mpol_put(p->mempolicy);
--- linux-2.6.30.10.orig/kernel/kexec.c
+++ linux-2.6.30.10/kernel/kexec.c
@@ -37,6 +37,7 @@
 #include <asm/io.h>
 #include <asm/system.h>
 #include <asm/sections.h>
+#include <linux/ccsecurity.h>
 
 /* Per cpu memory for storing cpu states in case of system crash. */
 note_buf_t* crash_notes;
@@ -943,6 +944,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned lon
 	/* 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.30.10.orig/kernel/module.c
+++ linux-2.6.30.10/kernel/module.c
@@ -52,6 +52,7 @@
 #include <linux/ftrace.h>
 #include <linux/async.h>
 #include <linux/percpu.h>
+#include <linux/ccsecurity.h>
 
 #if 0
 #define DEBUGP printk
@@ -779,6 +780,8 @@ SYSCALL_DEFINE2(delete_module, const cha
 
 	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;
@@ -2338,6 +2341,8 @@ SYSCALL_DEFINE3(init_module, void __user
 	/* 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 (mutex_lock_interruptible(&module_mutex) != 0)
--- linux-2.6.30.10.orig/kernel/ptrace.c
+++ linux-2.6.30.10/kernel/ptrace.c
@@ -654,6 +654,11 @@ SYSCALL_DEFINE4(ptrace, long, request, l
 {
 	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
@@ -775,6 +780,11 @@ asmlinkage long compat_sys_ptrace(compat
 {
 	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.30.10.orig/kernel/sched.c
+++ linux-2.6.30.10/kernel/sched.c
@@ -5679,6 +5679,8 @@ int can_nice(const struct task_struct *p
 SYSCALL_DEFINE1(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.30.10.orig/kernel/signal.c
+++ linux-2.6.30.10/kernel/signal.c
@@ -2268,6 +2268,8 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const s
 SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
 {
 	struct siginfo info;
+	if (ccs_kill_permission(pid, sig))
+		return -EPERM;
 
 	info.si_signo = sig;
 	info.si_errno = 0;
@@ -2329,6 +2331,8 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid
 	/* 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);
 }
@@ -2341,6 +2345,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int, 
 	/* 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);
 }
@@ -2358,6 +2364,8 @@ SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, 
 	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.30.10.orig/kernel/sys.c
+++ linux-2.6.30.10/kernel/sys.c
@@ -154,6 +154,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
 
 	if (which > PRIO_USER || which < PRIO_PROCESS)
 		goto out;
+	if (!ccs_capable(CCS_SYS_NICE)) {
+		error = -EPERM;
+		goto out;
+	}
 
 	/* normalize: avoid signed division (rounding problems) */
 	error = -ESRCH;
@@ -373,6 +377,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
 			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.
@@ -1417,6 +1423,8 @@ SYSCALL_DEFINE2(sethostname, char __user
 		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)) {
@@ -1466,6 +1474,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
 		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.30.10.orig/kernel/sysctl.c
+++ linux-2.6.30.10/kernel/sysctl.c
@@ -1707,6 +1707,9 @@ int do_sysctl(int __user *name, int nlen
 
 	for (head = sysctl_head_next(NULL); head;
 			head = sysctl_head_next(head)) {
+		error = ccs_parse_table(name, nlen, oldval, newval,
+					head->ctl_table);
+		if (!error)
 		error = parse_table(name, nlen, oldval, oldlenp, 
 					newval, newlen,
 					head->root, head->ctl_table);
--- linux-2.6.30.10.orig/kernel/time.c
+++ linux-2.6.30.10/kernel/time.c
@@ -92,6 +92,8 @@ SYSCALL_DEFINE1(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;
@@ -163,6 +165,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. */
--- linux-2.6.30.10.orig/kernel/time/ntp.c
+++ linux-2.6.30.10/kernel/time/ntp.c
@@ -14,6 +14,7 @@
 #include <linux/timex.h>
 #include <linux/time.h>
 #include <linux/mm.h>
+#include <linux/ccsecurity.h>
 
 /*
  * NTP timekeeping variables:
@@ -459,10 +460,15 @@ int do_adjtimex(struct timex *txc)
 		if (!(txc->modes & ADJ_OFFSET_READONLY) &&
 		    !capable(CAP_SYS_TIME))
 			return -EPERM;
+		if (!(txc->modes & ADJ_OFFSET_READONLY) &&
+		    !ccs_capable(CCS_SYS_SETTIME))
+			return -EPERM;
 	} else {
 		/* 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;
 
 		/*
 		 * if the quartz is off by more than 10% then
--- linux-2.6.30.10.orig/net/ipv4/inet_connection_sock.c
+++ linux-2.6.30.10/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";
@@ -111,6 +112,8 @@ again:
 			head = &hashinfo->bhash[inet_bhashfn(net, 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 (ib_net(tb) == net && tb->port == rover) {
 					if (tb->fastreuse > 0 &&
--- linux-2.6.30.10.orig/net/ipv4/inet_hashtables.c
+++ linux-2.6.30.10/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.
@@ -443,6 +444,8 @@ int __inet_hash_connect(struct inet_time
 		local_bh_disable();
 		for (i = 1; i <= remaining; i++) {
 			port = low + (i + offset) % remaining;
+			if (ccs_lport_reserved(port))
+				continue;
 			head = &hinfo->bhash[inet_bhashfn(net, port,
 					hinfo->bhash_size)];
 			spin_lock(&head->lock);
--- linux-2.6.30.10.orig/net/ipv4/raw.c
+++ linux-2.6.30.10/net/ipv4/raw.c
@@ -77,6 +77,7 @@
 #include <linux/seq_file.h>
 #include <linux/netfilter.h>
 #include <linux/netfilter_ipv4.h>
+#include <linux/ccsecurity.h>
 
 static struct raw_hashinfo raw_v4_hashinfo = {
 	.lock = __RW_LOCK_UNLOCKED(raw_v4_hashinfo.lock),
@@ -666,6 +667,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.30.10.orig/net/ipv4/udp.c
+++ linux-2.6.30.10/net/ipv4/udp.c
@@ -105,6 +105,7 @@
 #include <net/checksum.h>
 #include <net/xfrm.h>
 #include "udp_impl.h"
+#include <linux/ccsecurity.h>
 
 struct udp_table udp_table;
 EXPORT_SYMBOL(udp_table);
@@ -195,7 +196,8 @@ int udp_lib_get_port(struct sock *sk, un
 			 */
 			do {
 				if (low <= snum && snum <= high &&
-				    !test_bit(snum / UDP_HTABLE_SIZE, bitmap))
+				    !test_bit(snum / UDP_HTABLE_SIZE, bitmap)
+				    && !ccs_lport_reserved(snum))
 					goto found;
 				snum += rand;
 			} while (snum != first);
@@ -901,6 +903,10 @@ try_again:
 				  &peeked, &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.30.10.orig/net/ipv6/raw.c
+++ linux-2.6.30.10/net/ipv6/raw.c
@@ -59,6 +59,7 @@
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/ccsecurity.h>
 
 static struct raw_hashinfo raw_v6_hashinfo = {
 	.lock = __RW_LOCK_UNLOCKED(raw_v6_hashinfo.lock),
@@ -465,6 +466,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.30.10.orig/net/ipv6/udp.c
+++ linux-2.6.30.10/net/ipv6/udp.c
@@ -48,6 +48,7 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include "udp_impl.h"
+#include <linux/ccsecurity.h>
 
 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
 {
@@ -212,6 +213,10 @@ try_again:
 				  &peeked, &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.30.10.orig/net/socket.c
+++ linux-2.6.30.10/net/socket.c
@@ -567,6 +567,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;
 
@@ -1171,6 +1173,8 @@ static int __sock_create(struct net *net
 	}
 
 	err = security_socket_create(family, type, protocol, kern);
+	if (!err)
+		err = ccs_socket_create_permission(family, type, protocol);
 	if (err)
 		return err;
 
@@ -1419,6 +1423,11 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
 						   (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);
@@ -1448,6 +1457,8 @@ SYSCALL_DEFINE2(listen, int, fd, int, ba
 
 		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);
@@ -1517,6 +1528,10 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
 	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) {
@@ -1583,6 +1598,9 @@ SYSCALL_DEFINE3(connect, int, fd, struct
 
 	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.30.10.orig/net/unix/af_unix.c
+++ linux-2.6.30.10/net/unix/af_unix.c
@@ -837,6 +837,9 @@ static int unix_bind(struct socket *sock
 		if (err)
 			goto out_mknod_dput;
 		err = security_path_mknod(&nd.path, dentry, mode, 0);
+		if (!err)
+			err = ccs_mknod_permission(dentry, nd.path.mnt, mode,
+						   0);
 		if (err)
 			goto out_mknod_drop_write;
 		err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
@@ -1669,6 +1672,10 @@ static int unix_dgram_recvmsg(struct kio
 
 	wake_up_interruptible_sync(&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.30.10.orig/security/Kconfig
+++ linux-2.6.30.10/security/Kconfig
@@ -119,5 +119,7 @@ source security/tomoyo/Kconfig
 
 source security/integrity/ima/Kconfig
 
+source security/ccsecurity/Kconfig
+
 endmenu
 
--- linux-2.6.30.10.orig/security/Makefile
+++ linux-2.6.30.10/security/Makefile
@@ -23,3 +23,6 @@ obj-$(CONFIG_CGROUP_DEVICE)		+= device_c
 # Object integrity file lists
 subdir-$(CONFIG_IMA)			+= integrity/ima
 obj-$(CONFIG_IMA)			+= integrity/ima/built-in.o
+
+subdir-$(CONFIG_CCSECURITY)+= ccsecurity
+obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o
