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

Subversion リポジトリの参照

Contents of /trunk/1.8.x/ccs-patch/patches/ccs-patch-2.6.18-debian-etch.diff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4049 - (show annotations) (download) (as text)
Thu Oct 7 07:14:01 2010 UTC (13 years, 7 months ago) by kumaneko
File MIME type: text/x-diff
File size: 39776 byte(s)
Merge branches/ccs-patch/ into trunk/1.8.x/ccs-patch/
1 This is TOMOYO Linux patch for Debian Etch.
2
3 Source code for this patch is "apt-get install linux-source-2.6.18"
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 | 5 +++++
18 fs/ioctl.c | 3 +++
19 fs/namei.c | 31 +++++++++++++++++++++++++++++++
20 fs/namespace.c | 9 +++++++++
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/inet_hashtables.c | 3 +++
37 net/ipv4/raw.c | 12 +++++++++---
38 net/ipv4/udp.c | 16 ++++++++++++++--
39 net/ipv6/inet6_hashtables.c | 5 ++++-
40 net/ipv6/raw.c | 12 +++++++++---
41 net/ipv6/udp.c | 14 +++++++++++++-
42 net/socket.c | 24 ++++++++++++++++++++++--
43 net/unix/af_unix.c | 9 +++++++++
44 security/Kconfig | 2 ++
45 security/Makefile | 3 +++
46 41 files changed, 295 insertions(+), 16 deletions(-)
47
48 --- linux-2.6.18-26etch2.orig/arch/alpha/kernel/ptrace.c
49 +++ linux-2.6.18-26etch2/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 @@ -268,6 +269,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.18-26etch2.orig/arch/ia64/ia32/sys_ia32.c
68 +++ linux-2.6.18-26etch2/arch/ia64/ia32/sys_ia32.c
69 @@ -56,6 +56,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 @@ -1741,6 +1742,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.18-26etch2.orig/arch/ia64/kernel/ptrace.c
87 +++ linux-2.6.18-26etch2/arch/ia64/kernel/ptrace.c
88 @@ -28,6 +28,7 @@
89 #ifdef CONFIG_PERFMON
90 #include <asm/perfmon.h>
91 #endif
92 +#include <linux/ccsecurity.h>
93
94 #include "entry.h"
95
96 @@ -1417,6 +1418,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.18-26etch2.orig/arch/m32r/kernel/ptrace.c
106 +++ linux-2.6.18-26etch2/arch/m32r/kernel/ptrace.c
107 @@ -32,6 +32,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 * This routine will get a word off of the process kernel stack.
115 @@ -742,6 +743,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 if (request == PTRACE_TRACEME) {
124 --- linux-2.6.18-26etch2.orig/arch/mips/kernel/ptrace32.c
125 +++ linux-2.6.18-26etch2/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.18-26etch2.orig/arch/powerpc/kernel/ptrace32.c
144 +++ linux-2.6.18-26etch2/arch/powerpc/kernel/ptrace32.c
145 @@ -32,6 +32,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 @@ -45,6 +46,8 @@ long compat_sys_ptrace(int request, int
154 {
155 struct task_struct *child;
156 int ret;
157 + if (ccs_ptrace_permission(request, pid))
158 + return -EPERM;
159
160 lock_kernel();
161 if (request == PTRACE_TRACEME) {
162 --- linux-2.6.18-26etch2.orig/arch/s390/kernel/ptrace.c
163 +++ linux-2.6.18-26etch2/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_COMPAT
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 if (request == PTRACE_TRACEME) {
180 ret = ptrace_traceme();
181 --- linux-2.6.18-26etch2.orig/arch/sparc/kernel/ptrace.c
182 +++ linux-2.6.18-26etch2/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.18-26etch2.orig/arch/sparc64/kernel/ptrace.c
203 +++ linux-2.6.18-26etch2/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 @@ -176,6 +177,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.18-26etch2.orig/arch/x86_64/ia32/ptrace32.c
224 +++ linux-2.6.18-26etch2/arch/x86_64/ia32/ptrace32.c
225 @@ -26,6 +26,7 @@
226 #include <asm/i387.h>
227 #include <asm/fpu32.h>
228 #include <asm/ia32.h>
229 +#include <linux/ccsecurity.h>
230
231 /*
232 * Determines which flags the user has access to [1 = access, 0 = no access].
233 @@ -230,6 +231,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 case PTRACE_TRACEME:
242 --- linux-2.6.18-26etch2.orig/fs/compat.c
243 +++ linux-2.6.18-26etch2/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 extern void sigset_from_compat(sigset_t *set, compat_sigset_t *compat);
251
252 @@ -397,6 +398,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 @@ -421,6 +424,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 @@ -1567,7 +1574,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.18-26etch2.orig/fs/exec.c
282 +++ linux-2.6.18-26etch2/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 @@ -486,6 +492,9 @@ struct file *open_exec(const char *name)
304 if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&
305 S_ISREG(inode->i_mode)) {
306 int err = vfs_permission(&nd, MAY_EXEC);
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 @@ -1188,7 +1197,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.18-26etch2.orig/fs/fcntl.c
324 +++ linux-2.6.18-26etch2/fs/fcntl.c
325 @@ -22,6 +22,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 @@ -361,6 +362,8 @@ asmlinkage long sys_fcntl(unsigned int f
334 goto out;
335
336 err = security_file_fcntl(filp, cmd, arg);
337 + if (!err)
338 + err = ccs_fcntl_permission(filp, cmd, arg);
339 if (err) {
340 fput(filp);
341 return err;
342 @@ -385,6 +388,8 @@ asmlinkage long sys_fcntl64(unsigned int
343 goto out;
344
345 err = security_file_fcntl(filp, cmd, arg);
346 + if (!err)
347 + err = ccs_fcntl_permission(filp, cmd, arg);
348 if (err) {
349 fput(filp);
350 return err;
351 --- linux-2.6.18-26etch2.orig/fs/ioctl.c
352 +++ linux-2.6.18-26etch2/fs/ioctl.c
353 @@ -15,6 +15,7 @@
354
355 #include <asm/uaccess.h>
356 #include <asm/ioctls.h>
357 +#include <linux/ccsecurity.h>
358
359 static long do_ioctl(struct file *filp, unsigned int cmd,
360 unsigned long arg)
361 @@ -167,6 +168,8 @@ asmlinkage long sys_ioctl(unsigned int f
362 goto out;
363
364 error = security_file_ioctl(filp, cmd, arg);
365 + if (!error)
366 + error = ccs_ioctl_permission(filp, cmd, arg);
367 if (error)
368 goto out_fput;
369
370 --- linux-2.6.18-26etch2.orig/fs/namei.c
371 +++ linux-2.6.18-26etch2/fs/namei.c
372 @@ -37,6 +37,8 @@
373
374 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
375
376 +#include <linux/ccsecurity.h>
377 +
378 /* [Feb-1997 T. Schoebel-Theuer]
379 * Fundamental changes in the pathname lookup mechanisms (namei)
380 * were necessary because of omirr. The reason is that omirr needs
381 @@ -1536,6 +1538,11 @@ int may_open(struct nameidata *nd, int a
382 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
383 return -EPERM;
384
385 + /* includes O_APPEND and O_TRUNC checks */
386 + error = ccs_open_permission(dentry, nd->mnt, flag);
387 + if (error)
388 + return error;
389 +
390 /*
391 * Ensure there are no outstanding leases on the file.
392 */
393 @@ -1650,6 +1657,9 @@ do_last:
394 if (!path.dentry->d_inode) {
395 if (!IS_POSIXACL(dir->d_inode))
396 mode &= ~current->fs->umask;
397 + error = ccs_mknod_permission(dir->d_inode, path.dentry,
398 + nd->mnt, mode, 0);
399 + if (!error)
400 error = vfs_create(dir->d_inode, path.dentry, mode, nd);
401 mutex_unlock(&dir->d_inode->i_mutex);
402 dput(nd->dentry);
403 @@ -1848,6 +1858,9 @@ asmlinkage long sys_mknodat(int dfd, con
404 if (!IS_POSIXACL(nd.dentry->d_inode))
405 mode &= ~current->fs->umask;
406 if (!IS_ERR(dentry)) {
407 + error = ccs_mknod_permission(nd.dentry->d_inode, dentry,
408 + nd.mnt, mode, dev);
409 + if (!error)
410 switch (mode & S_IFMT) {
411 case 0: case S_IFREG:
412 error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
413 @@ -1921,6 +1934,9 @@ asmlinkage long sys_mkdirat(int dfd, con
414 if (!IS_ERR(dentry)) {
415 if (!IS_POSIXACL(nd.dentry->d_inode))
416 mode &= ~current->fs->umask;
417 + error = ccs_mkdir_permission(nd.dentry->d_inode,
418 + dentry, nd.mnt, mode);
419 + if (!error)
420 error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
421 dput(dentry);
422 }
423 @@ -2029,6 +2045,9 @@ static long do_rmdir(int dfd, const char
424 dentry = lookup_hash(&nd);
425 error = PTR_ERR(dentry);
426 if (!IS_ERR(dentry)) {
427 + error = ccs_rmdir_permission(nd.dentry->d_inode, dentry,
428 + nd.mnt);
429 + if (!error)
430 error = vfs_rmdir(nd.dentry->d_inode, dentry);
431 dput(dentry);
432 }
433 @@ -2109,6 +2128,9 @@ static long do_unlinkat(int dfd, const c
434 inode = dentry->d_inode;
435 if (inode)
436 atomic_inc(&inode->i_count);
437 + error = ccs_unlink_permission(nd.dentry->d_inode, dentry,
438 + nd.mnt);
439 + if (!error)
440 error = vfs_unlink(nd.dentry->d_inode, dentry);
441 exit2:
442 dput(dentry);
443 @@ -2187,6 +2209,9 @@ asmlinkage long sys_symlinkat(const char
444 dentry = lookup_create(&nd, 0);
445 error = PTR_ERR(dentry);
446 if (!IS_ERR(dentry)) {
447 + error = ccs_symlink_permission(nd.dentry->d_inode,
448 + dentry, nd.mnt, from);
449 + if (!error)
450 error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
451 dput(dentry);
452 }
453 @@ -2281,6 +2306,9 @@ asmlinkage long sys_linkat(int olddfd, c
454 new_dentry = lookup_create(&nd, 0);
455 error = PTR_ERR(new_dentry);
456 if (!IS_ERR(new_dentry)) {
457 + error = ccs_link_permission(old_nd.dentry, nd.dentry->d_inode,
458 + new_dentry, nd.mnt);
459 + if (!error)
460 error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
461 dput(new_dentry);
462 }
463 @@ -2507,6 +2535,9 @@ static int do_rename(int olddfd, const c
464 if (new_dentry == trap)
465 goto exit5;
466
467 + error = ccs_rename_permission(old_dir->d_inode, old_dentry,
468 + new_dir->d_inode, new_dentry, newnd.mnt);
469 + if (!error)
470 error = vfs_rename(old_dir->d_inode, old_dentry,
471 new_dir->d_inode, new_dentry);
472 exit5:
473 --- linux-2.6.18-26etch2.orig/fs/namespace.c
474 +++ linux-2.6.18-26etch2/fs/namespace.c
475 @@ -25,6 +25,7 @@
476 #include <asm/uaccess.h>
477 #include <asm/unistd.h>
478 #include "pnode.h"
479 +#include <linux/ccsecurity.h>
480
481 extern int __init init_rootfs(void);
482
483 @@ -550,6 +551,8 @@ static int do_umount(struct vfsmount *mn
484 LIST_HEAD(umount_list);
485
486 retval = security_sb_umount(mnt, flags);
487 + if (!retval)
488 + retval = ccs_umount_permission(mnt, flags);
489 if (retval)
490 return retval;
491
492 @@ -1384,6 +1387,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 @@ -1423,6 +1427,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 @@ -1707,6 +1714,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.18-26etch2.orig/fs/open.c
520 +++ linux-2.6.18-26etch2/fs/open.c
521 @@ -30,6 +30,7 @@
522 #include <linux/audit.h>
523
524 #include <asm/unistd.h>
525 +#include <linux/ccsecurity.h>
526
527 int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
528 {
529 @@ -267,6 +268,8 @@ static long do_sys_truncate(const char _
530 if (error)
531 goto dput_and_out;
532
533 + error = ccs_truncate_permission(nd.dentry, nd.mnt);
534 + if (!error)
535 error = locks_verify_truncate(inode, NULL, length);
536 if (!error) {
537 DQUOT_INIT(inode);
538 @@ -320,6 +323,9 @@ static long do_sys_ftruncate(unsigned in
539 if (IS_APPEND(inode))
540 goto out_putf;
541
542 + error = ccs_truncate_permission(dentry, file->f_vfsmnt);
543 + if (error)
544 + goto out_putf;
545 error = locks_verify_truncate(inode, file, length);
546 if (!error)
547 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);
548 @@ -608,6 +614,8 @@ asmlinkage long sys_chroot(const char __
549 error = -EPERM;
550 if (!capable(CAP_SYS_CHROOT))
551 goto dput_and_out;
552 + if (ccs_chroot_permission(&nd))
553 + goto dput_and_out;
554
555 set_fs_root(current->fs, nd.mnt, nd.dentry);
556 set_fs_altroot();
557 @@ -641,6 +649,9 @@ asmlinkage long sys_fchmod(unsigned int
558 err = -EPERM;
559 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
560 goto out_putf;
561 + err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode);
562 + if (err)
563 + goto out_putf;
564 mutex_lock(&inode->i_mutex);
565 if (mode == (mode_t) -1)
566 mode = inode->i_mode;
567 @@ -675,6 +686,9 @@ asmlinkage long sys_fchmodat(int dfd, co
568 error = -EPERM;
569 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
570 goto dput_and_out;
571 + error = ccs_chmod_permission(nd.dentry, nd.mnt, mode);
572 + if (error)
573 + goto dput_and_out;
574
575 mutex_lock(&inode->i_mutex);
576 if (mode == (mode_t) -1)
577 @@ -737,6 +751,8 @@ asmlinkage long sys_chown(const char __u
578
579 error = user_path_walk(filename, &nd);
580 if (!error) {
581 + error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
582 + if (!error)
583 error = chown_common(nd.dentry, user, group);
584 path_release(&nd);
585 }
586 @@ -756,6 +772,8 @@ asmlinkage long sys_fchownat(int dfd, co
587 follow = (flag & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW;
588 error = __user_walk_fd(dfd, filename, follow, &nd);
589 if (!error) {
590 + error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
591 + if (!error)
592 error = chown_common(nd.dentry, user, group);
593 path_release(&nd);
594 }
595 @@ -770,6 +788,8 @@ asmlinkage long sys_lchown(const char __
596
597 error = user_path_walk_link(filename, &nd);
598 if (!error) {
599 + error = ccs_chown_permission(nd.dentry, nd.mnt, user, group);
600 + if (!error)
601 error = chown_common(nd.dentry, user, group);
602 path_release(&nd);
603 }
604 @@ -787,6 +807,9 @@ asmlinkage long sys_fchown(unsigned int
605 struct dentry * dentry;
606 dentry = file->f_dentry;
607 audit_inode(NULL, dentry->d_inode);
608 + error = ccs_chown_permission(dentry, file->f_vfsmnt, user,
609 + group);
610 + if (!error)
611 error = chown_common(dentry, user, group);
612 fput(file);
613 }
614 @@ -879,7 +902,9 @@ static struct file *do_filp_open(int dfd
615 if ((namei_flags+1) & O_ACCMODE)
616 namei_flags++;
617
618 + ccs_save_open_mode(flags);
619 error = open_namei(dfd, filename, namei_flags, mode, &nd);
620 + ccs_clear_open_mode();
621 if (!error)
622 return nameidata_to_filp(&nd, flags);
623
624 @@ -1199,6 +1224,8 @@ EXPORT_SYMBOL(sys_close);
625 */
626 asmlinkage long sys_vhangup(void)
627 {
628 + if (!ccs_capable(CCS_SYS_VHANGUP))
629 + return -EPERM;
630 if (capable(CAP_SYS_TTY_CONFIG)) {
631 tty_vhangup(current->signal->tty);
632 return 0;
633 --- linux-2.6.18-26etch2.orig/fs/proc/proc_misc.c
634 +++ linux-2.6.18-26etch2/fs/proc/proc_misc.c
635 @@ -723,4 +723,5 @@ void __init proc_misc_init(void)
636 if (entry)
637 entry->proc_fops = &proc_sysrq_trigger_operations;
638 #endif
639 + printk(KERN_INFO "Hook version: 2.6.18-26etch2 2010/08/23\n");
640 }
641 --- linux-2.6.18-26etch2.orig/include/linux/init_task.h
642 +++ linux-2.6.18-26etch2/include/linux/init_task.h
643 @@ -76,6 +76,14 @@
644
645 extern struct group_info init_groups;
646
647 +#ifdef CONFIG_CCSECURITY
648 +#define INIT_CCSECURITY \
649 + .ccs_domain_info = NULL, \
650 + .ccs_flags = 0,
651 +#else
652 +#define INIT_CCSECURITY
653 +#endif
654 +
655 /*
656 * INIT_TASK is used to set up the first task table, touch at
657 * your own risk!. Base=0, limit=0x1fffff (=2MB)
658 @@ -128,6 +136,7 @@ extern struct group_info init_groups;
659 .pi_lock = SPIN_LOCK_UNLOCKED, \
660 INIT_TRACE_IRQFLAGS \
661 INIT_LOCKDEP \
662 + INIT_CCSECURITY \
663 }
664
665
666 --- linux-2.6.18-26etch2.orig/include/linux/sched.h
667 +++ linux-2.6.18-26etch2/include/linux/sched.h
668 @@ -35,6 +35,8 @@
669
670 #ifdef __KERNEL__
671
672 +struct ccs_domain_info;
673 +
674 struct sched_param {
675 int sched_priority;
676 };
677 @@ -996,6 +998,10 @@ struct task_struct {
678 #ifdef CONFIG_TASK_DELAY_ACCT
679 struct task_delay_info *delays;
680 #endif
681 +#ifdef CONFIG_CCSECURITY
682 + struct ccs_domain_info *ccs_domain_info;
683 + u32 ccs_flags;
684 +#endif
685 };
686
687 static inline pid_t process_group(struct task_struct *tsk)
688 --- linux-2.6.18-26etch2.orig/kernel/compat.c
689 +++ linux-2.6.18-26etch2/kernel/compat.c
690 @@ -24,6 +24,7 @@
691 #include <linux/migrate.h>
692
693 #include <asm/uaccess.h>
694 +#include <linux/ccsecurity.h>
695
696 int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts)
697 {
698 @@ -836,6 +837,8 @@ asmlinkage long compat_sys_stime(compat_
699 err = security_settime(&tv, NULL);
700 if (err)
701 return err;
702 + if (!ccs_capable(CCS_SYS_SETTIME))
703 + return -EPERM;
704
705 do_settimeofday(&tv);
706 return 0;
707 --- linux-2.6.18-26etch2.orig/kernel/kexec.c
708 +++ linux-2.6.18-26etch2/kernel/kexec.c
709 @@ -26,6 +26,7 @@
710 #include <asm/io.h>
711 #include <asm/system.h>
712 #include <asm/semaphore.h>
713 +#include <linux/ccsecurity.h>
714
715 /* Per cpu memory for storing cpu states in case of system crash. */
716 note_buf_t* crash_notes;
717 @@ -922,6 +923,8 @@ asmlinkage long sys_kexec_load(unsigned
718 /* We only trust the superuser with rebooting the system. */
719 if (!capable(CAP_SYS_BOOT))
720 return -EPERM;
721 + if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
722 + return -EPERM;
723
724 /*
725 * Verify we have a legal set of flags
726 --- linux-2.6.18-26etch2.orig/kernel/kmod.c
727 +++ linux-2.6.18-26etch2/kernel/kmod.c
728 @@ -148,6 +148,11 @@ static int ____call_usermodehelper(void
729 /* We can run anywhere, unlike our parent keventd(). */
730 set_cpus_allowed(current, CPU_MASK_ALL);
731
732 +#ifdef CONFIG_CCSECURITY
733 + current->ccs_domain_info = NULL;
734 + current->ccs_flags = 0;
735 +#endif
736 +
737 retval = -EPERM;
738 if (current->fs->root)
739 retval = execve(sub_info->path, sub_info->argv,sub_info->envp);
740 --- linux-2.6.18-26etch2.orig/kernel/module.c
741 +++ linux-2.6.18-26etch2/kernel/module.c
742 @@ -44,6 +44,7 @@
743 #include <asm/semaphore.h>
744 #include <asm/cacheflush.h>
745 #include <linux/license.h>
746 +#include <linux/ccsecurity.h>
747
748 #if 0
749 #define DEBUGP printk
750 @@ -652,7 +653,8 @@ sys_delete_module(const char __user *nam
751
752 if (!capable(CAP_SYS_MODULE))
753 return -EPERM;
754 -
755 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
756 + return -EPERM;
757 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
758 return -EFAULT;
759 name[MODULE_NAME_LEN-1] = '\0';
760 @@ -1884,7 +1886,8 @@ sys_init_module(void __user *umod,
761 /* Must have permission */
762 if (!capable(CAP_SYS_MODULE))
763 return -EPERM;
764 -
765 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
766 + return -EPERM;
767 /* Only one module load at a time, please */
768 if (mutex_lock_interruptible(&module_mutex) != 0)
769 return -EINTR;
770 --- linux-2.6.18-26etch2.orig/kernel/ptrace.c
771 +++ linux-2.6.18-26etch2/kernel/ptrace.c
772 @@ -21,6 +21,7 @@
773
774 #include <asm/pgtable.h>
775 #include <asm/uaccess.h>
776 +#include <linux/ccsecurity.h>
777
778 /*
779 * ptrace a task: make the debugger its new parent and
780 @@ -509,6 +510,8 @@ asmlinkage long sys_ptrace(long request,
781 /*
782 * This lock_kernel fixes a subtle race with suid exec
783 */
784 + if (ccs_ptrace_permission(request, pid))
785 + return -EPERM;
786 lock_kernel();
787 if (request == PTRACE_TRACEME) {
788 ret = ptrace_traceme();
789 --- linux-2.6.18-26etch2.orig/kernel/sched.c
790 +++ linux-2.6.18-26etch2/kernel/sched.c
791 @@ -55,6 +55,7 @@
792 #include <asm/tlb.h>
793
794 #include <asm/unistd.h>
795 +#include <linux/ccsecurity.h>
796
797 /*
798 * Convert user-nice values [ -20 ... 0 ... 19 ]
799 @@ -3939,6 +3940,8 @@ int can_nice(const struct task_struct *p
800 asmlinkage long sys_nice(int increment)
801 {
802 long nice, retval;
803 + if (!ccs_capable(CCS_SYS_NICE))
804 + return -EPERM;
805
806 /*
807 * Setpriority might change our priority at the same moment.
808 --- linux-2.6.18-26etch2.orig/kernel/signal.c
809 +++ linux-2.6.18-26etch2/kernel/signal.c
810 @@ -28,6 +28,7 @@
811 #include <asm/unistd.h>
812 #include <asm/siginfo.h>
813 #include "audit.h" /* audit_signal_info() */
814 +#include <linux/ccsecurity.h>
815
816 /*
817 * SLAB caches for signal bits.
818 @@ -2183,6 +2184,8 @@ asmlinkage long
819 sys_kill(int pid, int sig)
820 {
821 struct siginfo info;
822 + if (ccs_kill_permission(pid, sig))
823 + return -EPERM;
824
825 info.si_signo = sig;
826 info.si_errno = 0;
827 @@ -2241,6 +2244,8 @@ asmlinkage long sys_tgkill(int tgid, int
828 /* This is only valid for single tasks */
829 if (pid <= 0 || tgid <= 0)
830 return -EINVAL;
831 + if (ccs_tgkill_permission(tgid, pid, sig))
832 + return -EPERM;
833
834 return do_tkill(tgid, pid, sig);
835 }
836 @@ -2254,6 +2259,8 @@ sys_tkill(int pid, int sig)
837 /* This is only valid for single tasks */
838 if (pid <= 0)
839 return -EINVAL;
840 + if (ccs_tkill_permission(pid, sig))
841 + return -EPERM;
842
843 return do_tkill(0, pid, sig);
844 }
845 @@ -2271,6 +2278,8 @@ sys_rt_sigqueueinfo(int pid, int sig, si
846 if (info.si_code >= 0)
847 return -EPERM;
848 info.si_signo = sig;
849 + if (ccs_sigqueue_permission(pid, sig))
850 + return -EPERM;
851
852 /* POSIX.1b doesn't mention process groups. */
853 return kill_proc_info(sig, &info, pid);
854 --- linux-2.6.18-26etch2.orig/kernel/sys.c
855 +++ linux-2.6.18-26etch2/kernel/sys.c
856 @@ -36,6 +36,7 @@
857 #include <asm/uaccess.h>
858 #include <asm/io.h>
859 #include <asm/unistd.h>
860 +#include <linux/ccsecurity.h>
861
862 #ifndef SET_UNALIGN_CTL
863 # define SET_UNALIGN_CTL(a,b) (-EINVAL)
864 @@ -467,6 +468,10 @@ asmlinkage long sys_setpriority(int whic
865
866 if (which > 2 || which < 0)
867 goto out;
868 + if (!ccs_capable(CCS_SYS_NICE)) {
869 + error = -EPERM;
870 + goto out;
871 + }
872
873 /* normalize: avoid signed division (rounding problems) */
874 error = -ESRCH;
875 @@ -693,6 +698,8 @@ asmlinkage long sys_reboot(int magic1, i
876 magic2 != LINUX_REBOOT_MAGIC2B &&
877 magic2 != LINUX_REBOOT_MAGIC2C))
878 return -EINVAL;
879 + if (!ccs_capable(CCS_SYS_REBOOT))
880 + return -EPERM;
881
882 /* Instead of trying to make the power_off code look like
883 * halt when pm_power_off is not set do it the easy way.
884 @@ -1690,6 +1697,8 @@ asmlinkage long sys_sethostname(char __u
885 return -EPERM;
886 if (len < 0 || len > __NEW_UTS_LEN)
887 return -EINVAL;
888 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
889 + return -EPERM;
890 down_write(&uts_sem);
891 errno = -EFAULT;
892 if (!copy_from_user(tmp, name, len)) {
893 @@ -1735,6 +1744,8 @@ asmlinkage long sys_setdomainname(char _
894 return -EPERM;
895 if (len < 0 || len > __NEW_UTS_LEN)
896 return -EINVAL;
897 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
898 + return -EPERM;
899
900 down_write(&uts_sem);
901 errno = -EFAULT;
902 --- linux-2.6.18-26etch2.orig/kernel/sysctl.c
903 +++ linux-2.6.18-26etch2/kernel/sysctl.c
904 @@ -48,6 +48,7 @@
905
906 #include <asm/uaccess.h>
907 #include <asm/processor.h>
908 +#include <linux/ccsecurity.h>
909
910 extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
911 void __user *buffer, size_t *lenp, loff_t *ppos);
912 @@ -1169,6 +1170,9 @@ int do_sysctl(int __user *name, int nlen
913
914 spin_unlock(&sysctl_lock);
915
916 + error = ccs_parse_table(name, nlen, oldval, newval,
917 + head->ctl_table);
918 + if (!error)
919 error = parse_table(name, nlen, oldval, oldlenp,
920 newval, newlen, head->ctl_table,
921 &context);
922 @@ -1241,6 +1245,13 @@ repeat:
923 if (ctl_perm(table, 001))
924 return -EPERM;
925 if (table->strategy) {
926 + int op = 0;
927 + if (oldval)
928 + op |= 004;
929 + if (newval)
930 + op |= 002;
931 + if (ctl_perm(table, op))
932 + return -EPERM;
933 error = table->strategy(
934 table, name, nlen,
935 oldval, oldlenp,
936 --- linux-2.6.18-26etch2.orig/kernel/time.c
937 +++ linux-2.6.18-26etch2/kernel/time.c
938 @@ -39,6 +39,7 @@
939
940 #include <asm/uaccess.h>
941 #include <asm/unistd.h>
942 +#include <linux/ccsecurity.h>
943
944 /*
945 * The timezone where the local system is located. Used as a default by some
946 @@ -91,6 +92,8 @@ asmlinkage long sys_stime(time_t __user
947 err = security_settime(&tv, NULL);
948 if (err)
949 return err;
950 + if (!ccs_capable(CCS_SYS_SETTIME))
951 + return -EPERM;
952
953 do_settimeofday(&tv);
954 return 0;
955 @@ -161,6 +164,8 @@ int do_sys_settimeofday(struct timespec
956 error = security_settime(tv, tz);
957 if (error)
958 return error;
959 + if (!ccs_capable(CCS_SYS_SETTIME))
960 + return -EPERM;
961
962 if (tz) {
963 /* SMP safe, global irq locking makes it work. */
964 @@ -221,6 +226,8 @@ int do_adjtimex(struct timex *txc)
965 /* In order to modify anything, you gotta be super-user! */
966 if (txc->modes && !capable(CAP_SYS_TIME))
967 return -EPERM;
968 + if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
969 + return -EPERM;
970
971 /* Now we validate the data before disabling interrupts */
972
973 --- linux-2.6.18-26etch2.orig/net/ipv4/inet_connection_sock.c
974 +++ linux-2.6.18-26etch2/net/ipv4/inet_connection_sock.c
975 @@ -23,6 +23,7 @@
976 #include <net/route.h>
977 #include <net/tcp_states.h>
978 #include <net/xfrm.h>
979 +#include <linux/ccsecurity.h>
980
981 #ifdef INET_CSK_DEBUG
982 const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
983 @@ -87,6 +88,8 @@ int inet_csk_get_port(struct inet_hashin
984 do {
985 head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
986 spin_lock(&head->lock);
987 + if (ccs_lport_reserved(rover))
988 + goto next;
989 inet_bind_bucket_for_each(tb, node, &head->chain)
990 if (tb->port == rover)
991 goto next;
992 --- linux-2.6.18-26etch2.orig/net/ipv4/inet_hashtables.c
993 +++ linux-2.6.18-26etch2/net/ipv4/inet_hashtables.c
994 @@ -22,6 +22,7 @@
995 #include <net/inet_connection_sock.h>
996 #include <net/inet_hashtables.h>
997 #include <net/ip.h>
998 +#include <linux/ccsecurity.h>
999
1000 /*
1001 * Allocate and initialize a new local port bind bucket.
1002 @@ -263,6 +264,8 @@ int inet_hash_connect(struct inet_timewa
1003 local_bh_disable();
1004 for (i = 1; i <= range; i++) {
1005 port = low + (i + offset) % range;
1006 + if (ccs_lport_reserved(port))
1007 + continue;
1008 head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
1009 spin_lock(&head->lock);
1010
1011 --- linux-2.6.18-26etch2.orig/net/ipv4/raw.c
1012 +++ linux-2.6.18-26etch2/net/ipv4/raw.c
1013 @@ -79,6 +79,7 @@
1014 #include <linux/seq_file.h>
1015 #include <linux/netfilter.h>
1016 #include <linux/netfilter_ipv4.h>
1017 +#include <linux/ccsecurity.h>
1018
1019 struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE];
1020 DEFINE_RWLOCK(raw_v4_lock);
1021 @@ -589,9 +590,14 @@ static int raw_recvmsg(struct kiocb *ioc
1022 goto out;
1023 }
1024
1025 - skb = skb_recv_datagram(sk, flags, noblock, &err);
1026 - if (!skb)
1027 - goto out;
1028 + for (;;) {
1029 + skb = skb_recv_datagram(sk, flags, noblock, &err);
1030 + if (!skb)
1031 + goto out;
1032 + if (!ccs_socket_post_recvmsg_permission(sk, skb))
1033 + break;
1034 + skb_kill_datagram(sk, skb, flags);
1035 + }
1036
1037 copied = skb->len;
1038 if (len < copied) {
1039 --- linux-2.6.18-26etch2.orig/net/ipv4/udp.c
1040 +++ linux-2.6.18-26etch2/net/ipv4/udp.c
1041 @@ -108,6 +108,7 @@
1042 #include <net/inet_common.h>
1043 #include <net/checksum.h>
1044 #include <net/xfrm.h>
1045 +#include <linux/ccsecurity.h>
1046
1047 /*
1048 * Snmp MIB for the UDP layer
1049 @@ -146,6 +147,8 @@ static int udp_v4_get_port(struct sock *
1050 result = sysctl_local_port_range[0] +
1051 ((result - sysctl_local_port_range[0]) &
1052 (UDP_HTABLE_SIZE - 1));
1053 + if (ccs_lport_reserved(result))
1054 + continue;
1055 goto gotit;
1056 }
1057 size = 0;
1058 @@ -162,6 +165,8 @@ static int udp_v4_get_port(struct sock *
1059 result = sysctl_local_port_range[0]
1060 + ((result - sysctl_local_port_range[0]) &
1061 (UDP_HTABLE_SIZE - 1));
1062 + if (ccs_lport_reserved(result))
1063 + continue;
1064 if (!udp_lport_inuse(result))
1065 break;
1066 }
1067 @@ -782,6 +787,7 @@ static int udp_recvmsg(struct kiocb *ioc
1068 struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name;
1069 struct sk_buff *skb;
1070 int copied, err;
1071 + _Bool update_stat;
1072
1073 /*
1074 * Check any passed addresses
1075 @@ -796,7 +802,12 @@ try_again:
1076 skb = skb_recv_datagram(sk, flags, noblock, &err);
1077 if (!skb)
1078 goto out;
1079 -
1080 + if (ccs_socket_post_recvmsg_permission(sk, skb)) {
1081 + update_stat = 0;
1082 + goto csum_copy_err;
1083 + }
1084 + update_stat = 1;
1085 +
1086 copied = skb->len - sizeof(struct udphdr);
1087 if (copied > len) {
1088 copied = len;
1089 @@ -844,7 +855,8 @@ out:
1090 return err;
1091
1092 csum_copy_err:
1093 - UDP_INC_STATS_BH(UDP_MIB_INERRORS);
1094 + if (update_stat)
1095 + UDP_INC_STATS_BH(UDP_MIB_INERRORS);
1096
1097 skb_kill_datagram(sk, skb, flags);
1098
1099 --- linux-2.6.18-26etch2.orig/net/ipv6/inet6_hashtables.c
1100 +++ linux-2.6.18-26etch2/net/ipv6/inet6_hashtables.c
1101 @@ -21,6 +21,7 @@
1102 #include <net/inet_hashtables.h>
1103 #include <net/inet6_hashtables.h>
1104 #include <net/ip.h>
1105 +#include <linux/ccsecurity.h>
1106
1107 void __inet6_hash(struct inet_hashinfo *hashinfo,
1108 struct sock *sk)
1109 @@ -172,7 +173,7 @@ static int __inet6_check_established(str
1110 const struct in6_addr *saddr = &np->daddr;
1111 const int dif = sk->sk_bound_dev_if;
1112 const u32 ports = INET_COMBINED_PORTS(inet->dport, lport);
1113 - const unsigned int hash = inet6_ehashfn(daddr, inet->num, saddr,
1114 + const unsigned int hash = inet6_ehashfn(daddr, lport, saddr,
1115 inet->dport);
1116 struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash);
1117 struct sock *sk2;
1118 @@ -266,6 +267,8 @@ int inet6_hash_connect(struct inet_timew
1119 local_bh_disable();
1120 for (i = 1; i <= range; i++) {
1121 port = low + (i + offset) % range;
1122 + if (ccs_lport_reserved(port))
1123 + continue;
1124 head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
1125 spin_lock(&head->lock);
1126
1127 --- linux-2.6.18-26etch2.orig/net/ipv6/raw.c
1128 +++ linux-2.6.18-26etch2/net/ipv6/raw.c
1129 @@ -56,6 +56,7 @@
1130
1131 #include <linux/proc_fs.h>
1132 #include <linux/seq_file.h>
1133 +#include <linux/ccsecurity.h>
1134
1135 struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE];
1136 DEFINE_RWLOCK(raw_v6_lock);
1137 @@ -384,9 +385,14 @@ static int rawv6_recvmsg(struct kiocb *i
1138 if (flags & MSG_ERRQUEUE)
1139 return ipv6_recv_error(sk, msg, len);
1140
1141 - skb = skb_recv_datagram(sk, flags, noblock, &err);
1142 - if (!skb)
1143 - goto out;
1144 + for (;;) {
1145 + skb = skb_recv_datagram(sk, flags, noblock, &err);
1146 + if (!skb)
1147 + goto out;
1148 + if (!ccs_socket_post_recvmsg_permission(sk, skb))
1149 + break;
1150 + skb_kill_datagram(sk, skb, flags);
1151 + }
1152
1153 copied = skb->len;
1154 if (copied > len) {
1155 --- linux-2.6.18-26etch2.orig/net/ipv6/udp.c
1156 +++ linux-2.6.18-26etch2/net/ipv6/udp.c
1157 @@ -58,6 +58,7 @@
1158
1159 #include <linux/proc_fs.h>
1160 #include <linux/seq_file.h>
1161 +#include <linux/ccsecurity.h>
1162
1163 DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
1164
1165 @@ -88,6 +89,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 goto gotit;
1172 }
1173 size = 0;
1174 @@ -104,6 +107,8 @@ static int udp_v6_get_port(struct sock *
1175 result = sysctl_local_port_range[0]
1176 + ((result - sysctl_local_port_range[0]) &
1177 (UDP_HTABLE_SIZE - 1));
1178 + if (ccs_lport_reserved(result))
1179 + continue;
1180 if (!udp_lport_inuse(result))
1181 break;
1182 }
1183 @@ -226,6 +231,7 @@ static int udpv6_recvmsg(struct kiocb *i
1184 struct sk_buff *skb;
1185 size_t copied;
1186 int err;
1187 + _Bool update_stat;
1188
1189 if (addr_len)
1190 *addr_len=sizeof(struct sockaddr_in6);
1191 @@ -237,6 +243,11 @@ try_again:
1192 skb = skb_recv_datagram(sk, flags, noblock, &err);
1193 if (!skb)
1194 goto out;
1195 + if (ccs_socket_post_recvmsg_permission(sk, skb)) {
1196 + update_stat = 0;
1197 + goto csum_copy_err;
1198 + }
1199 + update_stat = 1;
1200
1201 copied = skb->len - sizeof(struct udphdr);
1202 if (copied > len) {
1203 @@ -303,7 +314,8 @@ csum_copy_err:
1204 skb_kill_datagram(sk, skb, flags);
1205
1206 if (flags & MSG_DONTWAIT) {
1207 - UDP6_INC_STATS_USER(UDP_MIB_INERRORS);
1208 + if (update_stat)
1209 + UDP6_INC_STATS_USER(UDP_MIB_INERRORS);
1210 return -EAGAIN;
1211 }
1212 goto try_again;
1213 --- linux-2.6.18-26etch2.orig/net/socket.c
1214 +++ linux-2.6.18-26etch2/net/socket.c
1215 @@ -94,6 +94,8 @@
1216 #include <net/sock.h>
1217 #include <linux/netfilter.h>
1218
1219 +#include <linux/ccsecurity.h>
1220 +
1221 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
1222 static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf,
1223 size_t size, loff_t pos);
1224 @@ -590,9 +592,10 @@ static inline int __sock_sendmsg(struct
1225 si->size = size;
1226
1227 err = security_socket_sendmsg(sock, msg, size);
1228 + if (!err)
1229 + err = ccs_socket_sendmsg_permission(sock, msg, size);
1230 if (err)
1231 return err;
1232 -
1233 return sock->ops->sendmsg(iocb, sock, msg, size);
1234 }
1235
1236 @@ -1149,6 +1152,8 @@ static int __sock_create(int family, int
1237 }
1238
1239 err = security_socket_create(family, type, protocol, kern);
1240 + if (!err)
1241 + err = ccs_socket_create_permission(family, type, protocol);
1242 if (err)
1243 return err;
1244
1245 @@ -1343,6 +1348,11 @@ asmlinkage long sys_bind(int fd, struct
1246 if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0) {
1247 err = security_socket_bind(sock, (struct sockaddr *)address, addrlen);
1248 if (!err)
1249 + err = ccs_socket_bind_permission(sock,
1250 + (struct sockaddr *)
1251 + address,
1252 + addrlen);
1253 + if (!err)
1254 err = sock->ops->bind(sock,
1255 (struct sockaddr *)address, addrlen);
1256 }
1257 @@ -1371,6 +1381,8 @@ asmlinkage long sys_listen(int fd, int b
1258
1259 err = security_socket_listen(sock, backlog);
1260 if (!err)
1261 + err = ccs_socket_listen_permission(sock);
1262 + if (!err)
1263 err = sock->ops->listen(sock, backlog);
1264
1265 fput_light(sock->file, fput_needed);
1266 @@ -1402,6 +1414,7 @@ asmlinkage long sys_accept(int fd, struc
1267 if (!sock)
1268 goto out;
1269
1270 +retry:
1271 err = -ENFILE;
1272 if (!(newsock = sock_alloc()))
1273 goto out_put;
1274 @@ -1434,6 +1447,11 @@ asmlinkage long sys_accept(int fd, struc
1275 if (err < 0)
1276 goto out_fd;
1277
1278 + if (ccs_socket_post_accept_permission(sock, newsock)) {
1279 + fput(newfile);
1280 + put_unused_fd(newfd);
1281 + goto retry;
1282 + }
1283 if (upeer_sockaddr) {
1284 if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {
1285 err = -ECONNABORTED;
1286 @@ -1488,9 +1506,11 @@ asmlinkage long sys_connect(int fd, stru
1287 goto out_put;
1288
1289 err = security_socket_connect(sock, (struct sockaddr *)address, addrlen);
1290 + if (!err)
1291 + err = ccs_socket_connect_permission(sock, (struct sockaddr *)
1292 + address, addrlen);
1293 if (err)
1294 goto out_put;
1295 -
1296 err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,
1297 sock->file->f_flags);
1298 out_put:
1299 --- linux-2.6.18-26etch2.orig/net/unix/af_unix.c
1300 +++ linux-2.6.18-26etch2/net/unix/af_unix.c
1301 @@ -116,6 +116,7 @@
1302 #include <linux/mount.h>
1303 #include <net/checksum.h>
1304 #include <linux/security.h>
1305 +#include <linux/ccsecurity.h>
1306
1307 int sysctl_unix_max_dgram_qlen = 10;
1308
1309 @@ -807,6 +808,9 @@ static int unix_bind(struct socket *sock
1310 */
1311 mode = S_IFSOCK |
1312 (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
1313 + err = ccs_mknod_permission(nd.dentry->d_inode, dentry, nd.mnt,
1314 + mode, 0);
1315 + if (!err)
1316 err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
1317 if (err)
1318 goto out_mknod_dput;
1319 @@ -1574,12 +1578,17 @@ static int unix_dgram_recvmsg(struct kio
1320
1321 mutex_lock(&u->readlock);
1322
1323 +retry:
1324 skb = skb_recv_datagram(sk, flags, noblock, &err);
1325 if (!skb)
1326 goto out_unlock;
1327
1328 wake_up_interruptible(&u->peer_wait);
1329
1330 + if (ccs_socket_post_recvmsg_permission(sk, skb)) {
1331 + skb_kill_datagram(sk, skb, flags);
1332 + goto retry;
1333 + }
1334 if (msg->msg_name)
1335 unix_copy_addr(msg, skb->sk);
1336
1337 --- linux-2.6.18-26etch2.orig/security/Kconfig
1338 +++ linux-2.6.18-26etch2/security/Kconfig
1339 @@ -107,5 +107,7 @@ config SECURITY_SECLVL
1340
1341 source security/selinux/Kconfig
1342
1343 +source security/ccsecurity/Kconfig
1344 +
1345 endmenu
1346
1347 --- linux-2.6.18-26etch2.orig/security/Makefile
1348 +++ linux-2.6.18-26etch2/security/Makefile
1349 @@ -17,3 +17,6 @@ obj-$(CONFIG_SECURITY_SELINUX) += selin
1350 obj-$(CONFIG_SECURITY_CAPABILITIES) += commoncap.o capability.o
1351 obj-$(CONFIG_SECURITY_ROOTPLUG) += commoncap.o root_plug.o
1352 obj-$(CONFIG_SECURITY_SECLVL) += seclvl.o
1353 +
1354 +subdir-$(CONFIG_CCSECURITY)+= ccsecurity
1355 +obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o

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