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

Subversion リポジトリの参照

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

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

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

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

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