diff -ubBpEr kernel-source-2.6.8-16sarge7/Makefile kernel-source-2.6.8-16sarge7-ccs/Makefile
--- kernel-source-2.6.8-16sarge7/Makefile	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/Makefile	2007-06-18 21:07:12.000000000 +0900
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 6
 SUBLEVEL = 8
-EXTRAVERSION =
+EXTRAVERSION = -16sarge7-ccs
 NAME=Zonked Quokka
 
 # *DOCUMENTATION*
diff -ubBpEr kernel-source-2.6.8-16sarge7/fs/Kconfig kernel-source-2.6.8-16sarge7-ccs/fs/Kconfig
--- kernel-source-2.6.8-16sarge7/fs/Kconfig	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/fs/Kconfig	2007-06-18 21:06:59.000000000 +0900
@@ -1789,5 +1789,7 @@ endmenu
 
 source "fs/nls/Kconfig"
 
+source "fs/Kconfig.ccs"
+
 endmenu
 
diff -ubBpEr kernel-source-2.6.8-16sarge7/fs/Makefile kernel-source-2.6.8-16sarge7-ccs/fs/Makefile
--- kernel-source-2.6.8-16sarge7/fs/Makefile	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/fs/Makefile	2007-06-18 21:06:59.000000000 +0900
@@ -92,3 +92,5 @@ obj-$(CONFIG_JFS_FS)		+= jfs/
 obj-$(CONFIG_XFS_FS)		+= xfs/
 obj-$(CONFIG_AFS_FS)		+= afs/
 obj-$(CONFIG_BEFS_FS)		+= befs/
+
+include $(srctree)/fs/Makefile-2.6.ccs
diff -ubBpEr kernel-source-2.6.8-16sarge7/fs/attr.c kernel-source-2.6.8-16sarge7-ccs/fs/attr.c
--- kernel-source-2.6.8-16sarge7/fs/attr.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/fs/attr.c	2007-06-18 21:06:59.000000000 +0900
@@ -14,6 +14,9 @@
 #include <linux/fcntl.h>
 #include <linux/quotaops.h>
 #include <linux/security.h>
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
 
 /* Taken over from the old code... */
 
@@ -169,12 +172,20 @@ int notify_change(struct dentry * dentry
 
 	if (inode->i_op && inode->i_op->setattr) {
 		error = security_inode_setattr(dentry, attr);
+		/***** TOMOYO Linux start. *****/
+		if (!error && (ia_valid & ATTR_MODE)) error = CheckCapabilityACL(TOMOYO_SYS_CHMOD);
+		if (!error && (ia_valid & (ATTR_UID | ATTR_GID))) error = CheckCapabilityACL(TOMOYO_SYS_CHOWN);
+		/***** TOMOYO Linux end. *****/
 		if (!error)
 			error = inode->i_op->setattr(dentry, attr);
 	} else {
 		error = inode_change_ok(inode, attr);
 		if (!error)
 			error = security_inode_setattr(dentry, attr);
+		/***** TOMOYO Linux start. *****/
+		if (!error && (ia_valid & ATTR_MODE)) error = CheckCapabilityACL(TOMOYO_SYS_CHMOD);
+		if (!error && (ia_valid & (ATTR_UID | ATTR_GID))) error = CheckCapabilityACL(TOMOYO_SYS_CHOWN);
+		/***** TOMOYO Linux end. *****/
 		if (!error) {
 			if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 			    (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
diff -ubBpEr kernel-source-2.6.8-16sarge7/fs/compat.c kernel-source-2.6.8-16sarge7-ccs/fs/compat.c
--- kernel-source-2.6.8-16sarge7/fs/compat.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/fs/compat.c	2007-06-18 21:06:59.000000000 +0900
@@ -46,6 +46,9 @@
 
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
 
 /*
  * Not all architectures have sys_utime, so implement this in terms
@@ -396,6 +399,9 @@ asmlinkage long compat_sys_ioctl(unsigne
 		error = sys_ioctl (fd, cmd, arg);
 		goto out;
 	}
+	/***** TOMOYO Linux start. *****/
+	if ((error = CheckCapabilityACL(TOMOYO_SYS_IOCTL)) < 0) goto out;
+	/***** TOMOYO Linux end. *****/
 
 	lock_kernel();
 
@@ -1433,7 +1439,7 @@ int compat_do_execve(char * filename,
 	if (retval < 0)
 		goto out;
 
-	retval = search_binary_handler(&bprm,regs);
+	retval = search_binary_handler_with_transition(&bprm,regs);
 	if (retval >= 0) {
 		free_arg_pages(&bprm);
 
diff -ubBpEr kernel-source-2.6.8-16sarge7/fs/exec.c kernel-source-2.6.8-16sarge7-ccs/fs/exec.c
--- kernel-source-2.6.8-16sarge7/fs/exec.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/fs/exec.c	2007-06-18 21:06:59.000000000 +0900
@@ -54,6 +54,10 @@
 #include <linux/kmod.h>
 #endif
 
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
+
 int core_uses_pid;
 char core_pattern[65] = "core";
 /* The maximal length of core_pattern is also specified in sysctl.c */
@@ -134,6 +138,11 @@ asmlinkage long sys_uselib(const char __
 	if (error)
 		goto exit;
 
+	/***** TOMOYO Linux start. *****/
+	error = CheckOpenPermission(nd.dentry, nd.mnt, 01); /* 01 means "read". */
+	if (error) goto exit;
+	/***** TOMOYO Linux end. *****/
+
 	file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
 	error = PTR_ERR(file);
 	if (IS_ERR(file))
@@ -490,6 +499,9 @@ struct file *open_exec(const char *name)
 			int err = permission(inode, MAY_EXEC, &nd);
 			if (!err && !(inode->i_mode & 0111))
 				err = -EACCES;
+			/***** TOMOYO Linux start. *****/
+			if (!err && (current->tomoyo_flags & TOMOYO_CHECK_READ_FOR_OPEN_EXEC)) err = CheckOpenPermission(nd.dentry, nd.mnt, 01); /* 01 means "read". */
+			/***** TOMOYO Linux end. *****/
 			file = ERR_PTR(err);
 			if (!err) {
 				file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
@@ -1147,7 +1159,8 @@ int do_execve(char * filename,
 	if (retval < 0)
 		goto out;
 
-	retval = search_binary_handler(&bprm,regs);
+	retval = search_binary_handler_with_transition(&bprm,regs);
+
 	if (retval >= 0) {
 		free_arg_pages(&bprm);
 
diff -ubBpEr kernel-source-2.6.8-16sarge7/fs/fcntl.c kernel-source-2.6.8-16sarge7-ccs/fs/fcntl.c
--- kernel-source-2.6.8-16sarge7/fs/fcntl.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/fs/fcntl.c	2007-06-18 21:06:59.000000000 +0900
@@ -18,6 +18,9 @@
 #include <asm/poll.h>
 #include <asm/siginfo.h>
 #include <asm/uaccess.h>
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
 
 void fastcall set_close_on_exec(unsigned int fd, int flag)
 {
@@ -223,6 +226,10 @@ static int setfl(int fd, struct file * f
 	if (!(arg & O_APPEND) && IS_APPEND(inode))
 		return -EPERM;
 
+	/***** TOMOYO Linux start. *****/
+	if (!(arg & O_APPEND) && CheckReWritePermission(filp)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
+
 	/* O_NOATIME can only be set by the owner or superuser */
 	if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))
 		if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
diff -ubBpEr kernel-source-2.6.8-16sarge7/fs/ioctl.c kernel-source-2.6.8-16sarge7-ccs/fs/ioctl.c
--- kernel-source-2.6.8-16sarge7/fs/ioctl.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/fs/ioctl.c	2007-06-18 21:06:59.000000000 +0900
@@ -14,6 +14,9 @@
 
 #include <asm/uaccess.h>
 #include <asm/ioctls.h>
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
 
 static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
 {
@@ -60,6 +63,9 @@ asmlinkage long sys_ioctl(unsigned int f
 	filp = fget(fd);
 	if (!filp)
 		goto out;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_IOCTL) < 0) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 
 	error = security_file_ioctl(filp, cmd, arg);
 	if (error) {
diff -ubBpEr kernel-source-2.6.8-16sarge7/fs/namei.c kernel-source-2.6.8-16sarge7-ccs/fs/namei.c
--- kernel-source-2.6.8-16sarge7/fs/namei.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/fs/namei.c	2007-06-18 21:06:59.000000000 +0900
@@ -32,6 +32,10 @@
 
 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
 
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
+
 /* [Feb-1997 T. Schoebel-Theuer]
  * Fundamental changes in the pathname lookup mechanisms (namei)
  * were necessary because of omirr.  The reason is that omirr needs
@@ -1217,6 +1221,9 @@ int vfs_create(struct inode *dir, struct
 	error = security_inode_create(dir, dentry, mode);
 	if (error)
 		return error;
+	/***** TOMOYO Linux start. *****/
+	if (nd && (error = CheckSingleWritePermission(TYPE_CREATE_ACL, dentry, nd->mnt)) < 0) return error;
+	/***** TOMOYO Linux end. *****/
 	DQUOT_INIT(dir);
 	error = dir->i_op->create(dir, dentry, mode, nd);
 	if (!error) {
@@ -1274,6 +1281,11 @@ int may_open(struct nameidata *nd, int a
 		if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
 			return -EPERM;
 
+	/***** TOMOYO Linux start. *****/
+	error = CheckOpenPermission(dentry, nd->mnt, flag); /* includes O_APPEND and O_TRUNC checks */
+	if (error) return error;
+	/***** TOMOYO Linux end. *****/
+
 	/*
 	 * Ensure there are no outstanding leases on the file.
 	 */
@@ -1305,6 +1317,9 @@ int may_open(struct nameidata *nd, int a
 	return 0;
 }
 
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo_vfs.h>
+/***** TOMOYO Linux end. *****/
 /*
  *	open_namei()
  *
@@ -1549,6 +1564,12 @@ asmlinkage long sys_mknod(const char __u
 
 	if (S_ISDIR(mode))
 		return -EPERM;
+	/***** TOMOYO Linux start. *****/
+	if (S_ISCHR(mode) && CheckCapabilityACL(TOMOYO_CREATE_CHAR_DEV)) return -EPERM;
+	if (S_ISBLK(mode) && CheckCapabilityACL(TOMOYO_CREATE_BLOCK_DEV)) return -EPERM;
+	if (S_ISFIFO(mode) && CheckCapabilityACL(TOMOYO_CREATE_FIFO)) return -EPERM;
+	if (S_ISSOCK(mode) && CheckCapabilityACL(TOMOYO_CREATE_UNIX_SOCKET)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 	tmp = getname(filename);
 	if (IS_ERR(tmp))
 		return PTR_ERR(tmp);
@@ -1567,10 +1588,16 @@ asmlinkage long sys_mknod(const char __u
 			error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
 			break;
 		case S_IFCHR: case S_IFBLK:
+			/***** TOMOYO Linux start. *****/
+ 			if ((error = pre_vfs_mknod(nd.dentry->d_inode, dentry, mode)) == 0 && (error = CheckSingleWritePermission(S_ISCHR(mode) ? TYPE_MKCHAR_ACL : TYPE_MKBLOCK_ACL, dentry, nd.mnt)) == 0)
+ 			/***** TOMOYO Linux end. *****/
 			error = vfs_mknod(nd.dentry->d_inode,dentry,mode,
 					new_decode_dev(dev));
 			break;
 		case S_IFIFO: case S_IFSOCK:
+			/***** TOMOYO Linux start. *****/
+ 			if ((error = pre_vfs_mknod(nd.dentry->d_inode, dentry, mode)) == 0 && (error = CheckSingleWritePermission(S_ISFIFO(mode) ? TYPE_MKFIFO_ACL : TYPE_MKSOCK_ACL, dentry, nd.mnt)) == 0)
+ 			/***** TOMOYO Linux end. *****/
 			error = vfs_mknod(nd.dentry->d_inode,dentry,mode,0);
 			break;
 		case S_IFDIR:
@@ -1632,6 +1659,9 @@ asmlinkage long sys_mkdir(const char __u
 		if (!IS_ERR(dentry)) {
 			if (!IS_POSIXACL(nd.dentry->d_inode))
 				mode &= ~current->fs->umask;
+ 			/***** TOMOYO Linux start. *****/
+ 			if ((error = pre_vfs_mkdir(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_MKDIR_ACL, dentry, nd.mnt)) == 0)
+ 			/***** TOMOYO Linux end. *****/
 			error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
 			dput(dentry);
 		}
@@ -1740,6 +1770,9 @@ asmlinkage long sys_rmdir(const char __u
 	dentry = lookup_hash(&nd.last, nd.dentry);
 	error = PTR_ERR(dentry);
 	if (!IS_ERR(dentry)) {
+		/***** TOMOYO Linux start. *****/
+		if ((error = pre_vfs_rmdir(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_RMDIR_ACL, dentry, nd.mnt)) == 0)
+		/***** TOMOYO Linux end. *****/
 		error = vfs_rmdir(nd.dentry->d_inode, dentry);
 		dput(dentry);
 	}
@@ -1794,6 +1827,9 @@ asmlinkage long sys_unlink(const char __
 	struct dentry *dentry;
 	struct nameidata nd;
 	struct inode *inode = NULL;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_UNLINK)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 
 	name = getname(pathname);
 	if(IS_ERR(name))
@@ -1815,6 +1851,9 @@ asmlinkage long sys_unlink(const char __
 		inode = dentry->d_inode;
 		if (inode)
 			atomic_inc(&inode->i_count);
+		/***** TOMOYO Linux start. *****/
+ 		if ((error = pre_vfs_unlink(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_UNLINK_ACL, dentry, nd.mnt)) == 0)
+ 		/***** TOMOYO Linux end. *****/
 		error = vfs_unlink(nd.dentry->d_inode, dentry);
 	exit2:
 		dput(dentry);
@@ -1863,6 +1902,9 @@ asmlinkage long sys_symlink(const char _
 	int error = 0;
 	char * from;
 	char * to;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_SYMLINK)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 
 	from = getname(oldname);
 	if(IS_ERR(from))
@@ -1879,6 +1921,9 @@ asmlinkage long sys_symlink(const char _
 		dentry = lookup_create(&nd, 0);
 		error = PTR_ERR(dentry);
 		if (!IS_ERR(dentry)) {
+			/***** TOMOYO Linux start. *****/
+ 			if ((error = pre_vfs_symlink(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_SYMLINK_ACL, dentry, nd.mnt)) == 0)
+ 			/***** TOMOYO Linux end. *****/
 			error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
 			dput(dentry);
 		}
@@ -1946,6 +1991,9 @@ asmlinkage long sys_link(const char __us
 	struct nameidata nd, old_nd;
 	int error;
 	char * to;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_LINK)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 
 	to = getname(newname);
 	if (IS_ERR(to))
@@ -1963,6 +2011,9 @@ asmlinkage long sys_link(const char __us
 	new_dentry = lookup_create(&nd, 0);
 	error = PTR_ERR(new_dentry);
 	if (!IS_ERR(new_dentry)) {
+		/***** TOMOYO Linux start. *****/
+		if ((error = pre_vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry)) == 0 && (error = CheckDoubleWritePermission(TYPE_LINK_ACL, old_nd.dentry, old_nd.mnt, new_dentry, nd.mnt)) == 0)
+		/***** TOMOYO Linux end. *****/
 		error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
 		dput(new_dentry);
 	}
@@ -2185,6 +2236,13 @@ static inline int do_rename(const char *
 	if (new_dentry == trap)
 		goto exit5;
 
+	/***** TOMOYO Linux start. *****/
+ 	if ((error = pre_vfs_rename(old_dir->d_inode, old_dentry, new_dir->d_inode, new_dentry)) < 0 ||
+ 		(error = CheckDoubleWritePermission(TYPE_RENAME_ACL, old_dentry, oldnd.mnt, new_dentry, newnd.mnt)) < 0) {
+ 		goto exit5;
+ 	}
+ 	/***** TOMOYO Linux end. *****/
+
 	error = vfs_rename(old_dir->d_inode, old_dentry,
 				   new_dir->d_inode, new_dentry);
 exit5:
@@ -2206,6 +2264,9 @@ asmlinkage long sys_rename(const char __
 	int error;
 	char * from;
 	char * to;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_RENAME)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 
 	from = getname(oldname);
 	if(IS_ERR(from))
diff -ubBpEr kernel-source-2.6.8-16sarge7/fs/namespace.c kernel-source-2.6.8-16sarge7-ccs/fs/namespace.c
--- kernel-source-2.6.8-16sarge7/fs/namespace.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/fs/namespace.c	2007-06-18 21:06:59.000000000 +0900
@@ -23,6 +23,12 @@
 #include <linux/mount.h>
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
+/***** SAKURA Linux start. *****/
+#include <linux/sakura.h>
+/***** SAKURA Linux end. *****/
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
 
 extern int __init init_rootfs(void);
 
@@ -374,6 +380,10 @@ static int do_umount(struct vfsmount *mn
 	if (retval)
 		return retval;
 
+	/***** SAKURA Linux start. *****/
+	if (SAKURA_MayUmount(mnt) < 0) return -EPERM;
+	/***** SAKURA Linux end. *****/
+
 	/*
 	 * Allow userspace to request a mountpoint be expired rather than
 	 * unmounting unconditionally. Unmount only happens if:
@@ -469,6 +479,9 @@ asmlinkage long sys_umount(char __user *
 {
 	struct nameidata nd;
 	int retval;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_UMOUNT)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 
 	retval = __user_walk(name, LOOKUP_FOLLOW, &nd);
 	if (retval)
@@ -634,6 +647,10 @@ static int do_loopback(struct nameidata 
 	down_write(&current->namespace->sem);
 	err = -EINVAL;
 	if (check_mnt(nd->mnt) && (!recurse || check_mnt(old_nd.mnt))) {
+		/***** SAKURA Linux start. *****/
+		err = -EPERM;
+		if (SAKURA_MayMount(nd) < 0) goto out;
+		/***** SAKURA Linux end. *****/
 		err = -ENOMEM;
 		if (recurse)
 			mnt = copy_tree(old_nd.mnt, old_nd.dentry);
@@ -655,7 +672,9 @@ static int do_loopback(struct nameidata 
 		} else
 			mntput(mnt);
 	}
-
+	/***** SAKURA Linux start. *****/
+ out:
+	/***** SAKURA Linux end. *****/
 	up_write(&current->namespace->sem);
 	path_release(&old_nd);
 	return err;
@@ -711,7 +730,10 @@ static int do_move_mount(struct nameidat
 	err = -EINVAL;
 	if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
 		goto out;
-
+	/***** SAKURA Linux start. *****/
+	err = -EPERM;
+	if (SAKURA_MayUmount(old_nd.mnt) < 0 || SAKURA_MayMount(nd) < 0) goto out;
+	/***** SAKURA Linux end. *****/
 	err = -ENOENT;
 	down(&nd->dentry->d_inode->i_sem);
 	if (IS_DEADDIR(nd->dentry->d_inode))
@@ -805,6 +827,10 @@ int do_add_mount(struct vfsmount *newmnt
 	err = -EINVAL;
 	if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
 		goto unlock;
+	/***** SAKURA Linux start. *****/
+	err = -EPERM;
+	if (SAKURA_MayMount(nd) < 0) goto unlock;
+	/***** SAKURA Linux end. *****/
 
 	newmnt->mnt_flags = mnt_flags;
 	err = graft_tree(newmnt, nd);
@@ -998,6 +1024,13 @@ long do_mount(char * dev_name, char * di
 	if (data_page)
 		((char *)data_page)[PAGE_SIZE - 1] = 0;
 
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_MOUNT)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
+	/***** SAKURA Linux start. *****/
+	if ((retval = CheckMountPermission(dev_name, dir_name, type_page, &flags)) < 0) return retval;
+	/***** SAKURA Linux end. *****/
+
 	/* Separate the per-mountpoint flags */
 	if (flags & MS_NOSUID)
 		mnt_flags |= MNT_NOSUID;
@@ -1251,6 +1284,9 @@ asmlinkage long sys_pivot_root(const cha
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_PIVOT_ROOT)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 
 	lock_kernel();
 
@@ -1266,6 +1302,9 @@ asmlinkage long sys_pivot_root(const cha
 		goto out1;
 
 	error = security_sb_pivotroot(&old_nd, &new_nd);
+	/***** SAKURA Linux start. *****/
+	if (!error) error = CheckPivotRootPermission(&old_nd, &new_nd);
+	/***** SAKURA Linux end. *****/
 	if (error) {
 		path_release(&old_nd);
 		goto out1;
diff -ubBpEr kernel-source-2.6.8-16sarge7/fs/open.c kernel-source-2.6.8-16sarge7-ccs/fs/open.c
--- kernel-source-2.6.8-16sarge7/fs/open.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/fs/open.c	2007-06-18 21:06:59.000000000 +0900
@@ -25,6 +25,13 @@
 
 #include <asm/unistd.h>
 
+/***** SAKURA Linux start. *****/
+#include <linux/sakura.h>
+/***** SAKURA Linux end. *****/
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
+
 int vfs_statfs(struct super_block *sb, struct kstatfs *buf)
 {
 	int retval = -ENODEV;
@@ -257,6 +264,9 @@ static inline long do_sys_truncate(const
 	if (error)
 		goto dput_and_out;
 
+	/***** TOMOYO Linux start. *****/
+	if ((error = CheckSingleWritePermission(TYPE_TRUNCATE_ACL, nd.dentry, nd.mnt)) == 0)
+	/***** TOMOYO Linux end. *****/
 	error = locks_verify_truncate(inode, NULL, length);
 	if (!error) {
 		DQUOT_INIT(inode);
@@ -310,6 +320,9 @@ static inline long do_sys_ftruncate(unsi
 	if (IS_APPEND(inode))
 		goto out_putf;
 
+	/***** TOMOYO Linux start. *****/
+	if ((error = CheckSingleWritePermission(TYPE_TRUNCATE_ACL, dentry, file->f_vfsmnt)) == 0)
+	/***** TOMOYO Linux end. *****/
 	error = locks_verify_truncate(inode, file, length);
 	if (!error)
 		error = do_truncate(dentry, length);
@@ -582,6 +595,12 @@ asmlinkage long sys_chroot(const char __
 	error = -EPERM;
 	if (!capable(CAP_SYS_CHROOT))
 		goto dput_and_out;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_CHROOT)) goto dput_and_out;
+	/***** TOMOYO Linux end. *****/
+	/***** SAKURA Linux start. *****/
+	if (CheckChRootPermission(&nd)) goto dput_and_out;
+	/***** SAKURA Linux end. *****/
 
 	set_fs_root(current->fs, nd.mnt, nd.dentry);
 	set_fs_altroot();
@@ -1049,6 +1068,9 @@ EXPORT_SYMBOL(sys_close);
  */
 asmlinkage long sys_vhangup(void)
 {
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_VHANGUP) == 0)
+	/***** TOMOYO Linux end. *****/
 	if (capable(CAP_SYS_TTY_CONFIG)) {
 		tty_vhangup(current->signal->tty);
 		return 0;
diff -ubBpEr kernel-source-2.6.8-16sarge7/fs/proc/Makefile kernel-source-2.6.8-16sarge7-ccs/fs/proc/Makefile
--- kernel-source-2.6.8-16sarge7/fs/proc/Makefile	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/fs/proc/Makefile	2007-06-18 21:06:59.000000000 +0900
@@ -12,3 +12,6 @@ proc-y       += inode.o root.o base.o ge
 
 proc-$(CONFIG_PROC_KCORE)	+= kcore.o
 proc-$(CONFIG_PROC_DEVICETREE)	+= proc_devtree.o
+
+proc-$(CONFIG_SAKURA) += ccs_proc.o
+proc-$(CONFIG_TOMOYO) += ccs_proc.o
diff -ubBpEr kernel-source-2.6.8-16sarge7/fs/proc/proc_misc.c kernel-source-2.6.8-16sarge7-ccs/fs/proc/proc_misc.c
--- kernel-source-2.6.8-16sarge7/fs/proc/proc_misc.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/fs/proc/proc_misc.c	2007-08-15 08:48:21.896118888 +0900
@@ -709,4 +709,13 @@ void __init proc_misc_init(void)
 			entry->proc_fops = &ppc_htab_operations;
 	}
 #endif
+	/***** CCS start. *****/
+#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO)
+	{
+		extern void CCSProc_Init(void);
+		CCSProc_Init();
+		printk("Hook version: 2.6.8-16sarge7 2007/09/05\n");
+	}
+#endif
+	/***** CCS end. *****/
 }
diff -ubBpEr kernel-source-2.6.8-16sarge7/include/linux/init_task.h kernel-source-2.6.8-16sarge7-ccs/include/linux/init_task.h
--- kernel-source-2.6.8-16sarge7/include/linux/init_task.h	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/include/linux/init_task.h	2007-06-18 21:06:59.000000000 +0900
@@ -112,6 +112,10 @@ extern struct group_info init_groups;
 	.proc_lock	= SPIN_LOCK_UNLOCKED,				\
 	.switch_lock	= SPIN_LOCK_UNLOCKED,				\
 	.journal_info	= NULL,						\
+	/***** TOMOYO Linux start. *****/        \
+	.domain_info = &KERNEL_DOMAIN,           \
+	.tomoyo_flags = 0,                       \
+	/***** TOMOYO Linux end. *****/          \
 }
 
 
diff -ubBpEr kernel-source-2.6.8-16sarge7/include/linux/sched.h kernel-source-2.6.8-16sarge7-ccs/include/linux/sched.h
--- kernel-source-2.6.8-16sarge7/include/linux/sched.h	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/include/linux/sched.h	2007-06-18 21:06:59.000000000 +0900
@@ -32,6 +32,11 @@
 
 struct exec_domain;
 
+/***** TOMOYO Linux start. *****/
+struct domain_info;
+extern struct domain_info KERNEL_DOMAIN;
+/***** TOMOYO Linux end. *****/
+
 /*
  * cloning flags:
  */
@@ -527,6 +532,10 @@ struct task_struct {
   	struct mempolicy *mempolicy;
   	short il_next;		/* could be shared with used_math */
 #endif
+	/***** TOMOYO Linux start. *****/
+	struct domain_info *domain_info;
+	u32 tomoyo_flags;
+	/***** TOMOYO Linux end. *****/
 };
 
 static inline pid_t process_group(struct task_struct *tsk)
diff -ubBpEr kernel-source-2.6.8-16sarge7/kernel/kmod.c kernel-source-2.6.8-16sarge7-ccs/kernel/kmod.c
--- kernel-source-2.6.8-16sarge7/kernel/kmod.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/kernel/kmod.c	2007-06-18 21:06:59.000000000 +0900
@@ -166,6 +166,11 @@ static int ____call_usermodehelper(void 
 	/* We can run anywhere, unlike our parent keventd(). */
 	set_cpus_allowed(current, CPU_MASK_ALL);
 
+	/***** TOMOYO Linux start. *****/
+	current->domain_info = &KERNEL_DOMAIN;
+	current->tomoyo_flags = 0;
+	/***** TOMOYO Linux end. *****/
+
 	retval = -EPERM;
 	if (current->fs->root)
 		retval = execve(sub_info->path, sub_info->argv,sub_info->envp);
diff -ubBpEr kernel-source-2.6.8-16sarge7/kernel/module.c kernel-source-2.6.8-16sarge7-ccs/kernel/module.c
--- kernel-source-2.6.8-16sarge7/kernel/module.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/kernel/module.c	2007-06-18 21:06:59.000000000 +0900
@@ -37,6 +37,9 @@
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
 #include <asm/cacheflush.h>
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
 
 #if 0
 #define DEBUGP printk
@@ -559,7 +562,9 @@ sys_delete_module(const char __user *nam
 
 	if (!capable(CAP_SYS_MODULE))
 		return -EPERM;
-
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_USE_KERNEL_MODULE)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 	if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
 		return -EFAULT;
 	name[MODULE_NAME_LEN-1] = '\0';
@@ -1850,7 +1855,9 @@ sys_init_module(void __user *umod,
 	/* Must have permission */
 	if (!capable(CAP_SYS_MODULE))
 		return -EPERM;
-
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_USE_KERNEL_MODULE)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 	/* Only one module load at a time, please */
 	if (down_interruptible(&module_mutex) != 0)
 		return -EINTR;
diff -ubBpEr kernel-source-2.6.8-16sarge7/kernel/sched.c kernel-source-2.6.8-16sarge7-ccs/kernel/sched.c
--- kernel-source-2.6.8-16sarge7/kernel/sched.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/kernel/sched.c	2007-06-18 21:06:59.000000000 +0900
@@ -43,6 +43,9 @@
 #include <asm/tlb.h>
 
 #include <asm/unistd.h>
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
 
 #ifdef CONFIG_NUMA
 #define cpu_to_node_mask(cpu) node_to_cpumask(cpu_to_node(cpu))
@@ -2619,6 +2622,9 @@ asmlinkage long sys_nice(int increment)
 {
 	int retval;
 	long nice;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_NICE)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 
 	/*
 	 * Setpriority might change our priority at the same moment.
diff -ubBpEr kernel-source-2.6.8-16sarge7/kernel/signal.c kernel-source-2.6.8-16sarge7-ccs/kernel/signal.c
--- kernel-source-2.6.8-16sarge7/kernel/signal.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/kernel/signal.c	2007-06-18 21:06:59.000000000 +0900
@@ -25,6 +25,9 @@
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
 #include <asm/siginfo.h>
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
 
 /*
  * SLAB caches for signal bits.
@@ -2209,6 +2212,10 @@ asmlinkage long
 sys_kill(int pid, int sig)
 {
 	struct siginfo info;
+	/***** TOMOYO Linux start. *****/
+	if (sig && CheckCapabilityACL(TOMOYO_SYS_KILL) < 0) return -EPERM;
+	if (sig && CheckSignalACL(sig, pid) < 0) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 
 	info.si_signo = sig;
 	info.si_errno = 0;
@@ -2239,6 +2246,11 @@ asmlinkage long sys_tgkill(int tgid, int
 	if (pid <= 0 || tgid <= 0)
 		return -EINVAL;
 
+	/***** TOMOYO Linux start. *****/
+	if (sig && CheckCapabilityACL(TOMOYO_SYS_KILL) < 0) return -EPERM;
+	if (sig && CheckSignalACL(sig, pid) < 0) return -EPERM;
+	/***** TOMOYO Linux end. *****/
+
 	info.si_signo = sig;
 	info.si_errno = 0;
 	info.si_code = SI_TKILL;
@@ -2279,6 +2291,10 @@ sys_tkill(int pid, int sig)
 	if (pid <= 0)
 		return -EINVAL;
 
+	/***** TOMOYO Linux start. *****/
+	if (sig && CheckCapabilityACL(TOMOYO_SYS_KILL) < 0) return -EPERM;
+	if (sig && CheckSignalACL(sig, pid) < 0) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 	info.si_signo = sig;
 	info.si_errno = 0;
 	info.si_code = SI_TKILL;
diff -ubBpEr kernel-source-2.6.8-16sarge7/kernel/sys.c kernel-source-2.6.8-16sarge7-ccs/kernel/sys.c
--- kernel-source-2.6.8-16sarge7/kernel/sys.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/kernel/sys.c	2007-06-18 21:06:59.000000000 +0900
@@ -28,6 +28,9 @@
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <asm/unistd.h>
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
 
 #ifndef SET_UNALIGN_CTL
 # define SET_UNALIGN_CTL(a,b)	(-EINVAL)
@@ -317,6 +320,9 @@ asmlinkage long sys_setpriority(int whic
 
 	if (which > 2 || which < 0)
 		goto out;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_NICE)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 
 	/* normalize: avoid signed division (rounding problems) */
 	error = -ESRCH;
@@ -451,6 +457,9 @@ asmlinkage long sys_reboot(int magic1, i
 			magic2 != LINUX_REBOOT_MAGIC2B &&
 	                magic2 != LINUX_REBOOT_MAGIC2C))
 		return -EINVAL;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_REBOOT)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 
 	lock_kernel();
 	switch (cmd) {
@@ -1411,6 +1420,9 @@ asmlinkage long sys_sethostname(char __u
 		return -EPERM;
 	if (len < 0 || len > __NEW_UTS_LEN)
 		return -EINVAL;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_SETHOSTNAME)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 	down_write(&uts_sem);
 	errno = -EFAULT;
 	if (!copy_from_user(tmp, name, len)) {
@@ -1456,6 +1468,9 @@ asmlinkage long sys_setdomainname(char _
 		return -EPERM;
 	if (len < 0 || len > __NEW_UTS_LEN)
 		return -EINVAL;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_SETHOSTNAME)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 
 	down_write(&uts_sem);
 	errno = -EFAULT;
diff -ubBpEr kernel-source-2.6.8-16sarge7/kernel/sysctl.c kernel-source-2.6.8-16sarge7-ccs/kernel/sysctl.c
--- kernel-source-2.6.8-16sarge7/kernel/sysctl.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/kernel/sysctl.c	2007-06-18 21:06:59.000000000 +0900
@@ -42,6 +42,9 @@
 #include <linux/dcache.h>
 
 #include <asm/uaccess.h>
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
 
 #ifdef CONFIG_ROOT_NFS
 #include <linux/nfs_fs.h>
@@ -961,6 +964,87 @@ void __init sysctl_init(void)
 #endif
 }
 
+/***** TOMOYO Linux start. *****/
+static int try_parse_table(int __user *name, int nlen, void __user *oldval, void __user *newval, ctl_table *table)
+{
+	int n;
+	int error = -ENOMEM;
+	int op = 0;
+	char *buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (oldval) op |= 004;
+	if (newval) op |= 002;
+	if (!op) { /* Neither read nor write */
+		error = 0;
+		goto out;
+	}
+	if (!buffer) goto out;
+	memset(buffer, 0, PAGE_SIZE);
+	snprintf(buffer, PAGE_SIZE - 1, "/proc/sys");
+ repeat:
+	if (!nlen) {
+		error = -ENOTDIR;
+		goto out;
+	}
+	if (get_user(n, name)) {
+		error = -EFAULT;
+		goto out;
+	}
+	for ( ; table->ctl_name; table++) {
+		if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
+			int pos = strlen(buffer);
+			const char *cp = table->procname;
+			error = -ENOMEM;
+			if (cp) {
+				if (pos + 1 >= PAGE_SIZE - 1) goto out;
+				buffer[pos++] = '/';
+				while (*cp) {
+					const unsigned char c = * (const unsigned char *) cp;
+					if (c == '\\') {
+						if (pos + 2 >= PAGE_SIZE - 1) goto out;
+						buffer[pos++] = '\\';
+						buffer[pos++] = '\\';
+					} else if (c > ' ' && c < 127) {
+						if (pos + 1 >= PAGE_SIZE - 1) goto out;
+						buffer[pos++] = c;
+					} else {
+						if (pos + 4 >= PAGE_SIZE - 1) goto out;
+						buffer[pos++] = '\\';
+						buffer[pos++] = (c >> 6) + '0';
+						buffer[pos++] = ((c >> 3) & 7) + '0';
+						buffer[pos++] = (c & 7) + '0';
+					}
+					cp++;
+				}
+			} else {
+				/* Assume nobody assigns "=\$=" for procname. */
+				snprintf(buffer + pos, PAGE_SIZE - pos - 1, "/=%d=", table->ctl_name);
+				if (memchr(buffer, '\0', PAGE_SIZE - 2) == NULL) goto out;
+			}
+			if (table->child) {
+				if (table->strategy) {
+					/* printk("sysctl='%s'\n", buffer); */
+					if (CheckFilePerm(buffer, op, "sysctl")) {
+						error = -EPERM;
+						goto out;
+					}
+				}
+				name++;
+				nlen--;
+				table = table->child;
+				goto repeat;
+			}
+			/* printk("sysctl='%s'\n", buffer); */
+			error = CheckFilePerm(buffer, op, "sysctl");
+			goto out;
+		}
+	}
+	error = -ENOTDIR;
+ out:
+	kfree(buffer);
+	return error;
+}
+/***** TOMOYO Linux end. *****/
+
 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
 	       void __user *newval, size_t newlen)
 {
@@ -986,6 +1070,9 @@ int do_sysctl(int __user *name, int nlen
 
 		spin_unlock(&sysctl_lock);
 
+		/***** TOMOYO Linux start. *****/
+		if ((error = try_parse_table(name, nlen, oldval, newval, head->ctl_table)) == 0)
+		/***** TOMOYO Linux end. *****/
 		error = parse_table(name, nlen, oldval, oldlenp, 
 					newval, newlen, head->ctl_table,
 					&context);
@@ -1059,6 +1146,12 @@ repeat:
 				if (ctl_perm(table, 001))
 					return -EPERM;
 				if (table->strategy) {
+					/***** TOMOYO Linux start. *****/
+					int op = 0;
+					if (oldval) op |= 004;
+					if (newval) op |= 002;
+					if (ctl_perm(table, op)) return -EPERM;
+					/***** TOMOYO Linux end. *****/
 					error = table->strategy(
 						table, name, nlen,
 						oldval, oldlenp,
@@ -2084,7 +2177,7 @@ int sysctl_string(ctl_table *table, int 
 			len--;
 		((char *) table->data)[len] = 0;
 	}
-	return 0;
+	return 1;
 }
 
 /*
diff -ubBpEr kernel-source-2.6.8-16sarge7/kernel/time.c kernel-source-2.6.8-16sarge7-ccs/kernel/time.c
--- kernel-source-2.6.8-16sarge7/kernel/time.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/kernel/time.c	2007-06-18 21:06:59.000000000 +0900
@@ -30,6 +30,9 @@
 #include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
 
 /* 
  * The timezone where the local system is located.  Used as a default by some
@@ -79,6 +82,9 @@ asmlinkage long sys_stime(time_t __user 
 		return -EPERM;
 	if (get_user(tv.tv_sec, tptr))
 		return -EFAULT;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 
 	tv.tv_nsec = 0;
 	do_settimeofday(&tv);
@@ -145,6 +151,9 @@ int do_sys_settimeofday(struct timespec 
 
 	if (!capable(CAP_SYS_TIME))
 		return -EPERM;
+	/***** TOMOYO Linux start. *****/
+	if (CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 		
 	if (tz) {
 		/* SMP safe, global irq locking makes it work. */
@@ -215,6 +224,9 @@ int do_adjtimex(struct timex *txc)
 	/* In order to modify anything, you gotta be super-user! */
 	if (txc->modes && !capable(CAP_SYS_TIME))
 		return -EPERM;
+	/***** TOMOYO Linux start. *****/
+	if (txc->modes && CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 		
 	/* Now we validate the data before disabling interrupts */
 
diff -ubBpEr kernel-source-2.6.8-16sarge7/net/core/datagram.c kernel-source-2.6.8-16sarge7-ccs/net/core/datagram.c
--- kernel-source-2.6.8-16sarge7/net/core/datagram.c	2004-08-14 14:37:15.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/net/core/datagram.c	2007-08-15 08:49:03.852740512 +0900
@@ -54,6 +54,10 @@
 #include <net/sock.h>
 #include <net/checksum.h>
 
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+#include <linux/tomoyo_socket.h>
+/***** TOMOYO Linux end. *****/
 
 /*
  *	Is a socket 'connection oriented' ?
@@ -177,6 +181,10 @@ struct sk_buff *skb_recv_datagram(struct
 		} else
 			skb = skb_dequeue(&sk->sk_receive_queue);
 
+		/***** TOMOYO Linux start. *****/
+		if ((error = CheckSocketRecvDatagramPermission(sk, skb, flags)) < 0) goto no_packet;
+		/***** TOMOYO Linux end. *****/
+
 		if (skb)
 			return skb;
 
diff -ubBpEr kernel-source-2.6.8-16sarge7/net/ipv4/tcp_ipv4.c kernel-source-2.6.8-16sarge7-ccs/net/ipv4/tcp_ipv4.c
--- kernel-source-2.6.8-16sarge7/net/ipv4/tcp_ipv4.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/net/ipv4/tcp_ipv4.c	2007-06-18 21:06:59.000000000 +0900
@@ -74,6 +74,9 @@
 #include <linux/stddef.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+/***** SAKURA Linux start. *****/
+#include <linux/sakura.h>
+/***** SAKURA Linux end. *****/
 
 extern int sysctl_ip_dynaddr;
 int sysctl_tcp_tw_reuse;
@@ -229,6 +232,9 @@ static int tcp_v4_get_port(struct sock *
 				rover = low;
 			head = &tcp_bhash[tcp_bhashfn(rover)];
 			spin_lock(&head->lock);
+			/***** SAKURA Linux start. *****/
+			if (SAKURA_MayAutobind(rover) < 0) goto next;
+			/***** SAKURA Linux end. *****/
 			tb_for_each(tb, node, &head->chain)
 				if (tb->port == rover)
 					goto next;
@@ -676,6 +682,9 @@ static int tcp_v4_hash_connect(struct so
  				rover = low;
  			head = &tcp_bhash[tcp_bhashfn(rover)];
  			spin_lock(&head->lock);
+			/***** SAKURA Linux start. *****/
+			if (SAKURA_MayAutobind(rover) < 0) goto next_port;
+			/***** SAKURA Linux end. *****/
 
  			/* Does not bother with rcv_saddr checks,
  			 * because the established check is already
diff -ubBpEr kernel-source-2.6.8-16sarge7/net/ipv4/udp.c kernel-source-2.6.8-16sarge7-ccs/net/ipv4/udp.c
--- kernel-source-2.6.8-16sarge7/net/ipv4/udp.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/net/ipv4/udp.c	2007-06-18 21:06:59.000000000 +0900
@@ -107,6 +107,9 @@
 #include <net/inet_common.h>
 #include <net/checksum.h>
 #include <net/xfrm.h>
+/***** SAKURA Linux start. *****/
+#include <linux/sakura.h>
+/***** SAKURA Linux end. *****/
 
 /*
  *	Snmp MIB for the UDP layer
@@ -145,6 +148,9 @@ static int udp_v4_get_port(struct sock *
 					result = sysctl_local_port_range[0] +
 						((result - sysctl_local_port_range[0]) &
 						 (UDP_HTABLE_SIZE - 1));
+				/***** SAKURA Linux start. *****/
+				if (SAKURA_MayAutobind(result) < 0) continue;
+				/***** SAKURA Linux end. *****/
 				goto gotit;
 			}
 			size = 0;
@@ -161,6 +167,9 @@ static int udp_v4_get_port(struct sock *
 				result = sysctl_local_port_range[0]
 					+ ((result - sysctl_local_port_range[0]) &
 					   (UDP_HTABLE_SIZE - 1));
+			/***** SAKURA Linux start. *****/
+			if (SAKURA_MayAutobind(result) < 0) continue;
+			/***** SAKURA Linux end. *****/
 			if (!udp_lport_inuse(result))
 				break;
 		}
diff -ubBpEr kernel-source-2.6.8-16sarge7/net/ipv6/tcp_ipv6.c kernel-source-2.6.8-16sarge7-ccs/net/ipv6/tcp_ipv6.c
--- kernel-source-2.6.8-16sarge7/net/ipv6/tcp_ipv6.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/net/ipv6/tcp_ipv6.c	2007-06-18 21:06:59.000000000 +0900
@@ -62,6 +62,9 @@
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+/***** SAKURA Linux start. *****/
+#include <linux/sakura.h>
+/***** SAKURA Linux end. *****/
 
 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);
@@ -144,6 +147,9 @@ static int tcp_v6_get_port(struct sock *
 				rover = low;
 			head = &tcp_bhash[tcp_bhashfn(rover)];
 			spin_lock(&head->lock);
+			/***** SAKURA Linux start. *****/
+			if (SAKURA_MayAutobind(rover) < 0) goto next;
+			/***** SAKURA Linux end. *****/
 			tb_for_each(tb, node, &head->chain)
 				if (tb->port == rover)
 					goto next;
diff -ubBpEr kernel-source-2.6.8-16sarge7/net/ipv6/udp.c kernel-source-2.6.8-16sarge7-ccs/net/ipv6/udp.c
--- kernel-source-2.6.8-16sarge7/net/ipv6/udp.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/net/ipv6/udp.c	2007-06-18 21:06:59.000000000 +0900
@@ -57,6 +57,9 @@
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+/***** SAKURA Linux start. *****/
+#include <linux/sakura.h>
+/***** SAKURA Linux end. *****/
 
 DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6);
 
@@ -87,6 +90,9 @@ static int udp_v6_get_port(struct sock *
 					result = sysctl_local_port_range[0] +
 						((result - sysctl_local_port_range[0]) &
 						 (UDP_HTABLE_SIZE - 1));
+				/***** SAKURA Linux start. *****/
+				if (SAKURA_MayAutobind(result) < 0) continue;
+				/***** SAKURA Linux end. *****/
 				goto gotit;
 			}
 			size = 0;
@@ -103,6 +109,9 @@ static int udp_v6_get_port(struct sock *
 				result = sysctl_local_port_range[0]
 					+ ((result - sysctl_local_port_range[0]) &
 					   (UDP_HTABLE_SIZE - 1));
+			/***** SAKURA Linux start. *****/
+			if (SAKURA_MayAutobind(result) < 0) continue;
+			/***** SAKURA Linux end. *****/
 			if (!udp_lport_inuse(result))
 				break;
 		}
diff -ubBpEr kernel-source-2.6.8-16sarge7/net/socket.c kernel-source-2.6.8-16sarge7-ccs/net/socket.c
--- kernel-source-2.6.8-16sarge7/net/socket.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/net/socket.c	2007-08-14 12:48:40.000000000 +0900
@@ -94,6 +94,11 @@
 #include <net/sock.h>
 #include <linux/netfilter.h>
 
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+#include <linux/tomoyo_socket.h>
+/***** TOMOYO Linux end. *****/
+
 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
 static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf,
 			 size_t size, loff_t pos);
@@ -541,7 +546,9 @@ static inline int __sock_sendmsg(struct 
 	err = security_socket_sendmsg(sock, msg, size);
 	if (err)
 		return err;
-
+	/***** TOMOYO Linux start. *****/
+	if (CheckSocketSendMsgPermission(sock, (struct sockaddr *) msg->msg_name, msg->msg_namelen)) return -EPERM;
+	/***** TOMOYO Linux end. *****/
 	return sock->ops->sendmsg(iocb, sock, msg, size);
 }
 
@@ -1099,6 +1106,10 @@ static int __sock_create(int family, int
 		family = PF_PACKET;
 	}
 
+	/***** TOMOYO Linux start. *****/
+	if ((err = CheckSocketCreatePermission(family, type, protocol)) < 0) return err;
+	/***** TOMOYO Linux end. *****/
+
 	err = security_socket_create(family, type, protocol, kern);
 	if (err)
 		return err;
@@ -1297,6 +1308,9 @@ asmlinkage long sys_bind(int fd, struct 
 				sockfd_put(sock);
 				return err;
 			}
+			/***** TOMOYO Linux start. *****/
+			if ((err = CheckSocketBindPermission(sock, (struct sockaddr *) address, addrlen)) == 0)
+			/***** TOMOYO Linux end. *****/
 			err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);
 		}
 		sockfd_put(sock);
@@ -1327,7 +1341,9 @@ asmlinkage long sys_listen(int fd, int b
 			sockfd_put(sock);
 			return err;
 		}
-
+		/***** TOMOYO Linux start. *****/
+		if ((err = CheckSocketListenPermission(sock)) == 0)
+		/***** TOMOYO Linux end. *****/
 		err=sock->ops->listen(sock, backlog);
 		sockfd_put(sock);
 	}
@@ -1378,6 +1394,12 @@ asmlinkage long sys_accept(int fd, struc
 	if (err < 0)
 		goto out_release;
 
+	/***** TOMOYO Linux start. *****/
+	if (CheckSocketAcceptPermission(newsock, (struct sockaddr *) address)) {
+		err = -ECONNABORTED; /* Hope less harmful than -EPERM. */
+		goto out_release;
+	}
+	/***** TOMOYO Linux end. *****/
 	if (upeer_sockaddr) {
 		if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {
 			err = -ECONNABORTED;
@@ -1433,7 +1455,9 @@ asmlinkage long sys_connect(int fd, stru
 	err = security_socket_connect(sock, (struct sockaddr *)address, addrlen);
 	if (err)
 		goto out_put;
-
+	/***** TOMOYO Linux start. *****/
+	if ((err = CheckSocketConnectPermission(sock, (struct sockaddr *) address, addrlen)) == 0)
+	/***** TOMOYO Linux end. *****/
 	err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,
 				 sock->file->f_flags);
 out_put:
diff -ubBpEr kernel-source-2.6.8-16sarge7/net/unix/af_unix.c kernel-source-2.6.8-16sarge7-ccs/net/unix/af_unix.c
--- kernel-source-2.6.8-16sarge7/net/unix/af_unix.c	2007-06-18 21:06:55.000000000 +0900
+++ kernel-source-2.6.8-16sarge7-ccs/net/unix/af_unix.c	2007-06-18 21:06:59.000000000 +0900
@@ -118,6 +118,9 @@
 #include <linux/mount.h>
 #include <net/checksum.h>
 #include <linux/security.h>
+/***** TOMOYO Linux start. *****/
+#include <linux/tomoyo.h>
+/***** TOMOYO Linux end. *****/
 
 int sysctl_unix_max_dgram_qlen = 10;
 
@@ -739,6 +742,10 @@ static int unix_bind(struct socket *sock
 		err = unix_autobind(sock);
 		goto out;
 	}
+	/***** TOMOYO Linux start. *****/
+	err = -EPERM;
+	if (sunaddr->sun_path[0] && CheckCapabilityACL(TOMOYO_CREATE_UNIX_SOCKET)) goto out;
+	/***** TOMOYO Linux end. *****/
 
 	err = unix_mkname(sunaddr, addr_len, &hash);
 	if (err < 0)
@@ -803,6 +810,9 @@ static int unix_bind(struct socket *sock
 		 */
 		mode = S_IFSOCK |
 		       (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
+		/***** TOMOYO Linux start. *****/
+		if ((err = pre_vfs_mknod(nd.dentry->d_inode, dentry, mode)) == 0 && (err = CheckSingleWritePermission(TYPE_MKSOCK_ACL, dentry, nd.mnt)) == 0)
+		/***** TOMOYO Linux end. *****/
 		err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
 		if (err)
 			goto out_mknod_dput;
