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

Subversion リポジトリの参照

Diff of /trunk/1.8.x/ccs-patch/patches/ccs-patch-2.6.15-ubuntu-6.06.diff

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

trunk/1.6.x/ccs-patch/patches/ccs-patch-2.6.15-ubuntu-6.06.diff revision 2297 by kumaneko, Mon Mar 23 00:46:34 2009 UTC branches/ccs-patch/patches/ccs-patch-2.6.15-ubuntu-6.06.diff revision 2859 by kumaneko, Thu Aug 6 07:51:05 2009 UTC
# Line 2  This is TOMOYO Linux patch for Ubuntu 6. Line 2  This is TOMOYO Linux patch for Ubuntu 6.
2    
3  Source code for this patch is "apt-get install linux-source-2.6.15"  Source code for this patch is "apt-get install linux-source-2.6.15"
4  ---  ---
5   arch/alpha/kernel/ptrace.c      |    7 ++   arch/alpha/kernel/ptrace.c      |    3 +++
6   arch/ia64/ia32/sys_ia32.c       |    7 ++   arch/ia64/ia32/sys_ia32.c       |    3 +++
7   arch/ia64/kernel/ptrace.c       |    7 ++   arch/ia64/kernel/ptrace.c       |    3 +++
8   arch/m32r/kernel/ptrace.c       |    7 ++   arch/m32r/kernel/ptrace.c       |    3 +++
9   arch/mips/kernel/ptrace32.c     |    7 ++   arch/mips/kernel/ptrace32.c     |    3 +++
10   arch/powerpc/kernel/ptrace32.c  |    7 ++   arch/powerpc/kernel/ptrace32.c  |    3 +++
11   arch/s390/kernel/ptrace.c       |    7 ++   arch/s390/kernel/ptrace.c       |    3 +++
12   arch/sparc/kernel/ptrace.c      |    9 +++   arch/sparc/kernel/ptrace.c      |    5 +++++
13   arch/sparc64/kernel/ptrace.c    |    9 +++   arch/sparc64/kernel/ptrace.c    |    5 +++++
14   arch/x86_64/ia32/ptrace32.c     |    7 ++   arch/x86_64/ia32/ptrace32.c     |    3 +++
15   fs/Kconfig                      |    2   fs/attr.c                       |    5 +++++
16   fs/Makefile                     |    2   fs/compat.c                     |    9 ++++++++-
17   fs/attr.c                       |   19 ++++++   fs/exec.c                       |   12 +++++++++++-
18   fs/compat.c                     |   15 +++++   fs/fcntl.c                      |    4 ++++
19   fs/exec.c                       |   21 +++++++   fs/ioctl.c                      |    5 +++++
20   fs/fcntl.c                      |    8 ++   fs/namei.c                      |   38 ++++++++++++++++++++++++++++++++++++++
21   fs/ioctl.c                      |   11 +++   fs/namespace.c                  |   27 ++++++++++++++++++++++++++-
22   fs/namei.c                      |   60 +++++++++++++++++++++   fs/open.c                       |   15 ++++++++++++++-
23   fs/namespace.c                  |   50 +++++++++++++++++-   fs/proc/proc_misc.c             |    1 +
24   fs/open.c                       |   30 ++++++++++   include/linux/init_task.h       |    2 ++
25   fs/proc/Makefile                |    3 +   include/linux/sched.h           |    4 ++++
26   fs/proc/proc_misc.c             |    5 +   kernel/compat.c                 |    3 +++
27   include/linux/init_task.h       |    4 +   kernel/kexec.c                  |    3 +++
28   include/linux/sched.h           |    8 ++   kernel/kmod.c                   |    3 +++
29   kernel/compat.c                 |    7 ++   kernel/module.c                 |    7 +++++--
30   kernel/kexec.c                  |    7 ++   kernel/ptrace.c                 |    3 +++
31   kernel/kmod.c                   |    5 +   kernel/sched.c                  |    3 +++
32   kernel/module.c                 |   13 +++-   kernel/signal.c                 |    7 +++++++
33   kernel/ptrace.c                 |    7 ++   kernel/sys.c                    |   11 +++++++++++
34   kernel/sched.c                  |    7 ++   kernel/sysctl.c                 |   11 +++++++++++
35   kernel/signal.c                 |   21 +++++++   kernel/time.c                   |    7 +++++++
36   kernel/sys.c                    |   21 +++++++   net/ipv4/inet_connection_sock.c |    3 +++
37   kernel/sysctl.c                 |  111 ++++++++++++++++++++++++++++++++++++++++   net/ipv4/raw.c                  |    4 ++++
38   kernel/time.c                   |   15 +++++   net/ipv4/tcp_ipv4.c             |    3 +++
39   net/core/datagram.c             |   11 +++   net/ipv4/udp.c                  |   10 +++++++++-
40   net/ipv4/inet_connection_sock.c |    7 ++   net/ipv6/raw.c                  |    4 ++++
41   net/ipv4/tcp_ipv4.c             |    7 ++   net/ipv6/tcp_ipv6.c             |    5 +++++
42   net/ipv4/udp.c                  |   11 +++   net/ipv6/udp.c                  |    8 ++++++++
43   net/ipv6/tcp_ipv6.c             |   11 +++   net/socket.c                    |   25 ++++++++++++++++++++++---
44   net/ipv6/udp.c                  |   11 +++   net/unix/af_unix.c              |    4 ++++
45   net/socket.c                    |   43 ++++++++++++++-   security/Kconfig                |    2 ++
46   net/unix/af_unix.c              |    8 ++   security/Makefile               |    3 +++
47   42 files changed, 626 insertions(+), 9 deletions(-)   42 files changed, 275 insertions(+), 10 deletions(-)
48    
49  --- linux-2.6.15-53.75.orig/arch/alpha/kernel/ptrace.c  --- linux-2.6.15-54.77.orig/arch/alpha/kernel/ptrace.c
50  +++ linux-2.6.15-53.75/arch/alpha/kernel/ptrace.c  +++ linux-2.6.15-54.77/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  @@ -261,6 +264,10 @@ do_sys_ptrace(long request, long pid, lo  @@ -261,6 +262,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;
 +       /***** TOMOYO Linux start. *****/  
63  +       if (!ccs_capable(CCS_SYS_PTRACE))  +       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.15-53.75.orig/arch/ia64/ia32/sys_ia32.c  --- linux-2.6.15-54.77.orig/arch/ia64/ia32/sys_ia32.c
69  +++ linux-2.6.15-53.75/arch/ia64/ia32/sys_ia32.c  +++ linux-2.6.15-54.77/arch/ia64/ia32/sys_ia32.c
70  @@ -57,6 +57,9 @@  @@ -57,6 +57,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;
 +       /***** TOMOYO Linux start. *****/  
82  +       if (!ccs_capable(CCS_SYS_PTRACE))  +       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.15-53.75.orig/arch/ia64/kernel/ptrace.c  --- linux-2.6.15-54.77.orig/arch/ia64/kernel/ptrace.c
88  +++ linux-2.6.15-53.75/arch/ia64/kernel/ptrace.c  +++ linux-2.6.15-54.77/arch/ia64/kernel/ptrace.c
89  @@ -29,6 +29,9 @@  @@ -29,6 +29,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;
 +       /***** TOMOYO Linux start. *****/  
101  +       if (!ccs_capable(CCS_SYS_PTRACE))  +       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.15-53.75.orig/arch/m32r/kernel/ptrace.c  --- linux-2.6.15-54.77.orig/arch/m32r/kernel/ptrace.c
107  +++ linux-2.6.15-53.75/arch/m32r/kernel/ptrace.c  +++ linux-2.6.15-54.77/arch/m32r/kernel/ptrace.c
108  @@ -33,6 +33,9 @@  @@ -33,6 +33,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    * Get the address of the live pt_regs for the specified task.    * Get the address of the live pt_regs for the specified task.
116  @@ -760,6 +763,10 @@ asmlinkage long sys_ptrace(long request,  @@ -760,6 +761,8 @@ asmlinkage long sys_ptrace(long request,
117   {   {
118          struct task_struct *child;          struct task_struct *child;
119          int ret;          int ret;
 +       /***** TOMOYO Linux start. *****/  
120  +       if (!ccs_capable(CCS_SYS_PTRACE))  +       if (!ccs_capable(CCS_SYS_PTRACE))
121  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
122    
123          lock_kernel();          lock_kernel();
124          ret = -EPERM;          ret = -EPERM;
125  --- linux-2.6.15-53.75.orig/arch/mips/kernel/ptrace32.c  --- linux-2.6.15-54.77.orig/arch/mips/kernel/ptrace32.c
126  +++ linux-2.6.15-53.75/arch/mips/kernel/ptrace32.c  +++ linux-2.6.15-54.77/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;
 +       /***** TOMOYO Linux start. *****/  
139  +       if (!ccs_capable(CCS_SYS_PTRACE))  +       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.15-53.75.orig/arch/powerpc/kernel/ptrace32.c  --- linux-2.6.15-54.77.orig/arch/powerpc/kernel/ptrace32.c
145  +++ linux-2.6.15-53.75/arch/powerpc/kernel/ptrace32.c  +++ linux-2.6.15-54.77/arch/powerpc/kernel/ptrace32.c
146  @@ -33,6 +33,9 @@  @@ -33,6 +33,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  @@ -46,6 +49,10 @@ long compat_sys_ptrace(int request, int  @@ -46,6 +47,8 @@ long compat_sys_ptrace(int request, int
155   {   {
156          struct task_struct *child;          struct task_struct *child;
157          int ret = -EPERM;          int ret = -EPERM;
 +       /***** TOMOYO Linux start. *****/  
158  +       if (!ccs_capable(CCS_SYS_PTRACE))  +       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.15-53.75.orig/arch/s390/kernel/ptrace.c  --- linux-2.6.15-54.77.orig/arch/s390/kernel/ptrace.c
164  +++ linux-2.6.15-53.75/arch/s390/kernel/ptrace.c  +++ linux-2.6.15-54.77/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_S390_SUPPORT   #ifdef CONFIG_S390_SUPPORT
172   #include "compat_ptrace.h"   #include "compat_ptrace.h"
173  @@ -711,6 +714,10 @@ sys_ptrace(long request, long pid, long  @@ -711,6 +712,8 @@ sys_ptrace(long request, long pid, long
174          struct task_struct *child;          struct task_struct *child;
175          int ret;          int ret;
176    
 +       /***** TOMOYO Linux start. *****/  
177  +       if (!ccs_capable(CCS_SYS_PTRACE))  +       if (!ccs_capable(CCS_SYS_PTRACE))
178  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
179          lock_kernel();          lock_kernel();
180    
181          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
182  --- linux-2.6.15-53.75.orig/arch/sparc/kernel/ptrace.c  --- linux-2.6.15-54.77.orig/arch/sparc/kernel/ptrace.c
183  +++ linux-2.6.15-53.75/arch/sparc/kernel/ptrace.c  +++ linux-2.6.15-54.77/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;
 +       /***** TOMOYO Linux start. *****/  
196  +       if (!ccs_capable(CCS_SYS_PTRACE)) {  +       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.15-53.75.orig/arch/sparc64/kernel/ptrace.c  --- linux-2.6.15-54.77.orig/arch/sparc64/kernel/ptrace.c
204  +++ linux-2.6.15-53.75/arch/sparc64/kernel/ptrace.c  +++ linux-2.6.15-54.77/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;
 +       /***** TOMOYO Linux start. *****/  
217  +       if (!ccs_capable(CCS_SYS_PTRACE)) {  +       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.15-53.75.orig/arch/x86_64/ia32/ptrace32.c  --- linux-2.6.15-54.77.orig/arch/x86_64/ia32/ptrace32.c
225  +++ linux-2.6.15-53.75/arch/x86_64/ia32/ptrace32.c  +++ linux-2.6.15-54.77/arch/x86_64/ia32/ptrace32.c
226  @@ -27,6 +27,9 @@  @@ -27,6 +27,7 @@
227   #include <asm/debugreg.h>   #include <asm/debugreg.h>
228   #include <asm/i387.h>   #include <asm/i387.h>
229   #include <asm/fpu32.h>   #include <asm/fpu32.h>
230  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
231    
232   /* determines which flags the user has access to. */   /* determines which flags the user has access to. */
233   /* 1 = access 0 = no access */   /* 1 = access 0 = no access */
234  @@ -233,6 +236,10 @@ asmlinkage long sys32_ptrace(long reques  @@ -233,6 +234,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;
 +       /***** TOMOYO Linux start. *****/  
238  +       if (!ccs_capable(CCS_SYS_PTRACE))  +       if (!ccs_capable(CCS_SYS_PTRACE))
239  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
240    
241          switch (request) {          switch (request) {
242          default:          default:
243  --- linux-2.6.15-53.75.orig/fs/Kconfig  --- linux-2.6.15-54.77.orig/fs/attr.c
244  +++ linux-2.6.15-53.75/fs/Kconfig  +++ linux-2.6.15-54.77/fs/attr.c
245  @@ -1910,5 +1910,7 @@ endmenu  @@ -15,6 +15,7 @@
   
  source "fs/nls/Kconfig"  
   
 +source "fs/Kconfig.ccs"  
 +  
  endmenu  
   
 --- linux-2.6.15-53.75.orig/fs/Makefile  
 +++ linux-2.6.15-53.75/fs/Makefile  
 @@ -108,3 +108,5 @@ obj-$(CONFIG_CONFIGFS_FS)   += configfs/  
  obj-$(CONFIG_OCFS2_FS)         += ocfs2/  
  obj-$(CONFIG_UNION_FS)          += unionfs/  
  obj-$(CONFIG_DAZUKO)           += dazuko/  
 +  
 +include $(srctree)/fs/Makefile-2.6.ccs  
 --- linux-2.6.15-53.75.orig/fs/attr.c  
 +++ linux-2.6.15-53.75/fs/attr.c  
 @@ -15,6 +15,9 @@  
246   #include <linux/quotaops.h>   #include <linux/quotaops.h>
247   #include <linux/security.h>   #include <linux/security.h>
248   #include <linux/time.h>   #include <linux/time.h>
249  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
250    
251   /* Taken over from the old code... */   /* Taken over from the old code... */
252    
253  @@ -153,12 +156,28 @@ int notify_change(struct dentry * dentry  @@ -154,11 +155,15 @@ int notify_change(struct dentry * dentry
   
254          if (inode->i_op && inode->i_op->setattr) {          if (inode->i_op && inode->i_op->setattr) {
255                  error = security_inode_setattr(dentry, attr);                  error = security_inode_setattr(dentry, attr);
 +               /***** TOMOYO Linux start. *****/  
 +               if (!error && (ia_valid & ATTR_MODE) &&  
 +                   !ccs_capable(CCS_SYS_CHMOD))  
 +                       error = -EPERM;  
 +               if (!error && (ia_valid & (ATTR_UID | ATTR_GID)) &&  
 +                   !ccs_capable(CCS_SYS_CHOWN))  
 +                       error = -EPERM;  
 +               /***** TOMOYO Linux end. *****/  
256                  if (!error)                  if (!error)
257    +                       error = ccs_check_setattr_permission(dentry, attr);
258    +               if (!error)
259                          error = inode->i_op->setattr(dentry, attr);                          error = inode->i_op->setattr(dentry, attr);
260          } else {          } else {
261                  error = inode_change_ok(inode, attr);                  error = inode_change_ok(inode, attr);
262                  if (!error)                  if (!error)
263                          error = security_inode_setattr(dentry, attr);                          error = security_inode_setattr(dentry, attr);
264  +               /***** TOMOYO Linux start. *****/  +               if (!error)
265  +               if (!error && (ia_valid & ATTR_MODE) &&  +                       error = ccs_check_setattr_permission(dentry, attr);
 +                   !ccs_capable(CCS_SYS_CHMOD))  
 +                       error = -EPERM;  
 +               if (!error && (ia_valid & (ATTR_UID | ATTR_GID)) &&  
 +                   !ccs_capable(CCS_SYS_CHOWN))  
 +                       error = -EPERM;  
 +               /***** TOMOYO Linux end. *****/  
266                  if (!error) {                  if (!error) {
267                          if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||                          if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
268                              (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))                              (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
269  --- linux-2.6.15-53.75.orig/fs/compat.c  --- linux-2.6.15-54.77.orig/fs/compat.c
270  +++ linux-2.6.15-53.75/fs/compat.c  +++ linux-2.6.15-54.77/fs/compat.c
271  @@ -52,6 +52,9 @@  @@ -52,6 +52,7 @@
272   #include <asm/uaccess.h>   #include <asm/uaccess.h>
273   #include <asm/mmu_context.h>   #include <asm/mmu_context.h>
274   #include <asm/ioctls.h>   #include <asm/ioctls.h>
275  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
276    
277   /*   /*
278    * Not all architectures have sys_utime, so implement this in terms    * Not all architectures have sys_utime, so implement this in terms
279  @@ -353,6 +356,10 @@ asmlinkage long compat_sys_ioctl(unsigne  @@ -353,6 +354,8 @@ asmlinkage long compat_sys_ioctl(unsigne
280    
281          /* RED-PEN how should LSM module know it's handling 32bit? */          /* RED-PEN how should LSM module know it's handling 32bit? */
282          error = security_file_ioctl(filp, cmd, arg);          error = security_file_ioctl(filp, cmd, arg);
 +       /***** TOMOYO Linux start. *****/  
283  +       if (!error)  +       if (!error)
284  +               error = ccs_check_ioctl_permission(filp, cmd, arg);  +               error = ccs_check_ioctl_permission(filp, cmd, arg);
 +       /***** TOMOYO Linux end. *****/  
285          if (error)          if (error)
286                  goto out_fput;                  goto out_fput;
287    
288  @@ -377,6 +384,12 @@ asmlinkage long compat_sys_ioctl(unsigne  @@ -377,6 +380,10 @@ asmlinkage long compat_sys_ioctl(unsigne
289                  /*FALL THROUGH*/                  /*FALL THROUGH*/
290    
291          default:          default:
 +               /***** TOMOYO Linux start. *****/  
292  +               if (!ccs_capable(CCS_SYS_IOCTL)) {  +               if (!ccs_capable(CCS_SYS_IOCTL)) {
293  +                       error = -EPERM;  +                       error = -EPERM;
294  +                       goto out_fput;  +                       goto out_fput;
295  +               }  +               }
 +               /***** TOMOYO Linux end. *****/  
296                  if (filp->f_op && filp->f_op->compat_ioctl) {                  if (filp->f_op && filp->f_op->compat_ioctl) {
297                          error = filp->f_op->compat_ioctl(filp, cmd, arg);                          error = filp->f_op->compat_ioctl(filp, cmd, arg);
298                          if (error != -ENOIOCTLCMD)                          if (error != -ENOIOCTLCMD)
299  @@ -1480,7 +1493,7 @@ int compat_do_execve(char * filename,  @@ -1480,7 +1487,7 @@ int compat_do_execve(char * filename,
300          if (retval < 0)          if (retval < 0)
301                  goto out;                  goto out;
302    
303  -       retval = search_binary_handler(bprm, regs);  -       retval = search_binary_handler(bprm, regs);
304  +       retval = search_binary_handler_with_transition(bprm, regs);  +       retval = ccs_search_binary_handler(bprm, regs);
305          if (retval >= 0) {          if (retval >= 0) {
306                  free_arg_pages(bprm);                  free_arg_pages(bprm);
307    
308  --- linux-2.6.15-53.75.orig/fs/exec.c  --- linux-2.6.15-54.77.orig/fs/exec.c
309  +++ linux-2.6.15-53.75/fs/exec.c  +++ linux-2.6.15-54.77/fs/exec.c
310  @@ -57,6 +57,10 @@  @@ -57,6 +57,8 @@
311   #include <linux/kmod.h>   #include <linux/kmod.h>
312   #endif   #endif
313    
314  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
315  +  +
316   int core_uses_pid;   int core_uses_pid;
317   char core_pattern[65] = "core";   char core_pattern[65] = "core";
318   int suid_dumpable = 0;   int suid_dumpable = 0;
319  @@ -139,6 +143,13 @@ asmlinkage long sys_uselib(const char __  @@ -139,6 +141,10 @@ SYSCALL_DEFINE1(uselib, const char __use
320          if (error)          if (error)
321                  goto exit;                  goto exit;
322    
323  +       /***** TOMOYO Linux start. *****/  +       error = ccs_check_uselib_permission(nd.dentry, nd.mnt);
 +       /* 01 means "read". */  
 +       error = ccs_check_open_permission(nd.dentry, nd.mnt, 01);  
324  +       if (error)  +       if (error)
325  +               goto exit;  +               goto exit;
 +       /***** TOMOYO Linux end. *****/  
326  +  +
327          file = nameidata_to_filp(&nd, O_RDONLY);          file = nameidata_to_filp(&nd, O_RDONLY);
328          error = PTR_ERR(file);          error = PTR_ERR(file);
329          if (IS_ERR(file))          if (IS_ERR(file))
330  @@ -488,6 +499,13 @@ struct file *open_exec(const char *name)  @@ -488,6 +494,9 @@ struct file *open_exec(const char *name)
331                          int err = vfs_permission(&nd, MAY_EXEC);                          int err = vfs_permission(&nd, MAY_EXEC);
332                          if (!err && !(inode->i_mode & 0111))                          if (!err && !(inode->i_mode & 0111))
333                                  err = -EACCES;                                  err = -EACCES;
334  +                       /***** TOMOYO Linux start. *****/  +                       if (!err)
335  +                       if (!err && (current->ccs_flags &  +                               err = ccs_check_open_exec_permission(nd.dentry,
336  +                                    CCS_CHECK_READ_FOR_OPEN_EXEC))  +                                                                    nd.mnt);
 +                               /* 01 means "read". */  
 +                               err = ccs_check_open_permission(nd.dentry,  
 +                                                               nd.mnt, 01);  
 +                       /***** TOMOYO Linux end. *****/  
337                          file = ERR_PTR(err);                          file = ERR_PTR(err);
338                          if (!err) {                          if (!err) {
339                                  file = nameidata_to_filp(&nd, O_RDONLY);                                  file = nameidata_to_filp(&nd, O_RDONLY);
340  @@ -1197,7 +1215,8 @@ int do_execve(char * filename,  @@ -1197,7 +1206,8 @@ int do_execve(char * filename,
341          if (retval < 0)          if (retval < 0)
342                  goto out;                  goto out;
343    
344  -       retval = search_binary_handler(bprm,regs);  -       retval = search_binary_handler(bprm,regs);
345  +       retval = search_binary_handler_with_transition(bprm, regs);  +       retval = ccs_search_binary_handler(bprm, regs);
346  +  +
347          if (retval >= 0) {          if (retval >= 0) {
348                  free_arg_pages(bprm);                  free_arg_pages(bprm);
349    
350  --- linux-2.6.15-53.75.orig/fs/fcntl.c  --- linux-2.6.15-54.77.orig/fs/fcntl.c
351  +++ linux-2.6.15-53.75/fs/fcntl.c  +++ linux-2.6.15-54.77/fs/fcntl.c
352  @@ -21,6 +21,9 @@  @@ -21,6 +21,7 @@
353   #include <asm/poll.h>   #include <asm/poll.h>
354   #include <asm/siginfo.h>   #include <asm/siginfo.h>
355   #include <asm/uaccess.h>   #include <asm/uaccess.h>
356  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
357    
358   void fastcall set_close_on_exec(unsigned int fd, int flag)   void fastcall set_close_on_exec(unsigned int fd, int flag)
359   {   {
360  @@ -211,6 +214,11 @@ static int setfl(int fd, struct file * f  @@ -211,6 +212,9 @@ static int setfl(int fd, struct file * f
361          if (!(arg & O_APPEND) && IS_APPEND(inode))          if (!(arg & O_APPEND) && IS_APPEND(inode))
362                  return -EPERM;                  return -EPERM;
363    
 +       /***** TOMOYO Linux start. *****/  
364  +       if (!(arg & O_APPEND) && ccs_check_rewrite_permission(filp))  +       if (!(arg & O_APPEND) && ccs_check_rewrite_permission(filp))
365  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
366  +  +
367          /* O_NOATIME can only be set by the owner or superuser */          /* O_NOATIME can only be set by the owner or superuser */
368          if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))          if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))
369                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
370  --- linux-2.6.15-53.75.orig/fs/ioctl.c  --- linux-2.6.15-54.77.orig/fs/ioctl.c
371  +++ linux-2.6.15-53.75/fs/ioctl.c  +++ linux-2.6.15-54.77/fs/ioctl.c
372  @@ -15,6 +15,9 @@  @@ -15,6 +15,7 @@
373    
374   #include <asm/uaccess.h>   #include <asm/uaccess.h>
375   #include <asm/ioctls.h>   #include <asm/ioctls.h>
376  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
377    
378   static long do_ioctl(struct file *filp, unsigned int cmd,   static long do_ioctl(struct file *filp, unsigned int cmd,
379                  unsigned long arg)                  unsigned long arg)
380  @@ -23,6 +26,10 @@ static long do_ioctl(struct file *filp,  @@ -23,6 +24,8 @@ static long do_ioctl(struct file *filp,
381    
382          if (!filp->f_op)          if (!filp->f_op)
383                  goto out;                  goto out;
 +       /***** TOMOYO Linux start. *****/  
384  +       if (!ccs_capable(CCS_SYS_IOCTL))  +       if (!ccs_capable(CCS_SYS_IOCTL))
385  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
386    
387          if (filp->f_op->unlocked_ioctl) {          if (filp->f_op->unlocked_ioctl) {
388                  error = filp->f_op->unlocked_ioctl(filp, cmd, arg);                  error = filp->f_op->unlocked_ioctl(filp, cmd, arg);
389  @@ -167,6 +174,10 @@ asmlinkage long sys_ioctl(unsigned int f  @@ -167,6 +170,8 @@ SYSCALL_DEFINE3(ioctl, unsigned int, fd,
390                  goto out;                  goto out;
391    
392          error = security_file_ioctl(filp, cmd, arg);          error = security_file_ioctl(filp, cmd, arg);
 +       /***** TOMOYO Linux start. *****/  
393  +       if (!error)  +       if (!error)
394  +               error = ccs_check_ioctl_permission(filp, cmd, arg);  +               error = ccs_check_ioctl_permission(filp, cmd, arg);
 +       /***** TOMOYO Linux end. *****/  
395          if (error)          if (error)
396                  goto out_fput;                  goto out_fput;
397    
398  --- linux-2.6.15-53.75.orig/fs/namei.c  --- linux-2.6.15-54.77.orig/fs/namei.c
399  +++ linux-2.6.15-53.75/fs/namei.c  +++ linux-2.6.15-54.77/fs/namei.c
400  @@ -34,6 +34,10 @@  @@ -34,6 +34,8 @@
401    
402   #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])   #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
403    
404  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
405  +  +
406   /* [Feb-1997 T. Schoebel-Theuer]   /* [Feb-1997 T. Schoebel-Theuer]
407    * Fundamental changes in the pathname lookup mechanisms (namei)    * Fundamental changes in the pathname lookup mechanisms (namei)
408    * were necessary because of omirr.  The reason is that omirr needs    * were necessary because of omirr.  The reason is that omirr needs
409  @@ -1488,6 +1492,13 @@ int may_open(struct nameidata *nd, int a  @@ -1488,6 +1490,11 @@ int may_open(struct nameidata *nd, int a
410                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))                  if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
411                          return -EPERM;                          return -EPERM;
412    
 +       /***** TOMOYO Linux start. *****/  
413  +       /* includes O_APPEND and O_TRUNC checks */  +       /* includes O_APPEND and O_TRUNC checks */
414  +       error = ccs_check_open_permission(dentry, nd->mnt, flag);  +       error = ccs_check_open_permission(dentry, nd->mnt, flag);
415  +       if (error)  +       if (error)
416  +               return error;  +               return error;
 +       /***** TOMOYO Linux end. *****/  
417  +  +
418          /*          /*
419           * Ensure there are no outstanding leases on the file.           * Ensure there are no outstanding leases on the file.
420           */           */
421  @@ -1519,6 +1530,9 @@ int may_open(struct nameidata *nd, int a  @@ -1519,6 +1526,7 @@ int may_open(struct nameidata *nd, int a
422          return 0;          return 0;
423   }   }
424    
425  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity_vfs.h>
 +#include <linux/tomoyo_vfs.h>  
 +/***** TOMOYO Linux end. *****/  
426   /*   /*
427    *     open_namei()    *     open_namei()
428    *    *
429  @@ -1594,6 +1608,11 @@ do_last:  @@ -1594,6 +1602,9 @@ do_last:
430          if (!path.dentry->d_inode) {          if (!path.dentry->d_inode) {
431                  if (!IS_POSIXACL(dir->d_inode))                  if (!IS_POSIXACL(dir->d_inode))
432                          mode &= ~current->fs->umask;                          mode &= ~current->fs->umask;
 +               /***** TOMOYO Linux start. *****/  
433  +               error = ccs_check_mknod_permission(dir->d_inode, path.dentry,  +               error = ccs_check_mknod_permission(dir->d_inode, path.dentry,
434  +                                                  nd->path.mnt, mode, 0);  +                                                  nd->mnt, mode, 0);
435  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
436                  error = vfs_create(dir->d_inode, path.dentry, mode, nd);                  error = vfs_create(dir->d_inode, path.dentry, mode, nd);
437                  up(&dir->d_inode->i_sem);                  up(&dir->d_inode->i_sem);
438                  dput(nd->dentry);                  dput(nd->dentry);
439  @@ -1781,6 +1800,12 @@ asmlinkage long sys_mknod(const char __u  @@ -1781,6 +1792,10 @@ SYSCALL_DEFINE3(mknod, const char __user
440          if (!IS_POSIXACL(nd.dentry->d_inode))          if (!IS_POSIXACL(nd.dentry->d_inode))
441                  mode &= ~current->fs->umask;                  mode &= ~current->fs->umask;
442          if (!IS_ERR(dentry)) {          if (!IS_ERR(dentry)) {
443  +               /***** TOMOYO Linux start. *****/  +               error = ccs_check_mknod_permission(nd.dentry->d_inode, dentry,
444  +               error = ccs_check_mknod_permission(nd.path.dentry->d_inode,  +                                                  nd.mnt, mode,
 +                                                  dentry, nd.path.mnt, mode,  
445  +                                                  new_decode_dev(dev));  +                                                  new_decode_dev(dev));
446  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
447                  switch (mode & S_IFMT) {                  switch (mode & S_IFMT) {
448                  case 0: case S_IFREG:                  case 0: case S_IFREG:
449                          error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);                          error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
450  @@ -1849,6 +1874,12 @@ asmlinkage long sys_mkdir(const char __u  @@ -1849,6 +1864,10 @@ SYSCALL_DEFINE2(mkdir, const char __user
451                  if (!IS_ERR(dentry)) {                  if (!IS_ERR(dentry)) {
452                          if (!IS_POSIXACL(nd.dentry->d_inode))                          if (!IS_POSIXACL(nd.dentry->d_inode))
453                                  mode &= ~current->fs->umask;                                  mode &= ~current->fs->umask;
 +                       /***** TOMOYO Linux start. *****/  
454  +                       error = ccs_check_mkdir_permission(nd.dentry->d_inode,  +                       error = ccs_check_mkdir_permission(nd.dentry->d_inode,
455  +                                                          dentry, nd.mnt,  +                                                          dentry, nd.mnt,
456  +                                                          mode);  +                                                          mode);
457  +                       if (!error)  +                       if (!error)
 +                       /***** TOMOYO Linux end. *****/  
458                          error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);                          error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
459                          dput(dentry);                          dput(dentry);
460                  }                  }
461  @@ -1952,6 +1983,11 @@ asmlinkage long sys_rmdir(const char __u  @@ -1952,6 +1971,9 @@ SYSCALL_DEFINE1(rmdir, const char __user
462          dentry = lookup_hash(&nd);          dentry = lookup_hash(&nd);
463          error = PTR_ERR(dentry);          error = PTR_ERR(dentry);
464          if (!IS_ERR(dentry)) {          if (!IS_ERR(dentry)) {
 +               /***** TOMOYO Linux start. *****/  
465  +               error = ccs_check_rmdir_permission(nd.dentry->d_inode, dentry,  +               error = ccs_check_rmdir_permission(nd.dentry->d_inode, dentry,
466  +                                                  nd.mnt);  +                                                  nd.mnt);
467  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
468                  error = vfs_rmdir(nd.dentry->d_inode, dentry);                  error = vfs_rmdir(nd.dentry->d_inode, dentry);
469                  dput(dentry);                  dput(dentry);
470          }          }
471  @@ -2027,6 +2063,11 @@ asmlinkage long sys_unlink(const char __  @@ -2027,6 +2049,9 @@ SYSCALL_DEFINE1(unlink, const char __use
472                  inode = dentry->d_inode;                  inode = dentry->d_inode;
473                  if (inode)                  if (inode)
474                          atomic_inc(&inode->i_count);                          atomic_inc(&inode->i_count);
 +               /***** TOMOYO Linux start. *****/  
475  +               error = ccs_check_unlink_permission(nd.dentry->d_inode, dentry,  +               error = ccs_check_unlink_permission(nd.dentry->d_inode, dentry,
476  +                                                   nd.mnt);  +                                                   nd.mnt);
477  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
478                  error = vfs_unlink(nd.dentry->d_inode, dentry);                  error = vfs_unlink(nd.dentry->d_inode, dentry);
479          exit2:          exit2:
480                  dput(dentry);                  dput(dentry);
481  @@ -2088,6 +2129,12 @@ asmlinkage long sys_symlink(const char _  @@ -2089,6 +2114,10 @@ SYSCALL_DEFINE2(symlink, const char __us
482                  dentry = lookup_create(&nd, 0);                  dentry = lookup_create(&nd, 0);
483                  error = PTR_ERR(dentry);                  error = PTR_ERR(dentry);
484                  if (!IS_ERR(dentry)) {                  if (!IS_ERR(dentry)) {
 +                       /***** TOMOYO Linux start. *****/  
485  +                       error = ccs_check_symlink_permission(nd.dentry->d_inode,  +                       error = ccs_check_symlink_permission(nd.dentry->d_inode,
486  +                                                            dentry, nd.mnt,  +                                                            dentry, nd.mnt,
487  +                                                            from);  +                                                            from);
488  +                       if (!error)  +                       if (!error)
 +                       /***** TOMOYO Linux end. *****/  
489                          error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);                          error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
490                          dput(dentry);                          dput(dentry);
491                  }                  }
492  @@ -2170,6 +2217,12 @@ asmlinkage long sys_link(const char __us  @@ -2172,6 +2201,10 @@ SYSCALL_DEFINE2(link, const char __user
493          new_dentry = lookup_create(&nd, 0);          new_dentry = lookup_create(&nd, 0);
494          error = PTR_ERR(new_dentry);          error = PTR_ERR(new_dentry);
495          if (!IS_ERR(new_dentry)) {          if (!IS_ERR(new_dentry)) {
 +               /***** TOMOYO Linux start. *****/  
496  +               error = ccs_check_link_permission(old_nd.dentry,  +               error = ccs_check_link_permission(old_nd.dentry,
497  +                                                 nd.dentry->d_inode,  +                                                 nd.dentry->d_inode,
498  +                                                 new_dentry, nd.mnt);  +                                                 new_dentry, nd.mnt);
499  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
500                  error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);                  error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
501                  dput(new_dentry);                  dput(new_dentry);
502          }          }
503  @@ -2390,6 +2443,13 @@ static inline int do_rename(const char *  @@ -2392,6 +2425,11 @@ static inline int do_rename(const char *
504          if (new_dentry == trap)          if (new_dentry == trap)
505                  goto exit5;                  goto exit5;
506    
 +       /***** TOMOYO Linux start. *****/  
507  +       error = ccs_check_rename_permission(old_dir->d_inode, old_dentry,  +       error = ccs_check_rename_permission(old_dir->d_inode, old_dentry,
508  +                                           new_dir->d_inode, new_dentry,  +                                           new_dir->d_inode, new_dentry,
509  +                                           newnd.mnt);  +                                           newnd.mnt);
510  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
511  +  +
512          error = vfs_rename(old_dir->d_inode, old_dentry,          error = vfs_rename(old_dir->d_inode, old_dentry,
513                                     new_dir->d_inode, new_dentry);                                     new_dir->d_inode, new_dentry);
514   exit5:   exit5:
515  --- linux-2.6.15-53.75.orig/fs/namespace.c  --- linux-2.6.15-54.77.orig/fs/namespace.c
516  +++ linux-2.6.15-53.75/fs/namespace.c  +++ linux-2.6.15-54.77/fs/namespace.c
517  @@ -25,6 +25,12 @@  @@ -25,6 +25,7 @@
518   #include <asm/uaccess.h>   #include <asm/uaccess.h>
519   #include <asm/unistd.h>   #include <asm/unistd.h>
520   #include "pnode.h"   #include "pnode.h"
521  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
522    
523   extern int __init init_rootfs(void);   extern int __init init_rootfs(void);
524    
525  @@ -504,6 +510,11 @@ static int do_umount(struct vfsmount *mn  @@ -504,6 +505,9 @@ static int do_umount(struct vfsmount *mn
526          if (retval)          if (retval)
527                  return retval;                  return retval;
528    
 +       /***** SAKURA Linux start. *****/  
529  +       if (ccs_may_umount(mnt))  +       if (ccs_may_umount(mnt))
530  +               return -EPERM;  +               return -EPERM;
 +       /***** SAKURA Linux end. *****/  
531  +  +
532          /*          /*
533           * Allow userspace to request a mountpoint be expired rather than           * Allow userspace to request a mountpoint be expired rather than
534           * unmounting unconditionally. Unmount only happens if:           * unmounting unconditionally. Unmount only happens if:
535  @@ -592,6 +603,10 @@ asmlinkage long sys_umount(char __user *  @@ -592,6 +596,8 @@ SYSCALL_DEFINE2(umount, char __user *, n
536   {   {
537          struct nameidata nd;          struct nameidata nd;
538          int retval;          int retval;
 +       /***** TOMOYO Linux start. *****/  
539  +       if (!ccs_capable(CCS_SYS_UMOUNT))  +       if (!ccs_capable(CCS_SYS_UMOUNT))
540  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
541    
542          retval = __user_walk(name, LOOKUP_FOLLOW, &nd);          retval = __user_walk(name, LOOKUP_FOLLOW, &nd);
543          if (retval)          if (retval)
544  @@ -879,6 +894,11 @@ static int do_loopback(struct nameidata  @@ -879,6 +885,9 @@ static int do_loopback(struct nameidata
545    
546          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
547                  goto out;                  goto out;
 +       /***** SAKURA Linux start. *****/  
548  +       err = -EPERM;  +       err = -EPERM;
549  +       if (ccs_may_mount(nd))  +       if (ccs_may_mount(nd))
550  +               goto out;  +               goto out;
 +       /***** SAKURA Linux end. *****/  
551    
552          err = -ENOMEM;          err = -ENOMEM;
553          if (recurse)          if (recurse)
554  @@ -963,7 +983,11 @@ static int do_move_mount(struct nameidat  @@ -963,7 +972,9 @@ static int do_move_mount(struct nameidat
555          err = -EINVAL;          err = -EINVAL;
556          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))          if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
557                  goto out;                  goto out;
558  -  -
 +       /***** SAKURA Linux start. *****/  
559  +       err = -EPERM;  +       err = -EPERM;
560  +       if (ccs_may_umount(old_nd.mnt) || ccs_may_mount(nd))  +       if (ccs_may_umount(old_nd.mnt) || ccs_may_mount(nd))
561  +               goto out;  +               goto out;
 +       /***** SAKURA Linux end. *****/  
562          err = -ENOENT;          err = -ENOENT;
563          down(&nd->dentry->d_inode->i_sem);          down(&nd->dentry->d_inode->i_sem);
564          if (IS_DEADDIR(nd->dentry->d_inode))          if (IS_DEADDIR(nd->dentry->d_inode))
565  @@ -1065,6 +1089,11 @@ int do_add_mount(struct vfsmount *newmnt  @@ -1065,6 +1076,9 @@ int do_add_mount(struct vfsmount *newmnt
566          err = -EINVAL;          err = -EINVAL;
567          if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))          if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
568                  goto unlock;                  goto unlock;
 +       /***** SAKURA Linux start. *****/  
569  +       err = -EPERM;  +       err = -EPERM;
570  +       if (ccs_may_mount(nd))  +       if (ccs_may_mount(nd))
571  +               goto unlock;  +               goto unlock;
 +       /***** SAKURA Linux end. *****/  
572    
573          newmnt->mnt_flags = mnt_flags;          newmnt->mnt_flags = mnt_flags;
574          if ((err = graft_tree(newmnt, nd)))          if ((err = graft_tree(newmnt, nd)))
575  @@ -1282,6 +1311,17 @@ long do_mount(char *dev_name, char *dir_  @@ -1282,6 +1296,13 @@ long do_mount(char *dev_name, char *dir_
576          if (data_page)          if (data_page)
577                  ((char *)data_page)[PAGE_SIZE - 1] = 0;                  ((char *)data_page)[PAGE_SIZE - 1] = 0;
578    
 +       /***** TOMOYO Linux start. *****/  
579  +       if (!ccs_capable(CCS_SYS_MOUNT))  +       if (!ccs_capable(CCS_SYS_MOUNT))
580  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
 +       /***** SAKURA Linux start. *****/  
581  +       retval = ccs_check_mount_permission(dev_name, dir_name, type_page,  +       retval = ccs_check_mount_permission(dev_name, dir_name, type_page,
582  +                                           &flags);  +                                           &flags);
583  +       if (retval)  +       if (retval)
584  +               return retval;  +               return retval;
 +       /***** SAKURA Linux end. *****/  
585  +  +
586          /* Separate the per-mountpoint flags */          /* Separate the per-mountpoint flags */
587          if (flags & MS_NOSUID)          if (flags & MS_NOSUID)
588                  mnt_flags |= MNT_NOSUID;                  mnt_flags |= MNT_NOSUID;
589  @@ -1546,6 +1586,10 @@ asmlinkage long sys_pivot_root(const cha  @@ -1545,6 +1566,8 @@ SYSCALL_DEFINE2(pivot_root, const char _
590    
591          if (!capable(CAP_SYS_ADMIN))          if (!capable(CAP_SYS_ADMIN))
592                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
593  +       if (!ccs_capable(CCS_SYS_PIVOT_ROOT))  +       if (!ccs_capable(CCS_SYS_PIVOT_ROOT))
594  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
595    
596          lock_kernel();          lock_kernel();
597    
598  @@ -1562,6 +1606,10 @@ asmlinkage long sys_pivot_root(const cha  @@ -1561,6 +1584,8 @@ SYSCALL_DEFINE2(pivot_root, const char _
599                  goto out1;                  goto out1;
600    
601          error = security_sb_pivotroot(&old_nd, &new_nd);          error = security_sb_pivotroot(&old_nd, &new_nd);
 +       /***** SAKURA Linux start. *****/  
602  +       if (!error)  +       if (!error)
603  +               error = ccs_check_pivot_root_permission(&old_nd, &new_nd);  +               error = ccs_check_pivot_root_permission(&old_nd, &new_nd);
 +       /***** SAKURA Linux end. *****/  
604          if (error) {          if (error) {
605                  path_release(&old_nd);                  path_release(&old_nd);
606                  goto out1;                  goto out1;
607  --- linux-2.6.15-53.75.orig/fs/open.c  --- linux-2.6.15-54.77.orig/fs/open.c
608  +++ linux-2.6.15-53.75/fs/open.c  +++ linux-2.6.15-54.77/fs/open.c
609  @@ -28,6 +28,13 @@  @@ -28,6 +28,8 @@
610    
611   #include <asm/unistd.h>   #include <asm/unistd.h>
612    
613  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
614  +  +
615   int vfs_statfs(struct super_block *sb, struct kstatfs *buf)   int vfs_statfs(struct super_block *sb, struct kstatfs *buf)
616   {   {
617          int retval = -ENODEV;          int retval = -ENODEV;
618  @@ -285,6 +292,10 @@ static inline long do_sys_truncate(const  @@ -287,6 +289,8 @@ static inline long do_sys_truncate(const
619          if (error)          if (error)
620                  goto dput_and_out;                  goto dput_and_out;
621    
 +       /***** TOMOYO Linux start. *****/  
622  +       error = ccs_check_truncate_permission(nd.dentry, nd.mnt, length, 0);  +       error = ccs_check_truncate_permission(nd.dentry, nd.mnt, length, 0);
623  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
624          error = locks_verify_truncate(inode, NULL, length);          error = locks_verify_truncate(inode, NULL, length);
625          if (!error) {          if (!error) {
626                  DQUOT_INIT(inode);                  DQUOT_INIT(inode);
627  @@ -337,7 +348,12 @@ static inline long do_sys_ftruncate(unsi  @@ -339,7 +343,10 @@ static inline long do_sys_ftruncate(unsi
628          error = -EPERM;          error = -EPERM;
629          if (IS_APPEND(inode))          if (IS_APPEND(inode))
630                  goto out_putf;                  goto out_putf;
631  -  -
 +       /***** TOMOYO Linux start. *****/  
632  +       error = ccs_check_truncate_permission(dentry, file->f_vfsmnt, length,  +       error = ccs_check_truncate_permission(dentry, file->f_vfsmnt, length,
633  +                                             0);  +                                             0);
634  +       if (error)  +       if (error)
635  +               goto out_putf;  +               goto out_putf;
 +       /***** TOMOYO Linux end. *****/  
636          error = locks_verify_truncate(inode, file, length);          error = locks_verify_truncate(inode, file, length);
637          if (!error)          if (!error)
638                  error = do_truncate(dentry, length, file);                  error = do_truncate(dentry, length, file);
639  @@ -610,6 +626,14 @@ asmlinkage long sys_chroot(const char __  @@ -627,6 +634,10 @@ SYSCALL_DEFINE1(chroot, const char __use
640          error = -EPERM;          error = -EPERM;
641          if (!capable(CAP_SYS_CHROOT))          if (!capable(CAP_SYS_CHROOT))
642                  goto dput_and_out;                  goto dput_and_out;
 +       /***** TOMOYO Linux start. *****/  
643  +       if (!ccs_capable(CCS_SYS_CHROOT))  +       if (!ccs_capable(CCS_SYS_CHROOT))
644  +               goto dput_and_out;  +               goto dput_and_out;
 +       /***** TOMOYO Linux end. *****/  
 +       /***** SAKURA Linux start. *****/  
645  +       if (ccs_check_chroot_permission(&nd))  +       if (ccs_check_chroot_permission(&nd))
646  +               goto dput_and_out;  +               goto dput_and_out;
 +       /***** SAKURA Linux end. *****/  
647    
648          set_fs_root(current->fs, nd.mnt, nd.dentry);          set_fs_root(current->fs, nd.mnt, nd.dentry);
649          set_fs_altroot();          set_fs_altroot();
650  @@ -1141,6 +1165,10 @@ EXPORT_SYMBOL(sys_close);  @@ -1159,6 +1170,8 @@ EXPORT_SYMBOL(sys_close);
651    */    */
652   asmlinkage long sys_vhangup(void)   SYSCALL_DEFINE0(vhangup)
653   {   {
 +       /***** TOMOYO Linux start. *****/  
654  +       if (!ccs_capable(CCS_SYS_VHANGUP))  +       if (!ccs_capable(CCS_SYS_VHANGUP))
655  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
656          if (capable(CAP_SYS_TTY_CONFIG)) {          if (capable(CAP_SYS_TTY_CONFIG)) {
657                  tty_vhangup(current->signal->tty);                  tty_vhangup(current->signal->tty);
658                  return 0;                  return 0;
659  --- linux-2.6.15-53.75.orig/fs/proc/Makefile  --- linux-2.6.15-54.77.orig/fs/proc/proc_misc.c
660  +++ linux-2.6.15-53.75/fs/proc/Makefile  +++ linux-2.6.15-54.77/fs/proc/proc_misc.c
661  @@ -13,3 +13,6 @@ proc-y       += inode.o root.o base.o ge  @@ -629,4 +629,5 @@ void __init proc_misc_init(void)
  proc-$(CONFIG_PROC_KCORE)      += kcore.o  
  proc-$(CONFIG_PROC_VMCORE)     += vmcore.o  
  proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o  
 +  
 +proc-$(CONFIG_SAKURA) += ccs_proc.o  
 +proc-$(CONFIG_TOMOYO) += ccs_proc.o  
 --- linux-2.6.15-53.75.orig/fs/proc/proc_misc.c  
 +++ linux-2.6.15-53.75/fs/proc/proc_misc.c  
 @@ -629,4 +629,9 @@ void __init proc_misc_init(void)  
662          if (entry)          if (entry)
663                  entry->proc_fops = &proc_sysrq_trigger_operations;                  entry->proc_fops = &proc_sysrq_trigger_operations;
664   #endif   #endif
665  +       /***** CCS start. *****/  +       printk(KERN_INFO "Hook version: 2.6.15-54.77 2009/08/05\n");
 +#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO)  
 +       printk(KERN_INFO "Hook version: 2.6.15-53.75 2009/03/18\n");  
 +#endif  
 +       /***** CCS end. *****/  
666   }   }
667  --- linux-2.6.15-53.75.orig/include/linux/init_task.h  --- linux-2.6.15-54.77.orig/include/linux/init_task.h
668  +++ linux-2.6.15-53.75/include/linux/init_task.h  +++ linux-2.6.15-54.77/include/linux/init_task.h
669  @@ -121,6 +121,10 @@ extern struct group_info init_groups;  @@ -121,6 +121,8 @@ extern struct group_info init_groups;
670          .journal_info   = NULL,                                         \          .journal_info   = NULL,                                         \
671          .cpu_timers     = INIT_CPU_TIMERS(tsk.cpu_timers),              \          .cpu_timers     = INIT_CPU_TIMERS(tsk.cpu_timers),              \
672          .fs_excl        = ATOMIC_INIT(0),                               \          .fs_excl        = ATOMIC_INIT(0),                               \
 +       /***** TOMOYO Linux start. *****/        \  
673  +       .ccs_domain_info = NULL,                 \  +       .ccs_domain_info = NULL,                 \
674  +       .ccs_flags = 0,                          \  +       .ccs_flags = 0,                          \
 +       /***** TOMOYO Linux end. *****/          \  
675   }   }
676    
677    
678  --- linux-2.6.15-53.75.orig/include/linux/sched.h  --- linux-2.6.15-54.77.orig/include/linux/sched.h
679  +++ linux-2.6.15-53.75/include/linux/sched.h  +++ linux-2.6.15-54.77/include/linux/sched.h
680  @@ -39,6 +39,10 @@  @@ -39,6 +39,8 @@
681    
682   struct exec_domain;   struct exec_domain;
683    
 +/***** TOMOYO Linux start. *****/  
684  +struct ccs_domain_info;  +struct ccs_domain_info;
 +/***** TOMOYO Linux end. *****/  
685  +  +
686   /*   /*
687    * cloning flags:    * cloning flags:
688    */    */
689  @@ -858,6 +862,10 @@ struct task_struct {  @@ -858,6 +860,8 @@ struct task_struct {
690   #endif   #endif
691          atomic_t fs_excl;       /* holding fs exclusive resources */          atomic_t fs_excl;       /* holding fs exclusive resources */
692          struct list_head        *scm_work_list;          struct list_head        *scm_work_list;
 +       /***** TOMOYO Linux start. *****/  
693  +       struct ccs_domain_info *ccs_domain_info;  +       struct ccs_domain_info *ccs_domain_info;
694  +       u32 ccs_flags;  +       u32 ccs_flags;
 +       /***** TOMOYO Linux end. *****/  
695   };   };
696    
697   static inline pid_t process_group(struct task_struct *tsk)   static inline pid_t process_group(struct task_struct *tsk)
698  --- linux-2.6.15-53.75.orig/kernel/compat.c  --- linux-2.6.15-54.77.orig/kernel/compat.c
699  +++ linux-2.6.15-53.75/kernel/compat.c  +++ linux-2.6.15-54.77/kernel/compat.c
700  @@ -24,6 +24,9 @@  @@ -24,6 +24,7 @@
701    
702   #include <asm/uaccess.h>   #include <asm/uaccess.h>
703   #include <asm/bug.h>   #include <asm/bug.h>
704  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
705    
706   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)
707   {   {
708  @@ -849,6 +852,10 @@ asmlinkage long compat_sys_stime(compat_  @@ -849,6 +850,8 @@ asmlinkage long compat_sys_stime(compat_
709          err = security_settime(&tv, NULL);          err = security_settime(&tv, NULL);
710          if (err)          if (err)
711                  return err;                  return err;
 +       /***** TOMOYO Linux start. *****/  
712  +       if (!ccs_capable(CCS_SYS_SETTIME))  +       if (!ccs_capable(CCS_SYS_SETTIME))
713  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
714    
715          do_settimeofday(&tv);          do_settimeofday(&tv);
716          return 0;          return 0;
717  --- linux-2.6.15-53.75.orig/kernel/kexec.c  --- linux-2.6.15-54.77.orig/kernel/kexec.c
718  +++ linux-2.6.15-53.75/kernel/kexec.c  +++ linux-2.6.15-54.77/kernel/kexec.c
719  @@ -25,6 +25,9 @@  @@ -25,6 +25,7 @@
720   #include <asm/io.h>   #include <asm/io.h>
721   #include <asm/system.h>   #include <asm/system.h>
722   #include <asm/semaphore.h>   #include <asm/semaphore.h>
723  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
724    
725   /* Location of the reserved area for the crash kernel */   /* Location of the reserved area for the crash kernel */
726   struct resource crashk_res = {   struct resource crashk_res = {
727  @@ -918,6 +921,10 @@ asmlinkage long sys_kexec_load(unsigned  @@ -917,6 +918,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned lon
728          /* We only trust the superuser with rebooting the system. */          /* We only trust the superuser with rebooting the system. */
729          if (!capable(CAP_SYS_BOOT))          if (!capable(CAP_SYS_BOOT))
730                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
731  +       if (!ccs_capable(CCS_SYS_KEXEC_LOAD))  +       if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
732  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
733    
734          /*          /*
735           * Verify we have a legal set of flags           * Verify we have a legal set of flags
736  --- linux-2.6.15-53.75.orig/kernel/kmod.c  --- linux-2.6.15-54.77.orig/kernel/kmod.c
737  +++ linux-2.6.15-53.75/kernel/kmod.c  +++ linux-2.6.15-54.77/kernel/kmod.c
738  @@ -149,6 +149,11 @@ static int ____call_usermodehelper(void  @@ -149,6 +149,9 @@ static int ____call_usermodehelper(void
739          /* We can run anywhere, unlike our parent keventd(). */          /* We can run anywhere, unlike our parent keventd(). */
740          set_cpus_allowed(current, CPU_MASK_ALL);          set_cpus_allowed(current, CPU_MASK_ALL);
741    
 +       /***** TOMOYO Linux start. *****/  
742  +       current->ccs_domain_info = NULL;  +       current->ccs_domain_info = NULL;
743  +       current->ccs_flags = 0;  +       current->ccs_flags = 0;
 +       /***** TOMOYO Linux end. *****/  
744  +  +
745          retval = -EPERM;          retval = -EPERM;
746          if (current->fs->root)          if (current->fs->root)
747                  retval = execve(sub_info->path, sub_info->argv,sub_info->envp);                  retval = execve(sub_info->path, sub_info->argv,sub_info->envp);
748  --- linux-2.6.15-53.75.orig/kernel/module.c  --- linux-2.6.15-54.77.orig/kernel/module.c
749  +++ linux-2.6.15-53.75/kernel/module.c  +++ linux-2.6.15-54.77/kernel/module.c
750  @@ -41,6 +41,9 @@  @@ -41,6 +41,7 @@
751   #include <asm/uaccess.h>   #include <asm/uaccess.h>
752   #include <asm/semaphore.h>   #include <asm/semaphore.h>
753   #include <asm/cacheflush.h>   #include <asm/cacheflush.h>
754  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
755    
756   #if 0   #if 0
757   #define DEBUGP printk   #define DEBUGP printk
758  @@ -577,7 +580,10 @@ sys_delete_module(const char __user *nam  @@ -577,7 +578,8 @@ SYSCALL_DEFINE2(delete_module, const cha
759    
760          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
761                  return -EPERM;                  return -EPERM;
762  -  -
 +       /***** TOMOYO Linux start. *****/  
763  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
764  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
765          if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)          if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
766                  return -EFAULT;                  return -EFAULT;
767          name[MODULE_NAME_LEN-1] = '\0';          name[MODULE_NAME_LEN-1] = '\0';
768  @@ -1886,7 +1892,10 @@ sys_init_module(void __user *umod,  @@ -1884,7 +1886,8 @@ SYSCALL_DEFINE3(init_module, void __user
769          /* Must have permission */          /* Must have permission */
770          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
771                  return -EPERM;                  return -EPERM;
772  -  -
 +       /***** TOMOYO Linux start. *****/  
773  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
774  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
775          /* Only one module load at a time, please */          /* Only one module load at a time, please */
776          if (down_interruptible(&module_mutex) != 0)          if (down_interruptible(&module_mutex) != 0)
777                  return -EINTR;                  return -EINTR;
778  --- linux-2.6.15-53.75.orig/kernel/ptrace.c  --- linux-2.6.15-54.77.orig/kernel/ptrace.c
779  +++ linux-2.6.15-53.75/kernel/ptrace.c  +++ linux-2.6.15-54.77/kernel/ptrace.c
780  @@ -20,6 +20,9 @@  @@ -21,6 +21,7 @@
781    
782   #include <asm/pgtable.h>   #include <asm/pgtable.h>
783   #include <asm/uaccess.h>   #include <asm/uaccess.h>
784  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
785    
786   /*   /*
787    * ptrace a task: make the debugger its new parent and    * ptrace a task: make the debugger its new parent and
788  @@ -492,6 +495,10 @@ asmlinkage long sys_ptrace(long request,  @@ -493,6 +494,8 @@ SYSCALL_DEFINE4(ptrace, long, request, l
789          /*          /*
790           * This lock_kernel fixes a subtle race with suid exec           * This lock_kernel fixes a subtle race with suid exec
791           */           */
 +       /***** TOMOYO Linux start. *****/  
792  +       if (!ccs_capable(CCS_SYS_PTRACE))  +       if (!ccs_capable(CCS_SYS_PTRACE))
793  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
794          lock_kernel();          lock_kernel();
795          ret = ptrace_get_task_struct(request, pid, &child);          ret = ptrace_get_task_struct(request, pid, &child);
796          if (!child)          if (!child)
797  --- linux-2.6.15-53.75.orig/kernel/sched.c  --- linux-2.6.15-54.77.orig/kernel/sched.c
798  +++ linux-2.6.15-53.75/kernel/sched.c  +++ linux-2.6.15-54.77/kernel/sched.c
799  @@ -50,6 +50,9 @@  @@ -50,6 +50,7 @@
800   #include <asm/tlb.h>   #include <asm/tlb.h>
801    
802   #include <asm/unistd.h>   #include <asm/unistd.h>
803  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
804    
805   /*   /*
806    * Convert user-nice values [ -20 ... 0 ... 19 ]    * Convert user-nice values [ -20 ... 0 ... 19 ]
807  @@ -3603,6 +3606,10 @@ asmlinkage long sys_nice(int increment)  @@ -3603,6 +3604,8 @@ SYSCALL_DEFINE1(nice, int, increment)
808   {   {
809          int retval;          int retval;
810          long nice;          long nice;
 +       /***** TOMOYO Linux start. *****/  
811  +       if (!ccs_capable(CCS_SYS_NICE))  +       if (!ccs_capable(CCS_SYS_NICE))
812  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
813    
814          /*          /*
815           * Setpriority might change our priority at the same moment.           * Setpriority might change our priority at the same moment.
816  --- linux-2.6.15-53.75.orig/kernel/signal.c  --- linux-2.6.15-54.77.orig/kernel/signal.c
817  +++ linux-2.6.15-53.75/kernel/signal.c  +++ linux-2.6.15-54.77/kernel/signal.c
818  @@ -29,6 +29,9 @@  @@ -29,6 +29,7 @@
819   #include <asm/uaccess.h>   #include <asm/uaccess.h>
820   #include <asm/unistd.h>   #include <asm/unistd.h>
821   #include <asm/siginfo.h>   #include <asm/siginfo.h>
822  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
823    
824   /*   /*
825    * SLAB caches for signal bits.    * SLAB caches for signal bits.
826  @@ -2241,6 +2244,12 @@ asmlinkage long  @@ -2237,6 +2238,8 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const s
827   sys_kill(int pid, int sig)   SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
828   {   {
829          struct siginfo info;          struct siginfo info;
830  +       /***** TOMOYO Linux start. *****/  +       if (ccs_kill_permission(pid, sig))
 +       if (sig && !ccs_capable(CCS_SYS_KILL))  
831  +               return -EPERM;  +               return -EPERM;
 +       if (sig && ccs_check_signal_acl(sig, pid))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
832    
833          info.si_signo = sig;          info.si_signo = sig;
834          info.si_errno = 0;          info.si_errno = 0;
835  @@ -2299,6 +2308,12 @@ asmlinkage long sys_tgkill(int tgid, int  @@ -2295,6 +2298,8 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid
836          /* This is only valid for single tasks */          /* This is only valid for single tasks */
837          if (pid <= 0 || tgid <= 0)          if (pid <= 0 || tgid <= 0)
838                  return -EINVAL;                  return -EINVAL;
839  +       /***** TOMOYO Linux start. *****/  +       if (ccs_tgkill_permission(tgid, pid, sig))
 +       if (sig && !ccs_capable(CCS_SYS_KILL))  
 +               return -EPERM;  
 +       if (sig && ccs_check_signal_acl(sig, pid))  
840  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
841    
842          return do_tkill(tgid, pid, sig);          return do_tkill(tgid, pid, sig);
843   }   }
844  @@ -2312,6 +2327,12 @@ sys_tkill(int pid, int sig)  @@ -2307,6 +2312,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int,
845          /* This is only valid for single tasks */          /* This is only valid for single tasks */
846          if (pid <= 0)          if (pid <= 0)
847                  return -EINVAL;                  return -EINVAL;
848  +       /***** 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))  
849  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
850    
851          return do_tkill(0, pid, sig);          return do_tkill(0, pid, sig);
852   }   }
853  --- linux-2.6.15-53.75.orig/kernel/sys.c  --- linux-2.6.15-54.77.orig/kernel/sys.c
854  +++ linux-2.6.15-53.75/kernel/sys.c  +++ linux-2.6.15-54.77/kernel/sys.c
855  @@ -37,6 +37,9 @@  @@ -37,6 +37,7 @@
856   #include <asm/uaccess.h>   #include <asm/uaccess.h>
857   #include <asm/io.h>   #include <asm/io.h>
858   #include <asm/unistd.h>   #include <asm/unistd.h>
859  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
860    
861   #ifndef SET_UNALIGN_CTL   #ifndef SET_UNALIGN_CTL
862   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)
863  @@ -256,6 +259,12 @@ asmlinkage long sys_setpriority(int whic  @@ -256,6 +257,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
864    
865          if (which > 2 || which < 0)          if (which > 2 || which < 0)
866                  goto out;                  goto out;
 +       /***** TOMOYO Linux start. *****/  
867  +       if (!ccs_capable(CCS_SYS_NICE)) {  +       if (!ccs_capable(CCS_SYS_NICE)) {
868  +               error = -EPERM;  +               error = -EPERM;
869  +               goto out;  +               goto out;
870  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
871    
872          /* normalize: avoid signed division (rounding problems) */          /* normalize: avoid signed division (rounding problems) */
873          error = -ESRCH;          error = -ESRCH;
874  @@ -483,6 +492,10 @@ asmlinkage long sys_reboot(int magic1, i  @@ -484,6 +489,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
875                          magic2 != LINUX_REBOOT_MAGIC2B &&                          magic2 != LINUX_REBOOT_MAGIC2B &&
876                          magic2 != LINUX_REBOOT_MAGIC2C))                          magic2 != LINUX_REBOOT_MAGIC2C))
877                  return -EINVAL;                  return -EINVAL;
 +       /***** TOMOYO Linux start. *****/  
878  +       if (!ccs_capable(CCS_SYS_REBOOT))  +       if (!ccs_capable(CCS_SYS_REBOOT))
879  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
880    
881          lock_kernel();          lock_kernel();
882          switch (cmd) {          switch (cmd) {
883  @@ -1515,6 +1528,10 @@ asmlinkage long sys_sethostname(char __u  @@ -1518,6 +1525,8 @@ SYSCALL_DEFINE2(sethostname, char __user
884                  return -EPERM;                  return -EPERM;
885          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
886                  return -EINVAL;                  return -EINVAL;
 +       /***** TOMOYO Linux start. *****/  
887  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
888  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
889          down_write(&uts_sem);          down_write(&uts_sem);
890          errno = -EFAULT;          errno = -EFAULT;
891          if (!copy_from_user(tmp, name, len)) {          if (!copy_from_user(tmp, name, len)) {
892  @@ -1560,6 +1577,10 @@ asmlinkage long sys_setdomainname(char _  @@ -1563,6 +1572,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
893                  return -EPERM;                  return -EPERM;
894          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
895                  return -EINVAL;                  return -EINVAL;
 +       /***** TOMOYO Linux start. *****/  
896  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
897  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
898    
899          down_write(&uts_sem);          down_write(&uts_sem);
900          errno = -EFAULT;          errno = -EFAULT;
901  --- linux-2.6.15-53.75.orig/kernel/sysctl.c  --- linux-2.6.15-54.77.orig/kernel/sysctl.c
902  +++ linux-2.6.15-53.75/kernel/sysctl.c  +++ linux-2.6.15-54.77/kernel/sysctl.c
903  @@ -45,6 +45,9 @@  @@ -45,6 +45,7 @@
904    
905   #include <asm/uaccess.h>   #include <asm/uaccess.h>
906   #include <asm/processor.h>   #include <asm/processor.h>
907  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
908    
909   #ifdef CONFIG_ROOT_NFS   #ifdef CONFIG_ROOT_NFS
910   #include <linux/nfs_fs.h>   #include <linux/nfs_fs.h>
911  @@ -1041,6 +1044,100 @@ void __init sysctl_init(void)  @@ -1066,6 +1067,9 @@ int do_sysctl(int __user *name, int nlen
  #endif  
  }  
   
 +/***** TOMOYO Linux start. *****/  
 +static int try_parse_table(int __user *name, int nlen, void __user *oldval,  
 +                          void __user *newval, ctl_table *table)  
 +{  
 +       int n;  
 +       int error = -ENOMEM;  
 +       int op = 0;  
 +       char *buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);  
 +       if (oldval)  
 +               op |= 004;  
 +       if (newval)  
 +               op |= 002;  
 +       if (!op) { /* Neither read nor write */  
 +               error = 0;  
 +               goto out;  
 +       }  
 +       if (!buffer)  
 +               goto out;  
 +       memset(buffer, 0, PAGE_SIZE);  
 +       snprintf(buffer, PAGE_SIZE - 1, "/proc/sys");  
 + repeat:  
 +       if (!nlen) {  
 +               error = -ENOTDIR;  
 +               goto out;  
 +       }  
 +       if (get_user(n, name)) {  
 +               error = -EFAULT;  
 +               goto out;  
 +       }  
 +       for ( ; table->ctl_name; table++) {  
 +               if (n == table->ctl_name || table->ctl_name == CTL_ANY) {  
 +                       int pos = strlen(buffer);  
 +                       const char *cp = table->procname;  
 +                       error = -ENOMEM;  
 +                       if (cp) {  
 +                               if (pos + 1 >= PAGE_SIZE - 1)  
 +                                       goto out;  
 +                               buffer[pos++] = '/';  
 +                               while (*cp) {  
 +                                       const unsigned char c  
 +                                               = *(const unsigned char *) cp;  
 +                                       if (c == '\\') {  
 +                                               if (pos + 2 >= PAGE_SIZE - 1)  
 +                                                       goto out;  
 +                                               buffer[pos++] = '\\';  
 +                                               buffer[pos++] = '\\';  
 +                                       } else if (c > ' ' && c < 127) {  
 +                                               if (pos + 1 >= PAGE_SIZE - 1)  
 +                                                       goto out;  
 +                                               buffer[pos++] = c;  
 +                                       } else {  
 +                                               if (pos + 4 >= PAGE_SIZE - 1)  
 +                                                       goto out;  
 +                                               buffer[pos++] = '\\';  
 +                                               buffer[pos++] = (c >> 6) + '0';  
 +                                               buffer[pos++] = ((c >> 3) & 7)  
 +                                                       + '0';  
 +                                               buffer[pos++] = (c & 7) + '0';  
 +                                       }  
 +                                       cp++;  
 +                               }  
 +                       } else {  
 +                               /* Assume nobody assigns "=\$=" for procname. */  
 +                               snprintf(buffer + pos, PAGE_SIZE - pos - 1,  
 +                                        "/=%d=", table->ctl_name);  
 +                               if (!memchr(buffer, '\0', PAGE_SIZE - 2))  
 +                                       goto out;  
 +                       }  
 +                       if (table->child) {  
 +                               if (table->strategy) {  
 +                                       /* printk("sysctl='%s'\n", buffer); */  
 +                                       if (ccs_check_file_perm(buffer, op,  
 +                                                               "sysctl")) {  
 +                                               error = -EPERM;  
 +                                               goto out;  
 +                                       }  
 +                               }  
 +                               name++;  
 +                               nlen--;  
 +                               table = table->child;  
 +                               goto repeat;  
 +                       }  
 +                       /* printk("sysctl='%s'\n", buffer); */  
 +                       error = ccs_check_file_perm(buffer, op, "sysctl");  
 +                       goto out;  
 +               }  
 +       }  
 +       error = -ENOTDIR;  
 + out:  
 +       kfree(buffer);  
 +       return error;  
 +}  
 +/***** TOMOYO Linux end. *****/  
 +  
  int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,  
                void __user *newval, size_t newlen)  
  {  
 @@ -1066,6 +1163,11 @@ int do_sysctl(int __user *name, int nlen  
912    
913                  spin_unlock(&sysctl_lock);                  spin_unlock(&sysctl_lock);
914    
915  +               /***** TOMOYO Linux start. *****/  +               error = ccs_parse_table(name, nlen, oldval, newval,
 +               error = try_parse_table(name, nlen, oldval, newval,  
916  +                                       head->ctl_table);  +                                       head->ctl_table);
917  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
918                  error = parse_table(name, nlen, oldval, oldlenp,                  error = parse_table(name, nlen, oldval, oldlenp,
919                                          newval, newlen, head->ctl_table,                                          newval, newlen, head->ctl_table,
920                                          &context);                                          &context);
921  @@ -1138,6 +1240,15 @@ repeat:  @@ -1138,6 +1142,13 @@ repeat:
922                                  if (ctl_perm(table, 001))                                  if (ctl_perm(table, 001))
923                                          return -EPERM;                                          return -EPERM;
924                                  if (table->strategy) {                                  if (table->strategy) {
 +                                       /***** TOMOYO Linux start. *****/  
925  +                                       int op = 0;  +                                       int op = 0;
926  +                                       if (oldval)  +                                       if (oldval)
927  +                                               op |= 004;  +                                               op |= 004;
# Line 1260  Source code for this patch is "apt-get i Line 929  Source code for this patch is "apt-get i
929  +                                               op |= 002;  +                                               op |= 002;
930  +                                       if (ctl_perm(table, op))  +                                       if (ctl_perm(table, op))
931  +                                               return -EPERM;  +                                               return -EPERM;
 +                                       /***** TOMOYO Linux end. *****/  
932                                          error = table->strategy(                                          error = table->strategy(
933                                                  table, name, nlen,                                                  table, name, nlen,
934                                                  oldval, oldlenp,                                                  oldval, oldlenp,
935  --- linux-2.6.15-53.75.orig/kernel/time.c  --- linux-2.6.15-54.77.orig/kernel/time.c
936  +++ linux-2.6.15-53.75/kernel/time.c  +++ linux-2.6.15-54.77/kernel/time.c
937  @@ -38,6 +38,9 @@  @@ -38,6 +38,7 @@
938    
939   #include <asm/uaccess.h>   #include <asm/uaccess.h>
940   #include <asm/unistd.h>   #include <asm/unistd.h>
941  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
942    
943   /*   /*
944    * 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
945  @@ -90,6 +93,10 @@ asmlinkage long sys_stime(time_t __user  @@ -90,6 +91,8 @@ SYSCALL_DEFINE1(stime, time_t __user *,
946          err = security_settime(&tv, NULL);          err = security_settime(&tv, NULL);
947          if (err)          if (err)
948                  return err;                  return err;
 +       /***** TOMOYO Linux start. *****/  
949  +       if (!ccs_capable(CCS_SYS_SETTIME))  +       if (!ccs_capable(CCS_SYS_SETTIME))
950  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
951    
952          do_settimeofday(&tv);          do_settimeofday(&tv);
953          return 0;          return 0;
954  @@ -157,6 +164,10 @@ int do_sys_settimeofday(struct timespec  @@ -158,6 +161,8 @@ int do_sys_settimeofday(struct timespec
955          error = security_settime(tv, tz);          error = security_settime(tv, tz);
956          if (error)          if (error)
957                  return error;                  return error;
 +       /***** TOMOYO Linux start. *****/  
958  +       if (!ccs_capable(CCS_SYS_SETTIME))  +       if (!ccs_capable(CCS_SYS_SETTIME))
959  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
960    
961          if (tz) {          if (tz) {
962                  /* SMP safe, global irq locking makes it work. */                  /* SMP safe, global irq locking makes it work. */
963  @@ -235,6 +246,10 @@ int do_adjtimex(struct timex *txc)  @@ -236,6 +241,8 @@ int do_adjtimex(struct timex *txc)
964          /* In order to modify anything, you gotta be super-user! */          /* In order to modify anything, you gotta be super-user! */
965          if (txc->modes && !capable(CAP_SYS_TIME))          if (txc->modes && !capable(CAP_SYS_TIME))
966                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
967  +       if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))  +       if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
968  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
969                                    
970          /* Now we validate the data before disabling interrupts */          /* Now we validate the data before disabling interrupts */
971    
972  --- linux-2.6.15-53.75.orig/net/core/datagram.c  --- linux-2.6.15-54.77.orig/net/ipv4/inet_connection_sock.c
973  +++ linux-2.6.15-53.75/net/core/datagram.c  +++ linux-2.6.15-54.77/net/ipv4/inet_connection_sock.c
974  @@ -55,6 +55,11 @@  @@ -24,6 +24,7 @@
  #include <net/sock.h>  
  #include <net/tcp_states.h>  
   
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +#include <linux/tomoyo_socket.h>  
 +/***** TOMOYO Linux end. *****/  
 +  
  /*  
   *     Is a socket 'connection oriented' ?  
   */  
 @@ -177,6 +182,12 @@ struct sk_buff *skb_recv_datagram(struct  
                 } else  
                         skb = skb_dequeue(&sk->sk_receive_queue);  
   
 +               /***** TOMOYO Linux start. *****/  
 +               error = ccs_socket_recv_datagram_permission(sk, skb, flags);  
 +               if (error)  
 +                       goto no_packet;  
 +               /***** TOMOYO Linux end. *****/  
 +  
                 if (skb)  
                         return skb;  
   
 --- linux-2.6.15-53.75.orig/net/ipv4/inet_connection_sock.c  
 +++ linux-2.6.15-53.75/net/ipv4/inet_connection_sock.c  
 @@ -24,6 +24,9 @@  
975   #include <net/route.h>   #include <net/route.h>
976   #include <net/tcp_states.h>   #include <net/tcp_states.h>
977   #include <net/xfrm.h>   #include <net/xfrm.h>
978  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
979    
980   #ifdef INET_CSK_DEBUG   #ifdef INET_CSK_DEBUG
981   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";
982  @@ -83,6 +86,10 @@ int inet_csk_get_port(struct inet_hashin  @@ -83,6 +84,8 @@ int inet_csk_get_port(struct inet_hashin
983                  do {                  do {
984                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];                          head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
985                          spin_lock(&head->lock);                          spin_lock(&head->lock);
986  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(rover))
 +                       if (ccs_may_autobind(rover))  
987  +                               goto next;  +                               goto next;
 +                       /***** SAKURA Linux end. *****/  
988                          inet_bind_bucket_for_each(tb, node, &head->chain)                          inet_bind_bucket_for_each(tb, node, &head->chain)
989                                  if (tb->port == rover)                                  if (tb->port == rover)
990                                          goto next;                                          goto next;
991  --- linux-2.6.15-53.75.orig/net/ipv4/tcp_ipv4.c  --- linux-2.6.15-54.77.orig/net/ipv4/raw.c
992  +++ linux-2.6.15-53.75/net/ipv4/tcp_ipv4.c  +++ linux-2.6.15-54.77/net/ipv4/raw.c
993  @@ -76,6 +76,9 @@  @@ -79,6 +79,7 @@
994     #include <linux/seq_file.h>
995     #include <linux/netfilter.h>
996     #include <linux/netfilter_ipv4.h>
997    +#include <linux/ccsecurity.h>
998    
999     struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE];
1000     DEFINE_RWLOCK(raw_v4_lock);
1001    @@ -591,6 +592,9 @@ static int raw_recvmsg(struct kiocb *ioc
1002            skb = skb_recv_datagram(sk, flags, noblock, &err);
1003            if (!skb)
1004                    goto out;
1005    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1006    +       if (err)
1007    +               goto out;
1008    
1009            copied = skb->len;
1010            if (len < copied) {
1011    --- linux-2.6.15-54.77.orig/net/ipv4/tcp_ipv4.c
1012    +++ linux-2.6.15-54.77/net/ipv4/tcp_ipv4.c
1013    @@ -76,6 +76,7 @@
1014   #include <linux/stddef.h>   #include <linux/stddef.h>
1015   #include <linux/proc_fs.h>   #include <linux/proc_fs.h>
1016   #include <linux/seq_file.h>   #include <linux/seq_file.h>
1017  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1018    
1019   int sysctl_tcp_tw_reuse;   int sysctl_tcp_tw_reuse;
1020   int sysctl_tcp_low_latency;   int sysctl_tcp_low_latency;
1021  @@ -243,6 +246,10 @@ static inline int tcp_v4_hash_connect(st  @@ -243,6 +244,8 @@ static inline int tcp_v4_hash_connect(st
1022                  local_bh_disable();                  local_bh_disable();
1023                  for (i = 1; i <= range; i++) {                  for (i = 1; i <= range; i++) {
1024                          port = low + (i + offset) % range;                          port = low + (i + offset) % range;
1025  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(port))
 +                       if (ccs_may_autobind(port))  
1026  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1027                          head = &tcp_hashinfo.bhash[inet_bhashfn(port, tcp_hashinfo.bhash_size)];                          head = &tcp_hashinfo.bhash[inet_bhashfn(port, tcp_hashinfo.bhash_size)];
1028                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1029    
1030  --- linux-2.6.15-53.75.orig/net/ipv4/udp.c  --- linux-2.6.15-54.77.orig/net/ipv4/udp.c
1031  +++ linux-2.6.15-53.75/net/ipv4/udp.c  +++ linux-2.6.15-54.77/net/ipv4/udp.c
1032  @@ -108,6 +108,9 @@  @@ -108,6 +108,7 @@
1033   #include <net/inet_common.h>   #include <net/inet_common.h>
1034   #include <net/checksum.h>   #include <net/checksum.h>
1035   #include <net/xfrm.h>   #include <net/xfrm.h>
1036  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1037    
1038   /*   /*
1039    *     Snmp MIB for the UDP layer    *     Snmp MIB for the UDP layer
1040  @@ -146,6 +149,10 @@ static int udp_v4_get_port(struct sock *  @@ -146,6 +147,8 @@ static int udp_v4_get_port(struct sock *
1041                                          result = sysctl_local_port_range[0] +                                          result = sysctl_local_port_range[0] +
1042                                                  ((result - sysctl_local_port_range[0]) &                                                  ((result - sysctl_local_port_range[0]) &
1043                                                   (UDP_HTABLE_SIZE - 1));                                                   (UDP_HTABLE_SIZE - 1));
1044  +                               /***** SAKURA Linux start. *****/  +                               if (ccs_lport_reserved(result))
 +                               if (ccs_may_autobind(result))  
1045  +                                       continue;  +                                       continue;
 +                               /***** SAKURA Linux end. *****/  
1046                                  goto gotit;                                  goto gotit;
1047                          }                          }
1048                          size = 0;                          size = 0;
1049  @@ -162,6 +169,10 @@ static int udp_v4_get_port(struct sock *  @@ -162,6 +165,8 @@ static int udp_v4_get_port(struct sock *
1050                                  result = sysctl_local_port_range[0]                                  result = sysctl_local_port_range[0]
1051                                          + ((result - sysctl_local_port_range[0]) &                                          + ((result - sysctl_local_port_range[0]) &
1052                                             (UDP_HTABLE_SIZE - 1));                                             (UDP_HTABLE_SIZE - 1));
1053  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(result))
 +                       if (ccs_may_autobind(result))  
1054  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1055                          if (!udp_lport_inuse(result))                          if (!udp_lport_inuse(result))
1056                                  break;                                  break;
1057                  }                  }
1058  --- linux-2.6.15-53.75.orig/net/ipv6/tcp_ipv6.c  @@ -796,7 +801,10 @@ try_again:
1059  +++ linux-2.6.15-53.75/net/ipv6/tcp_ipv6.c          skb = skb_recv_datagram(sk, flags, noblock, &err);
1060  @@ -64,6 +64,9 @@          if (!skb)
1061                    goto out;
1062    -  
1063    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1064    +       if (err)
1065    +               goto out;
1066    +
1067            copied = skb->len - sizeof(struct udphdr);
1068            if (copied > len) {
1069                    copied = len;
1070    --- linux-2.6.15-54.77.orig/net/ipv6/raw.c
1071    +++ linux-2.6.15-54.77/net/ipv6/raw.c
1072    @@ -56,6 +56,7 @@
1073    
1074     #include <linux/proc_fs.h>
1075     #include <linux/seq_file.h>
1076    +#include <linux/ccsecurity.h>
1077    
1078     struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE];
1079     DEFINE_RWLOCK(raw_v6_lock);
1080    @@ -387,6 +388,9 @@ static int rawv6_recvmsg(struct kiocb *i
1081            skb = skb_recv_datagram(sk, flags, noblock, &err);
1082            if (!skb)
1083                    goto out;
1084    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1085    +       if (err)
1086    +               goto out;
1087    
1088            copied = skb->len;
1089            if (copied > len) {
1090    --- linux-2.6.15-54.77.orig/net/ipv6/tcp_ipv6.c
1091    +++ linux-2.6.15-54.77/net/ipv6/tcp_ipv6.c
1092    @@ -64,6 +64,7 @@
1093    
1094   #include <linux/proc_fs.h>   #include <linux/proc_fs.h>
1095   #include <linux/seq_file.h>   #include <linux/seq_file.h>
1096  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1097    
1098   static void    tcp_v6_send_reset(struct sk_buff *skb);   static void    tcp_v6_send_reset(struct sk_buff *skb);
1099   static void    tcp_v6_reqsk_send_ack(struct sk_buff *skb, struct request_sock *req);   static void    tcp_v6_reqsk_send_ack(struct sk_buff *skb, struct request_sock *req);
1100  @@ -119,6 +122,10 @@ static int tcp_v6_get_port(struct sock *  @@ -119,6 +120,8 @@ static int tcp_v6_get_port(struct sock *
1101                  do {                  do {
1102                          head = &tcp_hashinfo.bhash[inet_bhashfn(rover, tcp_hashinfo.bhash_size)];                          head = &tcp_hashinfo.bhash[inet_bhashfn(rover, tcp_hashinfo.bhash_size)];
1103                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1104  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(rover))
 +                       if (ccs_may_autobind(rover))  
1105  +                               goto next;  +                               goto next;
 +                       /***** SAKURA Linux end. *****/  
1106                          inet_bind_bucket_for_each(tb, node, &head->chain)                          inet_bind_bucket_for_each(tb, node, &head->chain)
1107                                  if (tb->port == rover)                                  if (tb->port == rover)
1108                                          goto next;                                          goto next;
1109  @@ -419,6 +426,10 @@ static int tcp_v6_hash_connect(struct so  @@ -419,6 +422,8 @@ static int tcp_v6_hash_connect(struct so
1110                  local_bh_disable();                  local_bh_disable();
1111                  for (i = 1; i <= range; i++) {                  for (i = 1; i <= range; i++) {
1112                          port = low + (i + offset) % range;                          port = low + (i + offset) % range;
1113  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(port))
 +                       if (ccs_may_autobind(port))  
1114  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1115                          head = &tcp_hashinfo.bhash[inet_bhashfn(port, tcp_hashinfo.bhash_size)];                          head = &tcp_hashinfo.bhash[inet_bhashfn(port, tcp_hashinfo.bhash_size)];
1116                          spin_lock(&head->lock);                          spin_lock(&head->lock);
1117    
1118  --- linux-2.6.15-53.75.orig/net/ipv6/udp.c  --- linux-2.6.15-54.77.orig/net/ipv6/udp.c
1119  +++ linux-2.6.15-53.75/net/ipv6/udp.c  +++ linux-2.6.15-54.77/net/ipv6/udp.c
1120  @@ -58,6 +58,9 @@  @@ -58,6 +58,7 @@
1121    
1122   #include <linux/proc_fs.h>   #include <linux/proc_fs.h>
1123   #include <linux/seq_file.h>   #include <linux/seq_file.h>
1124  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1125    
1126   DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;   DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
1127    
1128  @@ -88,6 +91,10 @@ static int udp_v6_get_port(struct sock *  @@ -88,6 +89,8 @@ static int udp_v6_get_port(struct sock *
1129                                          result = sysctl_local_port_range[0] +                                          result = sysctl_local_port_range[0] +
1130                                                  ((result - sysctl_local_port_range[0]) &                                                  ((result - sysctl_local_port_range[0]) &
1131                                                   (UDP_HTABLE_SIZE - 1));                                                   (UDP_HTABLE_SIZE - 1));
1132  +                               /***** SAKURA Linux start. *****/  +                               if (ccs_lport_reserved(result))
 +                               if (ccs_may_autobind(result))  
1133  +                                       continue;  +                                       continue;
 +                               /***** SAKURA Linux end. *****/  
1134                                  goto gotit;                                  goto gotit;
1135                          }                          }
1136                          size = 0;                          size = 0;
1137  @@ -104,6 +111,10 @@ static int udp_v6_get_port(struct sock *  @@ -104,6 +107,8 @@ static int udp_v6_get_port(struct sock *
1138                                  result = sysctl_local_port_range[0]                                  result = sysctl_local_port_range[0]
1139                                          + ((result - sysctl_local_port_range[0]) &                                          + ((result - sysctl_local_port_range[0]) &
1140                                             (UDP_HTABLE_SIZE - 1));                                             (UDP_HTABLE_SIZE - 1));
1141  +                       /***** SAKURA Linux start. *****/  +                       if (ccs_lport_reserved(result))
 +                       if (ccs_may_autobind(result))  
1142  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1143                          if (!udp_lport_inuse(result))                          if (!udp_lport_inuse(result))
1144                                  break;                                  break;
1145                  }                  }
1146  --- linux-2.6.15-53.75.orig/net/socket.c  @@ -237,6 +242,9 @@ try_again:
1147  +++ linux-2.6.15-53.75/net/socket.c          skb = skb_recv_datagram(sk, flags, noblock, &err);
1148  @@ -97,6 +97,11 @@          if (!skb)
1149                    goto out;
1150    +       err = ccs_socket_recvmsg_permission(sk, skb, flags);
1151    +       if (err)
1152    +               goto out;
1153    
1154            copied = skb->len - sizeof(struct udphdr);
1155            if (copied > len) {
1156    --- linux-2.6.15-54.77.orig/net/socket.c
1157    +++ linux-2.6.15-54.77/net/socket.c
1158    @@ -97,6 +97,8 @@
1159   #include <net/sock.h>   #include <net/sock.h>
1160   #include <linux/netfilter.h>   #include <linux/netfilter.h>
1161    
1162  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +#include <linux/tomoyo_socket.h>  
 +/***** TOMOYO Linux end. *****/  
1163  +  +
1164   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
1165   static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf,   static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf,
1166                           size_t size, loff_t pos);                           size_t size, loff_t pos);
1167  @@ -546,7 +551,12 @@ static inline int __sock_sendmsg(struct  @@ -544,9 +546,12 @@ static inline int __sock_sendmsg(struct
1168            si->size = size;
1169    
1170          err = security_socket_sendmsg(sock, msg, size);          err = security_socket_sendmsg(sock, msg, size);
1171    +       if (!err)
1172    +               err = ccs_socket_sendmsg_permission(sock, (struct sockaddr *)
1173    +                                                   msg->msg_name,
1174    +                                                   msg->msg_namelen);
1175          if (err)          if (err)
1176                  return err;                  return err;
1177  -  -
 +       /***** TOMOYO Linux start. *****/  
 +       if (ccs_socket_sendmsg_permission(sock,  
 +                                         (struct sockaddr *) msg->msg_name,  
 +                                         msg->msg_namelen))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
1178          return sock->ops->sendmsg(iocb, sock, msg, size);          return sock->ops->sendmsg(iocb, sock, msg, size);
1179   }   }
1180    
1181  @@ -1099,6 +1109,12 @@ static int __sock_create(int family, int  @@ -1100,6 +1105,8 @@ static int __sock_create(int family, int
                 family = PF_PACKET;  
1182          }          }
1183    
 +       /***** TOMOYO Linux start. *****/  
 +       err = ccs_socket_create_permission(family, type, protocol);  
 +       if (err)  
 +               return err;  
 +       /***** TOMOYO Linux end. *****/  
 +  
1184          err = security_socket_create(family, type, protocol, kern);          err = security_socket_create(family, type, protocol, kern);
1185    +       if (!err)
1186    +               err = ccs_socket_create_permission(family, type, protocol);
1187          if (err)          if (err)
1188                  return err;                  return err;
1189  @@ -1296,6 +1312,12 @@ asmlinkage long sys_bind(int fd, struct                  
1190    @@ -1297,6 +1304,10 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
1191                                  sockfd_put(sock);                                  sockfd_put(sock);
1192                                  return err;                                  return err;
1193                          }                          }
 +                       /***** TOMOYO Linux start. *****/  
1194  +                       err = ccs_socket_bind_permission(sock,  +                       err = ccs_socket_bind_permission(sock,
1195  +                                                        (struct sockaddr *)  +                                                        (struct sockaddr *)
1196  +                                                        address, addrlen);  +                                                        address, addrlen);
1197  +                       if (!err)  +                       if (!err)
 +                       /***** TOMOYO Linux end. *****/  
1198                          err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);                          err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);
1199                  }                  }
1200                  sockfd_put(sock);                  sockfd_put(sock);
1201  @@ -1326,7 +1348,10 @@ asmlinkage long sys_listen(int fd, int b  @@ -1327,7 +1338,8 @@ SYSCALL_DEFINE2(listen, int, fd, int, ba
1202                          sockfd_put(sock);                          sockfd_put(sock);
1203                          return err;                          return err;
1204                  }                  }
1205  -  -
 +               /***** TOMOYO Linux start. *****/  
1206  +               err = ccs_socket_listen_permission(sock);  +               err = ccs_socket_listen_permission(sock);
1207  +               if (!err)  +               if (!err)
 +               /***** TOMOYO Linux end. *****/  
1208                  err=sock->ops->listen(sock, backlog);                  err=sock->ops->listen(sock, backlog);
1209                  sockfd_put(sock);                  sockfd_put(sock);
1210          }          }
1211  @@ -1377,6 +1402,13 @@ asmlinkage long sys_accept(int fd, struc  @@ -1379,6 +1391,11 @@ SYSCALL_DEFINE3(accept, int, fd, struct
1212          if (err < 0)          if (err < 0)
1213                  goto out_release;                  goto out_release;
1214    
 +       /***** TOMOYO Linux start. *****/  
1215  +       if (ccs_socket_accept_permission(newsock,  +       if (ccs_socket_accept_permission(newsock,
1216  +                                        (struct sockaddr *) address)) {  +                                        (struct sockaddr *) address)) {
1217  +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */  +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */
1218  +               goto out_release;  +               goto out_release;
1219  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
1220          if (upeer_sockaddr) {          if (upeer_sockaddr) {
1221                  if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {                  if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {
1222                          err = -ECONNABORTED;                          err = -ECONNABORTED;
1223  @@ -1432,7 +1464,12 @@ asmlinkage long sys_connect(int fd, stru  @@ -1433,9 +1450,11 @@ SYSCALL_DEFINE3(connect, int, fd, struct
1224                    goto out_put;
1225    
1226          err = security_socket_connect(sock, (struct sockaddr *)address, addrlen);          err = security_socket_connect(sock, (struct sockaddr *)address, addrlen);
1227    +       if (!err)
1228    +               err = ccs_socket_connect_permission(sock, (struct sockaddr *)
1229    +                                                   address, addrlen);
1230          if (err)          if (err)
1231                  goto out_put;                  goto out_put;
1232  -  -
 +       /***** TOMOYO Linux start. *****/  
 +       err = ccs_socket_connect_permission(sock, (struct sockaddr *) address,  
 +                                           addrlen);  
 +       if (err)  
 +               goto out_put;  
 +       /***** TOMOYO Linux end. *****/  
1233          err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,          err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,
1234                                   sock->file->f_flags);                                   sock->file->f_flags);
1235   out_put:   out_put:
1236  --- linux-2.6.15-53.75.orig/net/unix/af_unix.c  --- linux-2.6.15-54.77.orig/net/unix/af_unix.c
1237  +++ linux-2.6.15-53.75/net/unix/af_unix.c  +++ linux-2.6.15-54.77/net/unix/af_unix.c
1238  @@ -117,6 +117,9 @@  @@ -117,6 +117,7 @@
1239   #include <linux/mount.h>   #include <linux/mount.h>
1240   #include <net/checksum.h>   #include <net/checksum.h>
1241   #include <linux/security.h>   #include <linux/security.h>
1242  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
1243    
1244   int sysctl_unix_max_dgram_qlen = 10;   int sysctl_unix_max_dgram_qlen = 10;
1245    
1246  @@ -781,6 +784,11 @@ static int unix_bind(struct socket *sock  @@ -781,6 +782,9 @@ static int unix_bind(struct socket *sock
1247                   */                   */
1248                  mode = S_IFSOCK |                  mode = S_IFSOCK |
1249                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);                         (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
 +               /***** TOMOYO Linux start. *****/  
1250  +               err = ccs_check_mknod_permission(nd.dentry->d_inode, dentry,  +               err = ccs_check_mknod_permission(nd.dentry->d_inode, dentry,
1251  +                                                nd.mnt, mode, 0);  +                                                nd.mnt, mode, 0);
1252  +               if (!err)  +               if (!err)
 +               /***** TOMOYO Linux end. *****/  
1253                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
1254                  if (err)                  if (err)
1255                          goto out_mknod_dput;                          goto out_mknod_dput;
1256    --- linux-2.6.15-54.77.orig/security/Kconfig
1257    +++ linux-2.6.15-54.77/security/Kconfig
1258    @@ -94,5 +94,7 @@ config SECURITY_SECLVL
1259    
1260     source security/selinux/Kconfig
1261    
1262    +source security/ccsecurity/Kconfig
1263    +
1264     endmenu
1265    
1266    --- linux-2.6.15-54.77.orig/security/Makefile
1267    +++ linux-2.6.15-54.77/security/Makefile
1268    @@ -19,3 +19,6 @@ obj-$(CONFIG_SECURITY_ROOTPLUG)               += comm
1269     obj-$(CONFIG_SECURITY_REALTIME)                += commoncap.o realcap.o
1270    
1271     obj-$(CONFIG_SECURITY_SECLVL)          += seclvl.o
1272    +
1273    +subdir-$(CONFIG_CCSECURITY)+= ccsecurity
1274    +obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o

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

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