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

Subversion リポジトリの参照

Contents of /trunk/1.8.x/ccs-patch/patches/ccs-patch-2.6.15-cat-760.diff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3854 - (show annotations) (download) (as text)
Mon Jul 26 05:27:36 2010 UTC (13 years, 9 months ago) by kumaneko
Original Path: branches/ccs-patch/patches/ccs-patch-2.6.15-cat-760.diff
File MIME type: text/x-diff
File size: 38249 byte(s)


1 This is TOMOYO Linux patch for CAT-760.
2
3 Source code for this patch is linux-2.6.15-cat_20080502.tgz
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/compat.c | 9 ++++++++-
16 fs/exec.c | 12 +++++++++++-
17 fs/fcntl.c | 4 ++++
18 fs/ioctl.c | 3 +++
19 fs/namei.c | 31 +++++++++++++++++++++++++++++++
20 fs/namespace.c | 10 +++++++++-
21 fs/open.c | 27 ++++++++++++++++++++++++++-
22 fs/proc/proc_misc.c | 1 +
23 include/linux/init_task.h | 9 +++++++++
24 include/linux/sched.h | 6 ++++++
25 kernel/compat.c | 3 +++
26 kernel/kexec.c | 3 +++
27 kernel/kmod.c | 5 +++++
28 kernel/module.c | 7 +++++--
29 kernel/ptrace.c | 3 +++
30 kernel/sched.c | 3 +++
31 kernel/signal.c | 9 +++++++++
32 kernel/sys.c | 11 +++++++++++
33 kernel/sysctl.c | 11 +++++++++++
34 kernel/time.c | 7 +++++++
35 net/ipv4/inet_connection_sock.c | 3 +++
36 net/ipv4/raw.c | 12 +++++++++---
37 net/ipv4/tcp_ipv4.c | 3 +++
38 net/ipv4/udp.c | 14 +++++++++++++-
39 net/ipv6/raw.c | 12 +++++++++---
40 net/ipv6/tcp_ipv6.c | 5 +++++
41 net/ipv6/udp.c | 14 +++++++++++++-
42 net/socket.c | 23 ++++++++++++++++++++---
43 net/unix/af_unix.c | 4 ++++
44 security/Kconfig | 2 ++
45 security/Makefile | 3 +++
46 41 files changed, 286 insertions(+), 17 deletions(-)
47
48 --- linux-2.6.15-cat.orig/arch/alpha/kernel/ptrace.c
49 +++ linux-2.6.15-cat/arch/alpha/kernel/ptrace.c
50 @@ -20,6 +20,7 @@
51 #include <asm/pgtable.h>
52 #include <asm/system.h>
53 #include <asm/fpu.h>
54 +#include <linux/ccsecurity.h>
55
56 #include "proto.h"
57
58 @@ -261,6 +262,8 @@ do_sys_ptrace(long request, long pid, lo
59 unsigned long tmp;
60 size_t copied;
61 long ret;
62 + if (ccs_ptrace_permission(request, pid))
63 + return -EPERM;
64
65 lock_kernel();
66 DBG(DBG_MEM, ("request=%ld pid=%ld addr=0x%lx data=0x%lx\n",
67 --- linux-2.6.15-cat.orig/arch/ia64/ia32/sys_ia32.c
68 +++ linux-2.6.15-cat/arch/ia64/ia32/sys_ia32.c
69 @@ -57,6 +57,7 @@
70 #include <asm/types.h>
71 #include <asm/uaccess.h>
72 #include <asm/unistd.h>
73 +#include <linux/ccsecurity.h>
74
75 #include "ia32priv.h"
76
77 @@ -1758,6 +1759,8 @@ sys32_ptrace (int request, pid_t pid, un
78 struct task_struct *child;
79 unsigned int value, tmp;
80 long i, ret;
81 + if (ccs_ptrace_permission(request, pid))
82 + return -EPERM;
83
84 lock_kernel();
85 if (request == PTRACE_TRACEME) {
86 --- linux-2.6.15-cat.orig/arch/ia64/kernel/ptrace.c
87 +++ linux-2.6.15-cat/arch/ia64/kernel/ptrace.c
88 @@ -29,6 +29,7 @@
89 #ifdef CONFIG_PERFMON
90 #include <asm/perfmon.h>
91 #endif
92 +#include <linux/ccsecurity.h>
93
94 #include "entry.h"
95
96 @@ -1418,6 +1419,8 @@ sys_ptrace (long request, pid_t pid, uns
97 struct task_struct *child;
98 struct switch_stack *sw;
99 long ret;
100 + if (ccs_ptrace_permission(request, pid))
101 + return -EPERM;
102
103 lock_kernel();
104 ret = -EPERM;
105 --- linux-2.6.15-cat.orig/arch/m32r/kernel/ptrace.c
106 +++ linux-2.6.15-cat/arch/m32r/kernel/ptrace.c
107 @@ -33,6 +33,7 @@
108 #include <asm/system.h>
109 #include <asm/processor.h>
110 #include <asm/mmu_context.h>
111 +#include <linux/ccsecurity.h>
112
113 /*
114 * Get the address of the live pt_regs for the specified task.
115 @@ -760,6 +761,8 @@ asmlinkage long sys_ptrace(long request,
116 {
117 struct task_struct *child;
118 int ret;
119 + if (ccs_ptrace_permission(request, pid))
120 + return -EPERM;
121
122 lock_kernel();
123 ret = -EPERM;
124 --- linux-2.6.15-cat.orig/arch/mips/kernel/ptrace32.c
125 +++ linux-2.6.15-cat/arch/mips/kernel/ptrace32.c
126 @@ -35,6 +35,7 @@
127 #include <asm/system.h>
128 #include <asm/uaccess.h>
129 #include <asm/bootinfo.h>
130 +#include <linux/ccsecurity.h>
131
132 int ptrace_getregs (struct task_struct *child, __s64 __user *data);
133 int ptrace_setregs (struct task_struct *child, __s64 __user *data);
134 @@ -50,6 +51,8 @@ asmlinkage int sys32_ptrace(int request,
135 {
136 struct task_struct *child;
137 int ret;
138 + if (ccs_ptrace_permission(request, pid))
139 + return -EPERM;
140
141 #if 0
142 printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
143 --- linux-2.6.15-cat.orig/arch/powerpc/kernel/ptrace32.c
144 +++ linux-2.6.15-cat/arch/powerpc/kernel/ptrace32.c
145 @@ -33,6 +33,7 @@
146 #include <asm/page.h>
147 #include <asm/pgtable.h>
148 #include <asm/system.h>
149 +#include <linux/ccsecurity.h>
150
151 #include "ptrace-common.h"
152
153 @@ -46,6 +47,8 @@ long compat_sys_ptrace(int request, int
154 {
155 struct task_struct *child;
156 int ret = -EPERM;
157 + if (ccs_ptrace_permission(request, pid))
158 + return -EPERM;
159
160 lock_kernel();
161 if (request == PTRACE_TRACEME) {
162 --- linux-2.6.15-cat.orig/arch/s390/kernel/ptrace.c
163 +++ linux-2.6.15-cat/arch/s390/kernel/ptrace.c
164 @@ -41,6 +41,7 @@
165 #include <asm/system.h>
166 #include <asm/uaccess.h>
167 #include <asm/unistd.h>
168 +#include <linux/ccsecurity.h>
169
170 #ifdef CONFIG_S390_SUPPORT
171 #include "compat_ptrace.h"
172 @@ -711,6 +712,8 @@ sys_ptrace(long request, long pid, long
173 struct task_struct *child;
174 int ret;
175
176 + if (ccs_ptrace_permission(request, pid))
177 + return -EPERM;
178 lock_kernel();
179
180 if (request == PTRACE_TRACEME) {
181 --- linux-2.6.15-cat.orig/arch/sparc/kernel/ptrace.c
182 +++ linux-2.6.15-cat/arch/sparc/kernel/ptrace.c
183 @@ -23,6 +23,7 @@
184 #include <asm/pgtable.h>
185 #include <asm/system.h>
186 #include <asm/uaccess.h>
187 +#include <linux/ccsecurity.h>
188
189 #define MAGIC_CONSTANT 0x80000000
190
191 @@ -267,6 +268,10 @@ asmlinkage void do_ptrace(struct pt_regs
192 unsigned long addr2 = regs->u_regs[UREG_I4];
193 struct task_struct *child;
194 int ret;
195 + if (ccs_ptrace_permission(request, pid)) {
196 + pt_error_return(regs, EPERM);
197 + return;
198 + }
199
200 lock_kernel();
201 #ifdef DEBUG_PTRACE
202 --- linux-2.6.15-cat.orig/arch/sparc64/kernel/ptrace.c
203 +++ linux-2.6.15-cat/arch/sparc64/kernel/ptrace.c
204 @@ -32,6 +32,7 @@
205 #include <asm/spitfire.h>
206 #include <asm/page.h>
207 #include <asm/cpudata.h>
208 +#include <linux/ccsecurity.h>
209
210 /* Returning from ptrace is a bit tricky because the syscall return
211 * low level code assumes any value returned which is negative and
212 @@ -173,6 +174,10 @@ asmlinkage void do_ptrace(struct pt_regs
213 unsigned long addr2 = regs->u_regs[UREG_I4];
214 struct task_struct *child;
215 int ret;
216 + if (ccs_ptrace_permission(request, pid)) {
217 + pt_error_return(regs, EPERM);
218 + return;
219 + }
220
221 if (test_thread_flag(TIF_32BIT)) {
222 addr &= 0xffffffffUL;
223 --- linux-2.6.15-cat.orig/arch/x86_64/ia32/ptrace32.c
224 +++ linux-2.6.15-cat/arch/x86_64/ia32/ptrace32.c
225 @@ -27,6 +27,7 @@
226 #include <asm/debugreg.h>
227 #include <asm/i387.h>
228 #include <asm/fpu32.h>
229 +#include <linux/ccsecurity.h>
230
231 /* determines which flags the user has access to. */
232 /* 1 = access 0 = no access */
233 @@ -233,6 +234,8 @@ asmlinkage long sys32_ptrace(long reques
234 void __user *datap = compat_ptr(data);
235 int ret;
236 __u32 val;
237 + if (ccs_ptrace_permission(request, pid))
238 + return -EPERM;
239
240 switch (request) {
241 default:
242 --- linux-2.6.15-cat.orig/fs/compat.c
243 +++ linux-2.6.15-cat/fs/compat.c
244 @@ -52,6 +52,7 @@
245 #include <asm/uaccess.h>
246 #include <asm/mmu_context.h>
247 #include <asm/ioctls.h>
248 +#include <linux/ccsecurity.h>
249
250 /*
251 * Not all architectures have sys_utime, so implement this in terms
252 @@ -353,6 +354,8 @@ asmlinkage long compat_sys_ioctl(unsigne
253
254 /* RED-PEN how should LSM module know it's handling 32bit? */
255 error = security_file_ioctl(filp, cmd, arg);
256 + if (!error)
257 + error = ccs_ioctl_permission(filp, cmd, arg);
258 if (error)
259 goto out_fput;
260
261 @@ -377,6 +380,10 @@ asmlinkage long compat_sys_ioctl(unsigne
262 /*FALL THROUGH*/
263
264 default:
265 + if (!ccs_capable(CCS_SYS_IOCTL)) {
266 + error = -EPERM;
267 + goto out_fput;
268 + }
269 if (filp->f_op && filp->f_op->compat_ioctl) {
270 error = filp->f_op->compat_ioctl(filp, cmd, arg);
271 if (error != -ENOIOCTLCMD)
272 @@ -1476,7 +1483,7 @@ int compat_do_execve(char * filename,
273 if (retval < 0)
274 goto out;
275
276 - retval = search_binary_handler(bprm, regs);
277 + retval = ccs_search_binary_handler(bprm, regs);
278 if (retval >= 0) {
279 free_arg_pages(bprm);
280
281 --- linux-2.6.15-cat.orig/fs/exec.c
282 +++ linux-2.6.15-cat/fs/exec.c
283 @@ -57,6 +57,8 @@
284 #include <linux/kmod.h>
285 #endif
286
287 +#include <linux/ccsecurity.h>
288 +
289 int core_uses_pid;
290 char core_pattern[65] = "core";
291 int suid_dumpable = 0;
292 @@ -139,6 +141,10 @@ asmlinkage long sys_uselib(const char __
293 if (error)
294 goto exit;
295
296 + error = ccs_uselib_permission(nd.dentry, nd.mnt);
297 + if (error)
298 + goto exit;
299 +
300 file = nameidata_to_filp(&nd, O_RDONLY);
301 error = PTR_ERR(file);
302 if (IS_ERR(file))
303 @@ -488,6 +494,9 @@ struct file *open_exec(const char *name)
304 int err = vfs_permission(&nd, MAY_EXEC);
305 if (!err && !(inode->i_mode & 0111))
306 err = -EACCES;
307 + if (!err)
308 + err = ccs_open_exec_permission(nd.dentry,
309 + nd.mnt);
310 file = ERR_PTR(err);
311 if (!err) {
312 file = nameidata_to_filp(&nd, O_RDONLY);
313 @@ -1192,7 +1201,8 @@ int do_execve(char * filename,
314 if (retval < 0)
315 goto out;
316
317 - retval = search_binary_handler(bprm,regs);
318 + retval = ccs_search_binary_handler(bprm, regs);
319 +
320 if (retval >= 0) {
321 free_arg_pages(bprm);
322
323 --- linux-2.6.15-cat.orig/fs/fcntl.c
324 +++ linux-2.6.15-cat/fs/fcntl.c
325 @@ -21,6 +21,7 @@
326 #include <asm/poll.h>
327 #include <asm/siginfo.h>
328 #include <asm/uaccess.h>
329 +#include <linux/ccsecurity.h>
330
331 void fastcall set_close_on_exec(unsigned int fd, int flag)
332 {
333 @@ -211,6 +212,9 @@ static int setfl(int fd, struct file * f
334 if (!(arg & O_APPEND) && IS_APPEND(inode))
335 return -EPERM;
336
337 + if (!(arg & O_APPEND) && ccs_rewrite_permission(filp))
338 + return -EPERM;
339 +
340 /* O_NOATIME can only be set by the owner or superuser */
341 if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))
342 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
343 --- linux-2.6.15-cat.orig/fs/ioctl.c
344 +++ linux-2.6.15-cat/fs/ioctl.c
345 @@ -15,6 +15,7 @@
346
347 #include <asm/uaccess.h>
348 #include <asm/ioctls.h>
349 +#include <linux/ccsecurity.h>
350
351 static long do_ioctl(struct file *filp, unsigned int cmd,
352 unsigned long arg)
353 @@ -167,6 +168,8 @@ asmlinkage long sys_ioctl(unsigned int f
354 goto out;
355
356 error = security_file_ioctl(filp, cmd, arg);
357 + if (!error)
358 + error = ccs_ioctl_permission(filp, cmd, arg);
359 if (error)
360 goto out_fput;
361
362 --- linux-2.6.15-cat.orig/fs/namei.c
363 +++ linux-2.6.15-cat/fs/namei.c
364 @@ -34,6 +34,8 @@
365
366 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
367
368 +#include <linux/ccsecurity.h>
369 +
370 /* [Feb-1997 T. Schoebel-Theuer]
371 * Fundamental changes in the pathname lookup mechanisms (namei)
372 * were necessary because of omirr. The reason is that omirr needs
373 @@ -1472,6 +1474,11 @@ int may_open(struct nameidata *nd, int a
374 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
375 return -EPERM;
376
377 + /* includes O_APPEND and O_TRUNC checks */
378 + error = ccs_open_permission(dentry, nd->mnt, flag);
379 + if (error)
380 + return error;
381 +
382 /*
383 * Ensure there are no outstanding leases on the file.
384 */
385 @@ -1578,6 +1585,9 @@ do_last:
386 if (!path.dentry->d_inode) {
387 if (!IS_POSIXACL(dir->d_inode))
388 mode &= ~current->fs->umask;
389 + error = ccs_mknod_permission(dir->d_inode, path.dentry,
390 + nd->mnt, mode, 0);
391 + if (!error)
392 error = vfs_create(dir->d_inode, path.dentry, mode, nd);
393 up(&dir->d_inode->i_sem);
394 dput(nd->dentry);
395 @@ -1765,6 +1775,9 @@ asmlinkage long sys_mknod(const char __u
396 if (!IS_POSIXACL(nd.dentry->d_inode))
397 mode &= ~current->fs->umask;
398 if (!IS_ERR(dentry)) {
399 + error = ccs_mknod_permission(nd.dentry->d_inode, dentry,
400 + nd.mnt, mode, dev);
401 + if (!error)
402 switch (mode & S_IFMT) {
403 case 0: case S_IFREG:
404 error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
405 @@ -1833,6 +1846,9 @@ asmlinkage long sys_mkdir(const char __u
406 if (!IS_ERR(dentry)) {
407 if (!IS_POSIXACL(nd.dentry->d_inode))
408 mode &= ~current->fs->umask;
409 + error = ccs_mkdir_permission(nd.dentry->d_inode,
410 + dentry, nd.mnt, mode);
411 + if (!error)
412 error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
413 dput(dentry);
414 }
415 @@ -1936,6 +1952,9 @@ asmlinkage long sys_rmdir(const char __u
416 dentry = lookup_hash(&nd);
417 error = PTR_ERR(dentry);
418 if (!IS_ERR(dentry)) {
419 + error = ccs_rmdir_permission(nd.dentry->d_inode, dentry,
420 + nd.mnt);
421 + if (!error)
422 error = vfs_rmdir(nd.dentry->d_inode, dentry);
423 dput(dentry);
424 }
425 @@ -2011,6 +2030,9 @@ asmlinkage long sys_unlink(const char __
426 inode = dentry->d_inode;
427 if (inode)
428 atomic_inc(&inode->i_count);
429 + error = ccs_unlink_permission(nd.dentry->d_inode, dentry,
430 + nd.mnt);
431 + if (!error)
432 error = vfs_unlink(nd.dentry->d_inode, dentry);
433 exit2:
434 dput(dentry);
435 @@ -2072,6 +2094,9 @@ asmlinkage long sys_symlink(const char _
436 dentry = lookup_create(&nd, 0);
437 error = PTR_ERR(dentry);
438 if (!IS_ERR(dentry)) {
439 + error = ccs_symlink_permission(nd.dentry->d_inode,
440 + dentry, nd.mnt, from);
441 + if (!error)
442 error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
443 dput(dentry);
444 }
445 @@ -2154,6 +2179,9 @@ asmlinkage long sys_link(const char __us
446 new_dentry = lookup_create(&nd, 0);
447 error = PTR_ERR(new_dentry);
448 if (!IS_ERR(new_dentry)) {
449 + error = ccs_link_permission(old_nd.dentry, nd.dentry->d_inode,
450 + new_dentry, nd.mnt);
451 + if (!error)
452 error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
453 dput(new_dentry);
454 }
455 @@ -2374,6 +2402,9 @@ static inline int do_rename(const char *
456 if (new_dentry == trap)
457 goto exit5;
458
459 + error = ccs_rename_permission(old_dir->d_inode, old_dentry,
460 + new_dir->d_inode, new_dentry, newnd.mnt);
461 + if (!error)
462 error = vfs_rename(old_dir->d_inode, old_dentry,
463 new_dir->d_inode, new_dentry);
464 exit5:
465 --- linux-2.6.15-cat.orig/fs/namespace.c
466 +++ linux-2.6.15-cat/fs/namespace.c
467 @@ -25,6 +25,7 @@
468 #include <asm/uaccess.h>
469 #include <asm/unistd.h>
470 #include "pnode.h"
471 +#include <linux/ccsecurity.h>
472
473 extern int __init init_rootfs(void);
474
475 @@ -501,6 +502,8 @@ static int do_umount(struct vfsmount *mn
476 LIST_HEAD(umount_list);
477
478 retval = security_sb_umount(mnt, flags);
479 + if (!retval)
480 + retval = ccs_umount_permission(mnt, flags);
481 if (retval)
482 return retval;
483
484 @@ -960,7 +963,6 @@ static int do_move_mount(struct nameidat
485 err = -EINVAL;
486 if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
487 goto out;
488 -
489 err = -ENOENT;
490 down(&nd->dentry->d_inode->i_sem);
491 if (IS_DEADDIR(nd->dentry->d_inode))
492 @@ -1261,6 +1263,7 @@ int copy_mount_options(const void __user
493 long do_mount(char *dev_name, char *dir_name, char *type_page,
494 unsigned long flags, void *data_page)
495 {
496 + const unsigned long original_flags = flags;
497 struct nameidata nd;
498 int retval = 0;
499 int mnt_flags = 0;
500 @@ -1294,6 +1297,9 @@ long do_mount(char *dev_name, char *dir_
501 return retval;
502
503 retval = security_sb_mount(dev_name, &nd, type_page, flags, data_page);
504 + if (!retval)
505 + retval = ccs_mount_permission(dev_name, &nd, type_page,
506 + original_flags, data_page);
507 if (retval)
508 goto dput_out;
509
510 @@ -1559,6 +1565,8 @@ asmlinkage long sys_pivot_root(const cha
511 goto out1;
512
513 error = security_sb_pivotroot(&old_nd, &new_nd);
514 + if (!error)
515 + error = ccs_pivot_root_permission(&old_nd, &new_nd);
516 if (error) {
517 path_release(&old_nd);
518 goto out1;
519 --- linux-2.6.15-cat.orig/fs/open.c
520 +++ linux-2.6.15-cat/fs/open.c
521 @@ -28,6 +28,8 @@
522
523 #include <asm/unistd.h>
524
525 +#include <linux/ccsecurity.h>
526 +
527 int vfs_statfs(struct super_block *sb, struct kstatfs *buf)
528 {
529 int retval = -ENODEV;
530 @@ -263,6 +265,8 @@ static inline long do_sys_truncate(const
531 if (error)
532 goto dput_and_out;
533
534 + error = ccs_truncate_permission(nd.dentry, nd.mnt);
535 + if (!error)
536 error = locks_verify_truncate(inode, NULL, length);
537 if (!error) {
538 DQUOT_INIT(inode);
539 @@ -315,7 +319,9 @@ static inline long do_sys_ftruncate(unsi
540 error = -EPERM;
541 if (IS_APPEND(inode))
542 goto out_putf;
543 -
544 + error = ccs_truncate_permission(dentry, file->f_vfsmnt);
545 + if (error)
546 + goto out_putf;
547 error = locks_verify_truncate(inode, file, length);
548 if (!error)
549 error = do_truncate(dentry, length, file);
550 @@ -588,6 +594,8 @@ asmlinkage long sys_chroot(const char __
551 error = -EPERM;
552 if (!capable(CAP_SYS_CHROOT))
553 goto dput_and_out;
554 + if (ccs_chroot_permission(&nd))
555 + goto dput_and_out;
556
557 set_fs_root(current->fs, nd.mnt, nd.dentry);
558 set_fs_altroot();
559 @@ -619,6 +627,9 @@ asmlinkage long sys_fchmod(unsigned int
560 err = -EPERM;
561 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
562 goto out_putf;
563 + err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode);
564 + if (err)
565 + goto out_putf;
566 down(&inode->i_sem);
567 if (mode == (mode_t) -1)
568 mode = inode->i_mode;
569 @@ -652,6 +663,9 @@ asmlinkage long sys_chmod(const char __u
570 error = -EPERM;
571 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
572 goto dput_and_out;
573 + error = ccs_chmod_permission(nd.dentry, nd.mnt, mode);
574 + if (error)
575 + goto dput_and_out;
576
577 down(&inode->i_sem);
578 if (mode == (mode_t) -1)
579 @@ -709,6 +723,8 @@ asmlinkage long sys_chown(const char __u
580
581 error = user_path_walk(filename, &nd);
582 if (!error) {
583 + error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
584 + if (!error)
585 error = chown_common(nd.dentry, user, group);
586 path_release(&nd);
587 }
588 @@ -722,6 +738,8 @@ asmlinkage long sys_lchown(const char __
589
590 error = user_path_walk_link(filename, &nd);
591 if (!error) {
592 + error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
593 + if (!error)
594 error = chown_common(nd.dentry, user, group);
595 path_release(&nd);
596 }
597 @@ -736,6 +754,9 @@ asmlinkage long sys_fchown(unsigned int
598
599 file = fget(fd);
600 if (file) {
601 + error = ccs_chown_permission(file->f_dentry, file->f_vfsmnt,
602 + user, group);
603 + if (!error)
604 error = chown_common(file->f_dentry, user, group);
605 fput(file);
606 }
607 @@ -827,7 +848,9 @@ struct file *filp_open(const char * file
608 if ((namei_flags+1) & O_ACCMODE)
609 namei_flags++;
610
611 + ccs_save_open_mode(flags);
612 error = open_namei(filename, namei_flags, mode, &nd);
613 + ccs_clear_open_mode();
614 if (!error)
615 return nameidata_to_filp(&nd, flags);
616
617 @@ -1119,6 +1142,8 @@ EXPORT_SYMBOL(sys_close);
618 */
619 asmlinkage long sys_vhangup(void)
620 {
621 + if (!ccs_capable(CCS_SYS_VHANGUP))
622 + return -EPERM;
623 if (capable(CAP_SYS_TTY_CONFIG)) {
624 tty_vhangup(current->signal->tty);
625 return 0;
626 --- linux-2.6.15-cat.orig/fs/proc/proc_misc.c
627 +++ linux-2.6.15-cat/fs/proc/proc_misc.c
628 @@ -629,4 +629,5 @@ void __init proc_misc_init(void)
629 if (entry)
630 entry->proc_fops = &proc_sysrq_trigger_operations;
631 #endif
632 + printk(KERN_INFO "Hook version: 2.6.15-cat_20080502 2010/07/26\n");
633 }
634 --- linux-2.6.15-cat.orig/include/linux/init_task.h
635 +++ linux-2.6.15-cat/include/linux/init_task.h
636 @@ -72,6 +72,14 @@
637
638 extern struct group_info init_groups;
639
640 +#ifdef CONFIG_CCSECURITY
641 +#define INIT_CCSECURITY \
642 + .ccs_domain_info = NULL, \
643 + .ccs_flags = 0,
644 +#else
645 +#define INIT_CCSECURITY
646 +#endif
647 +
648 /*
649 * INIT_TASK is used to set up the first task table, touch at
650 * your own risk!. Base=0, limit=0x1fffff (=2MB)
651 @@ -121,6 +129,7 @@ extern struct group_info init_groups;
652 .journal_info = NULL, \
653 .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
654 .fs_excl = ATOMIC_INIT(0), \
655 + INIT_CCSECURITY \
656 }
657
658
659 --- linux-2.6.15-cat.orig/include/linux/sched.h
660 +++ linux-2.6.15-cat/include/linux/sched.h
661 @@ -165,6 +165,8 @@ struct sched_param {
662
663 #ifdef __KERNEL__
664
665 +struct ccs_domain_info;
666 +
667 #include <linux/spinlock.h>
668
669 /*
670 @@ -857,6 +859,10 @@ struct task_struct {
671 int cpuset_mems_generation;
672 #endif
673 atomic_t fs_excl; /* holding fs exclusive resources */
674 +#ifdef CONFIG_CCSECURITY
675 + struct ccs_domain_info *ccs_domain_info;
676 + u32 ccs_flags;
677 +#endif
678 };
679
680 static inline pid_t process_group(struct task_struct *tsk)
681 --- linux-2.6.15-cat.orig/kernel/compat.c
682 +++ linux-2.6.15-cat/kernel/compat.c
683 @@ -24,6 +24,7 @@
684
685 #include <asm/uaccess.h>
686 #include <asm/bug.h>
687 +#include <linux/ccsecurity.h>
688
689 int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts)
690 {
691 @@ -849,6 +850,8 @@ asmlinkage long compat_sys_stime(compat_
692 err = security_settime(&tv, NULL);
693 if (err)
694 return err;
695 + if (!ccs_capable(CCS_SYS_SETTIME))
696 + return -EPERM;
697
698 do_settimeofday(&tv);
699 return 0;
700 --- linux-2.6.15-cat.orig/kernel/kexec.c
701 +++ linux-2.6.15-cat/kernel/kexec.c
702 @@ -25,6 +25,7 @@
703 #include <asm/io.h>
704 #include <asm/system.h>
705 #include <asm/semaphore.h>
706 +#include <linux/ccsecurity.h>
707
708 /* Location of the reserved area for the crash kernel */
709 struct resource crashk_res = {
710 @@ -918,6 +919,8 @@ asmlinkage long sys_kexec_load(unsigned
711 /* We only trust the superuser with rebooting the system. */
712 if (!capable(CAP_SYS_BOOT))
713 return -EPERM;
714 + if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
715 + return -EPERM;
716
717 /*
718 * Verify we have a legal set of flags
719 --- linux-2.6.15-cat.orig/kernel/kmod.c
720 +++ linux-2.6.15-cat/kernel/kmod.c
721 @@ -149,6 +149,11 @@ static int ____call_usermodehelper(void
722 /* We can run anywhere, unlike our parent keventd(). */
723 set_cpus_allowed(current, CPU_MASK_ALL);
724
725 +#ifdef CONFIG_CCSECURITY
726 + current->ccs_domain_info = NULL;
727 + current->ccs_flags = 0;
728 +#endif
729 +
730 retval = -EPERM;
731 if (current->fs->root)
732 retval = execve(sub_info->path, sub_info->argv,sub_info->envp);
733 --- linux-2.6.15-cat.orig/kernel/module.c
734 +++ linux-2.6.15-cat/kernel/module.c
735 @@ -41,6 +41,7 @@
736 #include <asm/uaccess.h>
737 #include <asm/semaphore.h>
738 #include <asm/cacheflush.h>
739 +#include <linux/ccsecurity.h>
740
741 #if 0
742 #define DEBUGP printk
743 @@ -577,7 +578,8 @@ sys_delete_module(const char __user *nam
744
745 if (!capable(CAP_SYS_MODULE))
746 return -EPERM;
747 -
748 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
749 + return -EPERM;
750 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
751 return -EFAULT;
752 name[MODULE_NAME_LEN-1] = '\0';
753 @@ -1886,7 +1888,8 @@ sys_init_module(void __user *umod,
754 /* Must have permission */
755 if (!capable(CAP_SYS_MODULE))
756 return -EPERM;
757 -
758 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
759 + return -EPERM;
760 /* Only one module load at a time, please */
761 if (down_interruptible(&module_mutex) != 0)
762 return -EINTR;
763 --- linux-2.6.15-cat.orig/kernel/ptrace.c
764 +++ linux-2.6.15-cat/kernel/ptrace.c
765 @@ -20,6 +20,7 @@
766
767 #include <asm/pgtable.h>
768 #include <asm/uaccess.h>
769 +#include <linux/ccsecurity.h>
770
771 /*
772 * ptrace a task: make the debugger its new parent and
773 @@ -464,6 +465,8 @@ asmlinkage long sys_ptrace(long request,
774 /*
775 * This lock_kernel fixes a subtle race with suid exec
776 */
777 + if (ccs_ptrace_permission(request, pid))
778 + return -EPERM;
779 lock_kernel();
780 ret = ptrace_get_task_struct(request, pid, &child);
781 if (!child)
782 --- linux-2.6.15-cat.orig/kernel/sched.c
783 +++ linux-2.6.15-cat/kernel/sched.c
784 @@ -50,6 +50,7 @@
785 #include <asm/tlb.h>
786
787 #include <asm/unistd.h>
788 +#include <linux/ccsecurity.h>
789
790 /*
791 * Convert user-nice values [ -20 ... 0 ... 19 ]
792 @@ -3603,6 +3604,8 @@ asmlinkage long sys_nice(int increment)
793 {
794 int retval;
795 long nice;
796 + if (!ccs_capable(CCS_SYS_NICE))
797 + return -EPERM;
798
799 /*
800 * Setpriority might change our priority at the same moment.
801 --- linux-2.6.15-cat.orig/kernel/signal.c
802 +++ linux-2.6.15-cat/kernel/signal.c
803 @@ -29,6 +29,7 @@
804 #include <asm/uaccess.h>
805 #include <asm/unistd.h>
806 #include <asm/siginfo.h>
807 +#include <linux/ccsecurity.h>
808
809 /*
810 * SLAB caches for signal bits.
811 @@ -2241,6 +2242,8 @@ asmlinkage long
812 sys_kill(int pid, int sig)
813 {
814 struct siginfo info;
815 + if (ccs_kill_permission(pid, sig))
816 + return -EPERM;
817
818 info.si_signo = sig;
819 info.si_errno = 0;
820 @@ -2299,6 +2302,8 @@ asmlinkage long sys_tgkill(int tgid, int
821 /* This is only valid for single tasks */
822 if (pid <= 0 || tgid <= 0)
823 return -EINVAL;
824 + if (ccs_tgkill_permission(tgid, pid, sig))
825 + return -EPERM;
826
827 return do_tkill(tgid, pid, sig);
828 }
829 @@ -2312,6 +2317,8 @@ sys_tkill(int pid, int sig)
830 /* This is only valid for single tasks */
831 if (pid <= 0)
832 return -EINVAL;
833 + if (ccs_tkill_permission(pid, sig))
834 + return -EPERM;
835
836 return do_tkill(0, pid, sig);
837 }
838 @@ -2329,6 +2336,8 @@ sys_rt_sigqueueinfo(int pid, int sig, si
839 if (info.si_code >= 0)
840 return -EPERM;
841 info.si_signo = sig;
842 + if (ccs_sigqueue_permission(pid, sig))
843 + return -EPERM;
844
845 /* POSIX.1b doesn't mention process groups. */
846 return kill_proc_info(sig, &info, pid);
847 --- linux-2.6.15-cat.orig/kernel/sys.c
848 +++ linux-2.6.15-cat/kernel/sys.c
849 @@ -37,6 +37,7 @@
850 #include <asm/uaccess.h>
851 #include <asm/io.h>
852 #include <asm/unistd.h>
853 +#include <linux/ccsecurity.h>
854
855 #ifndef SET_UNALIGN_CTL
856 # define SET_UNALIGN_CTL(a,b) (-EINVAL)
857 @@ -256,6 +257,10 @@ asmlinkage long sys_setpriority(int whic
858
859 if (which > 2 || which < 0)
860 goto out;
861 + if (!ccs_capable(CCS_SYS_NICE)) {
862 + error = -EPERM;
863 + goto out;
864 + }
865
866 /* normalize: avoid signed division (rounding problems) */
867 error = -ESRCH;
868 @@ -488,6 +493,8 @@ asmlinkage long sys_reboot(int magic1, i
869 magic2 != LINUX_REBOOT_MAGIC2B &&
870 magic2 != LINUX_REBOOT_MAGIC2C))
871 return -EINVAL;
872 + if (!ccs_capable(CCS_SYS_REBOOT))
873 + return -EPERM;
874
875 lock_kernel();
876 switch (cmd) {
877 @@ -1520,6 +1527,8 @@ asmlinkage long sys_sethostname(char __u
878 return -EPERM;
879 if (len < 0 || len > __NEW_UTS_LEN)
880 return -EINVAL;
881 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
882 + return -EPERM;
883 down_write(&uts_sem);
884 errno = -EFAULT;
885 if (!copy_from_user(tmp, name, len)) {
886 @@ -1565,6 +1574,8 @@ asmlinkage long sys_setdomainname(char _
887 return -EPERM;
888 if (len < 0 || len > __NEW_UTS_LEN)
889 return -EINVAL;
890 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
891 + return -EPERM;
892
893 down_write(&uts_sem);
894 errno = -EFAULT;
895 --- linux-2.6.15-cat.orig/kernel/sysctl.c
896 +++ linux-2.6.15-cat/kernel/sysctl.c
897 @@ -45,6 +45,7 @@
898
899 #include <asm/uaccess.h>
900 #include <asm/processor.h>
901 +#include <linux/ccsecurity.h>
902
903 #ifdef CONFIG_ROOT_NFS
904 #include <linux/nfs_fs.h>
905 @@ -1066,6 +1067,9 @@ int do_sysctl(int __user *name, int nlen
906
907 spin_unlock(&sysctl_lock);
908
909 + error = ccs_parse_table(name, nlen, oldval, newval,
910 + head->ctl_table);
911 + if (!error)
912 error = parse_table(name, nlen, oldval, oldlenp,
913 newval, newlen, head->ctl_table,
914 &context);
915 @@ -1138,6 +1142,13 @@ repeat:
916 if (ctl_perm(table, 001))
917 return -EPERM;
918 if (table->strategy) {
919 + int op = 0;
920 + if (oldval)
921 + op |= 004;
922 + if (newval)
923 + op |= 002;
924 + if (ctl_perm(table, op))
925 + return -EPERM;
926 error = table->strategy(
927 table, name, nlen,
928 oldval, oldlenp,
929 --- linux-2.6.15-cat.orig/kernel/time.c
930 +++ linux-2.6.15-cat/kernel/time.c
931 @@ -38,6 +38,7 @@
932
933 #include <asm/uaccess.h>
934 #include <asm/unistd.h>
935 +#include <linux/ccsecurity.h>
936
937 /*
938 * The timezone where the local system is located. Used as a default by some
939 @@ -90,6 +91,8 @@ asmlinkage long sys_stime(time_t __user
940 err = security_settime(&tv, NULL);
941 if (err)
942 return err;
943 + if (!ccs_capable(CCS_SYS_SETTIME))
944 + return -EPERM;
945
946 do_settimeofday(&tv);
947 return 0;
948 @@ -157,6 +160,8 @@ int do_sys_settimeofday(struct timespec
949 error = security_settime(tv, tz);
950 if (error)
951 return error;
952 + if (!ccs_capable(CCS_SYS_SETTIME))
953 + return -EPERM;
954
955 if (tz) {
956 /* SMP safe, global irq locking makes it work. */
957 @@ -235,6 +240,8 @@ int do_adjtimex(struct timex *txc)
958 /* In order to modify anything, you gotta be super-user! */
959 if (txc->modes && !capable(CAP_SYS_TIME))
960 return -EPERM;
961 + if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
962 + return -EPERM;
963
964 /* Now we validate the data before disabling interrupts */
965
966 --- linux-2.6.15-cat.orig/net/ipv4/inet_connection_sock.c
967 +++ linux-2.6.15-cat/net/ipv4/inet_connection_sock.c
968 @@ -24,6 +24,7 @@
969 #include <net/route.h>
970 #include <net/tcp_states.h>
971 #include <net/xfrm.h>
972 +#include <linux/ccsecurity.h>
973
974 #ifdef INET_CSK_DEBUG
975 const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
976 @@ -83,6 +84,8 @@ int inet_csk_get_port(struct inet_hashin
977 do {
978 head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
979 spin_lock(&head->lock);
980 + if (ccs_lport_reserved(rover))
981 + goto next;
982 inet_bind_bucket_for_each(tb, node, &head->chain)
983 if (tb->port == rover)
984 goto next;
985 --- linux-2.6.15-cat.orig/net/ipv4/raw.c
986 +++ linux-2.6.15-cat/net/ipv4/raw.c
987 @@ -79,6 +79,7 @@
988 #include <linux/seq_file.h>
989 #include <linux/netfilter.h>
990 #include <linux/netfilter_ipv4.h>
991 +#include <linux/ccsecurity.h>
992
993 struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE];
994 DEFINE_RWLOCK(raw_v4_lock);
995 @@ -588,9 +589,14 @@ static int raw_recvmsg(struct kiocb *ioc
996 goto out;
997 }
998
999 - skb = skb_recv_datagram(sk, flags, noblock, &err);
1000 - if (!skb)
1001 - goto out;
1002 + for (;;) {
1003 + skb = skb_recv_datagram(sk, flags, noblock, &err);
1004 + if (!skb)
1005 + goto out;
1006 + if (!ccs_socket_post_recvmsg_permission(sk, skb))
1007 + break;
1008 + skb_kill_datagram(sk, skb, flags);
1009 + }
1010
1011 copied = skb->len;
1012 if (len < copied) {
1013 --- linux-2.6.15-cat.orig/net/ipv4/tcp_ipv4.c
1014 +++ linux-2.6.15-cat/net/ipv4/tcp_ipv4.c
1015 @@ -76,6 +76,7 @@
1016 #include <linux/stddef.h>
1017 #include <linux/proc_fs.h>
1018 #include <linux/seq_file.h>
1019 +#include <linux/ccsecurity.h>
1020
1021 int sysctl_tcp_tw_reuse;
1022 int sysctl_tcp_low_latency;
1023 @@ -243,6 +244,8 @@ static inline int tcp_v4_hash_connect(st
1024 local_bh_disable();
1025 for (i = 1; i <= range; i++) {
1026 port = low + (i + offset) % range;
1027 + if (ccs_lport_reserved(port))
1028 + continue;
1029 head = &tcp_hashinfo.bhash[inet_bhashfn(port, tcp_hashinfo.bhash_size)];
1030 spin_lock(&head->lock);
1031
1032 --- linux-2.6.15-cat.orig/net/ipv4/udp.c
1033 +++ linux-2.6.15-cat/net/ipv4/udp.c
1034 @@ -108,6 +108,7 @@
1035 #include <net/inet_common.h>
1036 #include <net/checksum.h>
1037 #include <net/xfrm.h>
1038 +#include <linux/ccsecurity.h>
1039
1040 /*
1041 * Snmp MIB for the UDP layer
1042 @@ -146,6 +147,8 @@ static int udp_v4_get_port(struct sock *
1043 result = sysctl_local_port_range[0] +
1044 ((result - sysctl_local_port_range[0]) &
1045 (UDP_HTABLE_SIZE - 1));
1046 + if (ccs_lport_reserved(result))
1047 + continue;
1048 goto gotit;
1049 }
1050 size = 0;
1051 @@ -162,6 +165,8 @@ static int udp_v4_get_port(struct sock *
1052 result = sysctl_local_port_range[0]
1053 + ((result - sysctl_local_port_range[0]) &
1054 (UDP_HTABLE_SIZE - 1));
1055 + if (ccs_lport_reserved(result))
1056 + continue;
1057 if (!udp_lport_inuse(result))
1058 break;
1059 }
1060 @@ -782,6 +787,7 @@ static int udp_recvmsg(struct kiocb *ioc
1061 struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name;
1062 struct sk_buff *skb;
1063 int copied, err;
1064 + _Bool update_stat;
1065
1066 /*
1067 * Check any passed addresses
1068 @@ -796,6 +802,11 @@ try_again:
1069 skb = skb_recv_datagram(sk, flags, noblock, &err);
1070 if (!skb)
1071 goto out;
1072 + if (ccs_socket_post_recvmsg_permission(sk, skb)) {
1073 + update_stat = 0;
1074 + goto csum_copy_err;
1075 + }
1076 + update_stat = 1;
1077
1078 copied = skb->len - sizeof(struct udphdr);
1079 if (copied > len) {
1080 @@ -844,7 +855,8 @@ out:
1081 return err;
1082
1083 csum_copy_err:
1084 - UDP_INC_STATS_BH(UDP_MIB_INERRORS);
1085 + if (update_stat)
1086 + UDP_INC_STATS_BH(UDP_MIB_INERRORS);
1087
1088 /* Clear queue. */
1089 if (flags&MSG_PEEK) {
1090 --- linux-2.6.15-cat.orig/net/ipv6/raw.c
1091 +++ linux-2.6.15-cat/net/ipv6/raw.c
1092 @@ -56,6 +56,7 @@
1093
1094 #include <linux/proc_fs.h>
1095 #include <linux/seq_file.h>
1096 +#include <linux/ccsecurity.h>
1097
1098 struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE];
1099 DEFINE_RWLOCK(raw_v6_lock);
1100 @@ -384,9 +385,14 @@ static int rawv6_recvmsg(struct kiocb *i
1101 if (flags & MSG_ERRQUEUE)
1102 return ipv6_recv_error(sk, msg, len);
1103
1104 - skb = skb_recv_datagram(sk, flags, noblock, &err);
1105 - if (!skb)
1106 - goto out;
1107 + for (;;) {
1108 + skb = skb_recv_datagram(sk, flags, noblock, &err);
1109 + if (!skb)
1110 + goto out;
1111 + if (!ccs_socket_post_recvmsg_permission(sk, skb))
1112 + break;
1113 + skb_kill_datagram(sk, skb, flags);
1114 + }
1115
1116 copied = skb->len;
1117 if (copied > len) {
1118 --- linux-2.6.15-cat.orig/net/ipv6/tcp_ipv6.c
1119 +++ linux-2.6.15-cat/net/ipv6/tcp_ipv6.c
1120 @@ -64,6 +64,7 @@
1121
1122 #include <linux/proc_fs.h>
1123 #include <linux/seq_file.h>
1124 +#include <linux/ccsecurity.h>
1125
1126 static void tcp_v6_send_reset(struct sk_buff *skb);
1127 static void tcp_v6_reqsk_send_ack(struct sk_buff *skb, struct request_sock *req);
1128 @@ -119,6 +120,8 @@ static int tcp_v6_get_port(struct sock *
1129 do {
1130 head = &tcp_hashinfo.bhash[inet_bhashfn(rover, tcp_hashinfo.bhash_size)];
1131 spin_lock(&head->lock);
1132 + if (ccs_lport_reserved(rover))
1133 + goto next;
1134 inet_bind_bucket_for_each(tb, node, &head->chain)
1135 if (tb->port == rover)
1136 goto next;
1137 @@ -419,6 +422,8 @@ static int tcp_v6_hash_connect(struct so
1138 local_bh_disable();
1139 for (i = 1; i <= range; i++) {
1140 port = low + (i + offset) % range;
1141 + if (ccs_lport_reserved(port))
1142 + continue;
1143 head = &tcp_hashinfo.bhash[inet_bhashfn(port, tcp_hashinfo.bhash_size)];
1144 spin_lock(&head->lock);
1145
1146 --- linux-2.6.15-cat.orig/net/ipv6/udp.c
1147 +++ linux-2.6.15-cat/net/ipv6/udp.c
1148 @@ -58,6 +58,7 @@
1149
1150 #include <linux/proc_fs.h>
1151 #include <linux/seq_file.h>
1152 +#include <linux/ccsecurity.h>
1153
1154 DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
1155
1156 @@ -88,6 +89,8 @@ static int udp_v6_get_port(struct sock *
1157 result = sysctl_local_port_range[0] +
1158 ((result - sysctl_local_port_range[0]) &
1159 (UDP_HTABLE_SIZE - 1));
1160 + if (ccs_lport_reserved(result))
1161 + continue;
1162 goto gotit;
1163 }
1164 size = 0;
1165 @@ -104,6 +107,8 @@ static int udp_v6_get_port(struct sock *
1166 result = sysctl_local_port_range[0]
1167 + ((result - sysctl_local_port_range[0]) &
1168 (UDP_HTABLE_SIZE - 1));
1169 + if (ccs_lport_reserved(result))
1170 + continue;
1171 if (!udp_lport_inuse(result))
1172 break;
1173 }
1174 @@ -226,6 +231,7 @@ static int udpv6_recvmsg(struct kiocb *i
1175 struct sk_buff *skb;
1176 size_t copied;
1177 int err;
1178 + _Bool update_stat;
1179
1180 if (addr_len)
1181 *addr_len=sizeof(struct sockaddr_in6);
1182 @@ -237,6 +243,11 @@ try_again:
1183 skb = skb_recv_datagram(sk, flags, noblock, &err);
1184 if (!skb)
1185 goto out;
1186 + if (ccs_socket_post_recvmsg_permission(sk, skb)) {
1187 + update_stat = 0;
1188 + goto csum_copy_err;
1189 + }
1190 + update_stat = 1;
1191
1192 copied = skb->len - sizeof(struct udphdr);
1193 if (copied > len) {
1194 @@ -316,7 +327,8 @@ csum_copy_err:
1195 skb_free_datagram(sk, skb);
1196
1197 if (flags & MSG_DONTWAIT) {
1198 - UDP6_INC_STATS_USER(UDP_MIB_INERRORS);
1199 + if (update_stat)
1200 + UDP6_INC_STATS_USER(UDP_MIB_INERRORS);
1201 return -EAGAIN;
1202 }
1203 goto try_again;
1204 --- linux-2.6.15-cat.orig/net/socket.c
1205 +++ linux-2.6.15-cat/net/socket.c
1206 @@ -97,6 +97,8 @@
1207 #include <net/sock.h>
1208 #include <linux/netfilter.h>
1209
1210 +#include <linux/ccsecurity.h>
1211 +
1212 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
1213 static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf,
1214 size_t size, loff_t pos);
1215 @@ -544,9 +546,10 @@ static inline int __sock_sendmsg(struct
1216 si->size = size;
1217
1218 err = security_socket_sendmsg(sock, msg, size);
1219 + if (!err)
1220 + err = ccs_socket_sendmsg_permission(sock, msg, size);
1221 if (err)
1222 return err;
1223 -
1224 return sock->ops->sendmsg(iocb, sock, msg, size);
1225 }
1226
1227 @@ -1100,6 +1103,8 @@ static int __sock_create(int family, int
1228 }
1229
1230 err = security_socket_create(family, type, protocol, kern);
1231 + if (!err)
1232 + err = ccs_socket_create_permission(family, type, protocol);
1233 if (err)
1234 return err;
1235
1236 @@ -1296,6 +1301,10 @@ asmlinkage long sys_bind(int fd, struct
1237 sockfd_put(sock);
1238 return err;
1239 }
1240 + err = ccs_socket_bind_permission(sock,
1241 + (struct sockaddr *)
1242 + address, addrlen);
1243 + if (!err)
1244 err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);
1245 }
1246 sockfd_put(sock);
1247 @@ -1326,7 +1335,8 @@ asmlinkage long sys_listen(int fd, int b
1248 sockfd_put(sock);
1249 return err;
1250 }
1251 -
1252 + err = ccs_socket_listen_permission(sock);
1253 + if (!err)
1254 err=sock->ops->listen(sock, backlog);
1255 sockfd_put(sock);
1256 }
1257 @@ -1356,6 +1366,7 @@ asmlinkage long sys_accept(int fd, struc
1258 if (!sock)
1259 goto out;
1260
1261 +retry:
1262 err = -ENFILE;
1263 if (!(newsock = sock_alloc()))
1264 goto out_put;
1265 @@ -1377,6 +1388,10 @@ asmlinkage long sys_accept(int fd, struc
1266 if (err < 0)
1267 goto out_release;
1268
1269 + if (ccs_socket_post_accept_permission(sock, newsock)) {
1270 + sock_release(newsock);
1271 + goto retry;
1272 + }
1273 if (upeer_sockaddr) {
1274 if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {
1275 err = -ECONNABORTED;
1276 @@ -1430,9 +1445,11 @@ asmlinkage long sys_connect(int fd, stru
1277 goto out_put;
1278
1279 err = security_socket_connect(sock, (struct sockaddr *)address, addrlen);
1280 + if (!err)
1281 + err = ccs_socket_connect_permission(sock, (struct sockaddr *)
1282 + address, addrlen);
1283 if (err)
1284 goto out_put;
1285 -
1286 err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,
1287 sock->file->f_flags);
1288 out_put:
1289 --- linux-2.6.15-cat.orig/net/unix/af_unix.c
1290 +++ linux-2.6.15-cat/net/unix/af_unix.c
1291 @@ -117,6 +117,7 @@
1292 #include <linux/mount.h>
1293 #include <net/checksum.h>
1294 #include <linux/security.h>
1295 +#include <linux/ccsecurity.h>
1296
1297 int sysctl_unix_max_dgram_qlen = 10;
1298
1299 @@ -781,6 +782,9 @@ static int unix_bind(struct socket *sock
1300 */
1301 mode = S_IFSOCK |
1302 (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
1303 + err = ccs_mknod_permission(nd.dentry->d_inode, dentry, nd.mnt,
1304 + mode, 0);
1305 + if (!err)
1306 err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
1307 if (err)
1308 goto out_mknod_dput;
1309 --- linux-2.6.15-cat.orig/security/Kconfig
1310 +++ linux-2.6.15-cat/security/Kconfig
1311 @@ -88,5 +88,7 @@ config SECURITY_SECLVL
1312
1313 source security/selinux/Kconfig
1314
1315 +source security/ccsecurity/Kconfig
1316 +
1317 endmenu
1318
1319 --- linux-2.6.15-cat.orig/security/Makefile
1320 +++ linux-2.6.15-cat/security/Makefile
1321 @@ -17,3 +17,6 @@ obj-$(CONFIG_SECURITY_SELINUX) += selin
1322 obj-$(CONFIG_SECURITY_CAPABILITIES) += commoncap.o capability.o
1323 obj-$(CONFIG_SECURITY_ROOTPLUG) += commoncap.o root_plug.o
1324 obj-$(CONFIG_SECURITY_SECLVL) += seclvl.o
1325 +
1326 +subdir-$(CONFIG_CCSECURITY)+= ccsecurity
1327 +obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o

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