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