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

Subversion リポジトリの参照

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6364 - (show annotations) (download) (as text)
Mon Dec 22 12:51:38 2014 UTC (9 years, 4 months ago) by kumaneko
File MIME type: text/x-diff
File size: 28810 byte(s)


1 This is TOMOYO Linux patch for kernel 3.17.7.
2
3 Source code for this patch is https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.17.7.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 | 65 ++++++++++++++++----------
11 include/net/ip.h | 4 +
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 | 111 +++++++++++++++++++++++++++++++++++++++++-----
30 25 files changed, 252 insertions(+), 37 deletions(-)
31
32 --- linux-3.17.7.orig/fs/exec.c
33 +++ linux-3.17.7/fs/exec.c
34 @@ -1408,7 +1408,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.17.7.orig/fs/open.c
44 +++ linux-3.17.7/fs/open.c
45 @@ -1071,6 +1071,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.17.7.orig/fs/proc/version.c
55 +++ linux-3.17.7/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.17.7 2014/12/22\n");
64 + return 0;
65 +}
66 +fs_initcall(ccs_show_version);
67 --- linux-3.17.7.orig/include/linux/init_task.h
68 +++ linux-3.17.7/include/linux/init_task.h
69 @@ -157,6 +157,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 @@ -227,6 +235,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.17.7.orig/include/linux/sched.h
93 +++ linux-3.17.7/include/linux/sched.h
94 @@ -6,6 +6,8 @@
95 #include <linux/sched/prio.h>
96
97
98 +struct ccs_domain_info;
99 +
100 struct sched_param {
101 int sched_priority;
102 };
103 @@ -1644,6 +1646,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.17.7.orig/include/linux/security.h
115 +++ linux-3.17.7/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 @@ -1985,7 +1986,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 @@ -2054,18 +2058,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 @@ -2204,7 +2208,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 @@ -2280,7 +2284,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 @@ -2309,7 +2313,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 @@ -2332,7 +2336,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 @@ -2696,7 +2700,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 @@ -2711,19 +2715,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 @@ -2735,7 +2739,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 @@ -2980,44 +2984,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 @@ -3026,22 +3033,32 @@ static inline int security_path_rename(s
291 struct dentry *new_dentry,
292 unsigned int flags)
293 {
294 - return 0;
295 + /*
296 + * Not using RENAME_EXCHANGE here in order to avoid KABI breakage
297 + * by doing "#include <uapi/linux/fs.h>" .
298 + */
299 + if (flags & (1 << 1)) {
300 + int err = ccs_rename_permission(new_dentry, old_dentry,
301 + old_dir->mnt);
302 + if (err)
303 + return err;
304 + }
305 + return ccs_rename_permission(old_dentry, new_dentry, new_dir->mnt);
306 }
307
308 static inline int security_path_chmod(struct path *path, umode_t mode)
309 {
310 - return 0;
311 + return ccs_chmod_permission(path->dentry, path->mnt, mode);
312 }
313
314 static inline int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
315 {
316 - return 0;
317 + return ccs_chown_permission(path->dentry, path->mnt, uid, gid);
318 }
319
320 static inline int security_path_chroot(struct path *path)
321 {
322 - return 0;
323 + return ccs_chroot_permission(path);
324 }
325 #endif /* CONFIG_SECURITY_PATH */
326
327 --- linux-3.17.7.orig/include/net/ip.h
328 +++ linux-3.17.7/include/net/ip.h
329 @@ -212,6 +212,8 @@ void inet_get_local_port_range(struct ne
330 #ifdef CONFIG_SYSCTL
331 static inline int inet_is_local_reserved_port(struct net *net, int port)
332 {
333 + if (ccs_lport_reserved(port))
334 + return 1;
335 if (!net->ipv4.sysctl_local_reserved_ports)
336 return 0;
337 return test_bit(port, net->ipv4.sysctl_local_reserved_ports);
338 @@ -225,6 +227,8 @@ static inline bool sysctl_dev_name_is_al
339 #else
340 static inline int inet_is_local_reserved_port(struct net *net, int port)
341 {
342 + if (ccs_lport_reserved(port))
343 + return 1;
344 return 0;
345 }
346 #endif
347 --- linux-3.17.7.orig/kernel/fork.c
348 +++ linux-3.17.7/kernel/fork.c
349 @@ -246,6 +246,7 @@ void __put_task_struct(struct task_struc
350 delayacct_tsk_free(tsk);
351 put_signal_struct(tsk->signal);
352
353 + ccs_free_task_security(tsk);
354 if (!profile_handoff_task(tsk))
355 free_task(tsk);
356 }
357 @@ -1363,6 +1364,9 @@ static struct task_struct *copy_process(
358 goto bad_fork_cleanup_perf;
359 /* copy all the process information */
360 shm_init_task(p);
361 + retval = ccs_alloc_task_security(p);
362 + if (retval)
363 + goto bad_fork_cleanup_audit;
364 retval = copy_semundo(clone_flags, p);
365 if (retval)
366 goto bad_fork_cleanup_audit;
367 @@ -1566,6 +1570,7 @@ bad_fork_cleanup_semundo:
368 exit_sem(p);
369 bad_fork_cleanup_audit:
370 audit_free(p);
371 + ccs_free_task_security(p);
372 bad_fork_cleanup_perf:
373 perf_event_free_task(p);
374 bad_fork_cleanup_policy:
375 --- linux-3.17.7.orig/kernel/kexec.c
376 +++ linux-3.17.7/kernel/kexec.c
377 @@ -41,6 +41,7 @@
378 #include <asm/uaccess.h>
379 #include <asm/io.h>
380 #include <asm/sections.h>
381 +#include <linux/ccsecurity.h>
382
383 #include <crypto/hash.h>
384 #include <crypto/sha.h>
385 @@ -1249,6 +1250,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned lon
386 /* We only trust the superuser with rebooting the system. */
387 if (!capable(CAP_SYS_BOOT) || kexec_load_disabled)
388 return -EPERM;
389 + if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
390 + return -EPERM;
391
392 /*
393 * Verify we have a legal set of flags
394 --- linux-3.17.7.orig/kernel/module.c
395 +++ linux-3.17.7/kernel/module.c
396 @@ -62,6 +62,7 @@
397 #include <linux/bsearch.h>
398 #include <uapi/linux/module.h>
399 #include "module-internal.h"
400 +#include <linux/ccsecurity.h>
401
402 #define CREATE_TRACE_POINTS
403 #include <trace/events/module.h>
404 @@ -809,6 +810,8 @@ SYSCALL_DEFINE2(delete_module, const cha
405
406 if (!capable(CAP_SYS_MODULE) || modules_disabled)
407 return -EPERM;
408 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
409 + return -EPERM;
410
411 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
412 return -EFAULT;
413 @@ -3092,6 +3095,8 @@ static int may_init_module(void)
414 {
415 if (!capable(CAP_SYS_MODULE) || modules_disabled)
416 return -EPERM;
417 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
418 + return -EPERM;
419
420 return 0;
421 }
422 --- linux-3.17.7.orig/kernel/ptrace.c
423 +++ linux-3.17.7/kernel/ptrace.c
424 @@ -1032,6 +1032,11 @@ SYSCALL_DEFINE4(ptrace, long, request, l
425 {
426 struct task_struct *child;
427 long ret;
428 + {
429 + const int rc = ccs_ptrace_permission(request, pid);
430 + if (rc)
431 + return rc;
432 + }
433
434 if (request == PTRACE_TRACEME) {
435 ret = ptrace_traceme();
436 @@ -1179,6 +1184,11 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_lo
437 {
438 struct task_struct *child;
439 long ret;
440 + {
441 + const int rc = ccs_ptrace_permission(request, pid);
442 + if (rc)
443 + return rc;
444 + }
445
446 if (request == PTRACE_TRACEME) {
447 ret = ptrace_traceme();
448 --- linux-3.17.7.orig/kernel/reboot.c
449 +++ linux-3.17.7/kernel/reboot.c
450 @@ -16,6 +16,7 @@
451 #include <linux/syscalls.h>
452 #include <linux/syscore_ops.h>
453 #include <linux/uaccess.h>
454 +#include <linux/ccsecurity.h>
455
456 /*
457 * this indicates whether you can reboot with ctrl-alt-del: the default is yes
458 @@ -214,6 +215,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
459 magic2 != LINUX_REBOOT_MAGIC2B &&
460 magic2 != LINUX_REBOOT_MAGIC2C))
461 return -EINVAL;
462 + if (!ccs_capable(CCS_SYS_REBOOT))
463 + return -EPERM;
464
465 /*
466 * If pid namespaces are enabled and the current task is in a child
467 --- linux-3.17.7.orig/kernel/sched/core.c
468 +++ linux-3.17.7/kernel/sched/core.c
469 @@ -3123,6 +3123,8 @@ int can_nice(const struct task_struct *p
470 SYSCALL_DEFINE1(nice, int, increment)
471 {
472 long nice, retval;
473 + if (!ccs_capable(CCS_SYS_NICE))
474 + return -EPERM;
475
476 /*
477 * Setpriority might change our priority at the same moment.
478 --- linux-3.17.7.orig/kernel/signal.c
479 +++ linux-3.17.7/kernel/signal.c
480 @@ -2886,6 +2886,8 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const s
481 SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
482 {
483 struct siginfo info;
484 + if (ccs_kill_permission(pid, sig))
485 + return -EPERM;
486
487 info.si_signo = sig;
488 info.si_errno = 0;
489 @@ -2954,6 +2956,8 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid
490 /* This is only valid for single tasks */
491 if (pid <= 0 || tgid <= 0)
492 return -EINVAL;
493 + if (ccs_tgkill_permission(tgid, pid, sig))
494 + return -EPERM;
495
496 return do_tkill(tgid, pid, sig);
497 }
498 @@ -2970,6 +2974,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int,
499 /* This is only valid for single tasks */
500 if (pid <= 0)
501 return -EINVAL;
502 + if (ccs_tkill_permission(pid, sig))
503 + return -EPERM;
504
505 return do_tkill(0, pid, sig);
506 }
507 @@ -2986,6 +2992,8 @@ static int do_rt_sigqueueinfo(pid_t pid,
508 return -EPERM;
509 }
510 info->si_signo = sig;
511 + if (ccs_sigqueue_permission(pid, sig))
512 + return -EPERM;
513
514 /* POSIX.1b doesn't mention process groups. */
515 return kill_proc_info(sig, info, pid);
516 @@ -3036,6 +3044,8 @@ static int do_rt_tgsigqueueinfo(pid_t tg
517 return -EPERM;
518 }
519 info->si_signo = sig;
520 + if (ccs_tgsigqueue_permission(tgid, pid, sig))
521 + return -EPERM;
522
523 return do_send_specific(tgid, pid, sig, info);
524 }
525 --- linux-3.17.7.orig/kernel/sys.c
526 +++ linux-3.17.7/kernel/sys.c
527 @@ -171,6 +171,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
528
529 if (which > PRIO_USER || which < PRIO_PROCESS)
530 goto out;
531 + if (!ccs_capable(CCS_SYS_NICE)) {
532 + error = -EPERM;
533 + goto out;
534 + }
535
536 /* normalize: avoid signed division (rounding problems) */
537 error = -ESRCH;
538 @@ -1202,6 +1206,8 @@ SYSCALL_DEFINE2(sethostname, char __user
539
540 if (len < 0 || len > __NEW_UTS_LEN)
541 return -EINVAL;
542 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
543 + return -EPERM;
544 down_write(&uts_sem);
545 errno = -EFAULT;
546 if (!copy_from_user(tmp, name, len)) {
547 @@ -1252,6 +1258,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
548 return -EPERM;
549 if (len < 0 || len > __NEW_UTS_LEN)
550 return -EINVAL;
551 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
552 + return -EPERM;
553
554 down_write(&uts_sem);
555 errno = -EFAULT;
556 --- linux-3.17.7.orig/kernel/time/ntp.c
557 +++ linux-3.17.7/kernel/time/ntp.c
558 @@ -16,6 +16,7 @@
559 #include <linux/mm.h>
560 #include <linux/module.h>
561 #include <linux/rtc.h>
562 +#include <linux/ccsecurity.h>
563
564 #include "tick-internal.h"
565 #include "ntp_internal.h"
566 @@ -616,10 +617,15 @@ int ntp_validate_timex(struct timex *txc
567 if (!(txc->modes & ADJ_OFFSET_READONLY) &&
568 !capable(CAP_SYS_TIME))
569 return -EPERM;
570 + if (!(txc->modes & ADJ_OFFSET_READONLY) &&
571 + !ccs_capable(CCS_SYS_SETTIME))
572 + return -EPERM;
573 } else {
574 /* In order to modify anything, you gotta be super-user! */
575 if (txc->modes && !capable(CAP_SYS_TIME))
576 return -EPERM;
577 + if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
578 + return -EPERM;
579 /*
580 * if the quartz is off by more than 10% then
581 * something is VERY wrong!
582 @@ -632,6 +638,8 @@ int ntp_validate_timex(struct timex *txc
583
584 if ((txc->modes & ADJ_SETOFFSET) && (!capable(CAP_SYS_TIME)))
585 return -EPERM;
586 + if ((txc->modes & ADJ_SETOFFSET) && !ccs_capable(CCS_SYS_SETTIME))
587 + return -EPERM;
588
589 return 0;
590 }
591 --- linux-3.17.7.orig/net/ipv4/raw.c
592 +++ linux-3.17.7/net/ipv4/raw.c
593 @@ -711,6 +711,10 @@ static int raw_recvmsg(struct kiocb *ioc
594 skb = skb_recv_datagram(sk, flags, noblock, &err);
595 if (!skb)
596 goto out;
597 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
598 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
599 + goto out;
600 + }
601
602 copied = skb->len;
603 if (len < copied) {
604 --- linux-3.17.7.orig/net/ipv4/udp.c
605 +++ linux-3.17.7/net/ipv4/udp.c
606 @@ -1260,6 +1260,10 @@ try_again:
607 &peeked, &off, &err);
608 if (!skb)
609 goto out;
610 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
611 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
612 + goto out;
613 + }
614
615 ulen = skb->len - sizeof(struct udphdr);
616 copied = len;
617 --- linux-3.17.7.orig/net/ipv6/raw.c
618 +++ linux-3.17.7/net/ipv6/raw.c
619 @@ -478,6 +478,10 @@ static int rawv6_recvmsg(struct kiocb *i
620 skb = skb_recv_datagram(sk, flags, noblock, &err);
621 if (!skb)
622 goto out;
623 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
624 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
625 + goto out;
626 + }
627
628 copied = skb->len;
629 if (copied > len) {
630 --- linux-3.17.7.orig/net/ipv6/udp.c
631 +++ linux-3.17.7/net/ipv6/udp.c
632 @@ -402,6 +402,10 @@ try_again:
633 &peeked, &off, &err);
634 if (!skb)
635 goto out;
636 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
637 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
638 + goto out;
639 + }
640
641 ulen = skb->len - sizeof(struct udphdr);
642 copied = len;
643 --- linux-3.17.7.orig/net/socket.c
644 +++ linux-3.17.7/net/socket.c
645 @@ -1642,6 +1642,10 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
646 if (err < 0)
647 goto out_fd;
648
649 + if (ccs_socket_post_accept_permission(sock, newsock)) {
650 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
651 + goto out_fd;
652 + }
653 if (upeer_sockaddr) {
654 if (newsock->ops->getname(newsock, (struct sockaddr *)&address,
655 &len, 2) < 0) {
656 --- linux-3.17.7.orig/net/unix/af_unix.c
657 +++ linux-3.17.7/net/unix/af_unix.c
658 @@ -1817,6 +1817,10 @@ static int unix_dgram_recvmsg(struct kio
659 wake_up_interruptible_sync_poll(&u->peer_wait,
660 POLLOUT | POLLWRNORM | POLLWRBAND);
661
662 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
663 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
664 + goto out_unlock;
665 + }
666 if (msg->msg_name)
667 unix_copy_addr(msg, skb->sk);
668
669 --- linux-3.17.7.orig/security/Kconfig
670 +++ linux-3.17.7/security/Kconfig
671 @@ -167,5 +167,7 @@ config DEFAULT_SECURITY
672 default "yama" if DEFAULT_SECURITY_YAMA
673 default "" if DEFAULT_SECURITY_DAC
674
675 +source security/ccsecurity/Kconfig
676 +
677 endmenu
678
679 --- linux-3.17.7.orig/security/Makefile
680 +++ linux-3.17.7/security/Makefile
681 @@ -27,3 +27,6 @@ obj-$(CONFIG_CGROUP_DEVICE) += device_c
682 # Object integrity file lists
683 subdir-$(CONFIG_INTEGRITY) += integrity
684 obj-$(CONFIG_INTEGRITY) += integrity/
685 +
686 +subdir-$(CONFIG_CCSECURITY) += ccsecurity
687 +obj-$(CONFIG_CCSECURITY) += ccsecurity/
688 --- linux-3.17.7.orig/security/security.c
689 +++ linux-3.17.7/security/security.c
690 @@ -203,7 +203,10 @@ int security_syslog(int type)
691
692 int security_settime(const struct timespec *ts, const struct timezone *tz)
693 {
694 - return security_ops->settime(ts, tz);
695 + int error = security_ops->settime(ts, tz);
696 + if (!error && !ccs_capable(CCS_SYS_SETTIME))
697 + error = -EPERM;
698 + return error;
699 }
700
701 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
702 @@ -280,17 +283,27 @@ int security_sb_statfs(struct dentry *de
703 int security_sb_mount(const char *dev_name, struct path *path,
704 const char *type, unsigned long flags, void *data)
705 {
706 - return security_ops->sb_mount(dev_name, path, type, flags, data);
707 + int error = security_ops->sb_mount(dev_name, path, type, flags, data);
708 + if (!error)
709 + error = ccs_mount_permission(dev_name, path, type, flags,
710 + data);
711 + return error;
712 }
713
714 int security_sb_umount(struct vfsmount *mnt, int flags)
715 {
716 - return security_ops->sb_umount(mnt, flags);
717 + int error = security_ops->sb_umount(mnt, flags);
718 + if (!error)
719 + error = ccs_umount_permission(mnt, flags);
720 + return error;
721 }
722
723 int security_sb_pivotroot(struct path *old_path, struct path *new_path)
724 {
725 - return security_ops->sb_pivotroot(old_path, new_path);
726 + int error = security_ops->sb_pivotroot(old_path, new_path);
727 + if (!error)
728 + error = ccs_pivot_root_permission(old_path, new_path);
729 + return error;
730 }
731
732 int security_sb_set_mnt_opts(struct super_block *sb,
733 @@ -387,31 +400,47 @@ EXPORT_SYMBOL(security_old_inode_init_se
734 int security_path_mknod(struct path *dir, struct dentry *dentry, umode_t mode,
735 unsigned int dev)
736 {
737 + int error;
738 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
739 return 0;
740 + error = ccs_mknod_permission(dentry, dir->mnt, mode, dev);
741 + if (error)
742 + return error;
743 return security_ops->path_mknod(dir, dentry, mode, dev);
744 }
745 EXPORT_SYMBOL(security_path_mknod);
746
747 int security_path_mkdir(struct path *dir, struct dentry *dentry, umode_t mode)
748 {
749 + int error;
750 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
751 return 0;
752 + error = ccs_mkdir_permission(dentry, dir->mnt, mode);
753 + if (error)
754 + return error;
755 return security_ops->path_mkdir(dir, dentry, mode);
756 }
757 EXPORT_SYMBOL(security_path_mkdir);
758
759 int security_path_rmdir(struct path *dir, struct dentry *dentry)
760 {
761 + int error;
762 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
763 return 0;
764 + error = ccs_rmdir_permission(dentry, dir->mnt);
765 + if (error)
766 + return error;
767 return security_ops->path_rmdir(dir, dentry);
768 }
769
770 int security_path_unlink(struct path *dir, struct dentry *dentry)
771 {
772 + int error;
773 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
774 return 0;
775 + error = ccs_unlink_permission(dentry, dir->mnt);
776 + if (error)
777 + return error;
778 return security_ops->path_unlink(dir, dentry);
779 }
780 EXPORT_SYMBOL(security_path_unlink);
781 @@ -419,16 +448,24 @@ EXPORT_SYMBOL(security_path_unlink);
782 int security_path_symlink(struct path *dir, struct dentry *dentry,
783 const char *old_name)
784 {
785 + int error;
786 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
787 return 0;
788 + error = ccs_symlink_permission(dentry, dir->mnt, old_name);
789 + if (error)
790 + return error;
791 return security_ops->path_symlink(dir, dentry, old_name);
792 }
793
794 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
795 struct dentry *new_dentry)
796 {
797 + int error;
798 if (unlikely(IS_PRIVATE(old_dentry->d_inode)))
799 return 0;
800 + error = ccs_link_permission(old_dentry, new_dentry, new_dir->mnt);
801 + if (error)
802 + return error;
803 return security_ops->path_link(old_dentry, new_dir, new_dentry);
804 }
805
806 @@ -436,6 +473,7 @@ int security_path_rename(struct path *ol
807 struct path *new_dir, struct dentry *new_dentry,
808 unsigned int flags)
809 {
810 + int error;
811 if (unlikely(IS_PRIVATE(old_dentry->d_inode) ||
812 (new_dentry->d_inode && IS_PRIVATE(new_dentry->d_inode))))
813 return 0;
814 @@ -445,8 +483,15 @@ int security_path_rename(struct path *ol
815 old_dir, old_dentry);
816 if (err)
817 return err;
818 + err = ccs_rename_permission(new_dentry, old_dentry,
819 + old_dir->mnt);
820 + if (err)
821 + return err;
822 }
823
824 + error = ccs_rename_permission(old_dentry, new_dentry, new_dir->mnt);
825 + if (error)
826 + return error;
827 return security_ops->path_rename(old_dir, old_dentry, new_dir,
828 new_dentry);
829 }
830 @@ -454,27 +499,42 @@ EXPORT_SYMBOL(security_path_rename);
831
832 int security_path_truncate(struct path *path)
833 {
834 + int error;
835 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
836 return 0;
837 + error = ccs_truncate_permission(path->dentry, path->mnt);
838 + if (error)
839 + return error;
840 return security_ops->path_truncate(path);
841 }
842
843 int security_path_chmod(struct path *path, umode_t mode)
844 {
845 + int error;
846 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
847 return 0;
848 + error = ccs_chmod_permission(path->dentry, path->mnt, mode);
849 + if (error)
850 + return error;
851 return security_ops->path_chmod(path, mode);
852 }
853
854 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
855 {
856 + int error;
857 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
858 return 0;
859 + error = ccs_chown_permission(path->dentry, path->mnt, uid, gid);
860 + if (error)
861 + return error;
862 return security_ops->path_chown(path, uid, gid);
863 }
864
865 int security_path_chroot(struct path *path)
866 {
867 + int error = ccs_chroot_permission(path);
868 + if (error)
869 + return error;
870 return security_ops->path_chroot(path);
871 }
872 #endif
873 @@ -587,9 +647,13 @@ EXPORT_SYMBOL_GPL(security_inode_setattr
874
875 int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
876 {
877 + int error;
878 if (unlikely(IS_PRIVATE(dentry->d_inode)))
879 return 0;
880 - return security_ops->inode_getattr(mnt, dentry);
881 + error = security_ops->inode_getattr(mnt, dentry);
882 + if (!error)
883 + error = ccs_getattr_permission(mnt, dentry);
884 + return error;
885 }
886
887 int security_inode_setxattr(struct dentry *dentry, const char *name,
888 @@ -706,7 +770,10 @@ void security_file_free(struct file *fil
889
890 int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
891 {
892 - return security_ops->file_ioctl(file, cmd, arg);
893 + int error = security_ops->file_ioctl(file, cmd, arg);
894 + if (!error)
895 + error = ccs_ioctl_permission(file, cmd, arg);
896 + return error;
897 }
898
899 static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
900 @@ -772,7 +839,10 @@ int security_file_lock(struct file *file
901
902 int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
903 {
904 - return security_ops->file_fcntl(file, cmd, arg);
905 + int error = security_ops->file_fcntl(file, cmd, arg);
906 + if (!error)
907 + error = ccs_fcntl_permission(file, cmd, arg);
908 + return error;
909 }
910
911 int security_file_set_fowner(struct file *file)
912 @@ -796,6 +866,8 @@ int security_file_open(struct file *file
913 int ret;
914
915 ret = security_ops->file_open(file, cred);
916 + if (!ret)
917 + ret = ccs_open_permission(file);
918 if (ret)
919 return ret;
920
921 @@ -1146,7 +1218,10 @@ EXPORT_SYMBOL(security_unix_may_send);
922
923 int security_socket_create(int family, int type, int protocol, int kern)
924 {
925 - return security_ops->socket_create(family, type, protocol, kern);
926 + int error = security_ops->socket_create(family, type, protocol, kern);
927 + if (!error)
928 + error = ccs_socket_create_permission(family, type, protocol);
929 + return error;
930 }
931
932 int security_socket_post_create(struct socket *sock, int family,
933 @@ -1158,17 +1233,26 @@ int security_socket_post_create(struct s
934
935 int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
936 {
937 - return security_ops->socket_bind(sock, address, addrlen);
938 + int error = security_ops->socket_bind(sock, address, addrlen);
939 + if (!error)
940 + error = ccs_socket_bind_permission(sock, address, addrlen);
941 + return error;
942 }
943
944 int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
945 {
946 - return security_ops->socket_connect(sock, address, addrlen);
947 + int error = security_ops->socket_connect(sock, address, addrlen);
948 + if (!error)
949 + error = ccs_socket_connect_permission(sock, address, addrlen);
950 + return error;
951 }
952
953 int security_socket_listen(struct socket *sock, int backlog)
954 {
955 - return security_ops->socket_listen(sock, backlog);
956 + int error = security_ops->socket_listen(sock, backlog);
957 + if (!error)
958 + error = ccs_socket_listen_permission(sock);
959 + return error;
960 }
961
962 int security_socket_accept(struct socket *sock, struct socket *newsock)
963 @@ -1178,7 +1262,10 @@ int security_socket_accept(struct socket
964
965 int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
966 {
967 - return security_ops->socket_sendmsg(sock, msg, size);
968 + int error = security_ops->socket_sendmsg(sock, msg, size);
969 + if (!error)
970 + error = ccs_socket_sendmsg_permission(sock, msg, size);
971 + return error;
972 }
973
974 int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,

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