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