Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 388 - (hide 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: 20331 byte(s)


1 kumaneko 388 This is TOMOYO Linux patch for kernel 6.1.82.
2 kumaneko 373
3 kumaneko 388 Source code for this patch is https://www.kernel.org/pub/linux/kernel/v6.x/linux-6.1.82.tar.xz
4 kumaneko 373 ---
5     fs/exec.c | 2 -
6     fs/open.c | 2 +
7     fs/proc/version.c | 7 +++++
8     include/linux/sched.h | 5 +++
9 kumaneko 388 include/linux/security.h | 62 +++++++++++++++++++++++++---------------------
10     include/net/ip.h | 4 ++
11     init/init_task.c | 4 ++
12     kernel/kexec.c | 4 ++
13 kumaneko 373 kernel/module/main.c | 5 +++
14     kernel/ptrace.c | 10 +++++++
15     kernel/reboot.c | 3 ++
16     kernel/sched/core.c | 2 +
17 kumaneko 388 kernel/signal.c | 25 ++++++++++++++++++
18     kernel/sys.c | 8 +++++
19     kernel/time/timekeeping.c | 8 +++++
20     net/ipv4/raw.c | 4 ++
21 kumaneko 373 net/ipv4/udp.c | 2 +
22 kumaneko 388 net/ipv6/raw.c | 4 ++
23 kumaneko 373 net/ipv6/udp.c | 2 +
24 kumaneko 388 net/socket.c | 4 ++
25 kumaneko 373 net/unix/af_unix.c | 5 +++
26     security/Kconfig | 2 +
27     security/Makefile | 3 ++
28 kumaneko 388 security/security.c | 5 ++-
29     24 files changed, 151 insertions(+), 31 deletions(-)
30 kumaneko 373
31 kumaneko 388 --- linux-6.1.82.orig/fs/exec.c
32     +++ linux-6.1.82/fs/exec.c
33     @@ -1843,7 +1843,7 @@ static int bprm_execve(struct linux_binp
34 kumaneko 373 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 388 --- linux-6.1.82.orig/fs/open.c
43     +++ linux-6.1.82/fs/open.c
44 kumaneko 380 @@ -1480,6 +1480,8 @@ SYSCALL_DEFINE3(close_range, unsigned in
45 kumaneko 373 */
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 388 --- linux-6.1.82.orig/fs/proc/version.c
54     +++ linux-6.1.82/fs/proc/version.c
55 kumaneko 373 @@ -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 388 + printk(KERN_INFO "Hook version: 6.1.82 2024/03/18\n");
63 kumaneko 373 + return 0;
64     +}
65     +fs_initcall(ccs_show_version);
66 kumaneko 388 --- linux-6.1.82.orig/include/linux/sched.h
67     +++ linux-6.1.82/include/linux/sched.h
68 kumaneko 373 @@ -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     @@ -1398,6 +1399,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 388 --- linux-6.1.82.orig/include/linux/security.h
88     +++ linux-6.1.82/include/linux/security.h
89 kumaneko 373 @@ -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 kumaneko 388 @@ -596,7 +597,10 @@ static inline int security_syslog(int ty
98 kumaneko 373 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 388 @@ -694,18 +698,18 @@ static inline int security_sb_mount(cons
110 kumaneko 373 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 388 @@ -727,7 +731,7 @@ static inline int security_sb_clone_mnt_
132 kumaneko 373 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 388 @@ -870,7 +874,7 @@ static inline int security_inode_setattr
141 kumaneko 373
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 kumaneko 388 @@ -968,14 +972,14 @@ static inline void security_file_free(st
150 kumaneko 373 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 kumaneko 388 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 kumaneko 373 static inline int security_mmap_file(struct file *file, unsigned long prot,
166 kumaneko 388 @@ -1004,7 +1008,7 @@ static inline int security_file_lock(str
167 kumaneko 373 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 kumaneko 388 @@ -1026,17 +1030,19 @@ static inline int security_file_receive(
176 kumaneko 373
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 kumaneko 388 @@ -1476,7 +1482,7 @@ static inline int security_unix_may_send
199 kumaneko 373 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 kumaneko 388 @@ -1497,19 +1503,19 @@ static inline int security_socket_bind(s
208 kumaneko 373 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 kumaneko 388 @@ -1521,7 +1527,7 @@ static inline int security_socket_accept
231 kumaneko 373 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 kumaneko 388 @@ -1818,42 +1824,42 @@ int security_path_chroot(const struct pa
240 kumaneko 373 #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 kumaneko 388 @@ -1862,22 +1868,22 @@ static inline int security_path_rename(c
290 kumaneko 373 struct dentry *new_dentry,
291     unsigned int flags)
292     {
293     - return 0;
294     + return ccs_path_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
295     }
296    
297     static inline int security_path_chmod(const struct path *path, umode_t mode)
298     {
299     - return 0;
300     + return ccs_path_chmod(path, mode);
301     }
302    
303     static inline int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
304     {
305     - return 0;
306     + return ccs_path_chown(path, uid, gid);
307     }
308    
309     static inline int security_path_chroot(const struct path *path)
310     {
311     - return 0;
312     + return ccs_path_chroot(path);
313     }
314     #endif /* CONFIG_SECURITY_PATH */
315    
316 kumaneko 388 --- linux-6.1.82.orig/include/net/ip.h
317     +++ linux-6.1.82/include/net/ip.h
318 kumaneko 382 @@ -349,6 +349,8 @@ void inet_sk_get_local_port_range(const
319 kumaneko 373 #ifdef CONFIG_SYSCTL
320     static inline bool inet_is_local_reserved_port(struct net *net, unsigned short port)
321     {
322     + if (ccs_lport_reserved(port))
323     + return true;
324     if (!net->ipv4.sysctl_local_reserved_ports)
325     return false;
326     return test_bit(port, net->ipv4.sysctl_local_reserved_ports);
327 kumaneko 382 @@ -367,6 +369,8 @@ static inline bool inet_port_requires_bi
328 kumaneko 373 #else
329     static inline bool inet_is_local_reserved_port(struct net *net, unsigned short port)
330     {
331     + if (ccs_lport_reserved(port))
332     + return true;
333     return false;
334     }
335    
336 kumaneko 388 --- linux-6.1.82.orig/init/init_task.c
337     +++ linux-6.1.82/init/init_task.c
338 kumaneko 373 @@ -210,6 +210,10 @@ struct task_struct init_task
339     #ifdef CONFIG_SECCOMP_FILTER
340     .seccomp = { .filter_count = ATOMIC_INIT(0) },
341     #endif
342     +#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY)
343     + .ccs_domain_info = NULL,
344     + .ccs_flags = 0,
345     +#endif
346     };
347     EXPORT_SYMBOL(init_task);
348    
349 kumaneko 388 --- linux-6.1.82.orig/kernel/kexec.c
350     +++ linux-6.1.82/kernel/kexec.c
351 kumaneko 373 @@ -16,7 +16,7 @@
352     #include <linux/syscalls.h>
353     #include <linux/vmalloc.h>
354     #include <linux/slab.h>
355     -
356     +#include <linux/ccsecurity.h>
357     #include "kexec_internal.h"
358    
359     static int kimage_alloc_init(struct kimage **rimage, unsigned long entry,
360     @@ -195,6 +195,8 @@ static inline int kexec_load_check(unsig
361     /* We only trust the superuser with rebooting the system. */
362     if (!capable(CAP_SYS_BOOT) || kexec_load_disabled)
363     return -EPERM;
364     + if (!ccs_capable(CCS_SYS_KEXEC_LOAD))
365     + return -EPERM;
366    
367     /* Permit LSMs and IMA to fail the kexec */
368     result = security_kernel_load_data(LOADING_KEXEC_IMAGE, false);
369 kumaneko 388 --- linux-6.1.82.orig/kernel/module/main.c
370     +++ linux-6.1.82/kernel/module/main.c
371 kumaneko 373 @@ -59,6 +59,7 @@
372    
373     #define CREATE_TRACE_POINTS
374     #include <trace/events/module.h>
375     +#include <linux/ccsecurity.h>
376    
377     /*
378     * Mutex protects:
379     @@ -703,6 +704,8 @@ SYSCALL_DEFINE2(delete_module, const cha
380    
381     if (!capable(CAP_SYS_MODULE) || modules_disabled)
382     return -EPERM;
383     + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
384     + return -EPERM;
385    
386     if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
387     return -EFAULT;
388 kumaneko 382 @@ -2555,6 +2558,8 @@ static int may_init_module(void)
389 kumaneko 373 {
390     if (!capable(CAP_SYS_MODULE) || modules_disabled)
391     return -EPERM;
392     + if (!ccs_capable(CCS_USE_KERNEL_MODULE))
393     + return -EPERM;
394    
395     return 0;
396     }
397 kumaneko 388 --- linux-6.1.82.orig/kernel/ptrace.c
398     +++ linux-6.1.82/kernel/ptrace.c
399 kumaneko 373 @@ -1271,6 +1271,11 @@ SYSCALL_DEFINE4(ptrace, long, request, l
400     {
401     struct task_struct *child;
402     long ret;
403     + {
404     + const int rc = ccs_ptrace_permission(request, pid);
405     + if (rc)
406     + return rc;
407     + }
408    
409     if (request == PTRACE_TRACEME) {
410     ret = ptrace_traceme();
411     @@ -1410,6 +1415,11 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_lo
412     {
413     struct task_struct *child;
414     long ret;
415     + {
416     + const int rc = ccs_ptrace_permission(request, pid);
417     + if (rc)
418     + return rc;
419     + }
420    
421     if (request == PTRACE_TRACEME) {
422     ret = ptrace_traceme();
423 kumaneko 388 --- linux-6.1.82.orig/kernel/reboot.c
424     +++ linux-6.1.82/kernel/reboot.c
425 kumaneko 373 @@ -18,6 +18,7 @@
426     #include <linux/syscalls.h>
427     #include <linux/syscore_ops.h>
428     #include <linux/uaccess.h>
429     +#include <linux/ccsecurity.h>
430    
431     /*
432     * this indicates whether you can reboot with ctrl-alt-del: the default is yes
433 kumaneko 387 @@ -716,6 +717,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
434 kumaneko 373 magic2 != LINUX_REBOOT_MAGIC2B &&
435     magic2 != LINUX_REBOOT_MAGIC2C))
436     return -EINVAL;
437     + if (!ccs_capable(CCS_SYS_REBOOT))
438     + return -EPERM;
439    
440     /*
441     * If pid namespaces are enabled and the current task is in a child
442 kumaneko 388 --- linux-6.1.82.orig/kernel/sched/core.c
443     +++ linux-6.1.82/kernel/sched/core.c
444 kumaneko 387 @@ -7139,6 +7139,8 @@ int can_nice(const struct task_struct *p
445 kumaneko 373 SYSCALL_DEFINE1(nice, int, increment)
446     {
447     long nice, retval;
448     + if (!ccs_capable(CCS_SYS_NICE))
449     + return -EPERM;
450    
451     /*
452     * Setpriority might change our priority at the same moment.
453 kumaneko 388 --- linux-6.1.82.orig/kernel/signal.c
454     +++ linux-6.1.82/kernel/signal.c
455 kumaneko 381 @@ -3775,6 +3775,8 @@ static inline void prepare_kill_siginfo(
456 kumaneko 373 SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
457     {
458     struct kernel_siginfo info;
459     + if (ccs_kill_permission(pid, sig))
460     + return -EPERM;
461    
462     prepare_kill_siginfo(sig, &info);
463    
464 kumaneko 381 @@ -3874,6 +3876,21 @@ SYSCALL_DEFINE4(pidfd_send_signal, int,
465 kumaneko 373 if (!access_pidfd_pidns(pid))
466     goto err;
467    
468     + {
469     + struct task_struct *task;
470     + int id = 0;
471     +
472     + rcu_read_lock();
473     + task = pid_task(pid, PIDTYPE_PID);
474     + if (task)
475     + id = task_pid_vnr(task);
476     + rcu_read_unlock();
477     + if (task && ccs_kill_permission(id, sig)) {
478     + ret = -EPERM;
479     + goto err;
480     + }
481     + }
482     +
483     if (info) {
484     ret = copy_siginfo_from_user_any(&kinfo, info);
485     if (unlikely(ret))
486 kumaneko 381 @@ -3958,6 +3975,8 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid
487 kumaneko 373 /* This is only valid for single tasks */
488     if (pid <= 0 || tgid <= 0)
489     return -EINVAL;
490     + if (ccs_tgkill_permission(tgid, pid, sig))
491     + return -EPERM;
492    
493     return do_tkill(tgid, pid, sig);
494     }
495 kumaneko 381 @@ -3974,6 +3993,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int,
496 kumaneko 373 /* This is only valid for single tasks */
497     if (pid <= 0)
498     return -EINVAL;
499     + if (ccs_tkill_permission(pid, sig))
500     + return -EPERM;
501    
502     return do_tkill(0, pid, sig);
503     }
504 kumaneko 381 @@ -3986,6 +4007,8 @@ static int do_rt_sigqueueinfo(pid_t pid,
505 kumaneko 373 if ((info->si_code >= 0 || info->si_code == SI_TKILL) &&
506     (task_pid_vnr(current) != pid))
507     return -EPERM;
508     + if (ccs_sigqueue_permission(pid, sig))
509     + return -EPERM;
510    
511     /* POSIX.1b doesn't mention process groups. */
512     return kill_proc_info(sig, info, pid);
513 kumaneko 381 @@ -4033,6 +4056,8 @@ static int do_rt_tgsigqueueinfo(pid_t tg
514 kumaneko 373 if ((info->si_code >= 0 || info->si_code == SI_TKILL) &&
515     (task_pid_vnr(current) != pid))
516     return -EPERM;
517     + if (ccs_tgsigqueue_permission(tgid, pid, sig))
518     + return -EPERM;
519    
520     return do_send_specific(tgid, pid, sig, info);
521     }
522 kumaneko 388 --- linux-6.1.82.orig/kernel/sys.c
523     +++ linux-6.1.82/kernel/sys.c
524 kumaneko 373 @@ -219,6 +219,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
525    
526     if (which > PRIO_USER || which < PRIO_PROCESS)
527     goto out;
528     + if (!ccs_capable(CCS_SYS_NICE)) {
529     + error = -EPERM;
530     + goto out;
531     + }
532    
533     /* normalize: avoid signed division (rounding problems) */
534     error = -ESRCH;
535 kumaneko 380 @@ -1374,6 +1378,8 @@ SYSCALL_DEFINE2(sethostname, char __user
536 kumaneko 373
537     if (len < 0 || len > __NEW_UTS_LEN)
538     return -EINVAL;
539     + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
540     + return -EPERM;
541     errno = -EFAULT;
542     if (!copy_from_user(tmp, name, len)) {
543     struct new_utsname *u;
544 kumaneko 380 @@ -1427,6 +1433,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
545 kumaneko 373 return -EPERM;
546     if (len < 0 || len > __NEW_UTS_LEN)
547     return -EINVAL;
548     + if (!ccs_capable(CCS_SYS_SETHOSTNAME))
549     + return -EPERM;
550    
551     errno = -EFAULT;
552     if (!copy_from_user(tmp, name, len)) {
553 kumaneko 388 --- linux-6.1.82.orig/kernel/time/timekeeping.c
554     +++ linux-6.1.82/kernel/time/timekeeping.c
555 kumaneko 373 @@ -24,6 +24,7 @@
556     #include <linux/compiler.h>
557     #include <linux/audit.h>
558     #include <linux/random.h>
559     +#include <linux/ccsecurity.h>
560    
561     #include "tick-internal.h"
562     #include "ntp_internal.h"
563     @@ -2348,10 +2349,15 @@ static int timekeeping_validate_timex(co
564     if (!(txc->modes & ADJ_OFFSET_READONLY) &&
565     !capable(CAP_SYS_TIME))
566     return -EPERM;
567     + if (!(txc->modes & ADJ_OFFSET_READONLY) &&
568     + !ccs_capable(CCS_SYS_SETTIME))
569     + return -EPERM;
570     } else {
571     /* In order to modify anything, you gotta be super-user! */
572     if (txc->modes && !capable(CAP_SYS_TIME))
573     return -EPERM;
574     + if (txc->modes && !ccs_capable(CCS_SYS_SETTIME))
575     + return -EPERM;
576     /*
577     * if the quartz is off by more than 10% then
578     * something is VERY wrong!
579     @@ -2366,6 +2372,8 @@ static int timekeeping_validate_timex(co
580     /* In order to inject time, you gotta be super-user! */
581     if (!capable(CAP_SYS_TIME))
582     return -EPERM;
583     + if (!ccs_capable(CCS_SYS_SETTIME))
584     + return -EPERM;
585    
586     /*
587     * Validate if a timespec/timeval used to inject a time
588 kumaneko 388 --- linux-6.1.82.orig/net/ipv4/raw.c
589     +++ linux-6.1.82/net/ipv4/raw.c
590     @@ -748,6 +748,10 @@ static int raw_recvmsg(struct sock *sk,
591 kumaneko 373 skb = skb_recv_datagram(sk, flags, &err);
592     if (!skb)
593     goto out;
594     + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
595     + err = -EAGAIN; /* Hope less harmful than -EPERM. */
596     + goto out;
597     + }
598    
599     copied = skb->len;
600     if (len < copied) {
601 kumaneko 388 --- linux-6.1.82.orig/net/ipv4/udp.c
602     +++ linux-6.1.82/net/ipv4/udp.c
603     @@ -1839,6 +1839,8 @@ try_again:
604 kumaneko 373 skb = __skb_recv_udp(sk, flags, &off, &err);
605     if (!skb)
606     return err;
607     + if (ccs_socket_post_recvmsg_permission(sk, skb, flags))
608     + return -EAGAIN; /* Hope less harmful than -EPERM. */
609    
610     ulen = udp_skb_len(skb);
611     copied = len;
612 kumaneko 388 --- linux-6.1.82.orig/net/ipv6/raw.c
613     +++ linux-6.1.82/net/ipv6/raw.c
614 kumaneko 380 @@ -443,6 +443,10 @@ static int rawv6_recvmsg(struct sock *sk
615 kumaneko 373 skb = skb_recv_datagram(sk, flags, &err);
616     if (!skb)
617     goto out;
618     + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
619     + err = -EAGAIN; /* Hope less harmful than -EPERM. */
620     + goto out;
621     + }
622    
623     copied = skb->len;
624     if (copied > len) {
625 kumaneko 388 --- linux-6.1.82.orig/net/ipv6/udp.c
626     +++ linux-6.1.82/net/ipv6/udp.c
627 kumaneko 382 @@ -369,6 +369,8 @@ try_again:
628 kumaneko 373 skb = __skb_recv_udp(sk, flags, &off, &err);
629     if (!skb)
630     return err;
631     + if (ccs_socket_post_recvmsg_permission(sk, skb, flags))
632     + return -EAGAIN; /* Hope less harmful than -EPERM. */
633    
634     ulen = udp6_skb_len(skb);
635     copied = len;
636 kumaneko 388 --- linux-6.1.82.orig/net/socket.c
637     +++ linux-6.1.82/net/socket.c
638     @@ -1888,6 +1888,10 @@ struct file *do_accept(struct file *file
639 kumaneko 373 if (err < 0)
640     goto out_fd;
641    
642     + if (ccs_socket_post_accept_permission(sock, newsock)) {
643     + err = -EAGAIN; /* Hope less harmful than -EPERM. */
644     + goto out_fd;
645     + }
646     if (upeer_sockaddr) {
647     len = newsock->ops->getname(newsock,
648     (struct sockaddr *)&address, 2);
649 kumaneko 388 --- linux-6.1.82.orig/net/unix/af_unix.c
650     +++ linux-6.1.82/net/unix/af_unix.c
651     @@ -2474,6 +2474,10 @@ int __unix_dgram_recvmsg(struct sock *sk
652 kumaneko 373 EPOLLOUT | EPOLLWRNORM |
653     EPOLLWRBAND);
654    
655     + if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
656     + err = -EAGAIN; /* Hope less harmful than -EPERM. */
657     + goto out_unlock;
658     + }
659     if (msg->msg_name)
660     unix_copy_addr(msg, skb->sk);
661    
662 kumaneko 388 @@ -2524,6 +2528,7 @@ int __unix_dgram_recvmsg(struct sock *sk
663 kumaneko 373
664     out_free:
665     skb_free_datagram(sk, skb);
666     +out_unlock:
667     mutex_unlock(&u->iolock);
668     out:
669     return err;
670 kumaneko 388 --- linux-6.1.82.orig/security/Kconfig
671     +++ linux-6.1.82/security/Kconfig
672 kumaneko 373 @@ -260,5 +260,7 @@ config LSM
673    
674     source "security/Kconfig.hardening"
675    
676     +source "security/ccsecurity/Kconfig"
677     +
678     endmenu
679    
680 kumaneko 388 --- linux-6.1.82.orig/security/Makefile
681     +++ linux-6.1.82/security/Makefile
682 kumaneko 373 @@ -27,3 +27,6 @@ obj-$(CONFIG_SECURITY_LANDLOCK) += land
683    
684     # Object integrity file lists
685     obj-$(CONFIG_INTEGRITY) += integrity/
686     +
687     +subdir-$(CONFIG_CCSECURITY) += ccsecurity
688     +obj-$(CONFIG_CCSECURITY) += ccsecurity/
689 kumaneko 388 --- linux-6.1.82.orig/security/security.c
690     +++ linux-6.1.82/security/security.c
691     @@ -1691,7 +1691,9 @@ int security_task_alloc(struct task_stru
692 kumaneko 373
693     if (rc)
694     return rc;
695     - rc = call_int_hook(task_alloc, 0, task, clone_flags);
696     + rc = ccs_alloc_task_security(task);
697     + if (likely(!rc))
698     + rc = call_int_hook(task_alloc, 0, task, clone_flags);
699     if (unlikely(rc))
700     security_task_free(task);
701     return rc;
702 kumaneko 388 @@ -1700,6 +1702,7 @@ int security_task_alloc(struct task_stru
703 kumaneko 373 void security_task_free(struct task_struct *task)
704     {
705     call_void_hook(task_free, task);
706     + ccs_free_task_security(task);
707    
708     kfree(task->security);
709     task->security = NULL;

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