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

Subversion リポジトリの参照

Diff of /trunk/1.8.x/ccs-patch/patches/ccs-patch-2.6.18-debian-etch.diff

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

trunk/1.6.x/ccs-patch/patches/ccs-patch-2.6.18-debian-etch.diff revision 1498 by kumaneko, Fri Aug 29 12:08:57 2008 UTC branches/ccs-patch/patches/ccs-patch-2.6.18-debian-etch.diff revision 3838 by kumaneko, Fri Jul 23 03:20:04 2010 UTC
# Line 2  This is TOMOYO Linux patch for Debian Et Line 2  This is TOMOYO Linux patch for Debian Et
2    
3  Source code for this patch is "apt-get install linux-source-2.6.18"  Source code for this patch is "apt-get install linux-source-2.6.18"
4  ---  ---
5   arch/alpha/kernel/ptrace.c      |    9 +++   arch/alpha/kernel/ptrace.c      |    3 +++
6   arch/ia64/ia32/sys_ia32.c       |    9 +++   arch/ia64/ia32/sys_ia32.c       |    3 +++
7   arch/ia64/kernel/ptrace.c       |    9 +++   arch/ia64/kernel/ptrace.c       |    3 +++
8   arch/m32r/kernel/ptrace.c       |    9 +++   arch/m32r/kernel/ptrace.c       |    3 +++
9   arch/mips/kernel/ptrace32.c     |    9 +++   arch/mips/kernel/ptrace32.c     |    3 +++
10   arch/powerpc/kernel/ptrace32.c  |    9 +++   arch/powerpc/kernel/ptrace32.c  |    3 +++
11   arch/s390/kernel/ptrace.c       |    9 +++   arch/s390/kernel/ptrace.c       |    3 +++
12   arch/sh64/kernel/ptrace.c       |    9 +++   arch/sparc/kernel/ptrace.c      |    5 +++++
13   arch/sparc/kernel/ptrace.c      |   11 +++   arch/sparc64/kernel/ptrace.c    |    5 +++++
14   arch/sparc64/kernel/ptrace.c    |   11 +++   arch/x86_64/ia32/ptrace32.c     |    3 +++
15   arch/x86_64/ia32/ptrace32.c     |    9 +++   fs/compat.c                     |    9 ++++++++-
16   fs/Kconfig                      |    2   fs/exec.c                       |   12 +++++++++++-
17   fs/Makefile                     |    2   fs/fcntl.c                      |    4 ++++
18   fs/attr.c                       |   19 ++++++   fs/ioctl.c                      |    5 +++++
19   fs/compat.c                     |   11 +++   fs/namei.c                      |   32 ++++++++++++++++++++++++++++++++
20   fs/exec.c                       |   21 ++++++-   fs/namespace.c                  |   21 ++++++++++++++++++++-
21   fs/fcntl.c                      |    9 +++   fs/open.c                       |   27 +++++++++++++++++++++++++++
22   fs/ioctl.c                      |    7 ++   fs/proc/proc_misc.c             |    1 +
23   fs/namei.c                      |  118 ++++++++++++++++++++++++++++++++++++++++   include/linux/init_task.h       |    9 +++++++++
24   fs/namespace.c                  |   50 ++++++++++++++++   include/linux/sched.h           |    6 ++++++
25   fs/open.c                       |   27 +++++++++   kernel/compat.c                 |    3 +++
26   fs/proc/Makefile                |    3 +   kernel/kexec.c                  |    3 +++
27   fs/proc/proc_misc.c             |    5 +   kernel/kmod.c                   |    5 +++++
28   include/linux/init_task.h       |    4 +   kernel/module.c                 |    7 +++++--
29   include/linux/sched.h           |    9 +++   kernel/ptrace.c                 |    3 +++
30   kernel/compat.c                 |    7 ++   kernel/sched.c                  |    3 +++
31   kernel/kexec.c                  |    7 ++   kernel/signal.c                 |    9 +++++++++
32   kernel/kmod.c                   |    5 +   kernel/sys.c                    |   11 +++++++++++
33   kernel/module.c                 |   13 +++-   kernel/sysctl.c                 |   11 +++++++++++
34   kernel/ptrace.c                 |    9 +++   kernel/time.c                   |    7 +++++++
35   kernel/sched.c                  |    7 ++   net/ipv4/inet_connection_sock.c |    3 +++
36   kernel/signal.c                 |   21 +++++++   net/ipv4/inet_hashtables.c      |    3 +++
37   kernel/sys.c                    |   21 +++++++   net/ipv4/raw.c                  |   12 +++++++++---
38   kernel/sysctl.c                 |  111 +++++++++++++++++++++++++++++++++++++   net/ipv4/udp.c                  |   16 ++++++++++++++--
39   kernel/time.c                   |   15 +++++   net/ipv6/inet6_hashtables.c     |    5 ++++-
40   net/core/datagram.c             |   11 +++   net/ipv6/raw.c                  |   12 +++++++++---
41   net/ipv4/inet_connection_sock.c |    7 ++   net/ipv6/udp.c                  |   14 +++++++++++++-
42   net/ipv4/inet_hashtables.c      |    7 ++   net/socket.c                    |   24 ++++++++++++++++++++++--
43   net/ipv4/udp.c                  |   11 +++   net/unix/af_unix.c              |    4 ++++
44   net/ipv6/inet6_hashtables.c     |    9 ++-   security/Kconfig                |    2 ++
45   net/ipv6/udp.c                  |   11 +++   security/Makefile               |    3 +++
46   net/socket.c                    |   43 +++++++++++++-   41 files changed, 303 insertions(+), 17 deletions(-)
  net/unix/af_unix.c              |   15 +++++  
  43 files changed, 712 insertions(+), 8 deletions(-)  
47    
48  --- linux-source-2.6.18-22.orig/arch/alpha/kernel/ptrace.c  --- linux-2.6.18-26etch2.orig/arch/alpha/kernel/ptrace.c
49  +++ linux-source-2.6.18-22/arch/alpha/kernel/ptrace.c  +++ linux-2.6.18-26etch2/arch/alpha/kernel/ptrace.c
50  @@ -20,6 +20,9 @@  @@ -20,6 +20,7 @@
51   #include <asm/pgtable.h>   #include <asm/pgtable.h>
52   #include <asm/system.h>   #include <asm/system.h>
53   #include <asm/fpu.h>   #include <asm/fpu.h>
54  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
55    
56   #include "proto.h"   #include "proto.h"
57    
58  @@ -268,6 +271,12 @@ do_sys_ptrace(long request, long pid, lo  @@ -268,6 +269,8 @@ do_sys_ptrace(long request, long pid, lo
59          unsigned long tmp;          unsigned long tmp;
60          size_t copied;          size_t copied;
61          long ret;          long ret;
62  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
63  +               return -EPERM;  +               return -EPERM;
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
64    
65          lock_kernel();          lock_kernel();
66          DBG(DBG_MEM, ("request=%ld pid=%ld addr=0x%lx data=0x%lx\n",          DBG(DBG_MEM, ("request=%ld pid=%ld addr=0x%lx data=0x%lx\n",
67  --- linux-source-2.6.18-22.orig/arch/ia64/ia32/sys_ia32.c  --- linux-2.6.18-26etch2.orig/arch/ia64/ia32/sys_ia32.c
68  +++ linux-source-2.6.18-22/arch/ia64/ia32/sys_ia32.c  +++ linux-2.6.18-26etch2/arch/ia64/ia32/sys_ia32.c
69  @@ -56,6 +56,9 @@  @@ -56,6 +56,7 @@
70   #include <asm/types.h>   #include <asm/types.h>
71   #include <asm/uaccess.h>   #include <asm/uaccess.h>
72   #include <asm/unistd.h>   #include <asm/unistd.h>
73  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
74    
75   #include "ia32priv.h"   #include "ia32priv.h"
76    
77  @@ -1741,6 +1744,12 @@ sys32_ptrace (int request, pid_t pid, un  @@ -1741,6 +1742,8 @@ sys32_ptrace (int request, pid_t pid, un
78          struct task_struct *child;          struct task_struct *child;
79          unsigned int value, tmp;          unsigned int value, tmp;
80          long i, ret;          long i, ret;
81  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
82  +               return -EPERM;  +               return -EPERM;
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
83    
84          lock_kernel();          lock_kernel();
85          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
86  --- linux-source-2.6.18-22.orig/arch/ia64/kernel/ptrace.c  --- linux-2.6.18-26etch2.orig/arch/ia64/kernel/ptrace.c
87  +++ linux-source-2.6.18-22/arch/ia64/kernel/ptrace.c  +++ linux-2.6.18-26etch2/arch/ia64/kernel/ptrace.c
88  @@ -28,6 +28,9 @@  @@ -28,6 +28,7 @@
89   #ifdef CONFIG_PERFMON   #ifdef CONFIG_PERFMON
90   #include <asm/perfmon.h>   #include <asm/perfmon.h>
91   #endif   #endif
92  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
93    
94   #include "entry.h"   #include "entry.h"
95    
96  @@ -1417,6 +1420,12 @@ sys_ptrace (long request, pid_t pid, uns  @@ -1417,6 +1418,8 @@ sys_ptrace (long request, pid_t pid, uns
97          struct task_struct *child;          struct task_struct *child;
98          struct switch_stack *sw;          struct switch_stack *sw;
99          long ret;          long ret;
100  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
101  +               return -EPERM;  +               return -EPERM;
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
102    
103          lock_kernel();          lock_kernel();
104          ret = -EPERM;          ret = -EPERM;
105  --- linux-source-2.6.18-22.orig/arch/m32r/kernel/ptrace.c  --- linux-2.6.18-26etch2.orig/arch/m32r/kernel/ptrace.c
106  +++ linux-source-2.6.18-22/arch/m32r/kernel/ptrace.c  +++ linux-2.6.18-26etch2/arch/m32r/kernel/ptrace.c
107  @@ -32,6 +32,9 @@  @@ -32,6 +32,7 @@
108   #include <asm/system.h>   #include <asm/system.h>
109   #include <asm/processor.h>   #include <asm/processor.h>
110   #include <asm/mmu_context.h>   #include <asm/mmu_context.h>
111  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
112    
113   /*   /*
114    * This routine will get a word off of the process kernel stack.    * This routine will get a word off of the process kernel stack.
115  @@ -742,6 +745,12 @@ asmlinkage long sys_ptrace(long request,  @@ -742,6 +743,8 @@ asmlinkage long sys_ptrace(long request,
116   {   {
117          struct task_struct *child;          struct task_struct *child;
118          int ret;          int ret;
119  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
120  +               return -EPERM;  +               return -EPERM;
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
121    
122          lock_kernel();          lock_kernel();
123          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
124  --- linux-source-2.6.18-22.orig/arch/mips/kernel/ptrace32.c  --- linux-2.6.18-26etch2.orig/arch/mips/kernel/ptrace32.c
125  +++ linux-source-2.6.18-22/arch/mips/kernel/ptrace32.c  +++ linux-2.6.18-26etch2/arch/mips/kernel/ptrace32.c
126  @@ -35,6 +35,9 @@  @@ -35,6 +35,7 @@
127   #include <asm/system.h>   #include <asm/system.h>
128   #include <asm/uaccess.h>   #include <asm/uaccess.h>
129   #include <asm/bootinfo.h>   #include <asm/bootinfo.h>
130  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
131    
132   int ptrace_getregs (struct task_struct *child, __s64 __user *data);   int ptrace_getregs (struct task_struct *child, __s64 __user *data);
133   int ptrace_setregs (struct task_struct *child, __s64 __user *data);   int ptrace_setregs (struct task_struct *child, __s64 __user *data);
134  @@ -50,6 +53,12 @@ asmlinkage int sys32_ptrace(int request,  @@ -50,6 +51,8 @@ asmlinkage int sys32_ptrace(int request,
135   {   {
136          struct task_struct *child;          struct task_struct *child;
137          int ret;          int ret;
138  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
139  +               return -EPERM;  +               return -EPERM;
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
140    
141   #if 0   #if 0
142          printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",          printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
143  --- linux-source-2.6.18-22.orig/arch/powerpc/kernel/ptrace32.c  --- linux-2.6.18-26etch2.orig/arch/powerpc/kernel/ptrace32.c
144  +++ linux-source-2.6.18-22/arch/powerpc/kernel/ptrace32.c  +++ linux-2.6.18-26etch2/arch/powerpc/kernel/ptrace32.c
145  @@ -32,6 +32,9 @@  @@ -32,6 +32,7 @@
146   #include <asm/page.h>   #include <asm/page.h>
147   #include <asm/pgtable.h>   #include <asm/pgtable.h>
148   #include <asm/system.h>   #include <asm/system.h>
149  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
150    
151   #include "ptrace-common.h"   #include "ptrace-common.h"
152    
153  @@ -45,6 +48,12 @@ long compat_sys_ptrace(int request, int  @@ -45,6 +46,8 @@ long compat_sys_ptrace(int request, int
154   {   {
155          struct task_struct *child;          struct task_struct *child;
156          int ret;          int ret;
157  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
158  +               return -EPERM;  +               return -EPERM;
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
159    
160          lock_kernel();          lock_kernel();
161          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
162  --- linux-source-2.6.18-22.orig/arch/s390/kernel/ptrace.c  --- linux-2.6.18-26etch2.orig/arch/s390/kernel/ptrace.c
163  +++ linux-source-2.6.18-22/arch/s390/kernel/ptrace.c  +++ linux-2.6.18-26etch2/arch/s390/kernel/ptrace.c
164  @@ -41,6 +41,9 @@  @@ -41,6 +41,7 @@
165   #include <asm/system.h>   #include <asm/system.h>
166   #include <asm/uaccess.h>   #include <asm/uaccess.h>
167   #include <asm/unistd.h>   #include <asm/unistd.h>
168  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
169    
170   #ifdef CONFIG_COMPAT   #ifdef CONFIG_COMPAT
171   #include "compat_ptrace.h"   #include "compat_ptrace.h"
172  @@ -711,6 +714,12 @@ sys_ptrace(long request, long pid, long  @@ -711,6 +712,8 @@ sys_ptrace(long request, long pid, long
173          struct task_struct *child;          struct task_struct *child;
174          int ret;          int ret;
175    
176  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
177  +               return -EPERM;  +               return -EPERM;
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
178          lock_kernel();          lock_kernel();
179          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
180                   ret = ptrace_traceme();                   ret = ptrace_traceme();
181  --- linux-source-2.6.18-22.orig/arch/sh64/kernel/ptrace.c  --- linux-2.6.18-26etch2.orig/arch/sparc/kernel/ptrace.c
182  +++ linux-source-2.6.18-22/arch/sh64/kernel/ptrace.c  +++ linux-2.6.18-26etch2/arch/sparc/kernel/ptrace.c
183  @@ -35,6 +35,9 @@  @@ -23,6 +23,7 @@
  #include <asm/system.h>  
  #include <asm/processor.h>  
  #include <asm/mmu_context.h>  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
   
  /* This mask defines the bits of the SR which the user is not allowed to  
     change, which are everything except S, Q, M, PR, SZ, FR. */  
 @@ -271,6 +274,12 @@ asmlinkage int sh64_ptrace(long request,  
         extern void poke_real_address_q(unsigned long long addr, unsigned long long data);  
  #define WPC_DBRMODE 0x0d104008  
         static int first_call = 1;  
 +       /***** TOMOYO Linux start. *****/  
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
 +               return -EPERM;  
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
   
         lock_kernel();  
         if (first_call) {  
 --- linux-source-2.6.18-22.orig/arch/sparc/kernel/ptrace.c  
 +++ linux-source-2.6.18-22/arch/sparc/kernel/ptrace.c  
 @@ -23,6 +23,9 @@  
184   #include <asm/pgtable.h>   #include <asm/pgtable.h>
185   #include <asm/system.h>   #include <asm/system.h>
186   #include <asm/uaccess.h>   #include <asm/uaccess.h>
187  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
188    
189   #define MAGIC_CONSTANT 0x80000000   #define MAGIC_CONSTANT 0x80000000
190    
191  @@ -267,6 +270,14 @@ asmlinkage void do_ptrace(struct pt_regs  @@ -267,6 +268,10 @@ asmlinkage void do_ptrace(struct pt_regs
192          unsigned long addr2 = regs->u_regs[UREG_I4];          unsigned long addr2 = regs->u_regs[UREG_I4];
193          struct task_struct *child;          struct task_struct *child;
194          int ret;          int ret;
195  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid)) {
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE)) {  
196  +               pt_error_return(regs, EPERM);  +               pt_error_return(regs, EPERM);
197  +               return;  +               return;
198  +       }  +       }
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
199    
200          lock_kernel();          lock_kernel();
201   #ifdef DEBUG_PTRACE   #ifdef DEBUG_PTRACE
202  --- linux-source-2.6.18-22.orig/arch/sparc64/kernel/ptrace.c  --- linux-2.6.18-26etch2.orig/arch/sparc64/kernel/ptrace.c
203  +++ linux-source-2.6.18-22/arch/sparc64/kernel/ptrace.c  +++ linux-2.6.18-26etch2/arch/sparc64/kernel/ptrace.c
204  @@ -32,6 +32,9 @@  @@ -32,6 +32,7 @@
205   #include <asm/spitfire.h>   #include <asm/spitfire.h>
206   #include <asm/page.h>   #include <asm/page.h>
207   #include <asm/cpudata.h>   #include <asm/cpudata.h>
208  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
209    
210   /* Returning from ptrace is a bit tricky because the syscall return   /* Returning from ptrace is a bit tricky because the syscall return
211    * low level code assumes any value returned which is negative and    * low level code assumes any value returned which is negative and
212  @@ -176,6 +179,14 @@ asmlinkage void do_ptrace(struct pt_regs  @@ -176,6 +177,10 @@ asmlinkage void do_ptrace(struct pt_regs
213          unsigned long addr2 = regs->u_regs[UREG_I4];          unsigned long addr2 = regs->u_regs[UREG_I4];
214          struct task_struct *child;          struct task_struct *child;
215          int ret;          int ret;
216  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid)) {
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE)) {  
217  +               pt_error_return(regs, EPERM);  +               pt_error_return(regs, EPERM);
218  +               return;  +               return;
219  +       }  +       }
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
220    
221          if (test_thread_flag(TIF_32BIT)) {          if (test_thread_flag(TIF_32BIT)) {
222                  addr &= 0xffffffffUL;                  addr &= 0xffffffffUL;
223  --- linux-source-2.6.18-22.orig/arch/x86_64/ia32/ptrace32.c  --- linux-2.6.18-26etch2.orig/arch/x86_64/ia32/ptrace32.c
224  +++ linux-source-2.6.18-22/arch/x86_64/ia32/ptrace32.c  +++ linux-2.6.18-26etch2/arch/x86_64/ia32/ptrace32.c
225  @@ -26,6 +26,9 @@  @@ -26,6 +26,7 @@
226   #include <asm/i387.h>   #include <asm/i387.h>
227   #include <asm/fpu32.h>   #include <asm/fpu32.h>
228   #include <asm/ia32.h>   #include <asm/ia32.h>
229  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
230    
231   /*   /*
232    * Determines which flags the user has access to [1 = access, 0 = no access].    * Determines which flags the user has access to [1 = access, 0 = no access].
233  @@ -230,6 +233,12 @@ asmlinkage long sys32_ptrace(long reques  @@ -230,6 +231,8 @@ asmlinkage long sys32_ptrace(long reques
234          void __user *datap = compat_ptr(data);          void __user *datap = compat_ptr(data);
235          int ret;          int ret;
236          __u32 val;          __u32 val;
237  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
238  +               return -EPERM;  +               return -EPERM;
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
239    
240          switch (request) {          switch (request) {
241          case PTRACE_TRACEME:          case PTRACE_TRACEME:
242  --- linux-source-2.6.18-22.orig/fs/Kconfig  --- linux-2.6.18-26etch2.orig/fs/compat.c
243  +++ linux-source-2.6.18-22/fs/Kconfig  +++ linux-2.6.18-26etch2/fs/compat.c
244  @@ -1931,5 +1931,7 @@ endmenu  @@ -52,6 +52,7 @@
   
  source "fs/nls/Kconfig"  
   
 +source "fs/Kconfig.ccs"  
 +  
  endmenu  
   
 --- linux-source-2.6.18-22.orig/fs/Makefile  
 +++ linux-source-2.6.18-22/fs/Makefile  
 @@ -102,3 +102,5 @@ obj-$(CONFIG_HOSTFS)                += hostfs/  
  obj-$(CONFIG_HPPFS)            += hppfs/  
  obj-$(CONFIG_DEBUG_FS)         += debugfs/  
  obj-$(CONFIG_OCFS2_FS)         += ocfs2/  
 +  
 +include $(srctree)/fs/Makefile-2.6.ccs  
 --- linux-source-2.6.18-22.orig/fs/attr.c  
 +++ linux-source-2.6.18-22/fs/attr.c  
 @@ -15,6 +15,9 @@  
  #include <linux/fcntl.h>  
  #include <linux/quotaops.h>  
  #include <linux/security.h>  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
   
  /* Taken over from the old code... */  
   
 @@ -145,12 +148,28 @@ int notify_change(struct dentry * dentry  
   
         if (inode->i_op && inode->i_op->setattr) {  
                 error = security_inode_setattr(dentry, attr);  
 +               /***** TOMOYO Linux start. *****/  
 +               if (!error && (ia_valid & ATTR_MODE) &&  
 +                   !ccs_capable(TOMOYO_SYS_CHMOD))  
 +                       error = -EPERM;  
 +               if (!error && (ia_valid & (ATTR_UID | ATTR_GID)) &&  
 +                   !ccs_capable(TOMOYO_SYS_CHOWN))  
 +                       error = -EPERM;  
 +               /***** TOMOYO Linux end. *****/  
                 if (!error)  
                         error = inode->i_op->setattr(dentry, attr);  
         } else {  
                 error = inode_change_ok(inode, attr);  
                 if (!error)  
                         error = security_inode_setattr(dentry, attr);  
 +               /***** TOMOYO Linux start. *****/  
 +               if (!error && (ia_valid & ATTR_MODE) &&  
 +                   !ccs_capable(TOMOYO_SYS_CHMOD))  
 +                       error = -EPERM;  
 +               if (!error && (ia_valid & (ATTR_UID | ATTR_GID)) &&  
 +                   !ccs_capable(TOMOYO_SYS_CHOWN))  
 +                       error = -EPERM;  
 +               /***** TOMOYO Linux end. *****/  
                 if (!error) {  
                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||  
                             (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))  
 --- linux-source-2.6.18-22.orig/fs/compat.c  
 +++ linux-source-2.6.18-22/fs/compat.c  
 @@ -52,6 +52,9 @@  
245   #include <asm/uaccess.h>   #include <asm/uaccess.h>
246   #include <asm/mmu_context.h>   #include <asm/mmu_context.h>
247   #include <asm/ioctls.h>   #include <asm/ioctls.h>
248  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
249    
250   extern void sigset_from_compat(sigset_t *set, compat_sigset_t *compat);   extern void sigset_from_compat(sigset_t *set, compat_sigset_t *compat);
251    
252  @@ -421,6 +424,12 @@ asmlinkage long compat_sys_ioctl(unsigne  @@ -397,6 +398,8 @@ asmlinkage long compat_sys_ioctl(unsigne
253    
254            /* RED-PEN how should LSM module know it's handling 32bit? */
255            error = security_file_ioctl(filp, cmd, arg);
256    +       if (!error)
257    +               error = ccs_ioctl_permission(filp, cmd, arg);
258            if (error)
259                    goto out_fput;
260    
261    @@ -421,6 +424,10 @@ asmlinkage long compat_sys_ioctl(unsigne
262                  /*FALL THROUGH*/                  /*FALL THROUGH*/
263    
264          default:          default:
265  +               /***** TOMOYO Linux start. *****/  +               if (!ccs_capable(CCS_SYS_IOCTL)) {
 +               if (!ccs_capable(TOMOYO_SYS_IOCTL)) {  
266  +                       error = -EPERM;  +                       error = -EPERM;
267  +                       goto out_fput;  +                       goto out_fput;
268  +               }  +               }
 +               /***** TOMOYO Linux end. *****/  
269                  if (filp->f_op && filp->f_op->compat_ioctl) {                  if (filp->f_op && filp->f_op->compat_ioctl) {
270                          error = filp->f_op->compat_ioctl(filp, cmd, arg);                          error = filp->f_op->compat_ioctl(filp, cmd, arg);
271                          if (error != -ENOIOCTLCMD)                          if (error != -ENOIOCTLCMD)
272  @@ -1567,7 +1576,7 @@ int compat_do_execve(char * filename,  @@ -1567,7 +1574,7 @@ int compat_do_execve(char * filename,
273          if (retval < 0)          if (retval < 0)
274                  goto out;                  goto out;
275    
276  -       retval = search_binary_handler(bprm, regs);  -       retval = search_binary_handler(bprm, regs);
277  +       retval = search_binary_handler_with_transition(bprm, regs);  +       retval = ccs_search_binary_handler(bprm, regs);
278          if (retval >= 0) {          if (retval >= 0) {
279                  free_arg_pages(bprm);                  free_arg_pages(bprm);
280    
281  --- linux-source-2.6.18-22.orig/fs/exec.c  --- linux-2.6.18-26etch2.orig/fs/exec.c
282  +++ linux-source-2.6.18-22/fs/exec.c  +++ linux-2.6.18-26etch2/fs/exec.c
283  @@ -57,6 +57,10 @@  @@ -57,6 +57,8 @@
284   #include <linux/kmod.h>   #include <linux/kmod.h>
285   #endif   #endif
286    
287  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
288  +  +
289   int core_uses_pid;   int core_uses_pid;
290   char core_pattern[65] = "core";   char core_pattern[65] = "core";
291   int suid_dumpable = 0;   int suid_dumpable = 0;
292  @@ -139,6 +143,13 @@ asmlinkage long sys_uselib(const char __  @@ -139,6 +141,10 @@ asmlinkage long sys_uselib(const char __
293          if (error)          if (error)
294                  goto exit;                  goto exit;
295    
296  +       /***** TOMOYO Linux start. *****/  +       error = ccs_uselib_permission(nd.dentry, nd.mnt);
 +       /* 01 means "read". */  
 +       error = ccs_check_open_permission(nd.dentry, nd.mnt, 01);  
297  +       if (error)  +       if (error)
298  +               goto exit;  +               goto exit;
 +       /***** TOMOYO Linux end. *****/  
299  +  +
300          file = nameidata_to_filp(&nd, O_RDONLY);          file = nameidata_to_filp(&nd, O_RDONLY);
301          error = PTR_ERR(file);          error = PTR_ERR(file);
302          if (IS_ERR(file))          if (IS_ERR(file))
303  @@ -486,6 +497,13 @@ struct file *open_exec(const char *name)  @@ -486,6 +492,9 @@ struct file *open_exec(const char *name)
304                  if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&                  if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&
305                      S_ISREG(inode->i_mode)) {                      S_ISREG(inode->i_mode)) {
306                          int err = vfs_permission(&nd, MAY_EXEC);                          int err = vfs_permission(&nd, MAY_EXEC);
307  +                       /***** TOMOYO Linux start. *****/  +                       if (!err)
308  +                       if (!err && (current->tomoyo_flags &  +                               err = ccs_open_exec_permission(nd.dentry,
309  +                                    TOMOYO_CHECK_READ_FOR_OPEN_EXEC))  +                                                                    nd.mnt);
 +                               /* 01 means "read". */  
 +                               err = ccs_check_open_permission(nd.dentry,  
 +                                                               nd.mnt, 01);  
 +                       /***** TOMOYO Linux end. *****/  
310                          file = ERR_PTR(err);                          file = ERR_PTR(err);
311                          if (!err) {                          if (!err) {
312                                  file = nameidata_to_filp(&nd, O_RDONLY);                                  file = nameidata_to_filp(&nd, O_RDONLY);
313  @@ -1188,7 +1206,8 @@ int do_execve(char * filename,  @@ -1188,7 +1197,8 @@ int do_execve(char * filename,
314          if (retval < 0)          if (retval < 0)
315                  goto out;                  goto out;
316    
317  -       retval = search_binary_handler(bprm,regs);  -       retval = search_binary_handler(bprm,regs);
318  +       retval = search_binary_handler_with_transition(bprm, regs);  +       retval = ccs_search_binary_handler(bprm, regs);
319  +  +
320          if (retval >= 0) {          if (retval >= 0) {
321                  free_arg_pages(bprm);                  free_arg_pages(bprm);
322    
323  --- linux-source-2.6.18-22.orig/fs/fcntl.c  --- linux-2.6.18-26etch2.orig/fs/fcntl.c
324  +++ linux-source-2.6.18-22/fs/fcntl.c  +++ linux-2.6.18-26etch2/fs/fcntl.c
325  @@ -22,6 +22,9 @@  @@ -22,6 +22,7 @@
326   #include <asm/poll.h>   #include <asm/poll.h>
327   #include <asm/siginfo.h>   #include <asm/siginfo.h>
328   #include <asm/uaccess.h>   #include <asm/uaccess.h>
329  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
330    
331   void fastcall set_close_on_exec(unsigned int fd, int flag)   void fastcall set_close_on_exec(unsigned int fd, int flag)
332   {   {
333  @@ -214,6 +217,12 @@ static int setfl(int fd, struct file * f  @@ -214,6 +215,9 @@ static int setfl(int fd, struct file * f
334          if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode))          if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode))
335                  return -EPERM;                  return -EPERM;
336    
337  +       /***** TOMOYO Linux start. *****/  +       if (((arg ^ filp->f_flags) & O_APPEND) && ccs_rewrite_permission(filp))
 +       if (((arg ^ filp->f_flags) & O_APPEND) &&  
 +           ccs_check_rewrite_permission(filp))  
338  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
339  +  +
340          /* O_NOATIME can only be set by the owner or superuser */          /* O_NOATIME can only be set by the owner or superuser */
341          if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))          if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))
342                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
343  --- linux-source-2.6.18-22.orig/fs/ioctl.c  --- linux-2.6.18-26etch2.orig/fs/ioctl.c
344  +++ linux-source-2.6.18-22/fs/ioctl.c  +++ linux-2.6.18-26etch2/fs/ioctl.c
345  @@ -15,6 +15,9 @@  @@ -15,6 +15,7 @@
346    
347   #include <asm/uaccess.h>   #include <asm/uaccess.h>
348   #include <asm/ioctls.h>   #include <asm/ioctls.h>
349  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
350    
351   static long do_ioctl(struct file *filp, unsigned int cmd,   static long do_ioctl(struct file *filp, unsigned int cmd,
352                  unsigned long arg)                  unsigned long arg)
353  @@ -23,6 +26,10 @@ static long do_ioctl(struct file *filp,  @@ -23,6 +24,8 @@ static long do_ioctl(struct file *filp,
354    
355          if (!filp->f_op)          if (!filp->f_op)
356                  goto out;                  goto out;
357  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_IOCTL))
 +       if (!ccs_capable(TOMOYO_SYS_IOCTL))  
358  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
359    
360          if (filp->f_op->unlocked_ioctl) {          if (filp->f_op->unlocked_ioctl) {
361                  error = filp->f_op->unlocked_ioctl(filp, cmd, arg);                  error = filp->f_op->unlocked_ioctl(filp, cmd, arg);
362  --- linux-source-2.6.18-22.orig/fs/namei.c  @@ -167,6 +170,8 @@ asmlinkage long sys_ioctl(unsigned int f
363  +++ linux-source-2.6.18-22/fs/namei.c                  goto out;
364  @@ -37,6 +37,10 @@  
365            error = security_file_ioctl(filp, cmd, arg);
366    +       if (!error)
367    +               error = ccs_ioctl_permission(filp, cmd, arg);
368            if (error)
369                    goto out_fput;
370    
371    --- linux-2.6.18-26etch2.orig/fs/namei.c
372    +++ linux-2.6.18-26etch2/fs/namei.c
373    @@ -37,6 +37,8 @@
374    
375   #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])   #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
376    
377  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
378  +  +
379   /* [Feb-1997 T. Schoebel-Theuer]   /* [Feb-1997 T. Schoebel-Theuer]
380    * Fundamental changes in the pathname lookup mechanisms (namei)    * Fundamental changes in the pathname lookup mechanisms (namei)
381    * were necessary because of omirr.  The reason is that omirr needs    * were necessary because of omirr.  The reason is that omirr needs
382  @@ -1481,6 +1485,13 @@ int vfs_create(struct inode *dir, struct  @@ -1536,6 +1538,11 @@ 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 = ccs_check_1path_perm(TYPE_CREATE_ACL, dentry, nd->mnt);  
 +               if (error)  
 +                       return error;  
 +       }  
 +       /***** TOMOYO Linux end. *****/  
         DQUOT_INIT(dir);  
         error = dir->i_op->create(dir, dentry, mode, nd);  
         if (!error)  
 @@ -1536,6 +1547,13 @@ int may_open(struct nameidata *nd, int a  
383                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
384                          return -EPERM;                          return -EPERM;
385    
 +       /***** TOMOYO Linux start. *****/  
386  +       /* includes O_APPEND and O_TRUNC checks */  +       /* includes O_APPEND and O_TRUNC checks */
387  +       error = ccs_check_open_permission(dentry, nd->mnt, flag);  +       error = ccs_open_permission(dentry, nd->mnt, flag);
388  +       if (error)  +       if (error)
389  +               return error;  +               return error;
 +       /***** TOMOYO Linux end. *****/  
390  +  +
391          /*          /*
392           * Ensure there are no outstanding leases on the file.           * Ensure there are no outstanding leases on the file.
393           */           */
394  @@ -1567,6 +1585,9 @@ int may_open(struct nameidata *nd, int a  @@ -1567,6 +1574,7 @@ int may_open(struct nameidata *nd, int a
395          return 0;          return 0;
396   }   }
397    
398  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity_vfs.h>
 +#include <linux/tomoyo_vfs.h>  
 +/***** TOMOYO Linux end. *****/  
399   /*   /*
400    *     open_namei()    *     open_namei()
401    *    *
402  @@ -1835,6 +1856,16 @@ asmlinkage long sys_mknodat(int dfd, con  @@ -1650,6 +1658,9 @@ do_last:
403            if (!path.dentry->d_inode) {
404          if (S_ISDIR(mode))                  if (!IS_POSIXACL(dir->d_inode))
405                  return -EPERM;                          mode &= ~current->fs->umask;
406  +       /***** TOMOYO Linux start. *****/  +               error = ccs_mknod_permission(dir->d_inode, path.dentry,
407  +       if (S_ISCHR(mode) && !ccs_capable(TOMOYO_CREATE_CHAR_DEV))  +                                            nd->mnt, mode, 0);
408  +               return -EPERM;  +               if (!error)
409  +       if (S_ISBLK(mode) && !ccs_capable(TOMOYO_CREATE_BLOCK_DEV))                  error = vfs_create(dir->d_inode, path.dentry, mode, nd);
410  +               return -EPERM;                  mutex_unlock(&dir->d_inode->i_mutex);
411  +       if (S_ISFIFO(mode) && !ccs_capable(TOMOYO_CREATE_FIFO))                  dput(nd->dentry);
412  +               return -EPERM;  @@ -1848,6 +1859,9 @@ asmlinkage long sys_mknodat(int dfd, con
413  +       if (S_ISSOCK(mode) && !ccs_capable(TOMOYO_CREATE_UNIX_SOCKET))          if (!IS_POSIXACL(nd.dentry->d_inode))
414  +               return -EPERM;                  mode &= ~current->fs->umask;
415  +       /***** TOMOYO Linux end. *****/          if (!IS_ERR(dentry)) {
416          tmp = getname(filename);  +               error = ccs_mknod_permission(nd.dentry->d_inode, dentry,
417          if (IS_ERR(tmp))  +                                            nd.mnt, mode, dev);
418                  return PTR_ERR(tmp);  +               if (!error)
419  @@ -1853,10 +1884,32 @@ asmlinkage long sys_mknodat(int dfd, con                  switch (mode & S_IFMT) {
420                    case 0: case S_IFREG:
421                          error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);                          error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
422                          break;  @@ -1921,6 +1935,9 @@ asmlinkage long sys_mkdirat(int dfd, con
                 case S_IFCHR: case S_IFBLK:  
 +                       /***** TOMOYO Linux start. *****/  
 +                       error = pre_vfs_mknod(nd.dentry->d_inode, dentry, mode);  
 +                       if (error)  
 +                               break;  
 +                       error = ccs_check_1path_perm(S_ISCHR(mode) ?  
 +                                                    TYPE_MKCHAR_ACL :  
 +                                                    TYPE_MKBLOCK_ACL,  
 +                                                    dentry, nd.mnt);  
 +                       if (error)  
 +                               break;  
 +                       /***** 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. *****/  
 +                       error = pre_vfs_mknod(nd.dentry->d_inode, dentry, mode);  
 +                       if (error)  
 +                               break;  
 +                       error = ccs_check_1path_perm(S_ISFIFO(mode) ?  
 +                                                    TYPE_MKFIFO_ACL :  
 +                                                    TYPE_MKSOCK_ACL,  
 +                                                    dentry, nd.mnt);  
 +                       if (error)  
 +                               break;  
 +                       /***** TOMOYO Linux end. *****/  
                         error = vfs_mknod(nd.dentry->d_inode,dentry,mode,0);  
                         break;  
                 case S_IFDIR:  
 @@ -1921,6 +1974,13 @@ asmlinkage long sys_mkdirat(int dfd, con  
423                  if (!IS_ERR(dentry)) {                  if (!IS_ERR(dentry)) {
424                          if (!IS_POSIXACL(nd.dentry->d_inode))                          if (!IS_POSIXACL(nd.dentry->d_inode))
425                                  mode &= ~current->fs->umask;                                  mode &= ~current->fs->umask;
426  +                       /***** TOMOYO Linux start. *****/  +                       error = ccs_mkdir_permission(nd.dentry->d_inode,
427  +                       error = pre_vfs_mkdir(nd.dentry->d_inode, dentry);  +                                                    dentry, nd.mnt, mode);
 +                       if (!error)  
 +                               error = ccs_check_1path_perm(TYPE_MKDIR_ACL,  
 +                                                            dentry, nd.mnt);  
428  +                       if (!error)  +                       if (!error)
 +                       /***** TOMOYO Linux end. *****/  
429                          error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);                          error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
430                          dput(dentry);                          dput(dentry);
431                  }                  }
432  @@ -2029,6 +2089,13 @@ static long do_rmdir(int dfd, const char  @@ -2029,6 +2046,9 @@ static long do_rmdir(int dfd, const char
433          dentry = lookup_hash(&nd);          dentry = lookup_hash(&nd);
434          error = PTR_ERR(dentry);          error = PTR_ERR(dentry);
435          if (!IS_ERR(dentry)) {          if (!IS_ERR(dentry)) {
436  +               /***** TOMOYO Linux start. *****/  +               error = ccs_rmdir_permission(nd.dentry->d_inode, dentry,
437  +               error = pre_vfs_rmdir(nd.dentry->d_inode, dentry);  +                                            nd.mnt);
438  +               if (!error)  +               if (!error)
 +                       error = ccs_check_1path_perm(TYPE_RMDIR_ACL, dentry,  
 +                                                    nd.mnt);  
 +               if (!error)  
 +               /***** TOMOYO Linux end. *****/  
439                  error = vfs_rmdir(nd.dentry->d_inode, dentry);                  error = vfs_rmdir(nd.dentry->d_inode, dentry);
440                  dput(dentry);                  dput(dentry);
441          }          }
442  @@ -2088,6 +2155,10 @@ static long do_unlinkat(int dfd, const c  @@ -2109,6 +2129,9 @@ static long do_unlinkat(int dfd, const c
         struct dentry *dentry;  
         struct nameidata nd;  
         struct inode *inode = NULL;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (!ccs_capable(TOMOYO_SYS_UNLINK))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         name = getname(pathname);  
         if(IS_ERR(name))  
 @@ -2109,6 +2180,14 @@ static long do_unlinkat(int dfd, const c  
443                  inode = dentry->d_inode;                  inode = dentry->d_inode;
444                  if (inode)                  if (inode)
445                          atomic_inc(&inode->i_count);                          atomic_inc(&inode->i_count);
446  +               /***** TOMOYO Linux start. *****/  +               error = ccs_unlink_permission(nd.dentry->d_inode, dentry,
447  +               error = pre_vfs_unlink(nd.dentry->d_inode, dentry);  +                                             nd.mnt);
448  +               if (error)  +               if (!error)
 +                       goto exit2;  
 +               error = ccs_check_1path_perm(TYPE_UNLINK_ACL, dentry, nd.mnt);  
 +               if (error)  
 +                       goto exit2;  
 +               /***** TOMOYO Linux end. *****/  
449                  error = vfs_unlink(nd.dentry->d_inode, dentry);                  error = vfs_unlink(nd.dentry->d_inode, dentry);
450          exit2:          exit2:
451                  dput(dentry);                  dput(dentry);
452  @@ -2171,6 +2250,10 @@ asmlinkage long sys_symlinkat(const char  @@ -2187,6 +2210,9 @@ asmlinkage long sys_symlinkat(const char
         int error = 0;  
         char * from;  
         char * to;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (!ccs_capable(TOMOYO_SYS_SYMLINK))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         from = getname(oldname);  
         if(IS_ERR(from))  
 @@ -2187,6 +2270,13 @@ asmlinkage long sys_symlinkat(const char  
453                  dentry = lookup_create(&nd, 0);                  dentry = lookup_create(&nd, 0);
454                  error = PTR_ERR(dentry);                  error = PTR_ERR(dentry);
455                  if (!IS_ERR(dentry)) {                  if (!IS_ERR(dentry)) {
456  +                       /***** TOMOYO Linux start. *****/  +                       error = ccs_symlink_permission(nd.dentry->d_inode,
457  +                       error = pre_vfs_symlink(nd.dentry->d_inode, dentry);  +                                                      dentry, nd.mnt, from);
 +                       if (!error)  
 +                               error = ccs_check_1path_perm(TYPE_SYMLINK_ACL,  
 +                                                            dentry, nd.mnt);  
458  +                       if (!error)  +                       if (!error)
 +                       /***** TOMOYO Linux end. *****/  
459                          error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);                          error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
460                          dput(dentry);                          dput(dentry);
461                  }                  }
462  @@ -2259,6 +2349,10 @@ asmlinkage long sys_linkat(int olddfd, c  @@ -2281,6 +2307,9 @@ asmlinkage long sys_linkat(int olddfd, c
         struct nameidata nd, old_nd;  
         int error;  
         char * to;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (!ccs_capable(TOMOYO_SYS_LINK))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         if ((flags & ~AT_SYMLINK_FOLLOW) != 0)  
                 return -EINVAL;  
 @@ -2281,6 +2375,15 @@ asmlinkage long sys_linkat(int olddfd, c  
463          new_dentry = lookup_create(&nd, 0);          new_dentry = lookup_create(&nd, 0);
464          error = PTR_ERR(new_dentry);          error = PTR_ERR(new_dentry);
465          if (!IS_ERR(new_dentry)) {          if (!IS_ERR(new_dentry)) {
466  +               /***** TOMOYO Linux start. *****/  +               error = ccs_link_permission(old_nd.dentry, nd.dentry->d_inode,
467  +               error = pre_vfs_link(old_nd.dentry, nd.dentry->d_inode,  +                                           new_dentry, nd.mnt);
 +                                    new_dentry);  
468  +               if (!error)  +               if (!error)
 +                       error = ccs_check_2path_perm(TYPE_LINK_ACL,  
 +                                                    old_nd.dentry, old_nd.mnt,  
 +                                                    new_dentry, nd.mnt);  
 +               if (!error)  
 +               /***** TOMOYO Linux end. *****/  
469                  error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);                  error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
470                  dput(new_dentry);                  dput(new_dentry);
471          }          }
472  @@ -2507,6 +2610,17 @@ static int do_rename(int olddfd, const c  @@ -2507,6 +2536,9 @@ static int do_rename(int olddfd, const c
473          if (new_dentry == trap)          if (new_dentry == trap)
474                  goto exit5;                  goto exit5;
475    
476  +       /***** TOMOYO Linux start. *****/  +       error = ccs_rename_permission(old_dir->d_inode, old_dentry,
477  +       error = pre_vfs_rename(old_dir->d_inode, old_dentry,  +                                     new_dir->d_inode, new_dentry, newnd.mnt);
478  +                              new_dir->d_inode, new_dentry);  +       if (!error)
 +       if (error)  
 +               goto exit5;  
 +       error = ccs_check_2path_perm(TYPE_RENAME_ACL, old_dentry, oldnd.mnt,  
 +                                    new_dentry, newnd.mnt);  
 +       if (error)  
 +               goto exit5;  
 +       /***** TOMOYO Linux end. *****/  
 +  
479          error = vfs_rename(old_dir->d_inode, old_dentry,          error = vfs_rename(old_dir->d_inode, old_dentry,
480                                     new_dir->d_inode, new_dentry);                                     new_dir->d_inode, new_dentry);
481   exit5:   exit5:
482  @@ -2529,6 +2643,10 @@ asmlinkage long sys_renameat(int olddfd,  --- linux-2.6.18-26etch2.orig/fs/namespace.c
483          int error;  +++ linux-2.6.18-26etch2/fs/namespace.c
484          char * from;  @@ -25,6 +25,7 @@
         char * to;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (!ccs_capable(TOMOYO_SYS_RENAME))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         from = getname(oldname);  
         if(IS_ERR(from))  
 --- linux-source-2.6.18-22.orig/fs/namespace.c  
 +++ linux-source-2.6.18-22/fs/namespace.c  
 @@ -25,6 +25,12 @@  
485   #include <asm/uaccess.h>   #include <asm/uaccess.h>
486   #include <asm/unistd.h>   #include <asm/unistd.h>
487   #include "pnode.h"   #include "pnode.h"
488  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
489    
490   extern int __init init_rootfs(void);   extern int __init init_rootfs(void);
491    
492  @@ -553,6 +559,11 @@ static int do_umount(struct vfsmount *mn  @@ -550,6 +551,8 @@ static int do_umount(struct vfsmount *mn
493            LIST_HEAD(umount_list);
494    
495            retval = security_sb_umount(mnt, flags);
496    +       if (!retval)
497    +               retval = ccs_umount_permission(mnt, flags);
498          if (retval)          if (retval)
499                  return retval;                  return retval;
500    
501  +       /***** SAKURA Linux start. *****/  @@ -641,6 +644,8 @@ asmlinkage long sys_umount(char __user *
 +       if (ccs_may_umount(mnt))  
 +               return -EPERM;  
 +       /***** SAKURA Linux end. *****/  
 +  
         /*  
          * Allow userspace to request a mountpoint be expired rather than  
          * unmounting unconditionally. Unmount only happens if:  
 @@ -641,6 +652,10 @@ asmlinkage long sys_umount(char __user *  
502   {   {
503          struct nameidata nd;          struct nameidata nd;
504          int retval;          int retval;
505  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_UMOUNT))
 +       if (!ccs_capable(TOMOYO_SYS_UMOUNT))  
506  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
507    
508          retval = __user_walk(name, LOOKUP_FOLLOW, &nd);          retval = __user_walk(name, LOOKUP_FOLLOW, &nd);
509          if (retval)          if (retval)
510  @@ -925,6 +940,11 @@ static int do_loopback(struct nameidata  @@ -925,6 +930,9 @@ static int do_loopback(struct nameidata
511    
512          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
513                  goto out;                  goto out;
 +       /***** SAKURA Linux start. *****/  
514  +       err = -EPERM;  +       err = -EPERM;
515  +       if (ccs_may_mount(nd))  +       if (ccs_may_mount(nd))
516  +               goto out;  +               goto out;
 +       /***** SAKURA Linux end. *****/  
517    
518          err = -ENOMEM;          err = -ENOMEM;
519          if (recurse)          if (recurse)
520  @@ -1009,7 +1029,11 @@ static int do_move_mount(struct nameidat  @@ -1009,7 +1017,9 @@ static int do_move_mount(struct nameidat
521          err = -EINVAL;          err = -EINVAL;
522          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
523                  goto out;                  goto out;
524  -  -
 +       /***** SAKURA Linux start. *****/  
525  +       err = -EPERM;  +       err = -EPERM;
526  +       if (ccs_may_umount(old_nd.mnt) || ccs_may_mount(nd))  +       if (ccs_may_mount(nd))
527  +               goto out;  +               goto out;
 +       /***** SAKURA Linux end. *****/  
528          err = -ENOENT;          err = -ENOENT;
529          mutex_lock(&nd->dentry->d_inode->i_mutex);          mutex_lock(&nd->dentry->d_inode->i_mutex);
530          if (IS_DEADDIR(nd->dentry->d_inode))          if (IS_DEADDIR(nd->dentry->d_inode))
531  @@ -1111,6 +1135,11 @@ int do_add_mount(struct vfsmount *newmnt  @@ -1111,6 +1121,9 @@ int do_add_mount(struct vfsmount *newmnt
532          err = -EINVAL;          err = -EINVAL;
533          if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))          if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
534                  goto unlock;                  goto unlock;
 +       /***** SAKURA Linux start. *****/  
535  +       err = -EPERM;  +       err = -EPERM;
536  +       if (ccs_may_mount(nd))  +       if (ccs_may_mount(nd))
537  +               goto unlock;  +               goto unlock;
 +       /***** SAKURA Linux end. *****/  
538    
539          newmnt->mnt_flags = mnt_flags;          newmnt->mnt_flags = mnt_flags;
540          if ((err = graft_tree(newmnt, nd)))          if ((err = graft_tree(newmnt, nd)))
541  @@ -1402,6 +1431,17 @@ long do_mount(char *dev_name, char *dir_  @@ -1384,6 +1397,7 @@ int copy_mount_options(const void __user
542          if (data_page)   long do_mount(char *dev_name, char *dir_name, char *type_page,
543                  ((char *)data_page)[PAGE_SIZE - 1] = 0;                    unsigned long flags, void *data_page)
544     {
545  +       /***** TOMOYO Linux start. *****/  +       const unsigned long original_flags = flags;
546  +       if (!ccs_capable(TOMOYO_SYS_MOUNT))          struct nameidata nd;
547  +               return -EPERM;          int retval = 0;
548  +       /***** TOMOYO Linux end. *****/          int mnt_flags = 0;
549  +       /***** SAKURA Linux start. *****/  @@ -1423,6 +1437,9 @@ long do_mount(char *dev_name, char *dir_
550  +       retval = ccs_check_mount_permission(dev_name, dir_name, type_page,                  return retval;
 +                                           &flags);  
 +       if (retval)  
 +               return retval;  
 +       /***** SAKURA Linux end. *****/  
 +  
         /* Separate the per-mountpoint flags */  
         if (flags & MS_NOSUID)  
                 mnt_flags |= MNT_NOSUID;  
 @@ -1691,6 +1731,10 @@ asmlinkage long sys_pivot_root(const cha  
   
         if (!capable(CAP_SYS_ADMIN))  
                 return -EPERM;  
 +       /***** TOMOYO Linux start. *****/  
 +       if (!ccs_capable(TOMOYO_SYS_PIVOT_ROOT))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
551    
552          lock_kernel();          retval = security_sb_mount(dev_name, &nd, type_page, flags, data_page);
553    +       if (!retval)
554    +               retval = ccs_mount_permission(dev_name, &nd, type_page,
555    +                                             original_flags, data_page);
556            if (retval)
557                    goto dput_out;
558    
559  @@ -1707,6 +1751,10 @@ asmlinkage long sys_pivot_root(const cha  @@ -1707,6 +1724,8 @@ asmlinkage long sys_pivot_root(const cha
560                  goto out1;                  goto out1;
561    
562          error = security_sb_pivotroot(&old_nd, &new_nd);          error = security_sb_pivotroot(&old_nd, &new_nd);
 +       /***** SAKURA Linux start. *****/  
563  +       if (!error)  +       if (!error)
564  +               error = ccs_check_pivot_root_permission(&old_nd, &new_nd);  +               error = ccs_pivot_root_permission(&old_nd, &new_nd);
 +       /***** SAKURA Linux end. *****/  
565          if (error) {          if (error) {
566                  path_release(&old_nd);                  path_release(&old_nd);
567                  goto out1;                  goto out1;
568  --- linux-source-2.6.18-22.orig/fs/open.c  --- linux-2.6.18-26etch2.orig/fs/open.c
569  +++ linux-source-2.6.18-22/fs/open.c  +++ linux-2.6.18-26etch2/fs/open.c
570  @@ -30,6 +30,12 @@  @@ -30,6 +30,7 @@
571   #include <linux/audit.h>   #include <linux/audit.h>
572    
573   #include <asm/unistd.h>   #include <asm/unistd.h>
574  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
575    
576   int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)   int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
577   {   {
578  @@ -267,6 +273,10 @@ static long do_sys_truncate(const char _  @@ -267,6 +268,8 @@ static long do_sys_truncate(const char _
579          if (error)          if (error)
580                  goto dput_and_out;                  goto dput_and_out;
581    
582  +       /***** TOMOYO Linux start. *****/  +       error = ccs_truncate_permission(nd.dentry, nd.mnt, length, 0);
 +       error = ccs_check_1path_perm(TYPE_TRUNCATE_ACL, nd.dentry, nd.mnt);  
583  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
584          error = locks_verify_truncate(inode, NULL, length);          error = locks_verify_truncate(inode, NULL, length);
585          if (!error) {          if (!error) {
586                  DQUOT_INIT(inode);                  DQUOT_INIT(inode);
587  @@ -320,6 +330,11 @@ static long do_sys_ftruncate(unsigned in  @@ -320,6 +323,9 @@ static long do_sys_ftruncate(unsigned in
588          if (IS_APPEND(inode))          if (IS_APPEND(inode))
589                  goto out_putf;                  goto out_putf;
590    
591  +       /***** TOMOYO Linux start. *****/  +       error = ccs_truncate_permission(dentry, file->f_vfsmnt, length, 0);
 +       error = ccs_check_1path_perm(TYPE_TRUNCATE_ACL, dentry, file->f_vfsmnt);  
592  +       if (error)  +       if (error)
593  +               goto out_putf;  +               goto out_putf;
 +       /***** TOMOYO Linux end. *****/  
594          error = locks_verify_truncate(inode, file, length);          error = locks_verify_truncate(inode, file, length);
595          if (!error)          if (!error)
596                  error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);                  error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);
597  @@ -608,6 +623,14 @@ asmlinkage long sys_chroot(const char __  @@ -608,6 +614,8 @@ asmlinkage long sys_chroot(const char __
598          error = -EPERM;          error = -EPERM;
599          if (!capable(CAP_SYS_CHROOT))          if (!capable(CAP_SYS_CHROOT))
600                  goto dput_and_out;                  goto dput_and_out;
601  +       /***** TOMOYO Linux start. *****/  +       if (ccs_chroot_permission(&nd))
 +       if (!ccs_capable(TOMOYO_SYS_CHROOT))  
602  +               goto dput_and_out;  +               goto dput_and_out;
 +       /***** TOMOYO Linux end. *****/  
 +       /***** SAKURA Linux start. *****/  
 +       if (ccs_check_chroot_permission(&nd))  
 +               goto dput_and_out;  
 +       /***** SAKURA Linux end. *****/  
603    
604          set_fs_root(current->fs, nd.mnt, nd.dentry);          set_fs_root(current->fs, nd.mnt, nd.dentry);
605          set_fs_altroot();          set_fs_altroot();
606  @@ -1199,6 +1222,10 @@ EXPORT_SYMBOL(sys_close);  @@ -641,6 +649,9 @@ asmlinkage long sys_fchmod(unsigned int
607            err = -EPERM;
608            if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
609                    goto out_putf;
610    +       err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode);
611    +       if (err)
612    +               goto out_putf;
613            mutex_lock(&inode->i_mutex);
614            if (mode == (mode_t) -1)
615                    mode = inode->i_mode;
616    @@ -675,6 +686,9 @@ asmlinkage long sys_fchmodat(int dfd, co
617            error = -EPERM;
618            if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
619                    goto dput_and_out;
620    +       error = ccs_chmod_permission(nd.dentry, nd.mnt, mode);
621    +       if (error)
622    +               goto dput_and_out;
623    
624            mutex_lock(&inode->i_mutex);
625            if (mode == (mode_t) -1)
626    @@ -737,6 +751,8 @@ asmlinkage long sys_chown(const char __u
627    
628            error = user_path_walk(filename, &nd);
629            if (!error) {
630    +               error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
631    +               if (!error)
632                    error = chown_common(nd.dentry, user, group);
633                    path_release(&nd);
634            }
635    @@ -756,6 +772,8 @@ asmlinkage long sys_fchownat(int dfd, co
636            follow = (flag & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW;
637            error = __user_walk_fd(dfd, filename, follow, &nd);
638            if (!error) {
639    +               error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
640    +               if (!error)
641                    error = chown_common(nd.dentry, user, group);
642                    path_release(&nd);
643            }
644    @@ -770,6 +788,8 @@ asmlinkage long sys_lchown(const char __
645    
646            error = user_path_walk_link(filename, &nd);
647            if (!error) {
648    +               error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
649    +               if (!error)
650                    error = chown_common(nd.dentry, user, group);
651                    path_release(&nd);
652            }
653    @@ -787,6 +807,9 @@ asmlinkage long sys_fchown(unsigned int
654                    struct dentry * dentry;
655                    dentry = file->f_dentry;
656                    audit_inode(NULL, dentry->d_inode);
657    +               error = ccs_chown_permission(dentry, file->f_vfsmnt, user,
658    +                                            group);
659    +               if (!error)
660                    error = chown_common(dentry, user, group);
661                    fput(file);
662            }
663    @@ -879,7 +902,9 @@ static struct file *do_filp_open(int dfd
664            if ((namei_flags+1) & O_ACCMODE)
665                    namei_flags++;
666    
667    +       ccs_save_open_mode(flags);
668            error = open_namei(dfd, filename, namei_flags, mode, &nd);
669    +       ccs_clear_open_mode();
670            if (!error)
671                    return nameidata_to_filp(&nd, flags);
672    
673    @@ -1199,6 +1224,8 @@ EXPORT_SYMBOL(sys_close);
674    */    */
675   asmlinkage long sys_vhangup(void)   asmlinkage long sys_vhangup(void)
676   {   {
677  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_VHANGUP))
 +       if (!ccs_capable(TOMOYO_SYS_VHANGUP))  
678  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
679          if (capable(CAP_SYS_TTY_CONFIG)) {          if (capable(CAP_SYS_TTY_CONFIG)) {
680                  tty_vhangup(current->signal->tty);                  tty_vhangup(current->signal->tty);
681                  return 0;                  return 0;
682  --- linux-source-2.6.18-22.orig/fs/proc/Makefile  --- linux-2.6.18-26etch2.orig/fs/proc/proc_misc.c
683  +++ linux-source-2.6.18-22/fs/proc/Makefile  +++ linux-2.6.18-26etch2/fs/proc/proc_misc.c
684  @@ -13,3 +13,6 @@ proc-y       += inode.o root.o base.o ge  @@ -723,4 +723,5 @@ void __init proc_misc_init(void)
  proc-$(CONFIG_PROC_KCORE)      += kcore.o  
  proc-$(CONFIG_PROC_VMCORE)     += vmcore.o  
  proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o  
 +  
 +proc-$(CONFIG_SAKURA) += ccs_proc.o  
 +proc-$(CONFIG_TOMOYO) += ccs_proc.o  
 --- linux-source-2.6.18-22.orig/fs/proc/proc_misc.c  
 +++ linux-source-2.6.18-22/fs/proc/proc_misc.c  
 @@ -723,4 +723,9 @@ void __init proc_misc_init(void)  
685          if (entry)          if (entry)
686                  entry->proc_fops = &proc_sysrq_trigger_operations;                  entry->proc_fops = &proc_sysrq_trigger_operations;
687   #endif   #endif
688  +       /***** CCS start. *****/  +       printk(KERN_INFO "Hook version: 2.6.18-26etch2 2010/07/21\n");
 +#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO)  
 +       printk(KERN_INFO "Hook version: 2.6.18-22 2008/08/20\n");  
 +#endif  
 +       /***** CCS end. *****/  
689   }   }
690  --- linux-source-2.6.18-22.orig/include/linux/init_task.h  --- linux-2.6.18-26etch2.orig/include/linux/init_task.h
691  +++ linux-source-2.6.18-22/include/linux/init_task.h  +++ linux-2.6.18-26etch2/include/linux/init_task.h
692  @@ -128,6 +128,10 @@ extern struct group_info init_groups;  @@ -76,6 +76,14 @@
693    
694     extern struct group_info init_groups;
695    
696    +#ifdef CONFIG_CCSECURITY
697    +#define INIT_CCSECURITY          \
698    +       .ccs_domain_info = NULL, \
699    +       .ccs_flags = 0,
700    +#else
701    +#define INIT_CCSECURITY
702    +#endif
703    +
704     /*
705      *  INIT_TASK is used to set up the first task table, touch at
706      * your own risk!. Base=0, limit=0x1fffff (=2MB)
707    @@ -128,6 +136,7 @@ extern struct group_info init_groups;
708          .pi_lock        = SPIN_LOCK_UNLOCKED,                           \          .pi_lock        = SPIN_LOCK_UNLOCKED,                           \
709          INIT_TRACE_IRQFLAGS                                             \          INIT_TRACE_IRQFLAGS                                             \
710          INIT_LOCKDEP                                                    \          INIT_LOCKDEP                                                    \
711  +       /***** TOMOYO Linux start. *****/        \  +       INIT_CCSECURITY                                                 \
 +       .domain_info = &KERNEL_DOMAIN,           \  
 +       .tomoyo_flags = 0,                       \  
 +       /***** TOMOYO Linux end. *****/          \  
712   }   }
713    
714    
715  --- linux-source-2.6.18-22.orig/include/linux/sched.h  --- linux-2.6.18-26etch2.orig/include/linux/sched.h
716  +++ linux-source-2.6.18-22/include/linux/sched.h  +++ linux-2.6.18-26etch2/include/linux/sched.h
717  @@ -25,6 +25,11 @@  @@ -35,6 +35,8 @@
718   #define CLONE_CHILD_SETTID     0x01000000      /* set the TID in the child */  
719   #define CLONE_STOPPED          0x02000000      /* Start in stopped state */   #ifdef __KERNEL__
720    
721  +/***** TOMOYO Linux start. *****/  +struct ccs_domain_info;
 +struct domain_info;  
 +extern struct domain_info KERNEL_DOMAIN;  
 +/***** TOMOYO Linux end. *****/  
722  +  +
723   /*   struct sched_param {
724    * Scheduling policies          int sched_priority;
725    */   };
726  @@ -996,6 +1001,10 @@ struct task_struct {  @@ -996,6 +998,10 @@ struct task_struct {
727   #ifdef CONFIG_TASK_DELAY_ACCT   #ifdef CONFIG_TASK_DELAY_ACCT
728          struct task_delay_info *delays;          struct task_delay_info *delays;
729   #endif   #endif
730  +       /***** TOMOYO Linux start. *****/  +#ifdef CONFIG_CCSECURITY
731  +       struct domain_info *domain_info;  +       struct ccs_domain_info *ccs_domain_info;
732  +       u32 tomoyo_flags;  +       u32 ccs_flags;
733  +       /***** TOMOYO Linux end. *****/  +#endif
734   };   };
735    
736   static inline pid_t process_group(struct task_struct *tsk)   static inline pid_t process_group(struct task_struct *tsk)
737  --- linux-source-2.6.18-22.orig/kernel/compat.c  --- linux-2.6.18-26etch2.orig/kernel/compat.c
738  +++ linux-source-2.6.18-22/kernel/compat.c  +++ linux-2.6.18-26etch2/kernel/compat.c
739  @@ -24,6 +24,9 @@  @@ -24,6 +24,7 @@
740   #include <linux/migrate.h>   #include <linux/migrate.h>
741    
742   #include <asm/uaccess.h>   #include <asm/uaccess.h>
743  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
744    
745   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)
746   {   {
747  @@ -836,6 +839,10 @@ asmlinkage long compat_sys_stime(compat_  @@ -836,6 +837,8 @@ asmlinkage long compat_sys_stime(compat_
748          err = security_settime(&tv, NULL);          err = security_settime(&tv, NULL);
749          if (err)          if (err)
750                  return err;                  return err;
751  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_SETTIME))
 +       if (!ccs_capable(TOMOYO_SYS_SETTIME))  
752  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
753    
754          do_settimeofday(&tv);          do_settimeofday(&tv);
755          return 0;          return 0;
756  --- linux-source-2.6.18-22.orig/kernel/kexec.c  --- linux-2.6.18-26etch2.orig/kernel/kexec.c
757  +++ linux-source-2.6.18-22/kernel/kexec.c  +++ linux-2.6.18-26etch2/kernel/kexec.c
758  @@ -26,6 +26,9 @@  @@ -26,6 +26,7 @@
759   #include <asm/io.h>   #include <asm/io.h>
760   #include <asm/system.h>   #include <asm/system.h>
761   #include <asm/semaphore.h>   #include <asm/semaphore.h>
762  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
763    
764   /* Per cpu memory for storing cpu states in case of system crash. */   /* Per cpu memory for storing cpu states in case of system crash. */
765   note_buf_t* crash_notes;   note_buf_t* crash_notes;
766  @@ -922,6 +925,10 @@ asmlinkage long sys_kexec_load(unsigned  @@ -922,6 +923,8 @@ asmlinkage long sys_kexec_load(unsigned
767          /* We only trust the superuser with rebooting the system. */          /* We only trust the superuser with rebooting the system. */
768          if (!capable(CAP_SYS_BOOT))          if (!capable(CAP_SYS_BOOT))
769                  return -EPERM;                  return -EPERM;
770  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
 +       if (!ccs_capable(TOMOYO_SYS_KEXEC_LOAD))  
771  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
772    
773          /*          /*
774           * Verify we have a legal set of flags           * Verify we have a legal set of flags
775  --- linux-source-2.6.18-22.orig/kernel/kmod.c  --- linux-2.6.18-26etch2.orig/kernel/kmod.c
776  +++ linux-source-2.6.18-22/kernel/kmod.c  +++ linux-2.6.18-26etch2/kernel/kmod.c
777  @@ -148,6 +148,11 @@ static int ____call_usermodehelper(void  @@ -148,6 +148,11 @@ static int ____call_usermodehelper(void
778          /* We can run anywhere, unlike our parent keventd(). */          /* We can run anywhere, unlike our parent keventd(). */
779          set_cpus_allowed(current, CPU_MASK_ALL);          set_cpus_allowed(current, CPU_MASK_ALL);
780    
781  +       /***** TOMOYO Linux start. *****/  +#ifdef CONFIG_CCSECURITY
782  +       current->domain_info = &KERNEL_DOMAIN;  +       current->ccs_domain_info = NULL;
783  +       current->tomoyo_flags = 0;  +       current->ccs_flags = 0;
784  +       /***** TOMOYO Linux end. *****/  +#endif
785  +  +
786          retval = -EPERM;          retval = -EPERM;
787          if (current->fs->root)          if (current->fs->root)
788                  retval = execve(sub_info->path, sub_info->argv,sub_info->envp);                  retval = execve(sub_info->path, sub_info->argv,sub_info->envp);
789  --- linux-source-2.6.18-22.orig/kernel/module.c  --- linux-2.6.18-26etch2.orig/kernel/module.c
790  +++ linux-source-2.6.18-22/kernel/module.c  +++ linux-2.6.18-26etch2/kernel/module.c
791  @@ -44,6 +44,9 @@  @@ -44,6 +44,7 @@
792   #include <asm/semaphore.h>   #include <asm/semaphore.h>
793   #include <asm/cacheflush.h>   #include <asm/cacheflush.h>
794   #include <linux/license.h>   #include <linux/license.h>
795  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
796    
797   #if 0   #if 0
798   #define DEBUGP printk   #define DEBUGP printk
799  @@ -652,7 +655,10 @@ sys_delete_module(const char __user *nam  @@ -652,7 +653,8 @@ sys_delete_module(const char __user *nam
800    
801          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
802                  return -EPERM;                  return -EPERM;
803  -  -
804  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
 +       if (!ccs_capable(TOMOYO_USE_KERNEL_MODULE))  
805  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
806          if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)          if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
807                  return -EFAULT;                  return -EFAULT;
808          name[MODULE_NAME_LEN-1] = '\0';          name[MODULE_NAME_LEN-1] = '\0';
809  @@ -1884,7 +1890,10 @@ sys_init_module(void __user *umod,  @@ -1884,7 +1886,8 @@ sys_init_module(void __user *umod,
810          /* Must have permission */          /* Must have permission */
811          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
812                  return -EPERM;                  return -EPERM;
813  -  -
814  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
 +       if (!ccs_capable(TOMOYO_USE_KERNEL_MODULE))  
815  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
816          /* Only one module load at a time, please */          /* Only one module load at a time, please */
817          if (mutex_lock_interruptible(&module_mutex) != 0)          if (mutex_lock_interruptible(&module_mutex) != 0)
818                  return -EINTR;                  return -EINTR;
819  --- linux-source-2.6.18-22.orig/kernel/ptrace.c  --- linux-2.6.18-26etch2.orig/kernel/ptrace.c
820  +++ linux-source-2.6.18-22/kernel/ptrace.c  +++ linux-2.6.18-26etch2/kernel/ptrace.c
821  @@ -21,6 +21,9 @@  @@ -21,6 +21,7 @@
822    
823   #include <asm/pgtable.h>   #include <asm/pgtable.h>
824   #include <asm/uaccess.h>   #include <asm/uaccess.h>
825  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
826    
827   /*   /*
828    * ptrace a task: make the debugger its new parent and    * ptrace a task: make the debugger its new parent and
829  @@ -509,6 +512,12 @@ asmlinkage long sys_ptrace(long request,  @@ -509,6 +510,8 @@ asmlinkage long sys_ptrace(long request,
830          /*          /*
831           * This lock_kernel fixes a subtle race with suid exec           * This lock_kernel fixes a subtle race with suid exec
832           */           */
833  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +#ifdef TOMOYO_SYS_PTRACE  
 +       if (!ccs_capable(TOMOYO_SYS_PTRACE))  
834  +               return -EPERM;  +               return -EPERM;
 +#endif  
 +       /***** TOMOYO Linux end. *****/  
835          lock_kernel();          lock_kernel();
836          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
837                  ret = ptrace_traceme();                  ret = ptrace_traceme();
838  --- linux-source-2.6.18-22.orig/kernel/sched.c  --- linux-2.6.18-26etch2.orig/kernel/sched.c
839  +++ linux-source-2.6.18-22/kernel/sched.c  +++ linux-2.6.18-26etch2/kernel/sched.c
840  @@ -55,6 +55,9 @@  @@ -55,6 +55,7 @@
841   #include <asm/tlb.h>   #include <asm/tlb.h>
842    
843   #include <asm/unistd.h>   #include <asm/unistd.h>
844  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
845    
846   /*   /*
847    * Convert user-nice values [ -20 ... 0 ... 19 ]    * Convert user-nice values [ -20 ... 0 ... 19 ]
848  @@ -3939,6 +3942,10 @@ int can_nice(const struct task_struct *p  @@ -3939,6 +3940,8 @@ int can_nice(const struct task_struct *p
849   asmlinkage long sys_nice(int increment)   asmlinkage long sys_nice(int increment)
850   {   {
851          long nice, retval;          long nice, retval;
852  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_NICE))
 +       if (!ccs_capable(TOMOYO_SYS_NICE))  
853  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
854    
855          /*          /*
856           * Setpriority might change our priority at the same moment.           * Setpriority might change our priority at the same moment.
857  --- linux-source-2.6.18-22.orig/kernel/signal.c  --- linux-2.6.18-26etch2.orig/kernel/signal.c
858  +++ linux-source-2.6.18-22/kernel/signal.c  +++ linux-2.6.18-26etch2/kernel/signal.c
859  @@ -28,6 +28,9 @@  @@ -28,6 +28,7 @@
860   #include <asm/unistd.h>   #include <asm/unistd.h>
861   #include <asm/siginfo.h>   #include <asm/siginfo.h>
862   #include "audit.h"     /* audit_signal_info() */   #include "audit.h"     /* audit_signal_info() */
863  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
864    
865   /*   /*
866    * SLAB caches for signal bits.    * SLAB caches for signal bits.
867  @@ -2183,6 +2186,12 @@ asmlinkage long  @@ -2183,6 +2184,8 @@ asmlinkage long
868   sys_kill(int pid, int sig)   sys_kill(int pid, int sig)
869   {   {
870          struct siginfo info;          struct siginfo info;
871  +       /***** TOMOYO Linux start. *****/  +       if (ccs_kill_permission(pid, sig))
 +       if (sig && !ccs_capable(TOMOYO_SYS_KILL))  
 +               return -EPERM;  
 +       if (sig && ccs_check_signal_acl(sig, pid))  
872  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
873    
874          info.si_signo = sig;          info.si_signo = sig;
875          info.si_errno = 0;          info.si_errno = 0;
876  @@ -2241,6 +2250,12 @@ asmlinkage long sys_tgkill(int tgid, int  @@ -2241,6 +2244,8 @@ asmlinkage long sys_tgkill(int tgid, int
877          /* This is only valid for single tasks */          /* This is only valid for single tasks */
878          if (pid <= 0 || tgid <= 0)          if (pid <= 0 || tgid <= 0)
879                  return -EINVAL;                  return -EINVAL;
880  +       /***** TOMOYO Linux start. *****/  +       if (ccs_tgkill_permission(tgid, pid, sig))
 +       if (sig && !ccs_capable(TOMOYO_SYS_KILL))  
881  +               return -EPERM;  +               return -EPERM;
 +       if (sig && ccs_check_signal_acl(sig, pid))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
882    
883          return do_tkill(tgid, pid, sig);          return do_tkill(tgid, pid, sig);
884   }   }
885  @@ -2254,6 +2269,12 @@ sys_tkill(int pid, int sig)  @@ -2254,6 +2259,8 @@ sys_tkill(int pid, int sig)
886          /* This is only valid for single tasks */          /* This is only valid for single tasks */
887          if (pid <= 0)          if (pid <= 0)
888                  return -EINVAL;                  return -EINVAL;
889  +       /***** TOMOYO Linux start. *****/  +       if (ccs_tkill_permission(pid, sig))
 +       if (sig && !ccs_capable(TOMOYO_SYS_KILL))  
 +               return -EPERM;  
 +       if (sig && ccs_check_signal_acl(sig, pid))  
890  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
891    
892          return do_tkill(0, pid, sig);          return do_tkill(0, pid, sig);
893   }   }
894  --- linux-source-2.6.18-22.orig/kernel/sys.c  @@ -2271,6 +2278,8 @@ sys_rt_sigqueueinfo(int pid, int sig, si
895  +++ linux-source-2.6.18-22/kernel/sys.c          if (info.si_code >= 0)
896  @@ -36,6 +36,9 @@                  return -EPERM;
897            info.si_signo = sig;
898    +       if (ccs_sigqueue_permission(pid, sig))
899    +               return -EPERM;
900    
901            /* POSIX.1b doesn't mention process groups.  */
902            return kill_proc_info(sig, &info, pid);
903    --- linux-2.6.18-26etch2.orig/kernel/sys.c
904    +++ linux-2.6.18-26etch2/kernel/sys.c
905    @@ -36,6 +36,7 @@
906   #include <asm/uaccess.h>   #include <asm/uaccess.h>
907   #include <asm/io.h>   #include <asm/io.h>
908   #include <asm/unistd.h>   #include <asm/unistd.h>
909  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
910    
911   #ifndef SET_UNALIGN_CTL   #ifndef SET_UNALIGN_CTL
912   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)
913  @@ -467,6 +470,12 @@ asmlinkage long sys_setpriority(int whic  @@ -467,6 +468,10 @@ asmlinkage long sys_setpriority(int whic
914    
915          if (which > 2 || which < 0)          if (which > 2 || which < 0)
916                  goto out;                  goto out;
917  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_NICE)) {
 +       if (!ccs_capable(TOMOYO_SYS_NICE)) {  
918  +               error = -EPERM;  +               error = -EPERM;
919  +               goto out;  +               goto out;
920  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
921    
922          /* normalize: avoid signed division (rounding problems) */          /* normalize: avoid signed division (rounding problems) */
923          error = -ESRCH;          error = -ESRCH;
924  @@ -693,6 +702,10 @@ asmlinkage long sys_reboot(int magic1, i  @@ -693,6 +698,8 @@ asmlinkage long sys_reboot(int magic1, i
925                          magic2 != LINUX_REBOOT_MAGIC2B &&                          magic2 != LINUX_REBOOT_MAGIC2B &&
926                          magic2 != LINUX_REBOOT_MAGIC2C))                          magic2 != LINUX_REBOOT_MAGIC2C))
927                  return -EINVAL;                  return -EINVAL;
928  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_REBOOT))
 +       if (!ccs_capable(TOMOYO_SYS_REBOOT))  
929  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
930    
931          /* Instead of trying to make the power_off code look like          /* Instead of trying to make the power_off code look like
932           * 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.
933  @@ -1690,6 +1703,10 @@ asmlinkage long sys_sethostname(char __u  @@ -1690,6 +1697,8 @@ asmlinkage long sys_sethostname(char __u
934                  return -EPERM;                  return -EPERM;
935          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
936                  return -EINVAL;                  return -EINVAL;
937  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
 +       if (!ccs_capable(TOMOYO_SYS_SETHOSTNAME))  
938  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
939          down_write(&uts_sem);          down_write(&uts_sem);
940          errno = -EFAULT;          errno = -EFAULT;
941          if (!copy_from_user(tmp, name, len)) {          if (!copy_from_user(tmp, name, len)) {
942  @@ -1735,6 +1752,10 @@ asmlinkage long sys_setdomainname(char _  @@ -1735,6 +1744,8 @@ asmlinkage long sys_setdomainname(char _
943                  return -EPERM;                  return -EPERM;
944          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
945                  return -EINVAL;                  return -EINVAL;
946  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
 +       if (!ccs_capable(TOMOYO_SYS_SETHOSTNAME))  
947  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
948    
949          down_write(&uts_sem);          down_write(&uts_sem);
950          errno = -EFAULT;          errno = -EFAULT;
951  --- linux-source-2.6.18-22.orig/kernel/sysctl.c  --- linux-2.6.18-26etch2.orig/kernel/sysctl.c
952  +++ linux-source-2.6.18-22/kernel/sysctl.c  +++ linux-2.6.18-26etch2/kernel/sysctl.c
953  @@ -48,6 +48,9 @@  @@ -48,6 +48,7 @@
954    
955   #include <asm/uaccess.h>   #include <asm/uaccess.h>
956   #include <asm/processor.h>   #include <asm/processor.h>
957  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
958    
959   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,
960                        void __user *buffer, size_t *lenp, loff_t *ppos);                        void __user *buffer, size_t *lenp, loff_t *ppos);
961  @@ -1144,6 +1147,100 @@ void __init sysctl_init(void)  @@ -1169,6 +1170,9 @@ int do_sysctl(int __user *name, int nlen
  #endif  
  }  
   
 +/***** TOMOYO Linux start. *****/  
 +static int try_parse_table(int __user *name, int nlen, void __user *oldval,  
 +                          void __user *newval, ctl_table *table)  
 +{  
 +       int n;  
 +       int error = -ENOMEM;  
 +       int op = 0;  
 +       char *buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);  
 +       if (oldval)  
 +               op |= 004;  
 +       if (newval)  
 +               op |= 002;  
 +       if (!op) { /* Neither read nor write */  
 +               error = 0;  
 +               goto out;  
 +       }  
 +       if (!buffer)  
 +               goto out;  
 +       memset(buffer, 0, PAGE_SIZE);  
 +       snprintf(buffer, PAGE_SIZE - 1, "/proc/sys");  
 + repeat:  
 +       if (!nlen) {  
 +               error = -ENOTDIR;  
 +               goto out;  
 +       }  
 +       if (get_user(n, name)) {  
 +               error = -EFAULT;  
 +               goto out;  
 +       }  
 +       for ( ; table->ctl_name; table++) {  
 +               if (n == table->ctl_name || table->ctl_name == CTL_ANY) {  
 +                       int pos = strlen(buffer);  
 +                       const char *cp = table->procname;  
 +                       error = -ENOMEM;  
 +                       if (cp) {  
 +                               if (pos + 1 >= PAGE_SIZE - 1)  
 +                                       goto out;  
 +                               buffer[pos++] = '/';  
 +                               while (*cp) {  
 +                                       const unsigned char c  
 +                                               = *(const unsigned char *) cp;  
 +                                       if (c == '\\') {  
 +                                               if (pos + 2 >= PAGE_SIZE - 1)  
 +                                                       goto out;  
 +                                               buffer[pos++] = '\\';  
 +                                               buffer[pos++] = '\\';  
 +                                       } else if (c > ' ' && c < 127) {  
 +                                               if (pos + 1 >= PAGE_SIZE - 1)  
 +                                                       goto out;  
 +                                               buffer[pos++] = c;  
 +                                       } else {  
 +                                               if (pos + 4 >= PAGE_SIZE - 1)  
 +                                                       goto out;  
 +                                               buffer[pos++] = '\\';  
 +                                               buffer[pos++] = (c >> 6) + '0';  
 +                                               buffer[pos++] = ((c >> 3) & 7)  
 +                                                       + '0';  
 +                                               buffer[pos++] = (c & 7) + '0';  
 +                                       }  
 +                                       cp++;  
 +                               }  
 +                       } else {  
 +                               /* Assume nobody assigns "=\$=" for procname. */  
 +                               snprintf(buffer + pos, PAGE_SIZE - pos - 1,  
 +                                        "/=%d=", table->ctl_name);  
 +                               if (!memchr(buffer, '\0', PAGE_SIZE - 2))  
 +                                       goto out;  
 +                       }  
 +                       if (table->child) {  
 +                               if (table->strategy) {  
 +                                       /* printk("sysctl='%s'\n", buffer); */  
 +                                       if (ccs_check_file_perm(buffer, op,  
 +                                                               "sysctl")) {  
 +                                               error = -EPERM;  
 +                                               goto out;  
 +                                       }  
 +                               }  
 +                               name++;  
 +                               nlen--;  
 +                               table = table->child;  
 +                               goto repeat;  
 +                       }  
 +                       /* printk("sysctl='%s'\n", buffer); */  
 +                       error = ccs_check_file_perm(buffer, op, "sysctl");  
 +                       goto out;  
 +               }  
 +       }  
 +       error = -ENOTDIR;  
 + out:  
 +       kfree(buffer);  
 +       return error;  
 +}  
 +/***** TOMOYO Linux end. *****/  
 +  
  int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,  
                void __user *newval, size_t newlen)  
  {  
 @@ -1169,6 +1266,11 @@ int do_sysctl(int __user *name, int nlen  
962    
963                  spin_unlock(&sysctl_lock);                  spin_unlock(&sysctl_lock);
964    
965  +               /***** TOMOYO Linux start. *****/  +               error = ccs_parse_table(name, nlen, oldval, newval,
 +               error = try_parse_table(name, nlen, oldval, newval,  
966  +                                       head->ctl_table);  +                                       head->ctl_table);
967  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
968                  error = parse_table(name, nlen, oldval, oldlenp,                  error = parse_table(name, nlen, oldval, oldlenp,
969                                          newval, newlen, head->ctl_table,                                          newval, newlen, head->ctl_table,
970                                          &context);                                          &context);
971  @@ -1241,6 +1343,15 @@ repeat:  @@ -1241,6 +1245,13 @@ repeat:
972                                  if (ctl_perm(table, 001))                                  if (ctl_perm(table, 001))
973                                          return -EPERM;                                          return -EPERM;
974                                  if (table->strategy) {                                  if (table->strategy) {
 +                                       /***** TOMOYO Linux start. *****/  
975  +                                       int op = 0;  +                                       int op = 0;
976  +                                       if (oldval)  +                                       if (oldval)
977  +                                               op |= 004;  +                                               op |= 004;
# Line 1382  Source code for this patch is "apt-get i Line 979  Source code for this patch is "apt-get i
979  +                                               op |= 002;  +                                               op |= 002;
980  +                                       if (ctl_perm(table, op))  +                                       if (ctl_perm(table, op))
981  +                                               return -EPERM;  +                                               return -EPERM;
 +                                       /***** TOMOYO Linux end. *****/  
982                                          error = table->strategy(                                          error = table->strategy(
983                                                  table, name, nlen,                                                  table, name, nlen,
984                                                  oldval, oldlenp,                                                  oldval, oldlenp,
985  --- linux-source-2.6.18-22.orig/kernel/time.c  --- linux-2.6.18-26etch2.orig/kernel/time.c
986  +++ linux-source-2.6.18-22/kernel/time.c  +++ linux-2.6.18-26etch2/kernel/time.c
987  @@ -39,6 +39,9 @@  @@ -39,6 +39,7 @@
988    
989   #include <asm/uaccess.h>   #include <asm/uaccess.h>
990   #include <asm/unistd.h>   #include <asm/unistd.h>
991  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
992    
993   /*   /*
994    * 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
995  @@ -91,6 +94,10 @@ asmlinkage long sys_stime(time_t __user  @@ -91,6 +92,8 @@ asmlinkage long sys_stime(time_t __user
996          err = security_settime(&tv, NULL);          err = security_settime(&tv, NULL);
997          if (err)          if (err)
998                  return err;                  return err;
999  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_SETTIME))
 +       if (!ccs_capable(TOMOYO_SYS_SETTIME))  
1000  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1001    
1002          do_settimeofday(&tv);          do_settimeofday(&tv);
1003          return 0;          return 0;
1004  @@ -161,6 +168,10 @@ int do_sys_settimeofday(struct timespec  @@ -161,6 +164,8 @@ int do_sys_settimeofday(struct timespec
1005          error = security_settime(tv, tz);          error = security_settime(tv, tz);
1006          if (error)          if (error)
1007                  return error;                  return error;
1008  +       /***** TOMOYO Linux start. *****/  +       if (!ccs_capable(CCS_SYS_SETTIME))
 +       if (!ccs_capable(TOMOYO_SYS_SETTIME))  
1009  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1010    
1011          if (tz) {          if (tz) {
1012                  /* SMP safe, global irq locking makes it work. */                  /* SMP safe, global irq locking makes it work. */
1013  @@ -221,6 +232,10 @@ int do_adjtimex(struct timex *txc)  @@ -221,6 +226,8 @@ int do_adjtimex(struct timex *txc)
1014          /* In order to modify anything, you gotta be super-user! */          /* In order to modify anything, you gotta be super-user! */
1015          if (txc->modes && !capable(CAP_SYS_TIME))          if (txc->modes && !capable(CAP_SYS_TIME))
1016                  return -EPERM;                  return -EPERM;
1017  +       /***** TOMOYO Linux start. *****/  +       if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
 +       if (txc->modes && !ccs_capable(TOMOYO_SYS_SETTIME))  
1018  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1019                                    
1020          /* Now we validate the data before disabling interrupts */          /* Now we validate the data before disabling interrupts */
1021    
1022  --- linux-source-2.6.18-22.orig/net/core/datagram.c  --- linux-2.6.18-26etch2.orig/net/ipv4/inet_connection_sock.c
1023  +++ linux-source-2.6.18-22/net/core/datagram.c  +++ linux-2.6.18-26etch2/net/ipv4/inet_connection_sock.c
1024  @@ -56,6 +56,11 @@  @@ -23,6 +23,7 @@
  #include <net/sock.h>  
  #include <net/tcp_states.h>  
   
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +#include <linux/tomoyo_socket.h>  
 +/***** TOMOYO Linux end. *****/  
 +  
  /*  
   *     Is a socket 'connection oriented' ?  
   */  
 @@ -178,6 +183,12 @@ struct sk_buff *skb_recv_datagram(struct  
                 } else  
                         skb = skb_dequeue(&sk->sk_receive_queue);  
   
 +               /***** TOMOYO Linux start. *****/  
 +               error = ccs_socket_recv_datagram_permission(sk, skb, flags);  
 +               if (error)  
 +                       goto no_packet;  
 +               /***** TOMOYO Linux end. *****/  
 +  
                 if (skb)  
                         return skb;  
   
 --- linux-source-2.6.18-22.orig/net/ipv4/inet_connection_sock.c  
 +++ linux-source-2.6.18-22/net/ipv4/inet_connection_sock.c  
 @@ -23,6 +23,9 @@  
1025   #include <net/route.h>   #include <net/route.h>
1026   #include <net/tcp_states.h>   #include <net/tcp_states.h>
1027   #include <net/xfrm.h>   #include <net/xfrm.h>
1028  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1029    
1030   #ifdef INET_CSK_DEBUG   #ifdef INET_CSK_DEBUG
1031   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";
1032  @@ -87,6 +90,10 @@ int inet_csk_get_port(struct inet_hashin  @@ -87,6 +88,8 @@ int inet_csk_get_port(struct inet_hashin
1033                  do {                  do {
1034                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
1035                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1036  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(rover))
 +                       if (ccs_may_autobind(rover))  
1037  +                               goto next;  +                               goto next;
 +                       /***** SAKURA Linux end. *****/  
1038                          inet_bind_bucket_for_each(tb, node, &head->chain)                          inet_bind_bucket_for_each(tb, node, &head->chain)
1039                                  if (tb->port == rover)                                  if (tb->port == rover)
1040                                          goto next;                                          goto next;
1041  --- linux-source-2.6.18-22.orig/net/ipv4/inet_hashtables.c  --- linux-2.6.18-26etch2.orig/net/ipv4/inet_hashtables.c
1042  +++ linux-source-2.6.18-22/net/ipv4/inet_hashtables.c  +++ linux-2.6.18-26etch2/net/ipv4/inet_hashtables.c
1043  @@ -22,6 +22,9 @@  @@ -22,6 +22,7 @@
1044   #include <net/inet_connection_sock.h>   #include <net/inet_connection_sock.h>
1045   #include <net/inet_hashtables.h>   #include <net/inet_hashtables.h>
1046   #include <net/ip.h>   #include <net/ip.h>
1047  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1048    
1049   /*   /*
1050    * Allocate and initialize a new local port bind bucket.    * Allocate and initialize a new local port bind bucket.
1051  @@ -263,6 +266,10 @@ int inet_hash_connect(struct inet_timewa  @@ -263,6 +264,8 @@ int inet_hash_connect(struct inet_timewa
1052                  local_bh_disable();                  local_bh_disable();
1053                  for (i = 1; i <= range; i++) {                  for (i = 1; i <= range; i++) {
1054                          port = low + (i + offset) % range;                          port = low + (i + offset) % range;
1055  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(port))
 +                       if (ccs_may_autobind(port))  
1056  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1057                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
1058                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1059    
1060  --- linux-source-2.6.18-22.orig/net/ipv4/udp.c  --- linux-2.6.18-26etch2.orig/net/ipv4/raw.c
1061  +++ linux-source-2.6.18-22/net/ipv4/udp.c  +++ linux-2.6.18-26etch2/net/ipv4/raw.c
1062  @@ -108,6 +108,9 @@  @@ -79,6 +79,7 @@
1063     #include <linux/seq_file.h>
1064     #include <linux/netfilter.h>
1065     #include <linux/netfilter_ipv4.h>
1066    +#include <linux/ccsecurity.h>
1067    
1068     struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE];
1069     DEFINE_RWLOCK(raw_v4_lock);
1070    @@ -589,9 +590,14 @@ static int raw_recvmsg(struct kiocb *ioc
1071                    goto out;
1072            }
1073    
1074    -       skb = skb_recv_datagram(sk, flags, noblock, &err);
1075    -       if (!skb)
1076    -               goto out;
1077    +       for (;;) {
1078    +               skb = skb_recv_datagram(sk, flags, noblock, &err);
1079    +               if (!skb)
1080    +                       goto out;
1081    +               if (!ccs_socket_post_recvmsg_permission(sk, skb))
1082    +                       break;
1083    +               skb_kill_datagram(sk, skb, flags);
1084    +       }
1085    
1086            copied = skb->len;
1087            if (len < copied) {
1088    --- linux-2.6.18-26etch2.orig/net/ipv4/udp.c
1089    +++ linux-2.6.18-26etch2/net/ipv4/udp.c
1090    @@ -108,6 +108,7 @@
1091   #include <net/inet_common.h>   #include <net/inet_common.h>
1092   #include <net/checksum.h>   #include <net/checksum.h>
1093   #include <net/xfrm.h>   #include <net/xfrm.h>
1094  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1095    
1096   /*   /*
1097    *     Snmp MIB for the UDP layer    *     Snmp MIB for the UDP layer
1098  @@ -146,6 +149,10 @@ static int udp_v4_get_port(struct sock *  @@ -146,6 +147,8 @@ static int udp_v4_get_port(struct sock *
1099                                          result = sysctl_local_port_range[0] +                                          result = sysctl_local_port_range[0] +
1100                                                  ((result - sysctl_local_port_range[0]) &                                                  ((result - sysctl_local_port_range[0]) &
1101                                                   (UDP_HTABLE_SIZE - 1));                                                   (UDP_HTABLE_SIZE - 1));
1102  +                               /***** SAKURA Linux start. *****/  +                               if (ccs_lport_reserved(result))
 +                               if (ccs_may_autobind(result))  
1103  +                                       continue;  +                                       continue;
 +                               /***** SAKURA Linux end. *****/  
1104                                  goto gotit;                                  goto gotit;
1105                          }                          }
1106                          size = 0;                          size = 0;
1107  @@ -162,6 +169,10 @@ static int udp_v4_get_port(struct sock *  @@ -162,6 +165,8 @@ static int udp_v4_get_port(struct sock *
1108                                  result = sysctl_local_port_range[0]                                  result = sysctl_local_port_range[0]
1109                                          + ((result - sysctl_local_port_range[0]) &                                          + ((result - sysctl_local_port_range[0]) &
1110                                             (UDP_HTABLE_SIZE - 1));                                             (UDP_HTABLE_SIZE - 1));
1111  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(result))
 +                       if (ccs_may_autobind(result))  
1112  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1113                          if (!udp_lport_inuse(result))                          if (!udp_lport_inuse(result))
1114                                  break;                                  break;
1115                  }                  }
1116  --- linux-source-2.6.18-22.orig/net/ipv6/inet6_hashtables.c  @@ -782,6 +787,7 @@ static int udp_recvmsg(struct kiocb *ioc
1117  +++ linux-source-2.6.18-22/net/ipv6/inet6_hashtables.c          struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name;
1118  @@ -21,6 +21,9 @@          struct sk_buff *skb;
1119            int copied, err;
1120    +       _Bool update_stat;
1121    
1122            /*
1123             *      Check any passed addresses
1124    @@ -796,7 +802,12 @@ try_again:
1125            skb = skb_recv_datagram(sk, flags, noblock, &err);
1126            if (!skb)
1127                    goto out;
1128    -  
1129    +       if (ccs_socket_post_recvmsg_permission(sk, skb)) {
1130    +               update_stat = 0;
1131    +               goto csum_copy_err;
1132    +       }
1133    +       update_stat = 1;
1134    +
1135            copied = skb->len - sizeof(struct udphdr);
1136            if (copied > len) {
1137                    copied = len;
1138    @@ -844,7 +855,8 @@ out:
1139            return err;
1140    
1141     csum_copy_err:
1142    -       UDP_INC_STATS_BH(UDP_MIB_INERRORS);
1143    +       if (update_stat)
1144    +               UDP_INC_STATS_BH(UDP_MIB_INERRORS);
1145    
1146            skb_kill_datagram(sk, skb, flags);
1147    
1148    --- linux-2.6.18-26etch2.orig/net/ipv6/inet6_hashtables.c
1149    +++ linux-2.6.18-26etch2/net/ipv6/inet6_hashtables.c
1150    @@ -21,6 +21,7 @@
1151   #include <net/inet_hashtables.h>   #include <net/inet_hashtables.h>
1152   #include <net/inet6_hashtables.h>   #include <net/inet6_hashtables.h>
1153   #include <net/ip.h>   #include <net/ip.h>
1154  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1155    
1156   void __inet6_hash(struct inet_hashinfo *hashinfo,   void __inet6_hash(struct inet_hashinfo *hashinfo,
1157                                  struct sock *sk)                                  struct sock *sk)
1158  @@ -172,7 +175,7 @@ static int __inet6_check_established(str  @@ -172,7 +173,7 @@ static int __inet6_check_established(str
1159          const struct in6_addr *saddr = &np->daddr;          const struct in6_addr *saddr = &np->daddr;
1160          const int dif = sk->sk_bound_dev_if;          const int dif = sk->sk_bound_dev_if;
1161          const u32 ports = INET_COMBINED_PORTS(inet->dport, lport);          const u32 ports = INET_COMBINED_PORTS(inet->dport, lport);
# Line 1559  Source code for this patch is "apt-get i Line 1164  Source code for this patch is "apt-get i
1164                                                  inet->dport);                                                  inet->dport);
1165          struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash);          struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash);
1166          struct sock *sk2;          struct sock *sk2;
1167  @@ -266,6 +269,10 @@ int inet6_hash_connect(struct inet_timew  @@ -266,6 +267,8 @@ int inet6_hash_connect(struct inet_timew
1168                  local_bh_disable();                  local_bh_disable();
1169                  for (i = 1; i <= range; i++) {                  for (i = 1; i <= range; i++) {
1170                          port = low + (i + offset) % range;                          port = low + (i + offset) % range;
1171  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(port))
 +                       if (ccs_may_autobind(port))  
1172  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1173                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
1174                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1175    
1176  --- linux-source-2.6.18-22.orig/net/ipv6/udp.c  --- linux-2.6.18-26etch2.orig/net/ipv6/raw.c
1177  +++ linux-source-2.6.18-22/net/ipv6/udp.c  +++ linux-2.6.18-26etch2/net/ipv6/raw.c
1178  @@ -58,6 +58,9 @@  @@ -56,6 +56,7 @@
1179    
1180   #include <linux/proc_fs.h>   #include <linux/proc_fs.h>
1181   #include <linux/seq_file.h>   #include <linux/seq_file.h>
1182  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
1183  +#include <linux/sakura.h>  
1184  +/***** SAKURA Linux end. *****/   struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE];
1185     DEFINE_RWLOCK(raw_v6_lock);
1186    @@ -384,9 +385,14 @@ static int rawv6_recvmsg(struct kiocb *i
1187            if (flags & MSG_ERRQUEUE)
1188                    return ipv6_recv_error(sk, msg, len);
1189    
1190    -       skb = skb_recv_datagram(sk, flags, noblock, &err);
1191    -       if (!skb)
1192    -               goto out;
1193    +       for (;;) {
1194    +               skb = skb_recv_datagram(sk, flags, noblock, &err);
1195    +               if (!skb)
1196    +                       goto out;
1197    +               if (!ccs_socket_post_recvmsg_permission(sk, skb))
1198    +                       break;
1199    +               skb_kill_datagram(sk, skb, flags);
1200    +       }
1201    
1202            copied = skb->len;
1203            if (copied > len) {
1204    --- linux-2.6.18-26etch2.orig/net/ipv6/udp.c
1205    +++ linux-2.6.18-26etch2/net/ipv6/udp.c
1206    @@ -58,6 +58,7 @@
1207    
1208     #include <linux/proc_fs.h>
1209     #include <linux/seq_file.h>
1210    +#include <linux/ccsecurity.h>
1211    
1212   DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;   DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
1213    
1214  @@ -88,6 +91,10 @@ static int udp_v6_get_port(struct sock *  @@ -88,6 +89,8 @@ static int udp_v6_get_port(struct sock *
1215                                          result = sysctl_local_port_range[0] +                                          result = sysctl_local_port_range[0] +
1216                                                  ((result - sysctl_local_port_range[0]) &                                                  ((result - sysctl_local_port_range[0]) &
1217                                                   (UDP_HTABLE_SIZE - 1));                                                   (UDP_HTABLE_SIZE - 1));
1218  +                               /***** SAKURA Linux start. *****/  +                               if (ccs_lport_reserved(result))
 +                               if (ccs_may_autobind(result))  
1219  +                                       continue;  +                                       continue;
 +                               /***** SAKURA Linux end. *****/  
1220                                  goto gotit;                                  goto gotit;
1221                          }                          }
1222                          size = 0;                          size = 0;
1223  @@ -104,6 +111,10 @@ static int udp_v6_get_port(struct sock *  @@ -104,6 +107,8 @@ static int udp_v6_get_port(struct sock *
1224                                  result = sysctl_local_port_range[0]                                  result = sysctl_local_port_range[0]
1225                                          + ((result - sysctl_local_port_range[0]) &                                          + ((result - sysctl_local_port_range[0]) &
1226                                             (UDP_HTABLE_SIZE - 1));                                             (UDP_HTABLE_SIZE - 1));
1227  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(result))
 +                       if (ccs_may_autobind(result))  
1228  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1229                          if (!udp_lport_inuse(result))                          if (!udp_lport_inuse(result))
1230                                  break;                                  break;
1231                  }                  }
1232  --- linux-source-2.6.18-22.orig/net/socket.c  @@ -226,6 +231,7 @@ static int udpv6_recvmsg(struct kiocb *i
1233  +++ linux-source-2.6.18-22/net/socket.c          struct sk_buff *skb;
1234  @@ -94,6 +94,11 @@          size_t copied;
1235            int err;
1236    +       _Bool update_stat;
1237    
1238            if (addr_len)
1239                    *addr_len=sizeof(struct sockaddr_in6);
1240    @@ -237,6 +243,11 @@ try_again:
1241            skb = skb_recv_datagram(sk, flags, noblock, &err);
1242            if (!skb)
1243                    goto out;
1244    +       if (ccs_socket_post_recvmsg_permission(sk, skb)) {
1245    +               update_stat = 0;
1246    +               goto csum_copy_err;
1247    +       }
1248    +       update_stat = 1;
1249    
1250            copied = skb->len - sizeof(struct udphdr);
1251            if (copied > len) {
1252    @@ -303,7 +314,8 @@ csum_copy_err:
1253            skb_kill_datagram(sk, skb, flags);
1254    
1255            if (flags & MSG_DONTWAIT) {
1256    -               UDP6_INC_STATS_USER(UDP_MIB_INERRORS);
1257    +               if (update_stat)
1258    +                       UDP6_INC_STATS_USER(UDP_MIB_INERRORS);
1259                    return -EAGAIN;
1260            }
1261            goto try_again;
1262    --- linux-2.6.18-26etch2.orig/net/socket.c
1263    +++ linux-2.6.18-26etch2/net/socket.c
1264    @@ -94,6 +94,8 @@
1265   #include <net/sock.h>   #include <net/sock.h>
1266   #include <linux/netfilter.h>   #include <linux/netfilter.h>
1267    
1268  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +#include <linux/tomoyo_socket.h>  
 +/***** TOMOYO Linux end. *****/  
1269  +  +
1270   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
1271   static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf,   static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf,
1272                           size_t size, loff_t pos);                           size_t size, loff_t pos);
1273  @@ -592,7 +597,12 @@ static inline int __sock_sendmsg(struct  @@ -590,9 +592,10 @@ static inline int __sock_sendmsg(struct
1274            si->size = size;
1275    
1276          err = security_socket_sendmsg(sock, msg, size);          err = security_socket_sendmsg(sock, msg, size);
1277    +       if (!err)
1278    +               err = ccs_socket_sendmsg_permission(sock, msg, size);
1279          if (err)          if (err)
1280                  return err;                  return err;
1281  -  -
 +       /***** TOMOYO Linux start. *****/  
 +       if (ccs_socket_sendmsg_permission(sock,  
 +                                         (struct sockaddr *) msg->msg_name,  
 +                                         msg->msg_namelen))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
1282          return sock->ops->sendmsg(iocb, sock, msg, size);          return sock->ops->sendmsg(iocb, sock, msg, size);
1283   }   }
1284    
1285  @@ -1148,6 +1158,12 @@ static int __sock_create(int family, int  @@ -1149,6 +1152,8 @@ static int __sock_create(int family, int
                 family = PF_PACKET;  
1286          }          }
1287    
 +       /***** TOMOYO Linux start. *****/  
 +       err = ccs_socket_create_permission(family, type, protocol);  
 +       if (err)  
 +               return err;  
 +       /***** TOMOYO Linux end. *****/  
 +  
1288          err = security_socket_create(family, type, protocol, kern);          err = security_socket_create(family, type, protocol, kern);
1289    +       if (!err)
1290    +               err = ccs_socket_create_permission(family, type, protocol);
1291          if (err)          if (err)
1292                  return err;                  return err;
1293  @@ -1342,6 +1358,13 @@ asmlinkage long sys_bind(int fd, struct                  
1294          {  @@ -1343,6 +1348,11 @@ asmlinkage long sys_bind(int fd, struct
1295                  if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0) {                  if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0) {
1296                          err = security_socket_bind(sock, (struct sockaddr *)address, addrlen);                          err = security_socket_bind(sock, (struct sockaddr *)address, addrlen);
1297  +                       /***** TOMOYO Linux start. *****/                          if (!err)
 +                       if (!err)  
1298  +                               err = ccs_socket_bind_permission(sock,  +                               err = ccs_socket_bind_permission(sock,
1299  +                                                        (struct sockaddr *)  +                                                        (struct sockaddr *)
1300  +                                                                address,  +                                                                address,
1301  +                                                                addrlen);  +                                                                addrlen);
1302  +                       /***** TOMOYO Linux end. *****/  +                       if (!err)
                         if (!err)  
1303                                  err = sock->ops->bind(sock,                                  err = sock->ops->bind(sock,
1304                                          (struct sockaddr *)address, addrlen);                                          (struct sockaddr *)address, addrlen);
1305  @@ -1370,6 +1393,10 @@ asmlinkage long sys_listen(int fd, int b                  }
1306                          backlog = sysctl_somaxconn;  @@ -1371,6 +1381,8 @@ asmlinkage long sys_listen(int fd, int b
1307    
1308                  err = security_socket_listen(sock, backlog);                  err = security_socket_listen(sock, backlog);
 +               /***** TOMOYO Linux start. *****/  
 +               if (!err)  
 +                       err = ccs_socket_listen_permission(sock);  
 +               /***** TOMOYO Linux end. *****/  
1309                  if (!err)                  if (!err)
1310    +                       err = ccs_socket_listen_permission(sock);
1311    +               if (!err)
1312                          err = sock->ops->listen(sock, backlog);                          err = sock->ops->listen(sock, backlog);
1313    
1314  @@ -1434,6 +1461,13 @@ asmlinkage long sys_accept(int fd, struc                  fput_light(sock->file, fput_needed);
1315    @@ -1402,6 +1414,7 @@ asmlinkage long sys_accept(int fd, struc
1316            if (!sock)
1317                    goto out;
1318    
1319    +retry:
1320            err = -ENFILE;
1321            if (!(newsock = sock_alloc()))
1322                    goto out_put;
1323    @@ -1434,6 +1447,11 @@ asmlinkage long sys_accept(int fd, struc
1324          if (err < 0)          if (err < 0)
1325                  goto out_fd;                  goto out_fd;
1326    
1327  +       /***** TOMOYO Linux start. *****/  +       if (ccs_socket_post_accept_permission(sock, newsock)) {
1328  +       if (ccs_socket_accept_permission(newsock,  +               fput(newfile);
1329  +                                        (struct sockaddr *) address)) {  +               put_unused_fd(newfd);
1330  +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */  +               goto retry;
 +               goto out_fd;  
1331  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
1332          if (upeer_sockaddr) {          if (upeer_sockaddr) {
1333                  if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {                  if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {
1334                          err = -ECONNABORTED;                          err = -ECONNABORTED;
1335  @@ -1490,7 +1524,12 @@ asmlinkage long sys_connect(int fd, stru  @@ -1488,9 +1506,11 @@ asmlinkage long sys_connect(int fd, stru
1336                    goto out_put;
1337    
1338          err = security_socket_connect(sock, (struct sockaddr *)address, addrlen);          err = security_socket_connect(sock, (struct sockaddr *)address, addrlen);
1339    +       if (!err)
1340    +               err = ccs_socket_connect_permission(sock, (struct sockaddr *)
1341    +                                                   address, addrlen);
1342          if (err)          if (err)
1343                  goto out_put;                  goto out_put;
1344  -  -
 +       /***** TOMOYO Linux start. *****/  
 +       err = ccs_socket_connect_permission(sock, (struct sockaddr *) address,  
 +                                           addrlen);  
 +       if (err)  
 +               goto out_put;  
 +       /***** TOMOYO Linux end. *****/  
1345          err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,          err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,
1346                                   sock->file->f_flags);                                   sock->file->f_flags);
1347   out_put:   out_put:
1348  --- linux-source-2.6.18-22.orig/net/unix/af_unix.c  --- linux-2.6.18-26etch2.orig/net/unix/af_unix.c
1349  +++ linux-source-2.6.18-22/net/unix/af_unix.c  +++ linux-2.6.18-26etch2/net/unix/af_unix.c
1350  @@ -116,6 +116,9 @@  @@ -116,6 +116,7 @@
1351   #include <linux/mount.h>   #include <linux/mount.h>
1352   #include <net/checksum.h>   #include <net/checksum.h>
1353   #include <linux/security.h>   #include <linux/security.h>
1354  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
1355    
1356   int sysctl_unix_max_dgram_qlen = 10;   int sysctl_unix_max_dgram_qlen = 10;
1357    
1358  @@ -764,6 +767,11 @@ static int unix_bind(struct socket *sock  @@ -807,6 +808,9 @@ static int unix_bind(struct socket *sock
                 err = unix_autobind(sock);  
                 goto out;  
         }  
 +       /***** TOMOYO Linux start. *****/  
 +       err = -EPERM;  
 +       if (sunaddr->sun_path[0] && !ccs_capable(TOMOYO_CREATE_UNIX_SOCKET))  
 +               goto out;  
 +       /***** TOMOYO Linux end. *****/  
   
         err = unix_mkname(sunaddr, addr_len, &hash);  
         if (err < 0)  
 @@ -807,6 +815,13 @@ static int unix_bind(struct socket *sock  
1359                   */                   */
1360                  mode = S_IFSOCK |                  mode = S_IFSOCK |
1361                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
1362  +               /***** TOMOYO Linux start. *****/  +               err = ccs_mknod_permission(nd.dentry->d_inode, dentry, nd.mnt,
1363  +               err = pre_vfs_mknod(nd.dentry->d_inode, dentry, mode);  +                                          mode, 0);
 +               if (!err)  
 +                       err = ccs_check_1path_perm(TYPE_MKSOCK_ACL, dentry,  
 +                                                  nd.mnt);  
1364  +               if (!err)  +               if (!err)
 +               /***** TOMOYO Linux end. *****/  
1365                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
1366                  if (err)                  if (err)
1367                          goto out_mknod_dput;                          goto out_mknod_dput;
1368    --- linux-2.6.18-26etch2.orig/security/Kconfig
1369    +++ linux-2.6.18-26etch2/security/Kconfig
1370    @@ -107,5 +107,7 @@ config SECURITY_SECLVL
1371    
1372     source security/selinux/Kconfig
1373    
1374    +source security/ccsecurity/Kconfig
1375    +
1376     endmenu
1377    
1378    --- linux-2.6.18-26etch2.orig/security/Makefile
1379    +++ linux-2.6.18-26etch2/security/Makefile
1380    @@ -17,3 +17,6 @@ obj-$(CONFIG_SECURITY_SELINUX)                += selin
1381     obj-$(CONFIG_SECURITY_CAPABILITIES)    += commoncap.o capability.o
1382     obj-$(CONFIG_SECURITY_ROOTPLUG)                += commoncap.o root_plug.o
1383     obj-$(CONFIG_SECURITY_SECLVL)          += seclvl.o
1384    +
1385    +subdir-$(CONFIG_CCSECURITY)+= ccsecurity
1386    +obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o

Legend:
Removed from v.1498  
changed lines
  Added in v.3838

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