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