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

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

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

Legend:
Removed from v.2513  
changed lines
  Added in v.2851

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