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

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 2299 by kumaneko, Mon Mar 23 06:08:10 2009 UTC trunk/1.7.x/ccs-patch/patches/ccs-patch-2.6.21.diff revision 3053 by kumaneko, Thu Sep 17 07:09:58 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                  |   22 ++++++++++++++++++++++
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                 |    9 ++++++   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, 507 insertions(+), 2 deletions(-)   security/Makefile               |    3 +++
48     43 files changed, 278 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, nd->mnt,  +                                    0);
 +                                          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.dentry->d_inode, dentry,  +                                            nd.mnt, mode, dev);
 +                                                  nd.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  @@ -542,6 +543,8 @@ static int do_umount(struct vfsmount *mn
519            LIST_HEAD(umount_list);
520    
521            retval = security_sb_umount(mnt, flags);
522    +       if (!retval)
523    +               retval = ccs_umount_permission(mnt, flags);
524          if (retval)          if (retval)
525                  return retval;                  return retval;
526    
527  +       /***** SAKURA Linux start. *****/  @@ -633,6 +636,8 @@ asmlinkage long sys_umount(char __user *
 +       if (ccs_may_umount(mnt))  
 +               return -EPERM;  
 +       /***** SAKURA Linux end. *****/  
 +  
         /*  
          * Allow userspace to request a mountpoint be expired rather than  
          * unmounting unconditionally. Unmount only happens if:  
 @@ -633,6 +644,10 @@ asmlinkage long sys_umount(char __user *  
528   {   {
529          struct nameidata nd;          struct nameidata nd;
530          int retval;          int retval;
 +       /***** TOMOYO Linux start. *****/  
531  +       if (!ccs_capable(CCS_SYS_UMOUNT))  +       if (!ccs_capable(CCS_SYS_UMOUNT))
532  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
533    
534          retval = __user_walk(name, LOOKUP_FOLLOW, &nd);          retval = __user_walk(name, LOOKUP_FOLLOW, &nd);
535          if (retval)          if (retval)
536  @@ -917,6 +932,11 @@ static int do_loopback(struct nameidata  @@ -917,6 +922,9 @@ static int do_loopback(struct nameidata
537    
538          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
539                  goto out;                  goto out;
 +       /***** SAKURA Linux start. *****/  
540  +       err = -EPERM;  +       err = -EPERM;
541  +       if (ccs_may_mount(nd))  +       if (ccs_may_mount(nd))
542  +               goto out;  +               goto out;
 +       /***** SAKURA Linux end. *****/  
543    
544          err = -ENOMEM;          err = -ENOMEM;
545          if (recurse)          if (recurse)
546  @@ -1002,6 +1022,11 @@ static int do_move_mount(struct nameidat  @@ -1002,6 +1010,9 @@ static int do_move_mount(struct nameidat
547          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
548                  goto out;                  goto out;
549    
 +       /***** SAKURA Linux start. *****/  
550  +       err = -EPERM;  +       err = -EPERM;
551  +       if (ccs_may_umount(old_nd.mnt) || ccs_may_mount(nd))  +       if (ccs_may_mount(nd))
552  +               goto out;  +               goto out;
 +       /***** SAKURA Linux end. *****/  
553          err = -ENOENT;          err = -ENOENT;
554          mutex_lock(&nd->dentry->d_inode->i_mutex);          mutex_lock(&nd->dentry->d_inode->i_mutex);
555          if (IS_DEADDIR(nd->dentry->d_inode))          if (IS_DEADDIR(nd->dentry->d_inode))
556  @@ -1103,6 +1128,11 @@ int do_add_mount(struct vfsmount *newmnt  @@ -1103,6 +1114,9 @@ int do_add_mount(struct vfsmount *newmnt
557          err = -EINVAL;          err = -EINVAL;
558          if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))          if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
559                  goto unlock;                  goto unlock;
 +       /***** SAKURA Linux start. *****/  
560  +       err = -EPERM;  +       err = -EPERM;
561  +       if (ccs_may_mount(nd))  +       if (ccs_may_mount(nd))
562  +               goto unlock;  +               goto unlock;
 +       /***** SAKURA Linux end. *****/  
563    
564          newmnt->mnt_flags = mnt_flags;          newmnt->mnt_flags = mnt_flags;
565          if ((err = graft_tree(newmnt, nd)))          if ((err = graft_tree(newmnt, nd)))
566  @@ -1394,6 +1424,17 @@ long do_mount(char *dev_name, char *dir_  @@ -1376,6 +1390,7 @@ int copy_mount_options(const void __user
567          if (data_page)   long do_mount(char *dev_name, char *dir_name, char *type_page,
568                  ((char *)data_page)[PAGE_SIZE - 1] = 0;                    unsigned long flags, void *data_page)
569     {
570  +       /***** TOMOYO Linux start. *****/  +       const unsigned long original_flags = flags;
571  +       if (!ccs_capable(CCS_SYS_MOUNT))          struct nameidata nd;
572  +               return -EPERM;          int retval = 0;
573  +       /***** TOMOYO Linux end. *****/          int mnt_flags = 0;
574  +       /***** SAKURA Linux start. *****/  @@ -1417,6 +1432,9 @@ long do_mount(char *dev_name, char *dir_
575  +       retval = ccs_check_mount_permission(dev_name, dir_name, type_page,                  return retval;
576  +                                           &flags);  
577  +       if (retval)          retval = security_sb_mount(dev_name, &nd, type_page, flags, data_page);
578  +               return retval;  +       if (!retval)
579  +       /***** SAKURA Linux end. *****/  +               retval = ccs_mount_permission(dev_name, &nd, type_page,
580  +  +                                             original_flags, data_page);
581          /* Separate the per-mountpoint flags */          if (retval)
582          if (flags & MS_NOSUID)                  goto dput_out;
583                  mnt_flags |= MNT_NOSUID;  
584  @@ -1686,6 +1727,10 @@ asmlinkage long sys_pivot_root(const cha  @@ -1686,6 +1704,8 @@ asmlinkage long sys_pivot_root(const cha
585    
586          if (!capable(CAP_SYS_ADMIN))          if (!capable(CAP_SYS_ADMIN))
587                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
588  +       if (!ccs_capable(CCS_SYS_PIVOT_ROOT))  +       if (!ccs_capable(CCS_SYS_PIVOT_ROOT))
589  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
590    
591          lock_kernel();          lock_kernel();
592    
593  @@ -1702,6 +1747,10 @@ asmlinkage long sys_pivot_root(const cha  @@ -1702,6 +1722,8 @@ asmlinkage long sys_pivot_root(const cha
594                  goto out1;                  goto out1;
595    
596          error = security_sb_pivotroot(&old_nd, &new_nd);          error = security_sb_pivotroot(&old_nd, &new_nd);
 +       /***** SAKURA Linux start. *****/  
597  +       if (!error)  +       if (!error)
598  +               error = ccs_check_pivot_root_permission(&old_nd, &new_nd);  +               error = ccs_pivot_root_permission(&old_nd, &new_nd);
 +       /***** SAKURA Linux end. *****/  
599          if (error) {          if (error) {
600                  path_release(&old_nd);                  path_release(&old_nd);
601                  goto out1;                  goto out1;
602  --- linux-2.6.21.7.orig/fs/open.c  --- linux-2.6.21.7.orig/fs/open.c
603  +++ linux-2.6.21.7/fs/open.c  +++ linux-2.6.21.7/fs/open.c
604  @@ -27,6 +27,12 @@  @@ -27,6 +27,7 @@
605   #include <linux/syscalls.h>   #include <linux/syscalls.h>
606   #include <linux/rcupdate.h>   #include <linux/rcupdate.h>
607   #include <linux/audit.h>   #include <linux/audit.h>
608  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
609    
610   int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)   int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
611   {   {
612  @@ -264,6 +270,10 @@ static long do_sys_truncate(const char _  @@ -264,6 +265,8 @@ static long do_sys_truncate(const char _
613          if (error)          if (error)
614                  goto dput_and_out;                  goto dput_and_out;
615    
616  +       /***** TOMOYO Linux start. *****/  +       error = ccs_truncate_permission(nd.dentry, nd.mnt, length, 0);
 +       error = ccs_check_truncate_permission(nd.dentry, nd.mnt, length, 0);  
617  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
618          error = locks_verify_truncate(inode, NULL, length);          error = locks_verify_truncate(inode, NULL, length);
619          if (!error) {          if (!error) {
620                  DQUOT_INIT(inode);                  DQUOT_INIT(inode);
621  @@ -317,6 +327,12 @@ static long do_sys_ftruncate(unsigned in  @@ -317,6 +320,9 @@ static long do_sys_ftruncate(unsigned in
622          if (IS_APPEND(inode))          if (IS_APPEND(inode))
623                  goto out_putf;                  goto out_putf;
624    
625  +       /***** TOMOYO Linux start. *****/  +       error = ccs_truncate_permission(dentry, file->f_vfsmnt, length, 0);
 +       error = ccs_check_truncate_permission(dentry, file->f_vfsmnt, length,  
 +                                             0);  
626  +       if (error)  +       if (error)
627  +               goto out_putf;  +               goto out_putf;
 +       /***** TOMOYO Linux end. *****/  
628          error = locks_verify_truncate(inode, file, length);          error = locks_verify_truncate(inode, file, length);
629          if (!error)          if (!error)
630                  error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);                  error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);
631  @@ -481,6 +497,14 @@ asmlinkage long sys_chroot(const char __  @@ -481,6 +487,10 @@ asmlinkage long sys_chroot(const char __
632          error = -EPERM;          error = -EPERM;
633          if (!capable(CAP_SYS_CHROOT))          if (!capable(CAP_SYS_CHROOT))
634                  goto dput_and_out;                  goto dput_and_out;
 +       /***** TOMOYO Linux start. *****/  
635  +       if (!ccs_capable(CCS_SYS_CHROOT))  +       if (!ccs_capable(CCS_SYS_CHROOT))
636  +               goto dput_and_out;  +               goto dput_and_out;
637  +       /***** TOMOYO Linux end. *****/  +       if (ccs_chroot_permission(&nd))
 +       /***** SAKURA Linux start. *****/  
 +       if (ccs_check_chroot_permission(&nd))  
638  +               goto dput_and_out;  +               goto dput_and_out;
 +       /***** SAKURA Linux end. *****/  
639    
640          set_fs_root(current->fs, nd.mnt, nd.dentry);          set_fs_root(current->fs, nd.mnt, nd.dentry);
641          set_fs_altroot();          set_fs_altroot();
642  @@ -1085,6 +1109,10 @@ EXPORT_SYMBOL(sys_close);  @@ -514,6 +524,9 @@ asmlinkage long sys_fchmod(unsigned int
643            err = -EPERM;
644            if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
645                    goto out_putf;
646    +       err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode);
647    +       if (err)
648    +               goto out_putf;
649            mutex_lock(&inode->i_mutex);
650            if (mode == (mode_t) -1)
651                    mode = inode->i_mode;
652    @@ -548,6 +561,9 @@ asmlinkage long sys_fchmodat(int dfd, co
653            error = -EPERM;
654            if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
655                    goto dput_and_out;
656    +       error = ccs_chmod_permission(nd.dentry, nd.mnt, mode);
657    +       if (error)
658    +               goto dput_and_out;
659    
660            mutex_lock(&inode->i_mutex);
661            if (mode == (mode_t) -1)
662    @@ -611,6 +627,8 @@ asmlinkage long sys_chown(const char __u
663            error = user_path_walk(filename, &nd);
664            if (error)
665                    goto out;
666    +       error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
667    +       if (!error)
668            error = chown_common(nd.dentry, user, group);
669            path_release(&nd);
670     out:
671    @@ -631,6 +649,8 @@ asmlinkage long sys_fchownat(int dfd, co
672            error = __user_walk_fd(dfd, filename, follow, &nd);
673            if (error)
674                    goto out;
675    +       error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
676    +       if (!error)
677            error = chown_common(nd.dentry, user, group);
678            path_release(&nd);
679     out:
680    @@ -645,6 +665,8 @@ asmlinkage long sys_lchown(const char __
681            error = user_path_walk_link(filename, &nd);
682            if (error)
683                    goto out;
684    +       error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
685    +       if (!error)
686            error = chown_common(nd.dentry, user, group);
687            path_release(&nd);
688     out:
689    @@ -664,6 +686,8 @@ asmlinkage long sys_fchown(unsigned int
690    
691            dentry = file->f_path.dentry;
692            audit_inode(NULL, dentry->d_inode);
693    +       error = ccs_chown_permission(dentry, file->f_vfsmnt, user, group);
694    +       if (!error)
695            error = chown_common(dentry, user, group);
696            fput(file);
697     out:
698    @@ -756,7 +780,9 @@ static struct file *do_filp_open(int dfd
699            if ((namei_flags+1) & O_ACCMODE)
700                    namei_flags++;
701    
702    +       ccs_save_open_mode(flags);
703            error = open_namei(dfd, filename, namei_flags, mode, &nd);
704    +       ccs_clear_open_mode();
705            if (!error)
706                    return nameidata_to_filp(&nd, flags);
707    
708    @@ -1085,6 +1111,8 @@ EXPORT_SYMBOL(sys_close);
709    */    */
710   asmlinkage long sys_vhangup(void)   asmlinkage long sys_vhangup(void)
711   {   {
 +       /***** TOMOYO Linux start. *****/  
712  +       if (!ccs_capable(CCS_SYS_VHANGUP))  +       if (!ccs_capable(CCS_SYS_VHANGUP))
713  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
714          if (capable(CAP_SYS_TTY_CONFIG)) {          if (capable(CAP_SYS_TTY_CONFIG)) {
715                  /* XXX: this needs locking */                  /* XXX: this needs locking */
716                  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  
717  --- linux-2.6.21.7.orig/fs/proc/proc_misc.c  --- linux-2.6.21.7.orig/fs/proc/proc_misc.c
718  +++ linux-2.6.21.7/fs/proc/proc_misc.c  +++ linux-2.6.21.7/fs/proc/proc_misc.c
719  @@ -747,4 +747,9 @@ void __init proc_misc_init(void)  @@ -747,4 +747,5 @@ void __init proc_misc_init(void)
720                          entry->proc_fops = &proc_sysrq_trigger_operations;                          entry->proc_fops = &proc_sysrq_trigger_operations;
721          }          }
722   #endif   #endif
723  +       /***** CCS start. *****/  +       printk(KERN_INFO "Hook version: 2.6.21.7 2009/09/17\n);
 +#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO)  
 +       printk(KERN_INFO "Hook version: 2.6.21.7 2009/03/18\n");  
 +#endif  
 +       /***** CCS end. *****/  
724   }   }
725  --- linux-2.6.21.7.orig/include/linux/init_task.h  --- linux-2.6.21.7.orig/include/linux/init_task.h
726  +++ linux-2.6.21.7/include/linux/init_task.h  +++ linux-2.6.21.7/include/linux/init_task.h
727  @@ -141,6 +141,10 @@ extern struct group_info init_groups;  @@ -88,6 +88,14 @@ extern struct nsproxy init_nsproxy;
728    
729     extern struct group_info init_groups;
730    
731    +#ifdef CONFIG_CCSECURITY
732    +#define INIT_CCSECURITY          \
733    +       .ccs_domain_info = NULL, \
734    +       .ccs_flags = 0,
735    +#else
736    +#define INIT_CCSECURITY
737    +#endif
738    +
739     /*
740      *  INIT_TASK is used to set up the first task table, touch at
741      * your own risk!. Base=0, limit=0x1fffff (=2MB)
742    @@ -141,6 +149,7 @@ extern struct group_info init_groups;
743          .pi_lock        = SPIN_LOCK_UNLOCKED,                           \          .pi_lock        = SPIN_LOCK_UNLOCKED,                           \
744          INIT_TRACE_IRQFLAGS                                             \          INIT_TRACE_IRQFLAGS                                             \
745          INIT_LOCKDEP                                                    \          INIT_LOCKDEP                                                    \
746  +       /***** TOMOYO Linux start. *****/        \  +       INIT_CCSECURITY                                                 \
 +       .ccs_domain_info = NULL,                 \  
 +       .ccs_flags = 0,                          \  
 +       /***** TOMOYO Linux end. *****/          \  
747   }   }
748    
749    
750  --- linux-2.6.21.7.orig/include/linux/sched.h  --- linux-2.6.21.7.orig/include/linux/sched.h
751  +++ linux-2.6.21.7/include/linux/sched.h  +++ linux-2.6.21.7/include/linux/sched.h
752  @@ -27,6 +27,10 @@  @@ -27,6 +27,8 @@
753   #define CLONE_NEWUTS           0x04000000      /* New utsname group? */   #define CLONE_NEWUTS           0x04000000      /* New utsname group? */
754   #define CLONE_NEWIPC           0x08000000      /* New ipcs */   #define CLONE_NEWIPC           0x08000000      /* New ipcs */
755    
 +/***** TOMOYO Linux start. *****/  
756  +struct ccs_domain_info;  +struct ccs_domain_info;
 +/***** TOMOYO Linux end. *****/  
757  +  +
758   /*   /*
759    * Scheduling policies    * Scheduling policies
760    */    */
761  @@ -1052,6 +1056,10 @@ struct task_struct {  @@ -1052,6 +1054,10 @@ struct task_struct {
762   #ifdef CONFIG_FAULT_INJECTION   #ifdef CONFIG_FAULT_INJECTION
763          int make_it_fail;          int make_it_fail;
764   #endif   #endif
765  +       /***** TOMOYO Linux start. *****/  +#ifdef CONFIG_CCSECURITY
766  +       struct ccs_domain_info *ccs_domain_info;  +       struct ccs_domain_info *ccs_domain_info;
767  +       u32 ccs_flags;  +       u32 ccs_flags;
768  +       /***** TOMOYO Linux end. *****/  +#endif
769   };   };
770    
771   static inline pid_t process_group(struct task_struct *tsk)   static inline pid_t process_group(struct task_struct *tsk)
772  --- linux-2.6.21.7.orig/kernel/compat.c  --- linux-2.6.21.7.orig/kernel/compat.c
773  +++ linux-2.6.21.7/kernel/compat.c  +++ linux-2.6.21.7/kernel/compat.c
774  @@ -25,6 +25,9 @@  @@ -25,6 +25,7 @@
775   #include <linux/posix-timers.h>   #include <linux/posix-timers.h>
776    
777   #include <asm/uaccess.h>   #include <asm/uaccess.h>
778  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
779    
780   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)
781   {   {
782  @@ -869,6 +872,10 @@ asmlinkage long compat_sys_stime(compat_  @@ -869,6 +870,8 @@ asmlinkage long compat_sys_stime(compat_
783          err = security_settime(&tv, NULL);          err = security_settime(&tv, NULL);
784          if (err)          if (err)
785                  return err;                  return err;
 +       /***** TOMOYO Linux start. *****/  
786  +       if (!ccs_capable(CCS_SYS_SETTIME))  +       if (!ccs_capable(CCS_SYS_SETTIME))
787  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
788    
789          do_settimeofday(&tv);          do_settimeofday(&tv);
790          return 0;          return 0;
791  --- linux-2.6.21.7.orig/kernel/kexec.c  --- linux-2.6.21.7.orig/kernel/kexec.c
792  +++ linux-2.6.21.7/kernel/kexec.c  +++ linux-2.6.21.7/kernel/kexec.c
793  @@ -28,6 +28,9 @@  @@ -28,6 +28,7 @@
794   #include <asm/io.h>   #include <asm/io.h>
795   #include <asm/system.h>   #include <asm/system.h>
796   #include <asm/semaphore.h>   #include <asm/semaphore.h>
797  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
798    
799   /* Per cpu memory for storing cpu states in case of system crash. */   /* Per cpu memory for storing cpu states in case of system crash. */
800   note_buf_t* crash_notes;   note_buf_t* crash_notes;
801  @@ -924,6 +927,10 @@ asmlinkage long sys_kexec_load(unsigned  @@ -924,6 +925,8 @@ asmlinkage long sys_kexec_load(unsigned
802          /* We only trust the superuser with rebooting the system. */          /* We only trust the superuser with rebooting the system. */
803          if (!capable(CAP_SYS_BOOT))          if (!capable(CAP_SYS_BOOT))
804                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
805  +       if (!ccs_capable(CCS_SYS_KEXEC_LOAD))  +       if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
806  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
807    
808          /*          /*
809           * 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 813  Source code for this patch is http://www
813          /* We can run anywhere, unlike our parent keventd(). */          /* We can run anywhere, unlike our parent keventd(). */
814          set_cpus_allowed(current, CPU_MASK_ALL);          set_cpus_allowed(current, CPU_MASK_ALL);
815    
816  +       /***** TOMOYO Linux start. *****/  +#ifdef CONFIG_CCSECURITY
817  +       current->ccs_domain_info = NULL;  +       current->ccs_domain_info = NULL;
818  +       current->ccs_flags = 0;  +       current->ccs_flags = 0;
819  +       /***** TOMOYO Linux end. *****/  +#endif
820  +  +
821          retval = -EPERM;          retval = -EPERM;
822          if (current->fs->root)          if (current->fs->root)
823                  retval = kernel_execve(sub_info->path,                  retval = kernel_execve(sub_info->path,
824  --- linux-2.6.21.7.orig/kernel/module.c  --- linux-2.6.21.7.orig/kernel/module.c
825  +++ linux-2.6.21.7/kernel/module.c  +++ linux-2.6.21.7/kernel/module.c
826  @@ -44,6 +44,9 @@  @@ -44,6 +44,7 @@
827   #include <asm/semaphore.h>   #include <asm/semaphore.h>
828   #include <asm/cacheflush.h>   #include <asm/cacheflush.h>
829   #include <linux/license.h>   #include <linux/license.h>
830  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
831    
832   #if 0   #if 0
833   #define DEBUGP printk   #define DEBUGP printk
834  @@ -662,6 +665,10 @@ sys_delete_module(const char __user *nam  @@ -662,6 +663,8 @@ sys_delete_module(const char __user *nam
835    
836          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
837                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
838  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
839  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
840    
841          if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)          if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
842                  return -EFAULT;                  return -EFAULT;
843  @@ -1983,6 +1990,10 @@ sys_init_module(void __user *umod,  @@ -1983,6 +1986,8 @@ sys_init_module(void __user *umod,
844          /* Must have permission */          /* Must have permission */
845          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
846                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
847  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
848  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
849    
850          /* Only one module load at a time, please */          /* Only one module load at a time, please */
851          if (mutex_lock_interruptible(&module_mutex) != 0)          if (mutex_lock_interruptible(&module_mutex) != 0)
852  --- linux-2.6.21.7.orig/kernel/ptrace.c  --- linux-2.6.21.7.orig/kernel/ptrace.c
853  +++ linux-2.6.21.7/kernel/ptrace.c  +++ linux-2.6.21.7/kernel/ptrace.c
854  @@ -21,6 +21,9 @@  @@ -21,6 +21,7 @@
855    
856   #include <asm/pgtable.h>   #include <asm/pgtable.h>
857   #include <asm/uaccess.h>   #include <asm/uaccess.h>
858  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
859    
860   /*   /*
861    * ptrace a task: make the debugger its new parent and    * ptrace a task: make the debugger its new parent and
862  @@ -456,6 +459,10 @@ asmlinkage long sys_ptrace(long request,  @@ -456,6 +457,8 @@ asmlinkage long sys_ptrace(long request,
863          /*          /*
864           * This lock_kernel fixes a subtle race with suid exec           * This lock_kernel fixes a subtle race with suid exec
865           */           */
 +       /***** TOMOYO Linux start. *****/  
866  +       if (!ccs_capable(CCS_SYS_PTRACE))  +       if (!ccs_capable(CCS_SYS_PTRACE))
867  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
868          lock_kernel();          lock_kernel();
869          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
870                  ret = ptrace_traceme();                  ret = ptrace_traceme();
871  --- linux-2.6.21.7.orig/kernel/sched.c  --- linux-2.6.21.7.orig/kernel/sched.c
872  +++ linux-2.6.21.7/kernel/sched.c  +++ linux-2.6.21.7/kernel/sched.c
873  @@ -55,6 +55,9 @@  @@ -55,6 +55,7 @@
874   #include <asm/tlb.h>   #include <asm/tlb.h>
875    
876   #include <asm/unistd.h>   #include <asm/unistd.h>
877  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
878    
879   /*   /*
880    * Scheduler clock - returns current time in nanosec units.    * Scheduler clock - returns current time in nanosec units.
881  @@ -3964,6 +3967,10 @@ int can_nice(const struct task_struct *p  @@ -3964,6 +3965,8 @@ int can_nice(const struct task_struct *p
882   asmlinkage long sys_nice(int increment)   asmlinkage long sys_nice(int increment)
883   {   {
884          long nice, retval;          long nice, retval;
 +       /***** TOMOYO Linux start. *****/  
885  +       if (!ccs_capable(CCS_SYS_NICE))  +       if (!ccs_capable(CCS_SYS_NICE))
886  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
887    
888          /*          /*
889           * Setpriority might change our priority at the same moment.           * Setpriority might change our priority at the same moment.
890  --- linux-2.6.21.7.orig/kernel/signal.c  --- linux-2.6.21.7.orig/kernel/signal.c
891  +++ linux-2.6.21.7/kernel/signal.c  +++ linux-2.6.21.7/kernel/signal.c
892  @@ -32,6 +32,9 @@  @@ -32,6 +32,7 @@
893   #include <asm/unistd.h>   #include <asm/unistd.h>
894   #include <asm/siginfo.h>   #include <asm/siginfo.h>
895   #include "audit.h"     /* audit_signal_info() */   #include "audit.h"     /* audit_signal_info() */
896  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
897    
898   /*   /*
899    * SLAB caches for signal bits.    * SLAB caches for signal bits.
900  @@ -2235,6 +2238,12 @@ asmlinkage long  @@ -2235,6 +2236,8 @@ asmlinkage long
901   sys_kill(int pid, int sig)   sys_kill(int pid, int sig)
902   {   {
903          struct siginfo info;          struct siginfo info;
904  +       /***** 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))  
905  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
906    
907          info.si_signo = sig;          info.si_signo = sig;
908          info.si_errno = 0;          info.si_errno = 0;
909  @@ -2293,6 +2302,12 @@ asmlinkage long sys_tgkill(int tgid, int  @@ -2293,6 +2296,8 @@ asmlinkage long sys_tgkill(int tgid, int
910          /* This is only valid for single tasks */          /* This is only valid for single tasks */
911          if (pid <= 0 || tgid <= 0)          if (pid <= 0 || tgid <= 0)
912                  return -EINVAL;                  return -EINVAL;
913  +       /***** TOMOYO Linux start. *****/  +       if (ccs_tgkill_permission(tgid, pid, sig))
 +       if (sig && !ccs_capable(CCS_SYS_KILL))  
914  +               return -EPERM;  +               return -EPERM;
 +       if (sig && ccs_check_signal_acl(sig, pid))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
915    
916          return do_tkill(tgid, pid, sig);          return do_tkill(tgid, pid, sig);
917   }   }
918  @@ -2306,6 +2321,12 @@ sys_tkill(int pid, int sig)  @@ -2306,6 +2311,8 @@ sys_tkill(int pid, int sig)
919          /* This is only valid for single tasks */          /* This is only valid for single tasks */
920          if (pid <= 0)          if (pid <= 0)
921                  return -EINVAL;                  return -EINVAL;
922  +       /***** 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))  
923  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
924    
925          return do_tkill(0, pid, sig);          return do_tkill(0, pid, sig);
926   }   }
927    @@ -2323,6 +2330,8 @@ sys_rt_sigqueueinfo(int pid, int sig, si
928            if (info.si_code >= 0)
929                    return -EPERM;
930            info.si_signo = sig;
931    +       if (ccs_sigqueue_permission(pid, sig))
932    +               return -EPERM;
933    
934            /* POSIX.1b doesn't mention process groups.  */
935            return kill_proc_info(sig, &info, pid);
936  --- linux-2.6.21.7.orig/kernel/sys.c  --- linux-2.6.21.7.orig/kernel/sys.c
937  +++ linux-2.6.21.7/kernel/sys.c  +++ linux-2.6.21.7/kernel/sys.c
938  @@ -37,6 +37,9 @@  @@ -37,6 +37,7 @@
939   #include <asm/uaccess.h>   #include <asm/uaccess.h>
940   #include <asm/io.h>   #include <asm/io.h>
941   #include <asm/unistd.h>   #include <asm/unistd.h>
942  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
943    
944   #ifndef SET_UNALIGN_CTL   #ifndef SET_UNALIGN_CTL
945   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)
946  @@ -600,6 +603,12 @@ asmlinkage long sys_setpriority(int whic  @@ -600,6 +601,10 @@ asmlinkage long sys_setpriority(int whic
947    
948          if (which > 2 || which < 0)          if (which > 2 || which < 0)
949                  goto out;                  goto out;
 +       /***** TOMOYO Linux start. *****/  
950  +       if (!ccs_capable(CCS_SYS_NICE)) {  +       if (!ccs_capable(CCS_SYS_NICE)) {
951  +               error = -EPERM;  +               error = -EPERM;
952  +               goto out;  +               goto out;
953  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
954    
955          /* normalize: avoid signed division (rounding problems) */          /* normalize: avoid signed division (rounding problems) */
956          error = -ESRCH;          error = -ESRCH;
957  @@ -830,6 +839,10 @@ asmlinkage long sys_reboot(int magic1, i  @@ -830,6 +835,8 @@ asmlinkage long sys_reboot(int magic1, i
958                          magic2 != LINUX_REBOOT_MAGIC2B &&                          magic2 != LINUX_REBOOT_MAGIC2B &&
959                          magic2 != LINUX_REBOOT_MAGIC2C))                          magic2 != LINUX_REBOOT_MAGIC2C))
960                  return -EINVAL;                  return -EINVAL;
 +       /***** TOMOYO Linux start. *****/  
961  +       if (!ccs_capable(CCS_SYS_REBOOT))  +       if (!ccs_capable(CCS_SYS_REBOOT))
962  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
963    
964          /* Instead of trying to make the power_off code look like          /* Instead of trying to make the power_off code look like
965           * 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.
966  @@ -1806,6 +1819,10 @@ asmlinkage long sys_sethostname(char __u  @@ -1806,6 +1813,8 @@ asmlinkage long sys_sethostname(char __u
967                  return -EPERM;                  return -EPERM;
968          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
969                  return -EINVAL;                  return -EINVAL;
 +       /***** TOMOYO Linux start. *****/  
970  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
971  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
972          down_write(&uts_sem);          down_write(&uts_sem);
973          errno = -EFAULT;          errno = -EFAULT;
974          if (!copy_from_user(tmp, name, len)) {          if (!copy_from_user(tmp, name, len)) {
975  @@ -1851,6 +1868,10 @@ asmlinkage long sys_setdomainname(char _  @@ -1851,6 +1860,8 @@ asmlinkage long sys_setdomainname(char _
976                  return -EPERM;                  return -EPERM;
977          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
978                  return -EINVAL;                  return -EINVAL;
 +       /***** TOMOYO Linux start. *****/  
979  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
980  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
981    
982          down_write(&uts_sem);          down_write(&uts_sem);
983          errno = -EFAULT;          errno = -EFAULT;
984  --- linux-2.6.21.7.orig/kernel/sysctl.c  --- linux-2.6.21.7.orig/kernel/sysctl.c
985  +++ linux-2.6.21.7/kernel/sysctl.c  +++ linux-2.6.21.7/kernel/sysctl.c
986  @@ -48,6 +48,9 @@  @@ -48,6 +48,7 @@
987    
988   #include <asm/uaccess.h>   #include <asm/uaccess.h>
989   #include <asm/processor.h>   #include <asm/processor.h>
990  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
991    
992   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,
993                        void __user *buffer, size_t *lenp, loff_t *ppos);                        void __user *buffer, size_t *lenp, loff_t *ppos);
994  @@ -1088,6 +1091,7 @@ struct ctl_table_header *sysctl_head_nex  @@ -1088,6 +1089,7 @@ struct ctl_table_header *sysctl_head_nex
995   }   }
996    
997   #ifdef CONFIG_SYSCTL_SYSCALL   #ifdef CONFIG_SYSCTL_SYSCALL
# Line 1133  Source code for this patch is http://www Line 999  Source code for this patch is http://www
999   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,
1000                 void __user *newval, size_t newlen)                 void __user *newval, size_t newlen)
1001   {   {
1002  @@ -1104,6 +1108,11 @@ int do_sysctl(int __user *name, int nlen  @@ -1104,6 +1106,9 @@ int do_sysctl(int __user *name, int nlen
1003    
1004          for (head = sysctl_head_next(NULL); head;          for (head = sysctl_head_next(NULL); head;
1005                          head = sysctl_head_next(head)) {                          head = sysctl_head_next(head)) {
 +               /***** TOMOYO Linux start. *****/  
1006  +               error = ccs_parse_table(name, nlen, oldval, newval,  +               error = ccs_parse_table(name, nlen, oldval, newval,
1007  +                                       head->ctl_table);  +                                       head->ctl_table);
1008  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
1009                  error = parse_table(name, nlen, oldval, oldlenp,                  error = parse_table(name, nlen, oldval, oldlenp,
1010                                          newval, newlen, head->ctl_table);                                          newval, newlen, head->ctl_table);
1011                  if (error != -ENOTDIR) {                  if (error != -ENOTDIR) {
1012  --- linux-2.6.21.7.orig/kernel/time.c  --- linux-2.6.21.7.orig/kernel/time.c
1013  +++ linux-2.6.21.7/kernel/time.c  +++ linux-2.6.21.7/kernel/time.c
1014  @@ -39,6 +39,9 @@  @@ -39,6 +39,7 @@
1015    
1016   #include <asm/uaccess.h>   #include <asm/uaccess.h>
1017   #include <asm/unistd.h>   #include <asm/unistd.h>
1018  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
1019    
1020   /*   /*
1021    * 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
1022  @@ -91,6 +94,10 @@ asmlinkage long sys_stime(time_t __user  @@ -91,6 +92,8 @@ asmlinkage long sys_stime(time_t __user
1023          err = security_settime(&tv, NULL);          err = security_settime(&tv, NULL);
1024          if (err)          if (err)
1025                  return err;                  return err;
 +       /***** TOMOYO Linux start. *****/  
1026  +       if (!ccs_capable(CCS_SYS_SETTIME))  +       if (!ccs_capable(CCS_SYS_SETTIME))
1027  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1028    
1029          do_settimeofday(&tv);          do_settimeofday(&tv);
1030          return 0;          return 0;
1031  @@ -161,6 +168,10 @@ int do_sys_settimeofday(struct timespec  @@ -161,6 +164,8 @@ int do_sys_settimeofday(struct timespec
1032          error = security_settime(tv, tz);          error = security_settime(tv, tz);
1033          if (error)          if (error)
1034                  return error;                  return error;
 +       /***** TOMOYO Linux start. *****/  
1035  +       if (!ccs_capable(CCS_SYS_SETTIME))  +       if (!ccs_capable(CCS_SYS_SETTIME))
1036  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1037    
1038          if (tz) {          if (tz) {
1039                  /* SMP safe, global irq locking makes it work. */                  /* SMP safe, global irq locking makes it work. */
1040  --- linux-2.6.21.7.orig/kernel/time/ntp.c  --- linux-2.6.21.7.orig/kernel/time/ntp.c
1041  +++ linux-2.6.21.7/kernel/time/ntp.c  +++ linux-2.6.21.7/kernel/time/ntp.c
1042  @@ -14,6 +14,9 @@  @@ -14,6 +14,7 @@
1043    
1044   #include <asm/div64.h>   #include <asm/div64.h>
1045   #include <asm/timex.h>   #include <asm/timex.h>
1046  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
1047    
1048   /*   /*
1049    * Timekeeping variables    * Timekeeping variables
1050  @@ -201,6 +204,10 @@ int do_adjtimex(struct timex *txc)  @@ -201,6 +202,8 @@ int do_adjtimex(struct timex *txc)
1051          /* In order to modify anything, you gotta be super-user! */          /* In order to modify anything, you gotta be super-user! */
1052          if (txc->modes && !capable(CAP_SYS_TIME))          if (txc->modes && !capable(CAP_SYS_TIME))
1053                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
1054  +       if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))  +       if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
1055  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1056    
1057          /* Now we validate the data before disabling interrupts */          /* Now we validate the data before disabling interrupts */
1058    
 --- 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;  
   
1059  --- linux-2.6.21.7.orig/net/ipv4/inet_connection_sock.c  --- linux-2.6.21.7.orig/net/ipv4/inet_connection_sock.c
1060  +++ linux-2.6.21.7/net/ipv4/inet_connection_sock.c  +++ linux-2.6.21.7/net/ipv4/inet_connection_sock.c
1061  @@ -23,6 +23,9 @@  @@ -23,6 +23,7 @@
1062   #include <net/route.h>   #include <net/route.h>
1063   #include <net/tcp_states.h>   #include <net/tcp_states.h>
1064   #include <net/xfrm.h>   #include <net/xfrm.h>
1065  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1066    
1067   #ifdef INET_CSK_DEBUG   #ifdef INET_CSK_DEBUG
1068   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";
1069  @@ -85,6 +88,10 @@ int inet_csk_get_port(struct inet_hashin  @@ -85,6 +86,8 @@ int inet_csk_get_port(struct inet_hashin
1070                  do {                  do {
1071                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
1072                          spin_lock(&head->lock);                          spin_lock(&head->lock);
 +                       /***** SAKURA Linux start. *****/  
1073  +                       if (ccs_lport_reserved(rover))  +                       if (ccs_lport_reserved(rover))
1074  +                               goto next;  +                               goto next;
 +                       /***** SAKURA Linux end. *****/  
1075                          inet_bind_bucket_for_each(tb, node, &head->chain)                          inet_bind_bucket_for_each(tb, node, &head->chain)
1076                                  if (tb->port == rover)                                  if (tb->port == rover)
1077                                          goto next;                                          goto next;
1078  --- linux-2.6.21.7.orig/net/ipv4/inet_hashtables.c  --- linux-2.6.21.7.orig/net/ipv4/inet_hashtables.c
1079  +++ linux-2.6.21.7/net/ipv4/inet_hashtables.c  +++ linux-2.6.21.7/net/ipv4/inet_hashtables.c
1080  @@ -22,6 +22,9 @@  @@ -22,6 +22,7 @@
1081   #include <net/inet_connection_sock.h>   #include <net/inet_connection_sock.h>
1082   #include <net/inet_hashtables.h>   #include <net/inet_hashtables.h>
1083   #include <net/ip.h>   #include <net/ip.h>
1084  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1085    
1086   /*   /*
1087    * Allocate and initialize a new local port bind bucket.    * Allocate and initialize a new local port bind bucket.
1088  @@ -292,6 +295,10 @@ int inet_hash_connect(struct inet_timewa  @@ -292,6 +293,8 @@ int inet_hash_connect(struct inet_timewa
1089                  local_bh_disable();                  local_bh_disable();
1090                  for (i = 1; i <= range; i++) {                  for (i = 1; i <= range; i++) {
1091                          port = low + (i + offset) % range;                          port = low + (i + offset) % range;
 +                       /***** SAKURA Linux start. *****/  
1092  +                       if (ccs_lport_reserved(port))  +                       if (ccs_lport_reserved(port))
1093  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1094                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
1095                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1096    
1097    --- linux-2.6.21.7.orig/net/ipv4/raw.c
1098    +++ linux-2.6.21.7/net/ipv4/raw.c
1099    @@ -78,6 +78,7 @@
1100     #include <linux/seq_file.h>
1101     #include <linux/netfilter.h>
1102     #include <linux/netfilter_ipv4.h>
1103    +#include <linux/ccsecurity.h>
1104    
1105     struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE];
1106     DEFINE_RWLOCK(raw_v4_lock);
1107    @@ -597,6 +598,9 @@ static int raw_recvmsg(struct kiocb *ioc
1108            skb = skb_recv_datagram(sk, flags, noblock, &err);
1109            if (!skb)
1110                    goto out;
1111    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1112    +       if (err)
1113    +               goto out;
1114    
1115            copied = skb->len;
1116            if (len < copied) {
1117  --- linux-2.6.21.7.orig/net/ipv4/udp.c  --- linux-2.6.21.7.orig/net/ipv4/udp.c
1118  +++ linux-2.6.21.7/net/ipv4/udp.c  +++ linux-2.6.21.7/net/ipv4/udp.c
1119  @@ -102,6 +102,9 @@  @@ -102,6 +102,7 @@
1120   #include <net/checksum.h>   #include <net/checksum.h>
1121   #include <net/xfrm.h>   #include <net/xfrm.h>
1122   #include "udp_impl.h"   #include "udp_impl.h"
1123  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1124    
1125   /*   /*
1126    *     Snmp MIB for the UDP layer    *     Snmp MIB for the UDP layer
1127  @@ -162,6 +165,10 @@ int __udp_lib_get_port(struct sock *sk,  @@ -162,6 +163,8 @@ int __udp_lib_get_port(struct sock *sk,
1128                                          result = sysctl_local_port_range[0] +                                          result = sysctl_local_port_range[0] +
1129                                                  ((result - sysctl_local_port_range[0]) &                                                  ((result - sysctl_local_port_range[0]) &
1130                                                   (UDP_HTABLE_SIZE - 1));                                                   (UDP_HTABLE_SIZE - 1));
 +                               /***** SAKURA Linux start. *****/  
1131  +                               if (ccs_lport_reserved(result))  +                               if (ccs_lport_reserved(result))
1132  +                                       continue;  +                                       continue;
 +                               /***** SAKURA Linux end. *****/  
1133                                  goto gotit;                                  goto gotit;
1134                          }                          }
1135                          size = 0;                          size = 0;
1136  @@ -180,6 +187,10 @@ int __udp_lib_get_port(struct sock *sk,  @@ -180,6 +183,8 @@ int __udp_lib_get_port(struct sock *sk,
1137                                  result = sysctl_local_port_range[0]                                  result = sysctl_local_port_range[0]
1138                                          + ((result - sysctl_local_port_range[0]) &                                          + ((result - sysctl_local_port_range[0]) &
1139                                             (UDP_HTABLE_SIZE - 1));                                             (UDP_HTABLE_SIZE - 1));
 +                       /***** SAKURA Linux start. *****/  
1140  +                       if (ccs_lport_reserved(result))  +                       if (ccs_lport_reserved(result))
1141  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1142                          if (! __udp_lib_lport_inuse(result, udptable))                          if (! __udp_lib_lport_inuse(result, udptable))
1143                                  break;                                  break;
1144                  }                  }
1145    @@ -825,6 +830,9 @@ try_again:
1146            skb = skb_recv_datagram(sk, flags, noblock, &err);
1147            if (!skb)
1148                    goto out;
1149    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1150    +       if (err)
1151    +               goto out;
1152    
1153            copied = skb->len - sizeof(struct udphdr);
1154            if (copied > len) {
1155  --- linux-2.6.21.7.orig/net/ipv6/inet6_hashtables.c  --- linux-2.6.21.7.orig/net/ipv6/inet6_hashtables.c
1156  +++ linux-2.6.21.7/net/ipv6/inet6_hashtables.c  +++ linux-2.6.21.7/net/ipv6/inet6_hashtables.c
1157  @@ -21,6 +21,9 @@  @@ -21,6 +21,7 @@
1158   #include <net/inet_hashtables.h>   #include <net/inet_hashtables.h>
1159   #include <net/inet6_hashtables.h>   #include <net/inet6_hashtables.h>
1160   #include <net/ip.h>   #include <net/ip.h>
1161  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1162    
1163   void __inet6_hash(struct inet_hashinfo *hashinfo,   void __inet6_hash(struct inet_hashinfo *hashinfo,
1164                                  struct sock *sk)                                  struct sock *sk)
1165  @@ -266,6 +269,10 @@ int inet6_hash_connect(struct inet_timew  @@ -266,6 +267,8 @@ int inet6_hash_connect(struct inet_timew
1166                  local_bh_disable();                  local_bh_disable();
1167                  for (i = 1; i <= range; i++) {                  for (i = 1; i <= range; i++) {
1168                          port = low + (i + offset) % range;                          port = low + (i + offset) % range;
 +                       /***** SAKURA Linux start. *****/  
1169  +                       if (ccs_lport_reserved(port))  +                       if (ccs_lport_reserved(port))
1170  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1171                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];                          head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
1172                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1173    
1174    --- linux-2.6.21.7.orig/net/ipv6/raw.c
1175    +++ linux-2.6.21.7/net/ipv6/raw.c
1176    @@ -58,6 +58,7 @@
1177    
1178     #include <linux/proc_fs.h>
1179     #include <linux/seq_file.h>
1180    +#include <linux/ccsecurity.h>
1181    
1182     struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE];
1183     DEFINE_RWLOCK(raw_v6_lock);
1184    @@ -413,6 +414,9 @@ static int rawv6_recvmsg(struct kiocb *i
1185            skb = skb_recv_datagram(sk, flags, noblock, &err);
1186            if (!skb)
1187                    goto out;
1188    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1189    +       if (err)
1190    +               goto out;
1191    
1192            copied = skb->len;
1193            if (copied > len) {
1194    --- linux-2.6.21.7.orig/net/ipv6/udp.c
1195    +++ linux-2.6.21.7/net/ipv6/udp.c
1196    @@ -49,6 +49,7 @@
1197     #include <linux/proc_fs.h>
1198     #include <linux/seq_file.h>
1199     #include "udp_impl.h"
1200    +#include <linux/ccsecurity.h>
1201    
1202     DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
1203    
1204    @@ -133,6 +134,9 @@ try_again:
1205            skb = skb_recv_datagram(sk, flags, noblock, &err);
1206            if (!skb)
1207                    goto out;
1208    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1209    +       if (err)
1210    +               goto out;
1211    
1212            copied = skb->len - sizeof(struct udphdr);
1213            if (copied > len) {
1214  --- linux-2.6.21.7.orig/net/socket.c  --- linux-2.6.21.7.orig/net/socket.c
1215  +++ linux-2.6.21.7/net/socket.c  +++ linux-2.6.21.7/net/socket.c
1216  @@ -93,6 +93,11 @@  @@ -93,6 +93,8 @@
1217   #include <net/sock.h>   #include <net/sock.h>
1218   #include <linux/netfilter.h>   #include <linux/netfilter.h>
1219    
1220  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +#include <linux/tomoyo_socket.h>  
 +/***** TOMOYO Linux end. *****/  
1221  +  +
1222   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
1223   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,
1224                           unsigned long nr_segs, loff_t pos);                           unsigned long nr_segs, loff_t pos);
1225  @@ -549,6 +554,12 @@ static inline int __sock_sendmsg(struct  @@ -547,6 +549,10 @@ static inline int __sock_sendmsg(struct
1226            si->size = size;
1227    
1228          err = security_socket_sendmsg(sock, msg, size);          err = security_socket_sendmsg(sock, msg, size);
1229    +       if (!err)
1230    +               err = ccs_socket_sendmsg_permission(sock, (struct sockaddr *)
1231    +                                                   msg->msg_name,
1232    +                                                   msg->msg_namelen);
1233          if (err)          if (err)
1234                  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. *****/  
1235    
1236          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;  
1237          }          }
1238    
 +       /***** TOMOYO Linux start. *****/  
 +       err = ccs_socket_create_permission(family, type, protocol);  
 +       if (err)  
 +               return err;  
 +       /***** TOMOYO Linux end. *****/  
 +  
1239          err = security_socket_create(family, type, protocol, kern);          err = security_socket_create(family, type, protocol, kern);
1240    +       if (!err)
1241    +               err = ccs_socket_create_permission(family, type, protocol);
1242          if (err)          if (err)
1243                  return err;                  return err;
1244  @@ -1298,6 +1315,13 @@ asmlinkage long sys_bind(int fd, struct  
1245                          err = security_socket_bind(sock,  @@ -1299,6 +1307,11 @@ asmlinkage long sys_bind(int fd, struct
1246                                                     (struct sockaddr *)address,                                                     (struct sockaddr *)address,
1247                                                     addrlen);                                                     addrlen);
1248  +                       /***** TOMOYO Linux start. *****/                          if (!err)
 +                       if (!err)  
1249  +                               err = ccs_socket_bind_permission(sock,  +                               err = ccs_socket_bind_permission(sock,
1250  +                                                        (struct sockaddr *)  +                                                        (struct sockaddr *)
1251  +                                                                address,  +                                                                address,
1252  +                                                                addrlen);  +                                                                addrlen);
1253  +                       /***** TOMOYO Linux end. *****/  +                       if (!err)
                         if (!err)  
1254                                  err = sock->ops->bind(sock,                                  err = sock->ops->bind(sock,
1255                                                        (struct sockaddr *)                                                        (struct sockaddr *)
1256  @@ -1327,6 +1351,10 @@ asmlinkage long sys_listen(int fd, int b                                                        address, addrlen);
1257                          backlog = sysctl_somaxconn;  @@ -1328,6 +1341,8 @@ asmlinkage long sys_listen(int fd, int b
1258    
1259                  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. *****/  
1260                  if (!err)                  if (!err)
1261    +                       err = ccs_socket_listen_permission(sock);
1262    +               if (!err)
1263                          err = sock->ops->listen(sock, backlog);                          err = sock->ops->listen(sock, backlog);
1264    
1265  @@ -1391,6 +1419,13 @@ asmlinkage long sys_accept(int fd, struc                  fput_light(sock->file, fput_needed);
1266    @@ -1391,6 +1406,11 @@ asmlinkage long sys_accept(int fd, struc
1267          if (err < 0)          if (err < 0)
1268                  goto out_fd;                  goto out_fd;
1269    
 +       /***** TOMOYO Linux start. *****/  
1270  +       if (ccs_socket_accept_permission(newsock,  +       if (ccs_socket_accept_permission(newsock,
1271  +                                        (struct sockaddr *) address)) {  +                                        (struct sockaddr *) address)) {
1272  +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */  +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */
1273  +               goto out_fd;  +               goto out_fd;
1274  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
1275          if (upeer_sockaddr) {          if (upeer_sockaddr) {
1276                  if (newsock->ops->getname(newsock, (struct sockaddr *)address,                  if (newsock->ops->getname(newsock, (struct sockaddr *)address,
1277                                            &len, 2) < 0) {                                            &len, 2) < 0) {
1278  @@ -1455,6 +1490,12 @@ asmlinkage long sys_connect(int fd, stru  @@ -1453,6 +1473,9 @@ asmlinkage long sys_connect(int fd, stru
1279    
1280            err =
1281              security_socket_connect(sock, (struct sockaddr *)address, addrlen);              security_socket_connect(sock, (struct sockaddr *)address, addrlen);
1282    +       if (!err)
1283    +               err = ccs_socket_connect_permission(sock, (struct sockaddr *)
1284    +                                                   address, addrlen);
1285          if (err)          if (err)
1286                  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. *****/  
1287    
         err = sock->ops->connect(sock, (struct sockaddr *)address, addrlen,  
                                  sock->file->f_flags);  
1288  --- linux-2.6.21.7.orig/net/unix/af_unix.c  --- linux-2.6.21.7.orig/net/unix/af_unix.c
1289  +++ linux-2.6.21.7/net/unix/af_unix.c  +++ linux-2.6.21.7/net/unix/af_unix.c
1290  @@ -116,6 +116,9 @@  @@ -116,6 +116,7 @@
1291   #include <linux/mount.h>   #include <linux/mount.h>
1292   #include <net/checksum.h>   #include <net/checksum.h>
1293   #include <linux/security.h>   #include <linux/security.h>
1294  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
1295    
1296   int sysctl_unix_max_dgram_qlen __read_mostly = 10;   int sysctl_unix_max_dgram_qlen __read_mostly = 10;
1297    
1298  @@ -808,6 +811,11 @@ static int unix_bind(struct socket *sock  @@ -808,6 +809,9 @@ static int unix_bind(struct socket *sock
1299                   */                   */
1300                  mode = S_IFSOCK |                  mode = S_IFSOCK |
1301                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
1302  +               /***** TOMOYO Linux start. *****/  +               err = ccs_mknod_permission(nd.dentry->d_inode, dentry, nd.mnt,
1303  +               err = ccs_check_mknod_permission(nd.dentry->d_inode, dentry,  +                                          mode, 0);
 +                                                nd.mnt, mode, 0);  
1304  +               if (!err)  +               if (!err)
 +               /***** TOMOYO Linux end. *****/  
1305                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
1306                  if (err)                  if (err)
1307                          goto out_mknod_dput;                          goto out_mknod_dput;
1308    --- linux-2.6.21.7.orig/security/Kconfig
1309    +++ linux-2.6.21.7/security/Kconfig
1310    @@ -95,5 +95,7 @@ config SECURITY_ROOTPLUG
1311    
1312     source security/selinux/Kconfig
1313    
1314    +source security/ccsecurity/Kconfig
1315    +
1316     endmenu
1317    
1318    --- linux-2.6.21.7.orig/security/Makefile
1319    +++ linux-2.6.21.7/security/Makefile
1320    @@ -16,3 +16,6 @@ obj-$(CONFIG_SECURITY)                        += security.o d
1321     obj-$(CONFIG_SECURITY_SELINUX)         += selinux/built-in.o
1322     obj-$(CONFIG_SECURITY_CAPABILITIES)    += commoncap.o capability.o
1323     obj-$(CONFIG_SECURITY_ROOTPLUG)                += commoncap.o root_plug.o
1324    +
1325    +subdir-$(CONFIG_CCSECURITY)+= ccsecurity
1326    +obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o

Legend:
Removed from v.2299  
changed lines
  Added in v.3053

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