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

Subversion リポジトリの参照

Contents of /trunk/1.8.x/ccs-patch/patches/ccs-patch-3.10.diff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6456 - (show annotations) (download) (as text)
Wed Nov 11 11:27:21 2015 UTC (8 years, 6 months ago) by kumaneko
File MIME type: text/x-diff
File size: 27733 byte(s)


1 This is TOMOYO Linux patch for kernel 3.10.93.
2
3 Source code for this patch is https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.93.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 | 107 ++++++++++++++++++++++++++++++++++++++++------
29 24 files changed, 235 insertions(+), 37 deletions(-)
30
31 --- linux-3.10.93.orig/fs/exec.c
32 +++ linux-3.10.93/fs/exec.c
33 @@ -1560,7 +1560,7 @@ static int do_execve_common(const char *
34 if (retval < 0)
35 goto out;
36
37 - retval = search_binary_handler(bprm);
38 + retval = ccs_search_binary_handler(bprm);
39 if (retval < 0)
40 goto out;
41
42 --- linux-3.10.93.orig/fs/open.c
43 +++ linux-3.10.93/fs/open.c
44 @@ -1021,6 +1021,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.10.93.orig/fs/proc/version.c
54 +++ linux-3.10.93/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.10.93 2015/11/11\n");
63 + return 0;
64 +}
65 +module_init(ccs_show_version);
66 --- linux-3.10.93.orig/include/linux/init_task.h
67 +++ linux-3.10.93/include/linux/init_task.h
68 @@ -155,6 +155,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 @@ -224,6 +232,7 @@ extern struct task_group root_task_group
84 INIT_TASK_RCU_PREEMPT(tsk) \
85 INIT_CPUSET_SEQ \
86 INIT_VTIME(tsk) \
87 + INIT_CCSECURITY \
88 }
89
90
91 --- linux-3.10.93.orig/include/linux/sched.h
92 +++ linux-3.10.93/include/linux/sched.h
93 @@ -4,6 +4,8 @@
94 #include <uapi/linux/sched.h>
95
96
97 +struct ccs_domain_info;
98 +
99 struct sched_param {
100 int sched_priority;
101 };
102 @@ -1428,6 +1430,10 @@ struct task_struct {
103 unsigned int sequential_io;
104 unsigned int sequential_io_avg;
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.10.93.orig/include/linux/security.h
114 +++ linux-3.10.93/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 @@ -1927,7 +1928,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 @@ -1996,18 +2000,18 @@ static inline int security_sb_mount(cons
136 const 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 @@ -2133,7 +2137,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 @@ -2209,7 +2213,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_mmap_file(struct file *file, unsigned long prot,
175 @@ -2238,7 +2242,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 @@ -2261,7 +2265,7 @@ static inline int security_file_receive(
185 static inline int security_file_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 @@ -2614,7 +2618,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 @@ -2629,19 +2633,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 @@ -2653,7 +2657,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 @@ -2894,44 +2898,47 @@ int security_path_chmod(struct path *pat
235 int security_path_chown(struct path *path, kuid_t uid, kgid_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 @@ -2939,22 +2946,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, kuid_t uid, kgid_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.10.93.orig/include/net/ip.h
317 +++ linux-3.10.93/include/net/ip.h
318 @@ -207,6 +207,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.10.93.orig/kernel/fork.c
328 +++ linux-3.10.93/kernel/fork.c
329 @@ -242,6 +242,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 @@ -1325,6 +1326,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 @@ -1522,6 +1526,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.10.93.orig/kernel/kexec.c
356 +++ linux-3.10.93/kernel/kexec.c
357 @@ -37,6 +37,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 @@ -944,6 +945,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.10.93.orig/kernel/module.c
375 +++ linux-3.10.93/kernel/module.c
376 @@ -63,6 +63,7 @@
377 #include <linux/fips.h>
378 #include <uapi/linux/module.h>
379 #include "module-internal.h"
380 +#include <linux/ccsecurity.h>
381
382 #define CREATE_TRACE_POINTS
383 #include <trace/events/module.h>
384 @@ -829,6 +830,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 @@ -3137,6 +3140,8 @@ static int may_init_module(void)
394 {
395 if (!capable(CAP_SYS_MODULE) || modules_disabled)
396 return -EPERM;
397 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
398 + return -EPERM;
399
400 return 0;
401 }
402 --- linux-3.10.93.orig/kernel/ptrace.c
403 +++ linux-3.10.93/kernel/ptrace.c
404 @@ -1018,6 +1018,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 @@ -1165,6 +1170,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.10.93.orig/kernel/sched/core.c
429 +++ linux-3.10.93/kernel/sched/core.c
430 @@ -3732,6 +3732,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.10.93.orig/kernel/signal.c
440 +++ linux-3.10.93/kernel/signal.c
441 @@ -2910,6 +2910,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 @@ -2978,6 +2980,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 @@ -2994,6 +2998,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 @@ -3010,6 +3016,8 @@ static int do_rt_sigqueueinfo(pid_t pid,
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 @@ -3060,6 +3068,8 @@ static int do_rt_tgsigqueueinfo(pid_t tg
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.10.93.orig/kernel/sys.c
487 +++ linux-3.10.93/kernel/sys.c
488 @@ -186,6 +186,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 @@ -478,6 +482,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 @@ -1467,6 +1473,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 @@ -1517,6 +1525,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.10.93.orig/kernel/time/ntp.c
527 +++ linux-3.10.93/kernel/time/ntp.c
528 @@ -16,6 +16,7 @@
529 #include <linux/mm.h>
530 #include <linux/module.h>
531 #include <linux/rtc.h>
532 +#include <linux/ccsecurity.h>
533
534 #include "tick-internal.h"
535 #include "ntp_internal.h"
536 @@ -614,10 +615,15 @@ int ntp_validate_timex(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 * if the quartz is off by more than 10% then
551 * something is VERY wrong!
552 @@ -630,6 +636,8 @@ int ntp_validate_timex(struct timex *txc
553
554 if ((txc->modes & ADJ_SETOFFSET) && (!capable(CAP_SYS_TIME)))
555 return -EPERM;
556 + if ((txc->modes & ADJ_SETOFFSET) && !ccs_capable(CCS_SYS_SETTIME))
557 + return -EPERM;
558
559 /*
560 * Check for potential multiplication overflows that can
561 --- linux-3.10.93.orig/net/ipv4/raw.c
562 +++ linux-3.10.93/net/ipv4/raw.c
563 @@ -700,6 +700,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.10.93.orig/net/ipv4/udp.c
575 +++ linux-3.10.93/net/ipv4/udp.c
576 @@ -1218,6 +1218,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.10.93.orig/net/ipv6/raw.c
588 +++ linux-3.10.93/net/ipv6/raw.c
589 @@ -468,6 +468,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.10.93.orig/net/ipv6/udp.c
601 +++ linux-3.10.93/net/ipv6/udp.c
602 @@ -384,6 +384,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.10.93.orig/net/socket.c
614 +++ linux-3.10.93/net/socket.c
615 @@ -1611,6 +1611,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.10.93.orig/net/unix/af_unix.c
627 +++ linux-3.10.93/net/unix/af_unix.c
628 @@ -1816,6 +1816,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.10.93.orig/security/Kconfig
640 +++ linux-3.10.93/security/Kconfig
641 @@ -167,5 +167,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.10.93.orig/security/Makefile
650 +++ linux-3.10.93/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.10.93.orig/security/security.c
659 +++ linux-3.10.93/security/security.c
660 @@ -202,7 +202,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 @@ -279,17 +282,27 @@ int security_sb_statfs(struct dentry *de
673 int security_sb_mount(const char *dev_name, struct path *path,
674 const 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 @@ -376,31 +389,47 @@ 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 + error = ccs_mknod_permission(dentry, dir->mnt, mode, dev);
711 + if (error)
712 + return error;
713 return security_ops->path_mknod(dir, dentry, mode, dev);
714 }
715 EXPORT_SYMBOL(security_path_mknod);
716
717 int security_path_mkdir(struct path *dir, struct dentry *dentry, umode_t mode)
718 {
719 + int error;
720 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
721 return 0;
722 + error = ccs_mkdir_permission(dentry, dir->mnt, mode);
723 + if (error)
724 + return error;
725 return security_ops->path_mkdir(dir, dentry, mode);
726 }
727 EXPORT_SYMBOL(security_path_mkdir);
728
729 int security_path_rmdir(struct path *dir, struct dentry *dentry)
730 {
731 + int error;
732 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
733 return 0;
734 + error = ccs_rmdir_permission(dentry, dir->mnt);
735 + if (error)
736 + return error;
737 return security_ops->path_rmdir(dir, dentry);
738 }
739
740 int security_path_unlink(struct path *dir, struct dentry *dentry)
741 {
742 + int error;
743 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
744 return 0;
745 + error = ccs_unlink_permission(dentry, dir->mnt);
746 + if (error)
747 + return error;
748 return security_ops->path_unlink(dir, dentry);
749 }
750 EXPORT_SYMBOL(security_path_unlink);
751 @@ -408,25 +437,37 @@ EXPORT_SYMBOL(security_path_unlink);
752 int security_path_symlink(struct path *dir, struct dentry *dentry,
753 const char *old_name)
754 {
755 + int error;
756 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
757 return 0;
758 + error = ccs_symlink_permission(dentry, dir->mnt, old_name);
759 + if (error)
760 + return error;
761 return security_ops->path_symlink(dir, dentry, old_name);
762 }
763
764 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
765 struct dentry *new_dentry)
766 {
767 + int error;
768 if (unlikely(IS_PRIVATE(old_dentry->d_inode)))
769 return 0;
770 + error = ccs_link_permission(old_dentry, new_dentry, new_dir->mnt);
771 + if (error)
772 + return error;
773 return security_ops->path_link(old_dentry, new_dir, new_dentry);
774 }
775
776 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
777 struct path *new_dir, struct dentry *new_dentry)
778 {
779 + int error;
780 if (unlikely(IS_PRIVATE(old_dentry->d_inode) ||
781 (new_dentry->d_inode && IS_PRIVATE(new_dentry->d_inode))))
782 return 0;
783 + error = ccs_rename_permission(old_dentry, new_dentry, new_dir->mnt);
784 + if (error)
785 + return error;
786 return security_ops->path_rename(old_dir, old_dentry, new_dir,
787 new_dentry);
788 }
789 @@ -434,27 +475,42 @@ EXPORT_SYMBOL(security_path_rename);
790
791 int security_path_truncate(struct path *path)
792 {
793 + int error;
794 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
795 return 0;
796 + error = ccs_truncate_permission(path->dentry, path->mnt);
797 + if (error)
798 + return error;
799 return security_ops->path_truncate(path);
800 }
801
802 int security_path_chmod(struct path *path, umode_t mode)
803 {
804 + int error;
805 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
806 return 0;
807 + error = ccs_chmod_permission(path->dentry, path->mnt, mode);
808 + if (error)
809 + return error;
810 return security_ops->path_chmod(path, mode);
811 }
812
813 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
814 {
815 + int error;
816 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
817 return 0;
818 + error = ccs_chown_permission(path->dentry, path->mnt, uid, gid);
819 + if (error)
820 + return error;
821 return security_ops->path_chown(path, uid, gid);
822 }
823
824 int security_path_chroot(struct path *path)
825 {
826 + int error = ccs_chroot_permission(path);
827 + if (error)
828 + return error;
829 return security_ops->path_chroot(path);
830 }
831 #endif
832 @@ -558,9 +614,13 @@ EXPORT_SYMBOL_GPL(security_inode_setattr
833
834 int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
835 {
836 + int error;
837 if (unlikely(IS_PRIVATE(dentry->d_inode)))
838 return 0;
839 - return security_ops->inode_getattr(mnt, dentry);
840 + error = security_ops->inode_getattr(mnt, dentry);
841 + if (!error)
842 + error = ccs_getattr_permission(mnt, dentry);
843 + return error;
844 }
845
846 int security_inode_setxattr(struct dentry *dentry, const char *name,
847 @@ -676,7 +736,10 @@ void security_file_free(struct file *fil
848
849 int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
850 {
851 - return security_ops->file_ioctl(file, cmd, arg);
852 + int error = security_ops->file_ioctl(file, cmd, arg);
853 + if (!error)
854 + error = ccs_ioctl_permission(file, cmd, arg);
855 + return error;
856 }
857
858 static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
859 @@ -742,7 +805,10 @@ int security_file_lock(struct file *file
860
861 int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
862 {
863 - return security_ops->file_fcntl(file, cmd, arg);
864 + int error = security_ops->file_fcntl(file, cmd, arg);
865 + if (!error)
866 + error = ccs_fcntl_permission(file, cmd, arg);
867 + return error;
868 }
869
870 int security_file_set_fowner(struct file *file)
871 @@ -766,6 +832,8 @@ int security_file_open(struct file *file
872 int ret;
873
874 ret = security_ops->file_open(file, cred);
875 + if (!ret)
876 + ret = ccs_open_permission(file);
877 if (ret)
878 return ret;
879
880 @@ -1099,7 +1167,10 @@ EXPORT_SYMBOL(security_unix_may_send);
881
882 int security_socket_create(int family, int type, int protocol, int kern)
883 {
884 - return security_ops->socket_create(family, type, protocol, kern);
885 + int error = security_ops->socket_create(family, type, protocol, kern);
886 + if (!error)
887 + error = ccs_socket_create_permission(family, type, protocol);
888 + return error;
889 }
890
891 int security_socket_post_create(struct socket *sock, int family,
892 @@ -1111,17 +1182,26 @@ int security_socket_post_create(struct s
893
894 int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
895 {
896 - return security_ops->socket_bind(sock, address, addrlen);
897 + int error = security_ops->socket_bind(sock, address, addrlen);
898 + if (!error)
899 + error = ccs_socket_bind_permission(sock, address, addrlen);
900 + return error;
901 }
902
903 int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
904 {
905 - return security_ops->socket_connect(sock, address, addrlen);
906 + int error = security_ops->socket_connect(sock, address, addrlen);
907 + if (!error)
908 + error = ccs_socket_connect_permission(sock, address, addrlen);
909 + return error;
910 }
911
912 int security_socket_listen(struct socket *sock, int backlog)
913 {
914 - return security_ops->socket_listen(sock, backlog);
915 + int error = security_ops->socket_listen(sock, backlog);
916 + if (!error)
917 + error = ccs_socket_listen_permission(sock);
918 + return error;
919 }
920
921 int security_socket_accept(struct socket *sock, struct socket *newsock)
922 @@ -1131,7 +1211,10 @@ int security_socket_accept(struct socket
923
924 int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
925 {
926 - return security_ops->socket_sendmsg(sock, msg, size);
927 + int error = security_ops->socket_sendmsg(sock, msg, size);
928 + if (!error)
929 + error = ccs_socket_sendmsg_permission(sock, msg, size);
930 + return error;
931 }
932
933 int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,

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