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

Subversion リポジトリの参照

Diff of /trunk/1.8.x/ccs-patch/patches/ccs-patch-2.6.21.diff

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

trunk/1.5.x/ccs-patch/patches/ccs-patch-2.6.21.diff revision 885 by kumaneko, Thu Jan 10 09:23:18 2008 UTC trunk/1.6.x/ccs-patch/patches/ccs-patch-2.6.21.diff revision 2297 by kumaneko, Mon Mar 23 00:46:34 2009 UTC
# Line 1  Line 1 
1  This is TOMOYO Linux patch for kernel 2.6.21.  This is TOMOYO Linux patch for kernel 2.6.21.7.
2    
3  Source code for this patch is http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.21.tar.bz2  Source code for this patch is http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.21.7.tar.bz2
4  ---  ---
5   Makefile                        |    2   arch/alpha/kernel/ptrace.c      |    7 ++
6   arch/alpha/kernel/ptrace.c      |    8 +++   arch/ia64/ia32/sys_ia32.c       |    7 ++
7   arch/ia64/ia32/sys_ia32.c       |    8 +++   arch/ia64/kernel/ptrace.c       |    7 ++
8   arch/ia64/kernel/ptrace.c       |    8 +++   arch/m32r/kernel/ptrace.c       |    7 ++
9   arch/m32r/kernel/ptrace.c       |    8 +++   arch/mips/kernel/ptrace32.c     |    7 ++
10   arch/mips/kernel/ptrace32.c     |    8 +++   arch/powerpc/kernel/ptrace32.c  |    7 ++
11   arch/powerpc/kernel/ptrace32.c  |    8 +++   arch/s390/kernel/ptrace.c       |    7 ++
12   arch/s390/kernel/ptrace.c       |    8 +++   arch/sparc/kernel/ptrace.c      |    9 +++
13   arch/sh64/kernel/ptrace.c       |    8 +++   arch/sparc64/kernel/ptrace.c    |    9 +++
14   arch/sparc/kernel/ptrace.c      |   11 +++++   arch/x86_64/ia32/ptrace32.c     |    7 ++
  arch/sparc64/kernel/ptrace.c    |   11 +++++  
  arch/x86_64/ia32/ptrace32.c     |    8 +++  
15   fs/Kconfig                      |    2   fs/Kconfig                      |    2
16   fs/Makefile                     |    2   fs/Makefile                     |    2
17   fs/attr.c                       |   11 +++++   fs/attr.c                       |   19 ++++++++
18   fs/compat.c                     |    8 +++   fs/compat.c                     |   15 +++++-
19   fs/exec.c                       |   14 ++++++   fs/exec.c                       |   20 ++++++++
20   fs/fcntl.c                      |    7 +++   fs/fcntl.c                      |    9 +++
21   fs/ioctl.c                      |    6 ++   fs/ioctl.c                      |   11 ++++
22   fs/namei.c                      |   60 +++++++++++++++++++++++++++++   fs/namei.c                      |   55 +++++++++++++++++++++++
23   fs/namespace.c                  |   38 ++++++++++++++++++   fs/namespace.c                  |   49 ++++++++++++++++++++
24   fs/open.c                       |   21 ++++++++++   fs/open.c                       |   28 +++++++++++
25   fs/proc/Makefile                |    3 +   fs/proc/Makefile                |    3 +
26   fs/proc/proc_misc.c             |    9 ++++   fs/proc/proc_misc.c             |    5 ++
27   include/linux/init_task.h       |    4 +   include/linux/init_task.h       |    4 +
28   include/linux/sched.h           |    9 ++++   include/linux/sched.h           |    8 +++
29   kernel/compat.c                 |    6 ++   kernel/compat.c                 |    7 ++
30   kernel/kexec.c                  |    6 ++   kernel/kexec.c                  |    7 ++
31   kernel/kmod.c                   |    5 ++   kernel/kmod.c                   |    5 ++
32   kernel/module.c                 |    9 ++++   kernel/module.c                 |   11 ++++
33   kernel/ptrace.c                 |    8 +++   kernel/ptrace.c                 |    7 ++
34   kernel/sched.c                  |    6 ++   kernel/sched.c                  |    7 ++
35   kernel/signal.c                 |   15 +++++++   kernel/signal.c                 |   21 ++++++++
36   kernel/sys.c                    |   15 +++++++   kernel/sys.c                    |   21 ++++++++
37   kernel/sysctl.c                 |   81 ++++++++++++++++++++++++++++++++++++++++   kernel/sysctl.c                 |   95 ++++++++++++++++++++++++++++++++++++++++
38   kernel/time.c                   |    9 ++++   kernel/time.c                   |   11 ++++
39   kernel/time/ntp.c               |    6 ++   kernel/time/ntp.c               |    7 ++
40   net/core/datagram.c             |    9 ++++   net/core/datagram.c             |   11 ++++
41   net/ipv4/inet_connection_sock.c |    6 ++   net/ipv4/inet_connection_sock.c |    7 ++
42   net/ipv4/inet_hashtables.c      |    6 ++   net/ipv4/inet_hashtables.c      |    7 ++
43   net/ipv4/udp.c                  |    9 ++++   net/ipv4/udp.c                  |   11 ++++
44   net/ipv6/inet6_hashtables.c     |    6 ++   net/ipv6/inet6_hashtables.c     |    7 ++
45   net/socket.c                    |   28 +++++++++++++   net/socket.c                    |   41 +++++++++++++++++
46   net/unix/af_unix.c              |   10 ++++   net/unix/af_unix.c              |    8 +++
47   44 files changed, 527 insertions(+), 3 deletions(-)   42 files changed, 593 insertions(+), 2 deletions(-)
48    
49  --- linux-2.6.21.orig/Makefile  --- linux-2.6.21.7.orig/arch/alpha/kernel/ptrace.c
50  +++ linux-2.6.21/Makefile  +++ linux-2.6.21.7/arch/alpha/kernel/ptrace.c
 @@ -1,7 +1,7 @@  
  VERSION = 2  
  PATCHLEVEL = 6  
  SUBLEVEL = 21  
 -EXTRAVERSION =  
 +EXTRAVERSION = -ccs  
  NAME = Nocturnal Monster Puppy  
   
  # *DOCUMENTATION*  
 --- linux-2.6.21.orig/arch/alpha/kernel/ptrace.c  
 +++ linux-2.6.21/arch/alpha/kernel/ptrace.c  
51  @@ -20,6 +20,9 @@  @@ -20,6 +20,9 @@
52   #include <asm/pgtable.h>   #include <asm/pgtable.h>
53   #include <asm/system.h>   #include <asm/system.h>
# Line 71  Source code for this patch is http://www Line 58  Source code for this patch is http://www
58    
59   #include "proto.h"   #include "proto.h"
60    
61  @@ -268,6 +271,11 @@ do_sys_ptrace(long request, long pid, lo  @@ -268,6 +271,10 @@ do_sys_ptrace(long request, long pid, lo
62          unsigned long tmp;          unsigned long tmp;
63          size_t copied;          size_t copied;
64          long ret;          long ret;
65  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
66  +#ifdef TOMOYO_SYS_PTRACE  +       if (!ccs_capable(CCS_SYS_PTRACE))
67  +       if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;  +               return -EPERM;
 +#endif  
68  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
69    
70          lock_kernel();          lock_kernel();
71          DBG(DBG_MEM, ("request=%ld pid=%ld addr=0x%lx data=0x%lx\n",          DBG(DBG_MEM, ("request=%ld pid=%ld addr=0x%lx data=0x%lx\n",
72  --- linux-2.6.21.orig/arch/ia64/kernel/ptrace.c  --- linux-2.6.21.7.orig/arch/ia64/ia32/sys_ia32.c
73  +++ linux-2.6.21/arch/ia64/kernel/ptrace.c  +++ linux-2.6.21.7/arch/ia64/ia32/sys_ia32.c
74    @@ -56,6 +56,9 @@
75     #include <asm/types.h>
76     #include <asm/uaccess.h>
77     #include <asm/unistd.h>
78    +/***** TOMOYO Linux start. *****/
79    +#include <linux/tomoyo.h>
80    +/***** TOMOYO Linux end. *****/
81    
82     #include "ia32priv.h"
83    
84    @@ -1758,6 +1761,10 @@ sys32_ptrace (int request, pid_t pid, un
85            struct task_struct *child;
86            unsigned int value, tmp;
87            long i, ret;
88    +       /***** TOMOYO Linux start. *****/
89    +       if (!ccs_capable(CCS_SYS_PTRACE))
90    +               return -EPERM;
91    +       /***** TOMOYO Linux end. *****/
92    
93            lock_kernel();
94            if (request == PTRACE_TRACEME) {
95    --- linux-2.6.21.7.orig/arch/ia64/kernel/ptrace.c
96    +++ linux-2.6.21.7/arch/ia64/kernel/ptrace.c
97  @@ -28,6 +28,9 @@  @@ -28,6 +28,9 @@
98   #ifdef CONFIG_PERFMON   #ifdef CONFIG_PERFMON
99   #include <asm/perfmon.h>   #include <asm/perfmon.h>
# Line 95  Source code for this patch is http://www Line 104  Source code for this patch is http://www
104    
105   #include "entry.h"   #include "entry.h"
106    
107  @@ -1418,6 +1421,11 @@ sys_ptrace (long request, pid_t pid, uns  @@ -1418,6 +1421,10 @@ sys_ptrace (long request, pid_t pid, uns
108          struct task_struct *child;          struct task_struct *child;
109          struct switch_stack *sw;          struct switch_stack *sw;
110          long ret;          long ret;
111  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
112  +#ifdef TOMOYO_SYS_PTRACE  +       if (!ccs_capable(CCS_SYS_PTRACE))
113  +       if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;  +               return -EPERM;
 +#endif  
114  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
115    
116          lock_kernel();          lock_kernel();
117          ret = -EPERM;          ret = -EPERM;
118  --- linux-2.6.21.orig/arch/m32r/kernel/ptrace.c  --- linux-2.6.21.7.orig/arch/m32r/kernel/ptrace.c
119  +++ linux-2.6.21/arch/m32r/kernel/ptrace.c  +++ linux-2.6.21.7/arch/m32r/kernel/ptrace.c
120  @@ -32,6 +32,9 @@  @@ -32,6 +32,9 @@
121   #include <asm/system.h>   #include <asm/system.h>
122   #include <asm/processor.h>   #include <asm/processor.h>
# Line 119  Source code for this patch is http://www Line 127  Source code for this patch is http://www
127    
128   /*   /*
129    * This routine will get a word off of the process kernel stack.    * This routine will get a word off of the process kernel stack.
130  @@ -742,6 +745,11 @@ asmlinkage long sys_ptrace(long request,  @@ -742,6 +745,10 @@ asmlinkage long sys_ptrace(long request,
131   {   {
132          struct task_struct *child;          struct task_struct *child;
133          int ret;          int ret;
134  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
135  +#ifdef TOMOYO_SYS_PTRACE  +       if (!ccs_capable(CCS_SYS_PTRACE))
136  +       if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;  +               return -EPERM;
137  +#endif  +       /***** TOMOYO Linux end. *****/
138    
139            lock_kernel();
140            if (request == PTRACE_TRACEME) {
141    --- linux-2.6.21.7.orig/arch/mips/kernel/ptrace32.c
142    +++ linux-2.6.21.7/arch/mips/kernel/ptrace32.c
143    @@ -35,6 +35,9 @@
144     #include <asm/system.h>
145     #include <asm/uaccess.h>
146     #include <asm/bootinfo.h>
147    +/***** TOMOYO Linux start. *****/
148    +#include <linux/tomoyo.h>
149    +/***** TOMOYO Linux end. *****/
150    
151     int ptrace_getregs (struct task_struct *child, __s64 __user *data);
152     int ptrace_setregs (struct task_struct *child, __s64 __user *data);
153    @@ -50,6 +53,10 @@ asmlinkage int sys32_ptrace(int request,
154     {
155            struct task_struct *child;
156            int ret;
157    +       /***** TOMOYO Linux start. *****/
158    +       if (!ccs_capable(CCS_SYS_PTRACE))
159    +               return -EPERM;
160    +       /***** TOMOYO Linux end. *****/
161    
162     #if 0
163            printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
164    --- linux-2.6.21.7.orig/arch/powerpc/kernel/ptrace32.c
165    +++ linux-2.6.21.7/arch/powerpc/kernel/ptrace32.c
166    @@ -32,6 +32,9 @@
167     #include <asm/page.h>
168     #include <asm/pgtable.h>
169     #include <asm/system.h>
170    +/***** TOMOYO Linux start. *****/
171    +#include <linux/tomoyo.h>
172    +/***** TOMOYO Linux end. *****/
173    
174     #include "ptrace-common.h"
175    
176    @@ -45,6 +48,10 @@ long compat_sys_ptrace(int request, int
177     {
178            struct task_struct *child;
179            int ret;
180    +       /***** TOMOYO Linux start. *****/
181    +       if (!ccs_capable(CCS_SYS_PTRACE))
182    +               return -EPERM;
183  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
184    
185          lock_kernel();          lock_kernel();
186          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
187  --- linux-2.6.21.orig/arch/s390/kernel/ptrace.c  --- linux-2.6.21.7.orig/arch/s390/kernel/ptrace.c
188  +++ linux-2.6.21/arch/s390/kernel/ptrace.c  +++ linux-2.6.21.7/arch/s390/kernel/ptrace.c
189  @@ -41,6 +41,9 @@  @@ -41,6 +41,9 @@
190   #include <asm/system.h>   #include <asm/system.h>
191   #include <asm/uaccess.h>   #include <asm/uaccess.h>
# Line 143  Source code for this patch is http://www Line 196  Source code for this patch is http://www
196    
197   #ifdef CONFIG_COMPAT   #ifdef CONFIG_COMPAT
198   #include "compat_ptrace.h"   #include "compat_ptrace.h"
199  @@ -713,6 +716,11 @@ sys_ptrace(long request, long pid, long  @@ -713,6 +716,10 @@ sys_ptrace(long request, long pid, long
200          struct task_struct *child;          struct task_struct *child;
201          int ret;          int ret;
202    
203  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
204  +#ifdef TOMOYO_SYS_PTRACE  +       if (!ccs_capable(CCS_SYS_PTRACE))
205  +       if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;  +               return -EPERM;
 +#endif  
206  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
207          lock_kernel();          lock_kernel();
208          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
209                   ret = ptrace_traceme();                   ret = ptrace_traceme();
210  --- linux-2.6.21.orig/arch/sparc/kernel/ptrace.c  --- linux-2.6.21.7.orig/arch/sparc/kernel/ptrace.c
211  +++ linux-2.6.21/arch/sparc/kernel/ptrace.c  +++ linux-2.6.21.7/arch/sparc/kernel/ptrace.c
212  @@ -23,6 +23,9 @@  @@ -23,6 +23,9 @@
213   #include <asm/pgtable.h>   #include <asm/pgtable.h>
214   #include <asm/system.h>   #include <asm/system.h>
# Line 167  Source code for this patch is http://www Line 219  Source code for this patch is http://www
219    
220   #define MAGIC_CONSTANT 0x80000000   #define MAGIC_CONSTANT 0x80000000
221    
222  @@ -267,6 +270,14 @@ asmlinkage void do_ptrace(struct pt_regs  @@ -267,6 +270,12 @@ asmlinkage void do_ptrace(struct pt_regs
223          unsigned long addr2 = regs->u_regs[UREG_I4];          unsigned long addr2 = regs->u_regs[UREG_I4];
224          struct task_struct *child;          struct task_struct *child;
225          int ret;          int ret;
226  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
227  +#ifdef TOMOYO_SYS_PTRACE  +       if (!ccs_capable(CCS_SYS_PTRACE)) {
 +       if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) {  
228  +               pt_error_return(regs, EPERM);  +               pt_error_return(regs, EPERM);
229  +               return;  +               return;
230  +       }  +       }
 +#endif  
231  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
232    
233          lock_kernel();          lock_kernel();
234   #ifdef DEBUG_PTRACE   #ifdef DEBUG_PTRACE
235  --- linux-2.6.21.orig/arch/sparc64/kernel/ptrace.c  --- linux-2.6.21.7.orig/arch/sparc64/kernel/ptrace.c
236  +++ linux-2.6.21/arch/sparc64/kernel/ptrace.c  +++ linux-2.6.21.7/arch/sparc64/kernel/ptrace.c
237  @@ -32,6 +32,9 @@  @@ -32,6 +32,9 @@
238   #include <asm/spitfire.h>   #include <asm/spitfire.h>
239   #include <asm/page.h>   #include <asm/page.h>
# Line 194  Source code for this patch is http://www Line 244  Source code for this patch is http://www
244    
245   /* Returning from ptrace is a bit tricky because the syscall return   /* Returning from ptrace is a bit tricky because the syscall return
246    * low level code assumes any value returned which is negative and    * low level code assumes any value returned which is negative and
247  @@ -176,6 +179,14 @@ asmlinkage void do_ptrace(struct pt_regs  @@ -176,6 +179,12 @@ asmlinkage void do_ptrace(struct pt_regs
248          unsigned long addr2 = regs->u_regs[UREG_I4];          unsigned long addr2 = regs->u_regs[UREG_I4];
249          struct task_struct *child;          struct task_struct *child;
250          int ret;          int ret;
251  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
252  +#ifdef TOMOYO_SYS_PTRACE  +       if (!ccs_capable(CCS_SYS_PTRACE)) {
 +       if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) {  
253  +               pt_error_return(regs, EPERM);  +               pt_error_return(regs, EPERM);
254  +               return;  +               return;
255  +       }  +       }
 +#endif  
256  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
257    
258          if (test_thread_flag(TIF_32BIT)) {          if (test_thread_flag(TIF_32BIT)) {
259                  addr &= 0xffffffffUL;                  addr &= 0xffffffffUL;
260  --- linux-2.6.21.orig/fs/Kconfig  --- linux-2.6.21.7.orig/arch/x86_64/ia32/ptrace32.c
261  +++ linux-2.6.21/fs/Kconfig  +++ linux-2.6.21.7/arch/x86_64/ia32/ptrace32.c
262    @@ -26,6 +26,9 @@
263     #include <asm/i387.h>
264     #include <asm/fpu32.h>
265     #include <asm/ia32.h>
266    +/***** TOMOYO Linux start. *****/
267    +#include <linux/tomoyo.h>
268    +/***** TOMOYO Linux end. *****/
269    
270     /*
271      * Determines which flags the user has access to [1 = access, 0 = no access].
272    @@ -234,6 +237,10 @@ asmlinkage long sys32_ptrace(long reques
273            void __user *datap = compat_ptr(data);
274            int ret;
275            __u32 val;
276    +       /***** TOMOYO Linux start. *****/
277    +       if (!ccs_capable(CCS_SYS_PTRACE))
278    +               return -EPERM;
279    +       /***** TOMOYO Linux end. *****/
280    
281            switch (request) {
282            case PTRACE_TRACEME:
283    --- linux-2.6.21.7.orig/fs/Kconfig
284    +++ linux-2.6.21.7/fs/Kconfig
285  @@ -2055,5 +2055,7 @@ endif  @@ -2055,5 +2055,7 @@ endif
286   source "fs/nls/Kconfig"   source "fs/nls/Kconfig"
287   source "fs/dlm/Kconfig"   source "fs/dlm/Kconfig"
# Line 219  Source code for this patch is http://www Line 290  Source code for this patch is http://www
290  +  +
291   endmenu   endmenu
292    
293  --- linux-2.6.21.orig/fs/Makefile  --- linux-2.6.21.7.orig/fs/Makefile
294  +++ linux-2.6.21/fs/Makefile  +++ linux-2.6.21.7/fs/Makefile
295  @@ -114,3 +114,5 @@ obj-$(CONFIG_HPPFS)         += hppfs/  @@ -114,3 +114,5 @@ obj-$(CONFIG_HPPFS)         += hppfs/
296   obj-$(CONFIG_DEBUG_FS)         += debugfs/   obj-$(CONFIG_DEBUG_FS)         += debugfs/
297   obj-$(CONFIG_OCFS2_FS)         += ocfs2/   obj-$(CONFIG_OCFS2_FS)         += ocfs2/
298   obj-$(CONFIG_GFS2_FS)           += gfs2/   obj-$(CONFIG_GFS2_FS)           += gfs2/
299  +  +
300  +include $(srctree)/fs/Makefile-2.6.ccs  +include $(srctree)/fs/Makefile-2.6.ccs
301  --- linux-2.6.21.orig/fs/attr.c  --- linux-2.6.21.7.orig/fs/attr.c
302  +++ linux-2.6.21/fs/attr.c  +++ linux-2.6.21.7/fs/attr.c
303  @@ -15,6 +15,9 @@  @@ -15,6 +15,9 @@
304   #include <linux/fcntl.h>   #include <linux/fcntl.h>
305   #include <linux/quotaops.h>   #include <linux/quotaops.h>
# Line 239  Source code for this patch is http://www Line 310  Source code for this patch is http://www
310    
311   /* Taken over from the old code... */   /* Taken over from the old code... */
312    
313  @@ -145,12 +148,20 @@ int notify_change(struct dentry * dentry  @@ -145,12 +148,28 @@ int notify_change(struct dentry * dentry
314    
315          if (inode->i_op && inode->i_op->setattr) {          if (inode->i_op && inode->i_op->setattr) {
316                  error = security_inode_setattr(dentry, attr);                  error = security_inode_setattr(dentry, attr);
317  +               /***** TOMOYO Linux start. *****/  +               /***** TOMOYO Linux start. *****/
318  +               if (!error && (ia_valid & ATTR_MODE)) error = CheckCapabilityACL(TOMOYO_SYS_CHMOD);  +               if (!error && (ia_valid & ATTR_MODE) &&
319  +               if (!error && (ia_valid & (ATTR_UID | ATTR_GID))) error = CheckCapabilityACL(TOMOYO_SYS_CHOWN);  +                   !ccs_capable(CCS_SYS_CHMOD))
320    +                       error = -EPERM;
321    +               if (!error && (ia_valid & (ATTR_UID | ATTR_GID)) &&
322    +                   !ccs_capable(CCS_SYS_CHOWN))
323    +                       error = -EPERM;
324  +               /***** TOMOYO Linux end. *****/  +               /***** TOMOYO Linux end. *****/
325                  if (!error)                  if (!error)
326                          error = inode->i_op->setattr(dentry, attr);                          error = inode->i_op->setattr(dentry, attr);
# Line 254  Source code for this patch is http://www Line 329  Source code for this patch is http://www
329                  if (!error)                  if (!error)
330                          error = security_inode_setattr(dentry, attr);                          error = security_inode_setattr(dentry, attr);
331  +               /***** TOMOYO Linux start. *****/  +               /***** TOMOYO Linux start. *****/
332  +               if (!error && (ia_valid & ATTR_MODE)) error = CheckCapabilityACL(TOMOYO_SYS_CHMOD);  +               if (!error && (ia_valid & ATTR_MODE) &&
333  +               if (!error && (ia_valid & (ATTR_UID | ATTR_GID))) error = CheckCapabilityACL(TOMOYO_SYS_CHOWN);  +                   !ccs_capable(CCS_SYS_CHMOD))
334    +                       error = -EPERM;
335    +               if (!error && (ia_valid & (ATTR_UID | ATTR_GID)) &&
336    +                   !ccs_capable(CCS_SYS_CHOWN))
337    +                       error = -EPERM;
338  +               /***** TOMOYO Linux end. *****/  +               /***** TOMOYO Linux end. *****/
339                  if (!error) {                  if (!error) {
340                          if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||                          if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
341                              (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))                              (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
342  --- linux-2.6.21.orig/fs/compat.c  --- linux-2.6.21.7.orig/fs/compat.c
343  +++ linux-2.6.21/fs/compat.c  +++ linux-2.6.21.7/fs/compat.c
344  @@ -56,6 +56,9 @@  @@ -56,6 +56,9 @@
345   #include <asm/mmu_context.h>   #include <asm/mmu_context.h>
346   #include <asm/ioctls.h>   #include <asm/ioctls.h>
# Line 272  Source code for this patch is http://www Line 351  Source code for this patch is http://www
351    
352   int compat_log = 1;   int compat_log = 1;
353    
354  @@ -422,6 +425,9 @@ asmlinkage long compat_sys_ioctl(unsigne  @@ -398,6 +401,10 @@ asmlinkage long compat_sys_ioctl(unsigne
355    
356            /* RED-PEN how should LSM module know it's handling 32bit? */
357            error = security_file_ioctl(filp, cmd, arg);
358    +       /***** TOMOYO Linux start. *****/
359    +       if (!error)
360    +               error = ccs_check_ioctl_permission(filp, cmd, arg);
361    +       /***** TOMOYO Linux end. *****/
362            if (error)
363                    goto out_fput;
364    
365    @@ -422,6 +429,12 @@ asmlinkage long compat_sys_ioctl(unsigne
366                  /*FALL THROUGH*/                  /*FALL THROUGH*/
367    
368          default:          default:
369  +               /***** TOMOYO Linux start. *****/  +               /***** TOMOYO Linux start. *****/
370  +               if ((error = CheckCapabilityACL(TOMOYO_SYS_IOCTL)) < 0) goto out_fput;  +               if (!ccs_capable(CCS_SYS_IOCTL)) {
371    +                       error = -EPERM;
372    +                       goto out_fput;
373    +               }
374  +               /***** TOMOYO Linux end. *****/  +               /***** TOMOYO Linux end. *****/
375                  if (filp->f_op && filp->f_op->compat_ioctl) {                  if (filp->f_op && filp->f_op->compat_ioctl) {
376                          error = filp->f_op->compat_ioctl(filp, cmd, arg);                          error = filp->f_op->compat_ioctl(filp, cmd, arg);
377                          if (error != -ENOIOCTLCMD)                          if (error != -ENOIOCTLCMD)
378  @@ -1552,7 +1558,7 @@ int compat_do_execve(char * filename,  @@ -1552,7 +1565,7 @@ int compat_do_execve(char * filename,
379          if (retval < 0)          if (retval < 0)
380                  goto out;                  goto out;
381    
# Line 291  Source code for this patch is http://www Line 384  Source code for this patch is http://www
384          if (retval >= 0) {          if (retval >= 0) {
385                  free_arg_pages(bprm);                  free_arg_pages(bprm);
386    
387  --- linux-2.6.21.orig/fs/exec.c  --- linux-2.6.21.7.orig/fs/exec.c
388  +++ linux-2.6.21/fs/exec.c  +++ linux-2.6.21.7/fs/exec.c
389  @@ -58,6 +58,10 @@  @@ -58,6 +58,10 @@
390   #include <linux/kmod.h>   #include <linux/kmod.h>
391   #endif   #endif
# Line 304  Source code for this patch is http://www Line 397  Source code for this patch is http://www
397   int core_uses_pid;   int core_uses_pid;
398   char core_pattern[128] = "core";   char core_pattern[128] = "core";
399   int suid_dumpable = 0;   int suid_dumpable = 0;
400  @@ -140,6 +144,11 @@ asmlinkage long sys_uselib(const char __  @@ -140,6 +144,13 @@ asmlinkage long sys_uselib(const char __
401          if (error)          if (error)
402                  goto exit;                  goto exit;
403    
404  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
405  +       error = CheckOpenPermission(nd.dentry, nd.mnt, 01); /* 01 means "read". */  +       /* 01 means "read". */
406  +       if (error) goto exit;  +       error = ccs_check_open_permission(nd.dentry, nd.mnt, 01);
407    +       if (error)
408    +               goto exit;
409  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
410  +  +
411          file = nameidata_to_filp(&nd, O_RDONLY);          file = nameidata_to_filp(&nd, O_RDONLY);
412          error = PTR_ERR(file);          error = PTR_ERR(file);
413          if (IS_ERR(file))          if (IS_ERR(file))
414  @@ -485,6 +494,9 @@ struct file *open_exec(const char *name)  @@ -485,6 +496,13 @@ struct file *open_exec(const char *name)
415                  if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&                  if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&
416                      S_ISREG(inode->i_mode)) {                      S_ISREG(inode->i_mode)) {
417                          int err = vfs_permission(&nd, MAY_EXEC);                          int err = vfs_permission(&nd, MAY_EXEC);
418  +                       /***** TOMOYO Linux start. *****/  +                       /***** TOMOYO Linux start. *****/
419  +                       if (!err && (current->tomoyo_flags & TOMOYO_CHECK_READ_FOR_OPEN_EXEC)) err = CheckOpenPermission(nd.dentry, nd.mnt, 01); /* 01 means "read". */  +                       if (!err && (current->ccs_flags &
420    +                                    CCS_CHECK_READ_FOR_OPEN_EXEC))
421    +                               /* 01 means "read". */
422    +                               err = ccs_check_open_permission(nd.dentry,
423    +                                                               nd.mnt, 01);
424  +                       /***** TOMOYO Linux end. *****/  +                       /***** TOMOYO Linux end. *****/
425                          file = ERR_PTR(err);                          file = ERR_PTR(err);
426                          if (!err) {                          if (!err) {
427                                  file = nameidata_to_filp(&nd, O_RDONLY);                                  file = nameidata_to_filp(&nd, O_RDONLY);
428  @@ -1183,7 +1195,7 @@ int do_execve(char * filename,  @@ -1183,7 +1201,7 @@ int do_execve(char * filename,
429          if (retval < 0)          if (retval < 0)
430                  goto out;                  goto out;
431    
432  -       retval = search_binary_handler(bprm,regs);  -       retval = search_binary_handler(bprm,regs);
433  +       retval = search_binary_handler_with_transition(bprm,regs);  +       retval = search_binary_handler_with_transition(bprm, regs);
434          if (retval >= 0) {          if (retval >= 0) {
435                  free_arg_pages(bprm);                  free_arg_pages(bprm);
436    
437  --- linux-2.6.21.orig/fs/fcntl.c  --- linux-2.6.21.7.orig/fs/fcntl.c
438  +++ linux-2.6.21/fs/fcntl.c  +++ linux-2.6.21.7/fs/fcntl.c
439  @@ -22,6 +22,9 @@  @@ -22,6 +22,9 @@
440   #include <asm/poll.h>   #include <asm/poll.h>
441   #include <asm/siginfo.h>   #include <asm/siginfo.h>
# Line 347  Source code for this patch is http://www Line 446  Source code for this patch is http://www
446    
447   void fastcall set_close_on_exec(unsigned int fd, int flag)   void fastcall set_close_on_exec(unsigned int fd, int flag)
448   {   {
449  @@ -213,6 +216,10 @@ static int setfl(int fd, struct file * f  @@ -213,6 +216,12 @@ static int setfl(int fd, struct file * f
450          if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode))          if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode))
451                  return -EPERM;                  return -EPERM;
452    
453  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
454  +       if (((arg ^ filp->f_flags) & O_APPEND) && CheckReWritePermission(filp)) return -EPERM;  +       if (((arg ^ filp->f_flags) & O_APPEND) &&
455    +           ccs_check_rewrite_permission(filp))
456    +               return -EPERM;
457  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
458  +  +
459          /* O_NOATIME can only be set by the owner or superuser */          /* O_NOATIME can only be set by the owner or superuser */
460          if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))          if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))
461                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
462  --- linux-2.6.21.orig/fs/ioctl.c  --- linux-2.6.21.7.orig/fs/ioctl.c
463  +++ linux-2.6.21/fs/ioctl.c  +++ linux-2.6.21.7/fs/ioctl.c
464  @@ -15,6 +15,9 @@  @@ -15,6 +15,9 @@
465    
466   #include <asm/uaccess.h>   #include <asm/uaccess.h>
# Line 370  Source code for this patch is http://www Line 471  Source code for this patch is http://www
471    
472   static long do_ioctl(struct file *filp, unsigned int cmd,   static long do_ioctl(struct file *filp, unsigned int cmd,
473                  unsigned long arg)                  unsigned long arg)
474  @@ -23,6 +26,9 @@ static long do_ioctl(struct file *filp,  @@ -23,6 +26,10 @@ static long do_ioctl(struct file *filp,
475    
476          if (!filp->f_op)          if (!filp->f_op)
477                  goto out;                  goto out;
478  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
479  +       if (CheckCapabilityACL(TOMOYO_SYS_IOCTL) < 0) return -EPERM;  +       if (!ccs_capable(CCS_SYS_IOCTL))
480    +               return -EPERM;
481  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
482    
483          if (filp->f_op->unlocked_ioctl) {          if (filp->f_op->unlocked_ioctl) {
484                  error = filp->f_op->unlocked_ioctl(filp, cmd, arg);                  error = filp->f_op->unlocked_ioctl(filp, cmd, arg);
485  --- linux-2.6.21.orig/fs/namei.c  @@ -167,6 +174,10 @@ asmlinkage long sys_ioctl(unsigned int f
486  +++ linux-2.6.21/fs/namei.c                  goto out;
487    
488            error = security_file_ioctl(filp, cmd, arg);
489    +       /***** TOMOYO Linux start. *****/
490    +       if (!error)
491    +               error = ccs_check_ioctl_permission(filp, cmd, arg);
492    +       /***** TOMOYO Linux end. *****/
493            if (error)
494                    goto out_fput;
495    
496    --- linux-2.6.21.7.orig/fs/namei.c
497    +++ linux-2.6.21.7/fs/namei.c
498  @@ -37,6 +37,10 @@  @@ -37,6 +37,10 @@
499    
500   #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])   #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
# Line 393  Source code for this patch is http://www Line 506  Source code for this patch is http://www
506   /* [Feb-1997 T. Schoebel-Theuer]   /* [Feb-1997 T. Schoebel-Theuer]
507    * Fundamental changes in the pathname lookup mechanisms (namei)    * Fundamental changes in the pathname lookup mechanisms (namei)
508    * were necessary because of omirr.  The reason is that omirr needs    * were necessary because of omirr.  The reason is that omirr needs
509  @@ -1506,6 +1510,9 @@ int vfs_create(struct inode *dir, struct  @@ -1561,6 +1565,13 @@ int may_open(struct nameidata *nd, int a
         error = security_inode_create(dir, dentry, mode);  
         if (error)  
                 return error;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (nd && (error = CheckSingleWritePermission(TYPE_CREATE_ACL, dentry, nd->mnt)) < 0) return error;  
 +       /***** TOMOYO Linux end. *****/  
         DQUOT_INIT(dir);  
         error = dir->i_op->create(dir, dentry, mode, nd);  
         if (!error)  
 @@ -1561,6 +1568,11 @@ int may_open(struct nameidata *nd, int a  
510                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
511                          return -EPERM;                          return -EPERM;
512    
513  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
514  +       error = CheckOpenPermission(dentry, nd->mnt, flag); /* includes O_APPEND and O_TRUNC checks */  +       /* includes O_APPEND and O_TRUNC checks */
515  +       if (error) return error;  +       error = ccs_check_open_permission(dentry, nd->mnt, flag);
516    +       if (error)
517    +               return error;
518  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
519  +  +
520          /*          /*
521           * Ensure there are no outstanding leases on the file.           * Ensure there are no outstanding leases on the file.
522           */           */
523  @@ -1610,6 +1622,9 @@ static int open_namei_create(struct name  @@ -1600,6 +1611,11 @@ static int open_namei_create(struct name
524    
525            if (!IS_POSIXACL(dir->d_inode))
526                    mode &= ~current->fs->umask;
527    +       /***** TOMOYO Linux start. *****/
528    +       error = ccs_check_mknod_permission(dir->d_inode, path->dentry,
529    +                                          nd->path.mnt, mode, 0);
530    +       if (!error)
531    +       /***** TOMOYO Linux end. *****/
532            error = vfs_create(dir->d_inode, path->dentry, mode, nd);
533            mutex_unlock(&dir->d_inode->i_mutex);
534            dput(nd->dentry);
535    @@ -1610,6 +1626,9 @@ static int open_namei_create(struct name
536          return may_open(nd, 0, flag & ~O_TRUNC);          return may_open(nd, 0, flag & ~O_TRUNC);
537   }   }
538    
# Line 425  Source code for this patch is http://www Line 542  Source code for this patch is http://www
542   /*   /*
543    *     open_namei()    *     open_namei()
544    *    *
545  @@ -1870,6 +1885,12 @@ asmlinkage long sys_mknodat(int dfd, con  @@ -1883,6 +1902,12 @@ asmlinkage long sys_mknodat(int dfd, con
546            if (!IS_POSIXACL(nd.dentry->d_inode))
547          if (S_ISDIR(mode))                  mode &= ~current->fs->umask;
548                  return -EPERM;          if (!IS_ERR(dentry)) {
549  +       /***** TOMOYO Linux start. *****/  +               /***** TOMOYO Linux start. *****/
550  +       if (S_ISCHR(mode) && CheckCapabilityACL(TOMOYO_CREATE_CHAR_DEV)) return -EPERM;  +               error = ccs_check_mknod_permission(nd.path.dentry->d_inode,
551  +       if (S_ISBLK(mode) && CheckCapabilityACL(TOMOYO_CREATE_BLOCK_DEV)) return -EPERM;  +                                                  dentry, nd.path.mnt, mode,
552  +       if (S_ISFIFO(mode) && CheckCapabilityACL(TOMOYO_CREATE_FIFO)) return -EPERM;  +                                                  new_decode_dev(dev));
553  +       if (S_ISSOCK(mode) && CheckCapabilityACL(TOMOYO_CREATE_UNIX_SOCKET)) return -EPERM;  +               if (!error)
554  +       /***** TOMOYO Linux end. *****/  +               /***** TOMOYO Linux end. *****/
555          tmp = getname(filename);                  switch (mode & S_IFMT) {
556          if (IS_ERR(tmp))                  case 0: case S_IFREG:
                 return PTR_ERR(tmp);  
 @@ -1888,10 +1909,16 @@ asmlinkage long sys_mknodat(int dfd, con  
557                          error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);                          error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
558                          break;  @@ -1959,6 +1984,11 @@ asmlinkage long sys_mkdirat(int dfd, con
                 case S_IFCHR: case S_IFBLK:  
 +                       /***** TOMOYO Linux start. *****/  
 +                       if ((error = pre_vfs_mknod(nd.dentry->d_inode, dentry, mode)) == 0 && (error = CheckSingleWritePermission(S_ISCHR(mode) ? TYPE_MKCHAR_ACL : TYPE_MKBLOCK_ACL, dentry, nd.mnt)) == 0)  
 +                       /***** TOMOYO Linux end. *****/  
                         error = vfs_mknod(nd.dentry->d_inode,dentry,mode,  
                                         new_decode_dev(dev));  
                         break;  
                 case S_IFIFO: case S_IFSOCK:  
 +                       /***** TOMOYO Linux start. *****/  
 +                       if ((error = pre_vfs_mknod(nd.dentry->d_inode, dentry, mode)) == 0 && (error = CheckSingleWritePermission(S_ISFIFO(mode) ? TYPE_MKFIFO_ACL : TYPE_MKSOCK_ACL, dentry, nd.mnt)) == 0)  
 +                       /***** TOMOYO Linux end. *****/  
                         error = vfs_mknod(nd.dentry->d_inode,dentry,mode,0);  
                         break;  
                 case S_IFDIR:  
 @@ -1959,6 +1986,9 @@ asmlinkage long sys_mkdirat(int dfd, con  
559    
560          if (!IS_POSIXACL(nd.dentry->d_inode))          if (!IS_POSIXACL(nd.dentry->d_inode))
561                  mode &= ~current->fs->umask;                  mode &= ~current->fs->umask;
562  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
563  +       if ((error = pre_vfs_mkdir(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_MKDIR_ACL, dentry, nd.mnt)) == 0)  +       error = ccs_check_mkdir_permission(nd.dentry->d_inode, dentry, nd.mnt,
564    +                                          mode);
565    +       if (!error)
566  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
567          error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);          error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
568          dput(dentry);          dput(dentry);
569   out_unlock:   out_unlock:
570  @@ -2066,6 +2096,9 @@ static long do_rmdir(int dfd, const char  @@ -2066,6 +2096,10 @@ static long do_rmdir(int dfd, const char
571          error = PTR_ERR(dentry);          error = PTR_ERR(dentry);
572          if (IS_ERR(dentry))          if (IS_ERR(dentry))
573                  goto exit2;                  goto exit2;
574  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
575  +       if ((error = pre_vfs_rmdir(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_RMDIR_ACL, dentry, nd.mnt)) == 0)  +       error = ccs_check_rmdir_permission(nd.dentry->d_inode, dentry, nd.mnt);
576    +       if (!error)
577  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
578          error = vfs_rmdir(nd.dentry->d_inode, dentry);          error = vfs_rmdir(nd.dentry->d_inode, dentry);
579          dput(dentry);          dput(dentry);
580   exit2:   exit2:
581  @@ -2125,6 +2158,9 @@ static long do_unlinkat(int dfd, const c  @@ -2146,6 +2180,11 @@ static long do_unlinkat(int dfd, const c
         struct dentry *dentry;  
         struct nameidata nd;  
         struct inode *inode = NULL;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (CheckCapabilityACL(TOMOYO_SYS_UNLINK)) return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         name = getname(pathname);  
         if(IS_ERR(name))  
 @@ -2146,6 +2182,9 @@ static long do_unlinkat(int dfd, const c  
582                  inode = dentry->d_inode;                  inode = dentry->d_inode;
583                  if (inode)                  if (inode)
584                          atomic_inc(&inode->i_count);                          atomic_inc(&inode->i_count);
585  +               /***** TOMOYO Linux start. *****/  +               /***** TOMOYO Linux start. *****/
586  +               if ((error = pre_vfs_unlink(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_UNLINK_ACL, dentry, nd.mnt)) == 0)  +               error = ccs_check_unlink_permission(nd.dentry->d_inode, dentry,
587  +               /***** TOMOYO Linux end. *****/  +                                                   nd.mnt);
588    +               if (!error)
589    +               /***** TOMOYO Linux end. *****/
590                  error = vfs_unlink(nd.dentry->d_inode, dentry);                  error = vfs_unlink(nd.dentry->d_inode, dentry);
591          exit2:          exit2:
592                  dput(dentry);                  dput(dentry);
593  @@ -2210,6 +2249,9 @@ asmlinkage long sys_symlinkat(const char  @@ -2227,6 +2266,11 @@ asmlinkage long sys_symlinkat(const char
         char * to;  
         struct dentry *dentry;  
         struct nameidata nd;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (CheckCapabilityACL(TOMOYO_SYS_SYMLINK)) return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         from = getname(oldname);  
         if(IS_ERR(from))  
 @@ -2227,6 +2269,9 @@ asmlinkage long sys_symlinkat(const char  
594          if (IS_ERR(dentry))          if (IS_ERR(dentry))
595                  goto out_unlock;                  goto out_unlock;
596    
597  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
598  +       if ((error = pre_vfs_symlink(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_SYMLINK_ACL, dentry, nd.mnt)) == 0)  +       error = ccs_check_symlink_permission(nd.dentry->d_inode, dentry,
599    +                                            nd.mnt, from);
600    +       if (!error)
601  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
602          error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);          error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
603          dput(dentry);          dput(dentry);
604   out_unlock:   out_unlock:
605  @@ -2299,6 +2344,9 @@ asmlinkage long sys_linkat(int olddfd, c  @@ -2322,6 +2366,11 @@ asmlinkage long sys_linkat(int olddfd, c
         struct nameidata nd, old_nd;  
         int error;  
         char * to;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (CheckCapabilityACL(TOMOYO_SYS_LINK)) return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         if ((flags & ~AT_SYMLINK_FOLLOW) != 0)  
                 return -EINVAL;  
 @@ -2322,6 +2370,9 @@ asmlinkage long sys_linkat(int olddfd, c  
606          error = PTR_ERR(new_dentry);          error = PTR_ERR(new_dentry);
607          if (IS_ERR(new_dentry))          if (IS_ERR(new_dentry))
608                  goto out_unlock;                  goto out_unlock;
609  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
610  +       if ((error = pre_vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry)) == 0 && (error = CheckDoubleWritePermission(TYPE_LINK_ACL, old_nd.dentry, old_nd.mnt, new_dentry, nd.mnt)) == 0)  +       error = ccs_check_link_permission(old_nd.dentry, nd.dentry->d_inode,
611    +                                         new_dentry, nd.mnt);
612    +       if (!error)
613  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
614          error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);          error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
615          dput(new_dentry);          dput(new_dentry);
616   out_unlock:   out_unlock:
617  @@ -2547,6 +2598,12 @@ static int do_rename(int olddfd, const c  @@ -2547,6 +2596,12 @@ static int do_rename(int olddfd, const c
618          error = -ENOTEMPTY;          error = -ENOTEMPTY;
619          if (new_dentry == trap)          if (new_dentry == trap)
620                  goto exit5;                  goto exit5;
621  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
622  +       if ((error = pre_vfs_rename(old_dir->d_inode, old_dentry, new_dir->d_inode, new_dentry)) < 0 ||  +       error = ccs_check_rename_permission(old_dir->d_inode, old_dentry,
623  +               (error = CheckDoubleWritePermission(TYPE_RENAME_ACL, old_dentry, oldnd.mnt, new_dentry, newnd.mnt)) < 0) {  +                                           new_dir->d_inode, new_dentry,
624  +               goto exit5;  +                                           newnd.mnt);
625  +       }  +       if (!error)
626  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
627    
628          error = vfs_rename(old_dir->d_inode, old_dentry,          error = vfs_rename(old_dir->d_inode, old_dentry,
629                                     new_dir->d_inode, new_dentry);                                     new_dir->d_inode, new_dentry);
630  @@ -2570,6 +2627,9 @@ asmlinkage long sys_renameat(int olddfd,  --- linux-2.6.21.7.orig/fs/namespace.c
631          int error;  +++ linux-2.6.21.7/fs/namespace.c
         char * from;  
         char * to;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (CheckCapabilityACL(TOMOYO_SYS_RENAME)) return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         from = getname(oldname);  
         if(IS_ERR(from))  
 --- linux-2.6.21.orig/fs/namespace.c  
 +++ linux-2.6.21/fs/namespace.c  
632  @@ -28,6 +28,12 @@  @@ -28,6 +28,12 @@
633   #include <asm/uaccess.h>   #include <asm/uaccess.h>
634   #include <asm/unistd.h>   #include <asm/unistd.h>
# Line 573  Source code for this patch is http://www Line 642  Source code for this patch is http://www
642    
643   /* spinlock for vfsmount related operations, inplace of dcache_lock */   /* spinlock for vfsmount related operations, inplace of dcache_lock */
644   __cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);   __cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);
645  @@ -545,6 +551,10 @@ static int do_umount(struct vfsmount *mn  @@ -545,6 +551,11 @@ static int do_umount(struct vfsmount *mn
646          if (retval)          if (retval)
647                  return retval;                  return retval;
648    
649  +       /***** SAKURA Linux start. *****/  +       /***** SAKURA Linux start. *****/
650  +       if (SAKURA_MayUmount(mnt) < 0) return -EPERM;  +       if (ccs_may_umount(mnt))
651    +               return -EPERM;
652  +       /***** SAKURA Linux end. *****/  +       /***** SAKURA Linux end. *****/
653  +  +
654          /*          /*
655           * Allow userspace to request a mountpoint be expired rather than           * Allow userspace to request a mountpoint be expired rather than
656           * unmounting unconditionally. Unmount only happens if:           * unmounting unconditionally. Unmount only happens if:
657  @@ -633,6 +643,9 @@ asmlinkage long sys_umount(char __user *  @@ -633,6 +644,10 @@ asmlinkage long sys_umount(char __user *
658   {   {
659          struct nameidata nd;          struct nameidata nd;
660          int retval;          int retval;
661  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
662  +       if (CheckCapabilityACL(TOMOYO_SYS_UMOUNT)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_UMOUNT))
663    +               return -EPERM;
664  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
665    
666          retval = __user_walk(name, LOOKUP_FOLLOW, &nd);          retval = __user_walk(name, LOOKUP_FOLLOW, &nd);
667          if (retval)          if (retval)
668  @@ -917,6 +930,10 @@ static int do_loopback(struct nameidata  @@ -917,6 +932,11 @@ static int do_loopback(struct nameidata
669    
670          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
671                  goto out;                  goto out;
672  +       /***** SAKURA Linux start. *****/  +       /***** SAKURA Linux start. *****/
673  +       err = -EPERM;  +       err = -EPERM;
674  +       if (SAKURA_MayMount(nd) < 0) goto out;  +       if (ccs_may_mount(nd))
675    +               goto out;
676  +       /***** SAKURA Linux end. *****/  +       /***** SAKURA Linux end. *****/
677    
678          err = -ENOMEM;          err = -ENOMEM;
679          if (recurse)          if (recurse)
680  @@ -1002,6 +1019,10 @@ static int do_move_mount(struct nameidat  @@ -1002,6 +1022,11 @@ static int do_move_mount(struct nameidat
681          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
682                  goto out;                  goto out;
683    
684  +       /***** SAKURA Linux start. *****/  +       /***** SAKURA Linux start. *****/
685  +       err = -EPERM;  +       err = -EPERM;
686  +       if (SAKURA_MayUmount(old_nd.mnt) < 0 || SAKURA_MayMount(nd) < 0) goto out;  +       if (ccs_may_umount(old_nd.mnt) || ccs_may_mount(nd))
687    +               goto out;
688  +       /***** SAKURA Linux end. *****/  +       /***** SAKURA Linux end. *****/
689          err = -ENOENT;          err = -ENOENT;
690          mutex_lock(&nd->dentry->d_inode->i_mutex);          mutex_lock(&nd->dentry->d_inode->i_mutex);
691          if (IS_DEADDIR(nd->dentry->d_inode))          if (IS_DEADDIR(nd->dentry->d_inode))
692  @@ -1103,6 +1124,10 @@ int do_add_mount(struct vfsmount *newmnt  @@ -1103,6 +1128,11 @@ int do_add_mount(struct vfsmount *newmnt
693          err = -EINVAL;          err = -EINVAL;
694          if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))          if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
695                  goto unlock;                  goto unlock;
696  +       /***** SAKURA Linux start. *****/  +       /***** SAKURA Linux start. *****/
697  +       err = -EPERM;  +       err = -EPERM;
698  +       if (SAKURA_MayMount(nd) < 0) goto unlock;  +       if (ccs_may_mount(nd))
699    +               goto unlock;
700  +       /***** SAKURA Linux end. *****/  +       /***** SAKURA Linux end. *****/
701    
702          newmnt->mnt_flags = mnt_flags;          newmnt->mnt_flags = mnt_flags;
703          if ((err = graft_tree(newmnt, nd)))          if ((err = graft_tree(newmnt, nd)))
704  @@ -1394,6 +1419,13 @@ long do_mount(char *dev_name, char *dir_  @@ -1394,6 +1424,17 @@ long do_mount(char *dev_name, char *dir_
705          if (data_page)          if (data_page)
706                  ((char *)data_page)[PAGE_SIZE - 1] = 0;                  ((char *)data_page)[PAGE_SIZE - 1] = 0;
707    
708  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
709  +       if (CheckCapabilityACL(TOMOYO_SYS_MOUNT)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_MOUNT))
710    +               return -EPERM;
711  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
712  +       /***** SAKURA Linux start. *****/  +       /***** SAKURA Linux start. *****/
713  +       if ((retval = CheckMountPermission(dev_name, dir_name, type_page, &flags)) < 0) return retval;  +       retval = ccs_check_mount_permission(dev_name, dir_name, type_page,
714    +                                           &flags);
715    +       if (retval)
716    +               return retval;
717  +       /***** SAKURA Linux end. *****/  +       /***** SAKURA Linux end. *****/
718  +  +
719          /* Separate the per-mountpoint flags */          /* Separate the per-mountpoint flags */
720          if (flags & MS_NOSUID)          if (flags & MS_NOSUID)
721                  mnt_flags |= MNT_NOSUID;                  mnt_flags |= MNT_NOSUID;
722  @@ -1686,6 +1718,9 @@ asmlinkage long sys_pivot_root(const cha  @@ -1686,6 +1727,10 @@ asmlinkage long sys_pivot_root(const cha
723    
724          if (!capable(CAP_SYS_ADMIN))          if (!capable(CAP_SYS_ADMIN))
725                  return -EPERM;                  return -EPERM;
726  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
727  +       if (CheckCapabilityACL(TOMOYO_SYS_PIVOT_ROOT)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_PIVOT_ROOT))
728    +               return -EPERM;
729  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
730    
731          lock_kernel();          lock_kernel();
732    
733  @@ -1702,6 +1737,9 @@ asmlinkage long sys_pivot_root(const cha  @@ -1702,6 +1747,10 @@ asmlinkage long sys_pivot_root(const cha
734                  goto out1;                  goto out1;
735    
736          error = security_sb_pivotroot(&old_nd, &new_nd);          error = security_sb_pivotroot(&old_nd, &new_nd);
737  +       /***** SAKURA Linux start. *****/  +       /***** SAKURA Linux start. *****/
738  +       if (!error) error = CheckPivotRootPermission(&old_nd, &new_nd);  +       if (!error)
739    +               error = ccs_check_pivot_root_permission(&old_nd, &new_nd);
740  +       /***** SAKURA Linux end. *****/  +       /***** SAKURA Linux end. *****/
741          if (error) {          if (error) {
742                  path_release(&old_nd);                  path_release(&old_nd);
743                  goto out1;                  goto out1;
744  --- linux-2.6.21.orig/fs/open.c  --- linux-2.6.21.7.orig/fs/open.c
745  +++ linux-2.6.21/fs/open.c  +++ linux-2.6.21.7/fs/open.c
746  @@ -27,6 +27,12 @@  @@ -27,6 +27,12 @@
747   #include <linux/syscalls.h>   #include <linux/syscalls.h>
748   #include <linux/rcupdate.h>   #include <linux/rcupdate.h>
# Line 676  Source code for this patch is http://www Line 756  Source code for this patch is http://www
756    
757   int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)   int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
758   {   {
759  @@ -264,6 +270,9 @@ static long do_sys_truncate(const char _  @@ -264,6 +270,10 @@ static long do_sys_truncate(const char _
760          if (error)          if (error)
761                  goto dput_and_out;                  goto dput_and_out;
762    
763  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
764  +       if ((error = CheckSingleWritePermission(TYPE_TRUNCATE_ACL, nd.dentry, nd.mnt)) == 0)  +       error = ccs_check_truncate_permission(nd.dentry, nd.mnt, length, 0);
765    +       if (!error)
766  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
767          error = locks_verify_truncate(inode, NULL, length);          error = locks_verify_truncate(inode, NULL, length);
768          if (!error) {          if (!error) {
769                  DQUOT_INIT(inode);                  DQUOT_INIT(inode);
770  @@ -317,6 +326,9 @@ static long do_sys_ftruncate(unsigned in  @@ -317,6 +327,12 @@ static long do_sys_ftruncate(unsigned in
771          if (IS_APPEND(inode))          if (IS_APPEND(inode))
772                  goto out_putf;                  goto out_putf;
773    
774  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
775  +       if ((error = CheckSingleWritePermission(TYPE_TRUNCATE_ACL, dentry, file->f_vfsmnt)) == 0)  +       error = ccs_check_truncate_permission(dentry, file->f_vfsmnt, length,
776    +                                             0);
777    +       if (error)
778    +               goto out_putf;
779  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
780          error = locks_verify_truncate(inode, file, length);          error = locks_verify_truncate(inode, file, length);
781          if (!error)          if (!error)
782                  error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);                  error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);
783  @@ -481,6 +493,12 @@ asmlinkage long sys_chroot(const char __  @@ -481,6 +497,14 @@ asmlinkage long sys_chroot(const char __
784          error = -EPERM;          error = -EPERM;
785          if (!capable(CAP_SYS_CHROOT))          if (!capable(CAP_SYS_CHROOT))
786                  goto dput_and_out;                  goto dput_and_out;
787  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
788  +       if (CheckCapabilityACL(TOMOYO_SYS_CHROOT)) goto dput_and_out;  +       if (!ccs_capable(CCS_SYS_CHROOT))
789    +               goto dput_and_out;
790  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
791  +       /***** SAKURA Linux start. *****/  +       /***** SAKURA Linux start. *****/
792  +       if (CheckChRootPermission(&nd)) goto dput_and_out;  +       if (ccs_check_chroot_permission(&nd))
793    +               goto dput_and_out;
794  +       /***** SAKURA Linux end. *****/  +       /***** SAKURA Linux end. *****/
795    
796          set_fs_root(current->fs, nd.mnt, nd.dentry);          set_fs_root(current->fs, nd.mnt, nd.dentry);
797          set_fs_altroot();          set_fs_altroot();
798  @@ -1085,6 +1103,9 @@ EXPORT_SYMBOL(sys_close);  @@ -1085,6 +1109,10 @@ EXPORT_SYMBOL(sys_close);
799    */    */
800   asmlinkage long sys_vhangup(void)   asmlinkage long sys_vhangup(void)
801   {   {
802  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
803  +       if (CheckCapabilityACL(TOMOYO_SYS_VHANGUP) == 0)  +       if (!ccs_capable(CCS_SYS_VHANGUP))
804    +               return -EPERM;
805  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
806          if (capable(CAP_SYS_TTY_CONFIG)) {          if (capable(CAP_SYS_TTY_CONFIG)) {
807                  /* XXX: this needs locking */                  /* XXX: this needs locking */
808                  tty_vhangup(current->signal->tty);                  tty_vhangup(current->signal->tty);
809  --- linux-2.6.21.orig/fs/proc/Makefile  --- linux-2.6.21.7.orig/fs/proc/Makefile
810  +++ linux-2.6.21/fs/proc/Makefile  +++ linux-2.6.21.7/fs/proc/Makefile
811  @@ -15,3 +15,6 @@ proc-$(CONFIG_PROC_KCORE)     += kcore.o  @@ -15,3 +15,6 @@ proc-$(CONFIG_PROC_KCORE)     += kcore.o
812   proc-$(CONFIG_PROC_VMCORE)     += vmcore.o   proc-$(CONFIG_PROC_VMCORE)     += vmcore.o
813   proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o   proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o
# Line 728  Source code for this patch is http://www Line 815  Source code for this patch is http://www
815  +  +
816  +proc-$(CONFIG_SAKURA) += ccs_proc.o  +proc-$(CONFIG_SAKURA) += ccs_proc.o
817  +proc-$(CONFIG_TOMOYO) += ccs_proc.o  +proc-$(CONFIG_TOMOYO) += ccs_proc.o
818  --- linux-2.6.21.orig/fs/proc/proc_misc.c  --- linux-2.6.21.7.orig/fs/proc/proc_misc.c
819  +++ linux-2.6.21/fs/proc/proc_misc.c  +++ linux-2.6.21.7/fs/proc/proc_misc.c
820  @@ -747,4 +747,13 @@ void __init proc_misc_init(void)  @@ -747,4 +747,9 @@ void __init proc_misc_init(void)
821                          entry->proc_fops = &proc_sysrq_trigger_operations;                          entry->proc_fops = &proc_sysrq_trigger_operations;
822          }          }
823   #endif   #endif
824  +       /***** CCS start. *****/  +       /***** CCS start. *****/
825  +#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO)  +#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO)
826  +       {  +       printk(KERN_INFO "Hook version: 2.6.21.7 2009/03/18\n");
 +               extern void __init CCSProc_Init(void);  
 +               CCSProc_Init();  
 +               printk("Hook version: 2.6.21 2008/01/05\n");  
 +       }  
827  +#endif  +#endif
828  +       /***** CCS end. *****/  +       /***** CCS end. *****/
829   }   }
830  --- linux-2.6.21.orig/include/linux/init_task.h  --- linux-2.6.21.7.orig/include/linux/init_task.h
831  +++ linux-2.6.21/include/linux/init_task.h  +++ linux-2.6.21.7/include/linux/init_task.h
832  @@ -141,6 +141,10 @@ extern struct group_info init_groups;  @@ -141,6 +141,10 @@ extern struct group_info init_groups;
833          .pi_lock        = SPIN_LOCK_UNLOCKED,                           \          .pi_lock        = SPIN_LOCK_UNLOCKED,                           \
834          INIT_TRACE_IRQFLAGS                                             \          INIT_TRACE_IRQFLAGS                                             \
835          INIT_LOCKDEP                                                    \          INIT_LOCKDEP                                                    \
836  +       /***** TOMOYO Linux start. *****/        \  +       /***** TOMOYO Linux start. *****/        \
837  +       .domain_info = &KERNEL_DOMAIN,           \  +       .ccs_domain_info = NULL,                 \
838  +       .tomoyo_flags = 0,                       \  +       .ccs_flags = 0,                          \
839  +       /***** TOMOYO Linux end. *****/          \  +       /***** TOMOYO Linux end. *****/          \
840   }   }
841    
842    
843  --- linux-2.6.21.orig/include/linux/sched.h  --- linux-2.6.21.7.orig/include/linux/sched.h
844  +++ linux-2.6.21/include/linux/sched.h  +++ linux-2.6.21.7/include/linux/sched.h
845  @@ -27,6 +27,11 @@  @@ -27,6 +27,10 @@
846   #define CLONE_NEWUTS           0x04000000      /* New utsname group? */   #define CLONE_NEWUTS           0x04000000      /* New utsname group? */
847   #define CLONE_NEWIPC           0x08000000      /* New ipcs */   #define CLONE_NEWIPC           0x08000000      /* New ipcs */
848    
849  +/***** TOMOYO Linux start. *****/  +/***** TOMOYO Linux start. *****/
850  +struct domain_info;  +struct ccs_domain_info;
 +extern struct domain_info KERNEL_DOMAIN;  
851  +/***** TOMOYO Linux end. *****/  +/***** TOMOYO Linux end. *****/
852  +  +
853   /*   /*
854    * Scheduling policies    * Scheduling policies
855    */    */
856  @@ -1052,6 +1057,10 @@ struct task_struct {  @@ -1052,6 +1056,10 @@ struct task_struct {
857   #ifdef CONFIG_FAULT_INJECTION   #ifdef CONFIG_FAULT_INJECTION
858          int make_it_fail;          int make_it_fail;
859   #endif   #endif
860  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
861  +       struct domain_info *domain_info;  +       struct ccs_domain_info *ccs_domain_info;
862  +       u32 tomoyo_flags;  +       u32 ccs_flags;
863  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
864   };   };
865    
866   static inline pid_t process_group(struct task_struct *tsk)   static inline pid_t process_group(struct task_struct *tsk)
867  --- linux-2.6.21.orig/kernel/compat.c  --- linux-2.6.21.7.orig/kernel/compat.c
868  +++ linux-2.6.21/kernel/compat.c  +++ linux-2.6.21.7/kernel/compat.c
869  @@ -25,6 +25,9 @@  @@ -25,6 +25,9 @@
870   #include <linux/posix-timers.h>   #include <linux/posix-timers.h>
871    
# Line 794  Source code for this patch is http://www Line 876  Source code for this patch is http://www
876    
877   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)
878   {   {
879  @@ -869,6 +872,9 @@ asmlinkage long compat_sys_stime(compat_  @@ -869,6 +872,10 @@ asmlinkage long compat_sys_stime(compat_
880          err = security_settime(&tv, NULL);          err = security_settime(&tv, NULL);
881          if (err)          if (err)
882                  return err;                  return err;
883  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
884  +       if (CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_SETTIME))
885    +               return -EPERM;
886  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
887    
888          do_settimeofday(&tv);          do_settimeofday(&tv);
889          return 0;          return 0;
890  --- linux-2.6.21.orig/kernel/kexec.c  --- linux-2.6.21.7.orig/kernel/kexec.c
891  +++ linux-2.6.21/kernel/kexec.c  +++ linux-2.6.21.7/kernel/kexec.c
892  @@ -28,6 +28,9 @@  @@ -28,6 +28,9 @@
893   #include <asm/io.h>   #include <asm/io.h>
894   #include <asm/system.h>   #include <asm/system.h>
# Line 816  Source code for this patch is http://www Line 899  Source code for this patch is http://www
899    
900   /* Per cpu memory for storing cpu states in case of system crash. */   /* Per cpu memory for storing cpu states in case of system crash. */
901   note_buf_t* crash_notes;   note_buf_t* crash_notes;
902  @@ -924,6 +927,9 @@ asmlinkage long sys_kexec_load(unsigned  @@ -924,6 +927,10 @@ asmlinkage long sys_kexec_load(unsigned
903          /* We only trust the superuser with rebooting the system. */          /* We only trust the superuser with rebooting the system. */
904          if (!capable(CAP_SYS_BOOT))          if (!capable(CAP_SYS_BOOT))
905                  return -EPERM;                  return -EPERM;
906  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
907  +       if (CheckCapabilityACL(TOMOYO_SYS_KEXEC_LOAD)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
908    +               return -EPERM;
909  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
910    
911          /*          /*
912           * Verify we have a legal set of flags           * Verify we have a legal set of flags
913  --- linux-2.6.21.orig/kernel/kmod.c  --- linux-2.6.21.7.orig/kernel/kmod.c
914  +++ linux-2.6.21/kernel/kmod.c  +++ linux-2.6.21.7/kernel/kmod.c
915  @@ -166,6 +166,11 @@ static int ____call_usermodehelper(void  @@ -166,6 +166,11 @@ static int ____call_usermodehelper(void
916          /* We can run anywhere, unlike our parent keventd(). */          /* We can run anywhere, unlike our parent keventd(). */
917          set_cpus_allowed(current, CPU_MASK_ALL);          set_cpus_allowed(current, CPU_MASK_ALL);
918    
919  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
920  +       current->domain_info = &KERNEL_DOMAIN;  +       current->ccs_domain_info = NULL;
921  +       current->tomoyo_flags = 0;  +       current->ccs_flags = 0;
922  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
923  +  +
924          retval = -EPERM;          retval = -EPERM;
925          if (current->fs->root)          if (current->fs->root)
926                  retval = kernel_execve(sub_info->path,                  retval = kernel_execve(sub_info->path,
927  --- linux-2.6.21.orig/kernel/module.c  --- linux-2.6.21.7.orig/kernel/module.c
928  +++ linux-2.6.21/kernel/module.c  +++ linux-2.6.21.7/kernel/module.c
929  @@ -44,6 +44,9 @@  @@ -44,6 +44,9 @@
930   #include <asm/semaphore.h>   #include <asm/semaphore.h>
931   #include <asm/cacheflush.h>   #include <asm/cacheflush.h>
# Line 852  Source code for this patch is http://www Line 936  Source code for this patch is http://www
936    
937   #if 0   #if 0
938   #define DEBUGP printk   #define DEBUGP printk
939  @@ -662,6 +665,9 @@ sys_delete_module(const char __user *nam  @@ -662,6 +665,10 @@ sys_delete_module(const char __user *nam
940    
941          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
942                  return -EPERM;                  return -EPERM;
943  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
944  +       if (CheckCapabilityACL(TOMOYO_USE_KERNEL_MODULE)) return -EPERM;  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
945    +               return -EPERM;
946  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
947    
948          if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)          if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
949                  return -EFAULT;                  return -EFAULT;
950  @@ -1983,6 +1989,9 @@ sys_init_module(void __user *umod,  @@ -1983,6 +1990,10 @@ sys_init_module(void __user *umod,
951          /* Must have permission */          /* Must have permission */
952          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
953                  return -EPERM;                  return -EPERM;
954  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
955  +       if (CheckCapabilityACL(TOMOYO_USE_KERNEL_MODULE)) return -EPERM;  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
956    +               return -EPERM;
957  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
958    
959          /* Only one module load at a time, please */          /* Only one module load at a time, please */
960          if (mutex_lock_interruptible(&module_mutex) != 0)          if (mutex_lock_interruptible(&module_mutex) != 0)
961  --- linux-2.6.21.orig/kernel/ptrace.c  --- linux-2.6.21.7.orig/kernel/ptrace.c
962  +++ linux-2.6.21/kernel/ptrace.c  +++ linux-2.6.21.7/kernel/ptrace.c
963  @@ -21,6 +21,9 @@  @@ -21,6 +21,9 @@
964    
965   #include <asm/pgtable.h>   #include <asm/pgtable.h>
# Line 884  Source code for this patch is http://www Line 970  Source code for this patch is http://www
970    
971   /*   /*
972    * ptrace a task: make the debugger its new parent and    * ptrace a task: make the debugger its new parent and
973  @@ -456,6 +459,11 @@ asmlinkage long sys_ptrace(long request,  @@ -456,6 +459,10 @@ asmlinkage long sys_ptrace(long request,
974          /*          /*
975           * This lock_kernel fixes a subtle race with suid exec           * This lock_kernel fixes a subtle race with suid exec
976           */           */
977  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
978  +#ifdef TOMOYO_SYS_PTRACE  +       if (!ccs_capable(CCS_SYS_PTRACE))
979  +       if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;  +               return -EPERM;
 +#endif  
980  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
981          lock_kernel();          lock_kernel();
982          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
983                  ret = ptrace_traceme();                  ret = ptrace_traceme();
984  --- linux-2.6.21.orig/kernel/sched.c  --- linux-2.6.21.7.orig/kernel/sched.c
985  +++ linux-2.6.21/kernel/sched.c  +++ linux-2.6.21.7/kernel/sched.c
986  @@ -55,6 +55,9 @@  @@ -55,6 +55,9 @@
987   #include <asm/tlb.h>   #include <asm/tlb.h>
988    
# Line 908  Source code for this patch is http://www Line 993  Source code for this patch is http://www
993    
994   /*   /*
995    * Scheduler clock - returns current time in nanosec units.    * Scheduler clock - returns current time in nanosec units.
996  @@ -3960,6 +3963,9 @@ int can_nice(const struct task_struct *p  @@ -3964,6 +3967,10 @@ int can_nice(const struct task_struct *p
997   asmlinkage long sys_nice(int increment)   asmlinkage long sys_nice(int increment)
998   {   {
999          long nice, retval;          long nice, retval;
1000  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1001  +       if (CheckCapabilityACL(TOMOYO_SYS_NICE)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_NICE))
1002    +               return -EPERM;
1003  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1004    
1005          /*          /*
1006           * Setpriority might change our priority at the same moment.           * Setpriority might change our priority at the same moment.
1007  --- linux-2.6.21.orig/kernel/signal.c  --- linux-2.6.21.7.orig/kernel/signal.c
1008  +++ linux-2.6.21/kernel/signal.c  +++ linux-2.6.21.7/kernel/signal.c
1009  @@ -32,6 +32,9 @@  @@ -32,6 +32,9 @@
1010   #include <asm/unistd.h>   #include <asm/unistd.h>
1011   #include <asm/siginfo.h>   #include <asm/siginfo.h>
# Line 930  Source code for this patch is http://www Line 1016  Source code for this patch is http://www
1016    
1017   /*   /*
1018    * SLAB caches for signal bits.    * SLAB caches for signal bits.
1019  @@ -2235,6 +2238,10 @@ asmlinkage long  @@ -2235,6 +2238,12 @@ asmlinkage long
1020   sys_kill(int pid, int sig)   sys_kill(int pid, int sig)
1021   {   {
1022          struct siginfo info;          struct siginfo info;
1023  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1024  +       if (sig && CheckCapabilityACL(TOMOYO_SYS_KILL) < 0) return -EPERM;  +       if (sig && !ccs_capable(CCS_SYS_KILL))
1025  +       if (sig && CheckSignalACL(sig, pid) < 0) return -EPERM;  +               return -EPERM;
1026    +       if (sig && ccs_check_signal_acl(sig, pid))
1027    +               return -EPERM;
1028  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1029    
1030          info.si_signo = sig;          info.si_signo = sig;
1031          info.si_errno = 0;          info.si_errno = 0;
1032  @@ -2293,6 +2300,10 @@ asmlinkage long sys_tgkill(int tgid, int  @@ -2293,6 +2302,12 @@ asmlinkage long sys_tgkill(int tgid, int
1033          /* This is only valid for single tasks */          /* This is only valid for single tasks */
1034          if (pid <= 0 || tgid <= 0)          if (pid <= 0 || tgid <= 0)
1035                  return -EINVAL;                  return -EINVAL;
1036  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1037  +       if (sig && CheckCapabilityACL(TOMOYO_SYS_KILL) < 0) return -EPERM;  +       if (sig && !ccs_capable(CCS_SYS_KILL))
1038  +       if (sig && CheckSignalACL(sig, pid) < 0) return -EPERM;  +               return -EPERM;
1039    +       if (sig && ccs_check_signal_acl(sig, pid))
1040    +               return -EPERM;
1041  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1042    
1043          return do_tkill(tgid, pid, sig);          return do_tkill(tgid, pid, sig);
1044   }   }
1045  @@ -2306,6 +2317,10 @@ sys_tkill(int pid, int sig)  @@ -2306,6 +2321,12 @@ sys_tkill(int pid, int sig)
1046          /* This is only valid for single tasks */          /* This is only valid for single tasks */
1047          if (pid <= 0)          if (pid <= 0)
1048                  return -EINVAL;                  return -EINVAL;
1049  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1050  +       if (sig && CheckCapabilityACL(TOMOYO_SYS_KILL) < 0) return -EPERM;  +       if (sig && !ccs_capable(CCS_SYS_KILL))
1051  +       if (sig && CheckSignalACL(sig, pid) < 0) return -EPERM;  +               return -EPERM;
1052    +       if (sig && ccs_check_signal_acl(sig, pid))
1053    +               return -EPERM;
1054  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1055    
1056          return do_tkill(0, pid, sig);          return do_tkill(0, pid, sig);
1057   }   }
1058  --- linux-2.6.21.orig/kernel/sys.c  --- linux-2.6.21.7.orig/kernel/sys.c
1059  +++ linux-2.6.21/kernel/sys.c  +++ linux-2.6.21.7/kernel/sys.c
1060  @@ -37,6 +37,9 @@  @@ -37,6 +37,9 @@
1061   #include <asm/uaccess.h>   #include <asm/uaccess.h>
1062   #include <asm/io.h>   #include <asm/io.h>
# Line 975  Source code for this patch is http://www Line 1067  Source code for this patch is http://www
1067    
1068   #ifndef SET_UNALIGN_CTL   #ifndef SET_UNALIGN_CTL
1069   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)
1070  @@ -600,6 +603,9 @@ asmlinkage long sys_setpriority(int whic  @@ -600,6 +603,12 @@ asmlinkage long sys_setpriority(int whic
1071    
1072          if (which > 2 || which < 0)          if (which > 2 || which < 0)
1073                  goto out;                  goto out;
1074  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1075  +       if (CheckCapabilityACL(TOMOYO_SYS_NICE)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_NICE)) {
1076    +               error = -EPERM;
1077    +               goto out;
1078    +       }
1079  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1080    
1081          /* normalize: avoid signed division (rounding problems) */          /* normalize: avoid signed division (rounding problems) */
1082          error = -ESRCH;          error = -ESRCH;
1083  @@ -830,6 +836,9 @@ asmlinkage long sys_reboot(int magic1, i  @@ -830,6 +839,10 @@ asmlinkage long sys_reboot(int magic1, i
1084                          magic2 != LINUX_REBOOT_MAGIC2B &&                          magic2 != LINUX_REBOOT_MAGIC2B &&
1085                          magic2 != LINUX_REBOOT_MAGIC2C))                          magic2 != LINUX_REBOOT_MAGIC2C))
1086                  return -EINVAL;                  return -EINVAL;
1087  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1088  +       if (CheckCapabilityACL(TOMOYO_SYS_REBOOT)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_REBOOT))
1089    +               return -EPERM;
1090  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1091    
1092          /* Instead of trying to make the power_off code look like          /* Instead of trying to make the power_off code look like
1093           * 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.
1094  @@ -1806,6 +1815,9 @@ asmlinkage long sys_sethostname(char __u  @@ -1806,6 +1819,10 @@ asmlinkage long sys_sethostname(char __u
1095                  return -EPERM;                  return -EPERM;
1096          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
1097                  return -EINVAL;                  return -EINVAL;
1098  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1099  +       if (CheckCapabilityACL(TOMOYO_SYS_SETHOSTNAME)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
1100    +               return -EPERM;
1101  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1102          down_write(&uts_sem);          down_write(&uts_sem);
1103          errno = -EFAULT;          errno = -EFAULT;
1104          if (!copy_from_user(tmp, name, len)) {          if (!copy_from_user(tmp, name, len)) {
1105  @@ -1851,6 +1863,9 @@ asmlinkage long sys_setdomainname(char _  @@ -1851,6 +1868,10 @@ asmlinkage long sys_setdomainname(char _
1106                  return -EPERM;                  return -EPERM;
1107          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
1108                  return -EINVAL;                  return -EINVAL;
1109  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1110  +       if (CheckCapabilityACL(TOMOYO_SYS_SETHOSTNAME)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
1111    +               return -EPERM;
1112  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1113    
1114          down_write(&uts_sem);          down_write(&uts_sem);
1115          errno = -EFAULT;          errno = -EFAULT;
1116  --- linux-2.6.21.orig/kernel/sysctl.c  --- linux-2.6.21.7.orig/kernel/sysctl.c
1117  +++ linux-2.6.21/kernel/sysctl.c  +++ linux-2.6.21.7/kernel/sysctl.c
1118  @@ -48,6 +48,9 @@  @@ -48,6 +48,9 @@
1119    
1120   #include <asm/uaccess.h>   #include <asm/uaccess.h>
# Line 1027  Source code for this patch is http://www Line 1125  Source code for this patch is http://www
1125    
1126   extern int proc_nr_files(ctl_table *table, int write, struct file *filp,   extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
1127                        void __user *buffer, size_t *lenp, loff_t *ppos);                        void __user *buffer, size_t *lenp, loff_t *ppos);
1128  @@ -1088,6 +1091,81 @@ struct ctl_table_header *sysctl_head_nex  @@ -1088,6 +1091,93 @@ struct ctl_table_header *sysctl_head_nex
1129   }   }
1130    
1131   #ifdef CONFIG_SYSCTL_SYSCALL   #ifdef CONFIG_SYSCTL_SYSCALL
1132  +  +
1133  +/***** TOMOYO Linux start. *****/  +/***** TOMOYO Linux start. *****/
1134  +static int try_parse_table(int __user *name, int nlen, void __user *oldval, void __user *newval, ctl_table *table)  +static int try_parse_table(int __user *name, int nlen, void __user *oldval,
1135    +                          void __user *newval, ctl_table *table)
1136  +{  +{
1137  +       int n;  +       int n;
1138  +       int error = -ENOMEM;  +       int error = -ENOMEM;
1139  +       int op = 0;  +       int op = 0;
1140  +       char *buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);  +       char *buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
1141  +       if (oldval) op |= 004;  +       if (oldval)
1142  +       if (newval) op |= 002;  +               op |= 004;
1143    +       if (newval)
1144    +               op |= 002;
1145  +       if (!op) { /* Neither read nor write */  +       if (!op) { /* Neither read nor write */
1146  +               error = 0;  +               error = 0;
1147  +               goto out;  +               goto out;
1148  +       }  +       }
1149  +       if (!buffer) goto out;  +       if (!buffer)
1150    +               goto out;
1151  +       memset(buffer, 0, PAGE_SIZE);  +       memset(buffer, 0, PAGE_SIZE);
1152  +       snprintf(buffer, PAGE_SIZE - 1, "/proc/sys");  +       snprintf(buffer, PAGE_SIZE - 1, "/proc/sys");
1153  + repeat:  + repeat:
# Line 1063  Source code for this patch is http://www Line 1165  Source code for this patch is http://www
1165  +                       const char *cp = table->procname;  +                       const char *cp = table->procname;
1166  +                       error = -ENOMEM;  +                       error = -ENOMEM;
1167  +                       if (cp) {  +                       if (cp) {
1168  +                               if (pos + 1 >= PAGE_SIZE - 1) goto out;  +                               if (pos + 1 >= PAGE_SIZE - 1)
1169    +                                       goto out;
1170  +                               buffer[pos++] = '/';  +                               buffer[pos++] = '/';
1171  +                               while (*cp) {  +                               while (*cp) {
1172  +                                       const unsigned char c = * (const unsigned char *) cp;  +                                       const unsigned char c
1173    +                                               = *(const unsigned char *) cp;
1174  +                                       if (c == '\\') {  +                                       if (c == '\\') {
1175  +                                               if (pos + 2 >= PAGE_SIZE - 1) goto out;  +                                               if (pos + 2 >= PAGE_SIZE - 1)
1176    +                                                       goto out;
1177  +                                               buffer[pos++] = '\\';  +                                               buffer[pos++] = '\\';
1178  +                                               buffer[pos++] = '\\';  +                                               buffer[pos++] = '\\';
1179  +                                       } else if (c > ' ' && c < 127) {  +                                       } else if (c > ' ' && c < 127) {
1180  +                                               if (pos + 1 >= PAGE_SIZE - 1) goto out;  +                                               if (pos + 1 >= PAGE_SIZE - 1)
1181    +                                                       goto out;
1182  +                                               buffer[pos++] = c;  +                                               buffer[pos++] = c;
1183  +                                       } else {  +                                       } else {
1184  +                                               if (pos + 4 >= PAGE_SIZE - 1) goto out;  +                                               if (pos + 4 >= PAGE_SIZE - 1)
1185    +                                                       goto out;
1186  +                                               buffer[pos++] = '\\';  +                                               buffer[pos++] = '\\';
1187  +                                               buffer[pos++] = (c >> 6) + '0';  +                                               buffer[pos++] = (c >> 6) + '0';
1188  +                                               buffer[pos++] = ((c >> 3) & 7) + '0';  +                                               buffer[pos++] = ((c >> 3) & 7)
1189    +                                                       + '0';
1190  +                                               buffer[pos++] = (c & 7) + '0';  +                                               buffer[pos++] = (c & 7) + '0';
1191  +                                       }  +                                       }
1192  +                                       cp++;  +                                       cp++;
1193  +                               }  +                               }
1194  +                       } else {  +                       } else {
1195  +                               /* Assume nobody assigns "=\$=" for procname. */  +                               /* Assume nobody assigns "=\$=" for procname. */
1196  +                               snprintf(buffer + pos, PAGE_SIZE - pos - 1, "/=%d=", n);  +                               snprintf(buffer + pos, PAGE_SIZE - pos - 1,
1197  +                               if (memchr(buffer, '\0', PAGE_SIZE - 2) == NULL) goto out;  +                                        "/=%d=", n);
1198    +                               if (!memchr(buffer, '\0', PAGE_SIZE - 2))
1199    +                                       goto out;
1200  +                       }  +                       }
1201  +                       if (table->child) {  +                       if (table->child) {
1202  +                               name++;  +                               name++;
# Line 1095  Source code for this patch is http://www Line 1205  Source code for this patch is http://www
1205  +                               goto repeat;  +                               goto repeat;
1206  +                       }  +                       }
1207  +                       /* printk("sysctl='%s'\n", buffer); */  +                       /* printk("sysctl='%s'\n", buffer); */
1208  +                       error = CheckFilePerm(buffer, op, "sysctl");  +                       error = ccs_check_file_perm(buffer, op, "sysctl");
1209  +                       goto out;  +                       goto out;
1210  +               }  +               }
1211  +       }  +       }
# Line 1109  Source code for this patch is http://www Line 1219  Source code for this patch is http://www
1219   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,
1220                 void __user *newval, size_t newlen)                 void __user *newval, size_t newlen)
1221   {   {
1222  @@ -1104,6 +1182,9 @@ int do_sysctl(int __user *name, int nlen  @@ -1104,6 +1194,11 @@ int do_sysctl(int __user *name, int nlen
1223    
1224          for (head = sysctl_head_next(NULL); head;          for (head = sysctl_head_next(NULL); head;
1225                          head = sysctl_head_next(head)) {                          head = sysctl_head_next(head)) {
1226  +               /***** TOMOYO Linux start. *****/  +               /***** TOMOYO Linux start. *****/
1227  +               if ((error = try_parse_table(name, nlen, oldval, newval, head->ctl_table)) == 0)  +               error = try_parse_table(name, nlen, oldval, newval,
1228    +                                       head->ctl_table);
1229    +               if (!error)
1230  +               /***** TOMOYO Linux end. *****/  +               /***** TOMOYO Linux end. *****/
1231                  error = parse_table(name, nlen, oldval, oldlenp,                  error = parse_table(name, nlen, oldval, oldlenp,
1232                                          newval, newlen, head->ctl_table);                                          newval, newlen, head->ctl_table);
1233                  if (error != -ENOTDIR) {                  if (error != -ENOTDIR) {
1234  --- linux-2.6.21.orig/kernel/time.c  --- linux-2.6.21.7.orig/kernel/time.c
1235  +++ linux-2.6.21/kernel/time.c  +++ linux-2.6.21.7/kernel/time.c
1236  @@ -39,6 +39,9 @@  @@ -39,6 +39,9 @@
1237    
1238   #include <asm/uaccess.h>   #include <asm/uaccess.h>
# Line 1131  Source code for this patch is http://www Line 1243  Source code for this patch is http://www
1243    
1244   /*   /*
1245    * The timezone where the local system is located.  Used as a default by some    * The timezone where the local system is located.  Used as a default by some
1246  @@ -91,6 +94,9 @@ asmlinkage long sys_stime(time_t __user  @@ -91,6 +94,10 @@ asmlinkage long sys_stime(time_t __user
1247          err = security_settime(&tv, NULL);          err = security_settime(&tv, NULL);
1248          if (err)          if (err)
1249                  return err;                  return err;
1250  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1251  +       if (CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_SETTIME))
1252    +               return -EPERM;
1253  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1254    
1255          do_settimeofday(&tv);          do_settimeofday(&tv);
1256          return 0;          return 0;
1257  @@ -161,6 +167,9 @@ int do_sys_settimeofday(struct timespec  @@ -161,6 +168,10 @@ int do_sys_settimeofday(struct timespec
1258          error = security_settime(tv, tz);          error = security_settime(tv, tz);
1259          if (error)          if (error)
1260                  return error;                  return error;
1261  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1262  +       if (CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_SETTIME))
1263    +               return -EPERM;
1264  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1265    
1266          if (tz) {          if (tz) {
1267                  /* SMP safe, global irq locking makes it work. */                  /* SMP safe, global irq locking makes it work. */
1268  --- linux-2.6.21.orig/kernel/time/ntp.c  --- linux-2.6.21.7.orig/kernel/time/ntp.c
1269  +++ linux-2.6.21/kernel/time/ntp.c  +++ linux-2.6.21.7/kernel/time/ntp.c
1270  @@ -14,6 +14,9 @@  @@ -14,6 +14,9 @@
1271    
1272   #include <asm/div64.h>   #include <asm/div64.h>
# Line 1163  Source code for this patch is http://www Line 1277  Source code for this patch is http://www
1277    
1278   /*   /*
1279    * Timekeeping variables    * Timekeeping variables
1280  @@ -203,6 +206,9 @@ int do_adjtimex(struct timex *txc)  @@ -201,6 +204,10 @@ int do_adjtimex(struct timex *txc)
1281          /* In order to modify anything, you gotta be super-user! */          /* In order to modify anything, you gotta be super-user! */
1282          if (txc->modes && !capable(CAP_SYS_TIME))          if (txc->modes && !capable(CAP_SYS_TIME))
1283                  return -EPERM;                  return -EPERM;
1284  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1285  +       if (txc->modes && CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;  +       if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
1286    +               return -EPERM;
1287  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1288    
1289          /* Now we validate the data before disabling interrupts */          /* Now we validate the data before disabling interrupts */
1290    
1291  --- linux-2.6.21.orig/net/core/datagram.c  --- linux-2.6.21.7.orig/net/core/datagram.c
1292  +++ linux-2.6.21/net/core/datagram.c  +++ linux-2.6.21.7/net/core/datagram.c
1293  @@ -56,6 +56,11 @@  @@ -56,6 +56,11 @@
1294   #include <net/sock.h>   #include <net/sock.h>
1295   #include <net/tcp_states.h>   #include <net/tcp_states.h>
# Line 1187  Source code for this patch is http://www Line 1302  Source code for this patch is http://www
1302   /*   /*
1303    *     Is a socket 'connection oriented' ?    *     Is a socket 'connection oriented' ?
1304    */    */
1305  @@ -178,6 +183,10 @@ struct sk_buff *skb_recv_datagram(struct  @@ -178,6 +183,12 @@ struct sk_buff *skb_recv_datagram(struct
1306                  } else                  } else
1307                          skb = skb_dequeue(&sk->sk_receive_queue);                          skb = skb_dequeue(&sk->sk_receive_queue);
1308    
1309  +               /***** TOMOYO Linux start. *****/  +               /***** TOMOYO Linux start. *****/
1310  +               if ((error = CheckSocketRecvDatagramPermission(sk, skb, flags)) < 0) goto no_packet;  +               error = ccs_socket_recv_datagram_permission(sk, skb, flags);
1311    +               if (error)
1312    +                       goto no_packet;
1313  +               /***** TOMOYO Linux end. *****/  +               /***** TOMOYO Linux end. *****/
1314  +  +
1315                  if (skb)                  if (skb)
1316                          return skb;                          return skb;
1317    
1318  --- linux-2.6.21.orig/net/ipv4/inet_connection_sock.c  --- linux-2.6.21.7.orig/net/ipv4/inet_connection_sock.c
1319  +++ linux-2.6.21/net/ipv4/inet_connection_sock.c  +++ linux-2.6.21.7/net/ipv4/inet_connection_sock.c
1320  @@ -23,6 +23,9 @@  @@ -23,6 +23,9 @@
1321   #include <net/route.h>   #include <net/route.h>
1322   #include <net/tcp_states.h>   #include <net/tcp_states.h>
# Line 1210  Source code for this patch is http://www Line 1327  Source code for this patch is http://www
1327    
1328   #ifdef INET_CSK_DEBUG   #ifdef INET_CSK_DEBUG
1329   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";
1330  @@ -87,6 +90,9 @@ int inet_csk_get_port(struct inet_hashin  @@ -85,6 +88,10 @@ int inet_csk_get_port(struct inet_hashin
1331                  do {                  do {
1332                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
1333                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1334  +                       /***** SAKURA Linux start. *****/  +                       /***** SAKURA Linux start. *****/
1335  +                       if (SAKURA_MayAutobind(rover) < 0) goto next;  +                       if (ccs_may_autobind(rover))
1336    +                               goto next;
1337  +                       /***** SAKURA Linux end. *****/  +                       /***** SAKURA Linux end. *****/
1338                          inet_bind_bucket_for_each(tb, node, &head->chain)                          inet_bind_bucket_for_each(tb, node, &head->chain)
1339                                  if (tb->port == rover)                                  if (tb->port == rover)
1340                                          goto next;                                          goto next;
1341  --- linux-2.6.21.orig/net/ipv4/inet_hashtables.c  --- linux-2.6.21.7.orig/net/ipv4/inet_hashtables.c
1342  +++ linux-2.6.21/net/ipv4/inet_hashtables.c  +++ linux-2.6.21.7/net/ipv4/inet_hashtables.c
1343  @@ -22,6 +22,9 @@  @@ -22,6 +22,9 @@
1344   #include <net/inet_connection_sock.h>   #include <net/inet_connection_sock.h>
1345   #include <net/inet_hashtables.h>   #include <net/inet_hashtables.h>
# Line 1232  Source code for this patch is http://www Line 1350  Source code for this patch is http://www
1350    
1351   /*   /*
1352    * Allocate and initialize a new local port bind bucket.    * Allocate and initialize a new local port bind bucket.
1353  @@ -292,6 +295,9 @@ int inet_hash_connect(struct inet_timewa  @@ -292,6 +295,10 @@ int inet_hash_connect(struct inet_timewa
1354                  local_bh_disable();                  local_bh_disable();
1355                  for (i = 1; i <= range; i++) {                  for (i = 1; i <= range; i++) {
1356                          port = low + (i + offset) % range;                          port = low + (i + offset) % range;
1357  +                       /***** SAKURA Linux start. *****/  +                       /***** SAKURA Linux start. *****/
1358  +                       if (SAKURA_MayAutobind(port) < 0) continue;  +                       if (ccs_may_autobind(port))
1359    +                               continue;
1360  +                       /***** SAKURA Linux end. *****/  +                       /***** SAKURA Linux end. *****/
1361                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
1362                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1363    
1364  --- linux-2.6.21.orig/net/ipv4/udp.c  --- linux-2.6.21.7.orig/net/ipv4/udp.c
1365  +++ linux-2.6.21/net/ipv4/udp.c  +++ linux-2.6.21.7/net/ipv4/udp.c
1366  @@ -102,6 +102,9 @@  @@ -102,6 +102,9 @@
1367   #include <net/checksum.h>   #include <net/checksum.h>
1368   #include <net/xfrm.h>   #include <net/xfrm.h>
# Line 1254  Source code for this patch is http://www Line 1373  Source code for this patch is http://www
1373    
1374   /*   /*
1375    *     Snmp MIB for the UDP layer    *     Snmp MIB for the UDP layer
1376  @@ -162,6 +165,9 @@ int __udp_lib_get_port(struct sock *sk,  @@ -162,6 +165,10 @@ int __udp_lib_get_port(struct sock *sk,
1377                                          result = sysctl_local_port_range[0] +                                          result = sysctl_local_port_range[0] +
1378                                                  ((result - sysctl_local_port_range[0]) &                                                  ((result - sysctl_local_port_range[0]) &
1379                                                   (UDP_HTABLE_SIZE - 1));                                                   (UDP_HTABLE_SIZE - 1));
1380  +                               /***** SAKURA Linux start. *****/  +                               /***** SAKURA Linux start. *****/
1381  +                               if (SAKURA_MayAutobind(result) < 0) continue;  +                               if (ccs_may_autobind(result))
1382    +                                       continue;
1383  +                               /***** SAKURA Linux end. *****/  +                               /***** SAKURA Linux end. *****/
1384                                  goto gotit;                                  goto gotit;
1385                          }                          }
1386                          size = 0;                          size = 0;
1387  @@ -180,6 +186,9 @@ int __udp_lib_get_port(struct sock *sk,  @@ -180,6 +187,10 @@ int __udp_lib_get_port(struct sock *sk,
1388                                  result = sysctl_local_port_range[0]                                  result = sysctl_local_port_range[0]
1389                                          + ((result - sysctl_local_port_range[0]) &                                          + ((result - sysctl_local_port_range[0]) &
1390                                             (UDP_HTABLE_SIZE - 1));                                             (UDP_HTABLE_SIZE - 1));
1391  +                       /***** SAKURA Linux start. *****/  +                       /***** SAKURA Linux start. *****/
1392  +                       if (SAKURA_MayAutobind(result) < 0) continue;  +                       if (ccs_may_autobind(result))
1393    +                               continue;
1394  +                       /***** SAKURA Linux end. *****/  +                       /***** SAKURA Linux end. *****/
1395                          if (! __udp_lib_lport_inuse(result, udptable))                          if (! __udp_lib_lport_inuse(result, udptable))
1396                                  break;                                  break;
1397                  }                  }
1398  --- linux-2.6.21.orig/net/ipv6/inet6_hashtables.c  --- linux-2.6.21.7.orig/net/ipv6/inet6_hashtables.c
1399  +++ linux-2.6.21/net/ipv6/inet6_hashtables.c  +++ linux-2.6.21.7/net/ipv6/inet6_hashtables.c
1400  @@ -21,6 +21,9 @@  @@ -21,6 +21,9 @@
1401   #include <net/inet_hashtables.h>   #include <net/inet_hashtables.h>
1402   #include <net/inet6_hashtables.h>   #include <net/inet6_hashtables.h>
# Line 1286  Source code for this patch is http://www Line 1407  Source code for this patch is http://www
1407    
1408   void __inet6_hash(struct inet_hashinfo *hashinfo,   void __inet6_hash(struct inet_hashinfo *hashinfo,
1409                                  struct sock *sk)                                  struct sock *sk)
1410  @@ -266,6 +269,9 @@ int inet6_hash_connect(struct inet_timew  @@ -266,6 +269,10 @@ int inet6_hash_connect(struct inet_timew
1411                  local_bh_disable();                  local_bh_disable();
1412                  for (i = 1; i <= range; i++) {                  for (i = 1; i <= range; i++) {
1413                          port = low + (i + offset) % range;                          port = low + (i + offset) % range;
1414  +                       /***** SAKURA Linux start. *****/  +                       /***** SAKURA Linux start. *****/
1415  +                       if (SAKURA_MayAutobind(port) < 0) continue;  +                       if (ccs_may_autobind(port))
1416    +                               continue;
1417  +                       /***** SAKURA Linux end. *****/  +                       /***** SAKURA Linux end. *****/
1418                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
1419                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1420    
1421  --- linux-2.6.21.orig/net/socket.c  --- linux-2.6.21.7.orig/net/socket.c
1422  +++ linux-2.6.21/net/socket.c  +++ linux-2.6.21.7/net/socket.c
1423  @@ -93,6 +93,11 @@  @@ -93,6 +93,11 @@
1424   #include <net/sock.h>   #include <net/sock.h>
1425   #include <linux/netfilter.h>   #include <linux/netfilter.h>
# Line 1310  Source code for this patch is http://www Line 1432  Source code for this patch is http://www
1432   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
1433   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,
1434                           unsigned long nr_segs, loff_t pos);                           unsigned long nr_segs, loff_t pos);
1435  @@ -549,6 +554,9 @@ static inline int __sock_sendmsg(struct  @@ -549,6 +554,12 @@ static inline int __sock_sendmsg(struct
1436          err = security_socket_sendmsg(sock, msg, size);          err = security_socket_sendmsg(sock, msg, size);
1437          if (err)          if (err)
1438                  return err;                  return err;
1439  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1440  +       if (CheckSocketSendMsgPermission(sock, (struct sockaddr *) msg->msg_name, msg->msg_namelen)) return -EPERM;  +       if (ccs_socket_sendmsg_permission(sock,
1441    +                                         (struct sockaddr *) msg->msg_name,
1442    +                                         msg->msg_namelen))
1443    +               return -EPERM;
1444  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1445    
1446          return sock->ops->sendmsg(iocb, sock, msg, size);          return sock->ops->sendmsg(iocb, sock, msg, size);
1447   }   }
1448  @@ -1070,6 +1078,10 @@ static int __sock_create(int family, int  @@ -1070,6 +1081,12 @@ static int __sock_create(int family, int
1449                  family = PF_PACKET;                  family = PF_PACKET;
1450          }          }
1451    
1452  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1453  +       if ((err = CheckSocketCreatePermission(family, type, protocol)) < 0) return err;  +       err = ccs_socket_create_permission(family, type, protocol);
1454    +       if (err)
1455    +               return err;
1456  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1457  +  +
1458          err = security_socket_create(family, type, protocol, kern);          err = security_socket_create(family, type, protocol, kern);
1459          if (err)          if (err)
1460                  return err;                  return err;
1461  @@ -1298,6 +1310,9 @@ asmlinkage long sys_bind(int fd, struct  @@ -1298,6 +1315,13 @@ asmlinkage long sys_bind(int fd, struct
1462                          err = security_socket_bind(sock,                          err = security_socket_bind(sock,
1463                                                     (struct sockaddr *)address,                                                     (struct sockaddr *)address,
1464                                                     addrlen);                                                     addrlen);
1465  +                       /***** TOMOYO Linux start. *****/  +                       /***** TOMOYO Linux start. *****/
1466  +                       if (!err) err = CheckSocketBindPermission(sock, (struct sockaddr *) address, addrlen);  +                       if (!err)
1467    +                               err = ccs_socket_bind_permission(sock,
1468    +                                                        (struct sockaddr *)
1469    +                                                                address,
1470    +                                                                addrlen);
1471  +                       /***** TOMOYO Linux end. *****/  +                       /***** TOMOYO Linux end. *****/
1472                          if (!err)                          if (!err)
1473                                  err = sock->ops->bind(sock,                                  err = sock->ops->bind(sock,
1474                                                        (struct sockaddr *)                                                        (struct sockaddr *)
1475  @@ -1327,6 +1342,9 @@ asmlinkage long sys_listen(int fd, int b  @@ -1327,6 +1351,10 @@ asmlinkage long sys_listen(int fd, int b
1476                          backlog = sysctl_somaxconn;                          backlog = sysctl_somaxconn;
1477    
1478                  err = security_socket_listen(sock, backlog);                  err = security_socket_listen(sock, backlog);
1479  +               /***** TOMOYO Linux start. *****/  +               /***** TOMOYO Linux start. *****/
1480  +               if (!err) err = CheckSocketListenPermission(sock);  +               if (!err)
1481    +                       err = ccs_socket_listen_permission(sock);
1482  +               /***** TOMOYO Linux end. *****/  +               /***** TOMOYO Linux end. *****/
1483                  if (!err)                  if (!err)
1484                          err = sock->ops->listen(sock, backlog);                          err = sock->ops->listen(sock, backlog);
1485    
1486  @@ -1391,6 +1409,12 @@ asmlinkage long sys_accept(int fd, struc  @@ -1391,6 +1419,13 @@ asmlinkage long sys_accept(int fd, struc
1487          if (err < 0)          if (err < 0)
1488                  goto out_fd;                  goto out_fd;
1489    
1490  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1491  +       if (CheckSocketAcceptPermission(newsock, (struct sockaddr *) address)) {  +       if (ccs_socket_accept_permission(newsock,
1492    +                                        (struct sockaddr *) address)) {
1493  +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */  +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */
1494  +               goto out_fd;  +               goto out_fd;
1495  +       }  +       }
# Line 1364  Source code for this patch is http://www Line 1497  Source code for this patch is http://www
1497          if (upeer_sockaddr) {          if (upeer_sockaddr) {
1498                  if (newsock->ops->getname(newsock, (struct sockaddr *)address,                  if (newsock->ops->getname(newsock, (struct sockaddr *)address,
1499                                            &len, 2) < 0) {                                            &len, 2) < 0) {
1500  @@ -1455,6 +1479,10 @@ asmlinkage long sys_connect(int fd, stru  @@ -1455,6 +1490,12 @@ asmlinkage long sys_connect(int fd, stru
1501              security_socket_connect(sock, (struct sockaddr *)address, addrlen);              security_socket_connect(sock, (struct sockaddr *)address, addrlen);
1502          if (err)          if (err)
1503                  goto out_put;                  goto out_put;
1504  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1505  +       err = CheckSocketConnectPermission(sock, (struct sockaddr *) address, addrlen);  +       err = ccs_socket_connect_permission(sock, (struct sockaddr *) address,
1506  +       if (err) goto out_put;  +                                           addrlen);
1507    +       if (err)
1508    +               goto out_put;
1509  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1510    
1511          err = sock->ops->connect(sock, (struct sockaddr *)address, addrlen,          err = sock->ops->connect(sock, (struct sockaddr *)address, addrlen,
1512                                   sock->file->f_flags);                                   sock->file->f_flags);
1513  --- linux-2.6.21.orig/net/unix/af_unix.c  --- linux-2.6.21.7.orig/net/unix/af_unix.c
1514  +++ linux-2.6.21/net/unix/af_unix.c  +++ linux-2.6.21.7/net/unix/af_unix.c
1515  @@ -116,6 +116,9 @@  @@ -116,6 +116,9 @@
1516   #include <linux/mount.h>   #include <linux/mount.h>
1517   #include <net/checksum.h>   #include <net/checksum.h>
# Line 1387  Source code for this patch is http://www Line 1522  Source code for this patch is http://www
1522    
1523   int sysctl_unix_max_dgram_qlen __read_mostly = 10;   int sysctl_unix_max_dgram_qlen __read_mostly = 10;
1524    
1525  @@ -765,6 +768,10 @@ static int unix_bind(struct socket *sock  @@ -808,6 +811,11 @@ static int unix_bind(struct socket *sock
                 err = unix_autobind(sock);  
                 goto out;  
         }  
 +       /***** TOMOYO Linux start. *****/  
 +       err = -EPERM;  
 +       if (sunaddr->sun_path[0] && CheckCapabilityACL(TOMOYO_CREATE_UNIX_SOCKET)) goto out;  
 +       /***** TOMOYO Linux end. *****/  
   
         err = unix_mkname(sunaddr, addr_len, &hash);  
         if (err < 0)  
 @@ -808,6 +815,9 @@ static int unix_bind(struct socket *sock  
1526                   */                   */
1527                  mode = S_IFSOCK |                  mode = S_IFSOCK |
1528                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
1529  +               /***** TOMOYO Linux start. *****/  +               /***** TOMOYO Linux start. *****/
1530  +               if ((err = pre_vfs_mknod(nd.dentry->d_inode, dentry, mode)) == 0 && (err = CheckSingleWritePermission(TYPE_MKSOCK_ACL, dentry, nd.mnt)) == 0)  +               err = ccs_check_mknod_permission(nd.dentry->d_inode, dentry,
1531    +                                                nd.mnt, mode, 0);
1532    +               if (!err)
1533  +               /***** TOMOYO Linux end. *****/  +               /***** TOMOYO Linux end. *****/
1534                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
1535                  if (err)                  if (err)
1536                          goto out_mknod_dput;                          goto out_mknod_dput;
 --- linux-2.6.21.orig/arch/powerpc/kernel/ptrace32.c  
 +++ linux-2.6.21/arch/powerpc/kernel/ptrace32.c  
 @@ -32,6 +32,9 @@  
  #include <asm/page.h>  
  #include <asm/pgtable.h>  
  #include <asm/system.h>  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
   
  #include "ptrace-common.h"  
   
 @@ -45,6 +48,11 @@ long compat_sys_ptrace(int request, int  
  {  
         struct task_struct *child;  
         int ret;  
 +       /***** TOMOYO Linux start. *****/  
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;  
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
   
         lock_kernel();  
         if (request == PTRACE_TRACEME) {  
 --- linux-2.6.21.orig/arch/sh64/kernel/ptrace.c  
 +++ linux-2.6.21/arch/sh64/kernel/ptrace.c  
 @@ -35,6 +35,9 @@  
  #include <asm/system.h>  
  #include <asm/processor.h>  
  #include <asm/mmu_context.h>  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
   
  /* This mask defines the bits of the SR which the user is not allowed to  
     change, which are everything except S, Q, M, PR, SZ, FR. */  
 @@ -271,6 +274,11 @@ asmlinkage int sh64_ptrace(long request,  
         extern void poke_real_address_q(unsigned long long addr, unsigned long long data);  
  #define WPC_DBRMODE 0x0d104008  
         static int first_call = 1;  
 +       /***** TOMOYO Linux start. *****/  
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;  
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
   
         lock_kernel();  
         if (first_call) {  
 --- linux-2.6.21.orig/arch/x86_64/ia32/ptrace32.c  
 +++ linux-2.6.21/arch/x86_64/ia32/ptrace32.c  
 @@ -26,6 +26,9 @@  
  #include <asm/i387.h>  
  #include <asm/fpu32.h>  
  #include <asm/ia32.h>  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
   
  /*  
   * Determines which flags the user has access to [1 = access, 0 = no access].  
 @@ -234,6 +237,11 @@ asmlinkage long sys32_ptrace(long reques  
         void __user *datap = compat_ptr(data);  
         int ret;  
         __u32 val;  
 +       /***** TOMOYO Linux start. *****/  
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;  
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
   
         switch (request) {  
         case PTRACE_TRACEME:  
 --- linux-2.6.21.orig/arch/ia64/ia32/sys_ia32.c  
 +++ linux-2.6.21/arch/ia64/ia32/sys_ia32.c  
 @@ -56,6 +56,9 @@  
  #include <asm/types.h>  
  #include <asm/uaccess.h>  
  #include <asm/unistd.h>  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
   
  #include "ia32priv.h"  
   
 @@ -1758,6 +1761,11 @@ sys32_ptrace (int request, pid_t pid, un  
         struct task_struct *child;  
         unsigned int value, tmp;  
         long i, ret;  
 +       /***** TOMOYO Linux start. *****/  
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;  
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
   
         lock_kernel();  
         if (request == PTRACE_TRACEME) {  
 --- linux-2.6.21.orig/arch/mips/kernel/ptrace32.c  
 +++ linux-2.6.21/arch/mips/kernel/ptrace32.c  
 @@ -35,6 +35,9 @@  
  #include <asm/system.h>  
  #include <asm/uaccess.h>  
  #include <asm/bootinfo.h>  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
   
  int ptrace_getregs (struct task_struct *child, __s64 __user *data);  
  int ptrace_setregs (struct task_struct *child, __s64 __user *data);  
 @@ -50,6 +53,11 @@ asmlinkage int sys32_ptrace(int request,  
  {  
         struct task_struct *child;  
         int ret;  
 +       /***** TOMOYO Linux start. *****/  
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (CheckCapabilityACL(TOMOYO_SYS_PTRACE)) return -EPERM;  
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
   
  #if 0  
         printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",  

Legend:
Removed from v.885  
changed lines
  Added in v.2297

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