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

Subversion リポジトリの参照

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

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

trunk/1.6.x/ccs-patch/patches/ccs-patch-2.4.37.diff revision 2781 by kumaneko, Mon Jul 20 05:40:07 2009 UTC branches/ccs-patch/patches/ccs-patch-2.4.37.diff revision 3856 by kumaneko, Mon Jul 26 06:55:22 2010 UTC
# Line 1  Line 1 
1  This is TOMOYO Linux patch for kernel 2.4.37.3.  This is TOMOYO Linux patch for kernel 2.4.37.9.
2    
3  Source code for this patch is http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.37.3.tar.bz2  Source code for this patch is http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.37.9.tar.bz2
4  ---  ---
5   Documentation/Configure.help |   86 +++++++++++++++++++++++++++++++++++++++++++   Makefile                     |    8 ++++++++
6   arch/alpha/kernel/ptrace.c   |    7 +++   arch/alpha/kernel/ptrace.c   |    3 +++
7   arch/arm/kernel/ptrace.c     |    7 +++   arch/arm/kernel/ptrace.c     |    3 +++
8   arch/cris/kernel/ptrace.c    |    7 +++   arch/cris/kernel/ptrace.c    |    3 +++
9   arch/i386/kernel/ptrace.c    |    7 +++   arch/i386/kernel/ptrace.c    |    3 +++
10   arch/ia64/ia32/sys_ia32.c    |    7 +++   arch/ia64/ia32/sys_ia32.c    |    3 +++
11   arch/ia64/kernel/ptrace.c    |    7 +++   arch/ia64/kernel/ptrace.c    |    3 +++
12   arch/m68k/kernel/ptrace.c    |    7 +++   arch/m68k/kernel/ptrace.c    |    3 +++
13   arch/mips/kernel/ptrace.c    |    7 +++   arch/mips/kernel/ptrace.c    |    3 +++
14   arch/mips64/kernel/ptrace.c  |   11 +++++   arch/mips64/kernel/ptrace.c  |    5 +++++
15   arch/parisc/kernel/ptrace.c  |    7 +++   arch/parisc/kernel/ptrace.c  |    3 +++
16   arch/ppc/kernel/ptrace.c     |    7 +++   arch/ppc/kernel/ptrace.c     |    3 +++
17   arch/ppc64/kernel/ptrace.c   |    7 +++   arch/ppc64/kernel/ptrace.c   |    3 +++
18   arch/ppc64/kernel/ptrace32.c |    7 +++   arch/ppc64/kernel/ptrace32.c |    3 +++
19   arch/s390/kernel/ptrace.c    |    7 +++   arch/s390/kernel/ptrace.c    |    3 +++
20   arch/s390x/kernel/ptrace.c   |    7 +++   arch/s390x/kernel/ptrace.c   |    3 +++
21   arch/sh/kernel/ptrace.c      |    7 +++   arch/sh/kernel/ptrace.c      |    3 +++
22   arch/sh64/kernel/ptrace.c    |    7 +++   arch/sh64/kernel/ptrace.c    |    3 +++
23   arch/sparc/kernel/ptrace.c   |    9 ++++   arch/sparc/kernel/ptrace.c   |    5 +++++
24   arch/sparc64/kernel/ptrace.c |    9 ++++   arch/sparc64/kernel/ptrace.c |    5 +++++
25   arch/x86_64/ia32/ptrace32.c  |    7 +++   arch/x86_64/ia32/ptrace32.c  |    3 +++
26   arch/x86_64/kernel/ptrace.c  |    7 +++   arch/x86_64/kernel/ptrace.c  |    3 +++
27   fs/Config.in                 |    3 +   fs/Config.in                 |    3 +++
28   fs/Makefile                  |    2 -   fs/exec.c                    |   12 +++++++++++-
29   fs/attr.c                    |   10 +++++   fs/fcntl.c                   |    4 ++++
30   fs/exec.c                    |   18 ++++++++-   fs/ioctl.c                   |    6 ++++++
31   fs/fcntl.c                   |    8 ++++   fs/namei.c                   |   39 +++++++++++++++++++++++++++++++++++++++
32   fs/ioctl.c                   |   16 ++++++++   fs/namespace.c               |   17 +++++++++++++++++
33   fs/namei.c                   |   71 +++++++++++++++++++++++++++++++++++   fs/open.c                    |   27 +++++++++++++++++++++++++++
34   fs/namespace.c               |   58 ++++++++++++++++++++++++++++-   fs/proc/proc_misc.c          |    1 +
35   fs/open.c                    |   30 +++++++++++++++   include/linux/sched.h        |   14 ++++++++++++++
36   fs/proc/Makefile             |    4 ++   kernel/kmod.c                |    5 +++++
37   fs/proc/proc_misc.c          |    5 ++   kernel/module.c              |    7 +++++++
38   include/linux/sched.h        |   12 ++++++   kernel/sched.c               |    3 +++
39   kernel/kmod.c                |    5 ++   kernel/signal.c              |    7 +++++++
40   kernel/module.c              |   15 +++++++   kernel/sys.c                 |    9 +++++++++
41   kernel/sched.c               |    7 +++   kernel/sysctl.c              |   13 ++++++++++++-
42   kernel/signal.c              |   15 +++++++   kernel/time.c                |    7 +++++++
43   kernel/sys.c                 |   19 +++++++++   net/ipv4/raw.c               |   12 +++++++++---
44   kernel/sysctl.c              |   19 +++++++++   net/ipv4/tcp_ipv4.c          |    5 +++++
45   kernel/time.c                |   15 +++++++   net/ipv4/udp.c               |   14 +++++++++++++-
46   net/ipv4/raw.c               |    8 ++++   net/ipv6/raw.c               |   12 +++++++++---
47   net/ipv4/tcp_ipv4.c          |   11 +++++   net/ipv6/tcp_ipv6.c          |    3 +++
48   net/ipv4/udp.c               |   19 +++++++++   net/ipv6/udp.c               |   14 +++++++++++++-
49   net/ipv6/raw.c               |    8 ++++   net/socket.c                 |   23 +++++++++++++++++++++--
50   net/ipv6/tcp_ipv6.c          |    7 +++   net/unix/af_unix.c           |    4 ++++
51   net/ipv6/udp.c               |   19 +++++++++   46 files changed, 326 insertions(+), 12 deletions(-)
  net/socket.c                 |   40 +++++++++++++++++++-  
  net/unix/af_unix.c           |    8 ++++  
  49 files changed, 687 insertions(+), 6 deletions(-)  
52    
53  --- linux-2.4.37.3.orig/Documentation/Configure.help  --- linux-2.4.37.9.orig/Makefile
54  +++ linux-2.4.37.3/Documentation/Configure.help  +++ linux-2.4.37.9/Makefile
55  @@ -29158,6 +29158,92 @@ CONFIG_SOUND_WM97XX  @@ -139,6 +139,14 @@ NETWORKS   =net/network.o
56      
57     If unsure, say N.   LIBS           =$(TOPDIR)/lib/lib.a
58     SUBDIRS                =kernel drivers mm fs net ipc lib crypto
59  +CONFIG_SAKURA  +ifdef CONFIG_CCSECURITY
60  +  Say Y here to support the Domain-Free Mandatory Access Control.  +SUBDIRS += security/ccsecurity
61  +  +ifdef CONFIG_CCSECURITY_LKM
62  +  SAKURA stands for  +CORE_FILES += security/ccsecurity/load_policy.o
63  +  "Security Advancement Know-how Upon Read-only Approach".  +else
64  +  As the name shows, SAKURA was originally a methodology to make  +CORE_FILES += security/ccsecurity/ccsecurity.o
65  +  root fs read-only to avoid tampering the system files.  +endif
66  +  But now, SAKURA is not only a methodology but also a kernel patch  +endif
67  +  that improves the system security with less effort.  
68  +   DRIVERS-n :=
69  +  SAKURA can restrict operations that affect systemwide.   DRIVERS-y :=
70  +  --- linux-2.4.37.9.orig/arch/alpha/kernel/ptrace.c
71  +CONFIG_TOMOYO  +++ linux-2.4.37.9/arch/alpha/kernel/ptrace.c
72  +  Say Y here to support the Domain-Based Mandatory Access Control.  @@ -18,6 +18,7 @@
 +  
 +  TOMOYO stands for "Task Oriented Management Obviates Your Onus".  
 +  TOMOYO is intended to provide the Domain-Based MAC  
 +  utilizing task_struct.  
 +  
 +  The word "domain" in TOMOYO is a class that a process  
 +  (i.e. task_struct) belong to.  
 +  The domain of a process changes whenever the process  
 +  executes a program.  
 +  This allows you to classify at the finest level.  
 +  The access permission is granted to domains, not to processes.  
 +  Policy is defined as "Which domain can access to which resource.".  
 +  
 +  The biggest feature of TOMOYO is that TOMOYO has "learning mode".  
 +  The learning mode can automatically generate policy definition,  
 +  and dramatically reduces the policy definition labors.  
 +  
 +  TOMOYO is applicable to figuring out the system's behavior, for  
 +  TOMOYO uses the canonicalized absolute pathnames and  
 +  TreeView style domain transitions.  
 +  
 +  You can make custom root fs with minimum files  
 +  to run minimum applications with TOMOYO.  
 +  
 +CONFIG_TOMOYO_MAX_ACCEPT_ENTRY  
 +  This is the default value for maximal ACL entries  
 +  that are automatically appended into policy at "learning mode".  
 +  Some programs access thousands of objects, so running  
 +  such programs in "learning mode" dulls the system response  
 +  and consumes much memory.  
 +  This is the safeguard for such programs.  
 +  
 +CONFIG_TOMOYO_MAX_GRANT_LOG  
 +  This is the default value for maximal entries for  
 +  access grant logs that the kernel can hold on memory.  
 +  You can read the log via /proc/ccs/grant_log.  
 +  If you don't need access grant logs,  
 +  you may set this value to 0.  
 +  
 +CONFIG_TOMOYO_MAX_REJECT_LOG  
 +  This is the default value for maximal entries for  
 +  access reject logs that the kernel can hold on memory.  
 +  You can read the log via /proc/ccs/reject_log.  
 +  If you don't need access reject logs,  
 +  you may set this value to 0.  
 +  
 +CONFIG_SYAORAN  
 +  Say Y or M here to support the Tamper-Proof Device Filesystem.  
 +  
 +  SYAORAN stands for  
 +  "Simple Yet All-important Object Realizing Abiding Nexus".  
 +  SYAORAN is a filesystem for /dev with Mandatory Access Control.  
 +  
 +  SAKURA can make root fs read-only, but the system can't work  
 +  if /dev is read-only. Therefore you need to mount a writable  
 +  filesystem (such as tmpfs) for /dev if root fs is read-only.  
 +  
 +  But the writable /dev means that files on /dev might be tampered.  
 +  For example, if /dev/null is deleted and re-created as a symbolic  
 +  link to /dev/hda by an attacker, the contents of the IDE HDD  
 +  will be destroyed at a blow.  
 +  
 +  Also, TOMOYO controls file access by pathnames,  
 +  not by security labels.  
 +  Therefore /dev/null, for example, might be tampered  
 +  if a process have write permission to /dev/null .  
 +  
 +  SYAORAN can ensure /dev/null is a character device file  
 +  with major=1 minor=3.  
 +  
 +  You can use SAKURA to make /dev not unmountable.  
 +  
  #  
  # A couple of things I keep forgetting:  
  #   capitalize: AppleTalk, Ethernet, DOS, DMA, FAT, FTP, Internet,  
 --- linux-2.4.37.3.orig/arch/alpha/kernel/ptrace.c  
 +++ linux-2.4.37.3/arch/alpha/kernel/ptrace.c  
 @@ -18,6 +18,9 @@  
73   #include <asm/pgtable.h>   #include <asm/pgtable.h>
74   #include <asm/system.h>   #include <asm/system.h>
75   #include <asm/fpu.h>   #include <asm/fpu.h>
76  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
77    
78   #include "proto.h"   #include "proto.h"
79    
80  @@ -251,6 +254,10 @@ sys_ptrace(long request, long pid, long  @@ -251,6 +252,8 @@ sys_ptrace(long request, long pid, long
81   {   {
82          struct task_struct *child;          struct task_struct *child;
83          long ret;          long ret;
84  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
85  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
86    
87          lock_kernel();          lock_kernel();
88          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",
89  --- linux-2.4.37.3.orig/arch/arm/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/arm/kernel/ptrace.c
90  +++ linux-2.4.37.3/arch/arm/kernel/ptrace.c  +++ linux-2.4.37.9/arch/arm/kernel/ptrace.c
91  @@ -22,6 +22,9 @@  @@ -22,6 +22,7 @@
92   #include <asm/uaccess.h>   #include <asm/uaccess.h>
93   #include <asm/pgtable.h>   #include <asm/pgtable.h>
94   #include <asm/system.h>   #include <asm/system.h>
95  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
96    
97   #include "ptrace.h"   #include "ptrace.h"
98    
99  @@ -695,6 +698,10 @@ asmlinkage int sys_ptrace(long request,  @@ -695,6 +696,8 @@ asmlinkage int sys_ptrace(long request,
100   {   {
101          struct task_struct *child;          struct task_struct *child;
102          int ret;          int ret;
103  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
104  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
105    
106          lock_kernel();          lock_kernel();
107          ret = -EPERM;          ret = -EPERM;
108  --- linux-2.4.37.3.orig/arch/cris/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/cris/kernel/ptrace.c
109  +++ linux-2.4.37.3/arch/cris/kernel/ptrace.c  +++ linux-2.4.37.9/arch/cris/kernel/ptrace.c
110  @@ -48,6 +48,9 @@  @@ -48,6 +48,7 @@
111   #include <asm/pgtable.h>   #include <asm/pgtable.h>
112   #include <asm/system.h>   #include <asm/system.h>
113   #include <asm/processor.h>   #include <asm/processor.h>
114  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
115    
116   /*   /*
117    * does not yet catch signals sent when the child dies.    * does not yet catch signals sent when the child dies.
118  @@ -104,6 +107,10 @@ asmlinkage int sys_ptrace(long request,  @@ -104,6 +105,8 @@ asmlinkage int sys_ptrace(long request,
119   {   {
120          struct task_struct *child;          struct task_struct *child;
121          int ret;          int ret;
122  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
123  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
124    
125          lock_kernel();          lock_kernel();
126          ret = -EPERM;          ret = -EPERM;
127  --- linux-2.4.37.3.orig/arch/i386/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/i386/kernel/ptrace.c
128  +++ linux-2.4.37.3/arch/i386/kernel/ptrace.c  +++ linux-2.4.37.9/arch/i386/kernel/ptrace.c
129  @@ -20,6 +20,9 @@  @@ -20,6 +20,7 @@
130   #include <asm/processor.h>   #include <asm/processor.h>
131   #include <asm/i387.h>   #include <asm/i387.h>
132   #include <asm/debugreg.h>   #include <asm/debugreg.h>
133  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
134    
135   /*   /*
136    * does not yet catch signals sent when the child dies.    * does not yet catch signals sent when the child dies.
137  @@ -152,6 +155,10 @@ asmlinkage int sys_ptrace(long request,  @@ -152,6 +153,8 @@ asmlinkage int sys_ptrace(long request,
138          struct task_struct *child;          struct task_struct *child;
139          struct user * dummy = NULL;          struct user * dummy = NULL;
140          int i, ret;          int i, ret;
141  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
142  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
143    
144          lock_kernel();          lock_kernel();
145          ret = -EPERM;          ret = -EPERM;
146  --- linux-2.4.37.3.orig/arch/ia64/ia32/sys_ia32.c  --- linux-2.4.37.9.orig/arch/ia64/ia32/sys_ia32.c
147  +++ linux-2.4.37.3/arch/ia64/ia32/sys_ia32.c  +++ linux-2.4.37.9/arch/ia64/ia32/sys_ia32.c
148  @@ -57,6 +57,9 @@  @@ -57,6 +57,7 @@
149   #include <net/scm.h>   #include <net/scm.h>
150   #include <net/sock.h>   #include <net/sock.h>
151   #include <asm/ia32.h>   #include <asm/ia32.h>
152  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
153    
154   #define DEBUG  0   #define DEBUG  0
155    
156  @@ -3131,6 +3134,10 @@ sys32_ptrace (int request, pid_t pid, un  @@ -3131,6 +3132,8 @@ sys32_ptrace (int request, pid_t pid, un
157          struct task_struct *child;          struct task_struct *child;
158          unsigned int value, tmp;          unsigned int value, tmp;
159          long i, ret;          long i, ret;
160  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
161  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
162    
163          lock_kernel();          lock_kernel();
164          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
165  --- linux-2.4.37.3.orig/arch/ia64/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/ia64/kernel/ptrace.c
166  +++ linux-2.4.37.3/arch/ia64/kernel/ptrace.c  +++ linux-2.4.37.9/arch/ia64/kernel/ptrace.c
167  @@ -27,6 +27,9 @@  @@ -27,6 +27,7 @@
168   #ifdef CONFIG_PERFMON   #ifdef CONFIG_PERFMON
169   #include <asm/perfmon.h>   #include <asm/perfmon.h>
170   #endif   #endif
171  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
172    
173   #define offsetof(type,field)    ((unsigned long) &((type *) 0)->field)   #define offsetof(type,field)    ((unsigned long) &((type *) 0)->field)
174    
175  @@ -1273,6 +1276,10 @@ sys_ptrace (long request, pid_t pid, uns  @@ -1273,6 +1274,8 @@ sys_ptrace (long request, pid_t pid, uns
176          struct task_struct *child;          struct task_struct *child;
177          struct switch_stack *sw;          struct switch_stack *sw;
178          long ret;          long ret;
179  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
180  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
181    
182          lock_kernel();          lock_kernel();
183          ret = -EPERM;          ret = -EPERM;
184  --- linux-2.4.37.3.orig/arch/m68k/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/m68k/kernel/ptrace.c
185  +++ linux-2.4.37.3/arch/m68k/kernel/ptrace.c  +++ linux-2.4.37.9/arch/m68k/kernel/ptrace.c
186  @@ -25,6 +25,9 @@  @@ -25,6 +25,7 @@
187   #include <asm/pgtable.h>   #include <asm/pgtable.h>
188   #include <asm/system.h>   #include <asm/system.h>
189   #include <asm/processor.h>   #include <asm/processor.h>
190  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
191    
192   /*   /*
193    * does not yet catch signals sent when the child dies.    * does not yet catch signals sent when the child dies.
194  @@ -104,6 +107,10 @@ asmlinkage int sys_ptrace(long request,  @@ -104,6 +105,8 @@ asmlinkage int sys_ptrace(long request,
195   {   {
196          struct task_struct *child;          struct task_struct *child;
197          int ret;          int ret;
198  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
199  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
200    
201          lock_kernel();          lock_kernel();
202          ret = -EPERM;          ret = -EPERM;
203  --- linux-2.4.37.3.orig/arch/mips/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/mips/kernel/ptrace.c
204  +++ linux-2.4.37.3/arch/mips/kernel/ptrace.c  +++ linux-2.4.37.9/arch/mips/kernel/ptrace.c
205  @@ -28,6 +28,9 @@  @@ -28,6 +28,7 @@
206   #include <asm/bootinfo.h>   #include <asm/bootinfo.h>
207   #include <asm/cpu.h>   #include <asm/cpu.h>
208   #include <asm/fpu.h>   #include <asm/fpu.h>
209  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
210    
211   /*   /*
212    * Called by kernel/ptrace.c when detaching..    * Called by kernel/ptrace.c when detaching..
213  @@ -43,6 +46,10 @@ asmlinkage int sys_ptrace(long request,  @@ -43,6 +44,8 @@ asmlinkage int sys_ptrace(long request,
214   {   {
215          struct task_struct *child;          struct task_struct *child;
216          int ret;          int ret;
217  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
218  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
219    
220          lock_kernel();          lock_kernel();
221   #if 0   #if 0
222  --- linux-2.4.37.3.orig/arch/mips64/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/mips64/kernel/ptrace.c
223  +++ linux-2.4.37.3/arch/mips64/kernel/ptrace.c  +++ linux-2.4.37.9/arch/mips64/kernel/ptrace.c
224  @@ -30,6 +30,9 @@  @@ -30,6 +30,7 @@
225   #include <asm/system.h>   #include <asm/system.h>
226   #include <asm/uaccess.h>   #include <asm/uaccess.h>
227   #include <asm/bootinfo.h>   #include <asm/bootinfo.h>
228  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
229    
230   /*   /*
231    * Called by kernel/ptrace.c when detaching..    * Called by kernel/ptrace.c when detaching..
232  @@ -49,6 +52,10 @@ asmlinkage int sys32_ptrace(int request,  @@ -49,6 +50,8 @@ asmlinkage int sys32_ptrace(int request,
233   {   {
234          struct task_struct *child;          struct task_struct *child;
235          int ret;          int ret;
236  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
237  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
238    
239          lock_kernel();          lock_kernel();
240          ret = -EPERM;          ret = -EPERM;
241  @@ -288,6 +295,10 @@ asmlinkage int sys_ptrace(long request,  @@ -288,6 +291,8 @@ asmlinkage int sys_ptrace(long request,
242   {   {
243          struct task_struct *child;          struct task_struct *child;
244          int ret;          int ret;
245  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
246  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
247    
248          lock_kernel();          lock_kernel();
249   #if 0   #if 0
250  --- linux-2.4.37.3.orig/arch/parisc/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/parisc/kernel/ptrace.c
251  +++ linux-2.4.37.3/arch/parisc/kernel/ptrace.c  +++ linux-2.4.37.9/arch/parisc/kernel/ptrace.c
252  @@ -21,6 +21,9 @@  @@ -21,6 +21,7 @@
253   #include <asm/system.h>   #include <asm/system.h>
254   #include <asm/processor.h>   #include <asm/processor.h>
255   #include <asm/offset.h>   #include <asm/offset.h>
256  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
257    
258   /* These are used in entry.S, syscall_restore_rfi.  We need to record the   /* These are used in entry.S, syscall_restore_rfi.  We need to record the
259    * current stepping mode somewhere other than in PSW, because there is no    * current stepping mode somewhere other than in PSW, because there is no
260  @@ -94,6 +97,10 @@ long sys_ptrace(long request, pid_t pid,  @@ -94,6 +95,8 @@ long sys_ptrace(long request, pid_t pid,
261   #ifdef DEBUG_PTRACE   #ifdef DEBUG_PTRACE
262          long oaddr=addr, odata=data;          long oaddr=addr, odata=data;
263   #endif   #endif
264  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
265  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
266    
267          lock_kernel();          lock_kernel();
268          ret = -EPERM;          ret = -EPERM;
269  --- linux-2.4.37.3.orig/arch/ppc/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/ppc/kernel/ptrace.c
270  +++ linux-2.4.37.3/arch/ppc/kernel/ptrace.c  +++ linux-2.4.37.9/arch/ppc/kernel/ptrace.c
271  @@ -29,6 +29,9 @@  @@ -29,6 +29,7 @@
272   #include <asm/page.h>   #include <asm/page.h>
273   #include <asm/pgtable.h>   #include <asm/pgtable.h>
274   #include <asm/system.h>   #include <asm/system.h>
275  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
276    
277   /*   /*
278    * Set of msr bits that gdb can change on behalf of a process.    * Set of msr bits that gdb can change on behalf of a process.
279  @@ -171,6 +174,10 @@ int sys_ptrace(long request, long pid, l  @@ -171,6 +172,8 @@ int sys_ptrace(long request, long pid, l
280   {   {
281          struct task_struct *child;          struct task_struct *child;
282          int ret = -EPERM;          int ret = -EPERM;
283  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
284  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
285    
286          lock_kernel();          lock_kernel();
287          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
288  --- linux-2.4.37.3.orig/arch/ppc64/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/ppc64/kernel/ptrace.c
289  +++ linux-2.4.37.3/arch/ppc64/kernel/ptrace.c  +++ linux-2.4.37.9/arch/ppc64/kernel/ptrace.c
290  @@ -30,6 +30,9 @@  @@ -30,6 +30,7 @@
291   #include <asm/page.h>   #include <asm/page.h>
292   #include <asm/pgtable.h>   #include <asm/pgtable.h>
293   #include <asm/system.h>   #include <asm/system.h>
294  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
295    
296   /*   /*
297    * Set of msr bits that gdb can change on behalf of a process.    * Set of msr bits that gdb can change on behalf of a process.
298  @@ -120,6 +123,10 @@ int sys_ptrace(long request, long pid, l  @@ -120,6 +121,8 @@ int sys_ptrace(long request, long pid, l
299   {   {
300          struct task_struct *child;          struct task_struct *child;
301          int ret = -EPERM;          int ret = -EPERM;
302  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
303  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
304    
305          lock_kernel();          lock_kernel();
306          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
307  --- linux-2.4.37.3.orig/arch/ppc64/kernel/ptrace32.c  --- linux-2.4.37.9.orig/arch/ppc64/kernel/ptrace32.c
308  +++ linux-2.4.37.3/arch/ppc64/kernel/ptrace32.c  +++ linux-2.4.37.9/arch/ppc64/kernel/ptrace32.c
309  @@ -30,6 +30,9 @@  @@ -30,6 +30,7 @@
310   #include <asm/page.h>   #include <asm/page.h>
311   #include <asm/pgtable.h>   #include <asm/pgtable.h>
312   #include <asm/system.h>   #include <asm/system.h>
313  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
314    
315   #ifdef CONFIG_ALTIVEC   #ifdef CONFIG_ALTIVEC
316   /*   /*
317  @@ -121,6 +124,10 @@ int sys32_ptrace(long request, long pid,  @@ -121,6 +122,8 @@ int sys32_ptrace(long request, long pid,
318   {   {
319          struct task_struct *child;          struct task_struct *child;
320          int ret = -EPERM;          int ret = -EPERM;
321  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
322  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
323    
324          lock_kernel();          lock_kernel();
325          if (request == PTRACE_TRACEME) {          if (request == PTRACE_TRACEME) {
326  --- linux-2.4.37.3.orig/arch/s390/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/s390/kernel/ptrace.c
327  +++ linux-2.4.37.3/arch/s390/kernel/ptrace.c  +++ linux-2.4.37.9/arch/s390/kernel/ptrace.c
328  @@ -37,6 +37,9 @@  @@ -37,6 +37,7 @@
329   #include <asm/pgalloc.h>   #include <asm/pgalloc.h>
330   #include <asm/system.h>   #include <asm/system.h>
331   #include <asm/uaccess.h>   #include <asm/uaccess.h>
332  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
333    
334    
335   void FixPerRegisters(struct task_struct *task)   void FixPerRegisters(struct task_struct *task)
336  @@ -221,6 +224,10 @@ asmlinkage int sys_ptrace(long request,  @@ -221,6 +222,8 @@ asmlinkage int sys_ptrace(long request,
337          unsigned long tmp;          unsigned long tmp;
338          int copied;          int copied;
339          ptrace_area   parea;          ptrace_area   parea;
340  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
341  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
342    
343          lock_kernel();          lock_kernel();
344          if (request == PTRACE_TRACEME)          if (request == PTRACE_TRACEME)
345  --- linux-2.4.37.3.orig/arch/s390x/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/s390x/kernel/ptrace.c
346  +++ linux-2.4.37.3/arch/s390x/kernel/ptrace.c  +++ linux-2.4.37.9/arch/s390x/kernel/ptrace.c
347  @@ -43,6 +43,9 @@  @@ -43,6 +43,7 @@
348   #else   #else
349   #define parent_31bit 0   #define parent_31bit 0
350   #endif   #endif
351  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
352    
353    
354   void FixPerRegisters(struct task_struct *task)   void FixPerRegisters(struct task_struct *task)
355  @@ -431,6 +434,10 @@ asmlinkage int sys_ptrace(long request,  @@ -431,6 +432,8 @@ asmlinkage int sys_ptrace(long request,
356   #define sizeof_parent_long 8   #define sizeof_parent_long 8
357   #define dataptr (u8 *)&data   #define dataptr (u8 *)&data
358   #endif   #endif
359  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
360  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
361          lock_kernel();          lock_kernel();
362          if (request == PTRACE_TRACEME)          if (request == PTRACE_TRACEME)
363          {          {
364  --- linux-2.4.37.3.orig/arch/sh/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/sh/kernel/ptrace.c
365  +++ linux-2.4.37.3/arch/sh/kernel/ptrace.c  +++ linux-2.4.37.9/arch/sh/kernel/ptrace.c
366  @@ -26,6 +26,9 @@  @@ -26,6 +26,7 @@
367   #include <asm/system.h>   #include <asm/system.h>
368   #include <asm/processor.h>   #include <asm/processor.h>
369   #include <asm/mmu_context.h>   #include <asm/mmu_context.h>
370  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
371    
372   /*   /*
373    * does not yet catch signals sent when the child dies.    * does not yet catch signals sent when the child dies.
374  @@ -144,6 +147,10 @@ asmlinkage int sys_ptrace(long request,  @@ -144,6 +145,8 @@ asmlinkage int sys_ptrace(long request,
375          struct task_struct *child, *tsk = current;          struct task_struct *child, *tsk = current;
376          struct user * dummy = NULL;          struct user * dummy = NULL;
377          int ret;          int ret;
378  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
379  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
380    
381          lock_kernel();          lock_kernel();
382          ret = -EPERM;          ret = -EPERM;
383  --- linux-2.4.37.3.orig/arch/sh64/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/sh64/kernel/ptrace.c
384  +++ linux-2.4.37.3/arch/sh64/kernel/ptrace.c  +++ linux-2.4.37.9/arch/sh64/kernel/ptrace.c
385  @@ -32,6 +32,9 @@  @@ -32,6 +32,7 @@
386   #include <asm/system.h>   #include <asm/system.h>
387   #include <asm/processor.h>   #include <asm/processor.h>
388   #include <asm/mmu_context.h>   #include <asm/mmu_context.h>
389  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
390    
391   /* This mask defines the bits of the SR which the user is not allowed to   /* This mask defines the bits of the SR which the user is not allowed to
392      change, which are everything except S, Q, M, PR, SZ, FR. */      change, which are everything except S, Q, M, PR, SZ, FR. */
393  @@ -122,6 +125,10 @@ asmlinkage int sys_ptrace(long request,  @@ -122,6 +123,8 @@ asmlinkage int sys_ptrace(long request,
394   {   {
395          struct task_struct *child, *tsk = current;          struct task_struct *child, *tsk = current;
396          int ret;          int ret;
397  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
398  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
399    
400          lock_kernel();          lock_kernel();
401          ret = -EPERM;          ret = -EPERM;
402  --- linux-2.4.37.3.orig/arch/sparc/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/sparc/kernel/ptrace.c
403  +++ linux-2.4.37.3/arch/sparc/kernel/ptrace.c  +++ linux-2.4.37.9/arch/sparc/kernel/ptrace.c
404  @@ -21,6 +21,9 @@  @@ -21,6 +21,7 @@
405   #include <asm/pgtable.h>   #include <asm/pgtable.h>
406   #include <asm/system.h>   #include <asm/system.h>
407   #include <asm/uaccess.h>   #include <asm/uaccess.h>
408  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
409    
410   #define MAGIC_CONSTANT 0x80000000   #define MAGIC_CONSTANT 0x80000000
411    
412  @@ -262,6 +265,12 @@ asmlinkage void do_ptrace(struct pt_regs  @@ -262,6 +263,10 @@ asmlinkage void do_ptrace(struct pt_regs
413          unsigned long data = regs->u_regs[UREG_I3];          unsigned long data = regs->u_regs[UREG_I3];
414          unsigned long addr2 = regs->u_regs[UREG_I4];          unsigned long addr2 = regs->u_regs[UREG_I4];
415          struct task_struct *child;          struct task_struct *child;
416  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid)) {
 +       if (!ccs_capable(CCS_SYS_PTRACE)) {  
417  +               pt_error_return(regs, EPERM);  +               pt_error_return(regs, EPERM);
418  +               return;  +               return;
419  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
420    
421          lock_kernel();          lock_kernel();
422   #ifdef DEBUG_PTRACE   #ifdef DEBUG_PTRACE
423  --- linux-2.4.37.3.orig/arch/sparc64/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/sparc64/kernel/ptrace.c
424  +++ linux-2.4.37.3/arch/sparc64/kernel/ptrace.c  +++ linux-2.4.37.9/arch/sparc64/kernel/ptrace.c
425  @@ -26,6 +26,9 @@  @@ -26,6 +26,7 @@
426   #include <asm/psrcompat.h>   #include <asm/psrcompat.h>
427   #include <asm/visasm.h>   #include <asm/visasm.h>
428   #include <asm/spitfire.h>   #include <asm/spitfire.h>
429  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
430    
431   #define MAGIC_CONSTANT 0x80000000   #define MAGIC_CONSTANT 0x80000000
432    
433  @@ -108,6 +111,12 @@ asmlinkage void do_ptrace(struct pt_regs  @@ -108,6 +109,10 @@ asmlinkage void do_ptrace(struct pt_regs
434          unsigned long data = regs->u_regs[UREG_I3];          unsigned long data = regs->u_regs[UREG_I3];
435          unsigned long addr2 = regs->u_regs[UREG_I4];          unsigned long addr2 = regs->u_regs[UREG_I4];
436          struct task_struct *child;          struct task_struct *child;
437  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid)) {
 +       if (!ccs_capable(CCS_SYS_PTRACE)) {  
438  +               pt_error_return(regs, EPERM);  +               pt_error_return(regs, EPERM);
439  +               return;  +               return;
440  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
441    
442          if (current->thread.flags & SPARC_FLAG_32BIT) {          if (current->thread.flags & SPARC_FLAG_32BIT) {
443                  addr &= 0xffffffffUL;                  addr &= 0xffffffffUL;
444  --- linux-2.4.37.3.orig/arch/x86_64/ia32/ptrace32.c  --- linux-2.4.37.9.orig/arch/x86_64/ia32/ptrace32.c
445  +++ linux-2.4.37.3/arch/x86_64/ia32/ptrace32.c  +++ linux-2.4.37.9/arch/x86_64/ia32/ptrace32.c
446  @@ -24,6 +24,9 @@  @@ -24,6 +24,7 @@
447   #include <asm/i387.h>   #include <asm/i387.h>
448   #include <asm/fpu32.h>   #include <asm/fpu32.h>
449   #include <linux/mm.h>   #include <linux/mm.h>
450  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
451    
452   /* determines which flags the user has access to. */   /* determines which flags the user has access to. */
453   /* 1 = access 0 = no access */   /* 1 = access 0 = no access */
454  @@ -203,6 +206,10 @@ asmlinkage long sys32_ptrace(long reques  @@ -203,6 +204,8 @@ asmlinkage long sys32_ptrace(long reques
455          struct pt_regs *childregs;          struct pt_regs *childregs;
456          int ret;          int ret;
457          __u32 val;          __u32 val;
458  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
459  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
460    
461          switch (request) {          switch (request) {
462          case PTRACE_TRACEME:          case PTRACE_TRACEME:
463  --- linux-2.4.37.3.orig/arch/x86_64/kernel/ptrace.c  --- linux-2.4.37.9.orig/arch/x86_64/kernel/ptrace.c
464  +++ linux-2.4.37.3/arch/x86_64/kernel/ptrace.c  +++ linux-2.4.37.9/arch/x86_64/kernel/ptrace.c
465  @@ -22,6 +22,9 @@  @@ -22,6 +22,7 @@
466   #include <asm/processor.h>   #include <asm/processor.h>
467   #include <asm/i387.h>   #include <asm/i387.h>
468   #include <asm/debugreg.h>   #include <asm/debugreg.h>
469  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
470    
471   /*   /*
472    * does not yet catch signals sent when the child dies.    * does not yet catch signals sent when the child dies.
473  @@ -180,6 +183,10 @@ asmlinkage long sys_ptrace(long request,  @@ -180,6 +181,8 @@ asmlinkage long sys_ptrace(long request,
474          struct task_struct *child;          struct task_struct *child;
475          struct user * dummy = NULL;          struct user * dummy = NULL;
476          long i, ret;          long i, ret;
477  +       /***** TOMOYO Linux start. *****/  +       if (ccs_ptrace_permission(request, pid))
 +       if (!ccs_capable(CCS_SYS_PTRACE))  
478  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
479    
480          /* This lock_kernel fixes a subtle race with suid exec */          /* This lock_kernel fixes a subtle race with suid exec */
481          lock_kernel();          lock_kernel();
482  --- linux-2.4.37.3.orig/fs/Config.in  --- linux-2.4.37.9.orig/fs/Config.in
483  +++ linux-2.4.37.3/fs/Config.in  +++ linux-2.4.37.9/fs/Config.in
484  @@ -176,4 +176,7 @@ comment 'Partition Types'  @@ -176,4 +176,7 @@ comment 'Partition Types'
485   source fs/partitions/Config.in   source fs/partitions/Config.in
486   endmenu   endmenu
487   source fs/nls/Config.in   source fs/nls/Config.in
488  +  +
 +source fs/Config.ccs.in  
 +  
489   endmenu   endmenu
490  --- linux-2.4.37.3.orig/fs/Makefile  +
491  +++ linux-2.4.37.3/fs/Makefile  +source security/ccsecurity/Config.in
492  @@ -80,5 +80,5 @@ obj-$(CONFIG_BINFMT_ELF)      += binfmt_elf.o  --- linux-2.4.37.9.orig/fs/exec.c
493   # persistent filesystems  +++ linux-2.4.37.9/fs/exec.c
494   obj-y += $(join $(subdir-y),$(subdir-y:%=/%.o))  @@ -48,6 +48,8 @@
   
 -  
 +include Makefile-2.4.ccs  
  include $(TOPDIR)/Rules.make  
 --- linux-2.4.37.3.orig/fs/attr.c  
 +++ linux-2.4.37.3/fs/attr.c  
 @@ -12,6 +12,9 @@  
  #include <linux/dnotify.h>  
  #include <linux/fcntl.h>  
  #include <linux/quotaops.h>  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
   
  /* Taken over from the old code... */  
   
 @@ -127,6 +130,13 @@ int notify_change(struct dentry * dentry  
                 attr->ia_atime = now;  
         if (!(ia_valid & ATTR_MTIME_SET))  
                 attr->ia_mtime = now;  
 +       /***** TOMOYO Linux start. *****/  
 +       if ((ia_valid & ATTR_MODE) && !ccs_capable(CCS_SYS_CHMOD))  
 +               return -EPERM;  
 +       if ((ia_valid & (ATTR_UID | ATTR_GID)) &&  
 +           !ccs_capable(CCS_SYS_CHOWN))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         lock_kernel();  
         if (inode->i_op && inode->i_op->setattr)  
 --- linux-2.4.37.3.orig/fs/exec.c  
 +++ linux-2.4.37.3/fs/exec.c  
 @@ -48,6 +48,10 @@  
495   #include <linux/kmod.h>   #include <linux/kmod.h>
496   #endif   #endif
497    
498  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
499  +  +
500   int core_uses_pid;   int core_uses_pid;
501   char core_pattern[65] = "core";   char core_pattern[65] = "core";
502   int core_setuid_ok = 0;   int core_setuid_ok = 0;
503  @@ -125,6 +129,12 @@ asmlinkage long sys_uselib(const char *  @@ -125,6 +127,10 @@ asmlinkage long sys_uselib(const char *
504          if (error)          if (error)
505                  goto exit;                  goto exit;
506    
507  +       /***** TOMOYO Linux start. *****/  +       error = ccs_uselib_permission(nd.dentry, nd.mnt);
 +       error = ccs_check_uselib_permission(nd.dentry, nd.mnt);  
508  +       if (error)  +       if (error)
509  +               goto exit;  +               goto exit;
 +       /***** TOMOYO Linux end. *****/  
510  +  +
511          file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);          file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
512          error = PTR_ERR(file);          error = PTR_ERR(file);
513          if (IS_ERR(file))          if (IS_ERR(file))
514  @@ -389,6 +399,11 @@ struct file *open_exec(const char *name)  @@ -389,6 +395,9 @@ struct file *open_exec(const char *name)
515                          int err = permission(inode, MAY_EXEC);                          int err = permission(inode, MAY_EXEC);
516                          if (!err && !(inode->i_mode & 0111))                          if (!err && !(inode->i_mode & 0111))
517                                  err = -EACCES;                                  err = -EACCES;
 +                       /***** TOMOYO Linux start. *****/  
518  +                       if (!err)  +                       if (!err)
519  +                               err = ccs_check_open_exec_permission(nd.dentry,  +                               err = ccs_open_exec_permission(nd.dentry,
520  +                                                                    nd.mnt);  +                                                                    nd.mnt);
 +                       /***** TOMOYO Linux end. *****/  
521                          file = ERR_PTR(err);                          file = ERR_PTR(err);
522                          if (!err) {                          if (!err) {
523                                  file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);                                  file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
524  @@ -986,7 +1001,8 @@ int do_execve(char * filename, char ** a  @@ -989,7 +998,8 @@ int do_execve(char * filename, char ** a
525          if (retval < 0)          if (retval < 0)
526                  goto out;                  goto out;
527    
# Line 739  Source code for this patch is http://www Line 531  Source code for this patch is http://www
531          if (retval >= 0)          if (retval >= 0)
532                  /* execve success */                  /* execve success */
533                  return retval;                  return retval;
534  --- linux-2.4.37.3.orig/fs/fcntl.c  --- linux-2.4.37.9.orig/fs/fcntl.c
535  +++ linux-2.4.37.3/fs/fcntl.c  +++ linux-2.4.37.9/fs/fcntl.c
536  @@ -16,6 +16,9 @@  @@ -16,6 +16,7 @@
537   #include <asm/poll.h>   #include <asm/poll.h>
538   #include <asm/siginfo.h>   #include <asm/siginfo.h>
539   #include <asm/uaccess.h>   #include <asm/uaccess.h>
540  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
541    
542   extern int sock_fcntl (struct file *, unsigned int cmd, unsigned long arg);   extern int sock_fcntl (struct file *, unsigned int cmd, unsigned long arg);
543   extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);   extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
544  @@ -214,6 +217,11 @@ static int setfl(int fd, struct file * f  @@ -214,6 +215,9 @@ static int setfl(int fd, struct file * f
545          if (!(arg & O_APPEND) && IS_APPEND(inode))          if (!(arg & O_APPEND) && IS_APPEND(inode))
546                  return -EPERM;                  return -EPERM;
547    
548  +       /***** TOMOYO Linux start. *****/  +       if (!(arg & O_APPEND) && ccs_rewrite_permission(filp))
 +       if (!(arg & O_APPEND) && ccs_check_rewrite_permission(filp))  
549  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
550  +  +
551          /* Did FASYNC state change? */          /* Did FASYNC state change? */
552          if ((arg ^ filp->f_flags) & FASYNC) {          if ((arg ^ filp->f_flags) & FASYNC) {
553                  if (filp->f_op && filp->f_op->fasync) {                  if (filp->f_op && filp->f_op->fasync) {
554  --- linux-2.4.37.3.orig/fs/ioctl.c  --- linux-2.4.37.9.orig/fs/ioctl.c
555  +++ linux-2.4.37.3/fs/ioctl.c  +++ linux-2.4.37.9/fs/ioctl.c
556  @@ -10,6 +10,9 @@  @@ -10,6 +10,7 @@
557    
558   #include <asm/uaccess.h>   #include <asm/uaccess.h>
559   #include <asm/ioctls.h>   #include <asm/ioctls.h>
560  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
561    
562   static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)   static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
563   {   {
564  @@ -55,6 +58,13 @@ asmlinkage long sys_ioctl(unsigned int f  @@ -55,6 +56,11 @@ asmlinkage long sys_ioctl(unsigned int f
565          filp = fget(fd);          filp = fget(fd);
566          if (!filp)          if (!filp)
567                  goto out;                  goto out;
568  +       /***** TOMOYO Linux start. *****/  +       error = ccs_ioctl_permission(filp, cmd, arg);
 +       error = ccs_check_ioctl_permission(filp, cmd, arg);  
569  +       if (error) {  +       if (error) {
570  +               fput(filp);  +               fput(filp);
571  +               goto out;  +               goto out;
572  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
573          error = 0;          error = 0;
574          lock_kernel();          lock_kernel();
575          switch (cmd) {          switch (cmd) {
576  @@ -112,6 +122,12 @@ asmlinkage long sys_ioctl(unsigned int f  --- linux-2.4.37.9.orig/fs/namei.c
577                                  error = -ENOTTY;  +++ linux-2.4.37.9/fs/namei.c
578                          break;  @@ -28,6 +28,9 @@
                 default:  
 +                       /***** TOMOYO Linux start. *****/  
 +                       if (!ccs_capable(CCS_SYS_IOCTL)) {  
 +                               error = -EPERM;  
 +                               break;  
 +                       }  
 +                       /***** TOMOYO Linux end. *****/  
                         error = -ENOTTY;  
                         if (S_ISREG(filp->f_dentry->d_inode->i_mode))  
                                 error = file_ioctl(filp, cmd, arg);  
 --- linux-2.4.37.3.orig/fs/namei.c  
 +++ linux-2.4.37.3/fs/namei.c  
 @@ -28,6 +28,11 @@  
579    
580   #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])   #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
581    
582  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
583  +#include <linux/module.h>  +#include <linux/module.h>
 +/***** TOMOYO Linux end. *****/  
584  +  +
585   /* [Feb-1997 T. Schoebel-Theuer]   /* [Feb-1997 T. Schoebel-Theuer]
586    * Fundamental changes in the pathname lookup mechanisms (namei)    * Fundamental changes in the pathname lookup mechanisms (namei)
587    * were necessary because of omirr.  The reason is that omirr needs    * were necessary because of omirr.  The reason is that omirr needs
588  @@ -1003,6 +1008,9 @@ exit_lock:  @@ -1068,6 +1071,9 @@ do_last:
         return error;  
  }  
   
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo_vfs.h>  
 +/***** TOMOYO Linux end. *****/  
  /*  
   *     open_namei()  
   *  
 @@ -1068,6 +1076,13 @@ do_last:  
589    
590          /* Negative dentry, just create the file */          /* Negative dentry, just create the file */
591          if (!dentry->d_inode) {          if (!dentry->d_inode) {
592  +               /***** TOMOYO Linux start. *****/  +               error = ccs_mknod_permission(dir->d_inode, dentry, nd->mnt,
593  +               error = ccs_check_mknod_permission(dir->d_inode, dentry,  +                                            mode & ~current->fs->umask, 0);
 +                                                  nd->mnt,  
 +                                                  mode & ~current->fs->umask,  
 +                                                  0);  
594  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
595                  error = vfs_create(dir->d_inode, dentry,                  error = vfs_create(dir->d_inode, dentry,
596                                     mode & ~current->fs->umask);                                     mode & ~current->fs->umask);
597                  up(&dir->d_inode->i_sem);                  up(&dir->d_inode->i_sem);
598  @@ -1154,6 +1169,13 @@ ok:  @@ -1154,6 +1160,11 @@ ok:
599                          goto exit;                          goto exit;
600          }          }
601    
 +       /***** TOMOYO Linux start. *****/  
602  +       /* includes O_APPEND and O_TRUNC checks */  +       /* includes O_APPEND and O_TRUNC checks */
603  +       error = ccs_check_open_permission(dentry, nd->mnt, flag);  +       error = ccs_open_permission(dentry, nd->mnt, flag);
604  +       if (error)  +       if (error)
605  +               goto exit;  +               goto exit;
 +       /***** TOMOYO Linux end. *****/  
606  +  +
607          /*          /*
608           * Ensure there are no outstanding leases on the file.           * Ensure there are no outstanding leases on the file.
609           */           */
610  @@ -1292,6 +1314,7 @@ asmlinkage long sys_mknod(const char * f  @@ -1292,6 +1303,7 @@ asmlinkage long sys_mknod(const char * f
611    
612          if (S_ISDIR(mode))          if (S_ISDIR(mode))
613                  return -EPERM;                  return -EPERM;
# Line 862  Source code for this patch is http://www Line 615  Source code for this patch is http://www
615          tmp = getname(filename);          tmp = getname(filename);
616          if (IS_ERR(tmp))          if (IS_ERR(tmp))
617                  return PTR_ERR(tmp);                  return PTR_ERR(tmp);
618  @@ -1304,6 +1327,12 @@ asmlinkage long sys_mknod(const char * f  @@ -1304,6 +1316,10 @@ asmlinkage long sys_mknod(const char * f
619    
620          mode &= ~current->fs->umask;          mode &= ~current->fs->umask;
621          if (!IS_ERR(dentry)) {          if (!IS_ERR(dentry)) {
622  +               /***** TOMOYO Linux start. *****/  +               error = ccs_mknod_permission(nd.dentry->d_inode, dentry,
623  +               error = ccs_check_mknod_permission(nd.dentry->d_inode, dentry,  +                                            nd.mnt, mode, dev);
 +                                                  nd.mnt, mode, dev);  
624  +               if (error)  +               if (error)
625  +                       goto out_dput;  +                       goto out_dput;
 +               /***** TOMOYO Linux end. *****/  
626                  switch (mode & S_IFMT) {                  switch (mode & S_IFMT) {
627                  case 0: case S_IFREG:                  case 0: case S_IFREG:
628                          error = vfs_create(nd.dentry->d_inode,dentry,mode);                          error = vfs_create(nd.dentry->d_inode,dentry,mode);
629  @@ -1317,6 +1346,9 @@ asmlinkage long sys_mknod(const char * f  @@ -1317,6 +1333,7 @@ asmlinkage long sys_mknod(const char * f
630                  default:                  default:
631                          error = -EINVAL;                          error = -EINVAL;
632                  }                  }
 +               /***** TOMOYO Linux start. *****/  
633  +out_dput:  +out_dput:
 +               /***** TOMOYO Linux end. *****/  
634                  dput(dentry);                  dput(dentry);
635          }          }
636          up(&nd.dentry->d_inode->i_sem);          up(&nd.dentry->d_inode->i_sem);
637  @@ -1370,6 +1402,12 @@ asmlinkage long sys_mkdir(const char * p  @@ -1370,6 +1387,9 @@ asmlinkage long sys_mkdir(const char * p
638                  dentry = lookup_create(&nd, 1);                  dentry = lookup_create(&nd, 1);
639                  error = PTR_ERR(dentry);                  error = PTR_ERR(dentry);
640                  if (!IS_ERR(dentry)) {                  if (!IS_ERR(dentry)) {
641  +                       /***** TOMOYO Linux start. *****/  +                       error = ccs_mkdir_permission(nd.dentry->d_inode,
642  +                       error = ccs_check_mkdir_permission(nd.dentry->d_inode,  +                                                    dentry, nd.mnt, mode);
 +                                                          dentry, nd.mnt,  
 +                                                          mode);  
643  +                       if (!error)  +                       if (!error)
 +                       /***** TOMOYO Linux end. *****/  
644                          error = vfs_mkdir(nd.dentry->d_inode, dentry,                          error = vfs_mkdir(nd.dentry->d_inode, dentry,
645                                            mode & ~current->fs->umask);                                            mode & ~current->fs->umask);
646                          dput(dentry);                          dput(dentry);
647  @@ -1479,6 +1517,11 @@ asmlinkage long sys_rmdir(const char * p  @@ -1479,6 +1499,9 @@ asmlinkage long sys_rmdir(const char * p
648          dentry = lookup_hash(&nd.last, nd.dentry);          dentry = lookup_hash(&nd.last, nd.dentry);
649          error = PTR_ERR(dentry);          error = PTR_ERR(dentry);
650          if (!IS_ERR(dentry)) {          if (!IS_ERR(dentry)) {
651  +               /***** TOMOYO Linux start. *****/  +               error = ccs_rmdir_permission(nd.dentry->d_inode, dentry,
652  +               error = ccs_check_rmdir_permission(nd.dentry->d_inode, dentry,  +                                            nd.mnt);
 +                                                  nd.mnt);  
653  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
654                  error = vfs_rmdir(nd.dentry->d_inode, dentry);                  error = vfs_rmdir(nd.dentry->d_inode, dentry);
655                  dput(dentry);                  dput(dentry);
656          }          }
657  @@ -1548,6 +1591,12 @@ asmlinkage long sys_unlink(const char *  @@ -1548,6 +1571,10 @@ asmlinkage long sys_unlink(const char *
658                  /* Why not before? Because we want correct error value */                  /* Why not before? Because we want correct error value */
659                  if (nd.last.name[nd.last.len])                  if (nd.last.name[nd.last.len])
660                          goto slashes;                          goto slashes;
661  +               /***** TOMOYO Linux start. *****/  +               error = ccs_unlink_permission(nd.dentry->d_inode, dentry,
662  +               error = ccs_check_unlink_permission(nd.dentry->d_inode, dentry,  +                                             nd.mnt);
 +                                                   nd.mnt);  
663  +               if (error)  +               if (error)
664  +                       goto exit2;  +                       goto exit2;
 +               /***** TOMOYO Linux end. *****/  
665                  error = vfs_unlink(nd.dentry->d_inode, dentry);                  error = vfs_unlink(nd.dentry->d_inode, dentry);
666          exit2:          exit2:
667                  dput(dentry);                  dput(dentry);
668  @@ -1612,6 +1661,12 @@ asmlinkage long sys_symlink(const char *  @@ -1612,6 +1639,9 @@ asmlinkage long sys_symlink(const char *
669                  dentry = lookup_create(&nd, 0);                  dentry = lookup_create(&nd, 0);
670                  error = PTR_ERR(dentry);                  error = PTR_ERR(dentry);
671                  if (!IS_ERR(dentry)) {                  if (!IS_ERR(dentry)) {
672  +                       /***** TOMOYO Linux start. *****/  +                       error = ccs_symlink_permission(nd.dentry->d_inode,
673  +                       error = ccs_check_symlink_permission(nd.dentry->d_inode,  +                                                      dentry, nd.mnt, from);
 +                                                            dentry, nd.mnt,  
 +                                                            from);  
674  +                       if (!error)  +                       if (!error)
 +                       /***** TOMOYO Linux end. *****/  
675                          error = vfs_symlink(nd.dentry->d_inode, dentry, from);                          error = vfs_symlink(nd.dentry->d_inode, dentry, from);
676                          dput(dentry);                          dput(dentry);
677                  }                  }
678  @@ -1698,6 +1753,12 @@ asmlinkage long sys_link(const char * ol  @@ -1698,6 +1728,10 @@ asmlinkage long sys_link(const char * ol
679                  new_dentry = lookup_create(&nd, 0);                  new_dentry = lookup_create(&nd, 0);
680                  error = PTR_ERR(new_dentry);                  error = PTR_ERR(new_dentry);
681                  if (!IS_ERR(new_dentry)) {                  if (!IS_ERR(new_dentry)) {
682  +                       /***** TOMOYO Linux start. *****/  +                       error = ccs_link_permission(old_nd.dentry,
683  +                       error = ccs_check_link_permission(old_nd.dentry,  +                                                   nd.dentry->d_inode,
684  +                                                         nd.dentry->d_inode,  +                                                   new_dentry, nd.mnt);
 +                                                         new_dentry, nd.mnt);  
685  +                       if (!error)  +                       if (!error)
 +                       /***** TOMOYO Linux end. *****/  
686                          error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);                          error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
687                          dput(new_dentry);                          dput(new_dentry);
688                  }                  }
689  @@ -1928,12 +1989,22 @@ static inline int do_rename(const char *  @@ -1928,12 +1962,17 @@ static inline int do_rename(const char *
690          error = PTR_ERR(new_dentry);          error = PTR_ERR(new_dentry);
691          if (IS_ERR(new_dentry))          if (IS_ERR(new_dentry))
692                  goto exit4;                  goto exit4;
693  +       /***** TOMOYO Linux start. *****/  +       error = ccs_rename_permission(old_dir->d_inode, old_dentry,
694  +       error = ccs_check_rename_permission(old_dir->d_inode, old_dentry,  +                                     new_dir->d_inode, new_dentry, newnd.mnt);
 +                                           new_dir->d_inode, new_dentry,  
 +                                           newnd.mnt);  
695  +       if (error)  +       if (error)
696  +               goto exit5;  +               goto exit5;
 +       /***** TOMOYO Linux end. *****/  
697    
698          lock_kernel();          lock_kernel();
699          error = vfs_rename(old_dir->d_inode, old_dentry,          error = vfs_rename(old_dir->d_inode, old_dentry,
700                                     new_dir->d_inode, new_dentry);                                     new_dir->d_inode, new_dentry);
701          unlock_kernel();          unlock_kernel();
702    
 +       /***** TOMOYO Linux start. *****/  
703  +exit5:  +exit5:
 +       /***** TOMOYO Linux end. *****/  
704          dput(new_dentry);          dput(new_dentry);
705   exit4:   exit4:
706          dput(old_dentry);          dput(old_dentry);
707  --- linux-2.4.37.3.orig/fs/namespace.c  --- linux-2.4.37.9.orig/fs/namespace.c
708  +++ linux-2.4.37.3/fs/namespace.c  +++ linux-2.4.37.9/fs/namespace.c
709  @@ -21,6 +21,13 @@  @@ -21,6 +21,8 @@
710   #include <linux/seq_file.h>   #include <linux/seq_file.h>
711   #include <linux/namespace.h>   #include <linux/namespace.h>
712    
713  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
714  +  +
715   struct vfsmount *do_kern_mount(const char *type, int flags, char *name, void *data);   struct vfsmount *do_kern_mount(const char *type, int flags, char *name, void *data);
716   int do_remount_sb(struct super_block *sb, int flags, void * data);   int do_remount_sb(struct super_block *sb, int flags, void * data);
717   void kill_super(struct super_block *sb);   void kill_super(struct super_block *sb);
718  @@ -290,6 +297,10 @@ static int do_umount(struct vfsmount *mn  @@ -290,6 +292,9 @@ static int do_umount(struct vfsmount *mn
719   {   {
720          struct super_block * sb = mnt->mnt_sb;          struct super_block * sb = mnt->mnt_sb;
721          int retval = 0;          int retval = 0;
722  +       /***** SAKURA Linux start. *****/  +       retval = ccs_umount_permission(mnt, flags);
723  +       if (ccs_may_umount(mnt))  +       if (retval)
724  +               return -EPERM;  +               return retval;
 +       /***** SAKURA Linux end. *****/  
725    
726          /*          /*
727           * If we may have to abort operations to get out of this           * If we may have to abort operations to get out of this
728  @@ -365,6 +376,10 @@ asmlinkage long sys_umount(char * name,  @@ -700,6 +705,7 @@ static int copy_mount_options (const voi
729     long do_mount(char * dev_name, char * dir_name, char *type_page,
730                      unsigned long flags, void *data_page)
731   {   {
732    +       const unsigned long original_flags = flags;
733          struct nameidata nd;          struct nameidata nd;
734          int retval;          int retval = 0;
735  +       /***** TOMOYO Linux start. *****/          int mnt_flags = 0;
736  +       if (!ccs_capable(CCS_SYS_UMOUNT))  @@ -732,6 +738,11 @@ long do_mount(char * dev_name, char * di
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
   
         retval = __user_walk(name, LOOKUP_POSITIVE|LOOKUP_FOLLOW, &nd);  
737          if (retval)          if (retval)
738  @@ -500,6 +515,11 @@ static int do_loopback(struct nameidata                  return retval;
         down_write(&current->namespace->sem);  
         err = -EINVAL;  
         if (check_mnt(nd->mnt) && (!recurse || check_mnt(old_nd.mnt))) {  
 +               /***** SAKURA Linux start. *****/  
 +               err = -EPERM;  
 +               if (ccs_may_mount(nd))  
 +                       goto out;  
 +               /***** SAKURA Linux end. *****/  
                 err = -ENOMEM;  
                 if (recurse)  
                         mnt = copy_tree(old_nd.mnt, old_nd.dentry);  
 @@ -516,7 +536,9 @@ static int do_loopback(struct nameidata  
                 } else  
                         mntput(mnt);  
         }  
 -  
 +       /***** SAKURA Linux start. *****/  
 + out:  
 +       /***** SAKURA Linux end. *****/  
         up_write(&current->namespace->sem);  
         path_release(&old_nd);  
         return err;  
 @@ -570,6 +592,12 @@ static int do_move_mount(struct nameidat  
         if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))  
                 goto out;  
739    
740  +       /***** SAKURA Linux start. *****/  +       retval = ccs_mount_permission(dev_name, &nd, type_page, original_flags,
741  +       err = -EPERM;  +                                     data_page);
 +       if (ccs_may_umount(old_nd.mnt) || ccs_may_mount(nd))  
 +               goto out;  
 +       /***** SAKURA Linux end. *****/  
 +  
         err = -ENOENT;  
         down(&nd->dentry->d_inode->i_zombie);  
         if (IS_DEADDIR(nd->dentry->d_inode))  
 @@ -641,6 +669,12 @@ static int do_add_mount(struct nameidata  
         if (nd->mnt->mnt_sb == mnt->mnt_sb && nd->mnt->mnt_root == nd->dentry)  
                 goto unlock;  
   
 +       /***** SAKURA Linux start. *****/  
 +       err = -EPERM;  
 +       if (ccs_may_mount(nd))  
 +               goto unlock;  
 +       /***** SAKURA Linux end. *****/  
 +  
         mnt->mnt_flags = mnt_flags;  
         err = graft_tree(mnt, nd);  
  unlock:  
 @@ -718,6 +752,17 @@ long do_mount(char * dev_name, char * di  
         if (data_page)  
                 ((char *)data_page)[PAGE_SIZE - 1] = 0;  
   
 +       /***** TOMOYO Linux start. *****/  
 +       if (!ccs_capable(CCS_SYS_MOUNT))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
 +       /***** SAKURA Linux start. *****/  
 +       retval = ccs_check_mount_permission(dev_name, dir_name, type_page,  
 +                                           &flags);  
742  +       if (retval)  +       if (retval)
743  +               return retval;  +               goto out;
 +       /***** SAKURA Linux end. *****/  
744  +  +
745          /* Separate the per-mountpoint flags */          if (flags & MS_REMOUNT)
746          if (flags & MS_NOSUID)                  retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
747                  mnt_flags |= MNT_NOSUID;                                      data_page);
748  @@ -911,6 +956,10 @@ asmlinkage long sys_pivot_root(const cha  @@ -742,6 +753,7 @@ long do_mount(char * dev_name, char * di
749            else
750          if (!capable(CAP_SYS_ADMIN))                  retval = do_add_mount(&nd, type_page, flags, mnt_flags,
751                  return -EPERM;                                        dev_name, data_page);
752  +       /***** TOMOYO Linux start. *****/  + out:
753  +       if (!ccs_capable(CCS_SYS_PIVOT_ROOT))          path_release(&nd);
754  +               return -EPERM;          return retval;
755  +       /***** TOMOYO Linux end. *****/   }
756    @@ -925,6 +937,11 @@ asmlinkage long sys_pivot_root(const cha
         lock_kernel();  
   
 @@ -925,6 +974,13 @@ asmlinkage long sys_pivot_root(const cha  
757          if (error)          if (error)
758                  goto out1;                  goto out1;
759    
760  +       /***** SAKURA Linux start. *****/  +       error = ccs_pivot_root_permission(&old_nd, &new_nd);
 +       error = ccs_check_pivot_root_permission(&old_nd, &new_nd);  
761  +       if (error) {  +       if (error) {
762  +               path_release(&old_nd);  +               path_release(&old_nd);
763  +               goto out1;  +               goto out1;
764  +       }  +       }
 +       /***** SAKURA Linux end. *****/  
765          read_lock(&current->fs->lock);          read_lock(&current->fs->lock);
766          user_nd.mnt = mntget(current->fs->rootmnt);          user_nd.mnt = mntget(current->fs->rootmnt);
767          user_nd.dentry = dget(current->fs->root);          user_nd.dentry = dget(current->fs->root);
768  --- linux-2.4.37.3.orig/fs/open.c  --- linux-2.4.37.9.orig/fs/open.c
769  +++ linux-2.4.37.3/fs/open.c  +++ linux-2.4.37.9/fs/open.c
770  @@ -20,6 +20,13 @@  @@ -20,6 +20,8 @@
771    
772   #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m))   #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m))
773    
774  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
775  +  +
776   int vfs_statfs(struct super_block *sb, struct statfs *buf)   int vfs_statfs(struct super_block *sb, struct statfs *buf)
777   {   {
778          int retval = -ENODEV;          int retval = -ENODEV;
779  @@ -164,6 +171,11 @@ static inline long do_sys_truncate(const  @@ -164,6 +166,9 @@ static inline long do_sys_truncate(const
780          if (error)          if (error)
781                  goto dput_and_out;                  goto dput_and_out;
782    
783  +       /***** TOMOYO Linux start. *****/  +       error = ccs_truncate_permission(nd.dentry, nd.mnt);
 +       error = ccs_check_truncate_permission(nd.dentry, nd.mnt, length, 0);  
784  +       if (!error)  +       if (!error)
 +       /***** TOMOYO Linux end. *****/  
785  +  +
786          error = locks_verify_truncate(inode, NULL, length);          error = locks_verify_truncate(inode, NULL, length);
787          if (!error) {          if (!error) {
788                  DQUOT_INIT(inode);                  DQUOT_INIT(inode);
789  @@ -217,6 +229,12 @@ static inline long do_sys_ftruncate(unsi  @@ -217,6 +222,9 @@ static inline long do_sys_ftruncate(unsi
790          if (IS_APPEND(inode))          if (IS_APPEND(inode))
791                  goto out_putf;                  goto out_putf;
792    
793  +       /***** TOMOYO Linux start. *****/  +       error = ccs_truncate_permission(dentry, file->f_vfsmnt);
 +       error = ccs_check_truncate_permission(dentry, file->f_vfsmnt, length,  
 +                                             0);  
794  +       if (error)  +       if (error)
795  +               goto out_putf;  +               goto out_putf;
 +       /***** TOMOYO Linux end. *****/  
796          error = locks_verify_truncate(inode, file, length);          error = locks_verify_truncate(inode, file, length);
797          if (!error)          if (!error)
798                  error = do_truncate(dentry, length);                  error = do_truncate(dentry, length);
799  @@ -466,6 +484,14 @@ asmlinkage long sys_chroot(const char *  @@ -466,6 +474,8 @@ asmlinkage long sys_chroot(const char *
800          error = -EPERM;          error = -EPERM;
801          if (!capable(CAP_SYS_CHROOT))          if (!capable(CAP_SYS_CHROOT))
802                  goto dput_and_out;                  goto dput_and_out;
803  +       /***** TOMOYO Linux start. *****/  +       if (ccs_chroot_permission(&nd))
 +       if (!ccs_capable(CCS_SYS_CHROOT))  
804  +               goto dput_and_out;  +               goto dput_and_out;
 +       /***** TOMOYO Linux end. *****/  
 +       /***** SAKURA Linux start. *****/  
 +       if (ccs_check_chroot_permission(&nd))  
 +               goto dput_and_out;  
 +       /***** SAKURA Linux end. *****/  
805    
806          set_fs_root(current->fs, nd.mnt, nd.dentry);          set_fs_root(current->fs, nd.mnt, nd.dentry);
807          set_fs_altroot();          set_fs_altroot();
808  @@ -897,6 +923,10 @@ out_unlock:  @@ -497,6 +507,9 @@ asmlinkage long sys_fchmod(unsigned int
809            err = -EPERM;
810            if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
811                    goto out_putf;
812    +       err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode);
813    +       if (err)
814    +               goto out_putf;
815            if (mode == (mode_t) -1)
816                    mode = inode->i_mode;
817            newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
818    @@ -528,6 +541,9 @@ asmlinkage long sys_chmod(const char * f
819            error = -EPERM;
820            if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
821                    goto dput_and_out;
822    +       error = ccs_chmod_permission(nd.dentry, nd.mnt, mode);
823    +       if (error)
824    +               goto dput_and_out;
825    
826            if (mode == (mode_t) -1)
827                    mode = inode->i_mode;
828    @@ -608,6 +624,8 @@ asmlinkage long sys_chown(const char * f
829    
830            error = user_path_walk(filename, &nd);
831            if (!error) {
832    +               error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
833    +               if (!error)
834                    error = chown_common(nd.dentry, user, group);
835                    path_release(&nd);
836            }
837    @@ -621,6 +639,8 @@ asmlinkage long sys_lchown(const char *
838    
839            error = user_path_walk_link(filename, &nd);
840            if (!error) {
841    +               error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
842    +               if (!error)
843                    error = chown_common(nd.dentry, user, group);
844                    path_release(&nd);
845            }
846    @@ -635,6 +655,9 @@ asmlinkage long sys_fchown(unsigned int
847    
848            file = fget(fd);
849            if (file) {
850    +               error = ccs_chown_permission(file->f_dentry, file->f_vfsmnt,
851    +                                            user, group);
852    +               if (!error)
853                    error = chown_common(file->f_dentry, user, group);
854                    fput(file);
855            }
856    @@ -666,7 +689,9 @@ struct file *filp_open(const char * file
857            if (namei_flags & O_TRUNC)
858                    namei_flags |= 2;
859    
860    +       ccs_save_open_mode(flags);
861            error = open_namei(filename, namei_flags, mode, &nd);
862    +       ccs_clear_open_mode();
863            if (!error)
864                    return dentry_open(nd.dentry, nd.mnt, flags);
865    
866    @@ -897,6 +922,8 @@ out_unlock:
867    */    */
868   asmlinkage long sys_vhangup(void)   asmlinkage long sys_vhangup(void)
869   {   {
 +       /***** TOMOYO Linux start. *****/  
870  +       if (!ccs_capable(CCS_SYS_VHANGUP))  +       if (!ccs_capable(CCS_SYS_VHANGUP))
871  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
872          if (capable(CAP_SYS_TTY_CONFIG)) {          if (capable(CAP_SYS_TTY_CONFIG)) {
873                  tty_vhangup(current->tty);                  tty_vhangup(current->tty);
874                  return 0;                  return 0;
875  --- linux-2.4.37.3.orig/fs/proc/Makefile  --- linux-2.4.37.9.orig/fs/proc/proc_misc.c
876  +++ linux-2.4.37.3/fs/proc/Makefile  +++ linux-2.4.37.9/fs/proc/proc_misc.c
877  @@ -18,4 +18,8 @@ ifeq ($(CONFIG_PROC_DEVICETREE),y)  @@ -670,4 +670,5 @@ void __init proc_misc_init(void)
  obj-y += proc_devtree.o  
  endif  
   
 +export-objs += ccs_proc.o  
 +obj-$(CONFIG_SAKURA) += ccs_proc.o  
 +obj-$(CONFIG_TOMOYO) += ccs_proc.o  
 +  
  include $(TOPDIR)/Rules.make  
 --- linux-2.4.37.3.orig/fs/proc/proc_misc.c  
 +++ linux-2.4.37.3/fs/proc/proc_misc.c  
 @@ -670,4 +670,9 @@ void __init proc_misc_init(void)  
878                          entry->proc_fops = &ppc_htab_operations;                          entry->proc_fops = &ppc_htab_operations;
879          }          }
880   #endif   #endif
881  +       /***** CCS start. *****/  +       printk(KERN_INFO "Hook version: 2.4.37.9 2010/07/26\n");
 +#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO)  
 +       printk(KERN_INFO "Hook version: 2.4.37.3 2009/07/20\n");  
 +#endif  
 +       /***** CCS end. *****/  
882   }   }
883  --- linux-2.4.37.3.orig/include/linux/sched.h  --- linux-2.4.37.9.orig/include/linux/sched.h
884  +++ linux-2.4.37.3/include/linux/sched.h  +++ linux-2.4.37.9/include/linux/sched.h
885  @@ -29,6 +29,10 @@ extern unsigned long event;  @@ -123,6 +123,15 @@ struct completion;
886    
887   struct exec_domain;   #ifdef __KERNEL__
888    
889  +/***** TOMOYO Linux start. *****/  +#ifdef CONFIG_CCSECURITY
890  +struct ccs_domain_info;  +struct ccs_domain_info;
891  +/***** TOMOYO Linux end. *****/  +#define INIT_CCSECURITY          \
892    +       .ccs_domain_info = NULL, \
893    +       .ccs_flags = 0,
894    +#else
895    +#define INIT_CCSECURITY
896    +#endif
897  +  +
898     #include <linux/spinlock.h>
899    
900   /*   /*
901    * cloning flags:  @@ -417,6 +426,10 @@ struct task_struct {
   */  
 @@ -417,6 +421,10 @@ struct task_struct {  
902          void *journal_info;          void *journal_info;
903    
904          struct list_head *scm_work_list;          struct list_head *scm_work_list;
905  +       /***** TOMOYO Linux start. *****/  +#ifdef CONFIG_CCSECURITY
906  +       struct ccs_domain_info *ccs_domain_info;  +       struct ccs_domain_info *ccs_domain_info;
907  +       u32 ccs_flags;  +       u32 ccs_flags;
908  +       /***** TOMOYO Linux end. *****/  +#endif
909   };   };
910    
911   /*   /*
912  @@ -512,6 +520,10 @@ extern struct exec_domain  default_exec_d  @@ -512,6 +525,7 @@ extern struct exec_domain   default_exec_d
913       blocked:           {{0}},                                          \       blocked:           {{0}},                                          \
914       alloc_lock:                SPIN_LOCK_UNLOCKED,                             \       alloc_lock:                SPIN_LOCK_UNLOCKED,                             \
915       journal_info:      NULL,                                           \       journal_info:      NULL,                                           \
916  +       /***** TOMOYO Linux start. *****/ \  +       INIT_CCSECURITY                                                 \
 +       ccs_domain_info: NULL,            \  
 +       ccs_flags: 0                      \  
 +       /***** TOMOYO Linux end. *****/   \  
917   }   }
918    
919    
920  --- linux-2.4.37.3.orig/kernel/kmod.c  --- linux-2.4.37.9.orig/kernel/kmod.c
921  +++ linux-2.4.37.3/kernel/kmod.c  +++ linux-2.4.37.9/kernel/kmod.c
922  @@ -134,6 +134,11 @@ int exec_usermodehelper(char *program_pa  @@ -134,6 +134,11 @@ int exec_usermodehelper(char *program_pa
923          /* Allow execve args to be in kernel space. */          /* Allow execve args to be in kernel space. */
924          set_fs(KERNEL_DS);          set_fs(KERNEL_DS);
925    
926  +       /***** TOMOYO Linux start. *****/  +#ifdef CONFIG_CCSECURITY
927  +       current->ccs_domain_info = NULL;  +       current->ccs_domain_info = NULL;
928  +       current->ccs_flags = 0;  +       current->ccs_flags = 0;
929  +       /***** TOMOYO Linux end. *****/  +#endif
930  +  +
931          /* Go, go, go... */          /* Go, go, go... */
932          if (execve(program_path, argv, envp) < 0)          if (execve(program_path, argv, envp) < 0)
933                  return -errno;                  return -errno;
934  --- linux-2.4.37.3.orig/kernel/module.c  --- linux-2.4.37.9.orig/kernel/module.c
935  +++ linux-2.4.37.3/kernel/module.c  +++ linux-2.4.37.9/kernel/module.c
936  @@ -10,6 +10,9 @@  @@ -10,6 +10,7 @@
937   #include <linux/slab.h>   #include <linux/slab.h>
938   #include <linux/kmod.h>   #include <linux/kmod.h>
939   #include <linux/seq_file.h>   #include <linux/seq_file.h>
940  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
941    
942   /*   /*
943    * Originally by Anonymous (as far as I know...)    * Originally by Anonymous (as far as I know...)
944  @@ -298,6 +301,10 @@ sys_create_module(const char *name_user,  @@ -298,6 +299,8 @@ sys_create_module(const char *name_user,
945    
946          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
947                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
948  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
949  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
950          lock_kernel();          lock_kernel();
951          if ((namelen = get_mod_name(name_user, &name)) < 0) {          if ((namelen = get_mod_name(name_user, &name)) < 0) {
952                  error = namelen;                  error = namelen;
953  @@ -353,6 +360,10 @@ sys_init_module(const char *name_user, s  @@ -353,6 +356,8 @@ sys_init_module(const char *name_user, s
954    
955          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
956                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
957  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
958  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
959          lock_kernel();          lock_kernel();
960          if ((namelen = get_mod_name(name_user, &name)) < 0) {          if ((namelen = get_mod_name(name_user, &name)) < 0) {
961                  error = namelen;                  error = namelen;
962  @@ -614,6 +625,10 @@ sys_delete_module(const char *name_user)  @@ -614,6 +619,8 @@ sys_delete_module(const char *name_user)
963    
964          if (!capable(CAP_SYS_MODULE))          if (!capable(CAP_SYS_MODULE))
965                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
966  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))  +       if (!ccs_capable(CCS_USE_KERNEL_MODULE))
967  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
968    
969          lock_kernel();          lock_kernel();
970          if (name_user) {          if (name_user) {
971  --- linux-2.4.37.3.orig/kernel/sched.c  --- linux-2.4.37.9.orig/kernel/sched.c
972  +++ linux-2.4.37.3/kernel/sched.c  +++ linux-2.4.37.9/kernel/sched.c
973  @@ -32,6 +32,9 @@  @@ -32,6 +32,7 @@
974    
975   #include <asm/uaccess.h>   #include <asm/uaccess.h>
976   #include <asm/mmu_context.h>   #include <asm/mmu_context.h>
977  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
978    
979   extern void timer_bh(void);   extern void timer_bh(void);
980   extern void tqueue_bh(void);   extern void tqueue_bh(void);
981  @@ -899,6 +902,10 @@ void set_cpus_allowed(struct task_struct  @@ -899,6 +900,8 @@ void set_cpus_allowed(struct task_struct
982   asmlinkage long sys_nice(int increment)   asmlinkage long sys_nice(int increment)
983   {   {
984          long newprio;          long newprio;
 +       /***** TOMOYO Linux start. *****/  
985  +       if (!ccs_capable(CCS_SYS_NICE))  +       if (!ccs_capable(CCS_SYS_NICE))
986  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
987    
988          /*          /*
989           *      Setpriority might change our priority at the same moment.           *      Setpriority might change our priority at the same moment.
990  --- linux-2.4.37.3.orig/kernel/signal.c  --- linux-2.4.37.9.orig/kernel/signal.c
991  +++ linux-2.4.37.3/kernel/signal.c  +++ linux-2.4.37.9/kernel/signal.c
992  @@ -15,6 +15,9 @@  @@ -15,6 +15,7 @@
993   #include <linux/sched.h>   #include <linux/sched.h>
994    
995   #include <asm/uaccess.h>   #include <asm/uaccess.h>
996  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
997    
998   /*   /*
999    * SLAB caches for signal bits.    * SLAB caches for signal bits.
1000  @@ -1025,6 +1028,12 @@ asmlinkage long  @@ -1025,6 +1026,8 @@ asmlinkage long
1001   sys_kill(int pid, int sig)   sys_kill(int pid, int sig)
1002   {   {
1003          struct siginfo info;          struct siginfo info;
1004  +       /***** TOMOYO Linux start. *****/  +       if (ccs_kill_permission(pid, sig))
 +       if (sig && !ccs_capable(CCS_SYS_KILL))  
1005  +               return -EPERM;  +               return -EPERM;
 +       if (sig && ccs_check_signal_acl(sig, pid))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
1006    
1007          info.si_signo = sig;          info.si_signo = sig;
1008          info.si_errno = 0;          info.si_errno = 0;
1009  @@ -1049,6 +1058,12 @@ sys_tkill(int pid, int sig)  @@ -1048,6 +1051,8 @@ sys_tkill(int pid, int sig)
1010            /* This is only valid for single tasks */
1011          if (pid <= 0)          if (pid <= 0)
1012              return -EINVAL;              return -EINVAL;
1013    +       if (ccs_tkill_permission(pid, sig))
1014    +              return -EPERM;
1015    
 +       /***** TOMOYO Linux start. *****/  
 +       if (sig && !ccs_capable(CCS_SYS_KILL))  
 +               return -EPERM;  
 +       if (sig && ccs_check_signal_acl(sig, pid))  
 +               return -EPERM;  
 +       /***** TOMOYO Linux end. *****/  
1016          info.si_signo = sig;          info.si_signo = sig;
1017          info.si_errno = 0;          info.si_errno = 0;
1018          info.si_code = SI_TKILL;  @@ -1078,6 +1083,8 @@ sys_rt_sigqueueinfo(int pid, int sig, si
1019  --- linux-2.4.37.3.orig/kernel/sys.c          if (info.si_code >= 0)
1020  +++ linux-2.4.37.3/kernel/sys.c                  return -EPERM;
1021  @@ -17,6 +17,9 @@          info.si_signo = sig;
1022    +       if (ccs_sigqueue_permission(pid, sig))
1023    +               return -EPERM;
1024    
1025            /* POSIX.1b doesn't mention process groups.  */
1026            return kill_proc_info(sig, &info, pid);
1027    --- linux-2.4.37.9.orig/kernel/sys.c
1028    +++ linux-2.4.37.9/kernel/sys.c
1029    @@ -17,6 +17,7 @@
1030    
1031   #include <asm/uaccess.h>   #include <asm/uaccess.h>
1032   #include <asm/io.h>   #include <asm/io.h>
1033  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
1034    
1035   #ifndef SET_UNALIGN_CTL   #ifndef SET_UNALIGN_CTL
1036   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)   # define SET_UNALIGN_CTL(a,b)  (-EINVAL)
1037  @@ -220,6 +223,10 @@ asmlinkage long sys_setpriority(int whic  @@ -220,6 +221,8 @@ asmlinkage long sys_setpriority(int whic
1038    
1039          if (which > 2 || which < 0)          if (which > 2 || which < 0)
1040                  return -EINVAL;                  return -EINVAL;
 +       /***** TOMOYO Linux start. *****/  
1041  +       if (!ccs_capable(CCS_SYS_NICE))  +       if (!ccs_capable(CCS_SYS_NICE))
1042  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1043    
1044          /* normalize: avoid signed division (rounding problems) */          /* normalize: avoid signed division (rounding problems) */
1045          error = -ESRCH;          error = -ESRCH;
1046  @@ -299,6 +306,10 @@ asmlinkage long sys_reboot(int magic1, i  @@ -299,6 +302,8 @@ asmlinkage long sys_reboot(int magic1, i
1047              (magic2 != LINUX_REBOOT_MAGIC2 && magic2 != LINUX_REBOOT_MAGIC2A &&              (magic2 != LINUX_REBOOT_MAGIC2 && magic2 != LINUX_REBOOT_MAGIC2A &&
1048                          magic2 != LINUX_REBOOT_MAGIC2B))                          magic2 != LINUX_REBOOT_MAGIC2B))
1049                  return -EINVAL;                  return -EINVAL;
 +       /***** TOMOYO Linux start. *****/  
1050  +       if (!ccs_capable(CCS_SYS_REBOOT))  +       if (!ccs_capable(CCS_SYS_REBOOT))
1051  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1052    
1053          lock_kernel();          lock_kernel();
1054          switch (cmd) {          switch (cmd) {
1055  @@ -1042,6 +1053,10 @@ asmlinkage long sys_sethostname(char *na  @@ -1042,6 +1047,8 @@ asmlinkage long sys_sethostname(char *na
1056                  return -EPERM;                  return -EPERM;
1057          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
1058                  return -EINVAL;                  return -EINVAL;
 +       /***** TOMOYO Linux start. *****/  
1059  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
1060  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1061          down_write(&uts_sem);          down_write(&uts_sem);
1062          errno = -EFAULT;          errno = -EFAULT;
1063          if (!copy_from_user(tmp, name, len)) {          if (!copy_from_user(tmp, name, len)) {
1064  @@ -1083,6 +1098,10 @@ asmlinkage long sys_setdomainname(char *  @@ -1083,6 +1090,8 @@ asmlinkage long sys_setdomainname(char *
1065                  return -EPERM;                  return -EPERM;
1066          if (len < 0 || len > __NEW_UTS_LEN)          if (len < 0 || len > __NEW_UTS_LEN)
1067                  return -EINVAL;                  return -EINVAL;
 +       /***** TOMOYO Linux start. *****/  
1068  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))  +       if (!ccs_capable(CCS_SYS_SETHOSTNAME))
1069  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1070    
1071          down_write(&uts_sem);          down_write(&uts_sem);
1072          errno = -EFAULT;          errno = -EFAULT;
1073  --- linux-2.4.37.3.orig/kernel/sysctl.c  --- linux-2.4.37.9.orig/kernel/sysctl.c
1074  +++ linux-2.4.37.3/kernel/sysctl.c  +++ linux-2.4.37.9/kernel/sysctl.c
1075  @@ -33,6 +33,9 @@  @@ -33,6 +33,7 @@
1076   #include <linux/swap.h>   #include <linux/swap.h>
1077    
1078   #include <asm/uaccess.h>   #include <asm/uaccess.h>
1079  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
1080    
1081   #ifdef CONFIG_ROOT_NFS   #ifdef CONFIG_ROOT_NFS
1082   #include <linux/nfs_fs.h>   #include <linux/nfs_fs.h>
1083  @@ -439,6 +442,11 @@ int do_sysctl(int *name, int nlen, void  @@ -439,6 +440,9 @@ int do_sysctl(int *name, int nlen, void
1084    
1085                  spin_unlock(&sysctl_lock);                  spin_unlock(&sysctl_lock);
1086    
 +               /***** TOMOYO Linux start. *****/  
1087  +               error = ccs_parse_table(name, nlen, oldval, newval,  +               error = ccs_parse_table(name, nlen, oldval, newval,
1088  +                                       head->ctl_table);  +                                       head->ctl_table);
1089  +               if (!error)  +               if (!error)
 +               /***** TOMOYO Linux end. *****/  
1090                  error = parse_table(name, nlen, oldval, oldlenp,                  error = parse_table(name, nlen, oldval, oldlenp,
1091                                          newval, newlen, head->ctl_table,                                          newval, newlen, head->ctl_table,
1092                                          &context);                                          &context);
1093  @@ -508,6 +516,15 @@ repeat:  @@ -508,6 +512,13 @@ repeat:
1094                                  if (ctl_perm(table, 001))                                  if (ctl_perm(table, 001))
1095                                          return -EPERM;                                          return -EPERM;
1096                                  if (table->strategy) {                                  if (table->strategy) {
 +                                       /***** TOMOYO Linux start. *****/  
1097  +                                       int op = 0;  +                                       int op = 0;
1098  +                                       if (oldval)  +                                       if (oldval)
1099  +                                               op |= 004;  +                                               op |= 004;
# Line 1439  Source code for this patch is http://www Line 1101  Source code for this patch is http://www
1101  +                                               op |= 002;  +                                               op |= 002;
1102  +                                       if (ctl_perm(table, op))  +                                       if (ctl_perm(table, op))
1103  +                                               return -EPERM;  +                                               return -EPERM;
 +                                       /***** TOMOYO Linux end. *****/  
1104                                          error = table->strategy(                                          error = table->strategy(
1105                                                  table, name, nlen,                                                  table, name, nlen,
1106                                                  oldval, oldlenp,                                                  oldval, oldlenp,
1107  @@ -1456,7 +1473,7 @@ int sysctl_string(ctl_table *table, int  @@ -1456,7 +1467,7 @@ int sysctl_string(ctl_table *table, int
1108                          len--;                          len--;
1109                  ((char *) table->data)[len] = 0;                  ((char *) table->data)[len] = 0;
1110          }          }
# Line 1452  Source code for this patch is http://www Line 1113  Source code for this patch is http://www
1113   }   }
1114    
1115   /*   /*
1116  --- linux-2.4.37.3.orig/kernel/time.c  --- linux-2.4.37.9.orig/kernel/time.c
1117  +++ linux-2.4.37.3/kernel/time.c  +++ linux-2.4.37.9/kernel/time.c
1118  @@ -29,6 +29,9 @@  @@ -29,6 +29,7 @@
1119   #include <linux/smp_lock.h>   #include <linux/smp_lock.h>
1120    
1121   #include <asm/uaccess.h>   #include <asm/uaccess.h>
1122  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
1123    
1124   /*   /*
1125    * 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
1126  @@ -77,6 +80,10 @@ asmlinkage long sys_stime(int * tptr)  @@ -77,6 +78,8 @@ asmlinkage long sys_stime(int * tptr)
1127    
1128          if (!capable(CAP_SYS_TIME))          if (!capable(CAP_SYS_TIME))
1129                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
1130  +       if (!ccs_capable(CCS_SYS_SETTIME))  +       if (!ccs_capable(CCS_SYS_SETTIME))
1131  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1132          if (get_user(value, tptr))          if (get_user(value, tptr))
1133                  return -EFAULT;                  return -EFAULT;
1134          write_lock_irq(&xtime_lock);          write_lock_irq(&xtime_lock);
1135  @@ -151,6 +158,10 @@ int do_sys_settimeofday(struct timeval *  @@ -151,6 +154,8 @@ int do_sys_settimeofday(struct timeval *
1136    
1137          if (!capable(CAP_SYS_TIME))          if (!capable(CAP_SYS_TIME))
1138                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
1139  +       if (!ccs_capable(CCS_SYS_SETTIME))  +       if (!ccs_capable(CCS_SYS_SETTIME))
1140  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1141                                    
1142          if (tz) {          if (tz) {
1143                  /* SMP safe, global irq locking makes it work. */                  /* SMP safe, global irq locking makes it work. */
1144  @@ -217,6 +228,10 @@ int do_adjtimex(struct timex *txc)  @@ -217,6 +222,8 @@ int do_adjtimex(struct timex *txc)
1145          /* In order to modify anything, you gotta be super-user! */          /* In order to modify anything, you gotta be super-user! */
1146          if (txc->modes && !capable(CAP_SYS_TIME))          if (txc->modes && !capable(CAP_SYS_TIME))
1147                  return -EPERM;                  return -EPERM;
 +       /***** TOMOYO Linux start. *****/  
1148  +       if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))  +       if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
1149  +               return -EPERM;  +               return -EPERM;
 +       /***** TOMOYO Linux end. *****/  
1150                                    
1151          /* Now we validate the data before disabling interrupts */          /* Now we validate the data before disabling interrupts */
1152    
1153  --- linux-2.4.37.3.orig/net/ipv4/raw.c  --- linux-2.4.37.9.orig/net/ipv4/raw.c
1154  +++ linux-2.4.37.3/net/ipv4/raw.c  +++ linux-2.4.37.9/net/ipv4/raw.c
1155  @@ -64,6 +64,9 @@  @@ -64,6 +64,7 @@
1156   #include <net/raw.h>   #include <net/raw.h>
1157   #include <net/inet_common.h>   #include <net/inet_common.h>
1158   #include <net/checksum.h>   #include <net/checksum.h>
1159  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo_socket.h>  
 +/***** TOMOYO Linux end. *****/  
1160    
1161   struct sock *raw_v4_htable[RAWV4_HTABLE_SIZE];   struct sock *raw_v4_htable[RAWV4_HTABLE_SIZE];
1162   rwlock_t raw_v4_lock = RW_LOCK_UNLOCKED;   rwlock_t raw_v4_lock = RW_LOCK_UNLOCKED;
1163  @@ -503,6 +506,11 @@ int raw_recvmsg(struct sock *sk, struct  @@ -500,9 +501,14 @@ int raw_recvmsg(struct sock *sk, struct
         skb = skb_recv_datagram(sk, flags, noblock, &err);  
         if (!skb)  
1164                  goto out;                  goto out;
1165  +       /***** TOMOYO Linux start. *****/          }
1166  +       err = ccs_socket_recvmsg_permission(sk, skb, flags);  
1167  +       if (err)  -       skb = skb_recv_datagram(sk, flags, noblock, &err);
1168  +               goto out;  -       if (!skb)
1169  +       /***** TOMOYO Linux end. *****/  -               goto out;
1170    +       for (;;) {
1171    +               skb = skb_recv_datagram(sk, flags, noblock, &err);
1172    +               if (!skb)
1173    +                       goto out;
1174    +               if (!ccs_socket_post_recvmsg_permission(sk, skb))
1175    +                       break;
1176    +               skb_kill_datagram(sk, skb, flags);
1177    +       }
1178    
1179          copied = skb->len;          copied = skb->len;
1180          if (len < copied) {          if (len < copied) {
1181  --- linux-2.4.37.3.orig/net/ipv4/tcp_ipv4.c  --- linux-2.4.37.9.orig/net/ipv4/tcp_ipv4.c
1182  +++ linux-2.4.37.3/net/ipv4/tcp_ipv4.c  +++ linux-2.4.37.9/net/ipv4/tcp_ipv4.c
1183  @@ -67,6 +67,9 @@  @@ -67,6 +67,7 @@
1184   #include <linux/inet.h>   #include <linux/inet.h>
1185   #include <linux/stddef.h>   #include <linux/stddef.h>
1186   #include <linux/ipsec.h>   #include <linux/ipsec.h>
1187  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1188    
1189   extern int sysctl_ip_dynaddr;   extern int sysctl_ip_dynaddr;
1190   extern int sysctl_ip_default_ttl;   extern int sysctl_ip_default_ttl;
1191  @@ -228,6 +231,10 @@ static int tcp_v4_get_port(struct sock *  @@ -228,6 +229,8 @@ static int tcp_v4_get_port(struct sock *
1192                                  rover = low;                                  rover = low;
1193                          head = &tcp_bhash[tcp_bhashfn(rover)];                          head = &tcp_bhash[tcp_bhashfn(rover)];
1194                          spin_lock(&head->lock);                          spin_lock(&head->lock);
 +                       /***** SAKURA Linux start. *****/  
1195  +                       if (ccs_lport_reserved(rover))  +                       if (ccs_lport_reserved(rover))
1196  +                               goto next;  +                               goto next;
 +                       /***** SAKURA Linux end. *****/  
1197                          for (tb = head->chain; tb; tb = tb->next)                          for (tb = head->chain; tb; tb = tb->next)
1198                                  if (tb->port == rover)                                  if (tb->port == rover)
1199                                          goto next;                                          goto next;
1200  @@ -688,6 +695,10 @@ static int tcp_v4_hash_connect(struct so  @@ -688,6 +691,8 @@ static int tcp_v4_hash_connect(struct so
1201                                  rover = low;                                  rover = low;
1202                          head = &tcp_bhash[tcp_bhashfn(rover)];                          head = &tcp_bhash[tcp_bhashfn(rover)];
1203                          spin_lock(&head->lock);                                  spin_lock(&head->lock);        
 +                       /***** SAKURA Linux start. *****/  
1204  +                       if (ccs_lport_reserved(rover))  +                       if (ccs_lport_reserved(rover))
1205  +                               goto next_port;  +                               goto next_port;
 +                       /***** SAKURA Linux end. *****/  
1206    
1207                          /* Does not bother with rcv_saddr checks,                          /* Does not bother with rcv_saddr checks,
1208                           * because the established check is already                           * because the established check is already
1209  --- linux-2.4.37.3.orig/net/ipv4/udp.c  --- linux-2.4.37.9.orig/net/ipv4/udp.c
1210  +++ linux-2.4.37.3/net/ipv4/udp.c  +++ linux-2.4.37.9/net/ipv4/udp.c
1211  @@ -97,6 +97,12 @@  @@ -97,6 +97,7 @@
1212   #include <net/route.h>   #include <net/route.h>
1213   #include <net/inet_common.h>   #include <net/inet_common.h>
1214   #include <net/checksum.h>   #include <net/checksum.h>
1215  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo_socket.h>  
 +/***** TOMOYO Linux end. *****/  
1216    
1217   /*   /*
1218    *     Snmp MIB for the UDP layer    *     Snmp MIB for the UDP layer
1219  @@ -131,6 +137,10 @@ static int udp_v4_get_port(struct sock *  @@ -131,6 +132,8 @@ static int udp_v4_get_port(struct sock *
1220                                          result = sysctl_local_port_range[0] +                                          result = sysctl_local_port_range[0] +
1221                                                  ((result - sysctl_local_port_range[0]) &                                                  ((result - sysctl_local_port_range[0]) &
1222                                                   (UDP_HTABLE_SIZE - 1));                                                   (UDP_HTABLE_SIZE - 1));
 +                               /***** SAKURA Linux start. *****/  
1223  +                               if (ccs_lport_reserved(result))  +                               if (ccs_lport_reserved(result))
1224  +                                       continue;  +                                       continue;
 +                               /***** SAKURA Linux end. *****/  
1225                                  goto gotit;                                  goto gotit;
1226                          }                          }
1227                          size = 0;                          size = 0;
1228  @@ -148,6 +158,10 @@ static int udp_v4_get_port(struct sock *  @@ -148,6 +151,8 @@ static int udp_v4_get_port(struct sock *
1229                                  result = sysctl_local_port_range[0]                                  result = sysctl_local_port_range[0]
1230                                          + ((result - sysctl_local_port_range[0]) &                                          + ((result - sysctl_local_port_range[0]) &
1231                                             (UDP_HTABLE_SIZE - 1));                                             (UDP_HTABLE_SIZE - 1));
 +                       /***** SAKURA Linux start. *****/  
1232  +                       if (ccs_lport_reserved(result))  +                       if (ccs_lport_reserved(result))
1233  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1234                          if (!udp_lport_inuse(result))                          if (!udp_lport_inuse(result))
1235                                  break;                                  break;
1236                  }                  }
1237  @@ -711,6 +725,11 @@ try_again:  @@ -697,6 +702,7 @@ int udp_recvmsg(struct sock *sk, struct
1238            struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name;
1239            struct sk_buff *skb;
1240            int copied, err;
1241    +       _Bool update_stat;
1242    
1243            /*
1244             *      Check any passed addresses
1245    @@ -711,6 +717,11 @@ try_again:
1246          skb = skb_recv_datagram(sk, flags, noblock, &err);          skb = skb_recv_datagram(sk, flags, noblock, &err);
1247          if (!skb)          if (!skb)
1248                  goto out;                  goto out;
1249  +       /***** TOMOYO Linux start. *****/  +       if (ccs_socket_post_recvmsg_permission(sk, skb)) {
1250  +       err = ccs_socket_recvmsg_permission(sk, skb, flags);  +               update_stat = 0;
1251  +       if (err)  +               goto csum_copy_err;
1252  +               goto out;  +       }
1253  +       /***** TOMOYO Linux end. *****/  +       update_stat = 1;
1254        
1255          copied = skb->len - sizeof(struct udphdr);          copied = skb->len - sizeof(struct udphdr);
1256          if (copied > len) {          if (copied > len) {
1257  --- linux-2.4.37.3.orig/net/ipv6/raw.c  @@ -759,7 +770,8 @@ out:
1258  +++ linux-2.4.37.3/net/ipv6/raw.c          return err;
1259  @@ -45,6 +45,9 @@  
1260     csum_copy_err:
1261    -       UDP_INC_STATS_BH(UdpInErrors);
1262    +       if (update_stat)
1263    +               UDP_INC_STATS_BH(UdpInErrors);
1264    
1265            /* Clear queue. */
1266            if (flags&MSG_PEEK) {
1267    --- linux-2.4.37.9.orig/net/ipv6/raw.c
1268    +++ linux-2.4.37.9/net/ipv6/raw.c
1269    @@ -45,6 +45,7 @@
1270   #include <net/inet_common.h>   #include <net/inet_common.h>
1271    
1272   #include <net/rawv6.h>   #include <net/rawv6.h>
1273  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo_socket.h>  
 +/***** TOMOYO Linux end. *****/  
1274    
1275   struct sock *raw_v6_htable[RAWV6_HTABLE_SIZE];   struct sock *raw_v6_htable[RAWV6_HTABLE_SIZE];
1276   rwlock_t raw_v6_lock = RW_LOCK_UNLOCKED;   rwlock_t raw_v6_lock = RW_LOCK_UNLOCKED;
1277  @@ -369,6 +372,11 @@ int rawv6_recvmsg(struct sock *sk, struc  @@ -366,9 +367,14 @@ int rawv6_recvmsg(struct sock *sk, struc
1278          skb = skb_recv_datagram(sk, flags, noblock, &err);          if (flags & MSG_ERRQUEUE)
1279          if (!skb)                  return ipv6_recv_error(sk, msg, len);
1280                  goto out;  
1281  +       /***** TOMOYO Linux start. *****/  -       skb = skb_recv_datagram(sk, flags, noblock, &err);
1282  +       err = ccs_socket_recvmsg_permission(sk, skb, flags);  -       if (!skb)
1283  +       if (err)  -               goto out;
1284  +               goto out;  +       for (;;) {
1285  +       /***** TOMOYO Linux end. *****/  +               skb = skb_recv_datagram(sk, flags, noblock, &err);
1286    +               if (!skb)
1287    +                       goto out;
1288    +               if (!ccs_socket_post_recvmsg_permission(sk, skb))
1289    +                       break;
1290    +               skb_kill_datagram(sk, skb, flags);
1291    +       }
1292    
1293          copied = skb->len;          copied = skb->len;
1294          if (copied > len) {          if (copied > len) {
1295  --- linux-2.4.37.3.orig/net/ipv6/tcp_ipv6.c  --- linux-2.4.37.9.orig/net/ipv6/tcp_ipv6.c
1296  +++ linux-2.4.37.3/net/ipv6/tcp_ipv6.c  +++ linux-2.4.37.9/net/ipv6/tcp_ipv6.c
1297  @@ -52,6 +52,9 @@  @@ -52,6 +52,7 @@
1298   #include <net/inet_ecn.h>   #include <net/inet_ecn.h>
1299    
1300   #include <asm/uaccess.h>   #include <asm/uaccess.h>
1301  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
1302    
1303   static void    tcp_v6_send_reset(struct sk_buff *skb);   static void    tcp_v6_send_reset(struct sk_buff *skb);
1304   static void    tcp_v6_or_send_ack(struct sk_buff *skb, struct open_request *req);   static void    tcp_v6_or_send_ack(struct sk_buff *skb, struct open_request *req);
1305  @@ -110,6 +113,10 @@ static int tcp_v6_get_port(struct sock *  @@ -110,6 +111,8 @@ static int tcp_v6_get_port(struct sock *
1306                                  rover = low;                                  rover = low;
1307                          head = &tcp_bhash[tcp_bhashfn(rover)];                          head = &tcp_bhash[tcp_bhashfn(rover)];
1308                          spin_lock(&head->lock);                          spin_lock(&head->lock);
 +                       /***** SAKURA Linux start. *****/  
1309  +                       if (ccs_lport_reserved(rover))  +                       if (ccs_lport_reserved(rover))
1310  +                               goto next;  +                               goto next;
 +                       /***** SAKURA Linux end. *****/  
1311                          for (tb = head->chain; tb; tb = tb->next)                          for (tb = head->chain; tb; tb = tb->next)
1312                                  if (tb->port == rover)                                  if (tb->port == rover)
1313                                          goto next;                                          goto next;
1314  --- linux-2.4.37.3.orig/net/ipv6/udp.c  --- linux-2.4.37.9.orig/net/ipv6/udp.c
1315  +++ linux-2.4.37.3/net/ipv6/udp.c  +++ linux-2.4.37.9/net/ipv6/udp.c
1316  @@ -50,6 +50,12 @@  @@ -50,6 +50,7 @@
1317   #include <net/inet_common.h>   #include <net/inet_common.h>
1318    
1319   #include <net/checksum.h>   #include <net/checksum.h>
1320  +/***** SAKURA Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/sakura.h>  
 +/***** SAKURA Linux end. *****/  
 +/***** TOMOYO Linux start. *****/  
 +#include <linux/tomoyo_socket.h>  
 +/***** TOMOYO Linux end. *****/  
1321    
1322   struct udp_mib udp_stats_in6[NR_CPUS*2];   struct udp_mib udp_stats_in6[NR_CPUS*2];
1323    
1324  @@ -77,6 +83,10 @@ static int udp_v6_get_port(struct sock *  @@ -77,6 +78,8 @@ static int udp_v6_get_port(struct sock *
1325                                          result = sysctl_local_port_range[0] +                                          result = sysctl_local_port_range[0] +
1326                                                  ((result - sysctl_local_port_range[0]) &                                                  ((result - sysctl_local_port_range[0]) &
1327                                                   (UDP_HTABLE_SIZE - 1));                                                   (UDP_HTABLE_SIZE - 1));
 +                               /***** SAKURA Linux start. *****/  
1328  +                               if (ccs_lport_reserved(result))  +                               if (ccs_lport_reserved(result))
1329  +                                       continue;  +                                       continue;
 +                               /***** SAKURA Linux end. *****/  
1330                                  goto gotit;                                  goto gotit;
1331                          }                          }
1332                          size = 0;                          size = 0;
1333  @@ -94,6 +104,10 @@ static int udp_v6_get_port(struct sock *  @@ -94,6 +97,8 @@ static int udp_v6_get_port(struct sock *
1334                                  result = sysctl_local_port_range[0]                                  result = sysctl_local_port_range[0]
1335                                          + ((result - sysctl_local_port_range[0]) &                                          + ((result - sysctl_local_port_range[0]) &
1336                                             (UDP_HTABLE_SIZE - 1));                                             (UDP_HTABLE_SIZE - 1));
 +                       /***** SAKURA Linux start. *****/  
1337  +                       if (ccs_lport_reserved(result))  +                       if (ccs_lport_reserved(result))
1338  +                               continue;  +                               continue;
 +                       /***** SAKURA Linux end. *****/  
1339                          if (!udp_lport_inuse(result))                          if (!udp_lport_inuse(result))
1340                                  break;                                  break;
1341                  }                  }
1342  @@ -406,6 +420,11 @@ try_again:  @@ -395,6 +400,7 @@ int udpv6_recvmsg(struct sock *sk, struc
1343     {
1344            struct sk_buff *skb;
1345            int copied, err;
1346    +       _Bool update_stat;
1347    
1348            if (addr_len)
1349                    *addr_len=sizeof(struct sockaddr_in6);
1350    @@ -406,6 +412,11 @@ try_again:
1351          skb = skb_recv_datagram(sk, flags, noblock, &err);          skb = skb_recv_datagram(sk, flags, noblock, &err);
1352          if (!skb)          if (!skb)
1353                  goto out;                  goto out;
1354  +       /***** TOMOYO Linux start. *****/  +       if (ccs_socket_post_recvmsg_permission(sk, skb)) {
1355  +       err = ccs_socket_recvmsg_permission(sk, skb, flags);  +               update_stat = 0;
1356  +       if (err)  +               goto csum_copy_err;
1357  +               goto out;  +       }
1358  +       /***** TOMOYO Linux end. *****/  +       update_stat = 1;
1359    
1360          copied = skb->len - sizeof(struct udphdr);          copied = skb->len - sizeof(struct udphdr);
1361          if (copied > len) {          if (copied > len) {
1362  --- linux-2.4.37.3.orig/net/socket.c  @@ -485,7 +496,8 @@ csum_copy_err:
1363  +++ linux-2.4.37.3/net/socket.c          skb_free_datagram(sk, skb);
1364  @@ -84,6 +84,10 @@  
1365            if (flags & MSG_DONTWAIT) {
1366    -               UDP6_INC_STATS_USER(UdpInErrors);
1367    +               if (update_stat)
1368    +                       UDP6_INC_STATS_USER(UdpInErrors);
1369                    return -EAGAIN;
1370            }
1371            goto try_again;
1372    --- linux-2.4.37.9.orig/net/socket.c
1373    +++ linux-2.4.37.9/net/socket.c
1374    @@ -84,6 +84,7 @@
1375   #include <net/sock.h>   #include <net/sock.h>
1376   #include <net/scm.h>   #include <net/scm.h>
1377   #include <linux/netfilter.h>   #include <linux/netfilter.h>
1378  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +#include <linux/tomoyo_socket.h>  
 +/***** TOMOYO Linux end. *****/  
1379    
1380   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);   static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
1381   static ssize_t sock_read(struct file *file, char *buf,   static ssize_t sock_read(struct file *file, char *buf,
1382  @@ -501,7 +505,12 @@ int sock_sendmsg(struct socket *sock, st  @@ -501,7 +502,8 @@ int sock_sendmsg(struct socket *sock, st
1383   {   {
1384          int err;          int err;
1385          struct scm_cookie scm;          struct scm_cookie scm;
1386  -  -
1387  +       /***** TOMOYO Linux start. *****/  +       err = ccs_socket_sendmsg_permission(sock, msg, size);
 +       err = ccs_socket_sendmsg_permission(sock,  
 +                                           (struct sockaddr *) msg->msg_name,  
 +                                           msg->msg_namelen);  
1388  +       if (!err)  +       if (!err)
 +       /***** TOMOYO Linux end. *****/  
1389          err = scm_send(sock, msg, &scm);          err = scm_send(sock, msg, &scm);
1390          if (err >= 0) {          if (err >= 0) {
1391                  err = sock->ops->sendmsg(sock, msg, size, &scm);                  err = sock->ops->sendmsg(sock, msg, size, &scm);
1392  @@ -847,7 +856,11 @@ int sock_create(int family, int type, in  @@ -850,7 +852,9 @@ int sock_create(int family, int type, in
1393                  }                  }
1394                  family = PF_PACKET;                  family = PF_PACKET;
1395          }          }
1396  -                -              
 +       /***** TOMOYO Linux start. *****/  
1397  +       i = ccs_socket_create_permission(family, type, protocol);  +       i = ccs_socket_create_permission(family, type, protocol);
1398  +       if (i)  +       if (i)
1399  +               return i;  +               return i;
 +       /***** TOMOYO Linux end. *****/  
1400   #if defined(CONFIG_KMOD) && defined(CONFIG_NET)   #if defined(CONFIG_KMOD) && defined(CONFIG_NET)
1401          /* Attempt to load a protocol module if the find failed.          /* Attempt to load a protocol module if the find failed.
1402           *           *
1403  @@ -1003,6 +1016,12 @@ asmlinkage long sys_bind(int fd, struct  @@ -1006,6 +1010,10 @@ asmlinkage long sys_bind(int fd, struct
1404          if((sock = sockfd_lookup(fd,&err))!=NULL)          if((sock = sockfd_lookup(fd,&err))!=NULL)
1405          {          {
1406                  if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0)                  if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0)
 +                       /***** TOMOYO Linux start. *****/  
1407  +                       err = ccs_socket_bind_permission(sock,  +                       err = ccs_socket_bind_permission(sock,
1408  +                                                        (struct sockaddr *)  +                                                        (struct sockaddr *)
1409  +                                                        address, addrlen);  +                                                        address, addrlen);
1410  +               if (!err)  +               if (!err)
 +                       /***** TOMOYO Linux end. *****/  
1411                          err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);                          err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);
1412                  sockfd_put(sock);                  sockfd_put(sock);
1413          }                                }                      
1414  @@ -1026,6 +1045,10 @@ asmlinkage long sys_listen(int fd, int b  @@ -1029,6 +1037,8 @@ asmlinkage long sys_listen(int fd, int b
1415          if ((sock = sockfd_lookup(fd, &err)) != NULL) {          if ((sock = sockfd_lookup(fd, &err)) != NULL) {
1416                  if ((unsigned) backlog > sysctl_somaxconn)                  if ((unsigned) backlog > sysctl_somaxconn)
1417                          backlog = sysctl_somaxconn;                          backlog = sysctl_somaxconn;
 +               /***** TOMOYO Linux start. *****/  
1418  +               err = ccs_socket_listen_permission(sock);  +               err = ccs_socket_listen_permission(sock);
1419  +               if (!err)  +               if (!err)
 +               /***** TOMOYO Linux end. *****/  
1420                  err=sock->ops->listen(sock, backlog);                  err=sock->ops->listen(sock, backlog);
1421                  sockfd_put(sock);                  sockfd_put(sock);
1422          }          }
1423  @@ -1066,6 +1089,13 @@ asmlinkage long sys_accept(int fd, struc  @@ -1058,6 +1068,7 @@ asmlinkage long sys_accept(int fd, struc
1424            if (!sock)
1425                    goto out;
1426    
1427    +retry:
1428            err = -ENFILE;
1429            if (!(newsock = sock_alloc()))
1430                    goto out_put;
1431    @@ -1069,6 +1080,10 @@ asmlinkage long sys_accept(int fd, struc
1432          if (err < 0)          if (err < 0)
1433                  goto out_release;                  goto out_release;
1434    
1435  +       /***** TOMOYO Linux start. *****/  +       if (ccs_socket_post_accept_permission(sock, newsock)) {
1436  +       if (ccs_socket_accept_permission(newsock,  +               sock_release(newsock);
1437  +                                        (struct sockaddr *) address)) {  +               goto retry;
 +               err = -ECONNABORTED; /* Hope less harmful than -EPERM. */  
 +               goto out_release;  
1438  +       }  +       }
 +       /***** TOMOYO Linux end. *****/  
1439          if (upeer_sockaddr) {          if (upeer_sockaddr) {
1440                  if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {                  if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {
1441                          err = -ECONNABORTED;                          err = -ECONNABORTED;
1442  @@ -1116,6 +1146,12 @@ asmlinkage long sys_connect(int fd, stru  @@ -1119,6 +1134,10 @@ asmlinkage long sys_connect(int fd, stru
1443          err = move_addr_to_kernel(uservaddr, addrlen, address);          err = move_addr_to_kernel(uservaddr, addrlen, address);
1444          if (err < 0)          if (err < 0)
1445                  goto out_put;                  goto out_put;
 +       /***** TOMOYO Linux start. *****/  
1446  +       err = ccs_socket_connect_permission(sock, (struct sockaddr *) address,  +       err = ccs_socket_connect_permission(sock, (struct sockaddr *) address,
1447  +                                           addrlen);  +                                           addrlen);
1448  +       if (err)  +       if (err)
1449  +               goto out_put;  +               goto out_put;
 +       /***** TOMOYO Linux end. *****/  
1450          err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,          err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,
1451                                   sock->file->f_flags);                                   sock->file->f_flags);
1452   out_put:   out_put:
1453  --- linux-2.4.37.3.orig/net/unix/af_unix.c  --- linux-2.4.37.9.orig/net/unix/af_unix.c
1454  +++ linux-2.4.37.3/net/unix/af_unix.c  +++ linux-2.4.37.9/net/unix/af_unix.c
1455  @@ -111,6 +111,9 @@  @@ -111,6 +111,7 @@
1456   #include <linux/rtnetlink.h>   #include <linux/rtnetlink.h>
1457    
1458   #include <asm/checksum.h>   #include <asm/checksum.h>
1459  +/***** TOMOYO Linux start. *****/  +#include <linux/ccsecurity.h>
 +#include <linux/tomoyo.h>  
 +/***** TOMOYO Linux end. *****/  
1460    
1461   int sysctl_unix_max_dgram_qlen = 10;   int sysctl_unix_max_dgram_qlen = 10;
1462    
1463  @@ -710,6 +713,11 @@ static int unix_bind(struct socket *sock  @@ -710,6 +711,9 @@ static int unix_bind(struct socket *sock
1464                   * All right, let's create it.                   * All right, let's create it.
1465                   */                   */
1466                  mode = S_IFSOCK | (sock->inode->i_mode & ~current->fs->umask);                  mode = S_IFSOCK | (sock->inode->i_mode & ~current->fs->umask);
1467  +               /***** TOMOYO Linux start. *****/  +               err = ccs_mknod_permission(nd.dentry->d_inode, dentry, nd.mnt,
1468  +               err = ccs_check_mknod_permission(nd.dentry->d_inode, dentry,  +                                          mode, 0);
 +                                                nd.mnt, mode, 0);  
1469  +               if (!err)  +               if (!err)
 +               /***** TOMOYO Linux end. *****/  
1470                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);                  err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
1471                  if (err)                  if (err)
1472                          goto out_mknod_dput;                          goto out_mknod_dput;

Legend:
Removed from v.2781  
changed lines
  Added in v.3856

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