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