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

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

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

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