Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/caitsith-patch/patches/ccs-patch-6.5.diff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 387 - (hide annotations) (download) (as text)
Mon Dec 25 14:08:19 2023 UTC (3 months, 2 weeks ago) by kumaneko
File MIME type: text/x-diff
File size: 20246 byte(s)


1 kumaneko 387 This is TOMOYO Linux patch for kernel 6.5.13.
2 kumaneko 380
3 kumaneko 387 Source code for this patch is https://www.kernel.org/pub/linux/kernel/v6.x/linux-6.5.13.tar.xz
4 kumaneko 380 ---
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 | 62 +++++++++++++++++++++++++---------------------
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, 151 insertions(+), 31 deletions(-)
30    
31 kumaneko 387 --- linux-6.5.13.orig/fs/exec.c
32     +++ linux-6.5.13/fs/exec.c
33 kumaneko 380 @@ -1852,7 +1852,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 kumaneko 387 --- linux-6.5.13.orig/fs/open.c
43     +++ linux-6.5.13/fs/open.c
44 kumaneko 380 @@ -1568,6 +1568,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 kumaneko 387 --- linux-6.5.13.orig/fs/proc/version.c
54     +++ linux-6.5.13/fs/proc/version.c
55 kumaneko 380 @@ -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 kumaneko 387 + printk(KERN_INFO "Hook version: 6.5.13 2023/12/17\n");
63 kumaneko 380 + return 0;
64     +}
65     +fs_initcall(ccs_show_version);
66 kumaneko 387 --- linux-6.5.13.orig/include/linux/sched.h
67     +++ linux-6.5.13/include/linux/sched.h
68 kumaneko 380 @@ -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     @@ -1395,6 +1396,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 kumaneko 387 --- linux-6.5.13.orig/include/linux/security.h
88     +++ linux-6.5.13/include/linux/security.h
89 kumaneko 380 @@ -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 kumaneko 382 @@ -598,7 +599,10 @@ static inline int security_syslog(int ty
98 kumaneko 380 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 kumaneko 382 @@ -696,18 +700,18 @@ static inline int security_sb_mount(cons
110 kumaneko 380 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 kumaneko 382 @@ -729,7 +733,7 @@ static inline int security_sb_clone_mnt_
132 kumaneko 380 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 kumaneko 382 @@ -863,7 +867,7 @@ static inline int security_inode_setattr
141 kumaneko 380
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 kumaneko 382 @@ -983,7 +987,7 @@ static inline void security_file_free(st
150 kumaneko 380 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_mmap_file(struct file *file, unsigned long prot,
158 kumaneko 382 @@ -1012,7 +1016,7 @@ static inline int security_file_lock(str
159 kumaneko 380 static inline int security_file_fcntl(struct file *file, unsigned int cmd,
160     unsigned long arg)
161     {
162     - return 0;
163     + return ccs_file_fcntl(file, cmd, arg);
164     }
165    
166     static inline void security_file_set_fowner(struct file *file)
167 kumaneko 382 @@ -1034,22 +1038,24 @@ static inline int security_file_receive(
168 kumaneko 380
169     static inline int security_file_open(struct file *file)
170     {
171     - return 0;
172     + return ccs_file_open(file);
173     }
174    
175     static inline int security_file_truncate(struct file *file)
176     {
177     - return 0;
178     + return ccs_path_truncate(&file->f_path);
179     }
180    
181     static inline int security_task_alloc(struct task_struct *task,
182     unsigned long clone_flags)
183     {
184     - return 0;
185     + return ccs_alloc_task_security(task);
186     }
187    
188     static inline void security_task_free(struct task_struct *task)
189     -{ }
190     +{
191     + ccs_free_task_security(task);
192     +}
193    
194     static inline int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
195     {
196 kumaneko 382 @@ -1490,7 +1496,7 @@ static inline int security_unix_may_send
197 kumaneko 380 static inline int security_socket_create(int family, int type,
198     int protocol, int kern)
199     {
200     - return 0;
201     + return ccs_socket_create(family, type, protocol, kern);
202     }
203    
204     static inline int security_socket_post_create(struct socket *sock,
205 kumaneko 382 @@ -1511,19 +1517,19 @@ static inline int security_socket_bind(s
206 kumaneko 380 struct sockaddr *address,
207     int addrlen)
208     {
209     - return 0;
210     + return ccs_socket_bind(sock, address, addrlen);
211     }
212    
213     static inline int security_socket_connect(struct socket *sock,
214     struct sockaddr *address,
215     int addrlen)
216     {
217     - return 0;
218     + return ccs_socket_connect(sock, address, addrlen);
219     }
220    
221     static inline int security_socket_listen(struct socket *sock, int backlog)
222     {
223     - return 0;
224     + return ccs_socket_listen(sock, backlog);
225     }
226    
227     static inline int security_socket_accept(struct socket *sock,
228 kumaneko 382 @@ -1535,7 +1541,7 @@ static inline int security_socket_accept
229 kumaneko 380 static inline int security_socket_sendmsg(struct socket *sock,
230     struct msghdr *msg, int size)
231     {
232     - return 0;
233     + return ccs_socket_sendmsg(sock, msg, size);
234     }
235    
236     static inline int security_socket_recvmsg(struct socket *sock,
237 kumaneko 382 @@ -1839,42 +1845,42 @@ int security_path_chroot(const struct pa
238 kumaneko 380 #else /* CONFIG_SECURITY_PATH */
239     static inline int security_path_unlink(const struct path *dir, struct dentry *dentry)
240     {
241     - return 0;
242     + return ccs_path_unlink(dir, dentry);
243     }
244    
245     static inline int security_path_mkdir(const struct path *dir, struct dentry *dentry,
246     umode_t mode)
247     {
248     - return 0;
249     + return ccs_path_mkdir(dir, dentry, mode);
250     }
251    
252     static inline int security_path_rmdir(const struct path *dir, struct dentry *dentry)
253     {
254     - return 0;
255     + return ccs_path_rmdir(dir, dentry);
256     }
257    
258     static inline int security_path_mknod(const struct path *dir, struct dentry *dentry,
259     umode_t mode, unsigned int dev)
260     {
261     - return 0;
262     + return ccs_path_mknod(dir, dentry, mode, dev);
263     }
264    
265     static inline int security_path_truncate(const struct path *path)
266     {
267     - return 0;
268     + return ccs_path_truncate(path);
269     }
270    
271     static inline int security_path_symlink(const struct path *dir, struct dentry *dentry,
272     const char *old_name)
273     {
274     - return 0;
275     + return ccs_path_symlink(dir, dentry, old_name);
276     }
277    
278     static inline int security_path_link(struct dentry *old_dentry,
279     const struct path *new_dir,
280     struct dentry *new_dentry)
281     {
282     - return 0;
283     + return ccs_path_link(old_dentry, new_dir, new_dentry);
284     }
285    
286     static inline int security_path_rename(const struct path *old_dir,
287 kumaneko 382 @@ -1883,22 +1889,22 @@ static inline int security_path_rename(c
288 kumaneko 380 struct dentry *new_dentry,
289     unsigned int flags)
290     {
291     - return 0;
292     + return ccs_path_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
293     }
294    
295     static inline int security_path_chmod(const struct path *path, umode_t mode)
296     {
297     - return 0;
298     + return ccs_path_chmod(path, mode);
299     }
300    
301     static inline int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
302     {
303     - return 0;
304     + return ccs_path_chown(path, uid, gid);
305     }
306    
307     static inline int security_path_chroot(const struct path *path)
308     {
309     - return 0;
310     + return ccs_path_chroot(path);
311     }
312     #endif /* CONFIG_SECURITY_PATH */
313    
314 kumaneko 387 --- linux-6.5.13.orig/include/net/ip.h
315     +++ linux-6.5.13/include/net/ip.h
316 kumaneko 382 @@ -355,6 +355,8 @@ void inet_sk_get_local_port_range(const
317 kumaneko 380 #ifdef CONFIG_SYSCTL
318     static inline bool inet_is_local_reserved_port(struct net *net, unsigned short port)
319     {
320     + if (ccs_lport_reserved(port))
321     + return true;
322     if (!net->ipv4.sysctl_local_reserved_ports)
323     return false;
324     return test_bit(port, net->ipv4.sysctl_local_reserved_ports);
325 kumaneko 382 @@ -373,6 +375,8 @@ static inline bool inet_port_requires_bi
326 kumaneko 380 #else
327     static inline bool inet_is_local_reserved_port(struct net *net, unsigned short port)
328     {
329     + if (ccs_lport_reserved(port))
330     + return true;
331     return false;
332     }
333    
334 kumaneko 387 --- linux-6.5.13.orig/init/init_task.c
335     +++ linux-6.5.13/init/init_task.c
336 kumaneko 380 @@ -210,6 +210,10 @@ struct task_struct init_task
337     #ifdef CONFIG_SECCOMP_FILTER
338     .seccomp = { .filter_count = ATOMIC_INIT(0) },
339     #endif
340     +#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY)
341     + .ccs_domain_info = NULL,
342     + .ccs_flags = 0,
343     +#endif
344     };
345     EXPORT_SYMBOL(init_task);
346    
347 kumaneko 387 --- linux-6.5.13.orig/kernel/kexec.c
348     +++ linux-6.5.13/kernel/kexec.c
349 kumaneko 380 @@ -16,7 +16,7 @@
350     #include <linux/syscalls.h>
351     #include <linux/vmalloc.h>
352     #include <linux/slab.h>
353     -
354     +#include <linux/ccsecurity.h>
355     #include "kexec_internal.h"
356    
357     static int kimage_alloc_init(struct kimage **rimage, unsigned long entry,
358     @@ -197,6 +197,8 @@ static inline int kexec_load_check(unsig
359     /* We only trust the superuser with rebooting the system. */
360     if (!kexec_load_permitted(image_type))
361     return -EPERM;
362     + if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
363     + return -EPERM;
364    
365     /* Permit LSMs and IMA to fail the kexec */
366     result = security_kernel_load_data(LOADING_KEXEC_IMAGE, false);
367 kumaneko 387 --- linux-6.5.13.orig/kernel/module/main.c
368     +++ linux-6.5.13/kernel/module/main.c
369 kumaneko 380 @@ -62,6 +62,7 @@
370    
371     #define CREATE_TRACE_POINTS
372     #include <trace/events/module.h>
373     +#include <linux/ccsecurity.h>
374    
375     /*
376     * Mutex protects:
377     @@ -705,6 +706,8 @@ SYSCALL_DEFINE2(delete_module, const cha
378    
379     if (!capable(CAP_SYS_MODULE) || modules_disabled)
380     return -EPERM;
381     + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
382     + return -EPERM;
383    
384     if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
385     return -EFAULT;
386 kumaneko 382 @@ -2627,6 +2630,8 @@ static int may_init_module(void)
387 kumaneko 380 {
388     if (!capable(CAP_SYS_MODULE) || modules_disabled)
389     return -EPERM;
390     + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
391     + return -EPERM;
392    
393     return 0;
394     }
395 kumaneko 387 --- linux-6.5.13.orig/kernel/ptrace.c
396     +++ linux-6.5.13/kernel/ptrace.c
397 kumaneko 380 @@ -1280,6 +1280,11 @@ SYSCALL_DEFINE4(ptrace, long, request, l
398     {
399     struct task_struct *child;
400     long ret;
401     + {
402     + const int rc = ccs_ptrace_permission(request, pid);
403     + if (rc)
404     + return rc;
405     + }
406    
407     if (request == PTRACE_TRACEME) {
408     ret = ptrace_traceme();
409     @@ -1419,6 +1424,11 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_lo
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 kumaneko 387 --- linux-6.5.13.orig/kernel/reboot.c
422     +++ linux-6.5.13/kernel/reboot.c
423 kumaneko 380 @@ -18,6 +18,7 @@
424     #include <linux/syscalls.h>
425     #include <linux/syscore_ops.h>
426     #include <linux/uaccess.h>
427     +#include <linux/ccsecurity.h>
428    
429     /*
430     * this indicates whether you can reboot with ctrl-alt-del: the default is yes
431 kumaneko 387 @@ -716,6 +717,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
432 kumaneko 380 magic2 != LINUX_REBOOT_MAGIC2B &&
433     magic2 != LINUX_REBOOT_MAGIC2C))
434     return -EINVAL;
435     + if (!ccs_capable(CCS_SYS_REBOOT))
436     + return -EPERM;
437    
438     /*
439     * If pid namespaces are enabled and the current task is in a child
440 kumaneko 387 --- linux-6.5.13.orig/kernel/sched/core.c
441     +++ linux-6.5.13/kernel/sched/core.c
442     @@ -7292,6 +7292,8 @@ int can_nice(const struct task_struct *p
443 kumaneko 380 SYSCALL_DEFINE1(nice, int, increment)
444     {
445     long nice, retval;
446     + if (!ccs_capable(CCS_SYS_NICE))
447     + return -EPERM;
448    
449     /*
450     * Setpriority might change our priority at the same moment.
451 kumaneko 387 --- linux-6.5.13.orig/kernel/signal.c
452     +++ linux-6.5.13/kernel/signal.c
453 kumaneko 381 @@ -3796,6 +3796,8 @@ static inline void prepare_kill_siginfo(
454 kumaneko 380 SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
455     {
456     struct kernel_siginfo info;
457     + if (ccs_kill_permission(pid, sig))
458     + return -EPERM;
459    
460     prepare_kill_siginfo(sig, &info);
461    
462 kumaneko 381 @@ -3895,6 +3897,21 @@ SYSCALL_DEFINE4(pidfd_send_signal, int,
463 kumaneko 380 if (!access_pidfd_pidns(pid))
464     goto err;
465    
466     + {
467     + struct task_struct *task;
468     + int id = 0;
469     +
470     + rcu_read_lock();
471     + task = pid_task(pid, PIDTYPE_PID);
472     + if (task)
473     + id = task_pid_vnr(task);
474     + rcu_read_unlock();
475     + if (task && ccs_kill_permission(id, sig)) {
476     + ret = -EPERM;
477     + goto err;
478     + }
479     + }
480     +
481     if (info) {
482     ret = copy_siginfo_from_user_any(&kinfo, info);
483     if (unlikely(ret))
484 kumaneko 381 @@ -3979,6 +3996,8 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid
485 kumaneko 380 /* This is only valid for single tasks */
486     if (pid <= 0 || tgid <= 0)
487     return -EINVAL;
488     + if (ccs_tgkill_permission(tgid, pid, sig))
489     + return -EPERM;
490    
491     return do_tkill(tgid, pid, sig);
492     }
493 kumaneko 381 @@ -3995,6 +4014,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int,
494 kumaneko 380 /* This is only valid for single tasks */
495     if (pid <= 0)
496     return -EINVAL;
497     + if (ccs_tkill_permission(pid, sig))
498     + return -EPERM;
499    
500     return do_tkill(0, pid, sig);
501     }
502 kumaneko 381 @@ -4007,6 +4028,8 @@ static int do_rt_sigqueueinfo(pid_t pid,
503 kumaneko 380 if ((info->si_code >= 0 || info->si_code == SI_TKILL) &&
504     (task_pid_vnr(current) != pid))
505     return -EPERM;
506     + if (ccs_sigqueue_permission(pid, sig))
507     + return -EPERM;
508    
509     /* POSIX.1b doesn't mention process groups. */
510     return kill_proc_info(sig, info, pid);
511 kumaneko 381 @@ -4054,6 +4077,8 @@ static int do_rt_tgsigqueueinfo(pid_t tg
512 kumaneko 380 if ((info->si_code >= 0 || info->si_code == SI_TKILL) &&
513     (task_pid_vnr(current) != pid))
514     return -EPERM;
515     + if (ccs_tgsigqueue_permission(tgid, pid, sig))
516     + return -EPERM;
517    
518     return do_send_specific(tgid, pid, sig, info);
519     }
520 kumaneko 387 --- linux-6.5.13.orig/kernel/sys.c
521     +++ linux-6.5.13/kernel/sys.c
522 kumaneko 380 @@ -226,6 +226,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
523    
524     if (which > PRIO_USER || which < PRIO_PROCESS)
525     goto out;
526     + if (!ccs_capable(CCS_SYS_NICE)) {
527     + error = -EPERM;
528     + goto out;
529     + }
530    
531     /* normalize: avoid signed division (rounding problems) */
532     error = -ESRCH;
533     @@ -1381,6 +1385,8 @@ SYSCALL_DEFINE2(sethostname, char __user
534    
535     if (len < 0 || len > __NEW_UTS_LEN)
536     return -EINVAL;
537     + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
538     + return -EPERM;
539     errno = -EFAULT;
540     if (!copy_from_user(tmp, name, len)) {
541     struct new_utsname *u;
542     @@ -1434,6 +1440,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
543     return -EPERM;
544     if (len < 0 || len > __NEW_UTS_LEN)
545     return -EINVAL;
546     + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
547     + return -EPERM;
548    
549     errno = -EFAULT;
550     if (!copy_from_user(tmp, name, len)) {
551 kumaneko 387 --- linux-6.5.13.orig/kernel/time/timekeeping.c
552     +++ linux-6.5.13/kernel/time/timekeeping.c
553 kumaneko 380 @@ -24,6 +24,7 @@
554     #include <linux/compiler.h>
555     #include <linux/audit.h>
556     #include <linux/random.h>
557     +#include <linux/ccsecurity.h>
558    
559     #include "tick-internal.h"
560     #include "ntp_internal.h"
561     @@ -2348,10 +2349,15 @@ static int timekeeping_validate_timex(co
562     if (!(txc->modes & ADJ_OFFSET_READONLY) &&
563     !capable(CAP_SYS_TIME))
564     return -EPERM;
565     + if (!(txc->modes & ADJ_OFFSET_READONLY) &&
566     + !ccs_capable(CCS_SYS_SETTIME))
567     + return -EPERM;
568     } else {
569     /* In order to modify anything, you gotta be super-user! */
570     if (txc->modes && !capable(CAP_SYS_TIME))
571     return -EPERM;
572     + if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
573     + return -EPERM;
574     /*
575     * if the quartz is off by more than 10% then
576     * something is VERY wrong!
577     @@ -2366,6 +2372,8 @@ static int timekeeping_validate_timex(co
578     /* In order to inject time, you gotta be super-user! */
579     if (!capable(CAP_SYS_TIME))
580     return -EPERM;
581     + if (!ccs_capable(CCS_SYS_SETTIME))
582     + return -EPERM;
583    
584     /*
585     * Validate if a timespec/timeval used to inject a time
586 kumaneko 387 --- linux-6.5.13.orig/net/ipv4/raw.c
587     +++ linux-6.5.13/net/ipv4/raw.c
588 kumaneko 380 @@ -746,6 +746,10 @@ static int raw_recvmsg(struct sock *sk,
589     skb = skb_recv_datagram(sk, flags, &err);
590     if (!skb)
591     goto out;
592     + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
593     + err = -EAGAIN; /* Hope less harmful than -EPERM. */
594     + goto out;
595     + }
596    
597     copied = skb->len;
598     if (len < copied) {
599 kumaneko 387 --- linux-6.5.13.orig/net/ipv4/udp.c
600     +++ linux-6.5.13/net/ipv4/udp.c
601 kumaneko 382 @@ -1835,6 +1835,8 @@ try_again:
602 kumaneko 380 skb = __skb_recv_udp(sk, flags, &off, &err);
603     if (!skb)
604     return err;
605     + if (ccs_socket_post_recvmsg_permission(sk, skb, flags))
606     + return -EAGAIN; /* Hope less harmful than -EPERM. */
607    
608     ulen = udp_skb_len(skb);
609     copied = len;
610 kumaneko 387 --- linux-6.5.13.orig/net/ipv6/raw.c
611     +++ linux-6.5.13/net/ipv6/raw.c
612 kumaneko 380 @@ -445,6 +445,10 @@ static int rawv6_recvmsg(struct sock *sk
613     skb = skb_recv_datagram(sk, flags, &err);
614     if (!skb)
615     goto out;
616     + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
617     + err = -EAGAIN; /* Hope less harmful than -EPERM. */
618     + goto out;
619     + }
620    
621     copied = skb->len;
622     if (copied > len) {
623 kumaneko 387 --- linux-6.5.13.orig/net/ipv6/udp.c
624     +++ linux-6.5.13/net/ipv6/udp.c
625 kumaneko 382 @@ -375,6 +375,8 @@ try_again:
626 kumaneko 380 skb = __skb_recv_udp(sk, flags, &off, &err);
627     if (!skb)
628     return err;
629     + if (ccs_socket_post_recvmsg_permission(sk, skb, flags))
630     + return -EAGAIN; /* Hope less harmful than -EPERM. */
631    
632     ulen = udp6_skb_len(skb);
633     copied = len;
634 kumaneko 387 --- linux-6.5.13.orig/net/socket.c
635     +++ linux-6.5.13/net/socket.c
636 kumaneko 383 @@ -1892,6 +1892,10 @@ struct file *do_accept(struct file *file
637 kumaneko 380 if (err < 0)
638     goto out_fd;
639    
640     + if (ccs_socket_post_accept_permission(sock, newsock)) {
641     + err = -EAGAIN; /* Hope less harmful than -EPERM. */
642     + goto out_fd;
643     + }
644     if (upeer_sockaddr) {
645     len = newsock->ops->getname(newsock,
646     (struct sockaddr *)&address, 2);
647 kumaneko 387 --- linux-6.5.13.orig/net/unix/af_unix.c
648     +++ linux-6.5.13/net/unix/af_unix.c
649 kumaneko 381 @@ -2390,6 +2390,10 @@ int __unix_dgram_recvmsg(struct sock *sk
650 kumaneko 380 EPOLLOUT | EPOLLWRNORM |
651     EPOLLWRBAND);
652    
653     + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
654     + err = -EAGAIN; /* Hope less harmful than -EPERM. */
655     + goto out_unlock;
656     + }
657     if (msg->msg_name)
658     unix_copy_addr(msg, skb->sk);
659    
660 kumaneko 381 @@ -2440,6 +2444,7 @@ int __unix_dgram_recvmsg(struct sock *sk
661 kumaneko 380
662     out_free:
663     skb_free_datagram(sk, skb);
664     +out_unlock:
665     mutex_unlock(&u->iolock);
666     out:
667     return err;
668 kumaneko 387 --- linux-6.5.13.orig/security/Kconfig
669     +++ linux-6.5.13/security/Kconfig
670 kumaneko 380 @@ -249,5 +249,7 @@ config LSM
671    
672     source "security/Kconfig.hardening"
673    
674     +source "security/ccsecurity/Kconfig"
675     +
676     endmenu
677    
678 kumaneko 387 --- linux-6.5.13.orig/security/Makefile
679     +++ linux-6.5.13/security/Makefile
680 kumaneko 380 @@ -27,3 +27,6 @@ obj-$(CONFIG_SECURITY_LANDLOCK) += land
681    
682     # Object integrity file lists
683     obj-$(CONFIG_INTEGRITY) += integrity/
684     +
685     +subdir-$(CONFIG_CCSECURITY) += ccsecurity
686     +obj-$(CONFIG_CCSECURITY) += ccsecurity/
687 kumaneko 387 --- linux-6.5.13.orig/security/security.c
688     +++ linux-6.5.13/security/security.c
689 kumaneko 382 @@ -2845,7 +2845,9 @@ int security_task_alloc(struct task_stru
690 kumaneko 380
691     if (rc)
692     return rc;
693     - rc = call_int_hook(task_alloc, 0, task, clone_flags);
694     + rc = ccs_alloc_task_security(task);
695     + if (likely(!rc))
696     + rc = call_int_hook(task_alloc, 0, task, clone_flags);
697     if (unlikely(rc))
698     security_task_free(task);
699     return rc;
700 kumaneko 382 @@ -2861,6 +2863,7 @@ int security_task_alloc(struct task_stru
701 kumaneko 380 void security_task_free(struct task_struct *task)
702     {
703     call_void_hook(task_free, task);
704     + ccs_free_task_security(task);
705    
706     kfree(task->security);
707     task->security = NULL;

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