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

Subversion リポジトリの参照

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

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

trunk/1.6.x/ccs-patch/patches/ccs-patch-2.6.21.diff revision 2297 by kumaneko, Mon Mar 23 00:46:34 2009 UTC trunk/1.7.x/ccs-patch/patches/ccs-patch-2.6.21.diff revision 3009 by kumaneko, Thu Sep 10 05:40:52 2009 UTC
# Line 2  This is TOMOYO Linux patch for kernel 2. Line 2  This is TOMOYO Linux patch for kernel 2.
2    
3  Source code for this patch is http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.21.7.tar.bz2  Source code for this patch is http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.21.7.tar.bz2
4  ---  ---
5   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/attr.c                       |    5 +++++
16   fs/Makefile                     |    2   fs/compat.c                     |    9 ++++++++-
17   fs/attr.c                       |   19 ++++++++   fs/exec.c                       |   11 ++++++++++-
18   fs/compat.c                     |   15 +++++-   fs/fcntl.c                      |    4 ++++
19   fs/exec.c                       |   20 ++++++++   fs/ioctl.c                      |    5 +++++
20   fs/fcntl.c                      |    9 +++   fs/namei.c                      |   31 ++++++++++++++++++++++++++++++-
21   fs/ioctl.c                      |   11 ++++   fs/namespace.c                  |   23 +++++++++++++++++++++++
22   fs/namei.c                      |   55 +++++++++++++++++++++++   fs/open.c                       |   28 ++++++++++++++++++++++++++++
23   fs/namespace.c                  |   49 ++++++++++++++++++++   fs/proc/proc_misc.c             |    1 +
24   fs/open.c                       |   28 +++++++++++   include/linux/init_task.h       |    9 +++++++++
25   fs/proc/Makefile                |    3 +   include/linux/sched.h           |    6 ++++++
26   fs/proc/proc_misc.c             |    5 ++   kernel/compat.c                 |    3 +++
27   include/linux/init_task.h       |    4 +   kernel/kexec.c                  |    3 +++
28   include/linux/sched.h           |    8 +++   kernel/kmod.c                   |    5 +++++
29   kernel/compat.c                 |    7 ++   kernel/module.c                 |    5 +++++
30   kernel/kexec.c                  |    7 ++   kernel/ptrace.c                 |    3 +++
31   kernel/kmod.c                   |    5 ++   kernel/sched.c                  |    3 +++
32   kernel/module.c                 |   11 ++++   kernel/signal.c                 |    9 +++++++++
33   kernel/ptrace.c                 |    7 ++   kernel/sys.c                    |   11 +++++++++++
34   kernel/sched.c                  |    7 ++   kernel/sysctl.c                 |    5 +++++
35   kernel/signal.c                 |   21 ++++++++   kernel/time.c                   |    5 +++++
36   kernel/sys.c                    |   21 ++++++++   kernel/time/ntp.c               |    3 +++
37   kernel/sysctl.c                 |   95 ++++++++++++++++++++++++++++++++++++++++   net/ipv4/inet_connection_sock.c |    3 +++
38   kernel/time.c                   |   11 ++++   net/ipv4/inet_hashtables.c      |    3 +++
39   kernel/time/ntp.c               |    7 ++   net/ipv4/raw.c                  |    4 ++++
40   net/core/datagram.c             |   11 ++++   net/ipv4/udp.c                  |    8 ++++++++
41   net/ipv4/inet_connection_sock.c |    7 ++   net/ipv6/inet6_hashtables.c     |    3 +++
42   net/ipv4/inet_hashtables.c      |    7 ++   net/ipv6/raw.c                  |    4 ++++
43   net/ipv4/udp.c                  |   11 ++++   net/ipv6/udp.c                  |    4 ++++
44   net/ipv6/inet6_hashtables.c     |    7 ++   net/socket.c                    |   23 +++++++++++++++++++++++
45   net/socket.c                    |   41 +++++++++++++++++   net/unix/af_unix.c              |    4 ++++
46   net/unix/af_unix.c              |    8 +++   security/Kconfig                |    2 ++
47   42 files changed, 593 insertions(+), 2 deletions(-)   security/Makefile               |    3 +++
48     43 files changed, 279 insertions(+), 3 deletions(-)
49    
50  --- linux-2.6.21.7.orig/arch/alpha/kernel/ptrace.c  --- linux-2.6.21.7.orig/arch/alpha/kernel/ptrace.c
51  +++ linux-2.6.21.7/arch/alpha/kernel/ptrace.c  +++ linux-2.6.21.7/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>
56  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.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.21.7.orig/arch/ia64/ia32/sys_ia32.c  --- linux-2.6.21.7.orig/arch/ia64/ia32/sys_ia32.c
70  +++ linux-2.6.21.7/arch/ia64/ia32/sys_ia32.c  +++ linux-2.6.21.7/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>
75  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
76    
77   #include "ia32priv.h"   #include "ia32priv.h"
78    
79  @@ -1758,6 +1761,10 @@ sys32_ptrace (int request, pid_t pid, un  @@ -1758,6 +1759,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.21.7.orig/arch/ia64/kernel/ptrace.c  --- linux-2.6.21.7.orig/arch/ia64/kernel/ptrace.c
89  +++ linux-2.6.21.7/arch/ia64/kernel/ptrace.c  +++ linux-2.6.21.7/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
94  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
95    
96   #include "entry.h"   #include "entry.h"
97    
98  @@ -1418,6 +1421,10 @@ sys_ptrace (long request, pid_t pid, uns  @@ -1418,6 +1419,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.21.7.orig/arch/m32r/kernel/ptrace.c  --- linux-2.6.21.7.orig/arch/m32r/kernel/ptrace.c
108  +++ linux-2.6.21.7/arch/m32r/kernel/ptrace.c  +++ linux-2.6.21.7/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>
113  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.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.21.7.orig/arch/mips/kernel/ptrace32.c  --- linux-2.6.21.7.orig/arch/mips/kernel/ptrace32.c
127  +++ linux-2.6.21.7/arch/mips/kernel/ptrace32.c  +++ linux-2.6.21.7/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>
132  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.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.21.7.orig/arch/powerpc/kernel/ptrace32.c  --- linux-2.6.21.7.orig/arch/powerpc/kernel/ptrace32.c
146  +++ linux-2.6.21.7/arch/powerpc/kernel/ptrace32.c  +++ linux-2.6.21.7/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>
151  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.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.21.7.orig/arch/s390/kernel/ptrace.c  --- linux-2.6.21.7.orig/arch/s390/kernel/ptrace.c
165  +++ linux-2.6.21.7/arch/s390/kernel/ptrace.c  +++ linux-2.6.21.7/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>
170  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.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  @@ -713,6 +716,10 @@ sys_ptrace(long request, long pid, long  @@ -713,6 +714,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.21.7.orig/arch/sparc/kernel/ptrace.c  --- linux-2.6.21.7.orig/arch/sparc/kernel/ptrace.c
184  +++ linux-2.6.21.7/arch/sparc/kernel/ptrace.c  +++ linux-2.6.21.7/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>
189  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.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.21.7.orig/arch/sparc64/kernel/ptrace.c  --- linux-2.6.21.7.orig/arch/sparc64/kernel/ptrace.c
205  +++ linux-2.6.21.7/arch/sparc64/kernel/ptrace.c  +++ linux-2.6.21.7/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>
210  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.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.21.7.orig/arch/x86_64/ia32/ptrace32.c  --- linux-2.6.21.7.orig/arch/x86_64/ia32/ptrace32.c
226  +++ linux-2.6.21.7/arch/x86_64/ia32/ptrace32.c  +++ linux-2.6.21.7/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>
231  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.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  @@ -234,6 +237,10 @@ asmlinkage long sys32_ptrace(long reques  @@ -234,6 +235,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:
 --- linux-2.6.21.7.orig/fs/Kconfig  
 +++ linux-2.6.21.7/fs/Kconfig  
 @@ -2055,5 +2055,7 @@ endif  
  source "fs/nls/Kconfig"  
  source "fs/dlm/Kconfig"  
   
 +source "fs/Kconfig.ccs"  
 +  
  endmenu  
   
 --- linux-2.6.21.7.orig/fs/Makefile  
 +++ linux-2.6.21.7/fs/Makefile  
 @@ -114,3 +114,5 @@ obj-$(CONFIG_HPPFS)         += hppfs/  
  obj-$(CONFIG_DEBUG_FS)         += debugfs/  
  obj-$(CONFIG_OCFS2_FS)         += ocfs2/  
  obj-$(CONFIG_GFS2_FS)           += gfs2/  
 +  
 +include $(srctree)/fs/Makefile-2.6.ccs  
244  --- linux-2.6.21.7.orig/fs/attr.c  --- linux-2.6.21.7.orig/fs/attr.c
245  +++ linux-2.6.21.7/fs/attr.c  +++ linux-2.6.21.7/fs/attr.c
246  @@ -15,6 +15,9 @@  @@ -15,6 +15,7 @@
247   #include <linux/fcntl.h>   #include <linux/fcntl.h>
248   #include <linux/quotaops.h>   #include <linux/quotaops.h>
249   #include <linux/security.h>   #include <linux/security.h>
250  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
251    
252   /* Taken over from the old code... */   /* Taken over from the old code... */
253    
254  @@ -145,12 +148,28 @@ int notify_change(struct dentry * dentry  @@ -146,11 +147,15 @@ int notify_change(struct dentry * dentry
   
255          if (inode->i_op && inode->i_op->setattr) {          if (inode->i_op && inode->i_op->setattr) {
256                  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. *****/  
257                  if (!error)                  if (!error)
258    +                       error = ccs_setattr_permission(dentry, attr);
259    +               if (!error)
260                          error = inode->i_op->setattr(dentry, attr);                          error = inode->i_op->setattr(dentry, attr);
261          } else {          } else {
262                  error = inode_change_ok(inode, attr);                  error = inode_change_ok(inode, attr);
263                  if (!error)                  if (!error)
264                          error = security_inode_setattr(dentry, attr);                          error = security_inode_setattr(dentry, attr);
265  +               /***** TOMOYO Linux start. *****/  +               if (!error)
266  +               if (!error && (ia_valid & ATTR_MODE) &&  +                       error = ccs_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. *****/  
267                  if (!error) {                  if (!error) {
268                          if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||                          if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
269                              (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))                              (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
270  --- linux-2.6.21.7.orig/fs/compat.c  --- linux-2.6.21.7.orig/fs/compat.c
271  +++ linux-2.6.21.7/fs/compat.c  +++ linux-2.6.21.7/fs/compat.c
272  @@ -56,6 +56,9 @@  @@ -56,6 +56,7 @@
273   #include <asm/mmu_context.h>   #include <asm/mmu_context.h>
274   #include <asm/ioctls.h>   #include <asm/ioctls.h>
275   #include "internal.h"   #include "internal.h"
276  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
277    
278   int compat_log = 1;   int compat_log = 1;
279    
280  @@ -398,6 +401,10 @@ asmlinkage long compat_sys_ioctl(unsigne  @@ -398,6 +399,8 @@ asmlinkage long compat_sys_ioctl(unsigne
281    
282          /* RED-PEN how should LSM module know it's handling 32bit? */          /* RED-PEN how should LSM module know it's handling 32bit? */
283          error = security_file_ioctl(filp, cmd, arg);          error = security_file_ioctl(filp, cmd, arg);
 +       /***** TOMOYO Linux start. *****/  
284  +       if (!error)  +       if (!error)
285  +               error = ccs_check_ioctl_permission(filp, cmd, arg);  +               error = ccs_check_ioctl_permission(filp, cmd, arg);
 +       /***** TOMOYO Linux end. *****/  
286          if (error)          if (error)
287                  goto out_fput;                  goto out_fput;
288    
289  @@ -422,6 +429,12 @@ asmlinkage long compat_sys_ioctl(unsigne  @@ -422,6 +425,10 @@ asmlinkage long compat_sys_ioctl(unsigne
290                  /*FALL THROUGH*/                  /*FALL THROUGH*/
291    
292          default:          default:
 +               /***** TOMOYO Linux start. *****/  
293  +               if (!ccs_capable(CCS_SYS_IOCTL)) {  +               if (!ccs_capable(CCS_SYS_IOCTL)) {
294  +                       error = -EPERM;  +                       error = -EPERM;
295  +                       goto out_fput;  +                       goto out_fput;
296  +               }  +               }
 +               /***** TOMOYO Linux end. *****/  
297                  if (filp->f_op && filp->f_op->compat_ioctl) {                  if (filp->f_op && filp->f_op->compat_ioctl) {
298                          error = filp->f_op->compat_ioctl(filp, cmd, arg);                          error = filp->f_op->compat_ioctl(filp, cmd, arg);
299                          if (error != -ENOIOCTLCMD)                          if (error != -ENOIOCTLCMD)
300  @@ -1552,7 +1565,7 @@ int compat_do_execve(char * filename,  @@ -1552,7 +1559,7 @@ int compat_do_execve(char * filename,
301          if (retval < 0)          if (retval < 0)
302                  goto out;                  goto out;
303    
304  -       retval = search_binary_handler(bprm, regs);  -       retval = search_binary_handler(bprm, regs);
305  +       retval = search_binary_handler_with_transition(bprm, regs);  +       retval = ccs_search_binary_handler(bprm, regs);
306          if (retval >= 0) {          if (retval >= 0) {
307                  free_arg_pages(bprm);                  free_arg_pages(bprm);
308    
309  --- linux-2.6.21.7.orig/fs/exec.c  --- linux-2.6.21.7.orig/fs/exec.c
310  +++ linux-2.6.21.7/fs/exec.c  +++ linux-2.6.21.7/fs/exec.c
311  @@ -58,6 +58,10 @@  @@ -58,6 +58,8 @@
312   #include <linux/kmod.h>   #include <linux/kmod.h>
313   #endif   #endif
314    
315  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
316  +  +
317   int core_uses_pid;   int core_uses_pid;
318   char core_pattern[128] = "core";   char core_pattern[128] = "core";
319   int suid_dumpable = 0;   int suid_dumpable = 0;
320  @@ -140,6 +144,13 @@ asmlinkage long sys_uselib(const char __  @@ -140,6 +142,10 @@ asmlinkage long sys_uselib(const char __
321          if (error)          if (error)
322                  goto exit;                  goto exit;
323    
324  +       /***** TOMOYO Linux start. *****/  +       error = ccs_uselib_permission(nd.dentry, nd.mnt);
 +       /* 01 means "read". */  
 +       error = ccs_check_open_permission(nd.dentry, nd.mnt, 01);  
325  +       if (error)  +       if (error)
326  +               goto exit;  +               goto exit;
 +       /***** TOMOYO Linux end. *****/  
327  +  +
328          file = nameidata_to_filp(&nd, O_RDONLY);          file = nameidata_to_filp(&nd, O_RDONLY);
329          error = PTR_ERR(file);          error = PTR_ERR(file);
330          if (IS_ERR(file))          if (IS_ERR(file))
331  @@ -485,6 +496,13 @@ struct file *open_exec(const char *name)  @@ -485,6 +491,9 @@ struct file *open_exec(const char *name)
332                  if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&                  if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&
333                      S_ISREG(inode->i_mode)) {                      S_ISREG(inode->i_mode)) {
334                          int err = vfs_permission(&nd, MAY_EXEC);                          int err = vfs_permission(&nd, MAY_EXEC);
335  +                       /***** TOMOYO Linux start. *****/  +                       if (!err)
336  +                       if (!err && (current->ccs_flags &  +                               err = ccs_open_exec_permission(nd.dentry,
337  +                                    CCS_CHECK_READ_FOR_OPEN_EXEC))  +                                                                    nd.mnt);
 +                               /* 01 means "read". */  
 +                               err = ccs_check_open_permission(nd.dentry,  
 +                                                               nd.mnt, 01);  
 +                       /***** TOMOYO Linux end. *****/  
338                          file = ERR_PTR(err);                          file = ERR_PTR(err);
339                          if (!err) {                          if (!err) {
340                                  file = nameidata_to_filp(&nd, O_RDONLY);                                  file = nameidata_to_filp(&nd, O_RDONLY);
341  @@ -1183,7 +1201,7 @@ int do_execve(char * filename,  @@ -1183,7 +1192,7 @@ int do_execve(char * filename,
342          if (retval < 0)          if (retval < 0)
343                  goto out;                  goto out;
344    
345  -       retval = search_binary_handler(bprm,regs);  -       retval = search_binary_handler(bprm,regs);
346  +       retval = search_binary_handler_with_transition(bprm, regs);  +       retval = ccs_search_binary_handler(bprm, regs);
347          if (retval >= 0) {          if (retval >= 0) {
348                  free_arg_pages(bprm);                  free_arg_pages(bprm);
349    
350  --- linux-2.6.21.7.orig/fs/fcntl.c  --- linux-2.6.21.7.orig/fs/fcntl.c
351  +++ linux-2.6.21.7/fs/fcntl.c  +++ linux-2.6.21.7/fs/fcntl.c
352  @@ -22,6 +22,9 @@  @@ -22,6 +22,7 @@
353   #include <asm/poll.h>   #include <asm/poll.h>
354   #include <asm/siginfo.h>   #include <asm/siginfo.h>
355   #include <asm/uaccess.h>   #include <asm/uaccess.h>
356  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
357    
358   void fastcall set_close_on_exec(unsigned int fd, int flag)   void fastcall set_close_on_exec(unsigned int fd, int flag)
359   {   {
360  @@ -213,6 +216,12 @@ static int setfl(int fd, struct file * f  @@ -213,6 +214,9 @@ static int setfl(int fd, struct file * f
361          if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode))          if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode))
362                  return -EPERM;                  return -EPERM;
363    
364  +       /***** TOMOYO Linux start. *****/  +       if (((arg ^ filp->f_flags) & O_APPEND) && ccs_rewrite_permission(filp))
 +       if (((arg ^ filp->f_flags) & O_APPEND) &&  
 +           ccs_check_rewrite_permission(filp))  
365  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
366  +  +
367          /* O_NOATIME can only be set by the owner or superuser */          /* O_NOATIME can only be set by the owner or superuser */
368          if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))          if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))
369                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
370  --- linux-2.6.21.7.orig/fs/ioctl.c  --- linux-2.6.21.7.orig/fs/ioctl.c
371  +++ linux-2.6.21.7/fs/ioctl.c  +++ linux-2.6.21.7/fs/ioctl.c
372  @@ -15,6 +15,9 @@  @@ -15,6 +15,7 @@
373    
374   #include <asm/uaccess.h>   #include <asm/uaccess.h>
375   #include <asm/ioctls.h>   #include <asm/ioctls.h>
376  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
377    
378   static long do_ioctl(struct file *filp, unsigned int cmd,   static long do_ioctl(struct file *filp, unsigned int cmd,
379                  unsigned long arg)                  unsigned long arg)
380  @@ -23,6 +26,10 @@ static long do_ioctl(struct file *filp,  @@ -23,6 +24,8 @@ static long do_ioctl(struct file *filp,
381    
382          if (!filp->f_op)          if (!filp->f_op)
383                  goto out;                  goto out;
 +       /***** TOMOYO Linux start. *****/  
384  +       if (!ccs_capable(CCS_SYS_IOCTL))  +       if (!ccs_capable(CCS_SYS_IOCTL))
385  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
386    
387          if (filp->f_op->unlocked_ioctl) {          if (filp->f_op->unlocked_ioctl) {
388                  error = filp->f_op->unlocked_ioctl(filp, cmd, arg);                  error = filp->f_op->unlocked_ioctl(filp, cmd, arg);
389  @@ -167,6 +174,10 @@ asmlinkage long sys_ioctl(unsigned int f  @@ -167,6 +170,8 @@ asmlinkage long sys_ioctl(unsigned int f
390                  goto out;                  goto out;
391    
392          error = security_file_ioctl(filp, cmd, arg);          error = security_file_ioctl(filp, cmd, arg);
 +       /***** TOMOYO Linux start. *****/  
393  +       if (!error)  +       if (!error)
394  +               error = ccs_check_ioctl_permission(filp, cmd, arg);  +               error = ccs_ioctl_permission(filp, cmd, arg);
 +       /***** TOMOYO Linux end. *****/  
395          if (error)          if (error)
396                  goto out_fput;                  goto out_fput;
397    
398  --- linux-2.6.21.7.orig/fs/namei.c  --- linux-2.6.21.7.orig/fs/namei.c
399  +++ linux-2.6.21.7/fs/namei.c  +++ linux-2.6.21.7/fs/namei.c
400  @@ -37,6 +37,10 @@  @@ -37,6 +37,8 @@
401    
402   #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])   #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
403    
404  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
405  +  +
406   /* [Feb-1997 T. Schoebel-Theuer]   /* [Feb-1997 T. Schoebel-Theuer]
407    * Fundamental changes in the pathname lookup mechanisms (namei)    * Fundamental changes in the pathname lookup mechanisms (namei)
408    * were necessary because of omirr.  The reason is that omirr needs    * were necessary because of omirr.  The reason is that omirr needs
409  @@ -1561,6 +1565,13 @@ int may_open(struct nameidata *nd, int a  @@ -1561,6 +1563,11 @@ int may_open(struct nameidata *nd, int a
410                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
411                          return -EPERM;                          return -EPERM;
412    
 +       /***** TOMOYO Linux start. *****/  
413  +       /* includes O_APPEND and O_TRUNC checks */  +       /* includes O_APPEND and O_TRUNC checks */
414  +       error = ccs_check_open_permission(dentry, nd->mnt, flag);  +       error = ccs_open_permission(dentry, nd->mnt, flag);
415  +       if (error)  +       if (error)
416  +               return error;  +               return error;
 +       /***** TOMOYO Linux end. *****/  
417  +  +
418          /*          /*
419           * Ensure there are no outstanding leases on the file.           * Ensure there are no outstanding leases on the file.
420           */           */
421  @@ -1600,6 +1611,11 @@ static int open_namei_create(struct name  @@ -1600,6 +1607,9 @@ static int open_namei_create(struct name
422    
423          if (!IS_POSIXACL(dir->d_inode))          if (!IS_POSIXACL(dir->d_inode))
424                  mode &= ~current->fs->umask;                  mode &= ~current->fs->umask;
425  +       /***** TOMOYO Linux start. *****/  +       error = ccs_mknod_permission(dir->d_inode, path->dentry, nd->mnt, mode,
426  +       error = ccs_check_mknod_permission(dir->d_inode, path->dentry,  +                                    0);
 +                                          nd->path.mnt, mode, 0);  
427  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
428          error = vfs_create(dir->d_inode, path->dentry, mode, nd);          error = vfs_create(dir->d_inode, path->dentry, mode, nd);
429          mutex_unlock(&dir->d_inode->i_mutex);          mutex_unlock(&dir->d_inode->i_mutex);
430          dput(nd->dentry);          dput(nd->dentry);
431  @@ -1610,6 +1626,9 @@ static int open_namei_create(struct name  @@ -1610,6 +1620,7 @@ static int open_namei_create(struct name
432          return may_open(nd, 0, flag & ~O_TRUNC);          return may_open(nd, 0, flag & ~O_TRUNC);
433   }   }
434    
435  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity_vfs.h>
 +#include <linux/tomoyo_vfs.h>  
 +/***** TOMOYO Linux end. *****/  
436   /*   /*
437    *     open_namei()    *     open_namei()
438    *    *
439  @@ -1883,6 +1902,12 @@ asmlinkage long sys_mknodat(int dfd, con  @@ -1883,6 +1894,9 @@ asmlinkage long sys_mknodat(int dfd, con
440          if (!IS_POSIXACL(nd.dentry->d_inode))          if (!IS_POSIXACL(nd.dentry->d_inode))
441                  mode &= ~current->fs->umask;                  mode &= ~current->fs->umask;
442          if (!IS_ERR(dentry)) {          if (!IS_ERR(dentry)) {
443  +               /***** TOMOYO Linux start. *****/  +               error = ccs_mknod_permission(nd.dentry->d_inode, dentry,
444  +               error = ccs_check_mknod_permission(nd.path.dentry->d_inode,  +                                            nd.mnt, mode, dev);
 +                                                  dentry, nd.path.mnt, mode,  
 +                                                  new_decode_dev(dev));  
445  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
446                  switch (mode & S_IFMT) {                  switch (mode & S_IFMT) {
447                  case 0: case S_IFREG:                  case 0: case S_IFREG:
448                          error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);                          error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
449  @@ -1959,6 +1984,11 @@ asmlinkage long sys_mkdirat(int dfd, con  @@ -1959,6 +1973,8 @@ asmlinkage long sys_mkdirat(int dfd, con
450    
451          if (!IS_POSIXACL(nd.dentry->d_inode))          if (!IS_POSIXACL(nd.dentry->d_inode))
452                  mode &= ~current->fs->umask;                  mode &= ~current->fs->umask;
453  +       /***** TOMOYO Linux start. *****/  +       error = ccs_mkdir_permission(nd.dentry->d_inode, dentry, nd.mnt, mode);
 +       error = ccs_check_mkdir_permission(nd.dentry->d_inode, dentry, nd.mnt,  
 +                                          mode);  
454  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
455          error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);          error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
456          dput(dentry);          dput(dentry);
457   out_unlock:   out_unlock:
458  @@ -2066,6 +2096,10 @@ static long do_rmdir(int dfd, const char  @@ -2066,6 +2082,8 @@ static long do_rmdir(int dfd, const char
459          error = PTR_ERR(dentry);          error = PTR_ERR(dentry);
460          if (IS_ERR(dentry))          if (IS_ERR(dentry))
461                  goto exit2;                  goto exit2;
462  +       /***** TOMOYO Linux start. *****/  +       error = ccs_rmdir_permission(nd.dentry->d_inode, dentry, nd.mnt);
 +       error = ccs_check_rmdir_permission(nd.dentry->d_inode, dentry, nd.mnt);  
463  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
464          error = vfs_rmdir(nd.dentry->d_inode, dentry);          error = vfs_rmdir(nd.dentry->d_inode, dentry);
465          dput(dentry);          dput(dentry);
466   exit2:   exit2:
467  @@ -2146,6 +2180,11 @@ static long do_unlinkat(int dfd, const c  @@ -2146,6 +2164,9 @@ static long do_unlinkat(int dfd, const c
468                  inode = dentry->d_inode;                  inode = dentry->d_inode;
469                  if (inode)                  if (inode)
470                          atomic_inc(&inode->i_count);                          atomic_inc(&inode->i_count);
471  +               /***** TOMOYO Linux start. *****/  +               error = ccs_unlink_permission(nd.dentry->d_inode, dentry,
472  +               error = ccs_check_unlink_permission(nd.dentry->d_inode, dentry,  +                                             nd.mnt);
 +                                                   nd.mnt);  
473  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
474                  error = vfs_unlink(nd.dentry->d_inode, dentry);                  error = vfs_unlink(nd.dentry->d_inode, dentry);
475          exit2:          exit2:
476                  dput(dentry);                  dput(dentry);
477  @@ -2227,6 +2266,11 @@ asmlinkage long sys_symlinkat(const char  @@ -2227,6 +2248,9 @@ asmlinkage long sys_symlinkat(const char
478          if (IS_ERR(dentry))          if (IS_ERR(dentry))
479                  goto out_unlock;                  goto out_unlock;
480    
481  +       /***** TOMOYO Linux start. *****/  +       error = ccs_symlink_permission(nd.dentry->d_inode, dentry, nd.mnt,
482  +       error = ccs_check_symlink_permission(nd.dentry->d_inode, dentry,  +                                      from);
 +                                            nd.mnt, from);  
483  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
484          error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);          error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
485          dput(dentry);          dput(dentry);
486   out_unlock:   out_unlock:
487  @@ -2322,6 +2366,11 @@ asmlinkage long sys_linkat(int olddfd, c  @@ -2322,6 +2346,9 @@ asmlinkage long sys_linkat(int olddfd, c
488          error = PTR_ERR(new_dentry);          error = PTR_ERR(new_dentry);
489          if (IS_ERR(new_dentry))          if (IS_ERR(new_dentry))
490                  goto out_unlock;                  goto out_unlock;
491  +       /***** TOMOYO Linux start. *****/  +       error = ccs_link_permission(old_nd.dentry, nd.dentry->d_inode,
492  +       error = ccs_check_link_permission(old_nd.dentry, nd.dentry->d_inode,  +                                   new_dentry, nd.mnt);
 +                                         new_dentry, nd.mnt);  
493  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
494          error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);          error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
495          dput(new_dentry);          dput(new_dentry);
496   out_unlock:   out_unlock:
497  @@ -2547,6 +2596,12 @@ static int do_rename(int olddfd, const c  @@ -2547,7 +2574,9 @@ static int do_rename(int olddfd, const c
498          error = -ENOTEMPTY;          error = -ENOTEMPTY;
499          if (new_dentry == trap)          if (new_dentry == trap)
500                  goto exit5;                  goto exit5;
501  +       /***** TOMOYO Linux start. *****/  -
502  +       error = ccs_check_rename_permission(old_dir->d_inode, old_dentry,  +       error = ccs_rename_permission(old_dir->d_inode, old_dentry,
503  +                                           new_dir->d_inode, new_dentry,  +                                     new_dir->d_inode, new_dentry, newnd.mnt);
 +                                           newnd.mnt);  
504  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
   
505          error = vfs_rename(old_dir->d_inode, old_dentry,          error = vfs_rename(old_dir->d_inode, old_dentry,
506                                     new_dir->d_inode, new_dentry);                                     new_dir->d_inode, new_dentry);
507     exit5:
508  --- linux-2.6.21.7.orig/fs/namespace.c  --- linux-2.6.21.7.orig/fs/namespace.c
509  +++ linux-2.6.21.7/fs/namespace.c  +++ linux-2.6.21.7/fs/namespace.c
510  @@ -28,6 +28,12 @@  @@ -28,6 +28,7 @@
511   #include <asm/uaccess.h>   #include <asm/uaccess.h>
512   #include <asm/unistd.h>   #include <asm/unistd.h>
513   #include "pnode.h"   #include "pnode.h"
514  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
515    
516   /* spinlock for vfsmount related operations, inplace of dcache_lock */   /* spinlock for vfsmount related operations, inplace of dcache_lock */
517   __cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);   __cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);
518  @@ -545,6 +551,11 @@ static int do_umount(struct vfsmount *mn  @@ -545,6 +546,9 @@ static int do_umount(struct vfsmount *mn
519          if (retval)          if (retval)
520                  return retval;                  return retval;
521    
 +       /***** SAKURA Linux start. *****/  
522  +       if (ccs_may_umount(mnt))  +       if (ccs_may_umount(mnt))
523  +               return -EPERM;  +               return -EPERM;
 +       /***** SAKURA Linux end. *****/  
524  +  +
525          /*          /*
526           * Allow userspace to request a mountpoint be expired rather than           * Allow userspace to request a mountpoint be expired rather than
527           * unmounting unconditionally. Unmount only happens if:           * unmounting unconditionally. Unmount only happens if:
528  @@ -633,6 +644,10 @@ asmlinkage long sys_umount(char __user *  @@ -633,6 +637,8 @@ asmlinkage long sys_umount(char __user *
529   {   {
530          struct nameidata nd;          struct nameidata nd;
531          int retval;          int retval;
 +       /***** TOMOYO Linux start. *****/  
532  +       if (!ccs_capable(CCS_SYS_UMOUNT))  +       if (!ccs_capable(CCS_SYS_UMOUNT))
533  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
534    
535          retval = __user_walk(name, LOOKUP_FOLLOW, &nd);          retval = __user_walk(name, LOOKUP_FOLLOW, &nd);
536          if (retval)          if (retval)
537  @@ -917,6 +932,11 @@ static int do_loopback(struct nameidata  @@ -917,6 +923,9 @@ static int do_loopback(struct nameidata
538    
539          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
540                  goto out;                  goto out;
 +       /***** SAKURA Linux start. *****/  
541  +       err = -EPERM;  +       err = -EPERM;
542  +       if (ccs_may_mount(nd))  +       if (ccs_may_mount(nd))
543  +               goto out;  +               goto out;
 +       /***** SAKURA Linux end. *****/  
544    
545          err = -ENOMEM;          err = -ENOMEM;
546          if (recurse)          if (recurse)
547  @@ -1002,6 +1022,11 @@ static int do_move_mount(struct nameidat  @@ -1002,6 +1011,9 @@ static int do_move_mount(struct nameidat
548          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
549                  goto out;                  goto out;
550    
 +       /***** SAKURA Linux start. *****/  
551  +       err = -EPERM;  +       err = -EPERM;
552  +       if (ccs_may_umount(old_nd.mnt) || ccs_may_mount(nd))  +       if (ccs_may_mount(nd))
553  +               goto out;  +               goto out;
 +       /***** SAKURA Linux end. *****/  
554          err = -ENOENT;          err = -ENOENT;
555          mutex_lock(&nd->dentry->d_inode->i_mutex);          mutex_lock(&nd->dentry->d_inode->i_mutex);
556          if (IS_DEADDIR(nd->dentry->d_inode))          if (IS_DEADDIR(nd->dentry->d_inode))
557  @@ -1103,6 +1128,11 @@ int do_add_mount(struct vfsmount *newmnt  @@ -1103,6 +1115,9 @@ int do_add_mount(struct vfsmount *newmnt
558          err = -EINVAL;          err = -EINVAL;
559          if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))          if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
560                  goto unlock;                  goto unlock;
 +       /***** SAKURA Linux start. *****/  
561  +       err = -EPERM;  +       err = -EPERM;
562  +       if (ccs_may_mount(nd))  +       if (ccs_may_mount(nd))
563  +               goto unlock;  +               goto unlock;
 +       /***** SAKURA Linux end. *****/  
564    
565          newmnt->mnt_flags = mnt_flags;          newmnt->mnt_flags = mnt_flags;
566          if ((err = graft_tree(newmnt, nd)))          if ((err = graft_tree(newmnt, nd)))
567  @@ -1394,6 +1424,17 @@ long do_mount(char *dev_name, char *dir_  @@ -1394,6 +1409,10 @@ long do_mount(char *dev_name, char *dir_
568          if (data_page)          if (data_page)
569                  ((char *)data_page)[PAGE_SIZE - 1] = 0;                  ((char *)data_page)[PAGE_SIZE - 1] = 0;
570    
571  +       /***** TOMOYO Linux start. *****/  +       retval = ccs_mount_permission(dev_name, dir_name, type_page, &flags);
 +       if (!ccs_capable(CCS_SYS_MOUNT))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
 +       /***** SAKURA Linux start. *****/  
 +       retval = ccs_check_mount_permission(dev_name, dir_name, type_page,  
 +                                           &flags);  
572  +       if (retval)  +       if (retval)
573  +               return retval;  +               return retval;
 +       /***** SAKURA Linux end. *****/  
574  +  +
575          /* Separate the per-mountpoint flags */          /* Separate the per-mountpoint flags */
576          if (flags & MS_NOSUID)          if (flags & MS_NOSUID)
577                  mnt_flags |= MNT_NOSUID;                  mnt_flags |= MNT_NOSUID;
578  @@ -1686,6 +1727,10 @@ asmlinkage long sys_pivot_root(const cha  @@ -1686,6 +1705,8 @@ asmlinkage long sys_pivot_root(const cha
579    
580          if (!capable(CAP_SYS_ADMIN))          if (!capable(CAP_SYS_ADMIN))
581                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
582  +       if (!ccs_capable(CCS_SYS_PIVOT_ROOT))  +       if (!ccs_capable(CCS_SYS_PIVOT_ROOT))
583  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
584    
585          lock_kernel();          lock_kernel();
586    
587  @@ -1702,6 +1747,10 @@ asmlinkage long sys_pivot_root(const cha  @@ -1702,6 +1723,8 @@ asmlinkage long sys_pivot_root(const cha
588                  goto out1;                  goto out1;
589    
590          error = security_sb_pivotroot(&old_nd, &new_nd);          error = security_sb_pivotroot(&old_nd, &new_nd);
 +       /***** SAKURA Linux start. *****/  
591  +       if (!error)  +       if (!error)
592  +               error = ccs_check_pivot_root_permission(&old_nd, &new_nd);  +               error = ccs_pivot_root_permission(&old_nd, &new_nd);
 +       /***** SAKURA Linux end. *****/  
593          if (error) {          if (error) {
594                  path_release(&old_nd);                  path_release(&old_nd);
595                  goto out1;                  goto out1;
596  --- linux-2.6.21.7.orig/fs/open.c  --- linux-2.6.21.7.orig/fs/open.c
597  +++ linux-2.6.21.7/fs/open.c  +++ linux-2.6.21.7/fs/open.c
598  @@ -27,6 +27,12 @@  @@ -27,6 +27,7 @@
599   #include <linux/syscalls.h>   #include <linux/syscalls.h>
600   #include <linux/rcupdate.h>   #include <linux/rcupdate.h>
601   #include <linux/audit.h>   #include <linux/audit.h>
602  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
603    
604   int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)   int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
605   {   {
606  @@ -264,6 +270,10 @@ static long do_sys_truncate(const char _  @@ -264,6 +265,8 @@ static long do_sys_truncate(const char _
607          if (error)          if (error)
608                  goto dput_and_out;                  goto dput_and_out;
609    
610  +       /***** TOMOYO Linux start. *****/  +       error = ccs_truncate_permission(nd.dentry, nd.mnt, length, 0);
 +       error = ccs_check_truncate_permission(nd.dentry, nd.mnt, length, 0);  
611  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
612          error = locks_verify_truncate(inode, NULL, length);          error = locks_verify_truncate(inode, NULL, length);
613          if (!error) {          if (!error) {
614                  DQUOT_INIT(inode);                  DQUOT_INIT(inode);
615  @@ -317,6 +327,12 @@ static long do_sys_ftruncate(unsigned in  @@ -317,6 +320,9 @@ static long do_sys_ftruncate(unsigned in
616          if (IS_APPEND(inode))          if (IS_APPEND(inode))
617                  goto out_putf;                  goto out_putf;
618    
619  +       /***** TOMOYO Linux start. *****/  +       error = ccs_truncate_permission(dentry, file->f_vfsmnt, length, 0);
 +       error = ccs_check_truncate_permission(dentry, file->f_vfsmnt, length,  
 +                                             0);  
620  +       if (error)  +       if (error)
621  +               goto out_putf;  +               goto out_putf;
 +       /***** TOMOYO Linux end. *****/  
622          error = locks_verify_truncate(inode, file, length);          error = locks_verify_truncate(inode, file, length);
623          if (!error)          if (!error)
624                  error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);                  error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);
625  @@ -481,6 +497,14 @@ asmlinkage long sys_chroot(const char __  @@ -481,6 +487,10 @@ asmlinkage long sys_chroot(const char __
626          error = -EPERM;          error = -EPERM;
627          if (!capable(CAP_SYS_CHROOT))          if (!capable(CAP_SYS_CHROOT))
628                  goto dput_and_out;                  goto dput_and_out;
 +       /***** TOMOYO Linux start. *****/  
629  +       if (!ccs_capable(CCS_SYS_CHROOT))  +       if (!ccs_capable(CCS_SYS_CHROOT))
630  +               goto dput_and_out;  +               goto dput_and_out;
631  +       /***** TOMOYO Linux end. *****/  +       if (ccs_chroot_permission(&nd))
 +       /***** SAKURA Linux start. *****/  
 +       if (ccs_check_chroot_permission(&nd))  
632  +               goto dput_and_out;  +               goto dput_and_out;
 +       /***** SAKURA Linux end. *****/  
633    
634          set_fs_root(current->fs, nd.mnt, nd.dentry);          set_fs_root(current->fs, nd.mnt, nd.dentry);
635          set_fs_altroot();          set_fs_altroot();
636  @@ -1085,6 +1109,10 @@ EXPORT_SYMBOL(sys_close);  @@ -514,6 +524,9 @@ asmlinkage long sys_fchmod(unsigned int
637            err = -EPERM;
638            if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
639                    goto out_putf;
640    +       err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode);
641    +       if (err)
642    +               goto out_putf;
643            mutex_lock(&inode->i_mutex);
644            if (mode == (mode_t) -1)
645                    mode = inode->i_mode;
646    @@ -548,6 +561,9 @@ asmlinkage long sys_fchmodat(int dfd, co
647            error = -EPERM;
648            if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
649                    goto dput_and_out;
650    +       error = ccs_chmod_permission(nd.dentry, nd.mnt, mode);
651    +       if (error)
652    +               goto dput_and_out;
653    
654            mutex_lock(&inode->i_mutex);
655            if (mode == (mode_t) -1)
656    @@ -611,6 +627,8 @@ asmlinkage long sys_chown(const char __u
657            error = user_path_walk(filename, &nd);
658            if (error)
659                    goto out;
660    +       error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
661    +       if (!error)
662            error = chown_common(nd.dentry, user, group);
663            path_release(&nd);
664     out:
665    @@ -631,6 +649,8 @@ asmlinkage long sys_fchownat(int dfd, co
666            error = __user_walk_fd(dfd, filename, follow, &nd);
667            if (error)
668                    goto out;
669    +       error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
670    +       if (!error)
671            error = chown_common(nd.dentry, user, group);
672            path_release(&nd);
673     out:
674    @@ -645,6 +665,8 @@ asmlinkage long sys_lchown(const char __
675            error = user_path_walk_link(filename, &nd);
676            if (error)
677                    goto out;
678    +       error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
679    +       if (!error)
680            error = chown_common(nd.dentry, user, group);
681            path_release(&nd);
682     out:
683    @@ -664,6 +686,8 @@ asmlinkage long sys_fchown(unsigned int
684    
685            dentry = file->f_path.dentry;
686            audit_inode(NULL, dentry->d_inode);
687    +       error = ccs_chown_permission(dentry, file->f_vfsmnt, user, group);
688    +       if (!error)
689            error = chown_common(dentry, user, group);
690            fput(file);
691     out:
692    @@ -756,7 +780,9 @@ static struct file *do_filp_open(int dfd
693            if ((namei_flags+1) & O_ACCMODE)
694                    namei_flags++;
695    
696    +       ccs_save_open_mode(flags);
697            error = open_namei(dfd, filename, namei_flags, mode, &nd);
698    +       ccs_clear_open_mode();
699            if (!error)
700                    return nameidata_to_filp(&nd, flags);
701    
702    @@ -1085,6 +1111,8 @@ EXPORT_SYMBOL(sys_close);
703    */    */
704   asmlinkage long sys_vhangup(void)   asmlinkage long sys_vhangup(void)
705   {   {
 +       /***** TOMOYO Linux start. *****/  
706  +       if (!ccs_capable(CCS_SYS_VHANGUP))  +       if (!ccs_capable(CCS_SYS_VHANGUP))
707  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
708          if (capable(CAP_SYS_TTY_CONFIG)) {          if (capable(CAP_SYS_TTY_CONFIG)) {
709                  /* XXX: this needs locking */                  /* XXX: this needs locking */
710                  tty_vhangup(current->signal->tty);                  tty_vhangup(current->signal->tty);
 --- linux-2.6.21.7.orig/fs/proc/Makefile  
 +++ linux-2.6.21.7/fs/proc/Makefile  
 @@ -15,3 +15,6 @@ proc-$(CONFIG_PROC_KCORE)     += kcore.o  
  proc-$(CONFIG_PROC_VMCORE)     += vmcore.o  
  proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o  
  proc-$(CONFIG_PRINTK)  += kmsg.o  
 +  
 +proc-$(CONFIG_SAKURA) += ccs_proc.o  
 +proc-$(CONFIG_TOMOYO) += ccs_proc.o  
711  --- linux-2.6.21.7.orig/fs/proc/proc_misc.c  --- linux-2.6.21.7.orig/fs/proc/proc_misc.c
712  +++ linux-2.6.21.7/fs/proc/proc_misc.c  +++ linux-2.6.21.7/fs/proc/proc_misc.c
713  @@ -747,4 +747,9 @@ void __init proc_misc_init(void)  @@ -747,4 +747,5 @@ void __init proc_misc_init(void)
714                          entry->proc_fops = &proc_sysrq_trigger_operations;                          entry->proc_fops = &proc_sysrq_trigger_operations;
715          }          }
716   #endif   #endif
717  +       /***** CCS start. *****/  +       printk(KERN_INFO "Hook version: 2.6.21.7 2009/09/10\n");
 +#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO)  
 +       printk(KERN_INFO "Hook version: 2.6.21.7 2009/03/18\n");  
 +#endif  
 +       /***** CCS end. *****/  
718   }   }
719  --- linux-2.6.21.7.orig/include/linux/init_task.h  --- linux-2.6.21.7.orig/include/linux/init_task.h
720  +++ linux-2.6.21.7/include/linux/init_task.h  +++ linux-2.6.21.7/include/linux/init_task.h
721  @@ -141,6 +141,10 @@ extern struct group_info init_groups;  @@ -88,6 +88,14 @@ extern struct nsproxy init_nsproxy;
722    
723     extern struct group_info init_groups;
724    
725    +#ifdef CONFIG_CCSECURITY
726    +#define INIT_CCSECURITY          \
727    +       .ccs_domain_info = NULL, \
728    +       .ccs_flags = 0,
729    +#else
730    +#define INIT_CCSECURITY
731    +#endif
732    +
733     /*
734      *  INIT_TASK is used to set up the first task table, touch at
735      * your own risk!. Base=0, limit=0x1fffff (=2MB)
736    @@ -141,6 +149,7 @@ extern struct group_info init_groups;
737          .pi_lock        = SPIN_LOCK_UNLOCKED,                           \          .pi_lock        = SPIN_LOCK_UNLOCKED,                           \
738          INIT_TRACE_IRQFLAGS                                             \          INIT_TRACE_IRQFLAGS                                             \
739          INIT_LOCKDEP                                                    \          INIT_LOCKDEP                                                    \
740  +       /***** TOMOYO Linux start. *****/        \  +       INIT_CCSECURITY                                                 \
 +       .ccs_domain_info = NULL,                 \  
 +       .ccs_flags = 0,                          \  
 +       /***** TOMOYO Linux end. *****/          \  
741   }   }
742    
743    
744  --- linux-2.6.21.7.orig/include/linux/sched.h  --- linux-2.6.21.7.orig/include/linux/sched.h
745  +++ linux-2.6.21.7/include/linux/sched.h  +++ linux-2.6.21.7/include/linux/sched.h
746  @@ -27,6 +27,10 @@  @@ -27,6 +27,8 @@
747   #define CLONE_NEWUTS           0x04000000      /* New utsname group? */   #define CLONE_NEWUTS           0x04000000      /* New utsname group? */
748   #define CLONE_NEWIPC           0x08000000      /* New ipcs */   #define CLONE_NEWIPC           0x08000000      /* New ipcs */
749    
 +/***** TOMOYO Linux start. *****/  
750  +struct ccs_domain_info;  +struct ccs_domain_info;
 +/***** TOMOYO Linux end. *****/  
751  +  +
752   /*   /*
753    * Scheduling policies    * Scheduling policies
754    */    */
755  @@ -1052,6 +1056,10 @@ struct task_struct {  @@ -1052,6 +1054,10 @@ struct task_struct {
756   #ifdef CONFIG_FAULT_INJECTION   #ifdef CONFIG_FAULT_INJECTION
757          int make_it_fail;          int make_it_fail;
758   #endif   #endif
759  +       /***** TOMOYO Linux start. *****/  +#ifdef CONFIG_CCSECURITY
760  +       struct ccs_domain_info *ccs_domain_info;  +       struct ccs_domain_info *ccs_domain_info;
761  +       u32 ccs_flags;  +       u32 ccs_flags;
762  +       /***** TOMOYO Linux end. *****/  +#endif
763   };   };
764    
765   static inline pid_t process_group(struct task_struct *tsk)   static inline pid_t process_group(struct task_struct *tsk)
766  --- linux-2.6.21.7.orig/kernel/compat.c  --- linux-2.6.21.7.orig/kernel/compat.c
767  +++ linux-2.6.21.7/kernel/compat.c  +++ linux-2.6.21.7/kernel/compat.c
768  @@ -25,6 +25,9 @@  @@ -25,6 +25,7 @@
769   #include <linux/posix-timers.h>   #include <linux/posix-timers.h>
770    
771   #include <asm/uaccess.h>   #include <asm/uaccess.h>
772  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
773    
774   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)
775   {   {
776  @@ -869,6 +872,10 @@ asmlinkage long compat_sys_stime(compat_  @@ -869,6 +870,8 @@ asmlinkage long compat_sys_stime(compat_
777          err = security_settime(&tv, NULL);          err = security_settime(&tv, NULL);
778          if (err)          if (err)
779                  return err;                  return err;
 +       /***** TOMOYO Linux start. *****/  
780  +       if (!ccs_capable(CCS_SYS_SETTIME))  +       if (!ccs_capable(CCS_SYS_SETTIME))
781  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
782    
783          do_settimeofday(&tv);          do_settimeofday(&tv);
784          return 0;          return 0;
785  --- linux-2.6.21.7.orig/kernel/kexec.c  --- linux-2.6.21.7.orig/kernel/kexec.c
786  +++ linux-2.6.21.7/kernel/kexec.c  +++ linux-2.6.21.7/kernel/kexec.c
787  @@ -28,6 +28,9 @@  @@ -28,6 +28,7 @@
788   #include <asm/io.h>   #include <asm/io.h>
789   #include <asm/system.h>   #include <asm/system.h>
790   #include <asm/semaphore.h>   #include <asm/semaphore.h>
791  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
792    
793   /* Per cpu memory for storing cpu states in case of system crash. */   /* Per cpu memory for storing cpu states in case of system crash. */
794   note_buf_t* crash_notes;   note_buf_t* crash_notes;
795  @@ -924,6 +927,10 @@ asmlinkage long sys_kexec_load(unsigned  @@ -924,6 +925,8 @@ asmlinkage long sys_kexec_load(unsigned
796          /* We only trust the superuser with rebooting the system. */          /* We only trust the superuser with rebooting the system. */
797          if (!capable(CAP_SYS_BOOT))          if (!capable(CAP_SYS_BOOT))
798                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
799  +       if (!ccs_capable(CCS_SYS_KEXEC_LOAD))  +       if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
800  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
801    
802          /*          /*
803           * Verify we have a legal set of flags           * Verify we have a legal set of flags
# Line 916  Source code for this patch is http://www Line 807  Source code for this patch is http://www
807          /* We can run anywhere, unlike our parent keventd(). */          /* We can run anywhere, unlike our parent keventd(). */
808          set_cpus_allowed(current, CPU_MASK_ALL);          set_cpus_allowed(current, CPU_MASK_ALL);
809    
810  +       /***** TOMOYO Linux start. *****/  +#ifdef CONFIG_CCSECURITY
811  +       current->ccs_domain_info = NULL;  +       current->ccs_domain_info = NULL;
812  +       current->ccs_flags = 0;  +       current->ccs_flags = 0;
813  +       /***** TOMOYO Linux end. *****/  +#endif
814  +  +
815          retval = -EPERM;          retval = -EPERM;
816          if (current->fs->root)          if (current->fs->root)
817                  retval = kernel_execve(sub_info->path,                  retval = kernel_execve(sub_info->path,
818  --- linux-2.6.21.7.orig/kernel/module.c  --- linux-2.6.21.7.orig/kernel/module.c
819  +++ linux-2.6.21.7/kernel/module.c  +++ linux-2.6.21.7/kernel/module.c
820  @@ -44,6 +44,9 @@  @@ -44,6 +44,7 @@
821   #include <asm/semaphore.h>   #include <asm/semaphore.h>
822   #include <asm/cacheflush.h>   #include <asm/cacheflush.h>
823   #include <linux/license.h>   #include <linux/license.h>
824  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
825    
826   #if 0   #if 0
827   #define DEBUGP printk   #define DEBUGP printk
828  @@ -662,6 +665,10 @@ sys_delete_module(const char __user *nam  @@ -662,6 +663,8 @@ sys_delete_module(const char __user *nam
829    
830          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
831                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
832  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
833  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
834    
835          if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)          if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
836                  return -EFAULT;                  return -EFAULT;
837  @@ -1983,6 +1990,10 @@ sys_init_module(void __user *umod,  @@ -1983,6 +1986,8 @@ sys_init_module(void __user *umod,
838          /* Must have permission */          /* Must have permission */
839          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
840                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
841  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
842  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
843    
844          /* Only one module load at a time, please */          /* Only one module load at a time, please */
845          if (mutex_lock_interruptible(&module_mutex) != 0)          if (mutex_lock_interruptible(&module_mutex) != 0)
846  --- linux-2.6.21.7.orig/kernel/ptrace.c  --- linux-2.6.21.7.orig/kernel/ptrace.c
847  +++ linux-2.6.21.7/kernel/ptrace.c  +++ linux-2.6.21.7/kernel/ptrace.c
848  @@ -21,6 +21,9 @@  @@ -21,6 +21,7 @@
849    
850   #include <asm/pgtable.h>   #include <asm/pgtable.h>
851   #include <asm/uaccess.h>   #include <asm/uaccess.h>
852  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
853    
854   /*   /*
855    * ptrace a task: make the debugger its new parent and    * ptrace a task: make the debugger its new parent and
856  @@ -456,6 +459,10 @@ asmlinkage long sys_ptrace(long request,  @@ -456,6 +457,8 @@ asmlinkage long sys_ptrace(long request,
857          /*          /*
858           * This lock_kernel fixes a subtle race with suid exec           * This lock_kernel fixes a subtle race with suid exec
859           */           */
 +       /***** TOMOYO Linux start. *****/  
860  +       if (!ccs_capable(CCS_SYS_PTRACE))  +       if (!ccs_capable(CCS_SYS_PTRACE))
861  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
862          lock_kernel();          lock_kernel();
863          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
864                  ret = ptrace_traceme();                  ret = ptrace_traceme();
865  --- linux-2.6.21.7.orig/kernel/sched.c  --- linux-2.6.21.7.orig/kernel/sched.c
866  +++ linux-2.6.21.7/kernel/sched.c  +++ linux-2.6.21.7/kernel/sched.c
867  @@ -55,6 +55,9 @@  @@ -55,6 +55,7 @@
868   #include <asm/tlb.h>   #include <asm/tlb.h>
869    
870   #include <asm/unistd.h>   #include <asm/unistd.h>
871  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
872    
873   /*   /*
874    * Scheduler clock - returns current time in nanosec units.    * Scheduler clock - returns current time in nanosec units.
875  @@ -3964,6 +3967,10 @@ int can_nice(const struct task_struct *p  @@ -3964,6 +3965,8 @@ int can_nice(const struct task_struct *p
876   asmlinkage long sys_nice(int increment)   asmlinkage long sys_nice(int increment)
877   {   {
878          long nice, retval;          long nice, retval;
 +       /***** TOMOYO Linux start. *****/  
879  +       if (!ccs_capable(CCS_SYS_NICE))  +       if (!ccs_capable(CCS_SYS_NICE))
880  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
881    
882          /*          /*
883           * Setpriority might change our priority at the same moment.           * Setpriority might change our priority at the same moment.
884  --- linux-2.6.21.7.orig/kernel/signal.c  --- linux-2.6.21.7.orig/kernel/signal.c
885  +++ linux-2.6.21.7/kernel/signal.c  +++ linux-2.6.21.7/kernel/signal.c
886  @@ -32,6 +32,9 @@  @@ -32,6 +32,7 @@
887   #include <asm/unistd.h>   #include <asm/unistd.h>
888   #include <asm/siginfo.h>   #include <asm/siginfo.h>
889   #include "audit.h"     /* audit_signal_info() */   #include "audit.h"     /* audit_signal_info() */
890  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
891    
892   /*   /*
893    * SLAB caches for signal bits.    * SLAB caches for signal bits.
894  @@ -2235,6 +2238,12 @@ asmlinkage long  @@ -2235,6 +2236,8 @@ asmlinkage long
895   sys_kill(int pid, int sig)   sys_kill(int pid, int sig)
896   {   {
897          struct siginfo info;          struct siginfo info;
898  +       /***** TOMOYO Linux start. *****/  +       if (ccs_kill_permission(pid, sig))
 +       if (sig && !ccs_capable(CCS_SYS_KILL))  
 +               return -EPERM;  
 +       if (sig && ccs_check_signal_acl(sig, pid))  
899  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
900    
901          info.si_signo = sig;          info.si_signo = sig;
902          info.si_errno = 0;          info.si_errno = 0;
903  @@ -2293,6 +2302,12 @@ asmlinkage long sys_tgkill(int tgid, int  @@ -2293,6 +2296,8 @@ asmlinkage long sys_tgkill(int tgid, int
904          /* This is only valid for single tasks */          /* This is only valid for single tasks */
905          if (pid <= 0 || tgid <= 0)          if (pid <= 0 || tgid <= 0)
906                  return -EINVAL;                  return -EINVAL;
907  +       /***** TOMOYO Linux start. *****/  +       if (ccs_tgkill_permission(tgid, pid, sig))
 +       if (sig && !ccs_capable(CCS_SYS_KILL))  
908  +               return -EPERM;  +               return -EPERM;
 +       if (sig && ccs_check_signal_acl(sig, pid))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
909    
910          return do_tkill(tgid, pid, sig);          return do_tkill(tgid, pid, sig);
911   }   }
912  @@ -2306,6 +2321,12 @@ sys_tkill(int pid, int sig)  @@ -2306,6 +2311,8 @@ sys_tkill(int pid, int sig)
913          /* This is only valid for single tasks */          /* This is only valid for single tasks */
914          if (pid <= 0)          if (pid <= 0)
915                  return -EINVAL;                  return -EINVAL;
916  +       /***** TOMOYO Linux start. *****/  +       if (ccs_tkill_permission(pid, sig))
 +       if (sig && !ccs_capable(CCS_SYS_KILL))  
 +               return -EPERM;  
 +       if (sig && ccs_check_signal_acl(sig, pid))  
917  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
918    
919          return do_tkill(0, pid, sig);          return do_tkill(0, pid, sig);
920   }   }
921    @@ -2323,6 +2330,8 @@ sys_rt_sigqueueinfo(int pid, int sig, si
922            if (info.si_code >= 0)
923                    return -EPERM;
924            info.si_signo = sig;
925    +       if (ccs_sigqueue_permission(pid, sig))
926    +               return -EPERM;
927    
928            /* POSIX.1b doesn't mention process groups.  */
929            return kill_proc_info(sig, &info, pid);
930  --- linux-2.6.21.7.orig/kernel/sys.c  --- linux-2.6.21.7.orig/kernel/sys.c
931  +++ linux-2.6.21.7/kernel/sys.c  +++ linux-2.6.21.7/kernel/sys.c
932  @@ -37,6 +37,9 @@  @@ -37,6 +37,7 @@
933   #include <asm/uaccess.h>   #include <asm/uaccess.h>
934   #include <asm/io.h>   #include <asm/io.h>
935   #include <asm/unistd.h>   #include <asm/unistd.h>
936  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
937    
938   #ifndef SET_UNALIGN_CTL   #ifndef SET_UNALIGN_CTL
939   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)
940  @@ -600,6 +603,12 @@ asmlinkage long sys_setpriority(int whic  @@ -600,6 +601,10 @@ asmlinkage long sys_setpriority(int whic
941    
942          if (which > 2 || which < 0)          if (which > 2 || which < 0)
943                  goto out;                  goto out;
 +       /***** TOMOYO Linux start. *****/  
944  +       if (!ccs_capable(CCS_SYS_NICE)) {  +       if (!ccs_capable(CCS_SYS_NICE)) {
945  +               error = -EPERM;  +               error = -EPERM;
946  +               goto out;  +               goto out;
947  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
948    
949          /* normalize: avoid signed division (rounding problems) */          /* normalize: avoid signed division (rounding problems) */
950          error = -ESRCH;          error = -ESRCH;
951  @@ -830,6 +839,10 @@ asmlinkage long sys_reboot(int magic1, i  @@ -830,6 +835,8 @@ asmlinkage long sys_reboot(int magic1, i
952                          magic2 != LINUX_REBOOT_MAGIC2B &&                          magic2 != LINUX_REBOOT_MAGIC2B &&
953                          magic2 != LINUX_REBOOT_MAGIC2C))                          magic2 != LINUX_REBOOT_MAGIC2C))
954                  return -EINVAL;                  return -EINVAL;
 +       /***** TOMOYO Linux start. *****/  
955  +       if (!ccs_capable(CCS_SYS_REBOOT))  +       if (!ccs_capable(CCS_SYS_REBOOT))
956  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
957    
958          /* Instead of trying to make the power_off code look like          /* Instead of trying to make the power_off code look like
959           * 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.
960  @@ -1806,6 +1819,10 @@ asmlinkage long sys_sethostname(char __u  @@ -1806,6 +1813,8 @@ asmlinkage long sys_sethostname(char __u
961                  return -EPERM;                  return -EPERM;
962          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
963                  return -EINVAL;                  return -EINVAL;
 +       /***** TOMOYO Linux start. *****/  
964  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
965  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
966          down_write(&uts_sem);          down_write(&uts_sem);
967          errno = -EFAULT;          errno = -EFAULT;
968          if (!copy_from_user(tmp, name, len)) {          if (!copy_from_user(tmp, name, len)) {
969  @@ -1851,6 +1868,10 @@ asmlinkage long sys_setdomainname(char _  @@ -1851,6 +1860,8 @@ asmlinkage long sys_setdomainname(char _
970                  return -EPERM;                  return -EPERM;
971          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
972                  return -EINVAL;                  return -EINVAL;
 +       /***** TOMOYO Linux start. *****/  
973  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
974  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
975    
976          down_write(&uts_sem);          down_write(&uts_sem);
977          errno = -EFAULT;          errno = -EFAULT;
978  --- linux-2.6.21.7.orig/kernel/sysctl.c  --- linux-2.6.21.7.orig/kernel/sysctl.c
979  +++ linux-2.6.21.7/kernel/sysctl.c  +++ linux-2.6.21.7/kernel/sysctl.c
980  @@ -48,6 +48,9 @@  @@ -48,6 +48,7 @@
981    
982   #include <asm/uaccess.h>   #include <asm/uaccess.h>
983   #include <asm/processor.h>   #include <asm/processor.h>
984  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
985    
986   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,
987                        void __user *buffer, size_t *lenp, loff_t *ppos);                        void __user *buffer, size_t *lenp, loff_t *ppos);
988  @@ -1088,6 +1091,93 @@ struct ctl_table_header *sysctl_head_nex  @@ -1088,6 +1089,7 @@ struct ctl_table_header *sysctl_head_nex
989   }   }
990    
991   #ifdef CONFIG_SYSCTL_SYSCALL   #ifdef CONFIG_SYSCTL_SYSCALL
992  +  +
 +/***** TOMOYO Linux start. *****/  
 +static int try_parse_table(int __user *name, int nlen, void __user *oldval,  
 +                          void __user *newval, ctl_table *table)  
 +{  
 +       int n;  
 +       int error = -ENOMEM;  
 +       int op = 0;  
 +       char *buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);  
 +       if (oldval)  
 +               op |= 004;  
 +       if (newval)  
 +               op |= 002;  
 +       if (!op) { /* Neither read nor write */  
 +               error = 0;  
 +               goto out;  
 +       }  
 +       if (!buffer)  
 +               goto out;  
 +       memset(buffer, 0, PAGE_SIZE);  
 +       snprintf(buffer, PAGE_SIZE - 1, "/proc/sys");  
 + repeat:  
 +       if (!nlen) {  
 +               error = -ENOTDIR;  
 +               goto out;  
 +       }  
 +       if (get_user(n, name)) {  
 +               error = -EFAULT;  
 +               goto out;  
 +       }  
 +       for ( ; table->ctl_name || table->procname; table++) {  
 +               if (n == table->ctl_name && n) {  
 +                       int pos = strlen(buffer);  
 +                       const char *cp = table->procname;  
 +                       error = -ENOMEM;  
 +                       if (cp) {  
 +                               if (pos + 1 >= PAGE_SIZE - 1)  
 +                                       goto out;  
 +                               buffer[pos++] = '/';  
 +                               while (*cp) {  
 +                                       const unsigned char c  
 +                                               = *(const unsigned char *) cp;  
 +                                       if (c == '\\') {  
 +                                               if (pos + 2 >= PAGE_SIZE - 1)  
 +                                                       goto out;  
 +                                               buffer[pos++] = '\\';  
 +                                               buffer[pos++] = '\\';  
 +                                       } else if (c > ' ' && c < 127) {  
 +                                               if (pos + 1 >= PAGE_SIZE - 1)  
 +                                                       goto out;  
 +                                               buffer[pos++] = c;  
 +                                       } else {  
 +                                               if (pos + 4 >= PAGE_SIZE - 1)  
 +                                                       goto out;  
 +                                               buffer[pos++] = '\\';  
 +                                               buffer[pos++] = (c >> 6) + '0';  
 +                                               buffer[pos++] = ((c >> 3) & 7)  
 +                                                       + '0';  
 +                                               buffer[pos++] = (c & 7) + '0';  
 +                                       }  
 +                                       cp++;  
 +                               }  
 +                       } else {  
 +                               /* Assume nobody assigns "=\$=" for procname. */  
 +                               snprintf(buffer + pos, PAGE_SIZE - pos - 1,  
 +                                        "/=%d=", n);  
 +                               if (!memchr(buffer, '\0', PAGE_SIZE - 2))  
 +                                       goto out;  
 +                       }  
 +                       if (table->child) {  
 +                               name++;  
 +                               nlen--;  
 +                               table = table->child;  
 +                               goto repeat;  
 +                       }  
 +                       /* printk("sysctl='%s'\n", buffer); */  
 +                       error = ccs_check_file_perm(buffer, op, "sysctl");  
 +                       goto out;  
 +               }  
 +       }  
 +       error = -ENOTDIR;  
 + out:  
 +       kfree(buffer);  
 +       return error;  
 +}  
 +/***** TOMOYO Linux end. *****/  
 +  
993   int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,   int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
994                 void __user *newval, size_t newlen)                 void __user *newval, size_t newlen)
995   {   {
996  @@ -1104,6 +1194,11 @@ int do_sysctl(int __user *name, int nlen  @@ -1104,6 +1106,9 @@ int do_sysctl(int __user *name, int nlen
997    
998          for (head = sysctl_head_next(NULL); head;          for (head = sysctl_head_next(NULL); head;
999                          head = sysctl_head_next(head)) {                          head = sysctl_head_next(head)) {
1000  +               /***** TOMOYO Linux start. *****/  +               error = ccs_parse_table(name, nlen, oldval, newval,
 +               error = try_parse_table(name, nlen, oldval, newval,  
1001  +                                       head->ctl_table);  +                                       head->ctl_table);
1002  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
1003                  error = parse_table(name, nlen, oldval, oldlenp,                  error = parse_table(name, nlen, oldval, oldlenp,
1004                                          newval, newlen, head->ctl_table);                                          newval, newlen, head->ctl_table);
1005                  if (error != -ENOTDIR) {                  if (error != -ENOTDIR) {
1006  --- linux-2.6.21.7.orig/kernel/time.c  --- linux-2.6.21.7.orig/kernel/time.c
1007  +++ linux-2.6.21.7/kernel/time.c  +++ linux-2.6.21.7/kernel/time.c
1008  @@ -39,6 +39,9 @@  @@ -39,6 +39,7 @@
1009    
1010   #include <asm/uaccess.h>   #include <asm/uaccess.h>
1011   #include <asm/unistd.h>   #include <asm/unistd.h>
1012  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
1013    
1014   /*   /*
1015    * 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
1016  @@ -91,6 +94,10 @@ asmlinkage long sys_stime(time_t __user  @@ -91,6 +92,8 @@ asmlinkage long sys_stime(time_t __user
1017          err = security_settime(&tv, NULL);          err = security_settime(&tv, NULL);
1018          if (err)          if (err)
1019                  return err;                  return err;
 +       /***** TOMOYO Linux start. *****/  
1020  +       if (!ccs_capable(CCS_SYS_SETTIME))  +       if (!ccs_capable(CCS_SYS_SETTIME))
1021  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1022    
1023          do_settimeofday(&tv);          do_settimeofday(&tv);
1024          return 0;          return 0;
1025  @@ -161,6 +168,10 @@ int do_sys_settimeofday(struct timespec  @@ -161,6 +164,8 @@ int do_sys_settimeofday(struct timespec
1026          error = security_settime(tv, tz);          error = security_settime(tv, tz);
1027          if (error)          if (error)
1028                  return error;                  return error;
 +       /***** TOMOYO Linux start. *****/  
1029  +       if (!ccs_capable(CCS_SYS_SETTIME))  +       if (!ccs_capable(CCS_SYS_SETTIME))
1030  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1031    
1032          if (tz) {          if (tz) {
1033                  /* SMP safe, global irq locking makes it work. */                  /* SMP safe, global irq locking makes it work. */
1034  --- linux-2.6.21.7.orig/kernel/time/ntp.c  --- linux-2.6.21.7.orig/kernel/time/ntp.c
1035  +++ linux-2.6.21.7/kernel/time/ntp.c  +++ linux-2.6.21.7/kernel/time/ntp.c
1036  @@ -14,6 +14,9 @@  @@ -14,6 +14,7 @@
1037    
1038   #include <asm/div64.h>   #include <asm/div64.h>
1039   #include <asm/timex.h>   #include <asm/timex.h>
1040  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
1041    
1042   /*   /*
1043    * Timekeeping variables    * Timekeeping variables
1044  @@ -201,6 +204,10 @@ int do_adjtimex(struct timex *txc)  @@ -201,6 +202,8 @@ int do_adjtimex(struct timex *txc)
1045          /* In order to modify anything, you gotta be super-user! */          /* In order to modify anything, you gotta be super-user! */
1046          if (txc->modes && !capable(CAP_SYS_TIME))          if (txc->modes && !capable(CAP_SYS_TIME))
1047                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
1048  +       if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))  +       if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
1049  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1050    
1051          /* Now we validate the data before disabling interrupts */          /* Now we validate the data before disabling interrupts */
1052    
 --- linux-2.6.21.7.orig/net/core/datagram.c  
 +++ linux-2.6.21.7/net/core/datagram.c  
 @@ -56,6 +56,11 @@  
  #include <net/sock.h>  
  #include <net/tcp_states.h>  
   
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +#include <linux/tomoyo_socket.h>  
 +/***** TOMOYO Linux end. *****/  
 +  
  /*  
   *     Is a socket 'connection oriented' ?  
   */  
 @@ -178,6 +183,12 @@ struct sk_buff *skb_recv_datagram(struct  
                 } else  
                         skb = skb_dequeue(&sk->sk_receive_queue);  
   
 +               /***** TOMOYO Linux start. *****/  
 +               error = ccs_socket_recv_datagram_permission(sk, skb, flags);  
 +               if (error)  
 +                       goto no_packet;  
 +               /***** TOMOYO Linux end. *****/  
 +  
                 if (skb)  
                         return skb;  
   
1053  --- linux-2.6.21.7.orig/net/ipv4/inet_connection_sock.c  --- linux-2.6.21.7.orig/net/ipv4/inet_connection_sock.c
1054  +++ linux-2.6.21.7/net/ipv4/inet_connection_sock.c  +++ linux-2.6.21.7/net/ipv4/inet_connection_sock.c
1055  @@ -23,6 +23,9 @@  @@ -23,6 +23,7 @@
1056   #include <net/route.h>   #include <net/route.h>
1057   #include <net/tcp_states.h>   #include <net/tcp_states.h>
1058   #include <net/xfrm.h>   #include <net/xfrm.h>
1059  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1060    
1061   #ifdef INET_CSK_DEBUG   #ifdef INET_CSK_DEBUG
1062   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";
1063  @@ -85,6 +88,10 @@ int inet_csk_get_port(struct inet_hashin  @@ -85,6 +86,8 @@ int inet_csk_get_port(struct inet_hashin
1064                  do {                  do {
1065                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
1066                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1067  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(rover))
 +                       if (ccs_may_autobind(rover))  
1068  +                               goto next;  +                               goto next;
 +                       /***** SAKURA Linux end. *****/  
1069                          inet_bind_bucket_for_each(tb, node, &head->chain)                          inet_bind_bucket_for_each(tb, node, &head->chain)
1070                                  if (tb->port == rover)                                  if (tb->port == rover)
1071                                          goto next;                                          goto next;
1072  --- linux-2.6.21.7.orig/net/ipv4/inet_hashtables.c  --- linux-2.6.21.7.orig/net/ipv4/inet_hashtables.c
1073  +++ linux-2.6.21.7/net/ipv4/inet_hashtables.c  +++ linux-2.6.21.7/net/ipv4/inet_hashtables.c
1074  @@ -22,6 +22,9 @@  @@ -22,6 +22,7 @@
1075   #include <net/inet_connection_sock.h>   #include <net/inet_connection_sock.h>
1076   #include <net/inet_hashtables.h>   #include <net/inet_hashtables.h>
1077   #include <net/ip.h>   #include <net/ip.h>
1078  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1079    
1080   /*   /*
1081    * Allocate and initialize a new local port bind bucket.    * Allocate and initialize a new local port bind bucket.
1082  @@ -292,6 +295,10 @@ int inet_hash_connect(struct inet_timewa  @@ -292,6 +293,8 @@ int inet_hash_connect(struct inet_timewa
1083                  local_bh_disable();                  local_bh_disable();
1084                  for (i = 1; i <= range; i++) {                  for (i = 1; i <= range; i++) {
1085                          port = low + (i + offset) % range;                          port = low + (i + offset) % range;
1086  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(port))
 +                       if (ccs_may_autobind(port))  
1087  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1088                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
1089                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1090    
1091    --- linux-2.6.21.7.orig/net/ipv4/raw.c
1092    +++ linux-2.6.21.7/net/ipv4/raw.c
1093    @@ -78,6 +78,7 @@
1094     #include <linux/seq_file.h>
1095     #include <linux/netfilter.h>
1096     #include <linux/netfilter_ipv4.h>
1097    +#include <linux/ccsecurity.h>
1098    
1099     struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE];
1100     DEFINE_RWLOCK(raw_v4_lock);
1101    @@ -597,6 +598,9 @@ static int raw_recvmsg(struct kiocb *ioc
1102            skb = skb_recv_datagram(sk, flags, noblock, &err);
1103            if (!skb)
1104                    goto out;
1105    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1106    +       if (err)
1107    +               goto out;
1108    
1109            copied = skb->len;
1110            if (len < copied) {
1111  --- linux-2.6.21.7.orig/net/ipv4/udp.c  --- linux-2.6.21.7.orig/net/ipv4/udp.c
1112  +++ linux-2.6.21.7/net/ipv4/udp.c  +++ linux-2.6.21.7/net/ipv4/udp.c
1113  @@ -102,6 +102,9 @@  @@ -102,6 +102,7 @@
1114   #include <net/checksum.h>   #include <net/checksum.h>
1115   #include <net/xfrm.h>   #include <net/xfrm.h>
1116   #include "udp_impl.h"   #include "udp_impl.h"
1117  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1118    
1119   /*   /*
1120    *     Snmp MIB for the UDP layer    *     Snmp MIB for the UDP layer
1121  @@ -162,6 +165,10 @@ int __udp_lib_get_port(struct sock *sk,  @@ -162,6 +163,8 @@ int __udp_lib_get_port(struct sock *sk,
1122                                          result = sysctl_local_port_range[0] +                                          result = sysctl_local_port_range[0] +
1123                                                  ((result - sysctl_local_port_range[0]) &                                                  ((result - sysctl_local_port_range[0]) &
1124                                                   (UDP_HTABLE_SIZE - 1));                                                   (UDP_HTABLE_SIZE - 1));
1125  +                               /***** SAKURA Linux start. *****/  +                               if (ccs_lport_reserved(result))
 +                               if (ccs_may_autobind(result))  
1126  +                                       continue;  +                                       continue;
 +                               /***** SAKURA Linux end. *****/  
1127                                  goto gotit;                                  goto gotit;
1128                          }                          }
1129                          size = 0;                          size = 0;
1130  @@ -180,6 +187,10 @@ int __udp_lib_get_port(struct sock *sk,  @@ -180,6 +183,8 @@ int __udp_lib_get_port(struct sock *sk,
1131                                  result = sysctl_local_port_range[0]                                  result = sysctl_local_port_range[0]
1132                                          + ((result - sysctl_local_port_range[0]) &                                          + ((result - sysctl_local_port_range[0]) &
1133                                             (UDP_HTABLE_SIZE - 1));                                             (UDP_HTABLE_SIZE - 1));
1134  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(result))
 +                       if (ccs_may_autobind(result))  
1135  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1136                          if (! __udp_lib_lport_inuse(result, udptable))                          if (! __udp_lib_lport_inuse(result, udptable))
1137                                  break;                                  break;
1138                  }                  }
1139    @@ -825,6 +830,9 @@ try_again:
1140            skb = skb_recv_datagram(sk, flags, noblock, &err);
1141            if (!skb)
1142                    goto out;
1143    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1144    +       if (err)
1145    +               goto out;
1146    
1147            copied = skb->len - sizeof(struct udphdr);
1148            if (copied > len) {
1149  --- linux-2.6.21.7.orig/net/ipv6/inet6_hashtables.c  --- linux-2.6.21.7.orig/net/ipv6/inet6_hashtables.c
1150  +++ linux-2.6.21.7/net/ipv6/inet6_hashtables.c  +++ linux-2.6.21.7/net/ipv6/inet6_hashtables.c
1151  @@ -21,6 +21,9 @@  @@ -21,6 +21,7 @@
1152   #include <net/inet_hashtables.h>   #include <net/inet_hashtables.h>
1153   #include <net/inet6_hashtables.h>   #include <net/inet6_hashtables.h>
1154   #include <net/ip.h>   #include <net/ip.h>
1155  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1156    
1157   void __inet6_hash(struct inet_hashinfo *hashinfo,   void __inet6_hash(struct inet_hashinfo *hashinfo,
1158                                  struct sock *sk)                                  struct sock *sk)
1159  @@ -266,6 +269,10 @@ int inet6_hash_connect(struct inet_timew  @@ -266,6 +267,8 @@ int inet6_hash_connect(struct inet_timew
1160                  local_bh_disable();                  local_bh_disable();
1161                  for (i = 1; i <= range; i++) {                  for (i = 1; i <= range; i++) {
1162                          port = low + (i + offset) % range;                          port = low + (i + offset) % range;
1163  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(port))
 +                       if (ccs_may_autobind(port))  
1164  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1165                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
1166                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1167    
1168    --- linux-2.6.21.7.orig/net/ipv6/raw.c
1169    +++ linux-2.6.21.7/net/ipv6/raw.c
1170    @@ -58,6 +58,7 @@
1171    
1172     #include <linux/proc_fs.h>
1173     #include <linux/seq_file.h>
1174    +#include <linux/ccsecurity.h>
1175    
1176     struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE];
1177     DEFINE_RWLOCK(raw_v6_lock);
1178    @@ -413,6 +414,9 @@ static int rawv6_recvmsg(struct kiocb *i
1179            skb = skb_recv_datagram(sk, flags, noblock, &err);
1180            if (!skb)
1181                    goto out;
1182    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1183    +       if (err)
1184    +               goto out;
1185    
1186            copied = skb->len;
1187            if (copied > len) {
1188    --- linux-2.6.21.7.orig/net/ipv6/udp.c
1189    +++ linux-2.6.21.7/net/ipv6/udp.c
1190    @@ -49,6 +49,7 @@
1191     #include <linux/proc_fs.h>
1192     #include <linux/seq_file.h>
1193     #include "udp_impl.h"
1194    +#include <linux/ccsecurity.h>
1195    
1196     DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
1197    
1198    @@ -133,6 +134,9 @@ try_again:
1199            skb = skb_recv_datagram(sk, flags, noblock, &err);
1200            if (!skb)
1201                    goto out;
1202    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1203    +       if (err)
1204    +               goto out;
1205    
1206            copied = skb->len - sizeof(struct udphdr);
1207            if (copied > len) {
1208  --- linux-2.6.21.7.orig/net/socket.c  --- linux-2.6.21.7.orig/net/socket.c
1209  +++ linux-2.6.21.7/net/socket.c  +++ linux-2.6.21.7/net/socket.c
1210  @@ -93,6 +93,11 @@  @@ -93,6 +93,8 @@
1211   #include <net/sock.h>   #include <net/sock.h>
1212   #include <linux/netfilter.h>   #include <linux/netfilter.h>
1213    
1214  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +#include <linux/tomoyo_socket.h>  
 +/***** TOMOYO Linux end. *****/  
1215  +  +
1216   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
1217   static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,   static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
1218                           unsigned long nr_segs, loff_t pos);                           unsigned long nr_segs, loff_t pos);
1219  @@ -549,6 +554,12 @@ static inline int __sock_sendmsg(struct  @@ -547,6 +549,10 @@ static inline int __sock_sendmsg(struct
1220            si->size = size;
1221    
1222          err = security_socket_sendmsg(sock, msg, size);          err = security_socket_sendmsg(sock, msg, size);
1223    +       if (!err)
1224    +               err = ccs_socket_sendmsg_permission(sock, (struct sockaddr *)
1225    +                                                   msg->msg_name,
1226    +                                                   msg->msg_namelen);
1227          if (err)          if (err)
1228                  return err;                  return err;
 +       /***** TOMOYO Linux start. *****/  
 +       if (ccs_socket_sendmsg_permission(sock,  
 +                                         (struct sockaddr *) msg->msg_name,  
 +                                         msg->msg_namelen))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
1229    
1230          return sock->ops->sendmsg(iocb, sock, msg, size);  @@ -1071,6 +1077,8 @@ static int __sock_create(int family, int
  }  
 @@ -1070,6 +1081,12 @@ static int __sock_create(int family, int  
                 family = PF_PACKET;  
1231          }          }
1232    
 +       /***** TOMOYO Linux start. *****/  
 +       err = ccs_socket_create_permission(family, type, protocol);  
 +       if (err)  
 +               return err;  
 +       /***** TOMOYO Linux end. *****/  
 +  
1233          err = security_socket_create(family, type, protocol, kern);          err = security_socket_create(family, type, protocol, kern);
1234    +       if (!err)
1235    +               err = ccs_socket_create_permission(family, type, protocol);
1236          if (err)          if (err)
1237                  return err;                  return err;
1238  @@ -1298,6 +1315,13 @@ asmlinkage long sys_bind(int fd, struct  
1239                          err = security_socket_bind(sock,  @@ -1299,6 +1307,11 @@ asmlinkage long sys_bind(int fd, struct
1240                                                     (struct sockaddr *)address,                                                     (struct sockaddr *)address,
1241                                                     addrlen);                                                     addrlen);
1242  +                       /***** TOMOYO Linux start. *****/                          if (!err)
 +                       if (!err)  
1243  +                               err = ccs_socket_bind_permission(sock,  +                               err = ccs_socket_bind_permission(sock,
1244  +                                                        (struct sockaddr *)  +                                                        (struct sockaddr *)
1245  +                                                                address,  +                                                                address,
1246  +                                                                addrlen);  +                                                                addrlen);
1247  +                       /***** TOMOYO Linux end. *****/  +                       if (!err)
                         if (!err)  
1248                                  err = sock->ops->bind(sock,                                  err = sock->ops->bind(sock,
1249                                                        (struct sockaddr *)                                                        (struct sockaddr *)
1250  @@ -1327,6 +1351,10 @@ asmlinkage long sys_listen(int fd, int b                                                        address, addrlen);
1251                          backlog = sysctl_somaxconn;  @@ -1328,6 +1341,8 @@ asmlinkage long sys_listen(int fd, int b
1252    
1253                  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. *****/  
1254                  if (!err)                  if (!err)
1255    +                       err = ccs_socket_listen_permission(sock);
1256    +               if (!err)
1257                          err = sock->ops->listen(sock, backlog);                          err = sock->ops->listen(sock, backlog);
1258    
1259  @@ -1391,6 +1419,13 @@ asmlinkage long sys_accept(int fd, struc                  fput_light(sock->file, fput_needed);
1260    @@ -1391,6 +1406,11 @@ asmlinkage long sys_accept(int fd, struc
1261          if (err < 0)          if (err < 0)
1262                  goto out_fd;                  goto out_fd;
1263    
 +       /***** TOMOYO Linux start. *****/  
1264  +       if (ccs_socket_accept_permission(newsock,  +       if (ccs_socket_accept_permission(newsock,
1265  +                                        (struct sockaddr *) address)) {  +                                        (struct sockaddr *) address)) {
1266  +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */  +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */
1267  +               goto out_fd;  +               goto out_fd;
1268  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
1269          if (upeer_sockaddr) {          if (upeer_sockaddr) {
1270                  if (newsock->ops->getname(newsock, (struct sockaddr *)address,                  if (newsock->ops->getname(newsock, (struct sockaddr *)address,
1271                                            &len, 2) < 0) {                                            &len, 2) < 0) {
1272  @@ -1455,6 +1490,12 @@ asmlinkage long sys_connect(int fd, stru  @@ -1453,6 +1473,9 @@ asmlinkage long sys_connect(int fd, stru
1273    
1274            err =
1275              security_socket_connect(sock, (struct sockaddr *)address, addrlen);              security_socket_connect(sock, (struct sockaddr *)address, addrlen);
1276    +       if (!err)
1277    +               err = ccs_socket_connect_permission(sock, (struct sockaddr *)
1278    +                                                   address, addrlen);
1279          if (err)          if (err)
1280                  goto out_put;                  goto out_put;
 +       /***** TOMOYO Linux start. *****/  
 +       err = ccs_socket_connect_permission(sock, (struct sockaddr *) address,  
 +                                           addrlen);  
 +       if (err)  
 +               goto out_put;  
 +       /***** TOMOYO Linux end. *****/  
1281    
         err = sock->ops->connect(sock, (struct sockaddr *)address, addrlen,  
                                  sock->file->f_flags);  
1282  --- linux-2.6.21.7.orig/net/unix/af_unix.c  --- linux-2.6.21.7.orig/net/unix/af_unix.c
1283  +++ linux-2.6.21.7/net/unix/af_unix.c  +++ linux-2.6.21.7/net/unix/af_unix.c
1284  @@ -116,6 +116,9 @@  @@ -116,6 +116,7 @@
1285   #include <linux/mount.h>   #include <linux/mount.h>
1286   #include <net/checksum.h>   #include <net/checksum.h>
1287   #include <linux/security.h>   #include <linux/security.h>
1288  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
1289    
1290   int sysctl_unix_max_dgram_qlen __read_mostly = 10;   int sysctl_unix_max_dgram_qlen __read_mostly = 10;
1291    
1292  @@ -808,6 +811,11 @@ static int unix_bind(struct socket *sock  @@ -808,6 +809,9 @@ static int unix_bind(struct socket *sock
1293                   */                   */
1294                  mode = S_IFSOCK |                  mode = S_IFSOCK |
1295                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
1296  +               /***** TOMOYO Linux start. *****/  +               err = ccs_mknod_permission(nd.dentry->d_inode, dentry, nd.mnt,
1297  +               err = ccs_check_mknod_permission(nd.dentry->d_inode, dentry,  +                                          mode, 0);
 +                                                nd.mnt, mode, 0);  
1298  +               if (!err)  +               if (!err)
 +               /***** TOMOYO Linux end. *****/  
1299                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
1300                  if (err)                  if (err)
1301                          goto out_mknod_dput;                          goto out_mknod_dput;
1302    --- linux-2.6.21.7.orig/security/Kconfig
1303    +++ linux-2.6.21.7/security/Kconfig
1304    @@ -95,5 +95,7 @@ config SECURITY_ROOTPLUG
1305    
1306     source security/selinux/Kconfig
1307    
1308    +source security/ccsecurity/Kconfig
1309    +
1310     endmenu
1311    
1312    --- linux-2.6.21.7.orig/security/Makefile
1313    +++ linux-2.6.21.7/security/Makefile
1314    @@ -16,3 +16,6 @@ obj-$(CONFIG_SECURITY)                        += security.o d
1315     obj-$(CONFIG_SECURITY_SELINUX)         += selinux/built-in.o
1316     obj-$(CONFIG_SECURITY_CAPABILITIES)    += commoncap.o capability.o
1317     obj-$(CONFIG_SECURITY_ROOTPLUG)                += commoncap.o root_plug.o
1318    +
1319    +subdir-$(CONFIG_CCSECURITY)+= ccsecurity
1320    +obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o

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

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