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

Subversion リポジトリの参照

Contents of /trunk/1.8.x/ccs-patch/patches/ccs-patch-2.6.32.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: 32631 byte(s)
Merge branches/ccs-patch/ into trunk/1.8.x/ccs-patch/
1 This is TOMOYO Linux patch for kernel 2.6.32.24.
2
3 Source code for this patch is http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.24.tar.bz2
4 ---
5 fs/compat.c | 3 ++-
6 fs/compat_ioctl.c | 3 +++
7 fs/exec.c | 3 ++-
8 fs/fcntl.c | 5 +++++
9 fs/ioctl.c | 3 +++
10 fs/namei.c | 37 +++++++++++++++++++++++++++++++++++++
11 fs/namespace.c | 9 +++++++++
12 fs/open.c | 25 +++++++++++++++++++++++++
13 fs/proc/version.c | 7 +++++++
14 include/linux/init_task.h | 9 +++++++++
15 include/linux/sched.h | 6 ++++++
16 kernel/compat.c | 3 +++
17 kernel/kexec.c | 3 +++
18 kernel/kmod.c | 5 +++++
19 kernel/module.c | 5 +++++
20 kernel/ptrace.c | 5 +++++
21 kernel/sched.c | 3 +++
22 kernel/signal.c | 11 +++++++++++
23 kernel/sys.c | 11 +++++++++++
24 kernel/sysctl.c | 4 ++++
25 kernel/time.c | 5 +++++
26 kernel/time/ntp.c | 6 ++++++
27 net/ipv4/inet_connection_sock.c | 3 +++
28 net/ipv4/inet_hashtables.c | 3 +++
29 net/ipv4/raw.c | 12 +++++++++---
30 net/ipv4/udp.c | 12 ++++++++++--
31 net/ipv6/raw.c | 12 +++++++++---
32 net/ipv6/udp.c | 9 ++++++++-
33 net/socket.c | 22 ++++++++++++++++++++++
34 net/unix/af_unix.c | 10 ++++++++++
35 security/Kconfig | 2 ++
36 security/Makefile | 3 +++
37 32 files changed, 248 insertions(+), 11 deletions(-)
38
39 --- linux-2.6.32.24.orig/fs/compat.c
40 +++ linux-2.6.32.24/fs/compat.c
41 @@ -56,6 +56,7 @@
42 #include <asm/mmu_context.h>
43 #include <asm/ioctls.h>
44 #include "internal.h"
45 +#include <linux/ccsecurity.h>
46
47 int compat_log = 1;
48
49 @@ -1528,7 +1529,7 @@ int compat_do_execve(char * filename,
50 if (retval < 0)
51 goto out;
52
53 - retval = search_binary_handler(bprm, regs);
54 + retval = ccs_search_binary_handler(bprm, regs);
55 if (retval < 0)
56 goto out;
57
58 --- linux-2.6.32.24.orig/fs/compat_ioctl.c
59 +++ linux-2.6.32.24/fs/compat_ioctl.c
60 @@ -114,6 +114,7 @@
61 #ifdef CONFIG_SPARC
62 #include <asm/fbio.h>
63 #endif
64 +#include <linux/ccsecurity.h>
65
66 static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
67 unsigned long arg, struct file *f)
68 @@ -2778,6 +2779,8 @@ asmlinkage long compat_sys_ioctl(unsigne
69
70 /* RED-PEN how should LSM module know it's handling 32bit? */
71 error = security_file_ioctl(filp, cmd, arg);
72 + if (!error)
73 + error = ccs_ioctl_permission(filp, cmd, arg);
74 if (error)
75 goto out_fput;
76
77 --- linux-2.6.32.24.orig/fs/exec.c
78 +++ linux-2.6.32.24/fs/exec.c
79 @@ -61,6 +61,7 @@
80 #include <asm/mmu_context.h>
81 #include <asm/tlb.h>
82 #include "internal.h"
83 +#include <linux/ccsecurity.h>
84
85 int core_uses_pid;
86 char core_pattern[CORENAME_MAX_SIZE] = "core";
87 @@ -1375,7 +1376,7 @@ int do_execve(char * filename,
88 goto out;
89
90 current->flags &= ~PF_KTHREAD;
91 - retval = search_binary_handler(bprm,regs);
92 + retval = ccs_search_binary_handler(bprm, regs);
93 if (retval < 0)
94 goto out;
95
96 --- linux-2.6.32.24.orig/fs/fcntl.c
97 +++ linux-2.6.32.24/fs/fcntl.c
98 @@ -23,6 +23,7 @@
99 #include <asm/poll.h>
100 #include <asm/siginfo.h>
101 #include <asm/uaccess.h>
102 +#include <linux/ccsecurity.h>
103
104 void set_close_on_exec(unsigned int fd, int flag)
105 {
106 @@ -428,6 +429,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
107 goto out;
108
109 err = security_file_fcntl(filp, cmd, arg);
110 + if (!err)
111 + err = ccs_fcntl_permission(filp, cmd, arg);
112 if (err) {
113 fput(filp);
114 return err;
115 @@ -453,6 +456,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
116 goto out;
117
118 err = security_file_fcntl(filp, cmd, arg);
119 + if (!err)
120 + err = ccs_fcntl_permission(filp, cmd, arg);
121 if (err) {
122 fput(filp);
123 return err;
124 --- linux-2.6.32.24.orig/fs/ioctl.c
125 +++ linux-2.6.32.24/fs/ioctl.c
126 @@ -18,6 +18,7 @@
127 #include <linux/falloc.h>
128
129 #include <asm/ioctls.h>
130 +#include <linux/ccsecurity.h>
131
132 /* So that the fiemap access checks can't overflow on 32 bit machines. */
133 #define FIEMAP_MAX_EXTENTS (UINT_MAX / sizeof(struct fiemap_extent))
134 @@ -618,6 +619,8 @@ SYSCALL_DEFINE3(ioctl, unsigned int, fd,
135 goto out;
136
137 error = security_file_ioctl(filp, cmd, arg);
138 + if (!error)
139 + error = ccs_ioctl_permission(filp, cmd, arg);
140 if (error)
141 goto out_fput;
142
143 --- linux-2.6.32.24.orig/fs/namei.c
144 +++ linux-2.6.32.24/fs/namei.c
145 @@ -37,6 +37,8 @@
146
147 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
148
149 +#include <linux/ccsecurity.h>
150 +
151 /* [Feb-1997 T. Schoebel-Theuer]
152 * Fundamental changes in the pathname lookup mechanisms (namei)
153 * were necessary because of omirr. The reason is that omirr needs
154 @@ -1569,6 +1571,11 @@ int may_open(struct path *path, int acc_
155 goto err_out;
156 }
157
158 + /* includes O_APPEND and O_TRUNC checks */
159 + error = ccs_open_permission(dentry, path->mnt, flag);
160 + if (error)
161 + goto err_out;
162 +
163 /*
164 * Ensure there are no outstanding leases on the file.
165 */
166 @@ -1624,6 +1631,9 @@ static int __open_namei_create(struct na
167 if (!IS_POSIXACL(dir->d_inode))
168 mode &= ~current_umask();
169 error = security_path_mknod(&nd->path, path->dentry, mode, 0);
170 + if (!error)
171 + error = ccs_mknod_permission(dir->d_inode, path->dentry,
172 + nd->path.mnt, mode, 0);
173 if (error)
174 goto out_unlock;
175 error = vfs_create(dir->d_inode, path->dentry, mode, nd);
176 @@ -1776,7 +1786,9 @@ do_last:
177 error = mnt_want_write(nd.path.mnt);
178 if (error)
179 goto exit_mutex_unlock;
180 + ccs_save_open_mode(open_flag);
181 error = __open_namei_create(&nd, &path, flag, mode);
182 + ccs_clear_open_mode();
183 if (error) {
184 mnt_drop_write(nd.path.mnt);
185 goto exit;
186 @@ -1835,7 +1847,9 @@ ok:
187 if (error)
188 goto exit;
189 }
190 + ccs_save_open_mode(open_flag);
191 error = may_open(&nd.path, acc_mode, flag);
192 + ccs_clear_open_mode();
193 if (error) {
194 if (will_write)
195 mnt_drop_write(nd.path.mnt);
196 @@ -2065,6 +2079,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
197 if (error)
198 goto out_dput;
199 error = security_path_mknod(&nd.path, dentry, mode, dev);
200 + if (!error)
201 + error = ccs_mknod_permission(nd.path.dentry->d_inode, dentry,
202 + nd.path.mnt, mode, dev);
203 if (error)
204 goto out_drop_write;
205 switch (mode & S_IFMT) {
206 @@ -2140,6 +2157,9 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
207 if (error)
208 goto out_dput;
209 error = security_path_mkdir(&nd.path, dentry, mode);
210 + if (!error)
211 + error = ccs_mkdir_permission(nd.path.dentry->d_inode, dentry,
212 + nd.path.mnt, mode);
213 if (error)
214 goto out_drop_write;
215 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
216 @@ -2254,6 +2274,9 @@ static long do_rmdir(int dfd, const char
217 if (error)
218 goto exit3;
219 error = security_path_rmdir(&nd.path, dentry);
220 + if (!error)
221 + error = ccs_rmdir_permission(nd.path.dentry->d_inode, dentry,
222 + nd.path.mnt);
223 if (error)
224 goto exit4;
225 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
226 @@ -2343,6 +2366,9 @@ static long do_unlinkat(int dfd, const c
227 if (error)
228 goto exit2;
229 error = security_path_unlink(&nd.path, dentry);
230 + if (!error)
231 + error = ccs_unlink_permission(nd.path.dentry->d_inode,
232 + dentry, nd.path.mnt);
233 if (error)
234 goto exit3;
235 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
236 @@ -2428,6 +2454,9 @@ SYSCALL_DEFINE3(symlinkat, const char __
237 if (error)
238 goto out_dput;
239 error = security_path_symlink(&nd.path, dentry, from);
240 + if (!error)
241 + error = ccs_symlink_permission(nd.path.dentry->d_inode, dentry,
242 + nd.path.mnt, from);
243 if (error)
244 goto out_drop_write;
245 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
246 @@ -2528,6 +2557,10 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
247 if (error)
248 goto out_dput;
249 error = security_path_link(old_path.dentry, &nd.path, new_dentry);
250 + if (!error)
251 + error = ccs_link_permission(old_path.dentry,
252 + nd.path.dentry->d_inode,
253 + new_dentry, nd.path.mnt);
254 if (error)
255 goto out_drop_write;
256 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
257 @@ -2769,6 +2802,10 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
258 goto exit5;
259 error = security_path_rename(&oldnd.path, old_dentry,
260 &newnd.path, new_dentry);
261 + if (!error)
262 + error = ccs_rename_permission(old_dir->d_inode, old_dentry,
263 + new_dir->d_inode, new_dentry,
264 + newnd.path.mnt);
265 if (error)
266 goto exit6;
267 error = vfs_rename(old_dir->d_inode, old_dentry,
268 --- linux-2.6.32.24.orig/fs/namespace.c
269 +++ linux-2.6.32.24/fs/namespace.c
270 @@ -33,6 +33,7 @@
271 #include <asm/unistd.h>
272 #include "pnode.h"
273 #include "internal.h"
274 +#include <linux/ccsecurity.h>
275
276 #define HASH_SHIFT ilog2(PAGE_SIZE / sizeof(struct list_head))
277 #define HASH_SIZE (1UL << HASH_SHIFT)
278 @@ -1030,6 +1031,8 @@ static int do_umount(struct vfsmount *mn
279 LIST_HEAD(umount_list);
280
281 retval = security_sb_umount(mnt, flags);
282 + if (!retval)
283 + retval = ccs_umount_permission(mnt, flags);
284 if (retval)
285 return retval;
286
287 @@ -1912,6 +1915,7 @@ int copy_mount_string(const void __user
288 long do_mount(char *dev_name, char *dir_name, char *type_page,
289 unsigned long flags, void *data_page)
290 {
291 + const unsigned long original_flags = flags;
292 struct path path;
293 int retval = 0;
294 int mnt_flags = 0;
295 @@ -1959,6 +1963,9 @@ long do_mount(char *dev_name, char *dir_
296
297 retval = security_sb_mount(dev_name, &path,
298 type_page, flags, data_page);
299 + if (!retval)
300 + retval = ccs_mount_permission(dev_name, &path, type_page,
301 + original_flags, data_page);
302 if (retval)
303 goto dput_out;
304
305 @@ -2177,6 +2184,8 @@ SYSCALL_DEFINE2(pivot_root, const char _
306 goto out1;
307
308 error = security_sb_pivotroot(&old, &new);
309 + if (!error)
310 + error = ccs_pivot_root_permission(&old, &new);
311 if (error) {
312 path_put(&old);
313 goto out1;
314 --- linux-2.6.32.24.orig/fs/open.c
315 +++ linux-2.6.32.24/fs/open.c
316 @@ -30,6 +30,7 @@
317 #include <linux/audit.h>
318 #include <linux/falloc.h>
319 #include <linux/fs_struct.h>
320 +#include <linux/ccsecurity.h>
321
322 int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
323 {
324 @@ -275,6 +276,8 @@ static long do_sys_truncate(const char _
325 error = locks_verify_truncate(inode, NULL, length);
326 if (!error)
327 error = security_path_truncate(&path, length, 0);
328 + if (!error)
329 + error = ccs_truncate_permission(path.dentry, path.mnt);
330 if (!error) {
331 vfs_dq_init(inode);
332 error = do_truncate(path.dentry, length, 0, NULL);
333 @@ -334,6 +337,8 @@ static long do_sys_ftruncate(unsigned in
334 error = security_path_truncate(&file->f_path, length,
335 ATTR_MTIME|ATTR_CTIME);
336 if (!error)
337 + error = ccs_truncate_permission(dentry, file->f_vfsmnt);
338 + if (!error)
339 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);
340 out_putf:
341 fput(file);
342 @@ -587,6 +592,8 @@ SYSCALL_DEFINE1(chroot, const char __use
343 error = -EPERM;
344 if (!capable(CAP_SYS_CHROOT))
345 goto dput_and_out;
346 + if (ccs_chroot_permission(&path))
347 + goto dput_and_out;
348
349 set_fs_root(current->fs, &path);
350 error = 0;
351 @@ -616,6 +623,9 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
352 err = mnt_want_write_file(file);
353 if (err)
354 goto out_putf;
355 + err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode);
356 + if (err)
357 + goto out_drop_write;
358 mutex_lock(&inode->i_mutex);
359 if (mode == (mode_t) -1)
360 mode = inode->i_mode;
361 @@ -623,6 +633,7 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
362 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
363 err = notify_change(dentry, &newattrs);
364 mutex_unlock(&inode->i_mutex);
365 +out_drop_write:
366 mnt_drop_write(file->f_path.mnt);
367 out_putf:
368 fput(file);
369 @@ -645,6 +656,9 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
370 error = mnt_want_write(path.mnt);
371 if (error)
372 goto dput_and_out;
373 + error = ccs_chmod_permission(path.dentry, path.mnt, mode);
374 + if (error)
375 + goto out_drop_write;
376 mutex_lock(&inode->i_mutex);
377 if (mode == (mode_t) -1)
378 mode = inode->i_mode;
379 @@ -652,6 +666,7 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
380 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
381 error = notify_change(path.dentry, &newattrs);
382 mutex_unlock(&inode->i_mutex);
383 +out_drop_write:
384 mnt_drop_write(path.mnt);
385 dput_and_out:
386 path_put(&path);
387 @@ -700,6 +715,8 @@ SYSCALL_DEFINE3(chown, const char __user
388 error = mnt_want_write(path.mnt);
389 if (error)
390 goto out_release;
391 + error = ccs_chown_permission(path.dentry, path.mnt, user, group);
392 + if (!error)
393 error = chown_common(path.dentry, user, group);
394 mnt_drop_write(path.mnt);
395 out_release:
396 @@ -725,6 +742,8 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
397 error = mnt_want_write(path.mnt);
398 if (error)
399 goto out_release;
400 + error = ccs_chown_permission(path.dentry, path.mnt, user, group);
401 + if (!error)
402 error = chown_common(path.dentry, user, group);
403 mnt_drop_write(path.mnt);
404 out_release:
405 @@ -744,6 +763,8 @@ SYSCALL_DEFINE3(lchown, const char __use
406 error = mnt_want_write(path.mnt);
407 if (error)
408 goto out_release;
409 + error = ccs_chown_permission(path.dentry, path.mnt, user, group);
410 + if (!error)
411 error = chown_common(path.dentry, user, group);
412 mnt_drop_write(path.mnt);
413 out_release:
414 @@ -767,6 +788,8 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd
415 goto out_fput;
416 dentry = file->f_path.dentry;
417 audit_inode(NULL, dentry);
418 + error = ccs_chown_permission(dentry, file->f_vfsmnt, user, group);
419 + if (!error)
420 error = chown_common(dentry, user, group);
421 mnt_drop_write(file->f_path.mnt);
422 out_fput:
423 @@ -1160,6 +1183,8 @@ EXPORT_SYMBOL(sys_close);
424 */
425 SYSCALL_DEFINE0(vhangup)
426 {
427 + if (!ccs_capable(CCS_SYS_VHANGUP))
428 + return -EPERM;
429 if (capable(CAP_SYS_TTY_CONFIG)) {
430 tty_vhangup_self();
431 return 0;
432 --- linux-2.6.32.24.orig/fs/proc/version.c
433 +++ linux-2.6.32.24/fs/proc/version.c
434 @@ -32,3 +32,10 @@ static int __init proc_version_init(void
435 return 0;
436 }
437 module_init(proc_version_init);
438 +
439 +static int __init ccs_show_version(void)
440 +{
441 + printk(KERN_INFO "Hook version: 2.6.32.24 2010/10/04\n");
442 + return 0;
443 +}
444 +module_init(ccs_show_version);
445 --- linux-2.6.32.24.orig/include/linux/init_task.h
446 +++ linux-2.6.32.24/include/linux/init_task.h
447 @@ -115,6 +115,14 @@ extern struct cred init_cred;
448 # define INIT_PERF_EVENTS(tsk)
449 #endif
450
451 +#ifdef CONFIG_CCSECURITY
452 +#define INIT_CCSECURITY \
453 + .ccs_domain_info = NULL, \
454 + .ccs_flags = 0,
455 +#else
456 +#define INIT_CCSECURITY
457 +#endif
458 +
459 /*
460 * INIT_TASK is used to set up the first task table, touch at
461 * your own risk!. Base=0, limit=0x1fffff (=2MB)
462 @@ -184,6 +192,7 @@ extern struct cred init_cred;
463 INIT_FTRACE_GRAPH \
464 INIT_TRACE_RECURSION \
465 INIT_TASK_RCU_PREEMPT(tsk) \
466 + INIT_CCSECURITY \
467 }
468
469
470 --- linux-2.6.32.24.orig/include/linux/sched.h
471 +++ linux-2.6.32.24/include/linux/sched.h
472 @@ -43,6 +43,8 @@
473
474 #ifdef __KERNEL__
475
476 +struct ccs_domain_info;
477 +
478 struct sched_param {
479 int sched_priority;
480 };
481 @@ -1547,6 +1549,10 @@ struct task_struct {
482 /* bitmask of trace recursion */
483 unsigned long trace_recursion;
484 #endif /* CONFIG_TRACING */
485 +#ifdef CONFIG_CCSECURITY
486 + struct ccs_domain_info *ccs_domain_info;
487 + u32 ccs_flags;
488 +#endif
489 };
490
491 /* Future-safe accessor for struct task_struct's cpus_allowed. */
492 --- linux-2.6.32.24.orig/kernel/compat.c
493 +++ linux-2.6.32.24/kernel/compat.c
494 @@ -28,6 +28,7 @@
495 #include <linux/module.h>
496
497 #include <asm/uaccess.h>
498 +#include <linux/ccsecurity.h>
499
500 /*
501 * Note that the native side is already converted to a timespec, because
502 @@ -924,6 +925,8 @@ asmlinkage long compat_sys_stime(compat_
503 err = security_settime(&tv, NULL);
504 if (err)
505 return err;
506 + if (!ccs_capable(CCS_SYS_SETTIME))
507 + return -EPERM;
508
509 do_settimeofday(&tv);
510 return 0;
511 --- linux-2.6.32.24.orig/kernel/kexec.c
512 +++ linux-2.6.32.24/kernel/kexec.c
513 @@ -37,6 +37,7 @@
514 #include <asm/io.h>
515 #include <asm/system.h>
516 #include <asm/sections.h>
517 +#include <linux/ccsecurity.h>
518
519 /* Per cpu memory for storing cpu states in case of system crash. */
520 note_buf_t* crash_notes;
521 @@ -943,6 +944,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned lon
522 /* We only trust the superuser with rebooting the system. */
523 if (!capable(CAP_SYS_BOOT))
524 return -EPERM;
525 + if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
526 + return -EPERM;
527
528 /*
529 * Verify we have a legal set of flags
530 --- linux-2.6.32.24.orig/kernel/kmod.c
531 +++ linux-2.6.32.24/kernel/kmod.c
532 @@ -184,6 +184,11 @@ static int ____call_usermodehelper(void
533 */
534 set_user_nice(current, 0);
535
536 +#ifdef CONFIG_CCSECURITY
537 + current->ccs_domain_info = NULL;
538 + current->ccs_flags = 0;
539 +#endif
540 +
541 retval = kernel_execve(sub_info->path, sub_info->argv, sub_info->envp);
542
543 /* Exec failed? */
544 --- linux-2.6.32.24.orig/kernel/module.c
545 +++ linux-2.6.32.24/kernel/module.c
546 @@ -55,6 +55,7 @@
547 #include <linux/async.h>
548 #include <linux/percpu.h>
549 #include <linux/kmemleak.h>
550 +#include <linux/ccsecurity.h>
551
552 #define CREATE_TRACE_POINTS
553 #include <trace/events/module.h>
554 @@ -801,6 +802,8 @@ SYSCALL_DEFINE2(delete_module, const cha
555
556 if (!capable(CAP_SYS_MODULE) || modules_disabled)
557 return -EPERM;
558 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
559 + return -EPERM;
560
561 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
562 return -EFAULT;
563 @@ -2590,6 +2593,8 @@ SYSCALL_DEFINE3(init_module, void __user
564 /* Must have permission */
565 if (!capable(CAP_SYS_MODULE) || modules_disabled)
566 return -EPERM;
567 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
568 + return -EPERM;
569
570 /* Only one module load at a time, please */
571 if (mutex_lock_interruptible(&module_mutex) != 0)
572 --- linux-2.6.32.24.orig/kernel/ptrace.c
573 +++ linux-2.6.32.24/kernel/ptrace.c
574 @@ -22,6 +22,7 @@
575 #include <linux/pid_namespace.h>
576 #include <linux/syscalls.h>
577 #include <linux/uaccess.h>
578 +#include <linux/ccsecurity.h>
579
580
581 /*
582 @@ -603,6 +604,8 @@ SYSCALL_DEFINE4(ptrace, long, request, l
583 {
584 struct task_struct *child;
585 long ret;
586 + if (ccs_ptrace_permission(request, pid))
587 + return -EPERM;
588
589 /*
590 * This lock_kernel fixes a subtle race with suid exec
591 @@ -724,6 +727,8 @@ asmlinkage long compat_sys_ptrace(compat
592 {
593 struct task_struct *child;
594 long ret;
595 + if (ccs_ptrace_permission(request, pid))
596 + return -EPERM;
597
598 /*
599 * This lock_kernel fixes a subtle race with suid exec
600 --- linux-2.6.32.24.orig/kernel/sched.c
601 +++ linux-2.6.32.24/kernel/sched.c
602 @@ -74,6 +74,7 @@
603
604 #include <asm/tlb.h>
605 #include <asm/irq_regs.h>
606 +#include <linux/ccsecurity.h>
607
608 #include "sched_cpupri.h"
609
610 @@ -6237,6 +6238,8 @@ int can_nice(const struct task_struct *p
611 SYSCALL_DEFINE1(nice, int, increment)
612 {
613 long nice, retval;
614 + if (!ccs_capable(CCS_SYS_NICE))
615 + return -EPERM;
616
617 /*
618 * Setpriority might change our priority at the same moment.
619 --- linux-2.6.32.24.orig/kernel/signal.c
620 +++ linux-2.6.32.24/kernel/signal.c
621 @@ -34,6 +34,7 @@
622 #include <asm/unistd.h>
623 #include <asm/siginfo.h>
624 #include "audit.h" /* audit_signal_info() */
625 +#include <linux/ccsecurity.h>
626
627 /*
628 * SLAB caches for signal bits.
629 @@ -2258,6 +2259,8 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const s
630 SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
631 {
632 struct siginfo info;
633 + if (ccs_kill_permission(pid, sig))
634 + return -EPERM;
635
636 info.si_signo = sig;
637 info.si_errno = 0;
638 @@ -2326,6 +2329,8 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid
639 /* This is only valid for single tasks */
640 if (pid <= 0 || tgid <= 0)
641 return -EINVAL;
642 + if (ccs_tgkill_permission(tgid, pid, sig))
643 + return -EPERM;
644
645 return do_tkill(tgid, pid, sig);
646 }
647 @@ -2338,6 +2343,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int,
648 /* This is only valid for single tasks */
649 if (pid <= 0)
650 return -EINVAL;
651 + if (ccs_tkill_permission(pid, sig))
652 + return -EPERM;
653
654 return do_tkill(0, pid, sig);
655 }
656 @@ -2355,6 +2362,8 @@ SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t,
657 if (info.si_code >= 0)
658 return -EPERM;
659 info.si_signo = sig;
660 + if (ccs_sigqueue_permission(pid, sig))
661 + return -EPERM;
662
663 /* POSIX.1b doesn't mention process groups. */
664 return kill_proc_info(sig, &info, pid);
665 @@ -2371,6 +2380,8 @@ long do_rt_tgsigqueueinfo(pid_t tgid, pi
666 if (info->si_code >= 0)
667 return -EPERM;
668 info->si_signo = sig;
669 + if (ccs_tgsigqueue_permission(tgid, pid, sig))
670 + return -EPERM;
671
672 return do_send_specific(tgid, pid, sig, info);
673 }
674 --- linux-2.6.32.24.orig/kernel/sys.c
675 +++ linux-2.6.32.24/kernel/sys.c
676 @@ -45,6 +45,7 @@
677 #include <asm/uaccess.h>
678 #include <asm/io.h>
679 #include <asm/unistd.h>
680 +#include <linux/ccsecurity.h>
681
682 #ifndef SET_UNALIGN_CTL
683 # define SET_UNALIGN_CTL(a,b) (-EINVAL)
684 @@ -155,6 +156,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
685
686 if (which > PRIO_USER || which < PRIO_PROCESS)
687 goto out;
688 + if (!ccs_capable(CCS_SYS_NICE)) {
689 + error = -EPERM;
690 + goto out;
691 + }
692
693 /* normalize: avoid signed division (rounding problems) */
694 error = -ESRCH;
695 @@ -374,6 +379,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
696 magic2 != LINUX_REBOOT_MAGIC2B &&
697 magic2 != LINUX_REBOOT_MAGIC2C))
698 return -EINVAL;
699 + if (!ccs_capable(CCS_SYS_REBOOT))
700 + return -EPERM;
701
702 /* Instead of trying to make the power_off code look like
703 * halt when pm_power_off is not set do it the easy way.
704 @@ -1138,6 +1145,8 @@ SYSCALL_DEFINE2(sethostname, char __user
705 return -EPERM;
706 if (len < 0 || len > __NEW_UTS_LEN)
707 return -EINVAL;
708 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
709 + return -EPERM;
710 down_write(&uts_sem);
711 errno = -EFAULT;
712 if (!copy_from_user(tmp, name, len)) {
713 @@ -1187,6 +1196,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
714 return -EPERM;
715 if (len < 0 || len > __NEW_UTS_LEN)
716 return -EINVAL;
717 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
718 + return -EPERM;
719
720 down_write(&uts_sem);
721 errno = -EFAULT;
722 --- linux-2.6.32.24.orig/kernel/sysctl.c
723 +++ linux-2.6.32.24/kernel/sysctl.c
724 @@ -53,6 +53,7 @@
725
726 #include <asm/uaccess.h>
727 #include <asm/processor.h>
728 +#include <linux/ccsecurity.h>
729
730 #ifdef CONFIG_X86
731 #include <asm/nmi.h>
732 @@ -1853,6 +1854,9 @@ int do_sysctl(int __user *name, int nlen
733
734 for (head = sysctl_head_next(NULL); head;
735 head = sysctl_head_next(head)) {
736 + error = ccs_parse_table(name, nlen, oldval, newval,
737 + head->ctl_table);
738 + if (!error)
739 error = parse_table(name, nlen, oldval, oldlenp,
740 newval, newlen,
741 head->root, head->ctl_table);
742 --- linux-2.6.32.24.orig/kernel/time.c
743 +++ linux-2.6.32.24/kernel/time.c
744 @@ -41,6 +41,7 @@
745
746 #include <asm/uaccess.h>
747 #include <asm/unistd.h>
748 +#include <linux/ccsecurity.h>
749
750 #include "timeconst.h"
751
752 @@ -92,6 +93,8 @@ SYSCALL_DEFINE1(stime, time_t __user *,
753 err = security_settime(&tv, NULL);
754 if (err)
755 return err;
756 + if (!ccs_capable(CCS_SYS_SETTIME))
757 + return -EPERM;
758
759 do_settimeofday(&tv);
760 return 0;
761 @@ -163,6 +166,8 @@ int do_sys_settimeofday(struct timespec
762 error = security_settime(tv, tz);
763 if (error)
764 return error;
765 + if (!ccs_capable(CCS_SYS_SETTIME))
766 + return -EPERM;
767
768 if (tz) {
769 /* SMP safe, global irq locking makes it work. */
770 --- linux-2.6.32.24.orig/kernel/time/ntp.c
771 +++ linux-2.6.32.24/kernel/time/ntp.c
772 @@ -14,6 +14,7 @@
773 #include <linux/timex.h>
774 #include <linux/time.h>
775 #include <linux/mm.h>
776 +#include <linux/ccsecurity.h>
777
778 /*
779 * NTP timekeeping variables:
780 @@ -456,10 +457,15 @@ int do_adjtimex(struct timex *txc)
781 if (!(txc->modes & ADJ_OFFSET_READONLY) &&
782 !capable(CAP_SYS_TIME))
783 return -EPERM;
784 + if (!(txc->modes & ADJ_OFFSET_READONLY) &&
785 + !ccs_capable(CCS_SYS_SETTIME))
786 + return -EPERM;
787 } else {
788 /* In order to modify anything, you gotta be super-user! */
789 if (txc->modes && !capable(CAP_SYS_TIME))
790 return -EPERM;
791 + if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
792 + return -EPERM;
793
794 /*
795 * if the quartz is off by more than 10% then
796 --- linux-2.6.32.24.orig/net/ipv4/inet_connection_sock.c
797 +++ linux-2.6.32.24/net/ipv4/inet_connection_sock.c
798 @@ -23,6 +23,7 @@
799 #include <net/route.h>
800 #include <net/tcp_states.h>
801 #include <net/xfrm.h>
802 +#include <linux/ccsecurity.h>
803
804 #ifdef INET_CSK_DEBUG
805 const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
806 @@ -111,6 +112,8 @@ again:
807 head = &hashinfo->bhash[inet_bhashfn(net, rover,
808 hashinfo->bhash_size)];
809 spin_lock(&head->lock);
810 + if (ccs_lport_reserved(rover))
811 + goto next;
812 inet_bind_bucket_for_each(tb, node, &head->chain)
813 if (ib_net(tb) == net && tb->port == rover) {
814 if (tb->fastreuse > 0 &&
815 --- linux-2.6.32.24.orig/net/ipv4/inet_hashtables.c
816 +++ linux-2.6.32.24/net/ipv4/inet_hashtables.c
817 @@ -22,6 +22,7 @@
818 #include <net/inet_connection_sock.h>
819 #include <net/inet_hashtables.h>
820 #include <net/ip.h>
821 +#include <linux/ccsecurity.h>
822
823 /*
824 * Allocate and initialize a new local port bind bucket.
825 @@ -443,6 +444,8 @@ int __inet_hash_connect(struct inet_time
826 local_bh_disable();
827 for (i = 1; i <= remaining; i++) {
828 port = low + (i + offset) % remaining;
829 + if (ccs_lport_reserved(port))
830 + continue;
831 head = &hinfo->bhash[inet_bhashfn(net, port,
832 hinfo->bhash_size)];
833 spin_lock(&head->lock);
834 --- linux-2.6.32.24.orig/net/ipv4/raw.c
835 +++ linux-2.6.32.24/net/ipv4/raw.c
836 @@ -77,6 +77,7 @@
837 #include <linux/seq_file.h>
838 #include <linux/netfilter.h>
839 #include <linux/netfilter_ipv4.h>
840 +#include <linux/ccsecurity.h>
841
842 static struct raw_hashinfo raw_v4_hashinfo = {
843 .lock = __RW_LOCK_UNLOCKED(raw_v4_hashinfo.lock),
844 @@ -678,9 +679,14 @@ static int raw_recvmsg(struct kiocb *ioc
845 goto out;
846 }
847
848 - skb = skb_recv_datagram(sk, flags, noblock, &err);
849 - if (!skb)
850 - goto out;
851 + for (;;) {
852 + skb = skb_recv_datagram(sk, flags, noblock, &err);
853 + if (!skb)
854 + goto out;
855 + if (!ccs_socket_post_recvmsg_permission(sk, skb))
856 + break;
857 + skb_kill_datagram(sk, skb, flags);
858 + }
859
860 copied = skb->len;
861 if (len < copied) {
862 --- linux-2.6.32.24.orig/net/ipv4/udp.c
863 +++ linux-2.6.32.24/net/ipv4/udp.c
864 @@ -105,6 +105,7 @@
865 #include <net/checksum.h>
866 #include <net/xfrm.h>
867 #include "udp_impl.h"
868 +#include <linux/ccsecurity.h>
869
870 struct udp_table udp_table;
871 EXPORT_SYMBOL(udp_table);
872 @@ -196,7 +197,8 @@ int udp_lib_get_port(struct sock *sk, un
873 */
874 do {
875 if (low <= snum && snum <= high &&
876 - !test_bit(snum / UDP_HTABLE_SIZE, bitmap))
877 + !test_bit(snum / UDP_HTABLE_SIZE, bitmap)
878 + && !ccs_lport_reserved(snum))
879 goto found;
880 snum += rand;
881 } while (snum != first);
882 @@ -929,6 +931,7 @@ int udp_recvmsg(struct kiocb *iocb, stru
883 int peeked;
884 int err;
885 int is_udplite = IS_UDPLITE(sk);
886 + _Bool update_stat;
887
888 /*
889 * Check any passed addresses
890 @@ -944,6 +947,11 @@ try_again:
891 &peeked, &err);
892 if (!skb)
893 goto out;
894 + if (ccs_socket_post_recvmsg_permission(sk, skb)) {
895 + update_stat = 0;
896 + goto csum_copy_err;
897 + }
898 + update_stat = 1;
899
900 ulen = skb->len - sizeof(struct udphdr);
901 copied = len;
902 @@ -1005,7 +1013,7 @@ out:
903
904 csum_copy_err:
905 lock_sock(sk);
906 - if (!skb_kill_datagram(sk, skb, flags))
907 + if (!skb_kill_datagram(sk, skb, flags) && update_stat)
908 UDP_INC_STATS_USER(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
909 release_sock(sk);
910
911 --- linux-2.6.32.24.orig/net/ipv6/raw.c
912 +++ linux-2.6.32.24/net/ipv6/raw.c
913 @@ -59,6 +59,7 @@
914
915 #include <linux/proc_fs.h>
916 #include <linux/seq_file.h>
917 +#include <linux/ccsecurity.h>
918
919 static struct raw_hashinfo raw_v6_hashinfo = {
920 .lock = __RW_LOCK_UNLOCKED(raw_v6_hashinfo.lock),
921 @@ -462,9 +463,14 @@ static int rawv6_recvmsg(struct kiocb *i
922 if (flags & MSG_ERRQUEUE)
923 return ipv6_recv_error(sk, msg, len);
924
925 - skb = skb_recv_datagram(sk, flags, noblock, &err);
926 - if (!skb)
927 - goto out;
928 + for (;;) {
929 + skb = skb_recv_datagram(sk, flags, noblock, &err);
930 + if (!skb)
931 + goto out;
932 + if (!ccs_socket_post_recvmsg_permission(sk, skb))
933 + break;
934 + skb_kill_datagram(sk, skb, flags);
935 + }
936
937 copied = skb->len;
938 if (copied > len) {
939 --- linux-2.6.32.24.orig/net/ipv6/udp.c
940 +++ linux-2.6.32.24/net/ipv6/udp.c
941 @@ -48,6 +48,7 @@
942 #include <linux/proc_fs.h>
943 #include <linux/seq_file.h>
944 #include "udp_impl.h"
945 +#include <linux/ccsecurity.h>
946
947 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
948 {
949 @@ -199,6 +200,7 @@ int udpv6_recvmsg(struct kiocb *iocb, st
950 int err;
951 int is_udplite = IS_UDPLITE(sk);
952 int is_udp4;
953 + _Bool update_stat;
954
955 if (addr_len)
956 *addr_len=sizeof(struct sockaddr_in6);
957 @@ -211,6 +213,11 @@ try_again:
958 &peeked, &err);
959 if (!skb)
960 goto out;
961 + if (ccs_socket_post_recvmsg_permission(sk, skb)) {
962 + update_stat = 0;
963 + goto csum_copy_err;
964 + }
965 + update_stat = 1;
966
967 ulen = skb->len - sizeof(struct udphdr);
968 copied = len;
969 @@ -294,7 +301,7 @@ out:
970
971 csum_copy_err:
972 lock_sock(sk);
973 - if (!skb_kill_datagram(sk, skb, flags)) {
974 + if (!skb_kill_datagram(sk, skb, flags) && update_stat) {
975 if (is_udp4)
976 UDP_INC_STATS_USER(sock_net(sk),
977 UDP_MIB_INERRORS, is_udplite);
978 --- linux-2.6.32.24.orig/net/socket.c
979 +++ linux-2.6.32.24/net/socket.c
980 @@ -97,6 +97,8 @@
981 #include <net/sock.h>
982 #include <linux/netfilter.h>
983
984 +#include <linux/ccsecurity.h>
985 +
986 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
987 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
988 unsigned long nr_segs, loff_t pos);
989 @@ -567,6 +569,8 @@ static inline int __sock_sendmsg(struct
990 si->size = size;
991
992 err = security_socket_sendmsg(sock, msg, size);
993 + if (!err)
994 + err = ccs_socket_sendmsg_permission(sock, msg, size);
995 if (err)
996 return err;
997
998 @@ -1171,6 +1175,8 @@ static int __sock_create(struct net *net
999 }
1000
1001 err = security_socket_create(family, type, protocol, kern);
1002 + if (!err)
1003 + err = ccs_socket_create_permission(family, type, protocol);
1004 if (err)
1005 return err;
1006
1007 @@ -1419,6 +1425,11 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
1008 (struct sockaddr *)&address,
1009 addrlen);
1010 if (!err)
1011 + err = ccs_socket_bind_permission(sock,
1012 + (struct sockaddr *)
1013 + &address,
1014 + addrlen);
1015 + if (!err)
1016 err = sock->ops->bind(sock,
1017 (struct sockaddr *)
1018 &address, addrlen);
1019 @@ -1448,6 +1459,8 @@ SYSCALL_DEFINE2(listen, int, fd, int, ba
1020
1021 err = security_socket_listen(sock, backlog);
1022 if (!err)
1023 + err = ccs_socket_listen_permission(sock);
1024 + if (!err)
1025 err = sock->ops->listen(sock, backlog);
1026
1027 fput_light(sock->file, fput_needed);
1028 @@ -1485,6 +1498,7 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
1029 if (!sock)
1030 goto out;
1031
1032 +retry:
1033 err = -ENFILE;
1034 if (!(newsock = sock_alloc()))
1035 goto out_put;
1036 @@ -1517,6 +1531,11 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
1037 if (err < 0)
1038 goto out_fd;
1039
1040 + if (ccs_socket_post_accept_permission(sock, newsock)) {
1041 + fput(newfile);
1042 + put_unused_fd(newfd);
1043 + goto retry;
1044 + }
1045 if (upeer_sockaddr) {
1046 if (newsock->ops->getname(newsock, (struct sockaddr *)&address,
1047 &len, 2) < 0) {
1048 @@ -1583,6 +1602,9 @@ SYSCALL_DEFINE3(connect, int, fd, struct
1049
1050 err =
1051 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
1052 + if (!err)
1053 + err = ccs_socket_connect_permission(sock, (struct sockaddr *)
1054 + &address, addrlen);
1055 if (err)
1056 goto out_put;
1057
1058 --- linux-2.6.32.24.orig/net/unix/af_unix.c
1059 +++ linux-2.6.32.24/net/unix/af_unix.c
1060 @@ -114,6 +114,7 @@
1061 #include <linux/mount.h>
1062 #include <net/checksum.h>
1063 #include <linux/security.h>
1064 +#include <linux/ccsecurity.h>
1065
1066 static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
1067 static DEFINE_SPINLOCK(unix_table_lock);
1068 @@ -846,6 +847,10 @@ static int unix_bind(struct socket *sock
1069 if (err)
1070 goto out_mknod_dput;
1071 err = security_path_mknod(&nd.path, dentry, mode, 0);
1072 + if (!err)
1073 + err = ccs_mknod_permission(nd.path.dentry->d_inode,
1074 + dentry, nd.path.mnt, mode,
1075 + 0);
1076 if (err)
1077 goto out_mknod_drop_write;
1078 err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
1079 @@ -1670,6 +1675,7 @@ static int unix_dgram_recvmsg(struct kio
1080
1081 mutex_lock(&u->readlock);
1082
1083 +retry:
1084 skb = skb_recv_datagram(sk, flags, noblock, &err);
1085 if (!skb) {
1086 unix_state_lock(sk);
1087 @@ -1683,6 +1689,10 @@ static int unix_dgram_recvmsg(struct kio
1088
1089 wake_up_interruptible_sync(&u->peer_wait);
1090
1091 + if (ccs_socket_post_recvmsg_permission(sk, skb)) {
1092 + skb_kill_datagram(sk, skb, flags);
1093 + goto retry;
1094 + }
1095 if (msg->msg_name)
1096 unix_copy_addr(msg, skb->sk);
1097
1098 --- linux-2.6.32.24.orig/security/Kconfig
1099 +++ linux-2.6.32.24/security/Kconfig
1100 @@ -165,5 +165,7 @@ source security/tomoyo/Kconfig
1101
1102 source security/integrity/ima/Kconfig
1103
1104 +source security/ccsecurity/Kconfig
1105 +
1106 endmenu
1107
1108 --- linux-2.6.32.24.orig/security/Makefile
1109 +++ linux-2.6.32.24/security/Makefile
1110 @@ -25,3 +25,6 @@ obj-$(CONFIG_CGROUP_DEVICE) += device_c
1111 # Object integrity file lists
1112 subdir-$(CONFIG_IMA) += integrity/ima
1113 obj-$(CONFIG_IMA) += integrity/ima/built-in.o
1114 +
1115 +subdir-$(CONFIG_CCSECURITY) += ccsecurity
1116 +obj-$(CONFIG_CCSECURITY) += ccsecurity/built-in.o

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