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

Subversion リポジトリの参照

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6375 - (show annotations) (download) (as text)
Mon Jan 26 12:32:17 2015 UTC (9 years, 3 months ago) by kumaneko
File MIME type: text/x-diff
File size: 28145 byte(s)


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

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