Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/caitsith-patch/patches/ccs-patch-3.10-centos-7.diff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 137 - (show annotations) (download) (as text)
Mon Jan 12 13:02:37 2015 UTC (9 years, 3 months ago) by kumaneko
File MIME type: text/x-diff
File size: 28077 byte(s)


1 This is TOMOYO Linux patch for CentOS 7.
2
3 Source code for this patch is http://vault.centos.org/centos/7/updates/Source/SPackages/kernel-3.10.0-123.13.2.el7.src.rpm
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 | 2
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, 234 insertions(+), 37 deletions(-)
30
31 --- linux-3.10.0-123.13.2.el7.orig/fs/exec.c
32 +++ linux-3.10.0-123.13.2.el7/fs/exec.c
33 @@ -1536,7 +1536,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.0-123.13.2.el7.orig/fs/open.c
43 +++ linux-3.10.0-123.13.2.el7/fs/open.c
44 @@ -1064,6 +1064,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.0-123.13.2.el7.orig/fs/proc/version.c
54 +++ linux-3.10.0-123.13.2.el7/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.0-123.13.2.el7 2015/01/04\n");
63 + return 0;
64 +}
65 +module_init(ccs_show_version);
66 --- linux-3.10.0-123.13.2.el7.orig/include/linux/init_task.h
67 +++ linux-3.10.0-123.13.2.el7/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.0-123.13.2.el7.orig/include/linux/sched.h
92 +++ linux-3.10.0-123.13.2.el7/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 @@ -1502,6 +1504,10 @@ struct task_struct {
103 unsigned long rh_reserved6;
104 unsigned long rh_reserved7;
105 unsigned long rh_reserved8;
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.0-123.13.2.el7.orig/include/linux/security.h
114 +++ linux-3.10.0-123.13.2.el7/include/linux/security.h
115 @@ -53,6 +53,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 @@ -1961,7 +1962,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 @@ -2030,18 +2034,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 @@ -2179,7 +2183,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 @@ -2255,7 +2259,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 @@ -2284,7 +2288,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 @@ -2307,7 +2311,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 @@ -2665,7 +2669,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 @@ -2680,19 +2684,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 @@ -2704,7 +2708,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 @@ -2945,44 +2949,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 @@ -2990,22 +2997,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.0-123.13.2.el7.orig/include/net/ip.h
317 +++ linux-3.10.0-123.13.2.el7/include/net/ip.h
318 @@ -229,6 +229,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.0-123.13.2.el7.orig/kernel/fork.c
328 +++ linux-3.10.0-123.13.2.el7/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 @@ -1328,6 +1329,9 @@ static struct task_struct *copy_process(
338 retval = audit_alloc(p);
339 if (retval)
340 goto bad_fork_cleanup_policy;
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 @@ -1526,6 +1530,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_policy:
353 perf_event_free_task(p);
354 #ifdef CONFIG_NUMA
355 --- linux-3.10.0-123.13.2.el7.orig/kernel/kexec.c
356 +++ linux-3.10.0-123.13.2.el7/kernel/kexec.c
357 @@ -943,6 +943,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned lon
358 /* We only trust the superuser with rebooting the system. */
359 if (!capable(CAP_SYS_BOOT))
360 return -EPERM;
361 + if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
362 + return -EPERM;
363
364 if (get_securelevel() > 0)
365 return -EPERM;
366 --- linux-3.10.0-123.13.2.el7.orig/kernel/module.c
367 +++ linux-3.10.0-123.13.2.el7/kernel/module.c
368 @@ -63,6 +63,7 @@
369 #include <linux/fips.h>
370 #include <uapi/linux/module.h>
371 #include "module-internal.h"
372 +#include <linux/ccsecurity.h>
373
374 #define CREATE_TRACE_POINTS
375 #include <trace/events/module.h>
376 @@ -829,6 +830,8 @@ SYSCALL_DEFINE2(delete_module, const cha
377
378 if (!capable(CAP_SYS_MODULE) || modules_disabled)
379 return -EPERM;
380 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
381 + return -EPERM;
382
383 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
384 return -EFAULT;
385 @@ -3145,6 +3148,8 @@ static int may_init_module(void)
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 return 0;
393 }
394 --- linux-3.10.0-123.13.2.el7.orig/kernel/ptrace.c
395 +++ linux-3.10.0-123.13.2.el7/kernel/ptrace.c
396 @@ -998,6 +998,11 @@ SYSCALL_DEFINE4(ptrace, long, request, l
397 {
398 struct task_struct *child;
399 long ret;
400 + {
401 + const int rc = ccs_ptrace_permission(request, pid);
402 + if (rc)
403 + return rc;
404 + }
405
406 if (request == PTRACE_TRACEME) {
407 ret = ptrace_traceme();
408 @@ -1145,6 +1150,11 @@ asmlinkage long compat_sys_ptrace(compat
409 {
410 struct task_struct *child;
411 long ret;
412 + {
413 + const int rc = ccs_ptrace_permission(request, pid);
414 + if (rc)
415 + return rc;
416 + }
417
418 if (request == PTRACE_TRACEME) {
419 ret = ptrace_traceme();
420 --- linux-3.10.0-123.13.2.el7.orig/kernel/sched/core.c
421 +++ linux-3.10.0-123.13.2.el7/kernel/sched/core.c
422 @@ -3886,6 +3886,8 @@ int can_nice(const struct task_struct *p
423 SYSCALL_DEFINE1(nice, int, increment)
424 {
425 long nice, retval;
426 + if (!ccs_capable(CCS_SYS_NICE))
427 + return -EPERM;
428
429 /*
430 * Setpriority might change our priority at the same moment.
431 --- linux-3.10.0-123.13.2.el7.orig/kernel/signal.c
432 +++ linux-3.10.0-123.13.2.el7/kernel/signal.c
433 @@ -2909,6 +2909,8 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const s
434 SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
435 {
436 struct siginfo info;
437 + if (ccs_kill_permission(pid, sig))
438 + return -EPERM;
439
440 info.si_signo = sig;
441 info.si_errno = 0;
442 @@ -2977,6 +2979,8 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid
443 /* This is only valid for single tasks */
444 if (pid <= 0 || tgid <= 0)
445 return -EINVAL;
446 + if (ccs_tgkill_permission(tgid, pid, sig))
447 + return -EPERM;
448
449 return do_tkill(tgid, pid, sig);
450 }
451 @@ -2993,6 +2997,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int,
452 /* This is only valid for single tasks */
453 if (pid <= 0)
454 return -EINVAL;
455 + if (ccs_tkill_permission(pid, sig))
456 + return -EPERM;
457
458 return do_tkill(0, pid, sig);
459 }
460 @@ -3009,6 +3015,8 @@ static int do_rt_sigqueueinfo(pid_t pid,
461 return -EPERM;
462 }
463 info->si_signo = sig;
464 + if (ccs_sigqueue_permission(pid, sig))
465 + return -EPERM;
466
467 /* POSIX.1b doesn't mention process groups. */
468 return kill_proc_info(sig, info, pid);
469 @@ -3059,6 +3067,8 @@ static int do_rt_tgsigqueueinfo(pid_t tg
470 return -EPERM;
471 }
472 info->si_signo = sig;
473 + if (ccs_tgsigqueue_permission(tgid, pid, sig))
474 + return -EPERM;
475
476 return do_send_specific(tgid, pid, sig, info);
477 }
478 --- linux-3.10.0-123.13.2.el7.orig/kernel/sys.c
479 +++ linux-3.10.0-123.13.2.el7/kernel/sys.c
480 @@ -186,6 +186,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
481
482 if (which > PRIO_USER || which < PRIO_PROCESS)
483 goto out;
484 + if (!ccs_capable(CCS_SYS_NICE)) {
485 + error = -EPERM;
486 + goto out;
487 + }
488
489 /* normalize: avoid signed division (rounding problems) */
490 error = -ESRCH;
491 @@ -478,6 +482,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
492 magic2 != LINUX_REBOOT_MAGIC2B &&
493 magic2 != LINUX_REBOOT_MAGIC2C))
494 return -EINVAL;
495 + if (!ccs_capable(CCS_SYS_REBOOT))
496 + return -EPERM;
497
498 /*
499 * If pid namespaces are enabled and the current task is in a child
500 @@ -1467,6 +1473,8 @@ SYSCALL_DEFINE2(sethostname, char __user
501
502 if (len < 0 || len > __NEW_UTS_LEN)
503 return -EINVAL;
504 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
505 + return -EPERM;
506 down_write(&uts_sem);
507 errno = -EFAULT;
508 if (!copy_from_user(tmp, name, len)) {
509 @@ -1517,6 +1525,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
510 return -EPERM;
511 if (len < 0 || len > __NEW_UTS_LEN)
512 return -EINVAL;
513 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
514 + return -EPERM;
515
516 down_write(&uts_sem);
517 errno = -EFAULT;
518 --- linux-3.10.0-123.13.2.el7.orig/kernel/time/ntp.c
519 +++ linux-3.10.0-123.13.2.el7/kernel/time/ntp.c
520 @@ -16,6 +16,7 @@
521 #include <linux/mm.h>
522 #include <linux/module.h>
523 #include <linux/rtc.h>
524 +#include <linux/ccsecurity.h>
525
526 #include "tick-internal.h"
527 #include "ntp_internal.h"
528 @@ -614,10 +615,15 @@ int ntp_validate_timex(struct timex *txc
529 if (!(txc->modes & ADJ_OFFSET_READONLY) &&
530 !capable(CAP_SYS_TIME))
531 return -EPERM;
532 + if (!(txc->modes & ADJ_OFFSET_READONLY) &&
533 + !ccs_capable(CCS_SYS_SETTIME))
534 + return -EPERM;
535 } else {
536 /* In order to modify anything, you gotta be super-user! */
537 if (txc->modes && !capable(CAP_SYS_TIME))
538 return -EPERM;
539 + if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
540 + return -EPERM;
541 /*
542 * if the quartz is off by more than 10% then
543 * something is VERY wrong!
544 @@ -630,6 +636,8 @@ int ntp_validate_timex(struct timex *txc
545
546 if ((txc->modes & ADJ_SETOFFSET) && (!capable(CAP_SYS_TIME)))
547 return -EPERM;
548 + if ((txc->modes & ADJ_SETOFFSET) && !ccs_capable(CCS_SYS_SETTIME))
549 + return -EPERM;
550
551 return 0;
552 }
553 --- linux-3.10.0-123.13.2.el7.orig/net/ipv4/raw.c
554 +++ linux-3.10.0-123.13.2.el7/net/ipv4/raw.c
555 @@ -702,6 +702,10 @@ static int raw_recvmsg(struct kiocb *ioc
556 skb = skb_recv_datagram(sk, flags, noblock, &err);
557 if (!skb)
558 goto out;
559 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
560 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
561 + goto out;
562 + }
563
564 copied = skb->len;
565 if (len < copied) {
566 --- linux-3.10.0-123.13.2.el7.orig/net/ipv4/udp.c
567 +++ linux-3.10.0-123.13.2.el7/net/ipv4/udp.c
568 @@ -1221,6 +1221,10 @@ try_again:
569 &peeked, &off, &err);
570 if (!skb)
571 goto out;
572 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
573 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
574 + goto out;
575 + }
576
577 ulen = skb->len - sizeof(struct udphdr);
578 copied = len;
579 --- linux-3.10.0-123.13.2.el7.orig/net/ipv6/raw.c
580 +++ linux-3.10.0-123.13.2.el7/net/ipv6/raw.c
581 @@ -467,6 +467,10 @@ static int rawv6_recvmsg(struct kiocb *i
582 skb = skb_recv_datagram(sk, flags, noblock, &err);
583 if (!skb)
584 goto out;
585 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
586 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
587 + goto out;
588 + }
589
590 copied = skb->len;
591 if (copied > len) {
592 --- linux-3.10.0-123.13.2.el7.orig/net/ipv6/udp.c
593 +++ linux-3.10.0-123.13.2.el7/net/ipv6/udp.c
594 @@ -380,6 +380,10 @@ try_again:
595 &peeked, &off, &err);
596 if (!skb)
597 goto out;
598 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
599 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
600 + goto out;
601 + }
602
603 ulen = skb->len - sizeof(struct udphdr);
604 copied = len;
605 --- linux-3.10.0-123.13.2.el7.orig/net/socket.c
606 +++ linux-3.10.0-123.13.2.el7/net/socket.c
607 @@ -1628,6 +1628,10 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
608 if (err < 0)
609 goto out_fd;
610
611 + if (ccs_socket_post_accept_permission(sock, newsock)) {
612 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
613 + goto out_fd;
614 + }
615 if (upeer_sockaddr) {
616 if (newsock->ops->getname(newsock, (struct sockaddr *)&address,
617 &len, 2) < 0) {
618 --- linux-3.10.0-123.13.2.el7.orig/net/unix/af_unix.c
619 +++ linux-3.10.0-123.13.2.el7/net/unix/af_unix.c
620 @@ -1807,6 +1807,10 @@ static int unix_dgram_recvmsg(struct kio
621 wake_up_interruptible_sync_poll(&u->peer_wait,
622 POLLOUT | POLLWRNORM | POLLWRBAND);
623
624 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
625 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
626 + goto out_unlock;
627 + }
628 if (msg->msg_name)
629 unix_copy_addr(msg, skb->sk);
630
631 --- linux-3.10.0-123.13.2.el7.orig/security/Kconfig
632 +++ linux-3.10.0-123.13.2.el7/security/Kconfig
633 @@ -175,5 +175,7 @@ config DEFAULT_SECURITY
634 default "yama" if DEFAULT_SECURITY_YAMA
635 default "" if DEFAULT_SECURITY_DAC
636
637 +source security/ccsecurity/Kconfig
638 +
639 endmenu
640
641 --- linux-3.10.0-123.13.2.el7.orig/security/Makefile
642 +++ linux-3.10.0-123.13.2.el7/security/Makefile
643 @@ -29,3 +29,6 @@ obj-$(CONFIG_CGROUP_DEVICE) += device_c
644 # Object integrity file lists
645 subdir-$(CONFIG_INTEGRITY) += integrity
646 obj-$(CONFIG_INTEGRITY) += integrity/built-in.o
647 +
648 +subdir-$(CONFIG_CCSECURITY) += ccsecurity
649 +obj-$(CONFIG_CCSECURITY) += ccsecurity/built-in.o
650 --- linux-3.10.0-123.13.2.el7.orig/security/security.c
651 +++ linux-3.10.0-123.13.2.el7/security/security.c
652 @@ -203,7 +203,10 @@ int security_syslog(int type)
653
654 int security_settime(const struct timespec *ts, const struct timezone *tz)
655 {
656 - return security_ops->settime(ts, tz);
657 + int error = security_ops->settime(ts, tz);
658 + if (!error && !ccs_capable(CCS_SYS_SETTIME))
659 + error = -EPERM;
660 + return error;
661 }
662
663 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
664 @@ -280,17 +283,27 @@ int security_sb_statfs(struct dentry *de
665 int security_sb_mount(const char *dev_name, struct path *path,
666 const char *type, unsigned long flags, void *data)
667 {
668 - return security_ops->sb_mount(dev_name, path, type, flags, data);
669 + int error = security_ops->sb_mount(dev_name, path, type, flags, data);
670 + if (!error)
671 + error = ccs_mount_permission(dev_name, path, type, flags,
672 + data);
673 + return error;
674 }
675
676 int security_sb_umount(struct vfsmount *mnt, int flags)
677 {
678 - return security_ops->sb_umount(mnt, flags);
679 + int error = security_ops->sb_umount(mnt, flags);
680 + if (!error)
681 + error = ccs_umount_permission(mnt, flags);
682 + return error;
683 }
684
685 int security_sb_pivotroot(struct path *old_path, struct path *new_path)
686 {
687 - return security_ops->sb_pivotroot(old_path, new_path);
688 + int error = security_ops->sb_pivotroot(old_path, new_path);
689 + if (!error)
690 + error = ccs_pivot_root_permission(old_path, new_path);
691 + return error;
692 }
693
694 int security_sb_set_mnt_opts(struct super_block *sb,
695 @@ -389,31 +402,47 @@ EXPORT_SYMBOL(security_old_inode_init_se
696 int security_path_mknod(struct path *dir, struct dentry *dentry, umode_t mode,
697 unsigned int dev)
698 {
699 + int error;
700 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
701 return 0;
702 + error = ccs_mknod_permission(dentry, dir->mnt, mode, dev);
703 + if (error)
704 + return error;
705 return security_ops->path_mknod(dir, dentry, mode, dev);
706 }
707 EXPORT_SYMBOL(security_path_mknod);
708
709 int security_path_mkdir(struct path *dir, struct dentry *dentry, umode_t mode)
710 {
711 + int error;
712 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
713 return 0;
714 + error = ccs_mkdir_permission(dentry, dir->mnt, mode);
715 + if (error)
716 + return error;
717 return security_ops->path_mkdir(dir, dentry, mode);
718 }
719 EXPORT_SYMBOL(security_path_mkdir);
720
721 int security_path_rmdir(struct path *dir, struct dentry *dentry)
722 {
723 + int error;
724 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
725 return 0;
726 + error = ccs_rmdir_permission(dentry, dir->mnt);
727 + if (error)
728 + return error;
729 return security_ops->path_rmdir(dir, dentry);
730 }
731
732 int security_path_unlink(struct path *dir, struct dentry *dentry)
733 {
734 + int error;
735 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
736 return 0;
737 + error = ccs_unlink_permission(dentry, dir->mnt);
738 + if (error)
739 + return error;
740 return security_ops->path_unlink(dir, dentry);
741 }
742 EXPORT_SYMBOL(security_path_unlink);
743 @@ -421,25 +450,37 @@ EXPORT_SYMBOL(security_path_unlink);
744 int security_path_symlink(struct path *dir, struct dentry *dentry,
745 const char *old_name)
746 {
747 + int error;
748 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
749 return 0;
750 + error = ccs_symlink_permission(dentry, dir->mnt, old_name);
751 + if (error)
752 + return error;
753 return security_ops->path_symlink(dir, dentry, old_name);
754 }
755
756 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
757 struct dentry *new_dentry)
758 {
759 + int error;
760 if (unlikely(IS_PRIVATE(old_dentry->d_inode)))
761 return 0;
762 + error = ccs_link_permission(old_dentry, new_dentry, new_dir->mnt);
763 + if (error)
764 + return error;
765 return security_ops->path_link(old_dentry, new_dir, new_dentry);
766 }
767
768 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
769 struct path *new_dir, struct dentry *new_dentry)
770 {
771 + int error;
772 if (unlikely(IS_PRIVATE(old_dentry->d_inode) ||
773 (new_dentry->d_inode && IS_PRIVATE(new_dentry->d_inode))))
774 return 0;
775 + error = ccs_rename_permission(old_dentry, new_dentry, new_dir->mnt);
776 + if (error)
777 + return error;
778 return security_ops->path_rename(old_dir, old_dentry, new_dir,
779 new_dentry);
780 }
781 @@ -447,27 +488,42 @@ EXPORT_SYMBOL(security_path_rename);
782
783 int security_path_truncate(struct path *path)
784 {
785 + int error;
786 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
787 return 0;
788 + error = ccs_truncate_permission(path->dentry, path->mnt);
789 + if (error)
790 + return error;
791 return security_ops->path_truncate(path);
792 }
793
794 int security_path_chmod(struct path *path, umode_t mode)
795 {
796 + int error;
797 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
798 return 0;
799 + error = ccs_chmod_permission(path->dentry, path->mnt, mode);
800 + if (error)
801 + return error;
802 return security_ops->path_chmod(path, mode);
803 }
804
805 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
806 {
807 + int error;
808 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
809 return 0;
810 + error = ccs_chown_permission(path->dentry, path->mnt, uid, gid);
811 + if (error)
812 + return error;
813 return security_ops->path_chown(path, uid, gid);
814 }
815
816 int security_path_chroot(struct path *path)
817 {
818 + int error = ccs_chroot_permission(path);
819 + if (error)
820 + return error;
821 return security_ops->path_chroot(path);
822 }
823 #endif
824 @@ -571,9 +627,13 @@ EXPORT_SYMBOL_GPL(security_inode_setattr
825
826 int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
827 {
828 + int error;
829 if (unlikely(IS_PRIVATE(dentry->d_inode)))
830 return 0;
831 - return security_ops->inode_getattr(mnt, dentry);
832 + error = security_ops->inode_getattr(mnt, dentry);
833 + if (!error)
834 + error = ccs_getattr_permission(mnt, dentry);
835 + return error;
836 }
837
838 int security_inode_setxattr(struct dentry *dentry, const char *name,
839 @@ -690,7 +750,10 @@ void security_file_free(struct file *fil
840
841 int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
842 {
843 - return security_ops->file_ioctl(file, cmd, arg);
844 + int error = security_ops->file_ioctl(file, cmd, arg);
845 + if (!error)
846 + error = ccs_ioctl_permission(file, cmd, arg);
847 + return error;
848 }
849
850 static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
851 @@ -756,7 +819,10 @@ int security_file_lock(struct file *file
852
853 int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
854 {
855 - return security_ops->file_fcntl(file, cmd, arg);
856 + int error = security_ops->file_fcntl(file, cmd, arg);
857 + if (!error)
858 + error = ccs_fcntl_permission(file, cmd, arg);
859 + return error;
860 }
861
862 int security_file_set_fowner(struct file *file)
863 @@ -780,6 +846,8 @@ int security_file_open(struct file *file
864 int ret;
865
866 ret = security_ops->file_open(file, cred);
867 + if (!ret)
868 + ret = ccs_open_permission(file);
869 if (ret)
870 return ret;
871
872 @@ -1119,7 +1187,10 @@ EXPORT_SYMBOL(security_unix_may_send);
873
874 int security_socket_create(int family, int type, int protocol, int kern)
875 {
876 - return security_ops->socket_create(family, type, protocol, kern);
877 + int error = security_ops->socket_create(family, type, protocol, kern);
878 + if (!error)
879 + error = ccs_socket_create_permission(family, type, protocol);
880 + return error;
881 }
882
883 int security_socket_post_create(struct socket *sock, int family,
884 @@ -1131,17 +1202,26 @@ int security_socket_post_create(struct s
885
886 int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
887 {
888 - return security_ops->socket_bind(sock, address, addrlen);
889 + int error = security_ops->socket_bind(sock, address, addrlen);
890 + if (!error)
891 + error = ccs_socket_bind_permission(sock, address, addrlen);
892 + return error;
893 }
894
895 int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
896 {
897 - return security_ops->socket_connect(sock, address, addrlen);
898 + int error = security_ops->socket_connect(sock, address, addrlen);
899 + if (!error)
900 + error = ccs_socket_connect_permission(sock, address, addrlen);
901 + return error;
902 }
903
904 int security_socket_listen(struct socket *sock, int backlog)
905 {
906 - return security_ops->socket_listen(sock, backlog);
907 + int error = security_ops->socket_listen(sock, backlog);
908 + if (!error)
909 + error = ccs_socket_listen_permission(sock);
910 + return error;
911 }
912
913 int security_socket_accept(struct socket *sock, struct socket *newsock)
914 @@ -1151,7 +1231,10 @@ int security_socket_accept(struct socket
915
916 int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
917 {
918 - return security_ops->socket_sendmsg(sock, msg, size);
919 + int error = security_ops->socket_sendmsg(sock, msg, size);
920 + if (!error)
921 + error = ccs_socket_sendmsg_permission(sock, msg, size);
922 + return error;
923 }
924
925 int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,

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