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

Subversion リポジトリの参照

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

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