Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 388 - (show annotations) (download) (as text)
Mon Mar 18 10:55:14 2024 UTC (3 weeks, 3 days ago) by kumaneko
File MIME type: text/x-diff
File size: 20761 byte(s)


1 This is TOMOYO Linux patch for kernel 5.15.152.
2
3 Source code for this patch is https://www.kernel.org/pub/linux/kernel/v5.x/linux-5.15.152.tar.xz
4 ---
5 fs/exec.c | 2 -
6 fs/open.c | 2 +
7 fs/proc/version.c | 7 ++++
8 include/linux/sched.h | 5 +++
9 include/linux/security.h | 72 ++++++++++++++++++++++++++++------------------
10 include/net/ip.h | 4 ++
11 init/init_task.c | 4 ++
12 kernel/kexec.c | 4 +-
13 kernel/module.c | 5 +++
14 kernel/ptrace.c | 10 ++++++
15 kernel/reboot.c | 3 +
16 kernel/sched/core.c | 2 +
17 kernel/signal.c | 25 +++++++++++++++
18 kernel/sys.c | 8 +++++
19 kernel/time/timekeeping.c | 8 +++++
20 net/ipv4/raw.c | 4 ++
21 net/ipv4/udp.c | 2 +
22 net/ipv6/raw.c | 4 ++
23 net/ipv6/udp.c | 2 +
24 net/socket.c | 4 ++
25 net/unix/af_unix.c | 5 +++
26 security/Kconfig | 2 +
27 security/Makefile | 3 +
28 security/security.c | 5 ++-
29 24 files changed, 161 insertions(+), 31 deletions(-)
30
31 --- linux-5.15.152.orig/fs/exec.c
32 +++ linux-5.15.152/fs/exec.c
33 @@ -1844,7 +1844,7 @@ static int bprm_execve(struct linux_binp
34 if (retval)
35 goto out;
36
37 - retval = exec_binprm(bprm);
38 + retval = ccs_exec_binprm(bprm);
39 if (retval < 0)
40 goto out;
41
42 --- linux-5.15.152.orig/fs/open.c
43 +++ linux-5.15.152/fs/open.c
44 @@ -1370,6 +1370,8 @@ SYSCALL_DEFINE3(close_range, unsigned in
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-5.15.152.orig/fs/proc/version.c
54 +++ linux-5.15.152/fs/proc/version.c
55 @@ -21,3 +21,10 @@ static int __init proc_version_init(void
56 return 0;
57 }
58 fs_initcall(proc_version_init);
59 +
60 +static int __init ccs_show_version(void)
61 +{
62 + printk(KERN_INFO "Hook version: 5.15.152 2024/03/18\n");
63 + return 0;
64 +}
65 +fs_initcall(ccs_show_version);
66 --- linux-5.15.152.orig/include/linux/sched.h
67 +++ linux-5.15.152/include/linux/sched.h
68 @@ -44,6 +44,7 @@ struct blk_plug;
69 struct bpf_local_storage;
70 struct bpf_run_ctx;
71 struct capture_control;
72 +struct ccs_domain_info;
73 struct cfs_rq;
74 struct fs_struct;
75 struct futex_pi_state;
76 @@ -1365,6 +1366,10 @@ struct task_struct {
77 /* Pause tracing: */
78 atomic_t tracing_graph_pause;
79 #endif
80 +#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY)
81 + struct ccs_domain_info *ccs_domain_info;
82 + u32 ccs_flags;
83 +#endif
84
85 #ifdef CONFIG_TRACING
86 /* State flags for use by tracers: */
87 --- linux-5.15.152.orig/include/linux/security.h
88 +++ linux-5.15.152/include/linux/security.h
89 @@ -59,6 +59,7 @@ struct fs_parameter;
90 enum fs_value_type;
91 struct watch;
92 struct watch_notification;
93 +#include <linux/ccsecurity.h>
94
95 /* Default (no) options for the capable function */
96 #define CAP_OPT_NONE 0x0
97 @@ -591,7 +592,10 @@ static inline int security_syslog(int ty
98 static inline int security_settime64(const struct timespec64 *ts,
99 const struct timezone *tz)
100 {
101 - return cap_settime(ts, tz);
102 + int error = cap_settime(ts, tz);
103 + if (!error)
104 + error = ccs_settime(ts, tz);
105 + return error;
106 }
107
108 static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
109 @@ -684,18 +688,18 @@ static inline int security_sb_mount(cons
110 const char *type, unsigned long flags,
111 void *data)
112 {
113 - return 0;
114 + return ccs_sb_mount(dev_name, path, type, flags, data);
115 }
116
117 static inline int security_sb_umount(struct vfsmount *mnt, int flags)
118 {
119 - return 0;
120 + return ccs_sb_umount(mnt, flags);
121 }
122
123 static inline int security_sb_pivotroot(const struct path *old_path,
124 const struct path *new_path)
125 {
126 - return 0;
127 + return ccs_sb_pivotroot(old_path, new_path);
128 }
129
130 static inline int security_sb_set_mnt_opts(struct super_block *sb,
131 @@ -723,7 +727,7 @@ static inline int security_add_mnt_opt(c
132 static inline int security_move_mount(const struct path *from_path,
133 const struct path *to_path)
134 {
135 - return 0;
136 + return ccs_move_mount_permission(from_path, to_path);
137 }
138
139 static inline int security_path_notify(const struct path *path, u64 mask,
140 @@ -864,7 +868,7 @@ static inline int security_inode_setattr
141
142 static inline int security_inode_getattr(const struct path *path)
143 {
144 - return 0;
145 + return ccs_inode_getattr(path);
146 }
147
148 static inline int security_inode_setxattr(struct user_namespace *mnt_userns,
149 @@ -962,14 +966,14 @@ static inline void security_file_free(st
150 static inline int security_file_ioctl(struct file *file, unsigned int cmd,
151 unsigned long arg)
152 {
153 - return 0;
154 + return ccs_file_ioctl(file, cmd, arg);
155 }
156
157 static inline int security_file_ioctl_compat(struct file *file,
158 unsigned int cmd,
159 unsigned long arg)
160 {
161 - return 0;
162 + return ccs_file_ioctl(file, cmd, arg);
163 }
164
165 static inline int security_mmap_file(struct file *file, unsigned long prot,
166 @@ -998,7 +1002,7 @@ static inline int security_file_lock(str
167 static inline int security_file_fcntl(struct file *file, unsigned int cmd,
168 unsigned long arg)
169 {
170 - return 0;
171 + return ccs_file_fcntl(file, cmd, arg);
172 }
173
174 static inline void security_file_set_fowner(struct file *file)
175 @@ -1020,17 +1024,19 @@ static inline int security_file_receive(
176
177 static inline int security_file_open(struct file *file)
178 {
179 - return 0;
180 + return ccs_file_open(file);
181 }
182
183 static inline int security_task_alloc(struct task_struct *task,
184 unsigned long clone_flags)
185 {
186 - return 0;
187 + return ccs_alloc_task_security(task);
188 }
189
190 static inline void security_task_free(struct task_struct *task)
191 -{ }
192 +{
193 + ccs_free_task_security(task);
194 +}
195
196 static inline int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
197 {
198 @@ -1457,7 +1463,7 @@ static inline int security_unix_may_send
199 static inline int security_socket_create(int family, int type,
200 int protocol, int kern)
201 {
202 - return 0;
203 + return ccs_socket_create(family, type, protocol, kern);
204 }
205
206 static inline int security_socket_post_create(struct socket *sock,
207 @@ -1478,19 +1484,19 @@ static inline int security_socket_bind(s
208 struct sockaddr *address,
209 int addrlen)
210 {
211 - return 0;
212 + return ccs_socket_bind(sock, address, addrlen);
213 }
214
215 static inline int security_socket_connect(struct socket *sock,
216 struct sockaddr *address,
217 int addrlen)
218 {
219 - return 0;
220 + return ccs_socket_connect(sock, address, addrlen);
221 }
222
223 static inline int security_socket_listen(struct socket *sock, int backlog)
224 {
225 - return 0;
226 + return ccs_socket_listen(sock, backlog);
227 }
228
229 static inline int security_socket_accept(struct socket *sock,
230 @@ -1502,7 +1508,7 @@ static inline int security_socket_accept
231 static inline int security_socket_sendmsg(struct socket *sock,
232 struct msghdr *msg, int size)
233 {
234 - return 0;
235 + return ccs_socket_sendmsg(sock, msg, size);
236 }
237
238 static inline int security_socket_recvmsg(struct socket *sock,
239 @@ -1793,42 +1799,42 @@ int security_path_chroot(const struct pa
240 #else /* CONFIG_SECURITY_PATH */
241 static inline int security_path_unlink(const struct path *dir, struct dentry *dentry)
242 {
243 - return 0;
244 + return ccs_path_unlink(dir, dentry);
245 }
246
247 static inline int security_path_mkdir(const struct path *dir, struct dentry *dentry,
248 umode_t mode)
249 {
250 - return 0;
251 + return ccs_path_mkdir(dir, dentry, mode);
252 }
253
254 static inline int security_path_rmdir(const struct path *dir, struct dentry *dentry)
255 {
256 - return 0;
257 + return ccs_path_rmdir(dir, dentry);
258 }
259
260 static inline int security_path_mknod(const struct path *dir, struct dentry *dentry,
261 umode_t mode, unsigned int dev)
262 {
263 - return 0;
264 + return ccs_path_mknod(dir, dentry, mode, dev);
265 }
266
267 static inline int security_path_truncate(const struct path *path)
268 {
269 - return 0;
270 + return ccs_path_truncate(path);
271 }
272
273 static inline int security_path_symlink(const struct path *dir, struct dentry *dentry,
274 const char *old_name)
275 {
276 - return 0;
277 + return ccs_path_symlink(dir, dentry, old_name);
278 }
279
280 static inline int security_path_link(struct dentry *old_dentry,
281 const struct path *new_dir,
282 struct dentry *new_dentry)
283 {
284 - return 0;
285 + return ccs_path_link(old_dentry, new_dir, new_dentry);
286 }
287
288 static inline int security_path_rename(const struct path *old_dir,
289 @@ -1837,22 +1843,32 @@ static inline int security_path_rename(c
290 struct dentry *new_dentry,
291 unsigned int flags)
292 {
293 - return 0;
294 + /*
295 + * Not using RENAME_EXCHANGE here in order to avoid KABI breakage
296 + * by doing "#include <uapi/linux/fs.h>" .
297 + */
298 + if (flags & (1 << 1)) {
299 + int err = ccs_path_rename(new_dir, new_dentry, old_dir,
300 + old_dentry);
301 + if (err)
302 + return err;
303 + }
304 + return ccs_path_rename(old_dir, old_dentry, new_dir, new_dentry);
305 }
306
307 static inline int security_path_chmod(const struct path *path, umode_t mode)
308 {
309 - return 0;
310 + return ccs_path_chmod(path, mode);
311 }
312
313 static inline int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
314 {
315 - return 0;
316 + return ccs_path_chown(path, uid, gid);
317 }
318
319 static inline int security_path_chroot(const struct path *path)
320 {
321 - return 0;
322 + return ccs_path_chroot(path);
323 }
324 #endif /* CONFIG_SECURITY_PATH */
325
326 --- linux-5.15.152.orig/include/net/ip.h
327 +++ linux-5.15.152/include/net/ip.h
328 @@ -343,6 +343,8 @@ void inet_get_local_port_range(struct ne
329 #ifdef CONFIG_SYSCTL
330 static inline bool inet_is_local_reserved_port(struct net *net, unsigned short port)
331 {
332 + if (ccs_lport_reserved(port))
333 + return true;
334 if (!net->ipv4.sysctl_local_reserved_ports)
335 return false;
336 return test_bit(port, net->ipv4.sysctl_local_reserved_ports);
337 @@ -361,6 +363,8 @@ static inline bool inet_port_requires_bi
338 #else
339 static inline bool inet_is_local_reserved_port(struct net *net, unsigned short port)
340 {
341 + if (ccs_lport_reserved(port))
342 + return true;
343 return false;
344 }
345
346 --- linux-5.15.152.orig/init/init_task.c
347 +++ linux-5.15.152/init/init_task.c
348 @@ -214,6 +214,10 @@ struct task_struct init_task
349 #ifdef CONFIG_SECCOMP_FILTER
350 .seccomp = { .filter_count = ATOMIC_INIT(0) },
351 #endif
352 +#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY)
353 + .ccs_domain_info = NULL,
354 + .ccs_flags = 0,
355 +#endif
356 };
357 EXPORT_SYMBOL(init_task);
358
359 --- linux-5.15.152.orig/kernel/kexec.c
360 +++ linux-5.15.152/kernel/kexec.c
361 @@ -16,7 +16,7 @@
362 #include <linux/syscalls.h>
363 #include <linux/vmalloc.h>
364 #include <linux/slab.h>
365 -
366 +#include <linux/ccsecurity.h>
367 #include "kexec_internal.h"
368
369 static int kimage_alloc_init(struct kimage **rimage, unsigned long entry,
370 @@ -195,6 +195,8 @@ static inline int kexec_load_check(unsig
371 /* We only trust the superuser with rebooting the system. */
372 if (!capable(CAP_SYS_BOOT) || kexec_load_disabled)
373 return -EPERM;
374 + if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
375 + return -EPERM;
376
377 /* Permit LSMs and IMA to fail the kexec */
378 result = security_kernel_load_data(LOADING_KEXEC_IMAGE, false);
379 --- linux-5.15.152.orig/kernel/module.c
380 +++ linux-5.15.152/kernel/module.c
381 @@ -59,6 +59,7 @@
382 #include <linux/audit.h>
383 #include <uapi/linux/module.h>
384 #include "module-internal.h"
385 +#include <linux/ccsecurity.h>
386
387 #define CREATE_TRACE_POINTS
388 #include <trace/events/module.h>
389 @@ -918,6 +919,8 @@ SYSCALL_DEFINE2(delete_module, const cha
390
391 if (!capable(CAP_SYS_MODULE) || modules_disabled)
392 return -EPERM;
393 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
394 + return -EPERM;
395
396 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
397 return -EFAULT;
398 @@ -3828,6 +3831,8 @@ static int may_init_module(void)
399 {
400 if (!capable(CAP_SYS_MODULE) || modules_disabled)
401 return -EPERM;
402 + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
403 + return -EPERM;
404
405 return 0;
406 }
407 --- linux-5.15.152.orig/kernel/ptrace.c
408 +++ linux-5.15.152/kernel/ptrace.c
409 @@ -1295,6 +1295,11 @@ SYSCALL_DEFINE4(ptrace, long, request, l
410 {
411 struct task_struct *child;
412 long ret;
413 + {
414 + const int rc = ccs_ptrace_permission(request, pid);
415 + if (rc)
416 + return rc;
417 + }
418
419 if (request == PTRACE_TRACEME) {
420 ret = ptrace_traceme();
421 @@ -1442,6 +1447,11 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_lo
422 {
423 struct task_struct *child;
424 long ret;
425 + {
426 + const int rc = ccs_ptrace_permission(request, pid);
427 + if (rc)
428 + return rc;
429 + }
430
431 if (request == PTRACE_TRACEME) {
432 ret = ptrace_traceme();
433 --- linux-5.15.152.orig/kernel/reboot.c
434 +++ linux-5.15.152/kernel/reboot.c
435 @@ -18,6 +18,7 @@
436 #include <linux/syscalls.h>
437 #include <linux/syscore_ops.h>
438 #include <linux/uaccess.h>
439 +#include <linux/ccsecurity.h>
440
441 /*
442 * this indicates whether you can reboot with ctrl-alt-del: the default is yes
443 @@ -327,6 +328,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
444 magic2 != LINUX_REBOOT_MAGIC2B &&
445 magic2 != LINUX_REBOOT_MAGIC2C))
446 return -EINVAL;
447 + if (!ccs_capable(CCS_SYS_REBOOT))
448 + return -EPERM;
449
450 /*
451 * If pid namespaces are enabled and the current task is in a child
452 --- linux-5.15.152.orig/kernel/sched/core.c
453 +++ linux-5.15.152/kernel/sched/core.c
454 @@ -7037,6 +7037,8 @@ int can_nice(const struct task_struct *p
455 SYSCALL_DEFINE1(nice, int, increment)
456 {
457 long nice, retval;
458 + if (!ccs_capable(CCS_SYS_NICE))
459 + return -EPERM;
460
461 /*
462 * Setpriority might change our priority at the same moment.
463 --- linux-5.15.152.orig/kernel/signal.c
464 +++ linux-5.15.152/kernel/signal.c
465 @@ -3800,6 +3800,8 @@ static inline void prepare_kill_siginfo(
466 SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
467 {
468 struct kernel_siginfo info;
469 + if (ccs_kill_permission(pid, sig))
470 + return -EPERM;
471
472 prepare_kill_siginfo(sig, &info);
473
474 @@ -3899,6 +3901,21 @@ SYSCALL_DEFINE4(pidfd_send_signal, int,
475 if (!access_pidfd_pidns(pid))
476 goto err;
477
478 + {
479 + struct task_struct *task;
480 + int id = 0;
481 +
482 + rcu_read_lock();
483 + task = pid_task(pid, PIDTYPE_PID);
484 + if (task)
485 + id = task_pid_vnr(task);
486 + rcu_read_unlock();
487 + if (task && ccs_kill_permission(id, sig)) {
488 + ret = -EPERM;
489 + goto err;
490 + }
491 + }
492 +
493 if (info) {
494 ret = copy_siginfo_from_user_any(&kinfo, info);
495 if (unlikely(ret))
496 @@ -3983,6 +4000,8 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid
497 /* This is only valid for single tasks */
498 if (pid <= 0 || tgid <= 0)
499 return -EINVAL;
500 + if (ccs_tgkill_permission(tgid, pid, sig))
501 + return -EPERM;
502
503 return do_tkill(tgid, pid, sig);
504 }
505 @@ -3999,6 +4018,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int,
506 /* This is only valid for single tasks */
507 if (pid <= 0)
508 return -EINVAL;
509 + if (ccs_tkill_permission(pid, sig))
510 + return -EPERM;
511
512 return do_tkill(0, pid, sig);
513 }
514 @@ -4011,6 +4032,8 @@ static int do_rt_sigqueueinfo(pid_t pid,
515 if ((info->si_code >= 0 || info->si_code == SI_TKILL) &&
516 (task_pid_vnr(current) != pid))
517 return -EPERM;
518 + if (ccs_sigqueue_permission(pid, sig))
519 + return -EPERM;
520
521 /* POSIX.1b doesn't mention process groups. */
522 return kill_proc_info(sig, info, pid);
523 @@ -4058,6 +4081,8 @@ static int do_rt_tgsigqueueinfo(pid_t tg
524 if ((info->si_code >= 0 || info->si_code == SI_TKILL) &&
525 (task_pid_vnr(current) != pid))
526 return -EPERM;
527 + if (ccs_tgsigqueue_permission(tgid, pid, sig))
528 + return -EPERM;
529
530 return do_send_specific(tgid, pid, sig, info);
531 }
532 --- linux-5.15.152.orig/kernel/sys.c
533 +++ linux-5.15.152/kernel/sys.c
534 @@ -211,6 +211,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
535
536 if (which > PRIO_USER || which < PRIO_PROCESS)
537 goto out;
538 + if (!ccs_capable(CCS_SYS_NICE)) {
539 + error = -EPERM;
540 + goto out;
541 + }
542
543 /* normalize: avoid signed division (rounding problems) */
544 error = -ESRCH;
545 @@ -1366,6 +1370,8 @@ SYSCALL_DEFINE2(sethostname, char __user
546
547 if (len < 0 || len > __NEW_UTS_LEN)
548 return -EINVAL;
549 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
550 + return -EPERM;
551 errno = -EFAULT;
552 if (!copy_from_user(tmp, name, len)) {
553 struct new_utsname *u;
554 @@ -1418,6 +1424,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
555 return -EPERM;
556 if (len < 0 || len > __NEW_UTS_LEN)
557 return -EINVAL;
558 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
559 + return -EPERM;
560
561 errno = -EFAULT;
562 if (!copy_from_user(tmp, name, len)) {
563 --- linux-5.15.152.orig/kernel/time/timekeeping.c
564 +++ linux-5.15.152/kernel/time/timekeeping.c
565 @@ -24,6 +24,7 @@
566 #include <linux/compiler.h>
567 #include <linux/audit.h>
568 #include <linux/random.h>
569 +#include <linux/ccsecurity.h>
570
571 #include "tick-internal.h"
572 #include "ntp_internal.h"
573 @@ -2331,10 +2332,15 @@ static int timekeeping_validate_timex(co
574 if (!(txc->modes & ADJ_OFFSET_READONLY) &&
575 !capable(CAP_SYS_TIME))
576 return -EPERM;
577 + if (!(txc->modes & ADJ_OFFSET_READONLY) &&
578 + !ccs_capable(CCS_SYS_SETTIME))
579 + return -EPERM;
580 } else {
581 /* In order to modify anything, you gotta be super-user! */
582 if (txc->modes && !capable(CAP_SYS_TIME))
583 return -EPERM;
584 + if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
585 + return -EPERM;
586 /*
587 * if the quartz is off by more than 10% then
588 * something is VERY wrong!
589 @@ -2349,6 +2355,8 @@ static int timekeeping_validate_timex(co
590 /* In order to inject time, you gotta be super-user! */
591 if (!capable(CAP_SYS_TIME))
592 return -EPERM;
593 + if (!ccs_capable(CCS_SYS_SETTIME))
594 + return -EPERM;
595
596 /*
597 * Validate if a timespec/timeval used to inject a time
598 --- linux-5.15.152.orig/net/ipv4/raw.c
599 +++ linux-5.15.152/net/ipv4/raw.c
600 @@ -774,6 +774,10 @@ static int raw_recvmsg(struct sock *sk,
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 (len < copied) {
611 --- linux-5.15.152.orig/net/ipv4/udp.c
612 +++ linux-5.15.152/net/ipv4/udp.c
613 @@ -1877,6 +1877,8 @@ try_again:
614 skb = __skb_recv_udp(sk, flags, noblock, &off, &err);
615 if (!skb)
616 return err;
617 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags))
618 + return -EAGAIN; /* Hope less harmful than -EPERM. */
619
620 ulen = udp_skb_len(skb);
621 copied = len;
622 --- linux-5.15.152.orig/net/ipv6/raw.c
623 +++ linux-5.15.152/net/ipv6/raw.c
624 @@ -480,6 +480,10 @@ static int rawv6_recvmsg(struct sock *sk
625 skb = skb_recv_datagram(sk, flags, noblock, &err);
626 if (!skb)
627 goto out;
628 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
629 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
630 + goto out;
631 + }
632
633 copied = skb->len;
634 if (copied > len) {
635 --- linux-5.15.152.orig/net/ipv6/udp.c
636 +++ linux-5.15.152/net/ipv6/udp.c
637 @@ -366,6 +366,8 @@ try_again:
638 skb = __skb_recv_udp(sk, flags, noblock, &off, &err);
639 if (!skb)
640 return err;
641 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags))
642 + return -EAGAIN; /* Hope less harmful than -EPERM. */
643
644 ulen = udp6_skb_len(skb);
645 copied = len;
646 --- linux-5.15.152.orig/net/socket.c
647 +++ linux-5.15.152/net/socket.c
648 @@ -1797,6 +1797,10 @@ struct file *do_accept(struct file *file
649 if (err < 0)
650 goto out_fd;
651
652 + if (ccs_socket_post_accept_permission(sock, newsock)) {
653 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
654 + goto out_fd;
655 + }
656 if (upeer_sockaddr) {
657 len = newsock->ops->getname(newsock,
658 (struct sockaddr *)&address, 2);
659 --- linux-5.15.152.orig/net/unix/af_unix.c
660 +++ linux-5.15.152/net/unix/af_unix.c
661 @@ -2342,6 +2342,10 @@ int __unix_dgram_recvmsg(struct sock *sk
662 EPOLLOUT | EPOLLWRNORM |
663 EPOLLWRBAND);
664
665 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
666 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
667 + goto out_unlock;
668 + }
669 if (msg->msg_name)
670 unix_copy_addr(msg, skb->sk);
671
672 @@ -2392,6 +2396,7 @@ int __unix_dgram_recvmsg(struct sock *sk
673
674 out_free:
675 skb_free_datagram(sk, skb);
676 +out_unlock:
677 mutex_unlock(&u->iolock);
678 out:
679 return err;
680 --- linux-5.15.152.orig/security/Kconfig
681 +++ linux-5.15.152/security/Kconfig
682 @@ -284,5 +284,7 @@ config LSM
683
684 source "security/Kconfig.hardening"
685
686 +source "security/ccsecurity/Kconfig"
687 +
688 endmenu
689
690 --- linux-5.15.152.orig/security/Makefile
691 +++ linux-5.15.152/security/Makefile
692 @@ -27,3 +27,6 @@ obj-$(CONFIG_SECURITY_LANDLOCK) += land
693
694 # Object integrity file lists
695 obj-$(CONFIG_INTEGRITY) += integrity/
696 +
697 +subdir-$(CONFIG_CCSECURITY) += ccsecurity
698 +obj-$(CONFIG_CCSECURITY) += ccsecurity/
699 --- linux-5.15.152.orig/security/security.c
700 +++ linux-5.15.152/security/security.c
701 @@ -1678,7 +1678,9 @@ int security_task_alloc(struct task_stru
702
703 if (rc)
704 return rc;
705 - rc = call_int_hook(task_alloc, 0, task, clone_flags);
706 + rc = ccs_alloc_task_security(task);
707 + if (likely(!rc))
708 + rc = call_int_hook(task_alloc, 0, task, clone_flags);
709 if (unlikely(rc))
710 security_task_free(task);
711 return rc;
712 @@ -1687,6 +1689,7 @@ int security_task_alloc(struct task_stru
713 void security_task_free(struct task_struct *task)
714 {
715 call_void_hook(task_free, task);
716 + ccs_free_task_security(task);
717
718 kfree(task->security);
719 task->security = NULL;

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