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

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/ccs-patch-2.6.21.txt revision 352 by kumaneko, Tue Aug 14 11:27:50 2007 UTC trunk/1.6.x/ccs-patch/patches/ccs-patch-2.6.21.diff revision 2300 by kumaneko, Mon Mar 23 07:18:52 2009 UTC
# Line 1  Line 1 
1  diff -ubBpEr linux-2.6.21/Makefile linux-2.6.21-ccs/Makefile  This is TOMOYO Linux patch for kernel 2.6.21.7.
2  --- linux-2.6.21/Makefile       2007-04-28 04:02:41.000000000 +0900  
3  +++ linux-2.6.21-ccs/Makefile   2007-04-26 17:11:12.000000000 +0900  Source code for this patch is http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.21.7.tar.bz2
4  @@ -1,7 +1,7 @@  ---
5   VERSION = 2   arch/alpha/kernel/ptrace.c      |    7 +++++
6   PATCHLEVEL = 6   arch/ia64/ia32/sys_ia32.c       |    7 +++++
7   SUBLEVEL = 21   arch/ia64/kernel/ptrace.c       |    7 +++++
8  -EXTRAVERSION =   arch/m32r/kernel/ptrace.c       |    7 +++++
9  +EXTRAVERSION = -ccs   arch/mips/kernel/ptrace32.c     |    7 +++++
10   NAME = Nocturnal Monster Puppy   arch/powerpc/kernel/ptrace32.c  |    7 +++++
11     arch/s390/kernel/ptrace.c       |    7 +++++
12   # *DOCUMENTATION*   arch/sparc/kernel/ptrace.c      |    9 ++++++
13  diff -ubBpEr linux-2.6.21/fs/Kconfig linux-2.6.21-ccs/fs/Kconfig   arch/sparc64/kernel/ptrace.c    |    9 ++++++
14  --- linux-2.6.21/fs/Kconfig     2007-04-28 04:02:41.000000000 +0900   arch/x86_64/ia32/ptrace32.c     |    7 +++++
15  +++ linux-2.6.21-ccs/fs/Kconfig 2007-04-26 17:17:25.000000000 +0900   fs/Kconfig                      |    2 +
16     fs/Makefile                     |    2 +
17     fs/attr.c                       |   19 +++++++++++++
18     fs/compat.c                     |   15 ++++++++++
19     fs/exec.c                       |   20 +++++++++++++-
20     fs/fcntl.c                      |    9 ++++++
21     fs/ioctl.c                      |   11 ++++++++
22     fs/namei.c                      |   55 ++++++++++++++++++++++++++++++++++++++++
23     fs/namespace.c                  |   49 +++++++++++++++++++++++++++++++++++
24     fs/open.c                       |   28 ++++++++++++++++++++
25     fs/proc/Makefile                |    3 ++
26     fs/proc/proc_misc.c             |    5 +++
27     include/linux/init_task.h       |    4 ++
28     include/linux/sched.h           |    8 +++++
29     kernel/compat.c                 |    7 +++++
30     kernel/kexec.c                  |    7 +++++
31     kernel/kmod.c                   |    5 +++
32     kernel/module.c                 |   11 ++++++++
33     kernel/ptrace.c                 |    7 +++++
34     kernel/sched.c                  |    7 +++++
35     kernel/signal.c                 |   21 +++++++++++++++
36     kernel/sys.c                    |   21 +++++++++++++++
37     kernel/sysctl.c                 |    9 ++++++
38     kernel/time.c                   |   11 ++++++++
39     kernel/time/ntp.c               |    7 +++++
40     net/core/datagram.c             |   11 ++++++++
41     net/ipv4/inet_connection_sock.c |    7 +++++
42     net/ipv4/inet_hashtables.c      |    7 +++++
43     net/ipv4/udp.c                  |   11 ++++++++
44     net/ipv6/inet6_hashtables.c     |    7 +++++
45     net/socket.c                    |   41 +++++++++++++++++++++++++++++
46     net/unix/af_unix.c              |    8 +++++
47     42 files changed, 507 insertions(+), 2 deletions(-)
48    
49    --- linux-2.6.21.7.orig/arch/alpha/kernel/ptrace.c
50    +++ linux-2.6.21.7/arch/alpha/kernel/ptrace.c
51    @@ -20,6 +20,9 @@
52     #include <asm/pgtable.h>
53     #include <asm/system.h>
54     #include <asm/fpu.h>
55    +/***** TOMOYO Linux start. *****/
56    +#include <linux/tomoyo.h>
57    +/***** TOMOYO Linux end. *****/
58    
59     #include "proto.h"
60    
61    @@ -268,6 +271,10 @@ do_sys_ptrace(long request, long pid, lo
62            unsigned long tmp;
63            size_t copied;
64            long ret;
65    +       /***** TOMOYO Linux start. *****/
66    +       if (!ccs_capable(CCS_SYS_PTRACE))
67    +               return -EPERM;
68    +       /***** TOMOYO Linux end. *****/
69    
70            lock_kernel();
71            DBG(DBG_MEM, ("request=%ld pid=%ld addr=0x%lx data=0x%lx\n",
72    --- linux-2.6.21.7.orig/arch/ia64/ia32/sys_ia32.c
73    +++ 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 @@
98     #ifdef CONFIG_PERFMON
99     #include <asm/perfmon.h>
100     #endif
101    +/***** TOMOYO Linux start. *****/
102    +#include <linux/tomoyo.h>
103    +/***** TOMOYO Linux end. *****/
104    
105     #include "entry.h"
106    
107    @@ -1418,6 +1421,10 @@ sys_ptrace (long request, pid_t pid, uns
108            struct task_struct *child;
109            struct switch_stack *sw;
110            long ret;
111    +       /***** TOMOYO Linux start. *****/
112    +       if (!ccs_capable(CCS_SYS_PTRACE))
113    +               return -EPERM;
114    +       /***** TOMOYO Linux end. *****/
115    
116            lock_kernel();
117            ret = -EPERM;
118    --- linux-2.6.21.7.orig/arch/m32r/kernel/ptrace.c
119    +++ linux-2.6.21.7/arch/m32r/kernel/ptrace.c
120    @@ -32,6 +32,9 @@
121     #include <asm/system.h>
122     #include <asm/processor.h>
123     #include <asm/mmu_context.h>
124    +/***** TOMOYO Linux start. *****/
125    +#include <linux/tomoyo.h>
126    +/***** TOMOYO Linux end. *****/
127    
128     /*
129      * This routine will get a word off of the process kernel stack.
130    @@ -742,6 +745,10 @@ asmlinkage long sys_ptrace(long request,
131     {
132            struct task_struct *child;
133            int ret;
134    +       /***** TOMOYO Linux start. *****/
135    +       if (!ccs_capable(CCS_SYS_PTRACE))
136    +               return -EPERM;
137    +       /***** 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. *****/
184    
185            lock_kernel();
186            if (request == PTRACE_TRACEME) {
187    --- linux-2.6.21.7.orig/arch/s390/kernel/ptrace.c
188    +++ linux-2.6.21.7/arch/s390/kernel/ptrace.c
189    @@ -41,6 +41,9 @@
190     #include <asm/system.h>
191     #include <asm/uaccess.h>
192     #include <asm/unistd.h>
193    +/***** TOMOYO Linux start. *****/
194    +#include <linux/tomoyo.h>
195    +/***** TOMOYO Linux end. *****/
196    
197     #ifdef CONFIG_COMPAT
198     #include "compat_ptrace.h"
199    @@ -713,6 +716,10 @@ sys_ptrace(long request, long pid, long
200            struct task_struct *child;
201            int ret;
202    
203    +       /***** TOMOYO Linux start. *****/
204    +       if (!ccs_capable(CCS_SYS_PTRACE))
205    +               return -EPERM;
206    +       /***** TOMOYO Linux end. *****/
207            lock_kernel();
208            if (request == PTRACE_TRACEME) {
209                     ret = ptrace_traceme();
210    --- linux-2.6.21.7.orig/arch/sparc/kernel/ptrace.c
211    +++ linux-2.6.21.7/arch/sparc/kernel/ptrace.c
212    @@ -23,6 +23,9 @@
213     #include <asm/pgtable.h>
214     #include <asm/system.h>
215     #include <asm/uaccess.h>
216    +/***** TOMOYO Linux start. *****/
217    +#include <linux/tomoyo.h>
218    +/***** TOMOYO Linux end. *****/
219    
220     #define MAGIC_CONSTANT 0x80000000
221    
222    @@ -267,6 +270,12 @@ asmlinkage void do_ptrace(struct pt_regs
223            unsigned long addr2 = regs->u_regs[UREG_I4];
224            struct task_struct *child;
225            int ret;
226    +       /***** TOMOYO Linux start. *****/
227    +       if (!ccs_capable(CCS_SYS_PTRACE)) {
228    +               pt_error_return(regs, EPERM);
229    +               return;
230    +       }
231    +       /***** TOMOYO Linux end. *****/
232    
233            lock_kernel();
234     #ifdef DEBUG_PTRACE
235    --- linux-2.6.21.7.orig/arch/sparc64/kernel/ptrace.c
236    +++ linux-2.6.21.7/arch/sparc64/kernel/ptrace.c
237    @@ -32,6 +32,9 @@
238     #include <asm/spitfire.h>
239     #include <asm/page.h>
240     #include <asm/cpudata.h>
241    +/***** TOMOYO Linux start. *****/
242    +#include <linux/tomoyo.h>
243    +/***** TOMOYO Linux end. *****/
244    
245     /* Returning from ptrace is a bit tricky because the syscall return
246      * low level code assumes any value returned which is negative and
247    @@ -176,6 +179,12 @@ asmlinkage void do_ptrace(struct pt_regs
248            unsigned long addr2 = regs->u_regs[UREG_I4];
249            struct task_struct *child;
250            int ret;
251    +       /***** TOMOYO Linux start. *****/
252    +       if (!ccs_capable(CCS_SYS_PTRACE)) {
253    +               pt_error_return(regs, EPERM);
254    +               return;
255    +       }
256    +       /***** TOMOYO Linux end. *****/
257    
258            if (test_thread_flag(TIF_32BIT)) {
259                    addr &= 0xffffffffUL;
260    --- linux-2.6.21.7.orig/arch/x86_64/ia32/ptrace32.c
261    +++ 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 21  diff -ubBpEr linux-2.6.21/fs/Kconfig lin Line 290  diff -ubBpEr linux-2.6.21/fs/Kconfig lin
290  +  +
291   endmenu   endmenu
292    
293  diff -ubBpEr linux-2.6.21/fs/Makefile linux-2.6.21-ccs/fs/Makefile  --- linux-2.6.21.7.orig/fs/Makefile
294  --- linux-2.6.21/fs/Makefile    2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/fs/Makefile
 +++ linux-2.6.21-ccs/fs/Makefile        2007-04-28 04:02:47.000000000 +0900  
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  diff -ubBpEr linux-2.6.21/fs/attr.c linux-2.6.21-ccs/fs/attr.c  --- linux-2.6.21.7.orig/fs/attr.c
302  --- linux-2.6.21/fs/attr.c      2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/fs/attr.c
 +++ linux-2.6.21-ccs/fs/attr.c  2007-04-28 04:02:47.000000000 +0900  
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 43  diff -ubBpEr linux-2.6.21/fs/attr.c linu Line 310  diff -ubBpEr linux-2.6.21/fs/attr.c linu
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 58  diff -ubBpEr linux-2.6.21/fs/attr.c linu Line 329  diff -ubBpEr linux-2.6.21/fs/attr.c linu
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  diff -ubBpEr linux-2.6.21/fs/compat.c linux-2.6.21-ccs/fs/compat.c  --- linux-2.6.21.7.orig/fs/compat.c
343  --- linux-2.6.21/fs/compat.c    2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/fs/compat.c
 +++ linux-2.6.21-ccs/fs/compat.c        2007-04-28 04:02:47.000000000 +0900  
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 77  diff -ubBpEr linux-2.6.21/fs/compat.c li Line 351  diff -ubBpEr linux-2.6.21/fs/compat.c li
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    
382  -       retval = search_binary_handler(bprm, regs);  -       retval = search_binary_handler(bprm, regs);
383  +       retval = search_binary_handler_with_transition(bprm, regs);  +       retval = ccs_search_binary_handler(bprm, regs);
384          if (retval >= 0) {          if (retval >= 0) {
385                  free_arg_pages(bprm);                  free_arg_pages(bprm);
386    
387  diff -ubBpEr linux-2.6.21/fs/exec.c linux-2.6.21-ccs/fs/exec.c  --- linux-2.6.21.7.orig/fs/exec.c
388  --- linux-2.6.21/fs/exec.c      2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/fs/exec.c
 +++ linux-2.6.21-ccs/fs/exec.c  2007-04-28 04:02:47.000000000 +0900  
389  @@ -58,6 +58,10 @@  @@ -58,6 +58,10 @@
390   #include <linux/kmod.h>   #include <linux/kmod.h>
391   #endif   #endif
# Line 110  diff -ubBpEr linux-2.6.21/fs/exec.c linu Line 397  diff -ubBpEr linux-2.6.21/fs/exec.c linu
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 = ccs_search_binary_handler(bprm, regs);
434          if (retval >= 0) {          if (retval >= 0) {
435                  free_arg_pages(bprm);                  free_arg_pages(bprm);
436    
437  diff -ubBpEr linux-2.6.21/fs/fcntl.c linux-2.6.21-ccs/fs/fcntl.c  --- linux-2.6.21.7.orig/fs/fcntl.c
438  --- linux-2.6.21/fs/fcntl.c     2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/fs/fcntl.c
 +++ linux-2.6.21-ccs/fs/fcntl.c 2007-04-28 04:02:47.000000000 +0900  
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 154  diff -ubBpEr linux-2.6.21/fs/fcntl.c lin Line 446  diff -ubBpEr linux-2.6.21/fs/fcntl.c lin
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  diff -ubBpEr linux-2.6.21/fs/ioctl.c linux-2.6.21-ccs/fs/ioctl.c  --- linux-2.6.21.7.orig/fs/ioctl.c
463  --- linux-2.6.21/fs/ioctl.c     2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/fs/ioctl.c
 +++ linux-2.6.21-ccs/fs/ioctl.c 2007-04-28 04:02:47.000000000 +0900  
464  @@ -15,6 +15,9 @@  @@ -15,6 +15,9 @@
465    
466   #include <asm/uaccess.h>   #include <asm/uaccess.h>
# Line 178  diff -ubBpEr linux-2.6.21/fs/ioctl.c lin Line 471  diff -ubBpEr linux-2.6.21/fs/ioctl.c lin
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  diff -ubBpEr linux-2.6.21/fs/namei.c linux-2.6.21-ccs/fs/namei.c  @@ -167,6 +174,10 @@ asmlinkage long sys_ioctl(unsigned int f
486  --- linux-2.6.21/fs/namei.c     2007-04-28 04:02:41.000000000 +0900                  goto out;
487  +++ linux-2.6.21-ccs/fs/namei.c 2007-04-28 04:02:47.000000000 +0900  
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 202  diff -ubBpEr linux-2.6.21/fs/namei.c lin Line 506  diff -ubBpEr linux-2.6.21/fs/namei.c lin
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  +    /***** TOMOYO Linux end. *****/  +       if (error)
517    +               return error;
518    +       /***** 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, nd->mnt,
529    +                                          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 234  diff -ubBpEr linux-2.6.21/fs/namei.c lin Line 542  diff -ubBpEr linux-2.6.21/fs/namei.c lin
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.dentry->d_inode, dentry,
551  +       if (S_ISBLK(mode) && CheckCapabilityACL(TOMOYO_CREATE_BLOCK_DEV)) return -EPERM;  +                                                  nd.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))  
 diff -ubBpEr linux-2.6.21/fs/namespace.c linux-2.6.21-ccs/fs/namespace.c  
 --- linux-2.6.21/fs/namespace.c 2007-04-28 04:02:41.000000000 +0900  
 +++ linux-2.6.21-ccs/fs/namespace.c     2007-04-28 04:02:47.000000000 +0900  
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 383  diff -ubBpEr linux-2.6.21/fs/namespace.c Line 642  diff -ubBpEr linux-2.6.21/fs/namespace.c
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 (CheckMountPermission(dev_name, dir_name, type_page, &flags)) return -EPERM;  +       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  diff -ubBpEr linux-2.6.21/fs/open.c linux-2.6.21-ccs/fs/open.c  --- linux-2.6.21.7.orig/fs/open.c
745  --- linux-2.6.21/fs/open.c      2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/fs/open.c
 +++ linux-2.6.21-ccs/fs/open.c  2007-04-28 04:02:47.000000000 +0900  
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 487  diff -ubBpEr linux-2.6.21/fs/open.c linu Line 756  diff -ubBpEr linux-2.6.21/fs/open.c linu
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  diff -ubBpEr linux-2.6.21/fs/proc/Makefile linux-2.6.21-ccs/fs/proc/Makefile  --- linux-2.6.21.7.orig/fs/proc/Makefile
810  --- linux-2.6.21/fs/proc/Makefile       2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/fs/proc/Makefile
 +++ linux-2.6.21-ccs/fs/proc/Makefile   2007-04-28 04:02:47.000000000 +0900  
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 540  diff -ubBpEr linux-2.6.21/fs/proc/Makefi Line 815  diff -ubBpEr linux-2.6.21/fs/proc/Makefi
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  diff -ubBpEr linux-2.6.21/fs/proc/proc_misc.c linux-2.6.21-ccs/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    2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/fs/proc/proc_misc.c
820  +++ linux-2.6.21-ccs/fs/proc/proc_misc.c        2007-07-10 09:03:54.000000000 +0900  @@ -747,4 +747,9 @@ void __init proc_misc_init(void)
 @@ -747,4 +747,13 @@ 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 2007/08/14\n");  
 +       }  
827  +#endif  +#endif
828  +       /***** CCS end. *****/  +       /***** CCS end. *****/
829   }   }
830  diff -ubBpEr linux-2.6.21/include/linux/init_task.h linux-2.6.21-ccs/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      2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/include/linux/init_task.h
 +++ linux-2.6.21-ccs/include/linux/init_task.h  2007-04-28 04:02:47.000000000 +0900  
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  diff -ubBpEr linux-2.6.21/include/linux/sched.h linux-2.6.21-ccs/include/linux/sched.h  --- linux-2.6.21.7.orig/include/linux/sched.h
844  --- linux-2.6.21/include/linux/sched.h  2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/include/linux/sched.h
845  +++ linux-2.6.21-ccs/include/linux/sched.h      2007-04-28 04:02:47.000000000 +0900  @@ -27,6 +27,10 @@
 @@ -27,6 +27,11 @@  
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  diff -ubBpEr linux-2.6.21/kernel/compat.c linux-2.6.21-ccs/kernel/compat.c  --- linux-2.6.21.7.orig/kernel/compat.c
868  --- linux-2.6.21/kernel/compat.c        2007-04-26 12:08:32.000000000 +0900  +++ linux-2.6.21.7/kernel/compat.c
 +++ linux-2.6.21-ccs/kernel/compat.c    2007-07-10 09:02:19.000000000 +0900  
869  @@ -25,6 +25,9 @@  @@ -25,6 +25,9 @@
870   #include <linux/posix-timers.h>   #include <linux/posix-timers.h>
871    
# Line 610  diff -ubBpEr linux-2.6.21/kernel/compat. Line 876  diff -ubBpEr linux-2.6.21/kernel/compat.
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  diff -ubBpEr linux-2.6.21/kernel/kexec.c linux-2.6.21-ccs/kernel/kexec.c  --- linux-2.6.21.7.orig/kernel/kexec.c
891  --- linux-2.6.21/kernel/kexec.c 2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/kernel/kexec.c
 +++ linux-2.6.21-ccs/kernel/kexec.c     2007-04-28 04:02:47.000000000 +0900  
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 633  diff -ubBpEr linux-2.6.21/kernel/kexec.c Line 899  diff -ubBpEr linux-2.6.21/kernel/kexec.c
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  diff -ubBpEr linux-2.6.21/kernel/kmod.c linux-2.6.21-ccs/kernel/kmod.c  --- linux-2.6.21.7.orig/kernel/kmod.c
914  --- linux-2.6.21/kernel/kmod.c  2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/kernel/kmod.c
 +++ linux-2.6.21-ccs/kernel/kmod.c      2007-05-16 14:30:01.000000000 +0900  
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  diff -ubBpEr linux-2.6.21/kernel/module.c linux-2.6.21-ccs/kernel/module.c  --- linux-2.6.21.7.orig/kernel/module.c
928  --- linux-2.6.21/kernel/module.c        2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/kernel/module.c
 +++ linux-2.6.21-ccs/kernel/module.c    2007-04-28 04:02:47.000000000 +0900  
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 671  diff -ubBpEr linux-2.6.21/kernel/module. Line 936  diff -ubBpEr linux-2.6.21/kernel/module.
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  diff -ubBpEr linux-2.6.21/kernel/sched.c linux-2.6.21-ccs/kernel/sched.c  --- linux-2.6.21.7.orig/kernel/ptrace.c
962  --- linux-2.6.21/kernel/sched.c 2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/kernel/ptrace.c
963  +++ linux-2.6.21-ccs/kernel/sched.c     2007-04-28 04:02:47.000000000 +0900  @@ -21,6 +21,9 @@
964    
965     #include <asm/pgtable.h>
966     #include <asm/uaccess.h>
967    +/***** TOMOYO Linux start. *****/
968    +#include <linux/tomoyo.h>
969    +/***** TOMOYO Linux end. *****/
970    
971     /*
972      * ptrace a task: make the debugger its new parent and
973    @@ -456,6 +459,10 @@ asmlinkage long sys_ptrace(long request,
974            /*
975             * This lock_kernel fixes a subtle race with suid exec
976             */
977    +       /***** TOMOYO Linux start. *****/
978    +       if (!ccs_capable(CCS_SYS_PTRACE))
979    +               return -EPERM;
980    +       /***** TOMOYO Linux end. *****/
981            lock_kernel();
982            if (request == PTRACE_TRACEME) {
983                    ret = ptrace_traceme();
984    --- linux-2.6.21.7.orig/kernel/sched.c
985    +++ 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 704  diff -ubBpEr linux-2.6.21/kernel/sched.c Line 993  diff -ubBpEr linux-2.6.21/kernel/sched.c
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  diff -ubBpEr linux-2.6.21/kernel/signal.c linux-2.6.21-ccs/kernel/signal.c  --- linux-2.6.21.7.orig/kernel/signal.c
1008  --- linux-2.6.21/kernel/signal.c        2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/kernel/signal.c
 +++ linux-2.6.21-ccs/kernel/signal.c    2007-04-28 04:02:47.000000000 +0900  
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 727  diff -ubBpEr linux-2.6.21/kernel/signal. Line 1016  diff -ubBpEr linux-2.6.21/kernel/signal.
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  diff -ubBpEr linux-2.6.21/kernel/sys.c linux-2.6.21-ccs/kernel/sys.c  --- linux-2.6.21.7.orig/kernel/sys.c
1059  --- linux-2.6.21/kernel/sys.c   2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/kernel/sys.c
 +++ linux-2.6.21-ccs/kernel/sys.c       2007-04-28 04:02:47.000000000 +0900  
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 773  diff -ubBpEr linux-2.6.21/kernel/sys.c l Line 1067  diff -ubBpEr linux-2.6.21/kernel/sys.c l
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  diff -ubBpEr linux-2.6.21/kernel/sysctl.c linux-2.6.21-ccs/kernel/sysctl.c  --- linux-2.6.21.7.orig/kernel/sysctl.c
1117  --- linux-2.6.21/kernel/sysctl.c        2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/kernel/sysctl.c
 +++ linux-2.6.21-ccs/kernel/sysctl.c    2007-04-28 04:02:47.000000000 +0900  
1118  @@ -48,6 +48,9 @@  @@ -48,6 +48,9 @@
1119    
1120   #include <asm/uaccess.h>   #include <asm/uaccess.h>
# Line 826  diff -ubBpEr linux-2.6.21/kernel/sysctl. Line 1125  diff -ubBpEr linux-2.6.21/kernel/sysctl.
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,7 @@ struct ctl_table_header *sysctl_head_nex
1129   }   }
1130    
1131   #ifdef CONFIG_SYSCTL_SYSCALL   #ifdef CONFIG_SYSCTL_SYSCALL
1132  +  +
 +/***** TOMOYO Linux start. *****/  
 +static int try_parse_table(int __user *name, int nlen, void __user *oldval, void __user *newval, ctl_table *table)  
 +{  
 +       int n;  
 +       int error = -ENOMEM;  
 +       int op = 0;  
 +       char *buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);  
 +       if (oldval) op |= 004;  
 +       if (newval) op |= 002;  
 +       if (!op) { /* Neither read nor write */  
 +               error = 0;  
 +               goto out;  
 +       }  
 +       if (!buffer) goto out;  
 +       memset(buffer, 0, PAGE_SIZE);  
 +       snprintf(buffer, PAGE_SIZE - 1, "/proc/sys");  
 + repeat:  
 +       if (!nlen) {  
 +               error = -ENOTDIR;  
 +               goto out;  
 +       }  
 +       if (get_user(n, name)) {  
 +               error = -EFAULT;  
 +               goto out;  
 +       }  
 +       for ( ; table->ctl_name || table->procname; table++) {  
 +               if (n == table->ctl_name && n) {  
 +                       int pos = strlen(buffer);  
 +                       const char *cp = table->procname;  
 +                       error = -ENOMEM;  
 +                       if (cp) {  
 +                               if (pos + 1 >= PAGE_SIZE - 1) goto out;  
 +                               buffer[pos++] = '/';  
 +                               while (*cp) {  
 +                                       const unsigned char c = * (const unsigned char *) cp;  
 +                                       if (c == '\\') {  
 +                                               if (pos + 2 >= PAGE_SIZE - 1) goto out;  
 +                                               buffer[pos++] = '\\';  
 +                                               buffer[pos++] = '\\';  
 +                                       } else if (c > ' ' && c < 127) {  
 +                                               if (pos + 1 >= PAGE_SIZE - 1) goto out;  
 +                                               buffer[pos++] = c;  
 +                                       } else {  
 +                                               if (pos + 4 >= PAGE_SIZE - 1) goto out;  
 +                                               buffer[pos++] = '\\';  
 +                                               buffer[pos++] = (c >> 6) + '0';  
 +                                               buffer[pos++] = ((c >> 3) & 7) + '0';  
 +                                               buffer[pos++] = (c & 7) + '0';  
 +                                       }  
 +                                       cp++;  
 +                               }  
 +                       } else {  
 +                               /* Assume nobody assigns "=\$=" for procname. */  
 +                               snprintf(buffer + pos, PAGE_SIZE - pos - 1, "/=%d=", n);  
 +                               if (memchr(buffer, '\0', PAGE_SIZE - 2) == NULL) goto out;  
 +                       }  
 +                       if (table->child) {  
 +                               name++;  
 +                               nlen--;  
 +                               table = table->child;  
 +                               goto repeat;  
 +                       }  
 +                       /* printk("sysctl='%s'\n", buffer); */  
 +                       error = CheckFilePerm(buffer, op, "sysctl");  
 +                       goto out;  
 +               }  
 +       }  
 +       error = -ENOTDIR;  
 + out:  
 +       kfree(buffer);  
 +       return error;  
 +}  
 +/***** TOMOYO Linux end. *****/  
 +  
1133   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,
1134                 void __user *newval, size_t newlen)                 void __user *newval, size_t newlen)
1135   {   {
1136  @@ -1104,6 +1182,9 @@ int do_sysctl(int __user *name, int nlen  @@ -1104,6 +1108,11 @@ int do_sysctl(int __user *name, int nlen
1137    
1138          for (head = sysctl_head_next(NULL); head;          for (head = sysctl_head_next(NULL); head;
1139                          head = sysctl_head_next(head)) {                          head = sysctl_head_next(head)) {
1140  +               /***** TOMOYO Linux start. *****/  +               /***** TOMOYO Linux start. *****/
1141  +               if ((error = try_parse_table(name, nlen, oldval, newval, head->ctl_table)) == 0)  +               error = ccs_parse_table(name, nlen, oldval, newval,
1142    +                                       head->ctl_table);
1143    +               if (!error)
1144  +               /***** TOMOYO Linux end. *****/  +               /***** TOMOYO Linux end. *****/
1145                  error = parse_table(name, nlen, oldval, oldlenp,                  error = parse_table(name, nlen, oldval, oldlenp,
1146                                          newval, newlen, head->ctl_table);                                          newval, newlen, head->ctl_table);
1147                  if (error != -ENOTDIR) {                  if (error != -ENOTDIR) {
1148  diff -ubBpEr linux-2.6.21/kernel/time/ntp.c linux-2.6.21-ccs/kernel/time/ntp.c  --- linux-2.6.21.7.orig/kernel/time.c
1149  --- linux-2.6.21/kernel/time/ntp.c      2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/kernel/time.c
 +++ linux-2.6.21-ccs/kernel/time/ntp.c  2007-04-28 04:02:47.000000000 +0900  
 @@ -14,6 +14,9 @@  
   
  #include <asm/div64.h>  
  #include <asm/timex.h>  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
   
  /*  
   * Timekeeping variables  
 @@ -203,6 +206,9 @@ int do_adjtimex(struct timex *txc)  
         /* In order to modify anything, you gotta be super-user! */  
         if (txc->modes && !capable(CAP_SYS_TIME))  
                 return -EPERM;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (txc->modes && CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         /* Now we validate the data before disabling interrupts */  
   
 diff -ubBpEr linux-2.6.21/kernel/time.c linux-2.6.21-ccs/kernel/time.c  
 --- linux-2.6.21/kernel/time.c  2007-04-28 04:02:41.000000000 +0900  
 +++ linux-2.6.21-ccs/kernel/time.c      2007-04-28 04:02:47.000000000 +0900  
1150  @@ -39,6 +39,9 @@  @@ -39,6 +39,9 @@
1151    
1152   #include <asm/uaccess.h>   #include <asm/uaccess.h>
# Line 954  diff -ubBpEr linux-2.6.21/kernel/time.c Line 1157  diff -ubBpEr linux-2.6.21/kernel/time.c
1157    
1158   /*   /*
1159    * 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
1160  @@ -91,6 +94,9 @@ asmlinkage long sys_stime(time_t __user  @@ -91,6 +94,10 @@ asmlinkage long sys_stime(time_t __user
1161          err = security_settime(&tv, NULL);          err = security_settime(&tv, NULL);
1162          if (err)          if (err)
1163                  return err;                  return err;
1164  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1165  +       if (CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_SETTIME))
1166    +               return -EPERM;
1167  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1168    
1169          do_settimeofday(&tv);          do_settimeofday(&tv);
1170          return 0;          return 0;
1171  @@ -161,6 +167,9 @@ int do_sys_settimeofday(struct timespec  @@ -161,6 +168,10 @@ int do_sys_settimeofday(struct timespec
1172          error = security_settime(tv, tz);          error = security_settime(tv, tz);
1173          if (error)          if (error)
1174                  return error;                  return error;
1175  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1176  +       if (CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM;  +       if (!ccs_capable(CCS_SYS_SETTIME))
1177    +               return -EPERM;
1178  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1179    
1180          if (tz) {          if (tz) {
1181                  /* SMP safe, global irq locking makes it work. */                  /* SMP safe, global irq locking makes it work. */
1182  diff -ubBpEr linux-2.6.21/net/core/datagram.c linux-2.6.21-ccs/net/core/datagram.c  --- linux-2.6.21.7.orig/kernel/time/ntp.c
1183  --- linux-2.6.21/net/core/datagram.c    2007-04-26 12:08:32.000000000 +0900  +++ linux-2.6.21.7/kernel/time/ntp.c
1184  +++ linux-2.6.21-ccs/net/core/datagram.c        2007-08-14 10:55:26.000000000 +0900  @@ -14,6 +14,9 @@
1185    
1186     #include <asm/div64.h>
1187     #include <asm/timex.h>
1188    +/***** TOMOYO Linux start. *****/
1189    +#include <linux/tomoyo.h>
1190    +/***** TOMOYO Linux end. *****/
1191    
1192     /*
1193      * Timekeeping variables
1194    @@ -201,6 +204,10 @@ int do_adjtimex(struct timex *txc)
1195            /* In order to modify anything, you gotta be super-user! */
1196            if (txc->modes && !capable(CAP_SYS_TIME))
1197                    return -EPERM;
1198    +       /***** TOMOYO Linux start. *****/
1199    +       if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
1200    +               return -EPERM;
1201    +       /***** TOMOYO Linux end. *****/
1202    
1203            /* Now we validate the data before disabling interrupts */
1204    
1205    --- linux-2.6.21.7.orig/net/core/datagram.c
1206    +++ linux-2.6.21.7/net/core/datagram.c
1207  @@ -56,6 +56,11 @@  @@ -56,6 +56,11 @@
1208   #include <net/sock.h>   #include <net/sock.h>
1209   #include <net/tcp_states.h>   #include <net/tcp_states.h>
# Line 989  diff -ubBpEr linux-2.6.21/net/core/datag Line 1216  diff -ubBpEr linux-2.6.21/net/core/datag
1216   /*   /*
1217    *     Is a socket 'connection oriented' ?    *     Is a socket 'connection oriented' ?
1218    */    */
1219  @@ -178,6 +183,14 @@ struct sk_buff *skb_recv_datagram(struct  @@ -178,6 +183,12 @@ struct sk_buff *skb_recv_datagram(struct
1220                  } else                  } else
1221                          skb = skb_dequeue(&sk->sk_receive_queue);                          skb = skb_dequeue(&sk->sk_receive_queue);
1222    
1223  +                /***** TOMOYO Linux start. *****/  +               /***** TOMOYO Linux start. *****/
1224  +                error = CheckSocketRecvDatagramPermission(sk, skb);  +               error = ccs_socket_recv_datagram_permission(sk, skb, flags);
1225  +                if (error) {  +               if (error)
1226  +                        skb_kill_datagram(sk, skb, flags);  +                       goto no_packet;
1227  +                        goto no_packet;  +               /***** TOMOYO Linux end. *****/
 +                }  
 +                /***** TOMOYO Linux end. *****/  
1228  +  +
1229                  if (skb)                  if (skb)
1230                          return skb;                          return skb;
1231    
1232  diff -ubBpEr linux-2.6.21/net/ipv4/inet_connection_sock.c linux-2.6.21-ccs/net/ipv4/inet_connection_sock.c  --- linux-2.6.21.7.orig/net/ipv4/inet_connection_sock.c
1233  --- linux-2.6.21/net/ipv4/inet_connection_sock.c        2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/net/ipv4/inet_connection_sock.c
 +++ linux-2.6.21-ccs/net/ipv4/inet_connection_sock.c    2007-04-28 04:02:47.000000000 +0900  
1234  @@ -23,6 +23,9 @@  @@ -23,6 +23,9 @@
1235   #include <net/route.h>   #include <net/route.h>
1236   #include <net/tcp_states.h>   #include <net/tcp_states.h>
# Line 1017  diff -ubBpEr linux-2.6.21/net/ipv4/inet_ Line 1241  diff -ubBpEr linux-2.6.21/net/ipv4/inet_
1241    
1242   #ifdef INET_CSK_DEBUG   #ifdef INET_CSK_DEBUG
1243   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";
1244  @@ -87,6 +90,9 @@ int inet_csk_get_port(struct inet_hashin  @@ -85,6 +88,10 @@ int inet_csk_get_port(struct inet_hashin
1245                  do {                  do {
1246                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
1247                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1248  +                       /***** SAKURA Linux start. *****/  +                       /***** SAKURA Linux start. *****/
1249  +                       if (SAKURA_MayAutobind(rover) < 0) goto next;  +                       if (ccs_lport_reserved(rover))
1250    +                               goto next;
1251  +                       /***** SAKURA Linux end. *****/  +                       /***** SAKURA Linux end. *****/
1252                          inet_bind_bucket_for_each(tb, node, &head->chain)                          inet_bind_bucket_for_each(tb, node, &head->chain)
1253                                  if (tb->port == rover)                                  if (tb->port == rover)
1254                                          goto next;                                          goto next;
1255  diff -ubBpEr linux-2.6.21/net/ipv4/inet_hashtables.c linux-2.6.21-ccs/net/ipv4/inet_hashtables.c  --- linux-2.6.21.7.orig/net/ipv4/inet_hashtables.c
1256  --- linux-2.6.21/net/ipv4/inet_hashtables.c     2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/net/ipv4/inet_hashtables.c
 +++ linux-2.6.21-ccs/net/ipv4/inet_hashtables.c 2007-04-28 04:02:47.000000000 +0900  
1257  @@ -22,6 +22,9 @@  @@ -22,6 +22,9 @@
1258   #include <net/inet_connection_sock.h>   #include <net/inet_connection_sock.h>
1259   #include <net/inet_hashtables.h>   #include <net/inet_hashtables.h>
# Line 1040  diff -ubBpEr linux-2.6.21/net/ipv4/inet_ Line 1264  diff -ubBpEr linux-2.6.21/net/ipv4/inet_
1264    
1265   /*   /*
1266    * Allocate and initialize a new local port bind bucket.    * Allocate and initialize a new local port bind bucket.
1267  @@ -292,6 +295,9 @@ int inet_hash_connect(struct inet_timewa  @@ -292,6 +295,10 @@ int inet_hash_connect(struct inet_timewa
1268                  local_bh_disable();                  local_bh_disable();
1269                  for (i = 1; i <= range; i++) {                  for (i = 1; i <= range; i++) {
1270                          port = low + (i + offset) % range;                          port = low + (i + offset) % range;
1271  +                       /***** SAKURA Linux start. *****/  +                       /***** SAKURA Linux start. *****/
1272  +                       if (SAKURA_MayAutobind(port) < 0) continue;  +                       if (ccs_lport_reserved(port))
1273    +                               continue;
1274  +                       /***** SAKURA Linux end. *****/  +                       /***** SAKURA Linux end. *****/
1275                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
1276                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1277    
1278  diff -ubBpEr linux-2.6.21/net/ipv4/udp.c linux-2.6.21-ccs/net/ipv4/udp.c  --- linux-2.6.21.7.orig/net/ipv4/udp.c
1279  --- linux-2.6.21/net/ipv4/udp.c 2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/net/ipv4/udp.c
 +++ linux-2.6.21-ccs/net/ipv4/udp.c     2007-05-23 14:50:12.000000000 +0900  
1280  @@ -102,6 +102,9 @@  @@ -102,6 +102,9 @@
1281   #include <net/checksum.h>   #include <net/checksum.h>
1282   #include <net/xfrm.h>   #include <net/xfrm.h>
# Line 1063  diff -ubBpEr linux-2.6.21/net/ipv4/udp.c Line 1287  diff -ubBpEr linux-2.6.21/net/ipv4/udp.c
1287    
1288   /*   /*
1289    *     Snmp MIB for the UDP layer    *     Snmp MIB for the UDP layer
1290  @@ -162,6 +165,9 @@ int __udp_lib_get_port(struct sock *sk,  @@ -162,6 +165,10 @@ int __udp_lib_get_port(struct sock *sk,
1291                                          result = sysctl_local_port_range[0] +                                          result = sysctl_local_port_range[0] +
1292                                                  ((result - sysctl_local_port_range[0]) &                                                  ((result - sysctl_local_port_range[0]) &
1293                                                   (UDP_HTABLE_SIZE - 1));                                                   (UDP_HTABLE_SIZE - 1));
1294  +                               /***** SAKURA Linux start. *****/  +                               /***** SAKURA Linux start. *****/
1295  +                               if (SAKURA_MayAutobind(result) < 0) continue;  +                               if (ccs_lport_reserved(result))
1296    +                                       continue;
1297  +                               /***** SAKURA Linux end. *****/  +                               /***** SAKURA Linux end. *****/
1298                                  goto gotit;                                  goto gotit;
1299                          }                          }
1300                          size = 0;                          size = 0;
1301  @@ -180,6 +186,9 @@ int __udp_lib_get_port(struct sock *sk,  @@ -180,6 +187,10 @@ int __udp_lib_get_port(struct sock *sk,
1302                                  result = sysctl_local_port_range[0]                                  result = sysctl_local_port_range[0]
1303                                          + ((result - sysctl_local_port_range[0]) &                                          + ((result - sysctl_local_port_range[0]) &
1304                                             (UDP_HTABLE_SIZE - 1));                                             (UDP_HTABLE_SIZE - 1));
1305  +                       /***** SAKURA Linux start. *****/  +                       /***** SAKURA Linux start. *****/
1306  +                       if (SAKURA_MayAutobind(result) < 0) continue;  +                       if (ccs_lport_reserved(result))
1307    +                               continue;
1308  +                       /***** SAKURA Linux end. *****/  +                       /***** SAKURA Linux end. *****/
1309                          if (! __udp_lib_lport_inuse(result, udptable))                          if (! __udp_lib_lport_inuse(result, udptable))
1310                                  break;                                  break;
1311                  }                  }
1312  diff -ubBpEr linux-2.6.21/net/ipv6/inet6_hashtables.c linux-2.6.21-ccs/net/ipv6/inet6_hashtables.c  --- linux-2.6.21.7.orig/net/ipv6/inet6_hashtables.c
1313  --- linux-2.6.21/net/ipv6/inet6_hashtables.c    2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/net/ipv6/inet6_hashtables.c
 +++ linux-2.6.21-ccs/net/ipv6/inet6_hashtables.c        2007-04-28 04:02:47.000000000 +0900  
1314  @@ -21,6 +21,9 @@  @@ -21,6 +21,9 @@
1315   #include <net/inet_hashtables.h>   #include <net/inet_hashtables.h>
1316   #include <net/inet6_hashtables.h>   #include <net/inet6_hashtables.h>
# Line 1096  diff -ubBpEr linux-2.6.21/net/ipv6/inet6 Line 1321  diff -ubBpEr linux-2.6.21/net/ipv6/inet6
1321    
1322   void __inet6_hash(struct inet_hashinfo *hashinfo,   void __inet6_hash(struct inet_hashinfo *hashinfo,
1323                                  struct sock *sk)                                  struct sock *sk)
1324  @@ -266,6 +269,9 @@ int inet6_hash_connect(struct inet_timew  @@ -266,6 +269,10 @@ int inet6_hash_connect(struct inet_timew
1325                  local_bh_disable();                  local_bh_disable();
1326                  for (i = 1; i <= range; i++) {                  for (i = 1; i <= range; i++) {
1327                          port = low + (i + offset) % range;                          port = low + (i + offset) % range;
1328  +                       /***** SAKURA Linux start. *****/  +                       /***** SAKURA Linux start. *****/
1329  +                       if (SAKURA_MayAutobind(port) < 0) continue;  +                       if (ccs_lport_reserved(port))
1330    +                               continue;
1331  +                       /***** SAKURA Linux end. *****/  +                       /***** SAKURA Linux end. *****/
1332                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
1333                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1334    
1335  diff -ubBpEr linux-2.6.21/net/socket.c linux-2.6.21-ccs/net/socket.c  --- linux-2.6.21.7.orig/net/socket.c
1336  --- linux-2.6.21/net/socket.c   2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/net/socket.c
 +++ linux-2.6.21-ccs/net/socket.c       2007-08-14 10:46:32.000000000 +0900  
1337  @@ -93,6 +93,11 @@  @@ -93,6 +93,11 @@
1338   #include <net/sock.h>   #include <net/sock.h>
1339   #include <linux/netfilter.h>   #include <linux/netfilter.h>
# Line 1121  diff -ubBpEr linux-2.6.21/net/socket.c l Line 1346  diff -ubBpEr linux-2.6.21/net/socket.c l
1346   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
1347   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,
1348                           unsigned long nr_segs, loff_t pos);                           unsigned long nr_segs, loff_t pos);
1349  @@ -549,6 +554,9 @@ static inline int __sock_sendmsg(struct  @@ -549,6 +554,12 @@ static inline int __sock_sendmsg(struct
1350          err = security_socket_sendmsg(sock, msg, size);          err = security_socket_sendmsg(sock, msg, size);
1351          if (err)          if (err)
1352                  return err;                  return err;
1353  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1354  +       if (CheckSocketSendMsgPermission(sock, (struct sockaddr *) msg->msg_name, msg->msg_namelen)) return -EPERM;  +       if (ccs_socket_sendmsg_permission(sock,
1355  +       /***** TOMOYO Linux start. *****/  +                                         (struct sockaddr *) msg->msg_name,
1356    +                                         msg->msg_namelen))
1357    +               return -EPERM;
1358    +       /***** TOMOYO Linux end. *****/
1359    
1360          return sock->ops->sendmsg(iocb, sock, msg, size);          return sock->ops->sendmsg(iocb, sock, msg, size);
1361   }   }
1362  @@ -1070,6 +1078,10 @@ static int __sock_create(int family, int  @@ -1070,6 +1081,12 @@ static int __sock_create(int family, int
1363                  family = PF_PACKET;                  family = PF_PACKET;
1364          }          }
1365    
1366  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1367  +       if ((err = CheckSocketCreatePermission(family, type, protocol)) < 0) return err;  +       err = ccs_socket_create_permission(family, type, protocol);
1368    +       if (err)
1369    +               return err;
1370  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1371  +  +
1372          err = security_socket_create(family, type, protocol, kern);          err = security_socket_create(family, type, protocol, kern);
1373          if (err)          if (err)
1374                  return err;                  return err;
1375  @@ -1298,6 +1310,9 @@ asmlinkage long sys_bind(int fd, struct  @@ -1298,6 +1315,13 @@ asmlinkage long sys_bind(int fd, struct
1376                          err = security_socket_bind(sock,                          err = security_socket_bind(sock,
1377                                                     (struct sockaddr *)address,                                                     (struct sockaddr *)address,
1378                                                     addrlen);                                                     addrlen);
1379  +                       /***** TOMOYO Linux start. *****/  +                       /***** TOMOYO Linux start. *****/
1380  +                       if (!err) err = CheckSocketBindPermission(sock, (struct sockaddr *) address, addrlen);  +                       if (!err)
1381    +                               err = ccs_socket_bind_permission(sock,
1382    +                                                        (struct sockaddr *)
1383    +                                                                address,
1384    +                                                                addrlen);
1385  +                       /***** TOMOYO Linux end. *****/  +                       /***** TOMOYO Linux end. *****/
1386                          if (!err)                          if (!err)
1387                                  err = sock->ops->bind(sock,                                  err = sock->ops->bind(sock,
1388                                                        (struct sockaddr *)                                                        (struct sockaddr *)
1389  @@ -1327,6 +1342,9 @@ asmlinkage long sys_listen(int fd, int b  @@ -1327,6 +1351,10 @@ asmlinkage long sys_listen(int fd, int b
1390                          backlog = sysctl_somaxconn;                          backlog = sysctl_somaxconn;
1391    
1392                  err = security_socket_listen(sock, backlog);                  err = security_socket_listen(sock, backlog);
1393  +               /***** TOMOYO Linux start. *****/  +               /***** TOMOYO Linux start. *****/
1394  +               if (!err) err = CheckSocketListenPermission(sock);  +               if (!err)
1395    +                       err = ccs_socket_listen_permission(sock);
1396  +               /***** TOMOYO Linux end. *****/  +               /***** TOMOYO Linux end. *****/
1397                  if (!err)                  if (!err)
1398                          err = sock->ops->listen(sock, backlog);                          err = sock->ops->listen(sock, backlog);
1399    
1400  @@ -1391,6 +1409,12 @@ asmlinkage long sys_accept(int fd, struc  @@ -1391,6 +1419,13 @@ asmlinkage long sys_accept(int fd, struc
1401          if (err < 0)          if (err < 0)
1402                  goto out_fd;                  goto out_fd;
1403    
1404  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1405  +       if (CheckSocketAcceptPermission(newsock, (struct sockaddr *) address)) {  +       if (ccs_socket_accept_permission(newsock,
1406    +                                        (struct sockaddr *) address)) {
1407  +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */  +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */
1408  +               goto out_fd;  +               goto out_fd;
1409  +       }  +       }
# Line 1175  diff -ubBpEr linux-2.6.21/net/socket.c l Line 1411  diff -ubBpEr linux-2.6.21/net/socket.c l
1411          if (upeer_sockaddr) {          if (upeer_sockaddr) {
1412                  if (newsock->ops->getname(newsock, (struct sockaddr *)address,                  if (newsock->ops->getname(newsock, (struct sockaddr *)address,
1413                                            &len, 2) < 0) {                                            &len, 2) < 0) {
1414  @@ -1455,6 +1479,10 @@ asmlinkage long sys_connect(int fd, stru  @@ -1455,6 +1490,12 @@ asmlinkage long sys_connect(int fd, stru
1415              security_socket_connect(sock, (struct sockaddr *)address, addrlen);              security_socket_connect(sock, (struct sockaddr *)address, addrlen);
1416          if (err)          if (err)
1417                  goto out_put;                  goto out_put;
1418  +       /***** TOMOYO Linux start. *****/  +       /***** TOMOYO Linux start. *****/
1419  +       err = CheckSocketConnectPermission(sock, (struct sockaddr *) address, addrlen);  +       err = ccs_socket_connect_permission(sock, (struct sockaddr *) address,
1420  +       if (err) goto out_put;  +                                           addrlen);
1421    +       if (err)
1422    +               goto out_put;
1423  +       /***** TOMOYO Linux end. *****/  +       /***** TOMOYO Linux end. *****/
1424    
1425          err = sock->ops->connect(sock, (struct sockaddr *)address, addrlen,          err = sock->ops->connect(sock, (struct sockaddr *)address, addrlen,
1426                                   sock->file->f_flags);                                   sock->file->f_flags);
1427  diff -ubBpEr linux-2.6.21/net/unix/af_unix.c linux-2.6.21-ccs/net/unix/af_unix.c  --- linux-2.6.21.7.orig/net/unix/af_unix.c
1428  --- linux-2.6.21/net/unix/af_unix.c     2007-04-28 04:02:41.000000000 +0900  +++ linux-2.6.21.7/net/unix/af_unix.c
 +++ linux-2.6.21-ccs/net/unix/af_unix.c 2007-04-28 04:02:47.000000000 +0900  
1429  @@ -116,6 +116,9 @@  @@ -116,6 +116,9 @@
1430   #include <linux/mount.h>   #include <linux/mount.h>
1431   #include <net/checksum.h>   #include <net/checksum.h>
# Line 1199  diff -ubBpEr linux-2.6.21/net/unix/af_un Line 1436  diff -ubBpEr linux-2.6.21/net/unix/af_un
1436    
1437   int sysctl_unix_max_dgram_qlen __read_mostly = 10;   int sysctl_unix_max_dgram_qlen __read_mostly = 10;
1438    
1439  @@ -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  
1440                   */                   */
1441                  mode = S_IFSOCK |                  mode = S_IFSOCK |
1442                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
1443  +               /***** TOMOYO Linux start. *****/  +               /***** TOMOYO Linux start. *****/
1444  +               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,
1445    +                                                nd.mnt, mode, 0);
1446    +               if (!err)
1447  +               /***** TOMOYO Linux end. *****/  +               /***** TOMOYO Linux end. *****/
1448                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
1449                  if (err)                  if (err)

Legend:
Removed from v.352  
changed lines
  Added in v.2300

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