Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/caitsith-patch/patches/ccs-patch-3.4.diff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 220 - (show annotations) (download) (as text)
Sat Oct 29 13:44:43 2016 UTC (7 years, 7 months ago) by kumaneko
File MIME type: text/x-diff
File size: 28319 byte(s)


1 This is TOMOYO Linux patch for kernel 3.4.113.
2
3 Source code for this patch is https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.4.113.tar.xz
4 ---
5 fs/exec.c | 2
6 fs/open.c | 2
7 fs/proc/version.c | 7 ++
8 include/linux/init_task.h | 9 +++
9 include/linux/sched.h | 6 ++
10 include/linux/security.h | 55 ++++++++++--------
11 include/net/ip.h | 2
12 kernel/fork.c | 5 +
13 kernel/kexec.c | 3 +
14 kernel/module.c | 5 +
15 kernel/ptrace.c | 10 +++
16 kernel/sched/core.c | 2
17 kernel/signal.c | 10 +++
18 kernel/sys.c | 10 +++
19 kernel/time/ntp.c | 8 ++
20 net/ipv4/raw.c | 4 +
21 net/ipv4/udp.c | 4 +
22 net/ipv6/raw.c | 4 +
23 net/ipv6/udp.c | 4 +
24 net/socket.c | 4 +
25 net/unix/af_unix.c | 4 +
26 security/Kconfig | 2
27 security/Makefile | 3 +
28 security/security.c | 134 +++++++++++++++++++++++++++++++++++++---------
29 24 files changed, 250 insertions(+), 49 deletions(-)
30
31 --- linux-3.4.113.orig/fs/exec.c
32 +++ linux-3.4.113/fs/exec.c
33 @@ -1577,7 +1577,7 @@ static int do_execve_common(const char *
34 if (retval < 0)
35 goto out;
36
37 - retval = search_binary_handler(bprm,regs);
38 + retval = ccs_search_binary_handler(bprm, regs);
39 if (retval < 0)
40 goto out;
41
42 --- linux-3.4.113.orig/fs/open.c
43 +++ linux-3.4.113/fs/open.c
44 @@ -1105,6 +1105,8 @@ EXPORT_SYMBOL(sys_close);
45 */
46 SYSCALL_DEFINE0(vhangup)
47 {
48 + if (!ccs_capable(CCS_SYS_VHANGUP))
49 + return -EPERM;
50 if (capable(CAP_SYS_TTY_CONFIG)) {
51 tty_vhangup_self();
52 return 0;
53 --- linux-3.4.113.orig/fs/proc/version.c
54 +++ linux-3.4.113/fs/proc/version.c
55 @@ -32,3 +32,10 @@ static int __init proc_version_init(void
56 return 0;
57 }
58 module_init(proc_version_init);
59 +
60 +static int __init ccs_show_version(void)
61 +{
62 + printk(KERN_INFO "Hook version: 3.4.113 2016/10/27\n");
63 + return 0;
64 +}
65 +module_init(ccs_show_version);
66 --- linux-3.4.113.orig/include/linux/init_task.h
67 +++ linux-3.4.113/include/linux/init_task.h
68 @@ -144,6 +144,14 @@ extern struct task_group root_task_group
69
70 #define INIT_TASK_COMM "swapper"
71
72 +#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY)
73 +#define INIT_CCSECURITY \
74 + .ccs_domain_info = NULL, \
75 + .ccs_flags = 0,
76 +#else
77 +#define INIT_CCSECURITY
78 +#endif
79 +
80 /*
81 * INIT_TASK is used to set up the first task table, touch at
82 * your own risk!. Base=0, limit=0x1fffff (=2MB)
83 @@ -212,6 +220,7 @@ extern struct task_group root_task_group
84 INIT_TRACE_RECURSION \
85 INIT_TASK_RCU_PREEMPT(tsk) \
86 INIT_CPUSET_SEQ \
87 + INIT_CCSECURITY \
88 }
89
90
91 --- linux-3.4.113.orig/include/linux/sched.h
92 +++ linux-3.4.113/include/linux/sched.h
93 @@ -44,6 +44,8 @@
94
95 #ifdef __KERNEL__
96
97 +struct ccs_domain_info;
98 +
99 struct sched_param {
100 int sched_priority;
101 };
102 @@ -1629,6 +1631,10 @@ struct task_struct {
103 #ifdef CONFIG_HAVE_HW_BREAKPOINT
104 atomic_t ptrace_bp_refcnt;
105 #endif
106 +#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY)
107 + struct ccs_domain_info *ccs_domain_info;
108 + u32 ccs_flags;
109 +#endif
110 };
111
112 /* Future-safe accessor for struct task_struct's cpus_allowed. */
113 --- linux-3.4.113.orig/include/linux/security.h
114 +++ linux-3.4.113/include/linux/security.h
115 @@ -52,6 +52,7 @@ struct msg_queue;
116 struct xattr;
117 struct xfrm_sec_ctx;
118 struct mm_struct;
119 +#include <linux/ccsecurity.h>
120
121 /* Maximum number of letters for an LSM name string */
122 #define SECURITY_NAME_MAX 10
123 @@ -1900,7 +1901,10 @@ static inline int security_syslog(int ty
124 static inline int security_settime(const struct timespec *ts,
125 const struct timezone *tz)
126 {
127 - return cap_settime(ts, tz);
128 + int error = cap_settime(ts, tz);
129 + if (!error && !ccs_capable(CCS_SYS_SETTIME))
130 + error = -EPERM;
131 + return error;
132 }
133
134 static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
135 @@ -1969,18 +1973,18 @@ static inline int security_sb_mount(char
136 char *type, unsigned long flags,
137 void *data)
138 {
139 - return 0;
140 + return ccs_mount_permission(dev_name, path, type, flags, data);
141 }
142
143 static inline int security_sb_umount(struct vfsmount *mnt, int flags)
144 {
145 - return 0;
146 + return ccs_umount_permission(mnt, flags);
147 }
148
149 static inline int security_sb_pivotroot(struct path *old_path,
150 struct path *new_path)
151 {
152 - return 0;
153 + return ccs_pivot_root_permission(old_path, new_path);
154 }
155
156 static inline int security_sb_set_mnt_opts(struct super_block *sb,
157 @@ -2104,7 +2108,7 @@ static inline int security_inode_setattr
158 static inline int security_inode_getattr(struct vfsmount *mnt,
159 struct dentry *dentry)
160 {
161 - return 0;
162 + return ccs_getattr_permission(mnt, dentry);
163 }
164
165 static inline int security_inode_setxattr(struct dentry *dentry,
166 @@ -2180,7 +2184,7 @@ static inline void security_file_free(st
167 static inline int security_file_ioctl(struct file *file, unsigned int cmd,
168 unsigned long arg)
169 {
170 - return 0;
171 + return ccs_ioctl_permission(file, cmd, arg);
172 }
173
174 static inline int security_file_mmap(struct file *file, unsigned long reqprot,
175 @@ -2207,7 +2211,7 @@ static inline int security_file_lock(str
176 static inline int security_file_fcntl(struct file *file, unsigned int cmd,
177 unsigned long arg)
178 {
179 - return 0;
180 + return ccs_fcntl_permission(file, cmd, arg);
181 }
182
183 static inline int security_file_set_fowner(struct file *file)
184 @@ -2230,7 +2234,7 @@ static inline int security_file_receive(
185 static inline int security_dentry_open(struct file *file,
186 const struct cred *cred)
187 {
188 - return 0;
189 + return ccs_open_permission(file);
190 }
191
192 static inline int security_task_create(unsigned long clone_flags)
193 @@ -2573,7 +2577,7 @@ static inline int security_unix_may_send
194 static inline int security_socket_create(int family, int type,
195 int protocol, int kern)
196 {
197 - return 0;
198 + return ccs_socket_create_permission(family, type, protocol);
199 }
200
201 static inline int security_socket_post_create(struct socket *sock,
202 @@ -2588,19 +2592,19 @@ static inline int security_socket_bind(s
203 struct sockaddr *address,
204 int addrlen)
205 {
206 - return 0;
207 + return ccs_socket_bind_permission(sock, address, addrlen);
208 }
209
210 static inline int security_socket_connect(struct socket *sock,
211 struct sockaddr *address,
212 int addrlen)
213 {
214 - return 0;
215 + return ccs_socket_connect_permission(sock, address, addrlen);
216 }
217
218 static inline int security_socket_listen(struct socket *sock, int backlog)
219 {
220 - return 0;
221 + return ccs_socket_listen_permission(sock);
222 }
223
224 static inline int security_socket_accept(struct socket *sock,
225 @@ -2612,7 +2616,7 @@ static inline int security_socket_accept
226 static inline int security_socket_sendmsg(struct socket *sock,
227 struct msghdr *msg, int size)
228 {
229 - return 0;
230 + return ccs_socket_sendmsg_permission(sock, msg, size);
231 }
232
233 static inline int security_socket_recvmsg(struct socket *sock,
234 @@ -2833,44 +2837,47 @@ int security_path_chmod(struct path *pat
235 int security_path_chown(struct path *path, uid_t uid, gid_t gid);
236 int security_path_chroot(struct path *path);
237 #else /* CONFIG_SECURITY_PATH */
238 +
239 +#include <linux/path.h>
240 +
241 static inline int security_path_unlink(struct path *dir, struct dentry *dentry)
242 {
243 - return 0;
244 + return ccs_unlink_permission(dentry, dir->mnt);
245 }
246
247 static inline int security_path_mkdir(struct path *dir, struct dentry *dentry,
248 umode_t mode)
249 {
250 - return 0;
251 + return ccs_mkdir_permission(dentry, dir->mnt, mode);
252 }
253
254 static inline int security_path_rmdir(struct path *dir, struct dentry *dentry)
255 {
256 - return 0;
257 + return ccs_rmdir_permission(dentry, dir->mnt);
258 }
259
260 static inline int security_path_mknod(struct path *dir, struct dentry *dentry,
261 umode_t mode, unsigned int dev)
262 {
263 - return 0;
264 + return ccs_mknod_permission(dentry, dir->mnt, mode, dev);
265 }
266
267 static inline int security_path_truncate(struct path *path)
268 {
269 - return 0;
270 + return ccs_truncate_permission(path->dentry, path->mnt);
271 }
272
273 static inline int security_path_symlink(struct path *dir, struct dentry *dentry,
274 const char *old_name)
275 {
276 - return 0;
277 + return ccs_symlink_permission(dentry, dir->mnt, old_name);
278 }
279
280 static inline int security_path_link(struct dentry *old_dentry,
281 struct path *new_dir,
282 struct dentry *new_dentry)
283 {
284 - return 0;
285 + return ccs_link_permission(old_dentry, new_dentry, new_dir->mnt);
286 }
287
288 static inline int security_path_rename(struct path *old_dir,
289 @@ -2878,22 +2885,22 @@ static inline int security_path_rename(s
290 struct path *new_dir,
291 struct dentry *new_dentry)
292 {
293 - return 0;
294 + return ccs_rename_permission(old_dentry, new_dentry, new_dir->mnt);
295 }
296
297 static inline int security_path_chmod(struct path *path, umode_t mode)
298 {
299 - return 0;
300 + return ccs_chmod_permission(path->dentry, path->mnt, mode);
301 }
302
303 static inline int security_path_chown(struct path *path, uid_t uid, gid_t gid)
304 {
305 - return 0;
306 + return ccs_chown_permission(path->dentry, path->mnt, uid, gid);
307 }
308
309 static inline int security_path_chroot(struct path *path)
310 {
311 - return 0;
312 + return ccs_chroot_permission(path);
313 }
314 #endif /* CONFIG_SECURITY_PATH */
315
316 --- linux-3.4.113.orig/include/net/ip.h
317 +++ linux-3.4.113/include/net/ip.h
318 @@ -217,6 +217,8 @@ extern void inet_get_local_port_range(in
319 extern unsigned long *sysctl_local_reserved_ports;
320 static inline int inet_is_reserved_local_port(int port)
321 {
322 + if (ccs_lport_reserved(port))
323 + return 1;
324 return test_bit(port, sysctl_local_reserved_ports);
325 }
326
327 --- linux-3.4.113.orig/kernel/fork.c
328 +++ linux-3.4.113/kernel/fork.c
329 @@ -199,6 +199,7 @@ void __put_task_struct(struct task_struc
330 delayacct_tsk_free(tsk);
331 put_signal_struct(tsk->signal);
332
333 + ccs_free_task_security(tsk);
334 if (!profile_handoff_task(tsk))
335 free_task(tsk);
336 }
337 @@ -1291,6 +1292,9 @@ static struct task_struct *copy_process(
338 retval = audit_alloc(p);
339 if (retval)
340 goto bad_fork_cleanup_perf;
341 + retval = ccs_alloc_task_security(p);
342 + if (retval)
343 + goto bad_fork_cleanup_audit;
344 /* copy all the process information */
345 retval = copy_semundo(clone_flags, p);
346 if (retval)
347 @@ -1486,6 +1490,7 @@ bad_fork_cleanup_semundo:
348 exit_sem(p);
349 bad_fork_cleanup_audit:
350 audit_free(p);
351 + ccs_free_task_security(p);
352 bad_fork_cleanup_perf:
353 perf_event_free_task(p);
354 bad_fork_cleanup_policy:
355 --- linux-3.4.113.orig/kernel/kexec.c
356 +++ linux-3.4.113/kernel/kexec.c
357 @@ -38,6 +38,7 @@
358 #include <asm/uaccess.h>
359 #include <asm/io.h>
360 #include <asm/sections.h>
361 +#include <linux/ccsecurity.h>
362
363 /* Per cpu memory for storing cpu states in case of system crash. */
364 note_buf_t __percpu *crash_notes;
365 @@ -946,6 +947,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned lon
366 /* We only trust the superuser with rebooting the system. */
367 if (!capable(CAP_SYS_BOOT))
368 return -EPERM;
369 + if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
370 + return -EPERM;
371
372 /*
373 * Verify we have a legal set of flags
374 --- linux-3.4.113.orig/kernel/module.c
375 +++ linux-3.4.113/kernel/module.c
376 @@ -58,6 +58,7 @@
377 #include <linux/jump_label.h>
378 #include <linux/pfn.h>
379 #include <linux/bsearch.h>
380 +#include <linux/ccsecurity.h>
381
382 #define CREATE_TRACE_POINTS
383 #include <trace/events/module.h>
384 @@ -774,6 +775,8 @@ SYSCALL_DEFINE2(delete_module, const cha
385
386 if (!capable(CAP_SYS_MODULE) || modules_disabled)
387 return -EPERM;
388 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
389 + return -EPERM;
390
391 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
392 return -EFAULT;
393 @@ -3031,6 +3034,8 @@ SYSCALL_DEFINE3(init_module, void __user
394 /* Must have permission */
395 if (!capable(CAP_SYS_MODULE) || modules_disabled)
396 return -EPERM;
397 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
398 + return -EPERM;
399
400 /* Do all the hard work */
401 mod = load_module(umod, len, uargs);
402 --- linux-3.4.113.orig/kernel/ptrace.c
403 +++ linux-3.4.113/kernel/ptrace.c
404 @@ -920,6 +920,11 @@ SYSCALL_DEFINE4(ptrace, long, request, l
405 {
406 struct task_struct *child;
407 long ret;
408 + {
409 + const int rc = ccs_ptrace_permission(request, pid);
410 + if (rc)
411 + return rc;
412 + }
413
414 if (request == PTRACE_TRACEME) {
415 ret = ptrace_traceme();
416 @@ -1067,6 +1072,11 @@ asmlinkage long compat_sys_ptrace(compat
417 {
418 struct task_struct *child;
419 long ret;
420 + {
421 + const int rc = ccs_ptrace_permission(request, pid);
422 + if (rc)
423 + return rc;
424 + }
425
426 if (request == PTRACE_TRACEME) {
427 ret = ptrace_traceme();
428 --- linux-3.4.113.orig/kernel/sched/core.c
429 +++ linux-3.4.113/kernel/sched/core.c
430 @@ -4124,6 +4124,8 @@ int can_nice(const struct task_struct *p
431 SYSCALL_DEFINE1(nice, int, increment)
432 {
433 long nice, retval;
434 + if (!ccs_capable(CCS_SYS_NICE))
435 + return -EPERM;
436
437 /*
438 * Setpriority might change our priority at the same moment.
439 --- linux-3.4.113.orig/kernel/signal.c
440 +++ linux-3.4.113/kernel/signal.c
441 @@ -2825,6 +2825,8 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const s
442 SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
443 {
444 struct siginfo info;
445 + if (ccs_kill_permission(pid, sig))
446 + return -EPERM;
447
448 info.si_signo = sig;
449 info.si_errno = 0;
450 @@ -2893,6 +2895,8 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid
451 /* This is only valid for single tasks */
452 if (pid <= 0 || tgid <= 0)
453 return -EINVAL;
454 + if (ccs_tgkill_permission(tgid, pid, sig))
455 + return -EPERM;
456
457 return do_tkill(tgid, pid, sig);
458 }
459 @@ -2909,6 +2913,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int,
460 /* This is only valid for single tasks */
461 if (pid <= 0)
462 return -EINVAL;
463 + if (ccs_tkill_permission(pid, sig))
464 + return -EPERM;
465
466 return do_tkill(0, pid, sig);
467 }
468 @@ -2936,6 +2942,8 @@ SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t,
469 return -EPERM;
470 }
471 info.si_signo = sig;
472 + if (ccs_sigqueue_permission(pid, sig))
473 + return -EPERM;
474
475 /* POSIX.1b doesn't mention process groups. */
476 return kill_proc_info(sig, &info, pid);
477 @@ -2956,6 +2964,8 @@ long do_rt_tgsigqueueinfo(pid_t tgid, pi
478 return -EPERM;
479 }
480 info->si_signo = sig;
481 + if (ccs_tgsigqueue_permission(tgid, pid, sig))
482 + return -EPERM;
483
484 return do_send_specific(tgid, pid, sig, info);
485 }
486 --- linux-3.4.113.orig/kernel/sys.c
487 +++ linux-3.4.113/kernel/sys.c
488 @@ -180,6 +180,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
489
490 if (which > PRIO_USER || which < PRIO_PROCESS)
491 goto out;
492 + if (!ccs_capable(CCS_SYS_NICE)) {
493 + error = -EPERM;
494 + goto out;
495 + }
496
497 /* normalize: avoid signed division (rounding problems) */
498 error = -ESRCH;
499 @@ -468,6 +472,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
500 magic2 != LINUX_REBOOT_MAGIC2B &&
501 magic2 != LINUX_REBOOT_MAGIC2C))
502 return -EINVAL;
503 + if (!ccs_capable(CCS_SYS_REBOOT))
504 + return -EPERM;
505
506 /*
507 * If pid namespaces are enabled and the current task is in a child
508 @@ -1314,6 +1320,8 @@ SYSCALL_DEFINE2(sethostname, char __user
509
510 if (len < 0 || len > __NEW_UTS_LEN)
511 return -EINVAL;
512 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
513 + return -EPERM;
514 down_write(&uts_sem);
515 errno = -EFAULT;
516 if (!copy_from_user(tmp, name, len)) {
517 @@ -1364,6 +1372,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
518 return -EPERM;
519 if (len < 0 || len > __NEW_UTS_LEN)
520 return -EINVAL;
521 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
522 + return -EPERM;
523
524 down_write(&uts_sem);
525 errno = -EFAULT;
526 --- linux-3.4.113.orig/kernel/time/ntp.c
527 +++ linux-3.4.113/kernel/time/ntp.c
528 @@ -15,6 +15,7 @@
529 #include <linux/time.h>
530 #include <linux/mm.h>
531 #include <linux/module.h>
532 +#include <linux/ccsecurity.h>
533
534 #include "tick-internal.h"
535
536 @@ -663,10 +664,15 @@ int __do_adjtimex(struct timex *txc)
537 if (!(txc->modes & ADJ_OFFSET_READONLY) &&
538 !capable(CAP_SYS_TIME))
539 return -EPERM;
540 + if (!(txc->modes & ADJ_OFFSET_READONLY) &&
541 + !ccs_capable(CCS_SYS_SETTIME))
542 + return -EPERM;
543 } else {
544 /* In order to modify anything, you gotta be super-user! */
545 if (txc->modes && !capable(CAP_SYS_TIME))
546 return -EPERM;
547 + if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
548 + return -EPERM;
549
550 /*
551 * if the quartz is off by more than 10% then
552 @@ -684,6 +690,8 @@ int __do_adjtimex(struct timex *txc)
553 delta.tv_nsec = txc->time.tv_usec;
554 if (!capable(CAP_SYS_TIME))
555 return -EPERM;
556 + if (!ccs_capable(CCS_SYS_SETTIME))
557 + return -EPERM;
558 if (!(txc->modes & ADJ_NANO))
559 delta.tv_nsec *= 1000;
560 result = timekeeping_inject_offset(&delta);
561 --- linux-3.4.113.orig/net/ipv4/raw.c
562 +++ linux-3.4.113/net/ipv4/raw.c
563 @@ -696,6 +696,10 @@ static int raw_recvmsg(struct kiocb *ioc
564 skb = skb_recv_datagram(sk, flags, noblock, &err);
565 if (!skb)
566 goto out;
567 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
568 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
569 + goto out;
570 + }
571
572 copied = skb->len;
573 if (len < copied) {
574 --- linux-3.4.113.orig/net/ipv4/udp.c
575 +++ linux-3.4.113/net/ipv4/udp.c
576 @@ -1186,6 +1186,10 @@ try_again:
577 &peeked, &off, &err);
578 if (!skb)
579 goto out;
580 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
581 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
582 + goto out;
583 + }
584
585 ulen = skb->len - sizeof(struct udphdr);
586 copied = len;
587 --- linux-3.4.113.orig/net/ipv6/raw.c
588 +++ linux-3.4.113/net/ipv6/raw.c
589 @@ -466,6 +466,10 @@ static int rawv6_recvmsg(struct kiocb *i
590 skb = skb_recv_datagram(sk, flags, noblock, &err);
591 if (!skb)
592 goto out;
593 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
594 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
595 + goto out;
596 + }
597
598 copied = skb->len;
599 if (copied > len) {
600 --- linux-3.4.113.orig/net/ipv6/udp.c
601 +++ linux-3.4.113/net/ipv6/udp.c
602 @@ -360,6 +360,10 @@ try_again:
603 &peeked, &off, &err);
604 if (!skb)
605 goto out;
606 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
607 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
608 + goto out;
609 + }
610
611 ulen = skb->len - sizeof(struct udphdr);
612 copied = len;
613 --- linux-3.4.113.orig/net/socket.c
614 +++ linux-3.4.113/net/socket.c
615 @@ -1554,6 +1554,10 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
616 if (err < 0)
617 goto out_fd;
618
619 + if (ccs_socket_post_accept_permission(sock, newsock)) {
620 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
621 + goto out_fd;
622 + }
623 if (upeer_sockaddr) {
624 if (newsock->ops->getname(newsock, (struct sockaddr *)&address,
625 &len, 2) < 0) {
626 --- linux-3.4.113.orig/net/unix/af_unix.c
627 +++ linux-3.4.113/net/unix/af_unix.c
628 @@ -1959,6 +1959,10 @@ static int unix_dgram_recvmsg(struct kio
629 wake_up_interruptible_sync_poll(&u->peer_wait,
630 POLLOUT | POLLWRNORM | POLLWRBAND);
631
632 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
633 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
634 + goto out_unlock;
635 + }
636 if (msg->msg_name)
637 unix_copy_addr(msg, skb->sk);
638
639 --- linux-3.4.113.orig/security/Kconfig
640 +++ linux-3.4.113/security/Kconfig
641 @@ -233,5 +233,7 @@ config DEFAULT_SECURITY
642 default "yama" if DEFAULT_SECURITY_YAMA
643 default "" if DEFAULT_SECURITY_DAC
644
645 +source security/ccsecurity/Kconfig
646 +
647 endmenu
648
649 --- linux-3.4.113.orig/security/Makefile
650 +++ linux-3.4.113/security/Makefile
651 @@ -28,3 +28,6 @@ obj-$(CONFIG_CGROUP_DEVICE) += device_c
652 # Object integrity file lists
653 subdir-$(CONFIG_INTEGRITY) += integrity
654 obj-$(CONFIG_INTEGRITY) += integrity/built-in.o
655 +
656 +subdir-$(CONFIG_CCSECURITY) += ccsecurity
657 +obj-$(CONFIG_CCSECURITY) += ccsecurity/built-in.o
658 --- linux-3.4.113.orig/security/security.c
659 +++ linux-3.4.113/security/security.c
660 @@ -186,7 +186,10 @@ int security_syslog(int type)
661
662 int security_settime(const struct timespec *ts, const struct timezone *tz)
663 {
664 - return security_ops->settime(ts, tz);
665 + int error = security_ops->settime(ts, tz);
666 + if (!error && !ccs_capable(CCS_SYS_SETTIME))
667 + error = -EPERM;
668 + return error;
669 }
670
671 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
672 @@ -263,17 +266,27 @@ int security_sb_statfs(struct dentry *de
673 int security_sb_mount(char *dev_name, struct path *path,
674 char *type, unsigned long flags, void *data)
675 {
676 - return security_ops->sb_mount(dev_name, path, type, flags, data);
677 + int error = security_ops->sb_mount(dev_name, path, type, flags, data);
678 + if (!error)
679 + error = ccs_mount_permission(dev_name, path, type, flags,
680 + data);
681 + return error;
682 }
683
684 int security_sb_umount(struct vfsmount *mnt, int flags)
685 {
686 - return security_ops->sb_umount(mnt, flags);
687 + int error = security_ops->sb_umount(mnt, flags);
688 + if (!error)
689 + error = ccs_umount_permission(mnt, flags);
690 + return error;
691 }
692
693 int security_sb_pivotroot(struct path *old_path, struct path *new_path)
694 {
695 - return security_ops->sb_pivotroot(old_path, new_path);
696 + int error = security_ops->sb_pivotroot(old_path, new_path);
697 + if (!error)
698 + error = ccs_pivot_root_permission(old_path, new_path);
699 + return error;
700 }
701
702 int security_sb_set_mnt_opts(struct super_block *sb,
703 @@ -360,86 +373,132 @@ EXPORT_SYMBOL(security_old_inode_init_se
704 int security_path_mknod(struct path *dir, struct dentry *dentry, umode_t mode,
705 unsigned int dev)
706 {
707 + int error;
708 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
709 return 0;
710 - return security_ops->path_mknod(dir, dentry, mode, dev);
711 + error = security_ops->path_mknod(dir, dentry, mode, dev);
712 + if (!error)
713 + error = ccs_mknod_permission(dentry, dir->mnt, mode, dev);
714 + return error;
715 }
716 EXPORT_SYMBOL(security_path_mknod);
717
718 int security_path_mkdir(struct path *dir, struct dentry *dentry, umode_t mode)
719 {
720 + int error;
721 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
722 return 0;
723 - return security_ops->path_mkdir(dir, dentry, mode);
724 + error = security_ops->path_mkdir(dir, dentry, mode);
725 + if (!error)
726 + error = ccs_mkdir_permission(dentry, dir->mnt, mode);
727 + return error;
728 }
729 EXPORT_SYMBOL(security_path_mkdir);
730
731 int security_path_rmdir(struct path *dir, struct dentry *dentry)
732 {
733 + int error;
734 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
735 return 0;
736 - return security_ops->path_rmdir(dir, dentry);
737 + error = security_ops->path_rmdir(dir, dentry);
738 + if (!error)
739 + error = ccs_rmdir_permission(dentry, dir->mnt);
740 + return error;
741 }
742
743 int security_path_unlink(struct path *dir, struct dentry *dentry)
744 {
745 + int error;
746 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
747 return 0;
748 - return security_ops->path_unlink(dir, dentry);
749 + error = security_ops->path_unlink(dir, dentry);
750 + if (!error)
751 + error = ccs_unlink_permission(dentry, dir->mnt);
752 + return error;
753 }
754 EXPORT_SYMBOL(security_path_unlink);
755
756 int security_path_symlink(struct path *dir, struct dentry *dentry,
757 const char *old_name)
758 {
759 + int error;
760 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
761 return 0;
762 - return security_ops->path_symlink(dir, dentry, old_name);
763 + error = security_ops->path_symlink(dir, dentry, old_name);
764 + if (!error)
765 + error = ccs_symlink_permission(dentry, dir->mnt, old_name);
766 + return error;
767 }
768
769 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
770 struct dentry *new_dentry)
771 {
772 + int error;
773 if (unlikely(IS_PRIVATE(old_dentry->d_inode)))
774 return 0;
775 - return security_ops->path_link(old_dentry, new_dir, new_dentry);
776 + error = security_ops->path_link(old_dentry, new_dir, new_dentry);
777 + if (!error)
778 + error = ccs_link_permission(old_dentry, new_dentry,
779 + new_dir->mnt);
780 + return error;
781 }
782
783 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
784 struct path *new_dir, struct dentry *new_dentry)
785 {
786 + int error;
787 if (unlikely(IS_PRIVATE(old_dentry->d_inode) ||
788 (new_dentry->d_inode && IS_PRIVATE(new_dentry->d_inode))))
789 return 0;
790 - return security_ops->path_rename(old_dir, old_dentry, new_dir,
791 - new_dentry);
792 + error = security_ops->path_rename(old_dir, old_dentry, new_dir,
793 + new_dentry);
794 + if (!error)
795 + error = ccs_rename_permission(old_dentry, new_dentry,
796 + new_dir->mnt);
797 + return error;
798 }
799 EXPORT_SYMBOL(security_path_rename);
800
801 int security_path_truncate(struct path *path)
802 {
803 + int error;
804 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
805 return 0;
806 - return security_ops->path_truncate(path);
807 + error = security_ops->path_truncate(path);
808 + if (!error)
809 + error = ccs_truncate_permission(path->dentry, path->mnt);
810 + return error;
811 }
812
813 int security_path_chmod(struct path *path, umode_t mode)
814 {
815 + int error;
816 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
817 return 0;
818 - return security_ops->path_chmod(path, mode);
819 + error = security_ops->path_chmod(path, mode);
820 + if (!error)
821 + error = ccs_chmod_permission(path->dentry, path->mnt, mode);
822 + return error;
823 }
824
825 int security_path_chown(struct path *path, uid_t uid, gid_t gid)
826 {
827 + int error;
828 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
829 return 0;
830 - return security_ops->path_chown(path, uid, gid);
831 + error = security_ops->path_chown(path, uid, gid);
832 + if (!error)
833 + error = ccs_chown_permission(path->dentry, path->mnt, uid,
834 + gid);
835 + return error;
836 }
837
838 int security_path_chroot(struct path *path)
839 {
840 - return security_ops->path_chroot(path);
841 + int error = security_ops->path_chroot(path);
842 + if (!error)
843 + error = ccs_chroot_permission(path);
844 + return error;
845 }
846 #endif
847
848 @@ -542,9 +601,13 @@ EXPORT_SYMBOL_GPL(security_inode_setattr
849
850 int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
851 {
852 + int error;
853 if (unlikely(IS_PRIVATE(dentry->d_inode)))
854 return 0;
855 - return security_ops->inode_getattr(mnt, dentry);
856 + error = security_ops->inode_getattr(mnt, dentry);
857 + if (!error)
858 + error = ccs_getattr_permission(mnt, dentry);
859 + return error;
860 }
861
862 int security_inode_setxattr(struct dentry *dentry, const char *name,
863 @@ -654,7 +717,10 @@ void security_file_free(struct file *fil
864
865 int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
866 {
867 - return security_ops->file_ioctl(file, cmd, arg);
868 + int error = security_ops->file_ioctl(file, cmd, arg);
869 + if (!error)
870 + error = ccs_ioctl_permission(file, cmd, arg);
871 + return error;
872 }
873
874 int security_file_mmap(struct file *file, unsigned long reqprot,
875 @@ -682,7 +748,10 @@ int security_file_lock(struct file *file
876
877 int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
878 {
879 - return security_ops->file_fcntl(file, cmd, arg);
880 + int error = security_ops->file_fcntl(file, cmd, arg);
881 + if (!error)
882 + error = ccs_fcntl_permission(file, cmd, arg);
883 + return error;
884 }
885
886 int security_file_set_fowner(struct file *file)
887 @@ -706,6 +775,8 @@ int security_dentry_open(struct file *fi
888 int ret;
889
890 ret = security_ops->dentry_open(file, cred);
891 + if (!ret)
892 + ret = ccs_open_permission(file);
893 if (ret)
894 return ret;
895
896 @@ -1020,7 +1091,10 @@ EXPORT_SYMBOL(security_unix_may_send);
897
898 int security_socket_create(int family, int type, int protocol, int kern)
899 {
900 - return security_ops->socket_create(family, type, protocol, kern);
901 + int error = security_ops->socket_create(family, type, protocol, kern);
902 + if (!error)
903 + error = ccs_socket_create_permission(family, type, protocol);
904 + return error;
905 }
906
907 int security_socket_post_create(struct socket *sock, int family,
908 @@ -1032,17 +1106,26 @@ int security_socket_post_create(struct s
909
910 int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
911 {
912 - return security_ops->socket_bind(sock, address, addrlen);
913 + int error = security_ops->socket_bind(sock, address, addrlen);
914 + if (!error)
915 + error = ccs_socket_bind_permission(sock, address, addrlen);
916 + return error;
917 }
918
919 int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
920 {
921 - return security_ops->socket_connect(sock, address, addrlen);
922 + int error = security_ops->socket_connect(sock, address, addrlen);
923 + if (!error)
924 + error = ccs_socket_connect_permission(sock, address, addrlen);
925 + return error;
926 }
927
928 int security_socket_listen(struct socket *sock, int backlog)
929 {
930 - return security_ops->socket_listen(sock, backlog);
931 + int error = security_ops->socket_listen(sock, backlog);
932 + if (!error)
933 + error = ccs_socket_listen_permission(sock);
934 + return error;
935 }
936
937 int security_socket_accept(struct socket *sock, struct socket *newsock)
938 @@ -1052,7 +1135,10 @@ int security_socket_accept(struct socket
939
940 int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
941 {
942 - return security_ops->socket_sendmsg(sock, msg, size);
943 + int error = security_ops->socket_sendmsg(sock, msg, size);
944 + if (!error)
945 + error = ccs_socket_sendmsg_permission(sock, msg, size);
946 + return error;
947 }
948
949 int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,

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