Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/caitsith-patch/patches/ccs-patch-6.6.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: 20435 byte(s)


1 This is TOMOYO Linux patch for kernel 6.6.22.
2
3 Source code for this patch is https://www.kernel.org/pub/linux/kernel/v6.x/linux-6.6.22.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 | 64 +++++++++++++++++++++++++---------------------
10 include/net/ip.h | 4 ++
11 init/init_task.c | 4 ++
12 kernel/kexec.c | 4 ++
13 kernel/module/main.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, 152 insertions(+), 32 deletions(-)
30
31 --- linux-6.6.22.orig/fs/exec.c
32 +++ linux-6.6.22/fs/exec.c
33 @@ -1856,7 +1856,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-6.6.22.orig/fs/open.c
43 +++ linux-6.6.22/fs/open.c
44 @@ -1601,6 +1601,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-6.6.22.orig/fs/proc/version.c
54 +++ linux-6.6.22/fs/proc/version.c
55 @@ -25,3 +25,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: 6.6.22 2024/03/18\n");
63 + return 0;
64 +}
65 +fs_initcall(ccs_show_version);
66 --- linux-6.6.22.orig/include/linux/sched.h
67 +++ linux-6.6.22/include/linux/sched.h
68 @@ -46,6 +46,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 @@ -1400,6 +1401,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 /* Bitmask and counter of trace recursion: */
87 --- linux-6.6.22.orig/include/linux/security.h
88 +++ linux-6.6.22/include/linux/security.h
89 @@ -60,6 +60,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 @@ -601,7 +602,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 @@ -699,18 +703,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 @@ -732,7 +736,7 @@ static inline int security_sb_clone_mnt_
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 @@ -866,7 +870,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 mnt_idmap *idmap,
149 @@ -986,14 +990,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 @@ -1022,7 +1026,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 @@ -1044,22 +1048,24 @@ 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_file_truncate(struct file *file)
184 {
185 - return 0;
186 + return ccs_path_truncate(&file->f_path);
187 }
188
189 static inline int security_task_alloc(struct task_struct *task,
190 unsigned long clone_flags)
191 {
192 - return 0;
193 + return ccs_alloc_task_security(task);
194 }
195
196 static inline void security_task_free(struct task_struct *task)
197 -{ }
198 +{
199 + ccs_free_task_security(task);
200 +}
201
202 static inline int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
203 {
204 @@ -1501,7 +1507,7 @@ static inline int security_unix_may_send
205 static inline int security_socket_create(int family, int type,
206 int protocol, int kern)
207 {
208 - return 0;
209 + return ccs_socket_create(family, type, protocol, kern);
210 }
211
212 static inline int security_socket_post_create(struct socket *sock,
213 @@ -1522,19 +1528,19 @@ static inline int security_socket_bind(s
214 struct sockaddr *address,
215 int addrlen)
216 {
217 - return 0;
218 + return ccs_socket_bind(sock, address, addrlen);
219 }
220
221 static inline int security_socket_connect(struct socket *sock,
222 struct sockaddr *address,
223 int addrlen)
224 {
225 - return 0;
226 + return ccs_socket_connect(sock, address, addrlen);
227 }
228
229 static inline int security_socket_listen(struct socket *sock, int backlog)
230 {
231 - return 0;
232 + return ccs_socket_listen(sock, backlog);
233 }
234
235 static inline int security_socket_accept(struct socket *sock,
236 @@ -1546,7 +1552,7 @@ static inline int security_socket_accept
237 static inline int security_socket_sendmsg(struct socket *sock,
238 struct msghdr *msg, int size)
239 {
240 - return 0;
241 + return ccs_socket_sendmsg(sock, msg, size);
242 }
243
244 static inline int security_socket_recvmsg(struct socket *sock,
245 @@ -1850,42 +1856,42 @@ int security_path_chroot(const struct pa
246 #else /* CONFIG_SECURITY_PATH */
247 static inline int security_path_unlink(const struct path *dir, struct dentry *dentry)
248 {
249 - return 0;
250 + return ccs_path_unlink(dir, dentry);
251 }
252
253 static inline int security_path_mkdir(const struct path *dir, struct dentry *dentry,
254 umode_t mode)
255 {
256 - return 0;
257 + return ccs_path_mkdir(dir, dentry, mode);
258 }
259
260 static inline int security_path_rmdir(const struct path *dir, struct dentry *dentry)
261 {
262 - return 0;
263 + return ccs_path_rmdir(dir, dentry);
264 }
265
266 static inline int security_path_mknod(const struct path *dir, struct dentry *dentry,
267 umode_t mode, unsigned int dev)
268 {
269 - return 0;
270 + return ccs_path_mknod(dir, dentry, mode, dev);
271 }
272
273 static inline int security_path_truncate(const struct path *path)
274 {
275 - return 0;
276 + return ccs_path_truncate(path);
277 }
278
279 static inline int security_path_symlink(const struct path *dir, struct dentry *dentry,
280 const char *old_name)
281 {
282 - return 0;
283 + return ccs_path_symlink(dir, dentry, old_name);
284 }
285
286 static inline int security_path_link(struct dentry *old_dentry,
287 const struct path *new_dir,
288 struct dentry *new_dentry)
289 {
290 - return 0;
291 + return ccs_path_link(old_dentry, new_dir, new_dentry);
292 }
293
294 static inline int security_path_rename(const struct path *old_dir,
295 @@ -1894,22 +1900,22 @@ static inline int security_path_rename(c
296 struct dentry *new_dentry,
297 unsigned int flags)
298 {
299 - return 0;
300 + return ccs_path_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
301 }
302
303 static inline int security_path_chmod(const struct path *path, umode_t mode)
304 {
305 - return 0;
306 + return ccs_path_chmod(path, mode);
307 }
308
309 static inline int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
310 {
311 - return 0;
312 + return ccs_path_chown(path, uid, gid);
313 }
314
315 static inline int security_path_chroot(const struct path *path)
316 {
317 - return 0;
318 + return ccs_path_chroot(path);
319 }
320 #endif /* CONFIG_SECURITY_PATH */
321
322 --- linux-6.6.22.orig/include/net/ip.h
323 +++ linux-6.6.22/include/net/ip.h
324 @@ -355,6 +355,8 @@ void inet_sk_get_local_port_range(const
325 #ifdef CONFIG_SYSCTL
326 static inline bool inet_is_local_reserved_port(struct net *net, unsigned short port)
327 {
328 + if (ccs_lport_reserved(port))
329 + return true;
330 if (!net->ipv4.sysctl_local_reserved_ports)
331 return false;
332 return test_bit(port, net->ipv4.sysctl_local_reserved_ports);
333 @@ -373,6 +375,8 @@ static inline bool inet_port_requires_bi
334 #else
335 static inline bool inet_is_local_reserved_port(struct net *net, unsigned short port)
336 {
337 + if (ccs_lport_reserved(port))
338 + return true;
339 return false;
340 }
341
342 --- linux-6.6.22.orig/init/init_task.c
343 +++ linux-6.6.22/init/init_task.c
344 @@ -210,6 +210,10 @@ struct task_struct init_task
345 #ifdef CONFIG_SECCOMP_FILTER
346 .seccomp = { .filter_count = ATOMIC_INIT(0) },
347 #endif
348 +#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY)
349 + .ccs_domain_info = NULL,
350 + .ccs_flags = 0,
351 +#endif
352 };
353 EXPORT_SYMBOL(init_task);
354
355 --- linux-6.6.22.orig/kernel/kexec.c
356 +++ linux-6.6.22/kernel/kexec.c
357 @@ -16,7 +16,7 @@
358 #include <linux/syscalls.h>
359 #include <linux/vmalloc.h>
360 #include <linux/slab.h>
361 -
362 +#include <linux/ccsecurity.h>
363 #include "kexec_internal.h"
364
365 static int kimage_alloc_init(struct kimage **rimage, unsigned long entry,
366 @@ -202,6 +202,8 @@ static inline int kexec_load_check(unsig
367 /* We only trust the superuser with rebooting the system. */
368 if (!kexec_load_permitted(image_type))
369 return -EPERM;
370 + if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
371 + return -EPERM;
372
373 /* Permit LSMs and IMA to fail the kexec */
374 result = security_kernel_load_data(LOADING_KEXEC_IMAGE, false);
375 --- linux-6.6.22.orig/kernel/module/main.c
376 +++ linux-6.6.22/kernel/module/main.c
377 @@ -62,6 +62,7 @@
378
379 #define CREATE_TRACE_POINTS
380 #include <trace/events/module.h>
381 +#include <linux/ccsecurity.h>
382
383 /*
384 * Mutex protects:
385 @@ -705,6 +706,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 @@ -2627,6 +2630,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-6.6.22.orig/kernel/ptrace.c
404 +++ linux-6.6.22/kernel/ptrace.c
405 @@ -1280,6 +1280,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 @@ -1419,6 +1424,11 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_lo
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-6.6.22.orig/kernel/reboot.c
430 +++ linux-6.6.22/kernel/reboot.c
431 @@ -18,6 +18,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 @@ -716,6 +717,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-6.6.22.orig/kernel/sched/core.c
449 +++ linux-6.6.22/kernel/sched/core.c
450 @@ -7277,6 +7277,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-6.6.22.orig/kernel/signal.c
460 +++ linux-6.6.22/kernel/signal.c
461 @@ -3807,6 +3807,8 @@ static inline void prepare_kill_siginfo(
462 SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
463 {
464 struct kernel_siginfo info;
465 + if (ccs_kill_permission(pid, sig))
466 + return -EPERM;
467
468 prepare_kill_siginfo(sig, &info);
469
470 @@ -3906,6 +3908,21 @@ SYSCALL_DEFINE4(pidfd_send_signal, int,
471 if (!access_pidfd_pidns(pid))
472 goto err;
473
474 + {
475 + struct task_struct *task;
476 + int id = 0;
477 +
478 + rcu_read_lock();
479 + task = pid_task(pid, PIDTYPE_PID);
480 + if (task)
481 + id = task_pid_vnr(task);
482 + rcu_read_unlock();
483 + if (task && ccs_kill_permission(id, sig)) {
484 + ret = -EPERM;
485 + goto err;
486 + }
487 + }
488 +
489 if (info) {
490 ret = copy_siginfo_from_user_any(&kinfo, info);
491 if (unlikely(ret))
492 @@ -3990,6 +4007,8 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid
493 /* This is only valid for single tasks */
494 if (pid <= 0 || tgid <= 0)
495 return -EINVAL;
496 + if (ccs_tgkill_permission(tgid, pid, sig))
497 + return -EPERM;
498
499 return do_tkill(tgid, pid, sig);
500 }
501 @@ -4006,6 +4025,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int,
502 /* This is only valid for single tasks */
503 if (pid <= 0)
504 return -EINVAL;
505 + if (ccs_tkill_permission(pid, sig))
506 + return -EPERM;
507
508 return do_tkill(0, pid, sig);
509 }
510 @@ -4018,6 +4039,8 @@ static int do_rt_sigqueueinfo(pid_t pid,
511 if ((info->si_code >= 0 || info->si_code == SI_TKILL) &&
512 (task_pid_vnr(current) != pid))
513 return -EPERM;
514 + if (ccs_sigqueue_permission(pid, sig))
515 + return -EPERM;
516
517 /* POSIX.1b doesn't mention process groups. */
518 return kill_proc_info(sig, info, pid);
519 @@ -4065,6 +4088,8 @@ static int do_rt_tgsigqueueinfo(pid_t tg
520 if ((info->si_code >= 0 || info->si_code == SI_TKILL) &&
521 (task_pid_vnr(current) != pid))
522 return -EPERM;
523 + if (ccs_tgsigqueue_permission(tgid, pid, sig))
524 + return -EPERM;
525
526 return do_send_specific(tgid, pid, sig, info);
527 }
528 --- linux-6.6.22.orig/kernel/sys.c
529 +++ linux-6.6.22/kernel/sys.c
530 @@ -226,6 +226,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
531
532 if (which > PRIO_USER || which < PRIO_PROCESS)
533 goto out;
534 + if (!ccs_capable(CCS_SYS_NICE)) {
535 + error = -EPERM;
536 + goto out;
537 + }
538
539 /* normalize: avoid signed division (rounding problems) */
540 error = -ESRCH;
541 @@ -1381,6 +1385,8 @@ SYSCALL_DEFINE2(sethostname, char __user
542
543 if (len < 0 || len > __NEW_UTS_LEN)
544 return -EINVAL;
545 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
546 + return -EPERM;
547 errno = -EFAULT;
548 if (!copy_from_user(tmp, name, len)) {
549 struct new_utsname *u;
550 @@ -1434,6 +1440,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
551 return -EPERM;
552 if (len < 0 || len > __NEW_UTS_LEN)
553 return -EINVAL;
554 + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
555 + return -EPERM;
556
557 errno = -EFAULT;
558 if (!copy_from_user(tmp, name, len)) {
559 --- linux-6.6.22.orig/kernel/time/timekeeping.c
560 +++ linux-6.6.22/kernel/time/timekeeping.c
561 @@ -24,6 +24,7 @@
562 #include <linux/compiler.h>
563 #include <linux/audit.h>
564 #include <linux/random.h>
565 +#include <linux/ccsecurity.h>
566
567 #include "tick-internal.h"
568 #include "ntp_internal.h"
569 @@ -2348,10 +2349,15 @@ static int timekeeping_validate_timex(co
570 if (!(txc->modes & ADJ_OFFSET_READONLY) &&
571 !capable(CAP_SYS_TIME))
572 return -EPERM;
573 + if (!(txc->modes & ADJ_OFFSET_READONLY) &&
574 + !ccs_capable(CCS_SYS_SETTIME))
575 + return -EPERM;
576 } else {
577 /* In order to modify anything, you gotta be super-user! */
578 if (txc->modes && !capable(CAP_SYS_TIME))
579 return -EPERM;
580 + if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
581 + return -EPERM;
582 /*
583 * if the quartz is off by more than 10% then
584 * something is VERY wrong!
585 @@ -2366,6 +2372,8 @@ static int timekeeping_validate_timex(co
586 /* In order to inject time, you gotta be super-user! */
587 if (!capable(CAP_SYS_TIME))
588 return -EPERM;
589 + if (!ccs_capable(CCS_SYS_SETTIME))
590 + return -EPERM;
591
592 /*
593 * Validate if a timespec/timeval used to inject a time
594 --- linux-6.6.22.orig/net/ipv4/raw.c
595 +++ linux-6.6.22/net/ipv4/raw.c
596 @@ -744,6 +744,10 @@ static int raw_recvmsg(struct sock *sk,
597 skb = skb_recv_datagram(sk, flags, &err);
598 if (!skb)
599 goto out;
600 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
601 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
602 + goto out;
603 + }
604
605 copied = skb->len;
606 if (len < copied) {
607 --- linux-6.6.22.orig/net/ipv4/udp.c
608 +++ linux-6.6.22/net/ipv4/udp.c
609 @@ -1808,6 +1808,8 @@ try_again:
610 skb = __skb_recv_udp(sk, flags, &off, &err);
611 if (!skb)
612 return err;
613 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags))
614 + return -EAGAIN; /* Hope less harmful than -EPERM. */
615
616 ulen = udp_skb_len(skb);
617 copied = len;
618 --- linux-6.6.22.orig/net/ipv6/raw.c
619 +++ linux-6.6.22/net/ipv6/raw.c
620 @@ -444,6 +444,10 @@ static int rawv6_recvmsg(struct sock *sk
621 skb = skb_recv_datagram(sk, flags, &err);
622 if (!skb)
623 goto out;
624 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
625 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
626 + goto out;
627 + }
628
629 copied = skb->len;
630 if (copied > len) {
631 --- linux-6.6.22.orig/net/ipv6/udp.c
632 +++ linux-6.6.22/net/ipv6/udp.c
633 @@ -342,6 +342,8 @@ try_again:
634 skb = __skb_recv_udp(sk, flags, &off, &err);
635 if (!skb)
636 return err;
637 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags))
638 + return -EAGAIN; /* Hope less harmful than -EPERM. */
639
640 ulen = udp6_skb_len(skb);
641 copied = len;
642 --- linux-6.6.22.orig/net/socket.c
643 +++ linux-6.6.22/net/socket.c
644 @@ -1935,6 +1935,10 @@ struct file *do_accept(struct file *file
645 if (err < 0)
646 goto out_fd;
647
648 + if (ccs_socket_post_accept_permission(sock, newsock)) {
649 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
650 + goto out_fd;
651 + }
652 if (upeer_sockaddr) {
653 len = ops->getname(newsock, (struct sockaddr *)&address, 2);
654 if (len < 0) {
655 --- linux-6.6.22.orig/net/unix/af_unix.c
656 +++ linux-6.6.22/net/unix/af_unix.c
657 @@ -2386,6 +2386,10 @@ int __unix_dgram_recvmsg(struct sock *sk
658 EPOLLOUT | EPOLLWRNORM |
659 EPOLLWRBAND);
660
661 + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
662 + err = -EAGAIN; /* Hope less harmful than -EPERM. */
663 + goto out_unlock;
664 + }
665 if (msg->msg_name)
666 unix_copy_addr(msg, skb->sk);
667
668 @@ -2436,6 +2440,7 @@ int __unix_dgram_recvmsg(struct sock *sk
669
670 out_free:
671 skb_free_datagram(sk, skb);
672 +out_unlock:
673 mutex_unlock(&u->iolock);
674 out:
675 return err;
676 --- linux-6.6.22.orig/security/Kconfig
677 +++ linux-6.6.22/security/Kconfig
678 @@ -249,5 +249,7 @@ config LSM
679
680 source "security/Kconfig.hardening"
681
682 +source "security/ccsecurity/Kconfig"
683 +
684 endmenu
685
686 --- linux-6.6.22.orig/security/Makefile
687 +++ linux-6.6.22/security/Makefile
688 @@ -27,3 +27,6 @@ obj-$(CONFIG_SECURITY_LANDLOCK) += land
689
690 # Object integrity file lists
691 obj-$(CONFIG_INTEGRITY) += integrity/
692 +
693 +subdir-$(CONFIG_CCSECURITY) += ccsecurity
694 +obj-$(CONFIG_CCSECURITY) += ccsecurity/
695 --- linux-6.6.22.orig/security/security.c
696 +++ linux-6.6.22/security/security.c
697 @@ -2888,7 +2888,9 @@ int security_task_alloc(struct task_stru
698
699 if (rc)
700 return rc;
701 - rc = call_int_hook(task_alloc, 0, task, clone_flags);
702 + rc = ccs_alloc_task_security(task);
703 + if (likely(!rc))
704 + rc = call_int_hook(task_alloc, 0, task, clone_flags);
705 if (unlikely(rc))
706 security_task_free(task);
707 return rc;
708 @@ -2904,6 +2906,7 @@ int security_task_alloc(struct task_stru
709 void security_task_free(struct task_struct *task)
710 {
711 call_void_hook(task_free, task);
712 + ccs_free_task_security(task);
713
714 kfree(task->security);
715 task->security = NULL;

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