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

Subversion リポジトリの参照

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6225 - (show annotations) (download) (as text)
Sat Mar 16 12:08:01 2013 UTC (11 years, 2 months ago) by kumaneko
File MIME type: text/x-diff
File size: 31941 byte(s)


1 This is TOMOYO Linux patch for kernel 2.6.30.10.
2
3 Source code for this patch is https://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.30.10.tar.xz
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 | 9 +++++++++
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, 240 insertions(+), 3 deletions(-)
38
39 --- linux-2.6.30.10.orig/fs/compat.c
40 +++ linux-2.6.30.10/fs/compat.c
41 @@ -57,6 +57,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 @@ -1543,7 +1544,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.30.10.orig/fs/compat_ioctl.c
59 +++ linux-2.6.30.10/fs/compat_ioctl.c
60 @@ -113,6 +113,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 @@ -2799,6 +2800,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 @@ -2823,6 +2826,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.30.10.orig/fs/exec.c
89 +++ linux-2.6.30.10/fs/exec.c
90 @@ -59,6 +59,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 @@ -1324,7 +1325,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.30.10.orig/fs/fcntl.c
108 +++ linux-2.6.30.10/fs/fcntl.c
109 @@ -24,6 +24,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 @@ -157,6 +158,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.30.10.orig/fs/ioctl.c
128 +++ linux-2.6.30.10/fs/ioctl.c
129 @@ -17,6 +17,7 @@
130 #include <linux/buffer_head.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 @@ -40,6 +41,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 @@ -578,6 +581,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.30.10.orig/fs/namei.c
156 +++ linux-2.6.30.10/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 @@ -1533,6 +1535,11 @@ int may_open(struct path *path, int acc_
167 if (!is_owner_or_cap(inode))
168 return -EPERM;
169
170 + /* includes O_APPEND and O_TRUNC checks */
171 + error = ccs_open_permission(dentry, path->mnt, flag);
172 + if (error)
173 + return error;
174 +
175 /*
176 * Ensure there are no outstanding leases on the file.
177 */
178 @@ -1583,6 +1590,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 @@ -1727,7 +1737,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 @@ -1780,7 +1792,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 @@ -2001,6 +2015,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 @@ -2076,6 +2093,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 @@ -2190,6 +2210,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 @@ -2279,6 +2302,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 @@ -2364,6 +2390,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 @@ -2464,6 +2493,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 @@ -2705,6 +2738,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.30.10.orig/fs/namespace.c
281 +++ linux-2.6.30.10/fs/namespace.c
282 @@ -32,6 +32,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 @@ -1056,6 +1057,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 @@ -1148,6 +1151,8 @@ SYSCALL_DEFINE2(umount, char __user *, n
300 {
301 struct path path;
302 int retval;
303 + if (!ccs_capable(CCS_SYS_UMOUNT))
304 + return -EPERM;
305
306 retval = user_path(name, &path);
307 if (retval)
308 @@ -1496,6 +1501,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 @@ -1607,6 +1615,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 @@ -1710,6 +1721,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 @@ -1915,6 +1929,7 @@ int copy_mount_options(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 @@ -1964,6 +1979,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 @@ -2154,6 +2172,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.30.10.orig/fs/open.c
366 +++ linux-2.6.30.10/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 @@ -273,6 +274,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 @@ -333,6 +337,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 @@ -586,6 +593,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 @@ -615,6 +624,9 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
405 err = mnt_want_write(file->f_path.mnt);
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 @@ -622,6 +634,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 @@ -644,6 +657,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 @@ -651,6 +667,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 @@ -699,6 +716,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 @@ -724,6 +743,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 @@ -743,6 +764,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 @@ -766,6 +789,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 @@ -1157,6 +1182,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.30.10.orig/fs/proc/version.c
486 +++ linux-2.6.30.10/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.30.10 2010/09/21\n");
495 + return 0;
496 +}
497 +module_init(ccs_show_version);
498 --- linux-2.6.30.10.orig/include/linux/init_task.h
499 +++ linux-2.6.30.10/include/linux/init_task.h
500 @@ -108,6 +108,14 @@ extern struct group_info init_groups;
501
502 extern struct cred init_cred;
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 @@ -174,6 +182,7 @@ extern struct cred init_cred;
516 INIT_TRACE_IRQFLAGS \
517 INIT_LOCKDEP \
518 INIT_FTRACE_GRAPH \
519 + INIT_CCSECURITY \
520 }
521
522
523 --- linux-2.6.30.10.orig/include/linux/sched.h
524 +++ linux-2.6.30.10/include/linux/sched.h
525 @@ -41,6 +41,8 @@
526
527 #ifdef __KERNEL__
528
529 +struct ccs_domain_info;
530 +
531 struct sched_param {
532 int sched_priority;
533 };
534 @@ -1429,6 +1431,10 @@ struct task_struct {
535 /* state flags for use by tracers */
536 unsigned long trace;
537 #endif
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.30.10.orig/kernel/compat.c
546 +++ linux-2.6.30.10/kernel/compat.c
547 @@ -27,6 +27,7 @@
548 #include <linux/ptrace.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 @@ -915,6 +916,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.30.10.orig/kernel/kexec.c
565 +++ linux-2.6.30.10/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.30.10.orig/kernel/kmod.c
584 +++ linux-2.6.30.10/kernel/kmod.c
585 @@ -177,6 +177,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.30.10.orig/kernel/module.c
598 +++ linux-2.6.30.10/kernel/module.c
599 @@ -52,6 +52,7 @@
600 #include <linux/ftrace.h>
601 #include <linux/async.h>
602 #include <linux/percpu.h>
603 +#include <linux/ccsecurity.h>
604
605 #if 0
606 #define DEBUGP printk
607 @@ -779,6 +780,8 @@ SYSCALL_DEFINE2(delete_module, const cha
608
609 if (!capable(CAP_SYS_MODULE))
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 @@ -2338,6 +2341,8 @@ SYSCALL_DEFINE3(init_module, void __user
617 /* Must have permission */
618 if (!capable(CAP_SYS_MODULE))
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.30.10.orig/kernel/ptrace.c
626 +++ linux-2.6.30.10/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 @@ -654,6 +655,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 @@ -775,6 +778,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.30.10.orig/kernel/sched.c
654 +++ linux-2.6.30.10/kernel/sched.c
655 @@ -76,6 +76,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 @@ -5679,6 +5680,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.30.10.orig/kernel/signal.c
673 +++ linux-2.6.30.10/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 @@ -2268,6 +2269,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 @@ -2329,6 +2332,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 @@ -2341,6 +2346,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 @@ -2358,6 +2365,8 @@ SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t,
710 if (info.si_code >= 0)
711 return -EPERM;
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 --- linux-2.6.30.10.orig/kernel/sys.c
719 +++ linux-2.6.30.10/kernel/sys.c
720 @@ -44,6 +44,7 @@
721 #include <asm/uaccess.h>
722 #include <asm/io.h>
723 #include <asm/unistd.h>
724 +#include <linux/ccsecurity.h>
725
726 #ifndef SET_UNALIGN_CTL
727 # define SET_UNALIGN_CTL(a,b) (-EINVAL)
728 @@ -154,6 +155,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
729
730 if (which > PRIO_USER || which < PRIO_PROCESS)
731 goto out;
732 + if (!ccs_capable(CCS_SYS_NICE)) {
733 + error = -EPERM;
734 + goto out;
735 + }
736
737 /* normalize: avoid signed division (rounding problems) */
738 error = -ESRCH;
739 @@ -373,6 +378,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
740 magic2 != LINUX_REBOOT_MAGIC2B &&
741 magic2 != LINUX_REBOOT_MAGIC2C))
742 return -EINVAL;
743 + if (!ccs_capable(CCS_SYS_REBOOT))
744 + return -EPERM;
745
746 /* Instead of trying to make the power_off code look like
747 * halt when pm_power_off is not set do it the easy way.
748 @@ -1417,6 +1424,8 @@ SYSCALL_DEFINE2(sethostname, char __user
749 return -EPERM;
750 if (len < 0 || len > __NEW_UTS_LEN)
751 return -EINVAL;
752 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
753 + return -EPERM;
754 down_write(&uts_sem);
755 errno = -EFAULT;
756 if (!copy_from_user(tmp, name, len)) {
757 @@ -1466,6 +1475,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
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
764 down_write(&uts_sem);
765 errno = -EFAULT;
766 --- linux-2.6.30.10.orig/kernel/sysctl.c
767 +++ linux-2.6.30.10/kernel/sysctl.c
768 @@ -52,6 +52,7 @@
769
770 #include <asm/uaccess.h>
771 #include <asm/processor.h>
772 +#include <linux/ccsecurity.h>
773
774 #ifdef CONFIG_X86
775 #include <asm/nmi.h>
776 @@ -1707,6 +1708,9 @@ int do_sysctl(int __user *name, int nlen
777
778 for (head = sysctl_head_next(NULL); head;
779 head = sysctl_head_next(head)) {
780 + error = ccs_parse_table(name, nlen, oldval, newval,
781 + head->ctl_table);
782 + if (!error)
783 error = parse_table(name, nlen, oldval, oldlenp,
784 newval, newlen,
785 head->root, head->ctl_table);
786 --- linux-2.6.30.10.orig/kernel/time.c
787 +++ linux-2.6.30.10/kernel/time.c
788 @@ -41,6 +41,7 @@
789
790 #include <asm/uaccess.h>
791 #include <asm/unistd.h>
792 +#include <linux/ccsecurity.h>
793
794 #include "timeconst.h"
795
796 @@ -92,6 +93,8 @@ SYSCALL_DEFINE1(stime, time_t __user *,
797 err = security_settime(&tv, NULL);
798 if (err)
799 return err;
800 + if (!ccs_capable(CCS_SYS_SETTIME))
801 + return -EPERM;
802
803 do_settimeofday(&tv);
804 return 0;
805 @@ -163,6 +166,8 @@ int do_sys_settimeofday(struct timespec
806 error = security_settime(tv, tz);
807 if (error)
808 return error;
809 + if (!ccs_capable(CCS_SYS_SETTIME))
810 + return -EPERM;
811
812 if (tz) {
813 /* SMP safe, global irq locking makes it work. */
814 --- linux-2.6.30.10.orig/kernel/time/ntp.c
815 +++ linux-2.6.30.10/kernel/time/ntp.c
816 @@ -14,6 +14,7 @@
817 #include <linux/timex.h>
818 #include <linux/time.h>
819 #include <linux/mm.h>
820 +#include <linux/ccsecurity.h>
821
822 /*
823 * NTP timekeeping variables:
824 @@ -459,10 +460,15 @@ int do_adjtimex(struct timex *txc)
825 if (!(txc->modes & ADJ_OFFSET_READONLY) &&
826 !capable(CAP_SYS_TIME))
827 return -EPERM;
828 + if (!(txc->modes & ADJ_OFFSET_READONLY) &&
829 + !ccs_capable(CCS_SYS_SETTIME))
830 + return -EPERM;
831 } else {
832 /* In order to modify anything, you gotta be super-user! */
833 if (txc->modes && !capable(CAP_SYS_TIME))
834 return -EPERM;
835 + if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
836 + return -EPERM;
837
838 /*
839 * if the quartz is off by more than 10% then
840 --- linux-2.6.30.10.orig/net/ipv4/inet_connection_sock.c
841 +++ linux-2.6.30.10/net/ipv4/inet_connection_sock.c
842 @@ -23,6 +23,7 @@
843 #include <net/route.h>
844 #include <net/tcp_states.h>
845 #include <net/xfrm.h>
846 +#include <linux/ccsecurity.h>
847
848 #ifdef INET_CSK_DEBUG
849 const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
850 @@ -111,6 +112,8 @@ again:
851 head = &hashinfo->bhash[inet_bhashfn(net, rover,
852 hashinfo->bhash_size)];
853 spin_lock(&head->lock);
854 + if (ccs_lport_reserved(rover))
855 + goto next;
856 inet_bind_bucket_for_each(tb, node, &head->chain)
857 if (ib_net(tb) == net && tb->port == rover) {
858 if (tb->fastreuse > 0 &&
859 --- linux-2.6.30.10.orig/net/ipv4/inet_hashtables.c
860 +++ linux-2.6.30.10/net/ipv4/inet_hashtables.c
861 @@ -22,6 +22,7 @@
862 #include <net/inet_connection_sock.h>
863 #include <net/inet_hashtables.h>
864 #include <net/ip.h>
865 +#include <linux/ccsecurity.h>
866
867 /*
868 * Allocate and initialize a new local port bind bucket.
869 @@ -443,6 +444,8 @@ int __inet_hash_connect(struct inet_time
870 local_bh_disable();
871 for (i = 1; i <= remaining; i++) {
872 port = low + (i + offset) % remaining;
873 + if (ccs_lport_reserved(port))
874 + continue;
875 head = &hinfo->bhash[inet_bhashfn(net, port,
876 hinfo->bhash_size)];
877 spin_lock(&head->lock);
878 --- linux-2.6.30.10.orig/net/ipv4/raw.c
879 +++ linux-2.6.30.10/net/ipv4/raw.c
880 @@ -77,6 +77,7 @@
881 #include <linux/seq_file.h>
882 #include <linux/netfilter.h>
883 #include <linux/netfilter_ipv4.h>
884 +#include <linux/ccsecurity.h>
885
886 static struct raw_hashinfo raw_v4_hashinfo = {
887 .lock = __RW_LOCK_UNLOCKED(raw_v4_hashinfo.lock),
888 @@ -666,6 +667,9 @@ static int raw_recvmsg(struct kiocb *ioc
889 skb = skb_recv_datagram(sk, flags, noblock, &err);
890 if (!skb)
891 goto out;
892 + err = ccs_socket_recvmsg_permission(sk, skb, flags);
893 + if (err)
894 + goto out;
895
896 copied = skb->len;
897 if (len < copied) {
898 --- linux-2.6.30.10.orig/net/ipv4/udp.c
899 +++ linux-2.6.30.10/net/ipv4/udp.c
900 @@ -105,6 +105,7 @@
901 #include <net/checksum.h>
902 #include <net/xfrm.h>
903 #include "udp_impl.h"
904 +#include <linux/ccsecurity.h>
905
906 struct udp_table udp_table;
907 EXPORT_SYMBOL(udp_table);
908 @@ -195,7 +196,8 @@ int udp_lib_get_port(struct sock *sk, un
909 */
910 do {
911 if (low <= snum && snum <= high &&
912 - !test_bit(snum / UDP_HTABLE_SIZE, bitmap))
913 + !test_bit(snum / UDP_HTABLE_SIZE, bitmap)
914 + && !ccs_lport_reserved(snum))
915 goto found;
916 snum += rand;
917 } while (snum != first);
918 @@ -901,6 +903,9 @@ try_again:
919 &peeked, &err);
920 if (!skb)
921 goto out;
922 + err = ccs_socket_recvmsg_permission(sk, skb, flags);
923 + if (err)
924 + goto out;
925
926 ulen = skb->len - sizeof(struct udphdr);
927 copied = len;
928 --- linux-2.6.30.10.orig/net/ipv6/raw.c
929 +++ linux-2.6.30.10/net/ipv6/raw.c
930 @@ -59,6 +59,7 @@
931
932 #include <linux/proc_fs.h>
933 #include <linux/seq_file.h>
934 +#include <linux/ccsecurity.h>
935
936 static struct raw_hashinfo raw_v6_hashinfo = {
937 .lock = __RW_LOCK_UNLOCKED(raw_v6_hashinfo.lock),
938 @@ -465,6 +466,9 @@ static int rawv6_recvmsg(struct kiocb *i
939 skb = skb_recv_datagram(sk, flags, noblock, &err);
940 if (!skb)
941 goto out;
942 + err = ccs_socket_recvmsg_permission(sk, skb, flags);
943 + if (err)
944 + goto out;
945
946 copied = skb->len;
947 if (copied > len) {
948 --- linux-2.6.30.10.orig/net/ipv6/udp.c
949 +++ linux-2.6.30.10/net/ipv6/udp.c
950 @@ -48,6 +48,7 @@
951 #include <linux/proc_fs.h>
952 #include <linux/seq_file.h>
953 #include "udp_impl.h"
954 +#include <linux/ccsecurity.h>
955
956 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
957 {
958 @@ -212,6 +213,9 @@ try_again:
959 &peeked, &err);
960 if (!skb)
961 goto out;
962 + err = ccs_socket_recvmsg_permission(sk, skb, flags);
963 + if (err)
964 + goto out;
965
966 ulen = skb->len - sizeof(struct udphdr);
967 copied = len;
968 --- linux-2.6.30.10.orig/net/socket.c
969 +++ linux-2.6.30.10/net/socket.c
970 @@ -96,6 +96,8 @@
971 #include <net/sock.h>
972 #include <linux/netfilter.h>
973
974 +#include <linux/ccsecurity.h>
975 +
976 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
977 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
978 unsigned long nr_segs, loff_t pos);
979 @@ -567,6 +569,8 @@ static inline int __sock_sendmsg(struct
980 si->size = size;
981
982 err = security_socket_sendmsg(sock, msg, size);
983 + if (!err)
984 + err = ccs_socket_sendmsg_permission(sock, msg, size);
985 if (err)
986 return err;
987
988 @@ -1171,6 +1175,8 @@ static int __sock_create(struct net *net
989 }
990
991 err = security_socket_create(family, type, protocol, kern);
992 + if (!err)
993 + err = ccs_socket_create_permission(family, type, protocol);
994 if (err)
995 return err;
996
997 @@ -1419,6 +1425,11 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
998 (struct sockaddr *)&address,
999 addrlen);
1000 if (!err)
1001 + err = ccs_socket_bind_permission(sock,
1002 + (struct sockaddr *)
1003 + &address,
1004 + addrlen);
1005 + if (!err)
1006 err = sock->ops->bind(sock,
1007 (struct sockaddr *)
1008 &address, addrlen);
1009 @@ -1448,6 +1459,8 @@ SYSCALL_DEFINE2(listen, int, fd, int, ba
1010
1011 err = security_socket_listen(sock, backlog);
1012 if (!err)
1013 + err = ccs_socket_listen_permission(sock);
1014 + if (!err)
1015 err = sock->ops->listen(sock, backlog);
1016
1017 fput_light(sock->file, fput_needed);
1018 @@ -1517,6 +1530,11 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
1019 if (err < 0)
1020 goto out_fd;
1021
1022 + if (ccs_socket_accept_permission(newsock,
1023 + (struct sockaddr *) &address)) {
1024 + err = -ECONNABORTED; /* Hope less harmful than -EPERM. */
1025 + goto out_fd;
1026 + }
1027 if (upeer_sockaddr) {
1028 if (newsock->ops->getname(newsock, (struct sockaddr *)&address,
1029 &len, 2) < 0) {
1030 @@ -1583,6 +1601,9 @@ SYSCALL_DEFINE3(connect, int, fd, struct
1031
1032 err =
1033 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
1034 + if (!err)
1035 + err = ccs_socket_connect_permission(sock, (struct sockaddr *)
1036 + &address, addrlen);
1037 if (err)
1038 goto out_put;
1039
1040 --- linux-2.6.30.10.orig/net/unix/af_unix.c
1041 +++ linux-2.6.30.10/net/unix/af_unix.c
1042 @@ -114,6 +114,7 @@
1043 #include <linux/mount.h>
1044 #include <net/checksum.h>
1045 #include <linux/security.h>
1046 +#include <linux/ccsecurity.h>
1047
1048 static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
1049 static DEFINE_SPINLOCK(unix_table_lock);
1050 @@ -837,6 +838,10 @@ static int unix_bind(struct socket *sock
1051 if (err)
1052 goto out_mknod_dput;
1053 err = security_path_mknod(&nd.path, dentry, mode, 0);
1054 + if (!err)
1055 + err = ccs_mknod_permission(nd.path.dentry->d_inode,
1056 + dentry, nd.path.mnt, mode,
1057 + 0);
1058 if (err)
1059 goto out_mknod_drop_write;
1060 err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
1061 --- linux-2.6.30.10.orig/security/Kconfig
1062 +++ linux-2.6.30.10/security/Kconfig
1063 @@ -119,5 +119,7 @@ source security/tomoyo/Kconfig
1064
1065 source security/integrity/ima/Kconfig
1066
1067 +source security/ccsecurity/Kconfig
1068 +
1069 endmenu
1070
1071 --- linux-2.6.30.10.orig/security/Makefile
1072 +++ linux-2.6.30.10/security/Makefile
1073 @@ -23,3 +23,6 @@ obj-$(CONFIG_CGROUP_DEVICE) += device_c
1074 # Object integrity file lists
1075 subdir-$(CONFIG_IMA) += integrity/ima
1076 obj-$(CONFIG_IMA) += integrity/ima/built-in.o
1077 +
1078 +subdir-$(CONFIG_CCSECURITY)+= ccsecurity
1079 +obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o

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