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

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

Legend:
Removed from v.2647  
changed lines
  Added in v.4049

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