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

Subversion リポジトリの参照

Contents of /trunk/1.7.x/ccs-patch/patches/ccs-patch-2.6.32.diff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5839 - (show annotations) (download) (as text)
Tue Feb 14 01:18:52 2012 UTC (12 years, 3 months ago) by kumaneko
File MIME type: text/x-diff
File size: 32308 byte(s)


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

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