オープンソース・ソフトウェアの開発とダウンロード

Subversion リポジトリの参照

Diff of /trunk/1.8.x/ccs-patch/patches/ccs-patch-2.6.25-suse-11.0.diff

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/1.6.x/ccs-patch/patches/ccs-patch-2.6.25-suse-11.0.diff revision 2278 by kumaneko, Wed Mar 18 08:12:58 2009 UTC branches/ccs-patch/patches/ccs-patch-2.6.25-suse-11.0.diff revision 2855 by kumaneko, Thu Aug 6 03:24:41 2009 UTC
# Line 1  Line 1 
1  This is TOMOYO Linux patch for openSUSE 11.0.  This is TOMOYO Linux patch for openSUSE 11.0.
2    
3  Source code for this patch is http://download.opensuse.org/update/11.0/rpm/i586/kernel-source-2.6.25.20-0.1.i586.rpm  Source code for this patch is http://download.opensuse.org/update/11.0/rpm/i586/kernel-source-2.6.25.20-0.4.i586.rpm
4  ---  ---
5   arch/ia64/ia32/sys_ia32.c       |    7 ++   arch/ia64/ia32/sys_ia32.c       |    3 +++
6   arch/mips/kernel/ptrace32.c     |    7 ++   arch/mips/kernel/ptrace32.c     |    3 +++
7   arch/s390/kernel/ptrace.c       |    7 ++   arch/s390/kernel/ptrace.c       |    3 +++
8   arch/x86/kernel/ptrace.c        |    7 ++   arch/x86/kernel/ptrace.c        |    3 +++
9   fs/Kconfig                      |    2   fs/Kconfig                      |    2 ++
10   fs/Makefile                     |    2   fs/Makefile                     |    2 ++
11   fs/attr.c                       |   19 ++++++   fs/attr.c                       |    5 +++++
12   fs/compat.c                     |    5 +   fs/compat.c                     |    3 ++-
13   fs/compat_ioctl.c               |    9 ++   fs/compat_ioctl.c               |    7 +++++++
14   fs/exec.c                       |   20 ++++++   fs/exec.c                       |   12 +++++++++++-
15   fs/fcntl.c                      |    9 ++   fs/fcntl.c                      |    5 +++++
16   fs/ioctl.c                      |    7 ++   fs/ioctl.c                      |    5 +++++
17   fs/namei.c                      |  122 ++++++++++++++++++++++++++++++++++++++++   fs/namei.c                      |   35 +++++++++++++++++++++++++++++++++++
18   fs/namespace.c                  |   49 ++++++++++++++++   fs/namespace.c                  |   27 +++++++++++++++++++++++++++
19   fs/open.c                       |   29 +++++++++   fs/open.c                       |   16 ++++++++++++++++
20   fs/proc/Makefile                |    3   fs/proc/Makefile                |    3 +++
21   fs/proc/proc_misc.c             |    5 +   fs/proc/proc_misc.c             |    1 +
22   include/linux/init_task.h       |    4 +   include/linux/init_task.h       |    2 ++
23   include/linux/sched.h           |    9 ++   include/linux/sched.h           |    4 ++++
24   kernel/compat.c                 |    7 ++   kernel/compat.c                 |    3 +++
25   kernel/kexec.c                  |    7 ++   kernel/kexec.c                  |    3 +++
26   kernel/kmod.c                   |    5 +   kernel/kmod.c                   |    3 +++
27   kernel/module.c                 |   11 +++   kernel/module.c                 |    5 +++++
28   kernel/ptrace.c                 |   11 +++   kernel/ptrace.c                 |    5 +++++
29   kernel/sched.c                  |    7 ++   kernel/sched.c                  |    3 +++
30   kernel/signal.c                 |   21 ++++++   kernel/signal.c                 |    7 +++++++
31   kernel/sys.c                    |   21 ++++++   kernel/sys.c                    |   11 +++++++++++
32   kernel/sysctl.c                 |   95 +++++++++++++++++++++++++++++++   kernel/sysctl.c                 |    5 +++++
33   kernel/time.c                   |   11 +++   kernel/time.c                   |    5 +++++
34   kernel/time/ntp.c               |    7 ++   kernel/time/ntp.c               |    3 +++
35   net/core/datagram.c             |   11 +++   net/ipv4/inet_connection_sock.c |    3 +++
36   net/ipv4/inet_connection_sock.c |    7 ++   net/ipv4/inet_hashtables.c      |    3 +++
37   net/ipv4/inet_hashtables.c      |    7 ++   net/ipv4/raw.c                  |    4 ++++
38   net/ipv4/udp.c                  |   10 +++   net/ipv4/udp.c                  |    8 ++++++++
39   net/socket.c                    |   41 +++++++++++++   net/ipv6/raw.c                  |    4 ++++
40   net/unix/af_unix.c              |   15 ++++   net/ipv6/udp.c                  |    4 ++++
41   36 files changed, 614 insertions(+), 2 deletions(-)   net/socket.c                    |   24 ++++++++++++++++++++++++
42     net/unix/af_unix.c              |    4 ++++
43     38 files changed, 246 insertions(+), 2 deletions(-)
44    
45  --- linux-2.6.25.20-0.1.orig/arch/ia64/ia32/sys_ia32.c  --- linux-2.6.25.20-0.4.orig/arch/ia64/ia32/sys_ia32.c
46  +++ linux-2.6.25.20-0.1/arch/ia64/ia32/sys_ia32.c  +++ linux-2.6.25.20-0.4/arch/ia64/ia32/sys_ia32.c
47  @@ -50,6 +50,9 @@  @@ -50,6 +50,7 @@
48   #include <asm/types.h>   #include <asm/types.h>
49   #include <asm/uaccess.h>   #include <asm/uaccess.h>
50   #include <asm/unistd.h>   #include <asm/unistd.h>
 +/***** TOMOYO Linux start. *****/  
51  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
52    
53   #include "ia32priv.h"   #include "ia32priv.h"
54    
55  @@ -1753,6 +1756,10 @@ sys32_ptrace (int request, pid_t pid, un  @@ -1753,6 +1754,8 @@ sys32_ptrace (int request, pid_t pid, un
56          struct task_struct *child;          struct task_struct *child;
57          unsigned int value, tmp;          unsigned int value, tmp;
58          long i, ret;          long i, ret;
59  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_PTRACE))
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
60  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
61    
62          lock_kernel();          lock_kernel();
63          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
64  --- linux-2.6.25.20-0.1.orig/arch/mips/kernel/ptrace32.c  --- linux-2.6.25.20-0.4.orig/arch/mips/kernel/ptrace32.c
65  +++ linux-2.6.25.20-0.1/arch/mips/kernel/ptrace32.c  +++ linux-2.6.25.20-0.4/arch/mips/kernel/ptrace32.c
66  @@ -35,6 +35,9 @@  @@ -35,6 +35,7 @@
67   #include <asm/system.h>   #include <asm/system.h>
68   #include <asm/uaccess.h>   #include <asm/uaccess.h>
69   #include <asm/bootinfo.h>   #include <asm/bootinfo.h>
 +/***** TOMOYO Linux start. *****/  
70  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
71    
72   int ptrace_getregs(struct task_struct *child, __s64 __user *data);   int ptrace_getregs(struct task_struct *child, __s64 __user *data);
73   int ptrace_setregs(struct task_struct *child, __s64 __user *data);   int ptrace_setregs(struct task_struct *child, __s64 __user *data);
74  @@ -50,6 +53,10 @@ asmlinkage int sys32_ptrace(int request,  @@ -50,6 +51,8 @@ asmlinkage int sys32_ptrace(int request,
75   {   {
76          struct task_struct *child;          struct task_struct *child;
77          int ret;          int ret;
78  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_PTRACE))
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
79  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
80    
81   #if 0   #if 0
82          printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",          printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
83  --- linux-2.6.25.20-0.1.orig/arch/s390/kernel/ptrace.c  --- linux-2.6.25.20-0.4.orig/arch/s390/kernel/ptrace.c
84  +++ linux-2.6.25.20-0.1/arch/s390/kernel/ptrace.c  +++ linux-2.6.25.20-0.4/arch/s390/kernel/ptrace.c
85  @@ -41,6 +41,9 @@  @@ -41,6 +41,7 @@
86   #include <asm/system.h>   #include <asm/system.h>
87   #include <asm/uaccess.h>   #include <asm/uaccess.h>
88   #include <asm/unistd.h>   #include <asm/unistd.h>
 +/***** TOMOYO Linux start. *****/  
89  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
90    
91   #ifdef CONFIG_COMPAT   #ifdef CONFIG_COMPAT
92   #include "compat_ptrace.h"   #include "compat_ptrace.h"
93  @@ -698,6 +701,10 @@ sys_ptrace(long request, long pid, long  @@ -698,6 +699,8 @@ sys_ptrace(long request, long pid, long
94          struct task_struct *child;          struct task_struct *child;
95          int ret;          int ret;
96    
97  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_PTRACE))
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
98  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
99          lock_kernel();          lock_kernel();
100          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
101                   ret = ptrace_traceme();                   ret = ptrace_traceme();
102  --- linux-2.6.25.20-0.1.orig/arch/x86/kernel/ptrace.c  --- linux-2.6.25.20-0.4.orig/arch/x86/kernel/ptrace.c
103  +++ linux-2.6.25.20-0.1/arch/x86/kernel/ptrace.c  +++ linux-2.6.25.20-0.4/arch/x86/kernel/ptrace.c
104  @@ -32,6 +32,9 @@  @@ -32,6 +32,7 @@
105   #include <asm/prctl.h>   #include <asm/prctl.h>
106   #include <asm/proto.h>   #include <asm/proto.h>
107   #include <asm/ds.h>   #include <asm/ds.h>
 +/***** TOMOYO Linux start. *****/  
108  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
109    
110   #include "tls.h"   #include "tls.h"
111    
112  @@ -1240,6 +1243,10 @@ asmlinkage long sys32_ptrace(long reques  @@ -1240,6 +1241,8 @@ asmlinkage long sys32_ptrace(long reques
113          void __user *datap = compat_ptr(data);          void __user *datap = compat_ptr(data);
114          int ret;          int ret;
115          __u32 val;          __u32 val;
116  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_PTRACE))
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
117  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
118    
119          switch (request) {          switch (request) {
120          case PTRACE_TRACEME:          case PTRACE_TRACEME:
121  --- linux-2.6.25.20-0.1.orig/fs/Kconfig  --- linux-2.6.25.20-0.4.orig/fs/Kconfig
122  +++ linux-2.6.25.20-0.1/fs/Kconfig  +++ linux-2.6.25.20-0.4/fs/Kconfig
123  @@ -2187,4 +2187,6 @@ endif  @@ -2187,4 +2187,6 @@ endif
124   source "fs/nls/Kconfig"   source "fs/nls/Kconfig"
125   source "fs/dlm/Kconfig"   source "fs/dlm/Kconfig"
# Line 141  Source code for this patch is http://dow Line 127  Source code for this patch is http://dow
127  +source "fs/Kconfig.ccs"  +source "fs/Kconfig.ccs"
128  +  +
129   endmenu   endmenu
130  --- linux-2.6.25.20-0.1.orig/fs/Makefile  --- linux-2.6.25.20-0.4.orig/fs/Makefile
131  +++ linux-2.6.25.20-0.1/fs/Makefile  +++ linux-2.6.25.20-0.4/fs/Makefile
132  @@ -125,3 +125,5 @@ obj-$(CONFIG_OCFS2_FS)              += ocfs2/  @@ -125,3 +125,5 @@ obj-$(CONFIG_OCFS2_FS)              += ocfs2/
133   obj-$(CONFIG_GFS2_FS)           += gfs2/   obj-$(CONFIG_GFS2_FS)           += gfs2/
134   obj-$(CONFIG_NOVFS)            += novfs/   obj-$(CONFIG_NOVFS)            += novfs/
135   obj-$(CONFIG_SQUASHFS)         += squashfs/   obj-$(CONFIG_SQUASHFS)         += squashfs/
136  +  +
137  +include $(srctree)/fs/Makefile-2.6.ccs  +include $(srctree)/fs/Makefile-2.6.ccs
138  --- linux-2.6.25.20-0.1.orig/fs/attr.c  --- linux-2.6.25.20-0.4.orig/fs/attr.c
139  +++ linux-2.6.25.20-0.1/fs/attr.c  +++ linux-2.6.25.20-0.4/fs/attr.c
140  @@ -14,6 +14,9 @@  @@ -14,6 +14,7 @@
141   #include <linux/fcntl.h>   #include <linux/fcntl.h>
142   #include <linux/quotaops.h>   #include <linux/quotaops.h>
143   #include <linux/security.h>   #include <linux/security.h>
 +/***** TOMOYO Linux start. *****/  
144  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
145    
146   /* Taken over from the old code... */   /* Taken over from the old code... */
147    
148  @@ -160,6 +163,14 @@ int fnotify_change(struct dentry *dentry  @@ -160,6 +161,8 @@ int fnotify_change(struct dentry *dentry
149    
150          if (inode->i_op && inode->i_op->setattr) {          if (inode->i_op && inode->i_op->setattr) {
151                  error = security_inode_setattr(dentry, mnt, attr);                  error = security_inode_setattr(dentry, mnt, attr);
152  +               /***** TOMOYO Linux start. *****/  +               if (!error)
153  +               if (!error && (ia_valid & ATTR_MODE) &&  +                       error = ccs_check_setattr_permission(dentry, attr);
 +                   !ccs_capable(TOMOYO_SYS_CHMOD))  
 +                       error = -EPERM;  
 +               if (!error && (ia_valid & (ATTR_UID | ATTR_GID)) &&  
 +                   !ccs_capable(TOMOYO_SYS_CHOWN))  
 +                       error = -EPERM;  
 +               /***** TOMOYO Linux end. *****/  
154                  if (!error) {                  if (!error) {
155                          if (file && file->f_op && file->f_op->fsetattr)                          if (file && file->f_op && file->f_op->fsetattr)
156                                  error = file->f_op->fsetattr(file, attr);                                  error = file->f_op->fsetattr(file, attr);
157  @@ -181,6 +192,14 @@ int fnotify_change(struct dentry *dentry  @@ -181,6 +184,8 @@ int fnotify_change(struct dentry *dentry
158                  error = inode_change_ok(inode, attr);                  error = inode_change_ok(inode, attr);
159                  if (!error)                  if (!error)
160                          error = security_inode_setattr(dentry, mnt, attr);                          error = security_inode_setattr(dentry, mnt, attr);
161  +               /***** TOMOYO Linux start. *****/  +               if (!error)
162  +               if (!error && (ia_valid & ATTR_MODE) &&  +                       error = ccs_check_setattr_permission(dentry, attr);
 +                   !ccs_capable(TOMOYO_SYS_CHMOD))  
 +                       error = -EPERM;  
 +               if (!error && (ia_valid & (ATTR_UID | ATTR_GID)) &&  
 +                   !ccs_capable(TOMOYO_SYS_CHOWN))  
 +                       error = -EPERM;  
 +               /***** TOMOYO Linux end. *****/  
163                  if (!error) {                  if (!error) {
164                          if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||                          if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
165                              (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))                              (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
166  --- linux-2.6.25.20-0.1.orig/fs/compat.c  --- linux-2.6.25.20-0.4.orig/fs/compat.c
167  +++ linux-2.6.25.20-0.1/fs/compat.c  +++ linux-2.6.25.20-0.4/fs/compat.c
168  @@ -55,6 +55,9 @@  @@ -55,6 +55,7 @@
169   #include <asm/mmu_context.h>   #include <asm/mmu_context.h>
170   #include <asm/ioctls.h>   #include <asm/ioctls.h>
171   #include "internal.h"   #include "internal.h"
 +/***** TOMOYO Linux start. *****/  
172  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
173    
174   int compat_log = 1;   int compat_log = 1;
175    
176  @@ -1399,7 +1402,7 @@ int compat_do_execve(char * filename,  @@ -1399,7 +1400,7 @@ int compat_do_execve(char * filename,
177          if (retval < 0)          if (retval < 0)
178                  goto out;                  goto out;
179    
180  -       retval = search_binary_handler(bprm, regs);  -       retval = search_binary_handler(bprm, regs);
181  +       retval = search_binary_handler_with_transition(bprm, regs);  +       retval = ccs_search_binary_handler(bprm, regs);
182          if (retval >= 0) {          if (retval >= 0) {
183                  /* execve success */                  /* execve success */
184                  security_bprm_free(bprm);                  security_bprm_free(bprm);
185  --- linux-2.6.25.20-0.1.orig/fs/compat_ioctl.c  --- linux-2.6.25.20-0.4.orig/fs/compat_ioctl.c
186  +++ linux-2.6.25.20-0.1/fs/compat_ioctl.c  +++ linux-2.6.25.20-0.4/fs/compat_ioctl.c
187  @@ -120,6 +120,9 @@  @@ -120,6 +120,7 @@
188   #include <xen/public/privcmd.h>   #include <xen/public/privcmd.h>
189   #include <xen/compat_ioctl.h>   #include <xen/compat_ioctl.h>
190   #endif   #endif
 +/***** TOMOYO Linux start. *****/  
191  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
192    
193   static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,   static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
194                                unsigned long arg, struct file *f)                                unsigned long arg, struct file *f)
195  @@ -2930,6 +2933,12 @@ asmlinkage long compat_sys_ioctl(unsigne  @@ -2906,6 +2907,8 @@ asmlinkage long compat_sys_ioctl(unsigne
196    
197            /* RED-PEN how should LSM module know it's handling 32bit? */
198            error = security_file_ioctl(filp, cmd, arg);
199    +       if (!error)
200    +               error = ccs_check_ioctl_permission(filp, cmd, arg);
201            if (error)
202                    goto out_fput;
203    
204    @@ -2930,6 +2933,10 @@ asmlinkage long compat_sys_ioctl(unsigne
205                  /*FALL THROUGH*/                  /*FALL THROUGH*/
206    
207          default:          default:
208  +               /***** TOMOYO Linux start. *****/  +               if (!ccs_capable(CCS_SYS_IOCTL)) {
 +               if (!ccs_capable(TOMOYO_SYS_IOCTL)) {  
209  +                       error = -EPERM;  +                       error = -EPERM;
210  +                       goto out_fput;  +                       goto out_fput;
211  +               }  +               }
 +               /***** TOMOYO Linux end. *****/  
212                  if (filp->f_op && filp->f_op->compat_ioctl) {                  if (filp->f_op && filp->f_op->compat_ioctl) {
213                          error = filp->f_op->compat_ioctl(filp, cmd, arg);                          error = filp->f_op->compat_ioctl(filp, cmd, arg);
214                          if (error != -ENOIOCTLCMD)                          if (error != -ENOIOCTLCMD)
215  --- linux-2.6.25.20-0.1.orig/fs/exec.c  --- linux-2.6.25.20-0.4.orig/fs/exec.c
216  +++ linux-2.6.25.20-0.1/fs/exec.c  +++ linux-2.6.25.20-0.4/fs/exec.c
217  @@ -60,6 +60,10 @@  @@ -60,6 +60,8 @@
218   #include <linux/kmod.h>   #include <linux/kmod.h>
219   #endif   #endif
220    
 +/***** TOMOYO Linux start. *****/  
221  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
222  +  +
223   int core_uses_pid;   int core_uses_pid;
224   char core_pattern[CORENAME_MAX_SIZE] = "core";   char core_pattern[CORENAME_MAX_SIZE] = "core";
225   int suid_dumpable = 0;   int suid_dumpable = 0;
226  @@ -118,6 +122,12 @@ asmlinkage long sys_uselib(const char __  @@ -118,6 +120,9 @@ asmlinkage long sys_uselib(const char __
227          error = vfs_permission(&nd, MAY_READ | MAY_EXEC);          error = vfs_permission(&nd, MAY_READ | MAY_EXEC);
228          if (error)          if (error)
229                  goto exit;                  goto exit;
230  +       /***** TOMOYO Linux start. *****/  +       error = ccs_check_uselib_permission(nd.path.dentry, nd.path.mnt);
 +       /* 01 means "read". */  
 +       error = ccs_check_open_permission(nd.path.dentry, nd.path.mnt, 01);  
231  +       if (error)  +       if (error)
232  +               goto exit;  +               goto exit;
 +       /***** TOMOYO Linux end. *****/  
233    
234          file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE);          file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE);
235          error = PTR_ERR(file);          error = PTR_ERR(file);
236  @@ -664,6 +674,14 @@ struct file *open_exec(const char *name)  @@ -664,6 +669,11 @@ struct file *open_exec(const char *name)
237                  file = ERR_PTR(-EACCES);                  file = ERR_PTR(-EACCES);
238                  if (S_ISREG(inode->i_mode)) {                  if (S_ISREG(inode->i_mode)) {
239                          int err = vfs_permission(&nd, MAY_EXEC);                          int err = vfs_permission(&nd, MAY_EXEC);
240  +                       /***** TOMOYO Linux start. *****/  +                       if (!err)
241  +                       if (!err && (current->tomoyo_flags &  +                               err = ccs_check_open_exec_permission(nd.path.
242  +                                    TOMOYO_CHECK_READ_FOR_OPEN_EXEC))  +                                                                    dentry,
243  +                               /* 01 means "read". */  +                                                                    nd.path.
244  +                               err = ccs_check_open_permission(nd.path.dentry,  +                                                                    mnt);
 +                                                               nd.path.mnt,  
 +                                                               01);  
 +                       /***** TOMOYO Linux end. *****/  
245                          file = ERR_PTR(err);                          file = ERR_PTR(err);
246                          if (!err) {                          if (!err) {
247                                  file = nameidata_to_filp(&nd,                                  file = nameidata_to_filp(&nd,
248  @@ -1336,7 +1354,7 @@ int do_execve(char * filename,  @@ -1336,7 +1346,7 @@ int do_execve(char * filename,
249                  goto out;                  goto out;
250          bprm->argv_len = env_p - bprm->p;          bprm->argv_len = env_p - bprm->p;
251    
252  -       retval = search_binary_handler(bprm,regs);  -       retval = search_binary_handler(bprm,regs);
253  +       retval = search_binary_handler_with_transition(bprm, regs);  +       retval = ccs_search_binary_handler(bprm, regs);
254          if (retval >= 0) {          if (retval >= 0) {
255                  /* execve success */                  /* execve success */
256                  free_arg_pages(bprm);                  free_arg_pages(bprm);
257  --- linux-2.6.25.20-0.1.orig/fs/fcntl.c  --- linux-2.6.25.20-0.4.orig/fs/fcntl.c
258  +++ linux-2.6.25.20-0.1/fs/fcntl.c  +++ linux-2.6.25.20-0.4/fs/fcntl.c
259  @@ -23,6 +23,9 @@  @@ -23,6 +23,7 @@
260   #include <asm/poll.h>   #include <asm/poll.h>
261   #include <asm/siginfo.h>   #include <asm/siginfo.h>
262   #include <asm/uaccess.h>   #include <asm/uaccess.h>
 +/***** TOMOYO Linux start. *****/  
263  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
264    
265   void set_close_on_exec(unsigned int fd, int flag)   void set_close_on_exec(unsigned int fd, int flag)
266   {   {
267  @@ -217,6 +220,12 @@ static int setfl(int fd, struct file * f  @@ -217,6 +218,10 @@ static int setfl(int fd, struct file * f
268          if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode))          if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode))
269                  return -EPERM;                  return -EPERM;
270    
 +       /***** TOMOYO Linux start. *****/  
271  +       if (((arg ^ filp->f_flags) & O_APPEND) &&  +       if (((arg ^ filp->f_flags) & O_APPEND) &&
272  +           ccs_check_rewrite_permission(filp))  +           ccs_check_rewrite_permission(filp))
273  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
274  +  +
275          /* O_NOATIME can only be set by the owner or superuser */          /* O_NOATIME can only be set by the owner or superuser */
276          if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))          if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))
277                  if (!is_owner_or_cap(inode))                  if (!is_owner_or_cap(inode))
278  --- linux-2.6.25.20-0.1.orig/fs/ioctl.c  --- linux-2.6.25.20-0.4.orig/fs/ioctl.c
279  +++ linux-2.6.25.20-0.1/fs/ioctl.c  +++ linux-2.6.25.20-0.4/fs/ioctl.c
280  @@ -15,6 +15,9 @@  @@ -15,6 +15,7 @@
281   #include <linux/uaccess.h>   #include <linux/uaccess.h>
282    
283   #include <asm/ioctls.h>   #include <asm/ioctls.h>
 +/***** TOMOYO Linux start. *****/  
284  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
285    
286   /**   /**
287    * vfs_ioctl - call filesystem specific ioctl methods    * vfs_ioctl - call filesystem specific ioctl methods
288  @@ -35,6 +38,10 @@ long vfs_ioctl(struct file *filp, unsign  @@ -35,6 +36,8 @@ long vfs_ioctl(struct file *filp, unsign
289    
290          if (!filp->f_op)          if (!filp->f_op)
291                  goto out;                  goto out;
292  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_IOCTL))
 +       if (!ccs_capable(TOMOYO_SYS_IOCTL))  
293  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
294    
295          if (filp->f_op->unlocked_ioctl) {          if (filp->f_op->unlocked_ioctl) {
296                  error = filp->f_op->unlocked_ioctl(filp, cmd, arg);                  error = filp->f_op->unlocked_ioctl(filp, cmd, arg);
297  --- linux-2.6.25.20-0.1.orig/fs/namei.c  @@ -202,6 +205,8 @@ asmlinkage long sys_ioctl(unsigned int f
298  +++ linux-2.6.25.20-0.1/fs/namei.c                  goto out;
299  @@ -35,6 +35,10 @@  
300            error = security_file_ioctl(filp, cmd, arg);
301    +       if (!error)
302    +               error = ccs_check_ioctl_permission(filp, cmd, arg);
303            if (error)
304                    goto out_fput;
305    
306    --- linux-2.6.25.20-0.4.orig/fs/namei.c
307    +++ linux-2.6.25.20-0.4/fs/namei.c
308    @@ -35,6 +35,8 @@
309    
310   #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])   #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
311    
 +/***** TOMOYO Linux start. *****/  
312  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
313  +  +
314   /* [Feb-1997 T. Schoebel-Theuer]   /* [Feb-1997 T. Schoebel-Theuer]
315    * Fundamental changes in the pathname lookup mechanisms (namei)    * Fundamental changes in the pathname lookup mechanisms (namei)
316    * were necessary because of omirr.  The reason is that omirr needs    * were necessary because of omirr.  The reason is that omirr needs
317  @@ -1635,6 +1639,14 @@ int vfs_create(struct inode *dir, struct  @@ -1690,6 +1692,11 @@ int may_open(struct nameidata *nd, int a
         error = security_inode_create(dir, dentry, nd ? nd->path.mnt : NULL, mode);  
         if (error)  
                 return error;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (nd) {  
 +               error = ccs_check_1path_perm(TYPE_CREATE_ACL, dentry,  
 +                                            nd->path.mnt);  
 +               if (error)  
 +                       return error;  
 +       }  
 +       /***** TOMOYO Linux end. *****/  
         DQUOT_INIT(dir);  
         error = dir->i_op->create(dir, dentry, mode, nd);  
         if (!error)  
 @@ -1690,6 +1702,13 @@ int may_open(struct nameidata *nd, int a  
318                  if (!is_owner_or_cap(inode))                  if (!is_owner_or_cap(inode))
319                          return -EPERM;                          return -EPERM;
320    
 +       /***** TOMOYO Linux start. *****/  
321  +       /* includes O_APPEND and O_TRUNC checks */  +       /* includes O_APPEND and O_TRUNC checks */
322  +       error = ccs_check_open_permission(dentry, nd->path.mnt, flag);  +       error = ccs_check_open_permission(dentry, nd->path.mnt, flag);
323  +       if (error)  +       if (error)
324  +               return error;  +               return error;
 +       /***** TOMOYO Linux end. *****/  
325  +  +
326          /*          /*
327           * Ensure there are no outstanding leases on the file.           * Ensure there are no outstanding leases on the file.
328           */           */
329  @@ -1741,6 +1760,9 @@ static int open_namei_create(struct name  @@ -1731,6 +1738,9 @@ static int open_namei_create(struct name
330    
331            if (!IS_POSIXACL(dir->d_inode))
332                    mode &= ~current->fs->umask;
333    +       error = ccs_check_mknod_permission(dir->d_inode, path->dentry,
334    +                                          nd->path.mnt, mode, 0);
335    +       if (!error)
336            error = vfs_create(dir->d_inode, path->dentry, mode, nd);
337            mutex_unlock(&dir->d_inode->i_mutex);
338            dput(nd->path.dentry);
339    @@ -1741,6 +1751,7 @@ static int open_namei_create(struct name
340          return may_open(nd, 0, flag & ~O_TRUNC);          return may_open(nd, 0, flag & ~O_TRUNC);
341   }   }
342    
 +/***** TOMOYO Linux start. *****/  
343  +#include <linux/tomoyo_vfs.h>  +#include <linux/tomoyo_vfs.h>
 +/***** TOMOYO Linux end. *****/  
344   /*   /*
345    *     open_namei()    *     open_namei()
346    *    *
347  @@ -2006,6 +2028,16 @@ asmlinkage long sys_mknodat(int dfd, con  @@ -2019,6 +2030,10 @@ asmlinkage long sys_mknodat(int dfd, con
348            if (!IS_POSIXACL(nd.path.dentry->d_inode))
349          if (S_ISDIR(mode))                  mode &= ~current->fs->umask;
350                  return -EPERM;          if (!IS_ERR(dentry)) {
351  +       /***** TOMOYO Linux start. *****/  +               error = ccs_check_mknod_permission(nd.path.dentry->d_inode,
352  +       if (S_ISCHR(mode) && !ccs_capable(TOMOYO_CREATE_CHAR_DEV))  +                                                  dentry, nd.path.mnt, mode,
353  +               return -EPERM;  +                                                  new_decode_dev(dev));
354  +       if (S_ISBLK(mode) && !ccs_capable(TOMOYO_CREATE_BLOCK_DEV))  +               if (!error)
355  +               return -EPERM;                  switch (mode & S_IFMT) {
356  +       if (S_ISFIFO(mode) && !ccs_capable(TOMOYO_CREATE_FIFO))                  case 0: case S_IFREG:
 +               return -EPERM;  
 +       if (S_ISSOCK(mode) && !ccs_capable(TOMOYO_CREATE_UNIX_SOCKET))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
         tmp = getname(filename);  
         if (IS_ERR(tmp))  
                 return PTR_ERR(tmp);  
 @@ -2024,10 +2056,34 @@ asmlinkage long sys_mknodat(int dfd, con  
357                          error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd);                          error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd);
358                          break;  @@ -2097,6 +2112,9 @@ asmlinkage long sys_mkdirat(int dfd, con
                 case S_IFCHR: case S_IFBLK:  
 +                       /***** TOMOYO Linux start. *****/  
 +                       error = pre_vfs_mknod(nd.path.dentry->d_inode, dentry,  
 +                                             mode);  
 +                       if (error)  
 +                               break;  
 +                       error = ccs_check_1path_perm(S_ISCHR(mode) ?  
 +                                                    TYPE_MKCHAR_ACL :  
 +                                                    TYPE_MKBLOCK_ACL,  
 +                                                    dentry, nd.path.mnt);  
 +                       if (error)  
 +                               break;  
 +                       /***** TOMOYO Linux end. *****/  
                         error = vfs_mknod(nd.path.dentry->d_inode, dentry,  
                                           nd.path.mnt, mode, new_decode_dev(dev));  
                         break;  
                 case S_IFIFO: case S_IFSOCK:  
 +                       /***** TOMOYO Linux start. *****/  
 +                       error = pre_vfs_mknod(nd.path.dentry->d_inode, dentry,  
 +                                             mode);  
 +                       if (error)  
 +                               break;  
 +                       error = ccs_check_1path_perm(S_ISFIFO(mode) ?  
 +                                                    TYPE_MKFIFO_ACL :  
 +                                                    TYPE_MKSOCK_ACL,  
 +                                                    dentry, nd.path.mnt);  
 +                       if (error)  
 +                               break;  
 +                       /***** TOMOYO Linux end. *****/  
                         error = vfs_mknod(nd.path.dentry->d_inode, dentry,  
                                           nd.path.mnt, mode, 0);  
                         break;  
 @@ -2097,6 +2153,13 @@ asmlinkage long sys_mkdirat(int dfd, con  
359    
360          if (!IS_POSIXACL(nd.path.dentry->d_inode))          if (!IS_POSIXACL(nd.path.dentry->d_inode))
361                  mode &= ~current->fs->umask;                  mode &= ~current->fs->umask;
362  +       /***** TOMOYO Linux start. *****/  +       error = ccs_check_mkdir_permission(nd.path.dentry->d_inode, dentry,
363  +       error = pre_vfs_mkdir(nd.path.dentry->d_inode, dentry);  +                                          nd.path.mnt, mode);
364  +       if (!error)  +       if (!error)
 +               error = ccs_check_1path_perm(TYPE_MKDIR_ACL, dentry,  
 +                                            nd.path.mnt);  
 +       if (!error)  
 +       /***** TOMOYO Linux end. *****/  
365          error = vfs_mkdir(nd.path.dentry->d_inode, dentry, nd.path.mnt, mode);          error = vfs_mkdir(nd.path.dentry->d_inode, dentry, nd.path.mnt, mode);
366          dput(dentry);          dput(dentry);
367   out_unlock:   out_unlock:
368  @@ -2205,6 +2268,13 @@ static long do_rmdir(int dfd, const char  @@ -2205,6 +2223,9 @@ static long do_rmdir(int dfd, const char
369          error = PTR_ERR(dentry);          error = PTR_ERR(dentry);
370          if (IS_ERR(dentry))          if (IS_ERR(dentry))
371                  goto exit2;                  goto exit2;
372  +       /***** TOMOYO Linux start. *****/  +       error = ccs_check_rmdir_permission(nd.path.dentry->d_inode, dentry,
373  +       error = pre_vfs_rmdir(nd.path.dentry->d_inode, dentry);  +                                          nd.path.mnt);
 +       if (!error)  
 +               error = ccs_check_1path_perm(TYPE_RMDIR_ACL, dentry,  
 +                                            nd.path.mnt);  
374  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
375          error = vfs_rmdir(nd.path.dentry->d_inode, dentry, nd.path.mnt);          error = vfs_rmdir(nd.path.dentry->d_inode, dentry, nd.path.mnt);
376          dput(dentry);          dput(dentry);
377   exit2:   exit2:
378  @@ -2265,6 +2335,10 @@ static long do_unlinkat(int dfd, const c  @@ -2286,6 +2307,9 @@ static long do_unlinkat(int dfd, const c
         struct dentry *dentry;  
         struct nameidata nd;  
         struct inode *inode = NULL;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (!ccs_capable(TOMOYO_SYS_UNLINK))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         name = getname(pathname);  
         if(IS_ERR(name))  
 @@ -2286,6 +2360,15 @@ static long do_unlinkat(int dfd, const c  
379                  inode = dentry->d_inode;                  inode = dentry->d_inode;
380                  if (inode)                  if (inode)
381                          atomic_inc(&inode->i_count);                          atomic_inc(&inode->i_count);
382  +               /***** TOMOYO Linux start. *****/  +               error = ccs_check_unlink_permission(nd.path.dentry->d_inode,
383  +               error = pre_vfs_unlink(nd.path.dentry->d_inode, dentry);  +                                                   dentry, nd.path.mnt);
384  +               if (error)  +               if (!error)
 +                       goto exit2;  
 +               error = ccs_check_1path_perm(TYPE_UNLINK_ACL, dentry,  
 +                                            nd.path.mnt);  
 +               if (error)  
 +                       goto exit2;  
 +               /***** TOMOYO Linux end. *****/  
385                  error = vfs_unlink(nd.path.dentry->d_inode, dentry, nd.path.mnt);                  error = vfs_unlink(nd.path.dentry->d_inode, dentry, nd.path.mnt);
386          exit2:          exit2:
387                  dput(dentry);                  dput(dentry);
388  @@ -2351,6 +2434,10 @@ asmlinkage long sys_symlinkat(const char  @@ -2368,6 +2392,9 @@ asmlinkage long sys_symlinkat(const char
         char * to;  
         struct dentry *dentry;  
         struct nameidata nd;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (!ccs_capable(TOMOYO_SYS_SYMLINK))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         from = getname(oldname);  
         if(IS_ERR(from))  
 @@ -2368,6 +2455,13 @@ asmlinkage long sys_symlinkat(const char  
389          if (IS_ERR(dentry))          if (IS_ERR(dentry))
390                  goto out_unlock;                  goto out_unlock;
391    
392  +       /***** TOMOYO Linux start. *****/  +       error = ccs_check_symlink_permission(nd.path.dentry->d_inode, dentry,
393  +       error = pre_vfs_symlink(nd.path.dentry->d_inode, dentry);  +                                            nd.path.mnt, from);
 +       if (!error)  
 +               error = ccs_check_1path_perm(TYPE_SYMLINK_ACL, dentry,  
 +                                            nd.path.mnt);  
394  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
395          error = vfs_symlink(nd.path.dentry->d_inode, dentry, nd.path.mnt, from,          error = vfs_symlink(nd.path.dentry->d_inode, dentry, nd.path.mnt, from,
396                              S_IALLUGO);                              S_IALLUGO);
397          dput(dentry);          dput(dentry);
398  @@ -2442,6 +2536,10 @@ asmlinkage long sys_linkat(int olddfd, c  @@ -2465,6 +2492,10 @@ asmlinkage long sys_linkat(int olddfd, c
         struct nameidata nd, old_nd;  
         int error;  
         char * to;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (!ccs_capable(TOMOYO_SYS_LINK))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         if ((flags & ~AT_SYMLINK_FOLLOW) != 0)  
                 return -EINVAL;  
 @@ -2465,6 +2563,15 @@ asmlinkage long sys_linkat(int olddfd, c  
399          error = PTR_ERR(new_dentry);          error = PTR_ERR(new_dentry);
400          if (IS_ERR(new_dentry))          if (IS_ERR(new_dentry))
401                  goto out_unlock;                  goto out_unlock;
402  +       /***** TOMOYO Linux start. *****/  +       error = ccs_check_link_permission(old_nd.path.dentry,
403  +       error = pre_vfs_link(old_nd.path.dentry, nd.path.dentry->d_inode,  +                                         nd.path.dentry->d_inode, new_dentry,
404  +                            new_dentry);  +                                         nd.path.mnt);
 +       if (!error)  
 +               error = ccs_check_2path_perm(TYPE_LINK_ACL, old_nd.path.dentry,  
 +                                            old_nd.path.mnt, new_dentry,  
 +                                            nd.path.mnt);  
405  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
406          error = vfs_link(old_nd.path.dentry, old_nd.path.mnt, nd.path.dentry->d_inode,          error = vfs_link(old_nd.path.dentry, old_nd.path.mnt, nd.path.dentry->d_inode,
407                           new_dentry, nd.path.mnt);                           new_dentry, nd.path.mnt);
408          dput(new_dentry);          dput(new_dentry);
409  @@ -2698,6 +2805,17 @@ static int do_rename(int olddfd, const c  @@ -2698,6 +2729,10 @@ static int do_rename(int olddfd, const c
410          error = -ENOTEMPTY;          error = -ENOTEMPTY;
411          if (new_dentry == trap)          if (new_dentry == trap)
412                  goto exit5;                  goto exit5;
413  +       /***** TOMOYO Linux start. *****/  +       error = ccs_check_rename_permission(old_dir->d_inode, old_dentry,
414  +       error = pre_vfs_rename(old_dir->d_inode, old_dentry,  +                                           new_dir->d_inode, new_dentry,
415  +                              new_dir->d_inode, new_dentry);  +                                           newnd.path.mnt);
416  +       if (error)  +       if (!error)
 +               goto exit5;  
 +       error = ccs_check_2path_perm(TYPE_RENAME_ACL, old_dentry,  
 +                                    oldnd.path.mnt, new_dentry,  
 +                                    newnd.path.mnt);  
 +       if (error)  
 +               goto exit5;  
 +       /***** TOMOYO Linux end. *****/  
417    
418          error = vfs_rename(old_dir->d_inode, old_dentry, oldnd.path.mnt,          error = vfs_rename(old_dir->d_inode, old_dentry, oldnd.path.mnt,
419                             new_dir->d_inode, new_dentry, newnd.path.mnt);                             new_dir->d_inode, new_dentry, newnd.path.mnt);
420  @@ -2721,6 +2839,10 @@ asmlinkage long sys_renameat(int olddfd,  --- linux-2.6.25.20-0.4.orig/fs/namespace.c
421          int error;  +++ linux-2.6.25.20-0.4/fs/namespace.c
422          char * from;  @@ -30,6 +30,8 @@
         char * to;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (!ccs_capable(TOMOYO_SYS_RENAME))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         from = getname(oldname);  
         if(IS_ERR(from))  
 --- linux-2.6.25.20-0.1.orig/fs/namespace.c  
 +++ linux-2.6.25.20-0.1/fs/namespace.c  
 @@ -30,6 +30,12 @@  
423   #include <asm/unistd.h>   #include <asm/unistd.h>
424   #include "pnode.h"   #include "pnode.h"
425   #include "internal.h"   #include "internal.h"
 +/***** SAKURA Linux start. *****/  
426  +#include <linux/sakura.h>  +#include <linux/sakura.h>
 +/***** SAKURA Linux end. *****/  
 +/***** TOMOYO Linux start. *****/  
427  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
428    
429   #define HASH_SHIFT ilog2(PAGE_SIZE / sizeof(struct list_head))   #define HASH_SHIFT ilog2(PAGE_SIZE / sizeof(struct list_head))
430   #define HASH_SIZE (1UL << HASH_SHIFT)   #define HASH_SIZE (1UL << HASH_SHIFT)
431  @@ -591,6 +597,11 @@ static int do_umount(struct vfsmount *mn  @@ -591,6 +593,9 @@ static int do_umount(struct vfsmount *mn
432          if (retval)          if (retval)
433                  return retval;                  return retval;
434    
 +       /***** SAKURA Linux start. *****/  
435  +       if (ccs_may_umount(mnt))  +       if (ccs_may_umount(mnt))
436  +               return -EPERM;  +               return -EPERM;
 +       /***** SAKURA Linux end. *****/  
437  +  +
438          /*          /*
439           * Allow userspace to request a mountpoint be expired rather than           * Allow userspace to request a mountpoint be expired rather than
440           * unmounting unconditionally. Unmount only happens if:           * unmounting unconditionally. Unmount only happens if:
441  @@ -682,6 +693,10 @@ asmlinkage long sys_umount(char __user *  @@ -682,6 +687,8 @@ asmlinkage long sys_umount(char __user *
442   {   {
443          struct nameidata nd;          struct nameidata nd;
444          int retval;          int retval;
445  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_UMOUNT))
 +       if (!ccs_capable(TOMOYO_SYS_UMOUNT))  
446  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
447    
448          retval = __user_walk(name, LOOKUP_FOLLOW, &nd);          retval = __user_walk(name, LOOKUP_FOLLOW, &nd);
449          if (retval)          if (retval)
450  @@ -991,6 +1006,11 @@ static noinline int do_loopback(struct n  @@ -991,6 +998,9 @@ static noinline int do_loopback(struct n
451          err = -EINVAL;          err = -EINVAL;
452          if (IS_MNT_UNBINDABLE(old_nd.path.mnt))          if (IS_MNT_UNBINDABLE(old_nd.path.mnt))
453                  goto out;                  goto out;
 +       /***** SAKURA Linux start. *****/  
454  +       err = -EPERM;  +       err = -EPERM;
455  +       if (ccs_may_mount(nd))  +       if (ccs_may_mount(nd))
456  +               goto out;  +               goto out;
 +       /***** SAKURA Linux end. *****/  
457    
458          if (!check_mnt(nd->path.mnt) || !check_mnt(old_nd.path.mnt))          if (!check_mnt(nd->path.mnt) || !check_mnt(old_nd.path.mnt))
459                  goto out;                  goto out;
460  @@ -1085,6 +1105,11 @@ static noinline int do_move_mount(struct  @@ -1085,6 +1095,9 @@ static noinline int do_move_mount(struct
461          if (!check_mnt(nd->path.mnt) || !check_mnt(old_nd.path.mnt))          if (!check_mnt(nd->path.mnt) || !check_mnt(old_nd.path.mnt))
462                  goto out;                  goto out;
463    
 +       /***** SAKURA Linux start. *****/  
464  +       err = -EPERM;  +       err = -EPERM;
465  +       if (ccs_may_umount(old_nd.path.mnt) || ccs_may_mount(nd))  +       if (ccs_may_umount(old_nd.path.mnt) || ccs_may_mount(nd))
466  +               goto out;  +               goto out;
 +       /***** SAKURA Linux end. *****/  
467          err = -ENOENT;          err = -ENOENT;
468          mutex_lock(&nd->path.dentry->d_inode->i_mutex);          mutex_lock(&nd->path.dentry->d_inode->i_mutex);
469          if (IS_DEADDIR(nd->path.dentry->d_inode))          if (IS_DEADDIR(nd->path.dentry->d_inode))
470  @@ -1189,6 +1214,11 @@ int do_add_mount(struct vfsmount *newmnt  @@ -1189,6 +1202,9 @@ int do_add_mount(struct vfsmount *newmnt
471          err = -EINVAL;          err = -EINVAL;
472          if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))          if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
473                  goto unlock;                  goto unlock;
 +       /***** SAKURA Linux start. *****/  
474  +       err = -EPERM;  +       err = -EPERM;
475  +       if (ccs_may_mount(nd))  +       if (ccs_may_mount(nd))
476  +               goto unlock;  +               goto unlock;
 +       /***** SAKURA Linux end. *****/  
477    
478          newmnt->mnt_flags = mnt_flags;          newmnt->mnt_flags = mnt_flags;
479          if ((err = graft_tree(newmnt, nd)))          if ((err = graft_tree(newmnt, nd)))
480  @@ -1412,6 +1442,17 @@ long do_mount(char *dev_name, char *dir_  @@ -1412,6 +1428,13 @@ long do_mount(char *dev_name, char *dir_
481          if (data_page)          if (data_page)
482                  ((char *)data_page)[PAGE_SIZE - 1] = 0;                  ((char *)data_page)[PAGE_SIZE - 1] = 0;
483    
484  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_MOUNT))
 +       if (!ccs_capable(TOMOYO_SYS_MOUNT))  
485  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
 +       /***** SAKURA Linux start. *****/  
486  +       retval = ccs_check_mount_permission(dev_name, dir_name, type_page,  +       retval = ccs_check_mount_permission(dev_name, dir_name, type_page,
487  +                                           &flags);  +                                           &flags);
488  +       if (retval)  +       if (retval)
489  +               return retval;  +               return retval;
 +       /***** SAKURA Linux end. *****/  
490  +  +
491          /* Separate the per-mountpoint flags */          /* Separate the per-mountpoint flags */
492          if (flags & MS_NOSUID)          if (flags & MS_NOSUID)
493                  mnt_flags |= MNT_NOSUID;                  mnt_flags |= MNT_NOSUID;
494  @@ -1680,6 +1721,10 @@ asmlinkage long sys_pivot_root(const cha  @@ -1680,6 +1703,8 @@ asmlinkage long sys_pivot_root(const cha
495    
496          if (!capable(CAP_SYS_ADMIN))          if (!capable(CAP_SYS_ADMIN))
497                  return -EPERM;                  return -EPERM;
498  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_PIVOT_ROOT))
 +       if (!ccs_capable(TOMOYO_SYS_PIVOT_ROOT))  
499  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
500    
501          lock_kernel();          lock_kernel();
502    
503  @@ -1696,6 +1741,10 @@ asmlinkage long sys_pivot_root(const cha  @@ -1696,6 +1721,8 @@ asmlinkage long sys_pivot_root(const cha
504                  goto out1;                  goto out1;
505    
506          error = security_sb_pivotroot(&old_nd, &new_nd);          error = security_sb_pivotroot(&old_nd, &new_nd);
 +       /***** SAKURA Linux start. *****/  
507  +       if (!error)  +       if (!error)
508  +               error = ccs_check_pivot_root_permission(&old_nd, &new_nd);  +               error = ccs_check_pivot_root_permission(&old_nd, &new_nd);
 +       /***** SAKURA Linux end. *****/  
509          if (error) {          if (error) {
510                  path_put(&old_nd.path);                  path_put(&old_nd.path);
511                  goto out1;                  goto out1;
512  --- linux-2.6.25.20-0.1.orig/fs/open.c  --- linux-2.6.25.20-0.4.orig/fs/open.c
513  +++ linux-2.6.25.20-0.1/fs/open.c  +++ linux-2.6.25.20-0.4/fs/open.c
514  @@ -27,6 +27,12 @@  @@ -27,6 +27,8 @@
515   #include <linux/rcupdate.h>   #include <linux/rcupdate.h>
516   #include <linux/audit.h>   #include <linux/audit.h>
517   #include <linux/falloc.h>   #include <linux/falloc.h>
 +/***** SAKURA Linux start. *****/  
518  +#include <linux/sakura.h>  +#include <linux/sakura.h>
 +/***** SAKURA Linux end. *****/  
 +/***** TOMOYO Linux start. *****/  
519  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
520    
521   int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)   int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
522   {   {
523  @@ -267,6 +273,12 @@ static long do_sys_truncate(const char _  @@ -267,6 +269,10 @@ static long do_sys_truncate(const char _
524          if (error)          if (error)
525                  goto put_write_and_out;                  goto put_write_and_out;
526    
527  +       /***** TOMOYO Linux start. *****/  +       error = ccs_check_truncate_permission(nd.path.dentry, nd.path.mnt,
528  +       error = ccs_check_1path_perm(TYPE_TRUNCATE_ACL, nd.path.dentry,  +                                             length, 0);
 +                                    nd.path.mnt);  
529  +       if (error)  +       if (error)
530  +               goto put_write_and_out;  +               goto put_write_and_out;
 +       /***** TOMOYO Linux end. *****/  
531          error = locks_verify_truncate(inode, NULL, length);          error = locks_verify_truncate(inode, NULL, length);
532          if (!error) {          if (!error) {
533                  DQUOT_INIT(inode);                  DQUOT_INIT(inode);
534  @@ -321,6 +333,11 @@ static long do_sys_ftruncate(unsigned in  @@ -321,6 +327,10 @@ static long do_sys_ftruncate(unsigned in
535          if (IS_APPEND(inode))          if (IS_APPEND(inode))
536                  goto out_putf;                  goto out_putf;
537    
538  +       /***** TOMOYO Linux start. *****/  +       error = ccs_check_truncate_permission(dentry, file->f_vfsmnt, length,
539  +       error = ccs_check_1path_perm(TYPE_TRUNCATE_ACL, dentry, file->f_vfsmnt);  +                                             0);
540  +       if (error)  +       if (error)
541  +               goto out_putf;  +               goto out_putf;
 +       /***** TOMOYO Linux end. *****/  
542          error = locks_verify_truncate(inode, file, length);          error = locks_verify_truncate(inode, file, length);
543          if (!error)          if (!error)
544                  error = do_truncate(dentry, file->f_path.mnt, length,                  error = do_truncate(dentry, file->f_path.mnt, length,
545  @@ -539,6 +556,14 @@ asmlinkage long sys_chroot(const char __  @@ -539,6 +549,10 @@ asmlinkage long sys_chroot(const char __
546          error = -EPERM;          error = -EPERM;
547          if (!capable(CAP_SYS_CHROOT))          if (!capable(CAP_SYS_CHROOT))
548                  goto dput_and_out;                  goto dput_and_out;
549  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_CHROOT))
 +       if (!ccs_capable(TOMOYO_SYS_CHROOT))  
550  +               goto dput_and_out;  +               goto dput_and_out;
 +       /***** TOMOYO Linux end. *****/  
 +       /***** SAKURA Linux start. *****/  
551  +       if (ccs_check_chroot_permission(&nd))  +       if (ccs_check_chroot_permission(&nd))
552  +               goto dput_and_out;  +               goto dput_and_out;
 +       /***** SAKURA Linux end. *****/  
553    
554          set_fs_root(current->fs, &nd.path);          set_fs_root(current->fs, &nd.path);
555          set_fs_altroot();          set_fs_altroot();
556  @@ -1172,6 +1197,10 @@ EXPORT_SYMBOL(sys_close);  @@ -1172,6 +1186,8 @@ EXPORT_SYMBOL(sys_close);
557    */    */
558   asmlinkage long sys_vhangup(void)   asmlinkage long sys_vhangup(void)
559   {   {
560  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_VHANGUP))
 +       if (!ccs_capable(TOMOYO_SYS_VHANGUP))  
561  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
562          if (capable(CAP_SYS_TTY_CONFIG)) {          if (capable(CAP_SYS_TTY_CONFIG)) {
563                  /* XXX: this needs locking */                  /* XXX: this needs locking */
564                  tty_vhangup(current->signal->tty);                  tty_vhangup(current->signal->tty);
565  --- linux-2.6.25.20-0.1.orig/fs/proc/Makefile  --- linux-2.6.25.20-0.4.orig/fs/proc/Makefile
566  +++ linux-2.6.25.20-0.1/fs/proc/Makefile  +++ linux-2.6.25.20-0.4/fs/proc/Makefile
567  @@ -16,3 +16,6 @@ proc-$(CONFIG_PROC_KCORE)     += kcore.o  @@ -16,3 +16,6 @@ proc-$(CONFIG_PROC_KCORE)     += kcore.o
568   proc-$(CONFIG_PROC_VMCORE)     += vmcore.o   proc-$(CONFIG_PROC_VMCORE)     += vmcore.o
569   proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o   proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o
# Line 764  Source code for this patch is http://dow Line 571  Source code for this patch is http://dow
571  +  +
572  +proc-$(CONFIG_SAKURA) += ccs_proc.o  +proc-$(CONFIG_SAKURA) += ccs_proc.o
573  +proc-$(CONFIG_TOMOYO) += ccs_proc.o  +proc-$(CONFIG_TOMOYO) += ccs_proc.o
574  --- linux-2.6.25.20-0.1.orig/fs/proc/proc_misc.c  --- linux-2.6.25.20-0.4.orig/fs/proc/proc_misc.c
575  +++ linux-2.6.25.20-0.1/fs/proc/proc_misc.c  +++ linux-2.6.25.20-0.4/fs/proc/proc_misc.c
576  @@ -1021,4 +1021,9 @@ void __init proc_misc_init(void)  @@ -1021,4 +1021,5 @@ void __init proc_misc_init(void)
577                          entry->proc_fops = &proc_sysrq_trigger_operations;                          entry->proc_fops = &proc_sysrq_trigger_operations;
578          }          }
579   #endif   #endif
580  +       /***** CCS start. *****/  +       printk(KERN_INFO "Hook version: 2.6.25.20-0.4 2009/08/05\n");
 +#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO)  
 +       printk(KERN_INFO "Hook version: 2.6.25.20-0.1 2009/01/25\n");  
 +#endif  
 +       /***** CCS end. *****/  
581   }   }
582  --- linux-2.6.25.20-0.1.orig/include/linux/init_task.h  --- linux-2.6.25.20-0.4.orig/include/linux/init_task.h
583  +++ linux-2.6.25.20-0.1/include/linux/init_task.h  +++ linux-2.6.25.20-0.4/include/linux/init_task.h
584  @@ -196,6 +196,10 @@ extern struct group_info init_groups;  @@ -196,6 +196,8 @@ extern struct group_info init_groups;
585          INIT_IDS                                                        \          INIT_IDS                                                        \
586          INIT_TRACE_IRQFLAGS                                             \          INIT_TRACE_IRQFLAGS                                             \
587          INIT_LOCKDEP                                                    \          INIT_LOCKDEP                                                    \
588  +       /***** TOMOYO Linux start. *****/        \  +       .ccs_domain_info = NULL,                 \
589  +       .domain_info = &KERNEL_DOMAIN,           \  +       .ccs_flags = 0,                          \
 +       .tomoyo_flags = 0,                       \  
 +       /***** TOMOYO Linux end. *****/          \  
590   }   }
591    
592    
593  --- linux-2.6.25.20-0.1.orig/include/linux/sched.h  --- linux-2.6.25.20-0.4.orig/include/linux/sched.h
594  +++ linux-2.6.25.20-0.1/include/linux/sched.h  +++ linux-2.6.25.20-0.4/include/linux/sched.h
595  @@ -29,6 +29,11 @@  @@ -29,6 +29,8 @@
596   #define CLONE_NEWNET           0x40000000      /* New network namespace */   #define CLONE_NEWNET           0x40000000      /* New network namespace */
597   #define CLONE_IO               0x80000000      /* Clone io context */   #define CLONE_IO               0x80000000      /* Clone io context */
598    
599  +/***** TOMOYO Linux start. *****/  +struct ccs_domain_info;
 +struct domain_info;  
 +extern struct domain_info KERNEL_DOMAIN;  
 +/***** TOMOYO Linux end. *****/  
600  +  +
601   /*   /*
602    * Scheduling policies    * Scheduling policies
603    */    */
604  @@ -1274,6 +1279,10 @@ struct task_struct {  @@ -1274,6 +1276,8 @@ struct task_struct {
605   #ifndef __GENKSYMS__   #ifndef __GENKSYMS__
606          struct list_head        *scm_work_list;          struct list_head        *scm_work_list;
607   #endif   #endif
608  +       /***** TOMOYO Linux start. *****/  +       struct ccs_domain_info *ccs_domain_info;
609  +       struct domain_info *domain_info;  +       u32 ccs_flags;
 +       u32 tomoyo_flags;  
 +       /***** TOMOYO Linux end. *****/  
610   };   };
611    
612   /*   /*
613  --- linux-2.6.25.20-0.1.orig/kernel/compat.c  --- linux-2.6.25.20-0.4.orig/kernel/compat.c
614  +++ linux-2.6.25.20-0.1/kernel/compat.c  +++ linux-2.6.25.20-0.4/kernel/compat.c
615  @@ -25,6 +25,9 @@  @@ -25,6 +25,7 @@
616   #include <linux/posix-timers.h>   #include <linux/posix-timers.h>
617    
618   #include <asm/uaccess.h>   #include <asm/uaccess.h>
 +/***** TOMOYO Linux start. *****/  
619  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
620    
621   int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts)   int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts)
622   {   {
623  @@ -869,6 +872,10 @@ asmlinkage long compat_sys_stime(compat_  @@ -869,6 +870,8 @@ asmlinkage long compat_sys_stime(compat_
624          err = security_settime(&tv, NULL);          err = security_settime(&tv, NULL);
625          if (err)          if (err)
626                  return err;                  return err;
627  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_SETTIME))
 +       if (!ccs_capable(TOMOYO_SYS_SETTIME))  
628  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
629    
630          do_settimeofday(&tv);          do_settimeofday(&tv);
631          return 0;          return 0;
632  --- linux-2.6.25.20-0.1.orig/kernel/kexec.c  --- linux-2.6.25.20-0.4.orig/kernel/kexec.c
633  +++ linux-2.6.25.20-0.1/kernel/kexec.c  +++ linux-2.6.25.20-0.4/kernel/kexec.c
634  @@ -31,6 +31,9 @@  @@ -31,6 +31,7 @@
635   #include <asm/system.h>   #include <asm/system.h>
636   #include <asm/semaphore.h>   #include <asm/semaphore.h>
637   #include <asm/sections.h>   #include <asm/sections.h>
 +/***** TOMOYO Linux start. *****/  
638  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
639    
640   /* Per cpu memory for storing cpu states in case of system crash. */   /* Per cpu memory for storing cpu states in case of system crash. */
641   note_buf_t* crash_notes;   note_buf_t* crash_notes;
642  @@ -969,6 +972,10 @@ asmlinkage long sys_kexec_load(unsigned  @@ -969,6 +970,8 @@ asmlinkage long sys_kexec_load(unsigned
643          /* We only trust the superuser with rebooting the system. */          /* We only trust the superuser with rebooting the system. */
644          if (!capable(CAP_SYS_BOOT))          if (!capable(CAP_SYS_BOOT))
645                  return -EPERM;                  return -EPERM;
646  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
 +       if (!ccs_capable(TOMOYO_SYS_KEXEC_LOAD))  
647  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
648    
649          /*          /*
650           * Verify we have a legal set of flags           * Verify we have a legal set of flags
651  --- linux-2.6.25.20-0.1.orig/kernel/kmod.c  --- linux-2.6.25.20-0.4.orig/kernel/kmod.c
652  +++ linux-2.6.25.20-0.1/kernel/kmod.c  +++ linux-2.6.25.20-0.4/kernel/kmod.c
653  @@ -173,6 +173,11 @@ static int ____call_usermodehelper(void  @@ -173,6 +173,9 @@ static int ____call_usermodehelper(void
654           */           */
655          set_user_nice(current, 0);          set_user_nice(current, 0);
656    
657  +       /***** TOMOYO Linux start. *****/  +       current->ccs_domain_info = NULL;
658  +       current->domain_info = &KERNEL_DOMAIN;  +       current->ccs_flags = 0;
 +       current->tomoyo_flags = 0;  
 +       /***** TOMOYO Linux end. *****/  
659  +  +
660          retval = kernel_execve(sub_info->path, sub_info->argv, sub_info->envp);          retval = kernel_execve(sub_info->path, sub_info->argv, sub_info->envp);
661    
662          /* Exec failed? */          /* Exec failed? */
663  --- linux-2.6.25.20-0.1.orig/kernel/module.c  --- linux-2.6.25.20-0.4.orig/kernel/module.c
664  +++ linux-2.6.25.20-0.1/kernel/module.c  +++ linux-2.6.25.20-0.4/kernel/module.c
665  @@ -47,6 +47,9 @@  @@ -47,6 +47,7 @@
666   #include <asm/cacheflush.h>   #include <asm/cacheflush.h>
667   #include <linux/license.h>   #include <linux/license.h>
668   #include <asm/sections.h>   #include <asm/sections.h>
 +/***** TOMOYO Linux start. *****/  
669  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
670    
671   #if 0   #if 0
672   #define DEBUGP printk   #define DEBUGP printk
673  @@ -700,6 +703,10 @@ sys_delete_module(const char __user *nam  @@ -700,6 +701,8 @@ sys_delete_module(const char __user *nam
674    
675          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
676                  return -EPERM;                  return -EPERM;
677  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
 +       if (!ccs_capable(TOMOYO_USE_KERNEL_MODULE))  
678  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
679    
680          if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)          if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
681                  return -EFAULT;                  return -EFAULT;
682  @@ -2181,6 +2188,10 @@ sys_init_module(void __user *umod,  @@ -2181,6 +2184,8 @@ sys_init_module(void __user *umod,
683          /* Must have permission */          /* Must have permission */
684          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
685                  return -EPERM;                  return -EPERM;
686  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
 +       if (!ccs_capable(TOMOYO_USE_KERNEL_MODULE))  
687  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
688    
689          /* Only one module load at a time, please */          /* Only one module load at a time, please */
690          if (mutex_lock_interruptible(&module_mutex) != 0)          if (mutex_lock_interruptible(&module_mutex) != 0)
691  --- linux-2.6.25.20-0.1.orig/kernel/ptrace.c  --- linux-2.6.25.20-0.4.orig/kernel/ptrace.c
692  +++ linux-2.6.25.20-0.1/kernel/ptrace.c  +++ linux-2.6.25.20-0.4/kernel/ptrace.c
693  @@ -24,6 +24,9 @@  @@ -24,6 +24,7 @@
694    
695   #include <asm/pgtable.h>   #include <asm/pgtable.h>
696   #include <asm/uaccess.h>   #include <asm/uaccess.h>
 +/***** TOMOYO Linux start. *****/  
697  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
698    
699   /*   /*
700    * ptrace a task: make the debugger its new parent and    * ptrace a task: make the debugger its new parent and
701  @@ -548,6 +551,10 @@ asmlinkage long sys_ptrace(long request,  @@ -548,6 +549,8 @@ asmlinkage long sys_ptrace(long request,
702          /*          /*
703           * This lock_kernel fixes a subtle race with suid exec           * This lock_kernel fixes a subtle race with suid exec
704           */           */
705  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_PTRACE))
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
706  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
707          lock_kernel();          lock_kernel();
708          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
709                  ret = ptrace_traceme();                  ret = ptrace_traceme();
710  @@ -655,6 +662,10 @@ asmlinkage long compat_sys_ptrace(compat  @@ -655,6 +658,8 @@ asmlinkage long compat_sys_ptrace(compat
711          /*          /*
712           * This lock_kernel fixes a subtle race with suid exec           * This lock_kernel fixes a subtle race with suid exec
713           */           */
714  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_PTRACE))
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
715  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
716          lock_kernel();          lock_kernel();
717          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
718                  ret = ptrace_traceme();                  ret = ptrace_traceme();
719  --- linux-2.6.25.20-0.1.orig/kernel/sched.c  --- linux-2.6.25.20-0.4.orig/kernel/sched.c
720  +++ linux-2.6.25.20-0.1/kernel/sched.c  +++ linux-2.6.25.20-0.4/kernel/sched.c
721  @@ -69,6 +69,9 @@  @@ -69,6 +69,7 @@
722    
723   #include <asm/tlb.h>   #include <asm/tlb.h>
724   #include <asm/irq_regs.h>   #include <asm/irq_regs.h>
 +/***** TOMOYO Linux start. *****/  
725  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
726    
727   /*   /*
728    * Scheduler clock - returns current time in nanosec units.    * Scheduler clock - returns current time in nanosec units.
729  @@ -4510,6 +4513,10 @@ int can_nice(const struct task_struct *p  @@ -4510,6 +4511,8 @@ int can_nice(const struct task_struct *p
730   asmlinkage long sys_nice(int increment)   asmlinkage long sys_nice(int increment)
731   {   {
732          long nice, retval;          long nice, retval;
733  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_NICE))
 +       if (!ccs_capable(TOMOYO_SYS_NICE))  
734  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
735    
736          /*          /*
737           * Setpriority might change our priority at the same moment.           * Setpriority might change our priority at the same moment.
738  --- linux-2.6.25.20-0.1.orig/kernel/signal.c  --- linux-2.6.25.20-0.4.orig/kernel/signal.c
739  +++ linux-2.6.25.20-0.1/kernel/signal.c  +++ linux-2.6.25.20-0.4/kernel/signal.c
740  @@ -32,6 +32,9 @@  @@ -32,6 +32,7 @@
741   #include <asm/unistd.h>   #include <asm/unistd.h>
742   #include <asm/siginfo.h>   #include <asm/siginfo.h>
743   #include "audit.h"     /* audit_signal_info() */   #include "audit.h"     /* audit_signal_info() */
 +/***** TOMOYO Linux start. *****/  
744  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
745    
746   /*   /*
747    * SLAB caches for signal bits.    * SLAB caches for signal bits.
748  @@ -2232,6 +2235,12 @@ asmlinkage long  @@ -2232,6 +2233,8 @@ asmlinkage long
749   sys_kill(int pid, int sig)   sys_kill(int pid, int sig)
750   {   {
751          struct siginfo info;          struct siginfo info;
752  +       /***** TOMOYO Linux start. *****/  +       if (ccs_kill_permission(pid, sig))
 +       if (sig && !ccs_capable(TOMOYO_SYS_KILL))  
753  +               return -EPERM;  +               return -EPERM;
 +       if (sig && ccs_check_signal_acl(sig, pid))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
754    
755          info.si_signo = sig;          info.si_signo = sig;
756          info.si_errno = 0;          info.si_errno = 0;
757  @@ -2290,6 +2299,12 @@ asmlinkage long sys_tgkill(int tgid, int  @@ -2290,6 +2293,8 @@ asmlinkage long sys_tgkill(int tgid, int
758          /* This is only valid for single tasks */          /* This is only valid for single tasks */
759          if (pid <= 0 || tgid <= 0)          if (pid <= 0 || tgid <= 0)
760                  return -EINVAL;                  return -EINVAL;
761  +       /***** TOMOYO Linux start. *****/  +       if (ccs_tgkill_permission(tgid, pid, sig))
 +       if (sig && !ccs_capable(TOMOYO_SYS_KILL))  
 +               return -EPERM;  
 +       if (sig && ccs_check_signal_acl(sig, pid))  
762  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
763    
764          return do_tkill(tgid, pid, sig);          return do_tkill(tgid, pid, sig);
765   }   }
766  @@ -2303,6 +2318,12 @@ sys_tkill(int pid, int sig)  @@ -2303,6 +2308,8 @@ sys_tkill(int pid, int sig)
767          /* This is only valid for single tasks */          /* This is only valid for single tasks */
768          if (pid <= 0)          if (pid <= 0)
769                  return -EINVAL;                  return -EINVAL;
770  +       /***** TOMOYO Linux start. *****/  +       if (ccs_tkill_permission(pid, sig))
 +       if (sig && !ccs_capable(TOMOYO_SYS_KILL))  
771  +               return -EPERM;  +               return -EPERM;
 +       if (sig && ccs_check_signal_acl(sig, pid))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
772    
773          return do_tkill(0, pid, sig);          return do_tkill(0, pid, sig);
774   }   }
775  --- linux-2.6.25.20-0.1.orig/kernel/sys.c  --- linux-2.6.25.20-0.4.orig/kernel/sys.c
776  +++ linux-2.6.25.20-0.1/kernel/sys.c  +++ linux-2.6.25.20-0.4/kernel/sys.c
777  @@ -42,6 +42,9 @@  @@ -42,6 +42,7 @@
778   #include <asm/uaccess.h>   #include <asm/uaccess.h>
779   #include <asm/io.h>   #include <asm/io.h>
780   #include <asm/unistd.h>   #include <asm/unistd.h>
 +/***** TOMOYO Linux start. *****/  
781  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
782    
783   #ifndef SET_UNALIGN_CTL   #ifndef SET_UNALIGN_CTL
784   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)
785  @@ -140,6 +143,12 @@ asmlinkage long sys_setpriority(int whic  @@ -140,6 +141,10 @@ asmlinkage long sys_setpriority(int whic
786    
787          if (which > PRIO_USER || which < PRIO_PROCESS)          if (which > PRIO_USER || which < PRIO_PROCESS)
788                  goto out;                  goto out;
789  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_NICE)) {
 +       if (!ccs_capable(TOMOYO_SYS_NICE)) {  
790  +               error = -EPERM;  +               error = -EPERM;
791  +               goto out;  +               goto out;
792  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
793    
794          /* normalize: avoid signed division (rounding problems) */          /* normalize: avoid signed division (rounding problems) */
795          error = -ESRCH;          error = -ESRCH;
796  @@ -376,6 +385,10 @@ asmlinkage long sys_reboot(int magic1, i  @@ -376,6 +381,8 @@ asmlinkage long sys_reboot(int magic1, i
797                          magic2 != LINUX_REBOOT_MAGIC2B &&                          magic2 != LINUX_REBOOT_MAGIC2B &&
798                          magic2 != LINUX_REBOOT_MAGIC2C))                          magic2 != LINUX_REBOOT_MAGIC2C))
799                  return -EINVAL;                  return -EINVAL;
800  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_REBOOT))
 +       if (!ccs_capable(TOMOYO_SYS_REBOOT))  
801  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
802    
803          /* Instead of trying to make the power_off code look like          /* Instead of trying to make the power_off code look like
804           * halt when pm_power_off is not set do it the easy way.           * halt when pm_power_off is not set do it the easy way.
805  @@ -1347,6 +1360,10 @@ asmlinkage long sys_sethostname(char __u  @@ -1347,6 +1354,8 @@ asmlinkage long sys_sethostname(char __u
806                  return -EPERM;                  return -EPERM;
807          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
808                  return -EINVAL;                  return -EINVAL;
809  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
 +       if (!ccs_capable(TOMOYO_SYS_SETHOSTNAME))  
810  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
811          down_write(&uts_sem);          down_write(&uts_sem);
812          errno = -EFAULT;          errno = -EFAULT;
813          if (!copy_from_user(tmp, name, len)) {          if (!copy_from_user(tmp, name, len)) {
814  @@ -1392,6 +1409,10 @@ asmlinkage long sys_setdomainname(char _  @@ -1392,6 +1401,8 @@ asmlinkage long sys_setdomainname(char _
815                  return -EPERM;                  return -EPERM;
816          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
817                  return -EINVAL;                  return -EINVAL;
818  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
 +       if (!ccs_capable(TOMOYO_SYS_SETHOSTNAME))  
819  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
820    
821          down_write(&uts_sem);          down_write(&uts_sem);
822          errno = -EFAULT;          errno = -EFAULT;
823  --- linux-2.6.25.20-0.1.orig/kernel/sysctl.c  --- linux-2.6.25.20-0.4.orig/kernel/sysctl.c
824  +++ linux-2.6.25.20-0.1/kernel/sysctl.c  +++ linux-2.6.25.20-0.4/kernel/sysctl.c
825  @@ -48,6 +48,9 @@  @@ -48,6 +48,7 @@
826    
827   #include <asm/uaccess.h>   #include <asm/uaccess.h>
828   #include <asm/processor.h>   #include <asm/processor.h>
 +/***** TOMOYO Linux start. *****/  
829  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
830    
831   #ifdef CONFIG_X86   #ifdef CONFIG_X86
832   #include <asm/nmi.h>   #include <asm/nmi.h>
833  @@ -1500,6 +1503,93 @@ char *sysctl_pathname(struct ctl_table *  @@ -1500,6 +1501,7 @@ char *sysctl_pathname(struct ctl_table *
834   EXPORT_SYMBOL_GPL(sysctl_pathname);   EXPORT_SYMBOL_GPL(sysctl_pathname);
835    
836   #ifdef CONFIG_SYSCTL_SYSCALL   #ifdef CONFIG_SYSCTL_SYSCALL
837  +  +
 +/***** TOMOYO Linux start. *****/  
 +static int try_parse_table(int __user *name, int nlen, void __user *oldval,  
 +                          void __user *newval, ctl_table *table)  
 +{  
 +       int n;  
 +       int error = -ENOMEM;  
 +       int op = 0;  
 +       char *buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);  
 +       if (oldval)  
 +               op |= 004;  
 +       if (newval)  
 +               op |= 002;  
 +       if (!op) { /* Neither read nor write */  
 +               error = 0;  
 +               goto out;  
 +       }  
 +       if (!buffer)  
 +               goto out;  
 +       memset(buffer, 0, PAGE_SIZE);  
 +       snprintf(buffer, PAGE_SIZE - 1, "/proc/sys");  
 + repeat:  
 +       if (!nlen) {  
 +               error = -ENOTDIR;  
 +               goto out;  
 +       }  
 +       if (get_user(n, name)) {  
 +               error = -EFAULT;  
 +               goto out;  
 +       }  
 +       for ( ; table->ctl_name || table->procname; table++) {  
 +               if (n == table->ctl_name && n) {  
 +                       int pos = strlen(buffer);  
 +                       const char *cp = table->procname;  
 +                       error = -ENOMEM;  
 +                       if (cp) {  
 +                               if (pos + 1 >= PAGE_SIZE - 1)  
 +                                       goto out;  
 +                               buffer[pos++] = '/';  
 +                               while (*cp) {  
 +                                       const unsigned char c  
 +                                               = *(const unsigned char *) cp;  
 +                                       if (c == '\\') {  
 +                                               if (pos + 2 >= PAGE_SIZE - 1)  
 +                                                       goto out;  
 +                                               buffer[pos++] = '\\';  
 +                                               buffer[pos++] = '\\';  
 +                                       } else if (c > ' ' && c < 127) {  
 +                                               if (pos + 1 >= PAGE_SIZE - 1)  
 +                                                       goto out;  
 +                                               buffer[pos++] = c;  
 +                                       } else {  
 +                                               if (pos + 4 >= PAGE_SIZE - 1)  
 +                                                       goto out;  
 +                                               buffer[pos++] = '\\';  
 +                                               buffer[pos++] = (c >> 6) + '0';  
 +                                               buffer[pos++] = ((c >> 3) & 7)  
 +                                                       + '0';  
 +                                               buffer[pos++] = (c & 7) + '0';  
 +                                       }  
 +                                       cp++;  
 +                               }  
 +                       } else {  
 +                               /* Assume nobody assigns "=\$=" for procname. */  
 +                               snprintf(buffer + pos, PAGE_SIZE - pos - 1,  
 +                                        "/=%d=", n);  
 +                               if (!memchr(buffer, '\0', PAGE_SIZE - 2))  
 +                                       goto out;  
 +                       }  
 +                       if (table->child) {  
 +                               name++;  
 +                               nlen--;  
 +                               table = table->child;  
 +                               goto repeat;  
 +                       }  
 +                       /* printk("sysctl='%s'\n", buffer); */  
 +                       error = ccs_check_file_perm(buffer, op, "sysctl");  
 +                       goto out;  
 +               }  
 +       }  
 +       error = -ENOTDIR;  
 + out:  
 +       kfree(buffer);  
 +       return error;  
 +}  
 +/***** TOMOYO Linux end. *****/  
 +  
838   int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,   int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
839                 void __user *newval, size_t newlen)                 void __user *newval, size_t newlen)
840   {   {
841  @@ -1516,6 +1606,11 @@ int do_sysctl(int __user *name, int nlen  @@ -1516,6 +1518,9 @@ int do_sysctl(int __user *name, int nlen
842    
843          for (head = sysctl_head_next(NULL); head;          for (head = sysctl_head_next(NULL); head;
844                          head = sysctl_head_next(head)) {                          head = sysctl_head_next(head)) {
845  +               /***** TOMOYO Linux start. *****/  +               error = ccs_parse_table(name, nlen, oldval, newval,
 +               error = try_parse_table(name, nlen, oldval, newval,  
846  +                                       head->ctl_table);  +                                       head->ctl_table);
847  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
848                  error = parse_table(name, nlen, oldval, oldlenp,                  error = parse_table(name, nlen, oldval, oldlenp,
849                                          newval, newlen, head->ctl_table);                                          newval, newlen, head->ctl_table);
850                  if (error != -ENOTDIR) {                  if (error != -ENOTDIR) {
851  --- linux-2.6.25.20-0.1.orig/kernel/time.c  --- linux-2.6.25.20-0.4.orig/kernel/time.c
852  +++ linux-2.6.25.20-0.1/kernel/time.c  +++ linux-2.6.25.20-0.4/kernel/time.c
853  @@ -38,6 +38,9 @@  @@ -38,6 +38,7 @@
854    
855   #include <asm/uaccess.h>   #include <asm/uaccess.h>
856   #include <asm/unistd.h>   #include <asm/unistd.h>
 +/***** TOMOYO Linux start. *****/  
857  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
858    
859   #include "timeconst.h"   #include "timeconst.h"
860    
861  @@ -88,6 +91,10 @@ asmlinkage long sys_stime(time_t __user  @@ -88,6 +89,8 @@ asmlinkage long sys_stime(time_t __user
862          err = security_settime(&tv, NULL);          err = security_settime(&tv, NULL);
863          if (err)          if (err)
864                  return err;                  return err;
865  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_SETTIME))
 +       if (!ccs_capable(TOMOYO_SYS_SETTIME))  
866  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
867    
868          do_settimeofday(&tv);          do_settimeofday(&tv);
869          return 0;          return 0;
870  @@ -159,6 +166,10 @@ int do_sys_settimeofday(struct timespec  @@ -159,6 +162,8 @@ int do_sys_settimeofday(struct timespec
871          error = security_settime(tv, tz);          error = security_settime(tv, tz);
872          if (error)          if (error)
873                  return error;                  return error;
874  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_SETTIME))
 +       if (!ccs_capable(TOMOYO_SYS_SETTIME))  
875  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
876    
877          if (tz) {          if (tz) {
878                  /* SMP safe, global irq locking makes it work. */                  /* SMP safe, global irq locking makes it work. */
879  --- linux-2.6.25.20-0.1.orig/kernel/time/ntp.c  --- linux-2.6.25.20-0.4.orig/kernel/time/ntp.c
880  +++ linux-2.6.25.20-0.1/kernel/time/ntp.c  +++ linux-2.6.25.20-0.4/kernel/time/ntp.c
881  @@ -17,6 +17,9 @@  @@ -17,6 +17,7 @@
882   #include <linux/capability.h>   #include <linux/capability.h>
883   #include <asm/div64.h>   #include <asm/div64.h>
884   #include <asm/timex.h>   #include <asm/timex.h>
 +/***** TOMOYO Linux start. *****/  
885  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
886    
887   /*   /*
888    * Timekeeping variables    * Timekeeping variables
889  @@ -243,6 +246,10 @@ int do_adjtimex(struct timex *txc)  @@ -243,6 +244,8 @@ int do_adjtimex(struct timex *txc)
890          /* In order to modify anything, you gotta be super-user! */          /* In order to modify anything, you gotta be super-user! */
891          if (txc->modes && !capable(CAP_SYS_TIME))          if (txc->modes && !capable(CAP_SYS_TIME))
892                  return -EPERM;                  return -EPERM;
893  +       /***** TOMOYO Linux start. *****/  +       if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
 +       if (txc->modes && !ccs_capable(TOMOYO_SYS_SETTIME))  
894  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
895    
896          /* Now we validate the data before disabling interrupts */          /* Now we validate the data before disabling interrupts */
897    
898  --- linux-2.6.25.20-0.1.orig/net/core/datagram.c  --- linux-2.6.25.20-0.4.orig/net/ipv4/inet_connection_sock.c
899  +++ linux-2.6.25.20-0.1/net/core/datagram.c  +++ linux-2.6.25.20-0.4/net/ipv4/inet_connection_sock.c
900  @@ -56,6 +56,11 @@  @@ -23,6 +23,7 @@
  #include <net/sock.h>  
  #include <net/tcp_states.h>  
   
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +#include <linux/tomoyo_socket.h>  
 +/***** TOMOYO Linux end. *****/  
 +  
  /*  
   *     Is a socket 'connection oriented' ?  
   */  
 @@ -179,6 +184,12 @@ struct sk_buff *__skb_recv_datagram(stru  
                 }  
                 spin_unlock_irqrestore(&sk->sk_receive_queue.lock, cpu_flags);  
   
 +               /***** TOMOYO Linux start. *****/  
 +               error = ccs_socket_recv_datagram_permission(sk, skb, flags);  
 +               if (error)  
 +                       goto no_packet;  
 +               /***** TOMOYO Linux end. *****/  
 +  
                 if (skb)  
                         return skb;  
   
 --- linux-2.6.25.20-0.1.orig/net/ipv4/inet_connection_sock.c  
 +++ linux-2.6.25.20-0.1/net/ipv4/inet_connection_sock.c  
 @@ -23,6 +23,9 @@  
901   #include <net/route.h>   #include <net/route.h>
902   #include <net/tcp_states.h>   #include <net/tcp_states.h>
903   #include <net/xfrm.h>   #include <net/xfrm.h>
 +/***** SAKURA Linux start. *****/  
904  +#include <linux/sakura.h>  +#include <linux/sakura.h>
 +/***** SAKURA Linux end. *****/  
905    
906   #ifdef INET_CSK_DEBUG   #ifdef INET_CSK_DEBUG
907   const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";   const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
908  @@ -98,6 +101,10 @@ int inet_csk_get_port(struct sock *sk, u  @@ -98,6 +99,8 @@ int inet_csk_get_port(struct sock *sk, u
909                  do {                  do {
910                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
911                          spin_lock(&head->lock);                          spin_lock(&head->lock);
912  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(rover))
 +                       if (ccs_may_autobind(rover))  
913  +                               goto next;  +                               goto next;
 +                       /***** SAKURA Linux end. *****/  
914                          inet_bind_bucket_for_each(tb, node, &head->chain)                          inet_bind_bucket_for_each(tb, node, &head->chain)
915                                  if (tb->ib_net == net && tb->port == rover)                                  if (tb->ib_net == net && tb->port == rover)
916                                          goto next;                                          goto next;
917  --- linux-2.6.25.20-0.1.orig/net/ipv4/inet_hashtables.c  --- linux-2.6.25.20-0.4.orig/net/ipv4/inet_hashtables.c
918  +++ linux-2.6.25.20-0.1/net/ipv4/inet_hashtables.c  +++ linux-2.6.25.20-0.4/net/ipv4/inet_hashtables.c
919  @@ -22,6 +22,9 @@  @@ -22,6 +22,7 @@
920   #include <net/inet_connection_sock.h>   #include <net/inet_connection_sock.h>
921   #include <net/inet_hashtables.h>   #include <net/inet_hashtables.h>
922   #include <net/ip.h>   #include <net/ip.h>
 +/***** SAKURA Linux start. *****/  
923  +#include <linux/sakura.h>  +#include <linux/sakura.h>
 +/***** SAKURA Linux end. *****/  
924    
925   /*   /*
926    * Allocate and initialize a new local port bind bucket.    * Allocate and initialize a new local port bind bucket.
927  @@ -421,6 +424,10 @@ int __inet_hash_connect(struct inet_time  @@ -421,6 +422,8 @@ int __inet_hash_connect(struct inet_time
928                  local_bh_disable();                  local_bh_disable();
929                  for (i = 1; i <= remaining; i++) {                  for (i = 1; i <= remaining; i++) {
930                          port = low + (i + offset) % remaining;                          port = low + (i + offset) % remaining;
931  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(port))
 +                       if (ccs_may_autobind(port))  
932  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
933                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
934                          spin_lock(&head->lock);                          spin_lock(&head->lock);
935    
936  --- linux-2.6.25.20-0.1.orig/net/ipv4/udp.c  --- linux-2.6.25.20-0.4.orig/net/ipv4/raw.c
937  +++ linux-2.6.25.20-0.1/net/ipv4/udp.c  +++ linux-2.6.25.20-0.4/net/ipv4/raw.c
938  @@ -105,6 +105,9 @@  @@ -79,6 +79,7 @@
939     #include <linux/seq_file.h>
940     #include <linux/netfilter.h>
941     #include <linux/netfilter_ipv4.h>
942    +#include <linux/tomoyo_socket.h>
943    
944     static struct raw_hashinfo raw_v4_hashinfo = {
945            .lock = __RW_LOCK_UNLOCKED(),
946    @@ -668,6 +669,9 @@ static int raw_recvmsg(struct kiocb *ioc
947            skb = skb_recv_datagram(sk, flags, noblock, &err);
948            if (!skb)
949                    goto out;
950    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
951    +       if (err)
952    +               goto out;
953    
954            copied = skb->len;
955            if (len < copied) {
956    --- linux-2.6.25.20-0.4.orig/net/ipv4/udp.c
957    +++ linux-2.6.25.20-0.4/net/ipv4/udp.c
958    @@ -105,6 +105,8 @@
959   #include <net/checksum.h>   #include <net/checksum.h>
960   #include <net/xfrm.h>   #include <net/xfrm.h>
961   #include "udp_impl.h"   #include "udp_impl.h"
 +/***** SAKURA Linux start. *****/  
962  +#include <linux/sakura.h>  +#include <linux/sakura.h>
963  +/***** SAKURA Linux end. *****/  +#include <linux/tomoyo_socket.h>
964    
965   /*   /*
966    *     Snmp MIB for the UDP layer    *     Snmp MIB for the UDP layer
967  @@ -176,6 +179,10 @@ int __udp_lib_get_port(struct sock *sk,  @@ -176,6 +178,8 @@ int __udp_lib_get_port(struct sock *sk,
968                  /* 1st pass: look for empty (or shortest) hash chain */                  /* 1st pass: look for empty (or shortest) hash chain */
969                  for (i = 0; i < UDP_HTABLE_SIZE; i++) {                  for (i = 0; i < UDP_HTABLE_SIZE; i++) {
970                          int size = 0;                          int size = 0;
971  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(rover))
 +                       if (ccs_may_autobind(rover))  
972  +                               goto next;  +                               goto next;
 +                       /***** SAKURA Linux end. *****/  
973    
974                          head = &udptable[rover & (UDP_HTABLE_SIZE - 1)];                          head = &udptable[rover & (UDP_HTABLE_SIZE - 1)];
975                          if (hlist_empty(head))                          if (hlist_empty(head))
976  @@ -199,6 +206,9 @@ int __udp_lib_get_port(struct sock *sk,  @@ -199,6 +203,7 @@ int __udp_lib_get_port(struct sock *sk,
977                  /* 2nd pass: find hole in shortest hash chain */                  /* 2nd pass: find hole in shortest hash chain */
978                  rover = best;                  rover = best;
979                  for (i = 0; i < (1 << 16) / UDP_HTABLE_SIZE; i++) {                  for (i = 0; i < (1 << 16) / UDP_HTABLE_SIZE; i++) {
980  +                       /***** SAKURA Linux start. *****/  +                       if (!ccs_lport_reserved(rover))
 +                       if (!ccs_may_autobind(rover))  
 +                       /***** SAKURA Linux end. *****/  
981                          if (! __udp_lib_lport_inuse(net, rover, udptable))                          if (! __udp_lib_lport_inuse(net, rover, udptable))
982                                  goto gotit;                                  goto gotit;
983                          rover += UDP_HTABLE_SIZE;                          rover += UDP_HTABLE_SIZE;
984  --- linux-2.6.25.20-0.1.orig/net/socket.c  @@ -863,6 +868,9 @@ try_again:
985  +++ linux-2.6.25.20-0.1/net/socket.c                                    &peeked, &err);
986  @@ -94,6 +94,11 @@          if (!skb)
987                    goto out;
988    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
989    +       if (err)
990    +               goto out;
991    
992            ulen = skb->len - sizeof(struct udphdr);
993            copied = len;
994    --- linux-2.6.25.20-0.4.orig/net/ipv6/raw.c
995    +++ linux-2.6.25.20-0.4/net/ipv6/raw.c
996    @@ -60,6 +60,7 @@
997    
998     #include <linux/proc_fs.h>
999     #include <linux/seq_file.h>
1000    +#include <linux/tomoyo_socket.h>
1001    
1002     static struct raw_hashinfo raw_v6_hashinfo = {
1003            .lock = __RW_LOCK_UNLOCKED(),
1004    @@ -482,6 +483,9 @@ static int rawv6_recvmsg(struct kiocb *i
1005            skb = skb_recv_datagram(sk, flags, noblock, &err);
1006            if (!skb)
1007                    goto out;
1008    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1009    +       if (err)
1010    +               goto out;
1011    
1012            copied = skb->len;
1013            if (copied > len) {
1014    --- linux-2.6.25.20-0.4.orig/net/ipv6/udp.c
1015    +++ linux-2.6.25.20-0.4/net/ipv6/udp.c
1016    @@ -50,6 +50,7 @@
1017     #include <linux/proc_fs.h>
1018     #include <linux/seq_file.h>
1019     #include "udp_impl.h"
1020    +#include <linux/tomoyo_socket.h>
1021    
1022     static inline int udp_v6_get_port(struct sock *sk, unsigned short snum)
1023     {
1024    @@ -137,6 +138,9 @@ try_again:
1025                                      &peeked, &err);
1026            if (!skb)
1027                    goto out;
1028    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1029    +       if (err)
1030    +               goto out;
1031    
1032            ulen = skb->len - sizeof(struct udphdr);
1033            copied = len;
1034    --- linux-2.6.25.20-0.4.orig/net/socket.c
1035    +++ linux-2.6.25.20-0.4/net/socket.c
1036    @@ -94,6 +94,9 @@
1037   #include <net/sock.h>   #include <net/sock.h>
1038   #include <linux/netfilter.h>   #include <linux/netfilter.h>
1039    
 +/***** TOMOYO Linux start. *****/  
1040  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
1041  +#include <linux/tomoyo_socket.h>  +#include <linux/tomoyo_socket.h>
 +/***** TOMOYO Linux end. *****/  
1042  +  +
1043   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
1044   static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,   static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
1045                           unsigned long nr_segs, loff_t pos);                           unsigned long nr_segs, loff_t pos);
1046  @@ -557,6 +562,12 @@ static inline int __sock_sendmsg(struct  @@ -555,6 +558,10 @@ static inline int __sock_sendmsg(struct
1047            si->size = size;
1048    
1049          err = security_socket_sendmsg(sock, msg, size);          err = security_socket_sendmsg(sock, msg, size);
1050    +       if (!err)
1051    +               err = ccs_socket_sendmsg_permission(sock, (struct sockaddr *)
1052    +                                                   msg->msg_name,
1053    +                                                   msg->msg_namelen);
1054          if (err)          if (err)
1055                  return err;                  return err;
 +       /***** TOMOYO Linux start. *****/  
 +       if (ccs_socket_sendmsg_permission(sock,  
 +                                         (struct sockaddr *) msg->msg_name,  
 +                                         msg->msg_namelen))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
1056    
1057          return sock->ops->sendmsg(iocb, sock, msg, size);  @@ -1121,6 +1128,8 @@ static int __sock_create(struct net *net
  }  
 @@ -1120,6 +1131,12 @@ static int __sock_create(struct net *net  
                 family = PF_PACKET;  
1058          }          }
1059    
 +       /***** TOMOYO Linux start. *****/  
 +       err = ccs_socket_create_permission(family, type, protocol);  
 +       if (err)  
 +               return err;  
 +       /***** TOMOYO Linux end. *****/  
 +  
1060          err = security_socket_create(family, type, protocol, kern);          err = security_socket_create(family, type, protocol, kern);
1061    +       if (!err)
1062    +               err = ccs_socket_create_permission(family, type, protocol);
1063          if (err)          if (err)
1064                  return err;                  return err;
1065  @@ -1351,6 +1368,13 @@ asmlinkage long sys_bind(int fd, struct  
1066                          err = security_socket_bind(sock,  @@ -1352,6 +1361,11 @@ asmlinkage long sys_bind(int fd, struct
1067                                                     (struct sockaddr *)address,                                                     (struct sockaddr *)address,
1068                                                     addrlen);                                                     addrlen);
1069  +                       /***** TOMOYO Linux start. *****/                          if (!err)
 +                       if (!err)  
1070  +                               err = ccs_socket_bind_permission(sock,  +                               err = ccs_socket_bind_permission(sock,
1071  +                                                        (struct sockaddr *)  +                                                        (struct sockaddr *)
1072  +                                                                address,  +                                                                address,
1073  +                                                                addrlen);  +                                                                addrlen);
1074  +                       /***** TOMOYO Linux end. *****/  +                       if (!err)
                         if (!err)  
1075                                  err = sock->ops->bind(sock,                                  err = sock->ops->bind(sock,
1076                                                        (struct sockaddr *)                                                        (struct sockaddr *)
1077  @@ -1380,6 +1404,10 @@ asmlinkage long sys_listen(int fd, int b                                                        address, addrlen);
1078                          backlog = somaxconn;  @@ -1381,6 +1395,8 @@ asmlinkage long sys_listen(int fd, int b
1079    
1080                  err = security_socket_listen(sock, backlog);                  err = security_socket_listen(sock, backlog);
 +               /***** TOMOYO Linux start. *****/  
 +               if (!err)  
 +                       err = ccs_socket_listen_permission(sock);  
 +               /***** TOMOYO Linux end. *****/  
1081                  if (!err)                  if (!err)
1082    +                       err = ccs_socket_listen_permission(sock);
1083    +               if (!err)
1084                          err = sock->ops->listen(sock, backlog);                          err = sock->ops->listen(sock, backlog);
1085    
1086  @@ -1444,6 +1472,13 @@ asmlinkage long sys_accept(int fd, struc                  fput_light(sock->file, fput_needed);
1087    @@ -1444,6 +1460,11 @@ asmlinkage long sys_accept(int fd, struc
1088          if (err < 0)          if (err < 0)
1089                  goto out_fd;                  goto out_fd;
1090    
 +       /***** TOMOYO Linux start. *****/  
1091  +       if (ccs_socket_accept_permission(newsock,  +       if (ccs_socket_accept_permission(newsock,
1092  +                                        (struct sockaddr *) address)) {  +                                        (struct sockaddr *) address)) {
1093  +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */  +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */
1094  +               goto out_fd;  +               goto out_fd;
1095  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
1096          if (upeer_sockaddr) {          if (upeer_sockaddr) {
1097                  if (newsock->ops->getname(newsock, (struct sockaddr *)address,                  if (newsock->ops->getname(newsock, (struct sockaddr *)address,
1098                                            &len, 2) < 0) {                                            &len, 2) < 0) {
1099  @@ -1508,6 +1543,12 @@ asmlinkage long sys_connect(int fd, stru  @@ -1506,6 +1527,9 @@ asmlinkage long sys_connect(int fd, stru
1100    
1101            err =
1102              security_socket_connect(sock, (struct sockaddr *)address, addrlen);              security_socket_connect(sock, (struct sockaddr *)address, addrlen);
1103    +       if (!err)
1104    +               err = ccs_socket_connect_permission(sock, (struct sockaddr *)
1105    +                                                   address, addrlen);
1106          if (err)          if (err)
1107                  goto out_put;                  goto out_put;
 +       /***** TOMOYO Linux start. *****/  
 +       err = ccs_socket_connect_permission(sock, (struct sockaddr *) address,  
 +                                           addrlen);  
 +       if (err)  
 +               goto out_put;  
 +       /***** TOMOYO Linux end. *****/  
1108    
1109          err = sock->ops->connect(sock, (struct sockaddr *)address, addrlen,  --- linux-2.6.25.20-0.4.orig/net/unix/af_unix.c
1110                                   sock->file->f_flags);  +++ linux-2.6.25.20-0.4/net/unix/af_unix.c
1111  --- linux-2.6.25.20-0.1.orig/net/unix/af_unix.c  @@ -116,6 +116,7 @@
 +++ linux-2.6.25.20-0.1/net/unix/af_unix.c  
 @@ -116,6 +116,9 @@  
1112   #include <linux/mount.h>   #include <linux/mount.h>
1113   #include <net/checksum.h>   #include <net/checksum.h>
1114   #include <linux/security.h>   #include <linux/security.h>
 +/***** TOMOYO Linux start. *****/  
1115  +#include <linux/tomoyo.h>  +#include <linux/tomoyo.h>
 +/***** TOMOYO Linux end. *****/  
1116    
1117   static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];   static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
1118   static DEFINE_SPINLOCK(unix_table_lock);   static DEFINE_SPINLOCK(unix_table_lock);
1119  @@ -776,6 +779,11 @@ static int unix_bind(struct socket *sock  @@ -819,6 +820,9 @@ static int unix_bind(struct socket *sock
                 err = unix_autobind(sock);  
                 goto out;  
         }  
 +       /***** TOMOYO Linux start. *****/  
 +       err = -EPERM;  
 +       if (sunaddr->sun_path[0] && !ccs_capable(TOMOYO_CREATE_UNIX_SOCKET))  
 +               goto out;  
 +       /***** TOMOYO Linux end. *****/  
   
         err = unix_mkname(sunaddr, addr_len, &hash);  
         if (err < 0)  
 @@ -819,6 +827,13 @@ static int unix_bind(struct socket *sock  
1120                   */                   */
1121                  mode = S_IFSOCK |                  mode = S_IFSOCK |
1122                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
1123  +               /***** TOMOYO Linux start. *****/  +               err = ccs_check_mknod_permission(nd.path.dentry->d_inode,
1124  +               err = pre_vfs_mknod(nd.path.dentry->d_inode, dentry, mode);  +                                                dentry, nd.path.mnt, mode, 0);
 +               if (!err)  
 +                       err = ccs_check_1path_perm(TYPE_MKSOCK_ACL, dentry,  
 +                                                  nd.path.mnt);  
1125  +               if (!err)  +               if (!err)
 +               /***** TOMOYO Linux end. *****/  
1126                  err = vfs_mknod(nd.path.dentry->d_inode, dentry, nd.path.mnt,                  err = vfs_mknod(nd.path.dentry->d_inode, dentry, nd.path.mnt,
1127                                  mode, 0);                                  mode, 0);
1128                  if (err)                  if (err)

Legend:
Removed from v.2278  
changed lines
  Added in v.2855

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26