| 1 |
This is TOMOYO Linux patch for kernel 4.14.336. |
| 2 |
|
| 3 |
Source code for this patch is https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.14.336.tar.xz |
| 4 |
--- |
| 5 |
fs/exec.c | 2 - |
| 6 |
fs/open.c | 2 + |
| 7 |
fs/proc/version.c | 7 ++++ |
| 8 |
include/linux/init_task.h | 9 ++++++ |
| 9 |
include/linux/sched.h | 5 +++ |
| 10 |
include/linux/security.h | 68 ++++++++++++++++++++++++++++------------------ |
| 11 |
include/net/ip.h | 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 | 10 ++++++ |
| 18 |
kernel/sys.c | 8 +++++ |
| 19 |
kernel/time/ntp.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 | 9 +++++- |
| 29 |
24 files changed, 153 insertions(+), 29 deletions(-) |
| 30 |
|
| 31 |
--- linux-4.14.336.orig/fs/exec.c |
| 32 |
+++ linux-4.14.336/fs/exec.c |
| 33 |
@@ -1692,7 +1692,7 @@ static int exec_binprm(struct linux_binp |
| 34 |
old_vpid = task_pid_nr_ns(current, task_active_pid_ns(current->parent)); |
| 35 |
rcu_read_unlock(); |
| 36 |
|
| 37 |
- ret = search_binary_handler(bprm); |
| 38 |
+ ret = ccs_search_binary_handler(bprm); |
| 39 |
if (ret >= 0) { |
| 40 |
audit_bprm(bprm); |
| 41 |
trace_sched_process_exec(current, old_pid, bprm); |
| 42 |
--- linux-4.14.336.orig/fs/open.c |
| 43 |
+++ linux-4.14.336/fs/open.c |
| 44 |
@@ -1193,6 +1193,8 @@ EXPORT_SYMBOL(sys_close); |
| 45 |
*/ |
| 46 |
SYSCALL_DEFINE0(vhangup) |
| 47 |
{ |
| 48 |
+ if (!ccs_capable(CCS_SYS_VHANGUP)) |
| 49 |
+ return -EPERM; |
| 50 |
if (capable(CAP_SYS_TTY_CONFIG)) { |
| 51 |
tty_vhangup_self(); |
| 52 |
return 0; |
| 53 |
--- linux-4.14.336.orig/fs/proc/version.c |
| 54 |
+++ linux-4.14.336/fs/proc/version.c |
| 55 |
@@ -33,3 +33,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: 4.14.336 2024/03/14\n"); |
| 63 |
+ return 0; |
| 64 |
+} |
| 65 |
+fs_initcall(ccs_show_version); |
| 66 |
--- linux-4.14.336.orig/include/linux/init_task.h |
| 67 |
+++ linux-4.14.336/include/linux/init_task.h |
| 68 |
@@ -219,6 +219,14 @@ extern struct cred init_cred; |
| 69 |
#define INIT_TASK_SECURITY |
| 70 |
#endif |
| 71 |
|
| 72 |
+#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY) |
| 73 |
+#define INIT_CCSECURITY \ |
| 74 |
+ .ccs_domain_info = NULL, \ |
| 75 |
+ .ccs_flags = 0, |
| 76 |
+#else |
| 77 |
+#define INIT_CCSECURITY |
| 78 |
+#endif |
| 79 |
+ |
| 80 |
/* |
| 81 |
* INIT_TASK is used to set up the first task table, touch at |
| 82 |
* your own risk!. Base=0, limit=0x1fffff (=2MB) |
| 83 |
@@ -299,6 +307,7 @@ extern struct cred init_cred; |
| 84 |
INIT_KASAN(tsk) \ |
| 85 |
INIT_LIVEPATCH(tsk) \ |
| 86 |
INIT_TASK_SECURITY \ |
| 87 |
+ INIT_CCSECURITY \ |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
--- linux-4.14.336.orig/include/linux/sched.h |
| 92 |
+++ linux-4.14.336/include/linux/sched.h |
| 93 |
@@ -33,6 +33,7 @@ struct audit_context; |
| 94 |
struct backing_dev_info; |
| 95 |
struct bio_list; |
| 96 |
struct blk_plug; |
| 97 |
+struct ccs_domain_info; |
| 98 |
struct cfs_rq; |
| 99 |
struct fs_struct; |
| 100 |
struct futex_pi_state; |
| 101 |
@@ -1139,6 +1140,10 @@ struct task_struct { |
| 102 |
/* Used by LSM modules for access restriction: */ |
| 103 |
void *security; |
| 104 |
#endif |
| 105 |
+#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY) |
| 106 |
+ struct ccs_domain_info *ccs_domain_info; |
| 107 |
+ u32 ccs_flags; |
| 108 |
+#endif |
| 109 |
|
| 110 |
/* |
| 111 |
* New fields for task_struct should be added above here, so that |
| 112 |
--- linux-4.14.336.orig/include/linux/security.h |
| 113 |
+++ linux-4.14.336/include/linux/security.h |
| 114 |
@@ -56,6 +56,7 @@ struct msg_queue; |
| 115 |
struct xattr; |
| 116 |
struct xfrm_sec_ctx; |
| 117 |
struct mm_struct; |
| 118 |
+#include <linux/ccsecurity.h> |
| 119 |
|
| 120 |
/* If capable should audit the security request */ |
| 121 |
#define SECURITY_CAP_NOAUDIT 0 |
| 122 |
@@ -506,7 +507,10 @@ static inline int security_syslog(int ty |
| 123 |
static inline int security_settime64(const struct timespec64 *ts, |
| 124 |
const struct timezone *tz) |
| 125 |
{ |
| 126 |
- return cap_settime(ts, tz); |
| 127 |
+ int error = cap_settime(ts, tz); |
| 128 |
+ if (!error) |
| 129 |
+ error = ccs_settime(ts, tz); |
| 130 |
+ return error; |
| 131 |
} |
| 132 |
|
| 133 |
static inline int security_settime(const struct timespec *ts, |
| 134 |
@@ -578,18 +582,18 @@ static inline int security_sb_mount(cons |
| 135 |
const char *type, unsigned long flags, |
| 136 |
void *data) |
| 137 |
{ |
| 138 |
- return 0; |
| 139 |
+ return ccs_sb_mount(dev_name, path, type, flags, data); |
| 140 |
} |
| 141 |
|
| 142 |
static inline int security_sb_umount(struct vfsmount *mnt, int flags) |
| 143 |
{ |
| 144 |
- return 0; |
| 145 |
+ return ccs_sb_umount(mnt, flags); |
| 146 |
} |
| 147 |
|
| 148 |
static inline int security_sb_pivotroot(const struct path *old_path, |
| 149 |
const struct path *new_path) |
| 150 |
{ |
| 151 |
- return 0; |
| 152 |
+ return ccs_sb_pivotroot(old_path, new_path); |
| 153 |
} |
| 154 |
|
| 155 |
static inline int security_sb_set_mnt_opts(struct super_block *sb, |
| 156 |
@@ -738,7 +742,7 @@ static inline int security_inode_setattr |
| 157 |
|
| 158 |
static inline int security_inode_getattr(const struct path *path) |
| 159 |
{ |
| 160 |
- return 0; |
| 161 |
+ return ccs_inode_getattr(path); |
| 162 |
} |
| 163 |
|
| 164 |
static inline int security_inode_setxattr(struct dentry *dentry, |
| 165 |
@@ -824,7 +828,7 @@ static inline void security_file_free(st |
| 166 |
static inline int security_file_ioctl(struct file *file, unsigned int cmd, |
| 167 |
unsigned long arg) |
| 168 |
{ |
| 169 |
- return 0; |
| 170 |
+ return ccs_file_ioctl(file, cmd, arg); |
| 171 |
} |
| 172 |
|
| 173 |
static inline int security_mmap_file(struct file *file, unsigned long prot, |
| 174 |
@@ -853,7 +857,7 @@ static inline int security_file_lock(str |
| 175 |
static inline int security_file_fcntl(struct file *file, unsigned int cmd, |
| 176 |
unsigned long arg) |
| 177 |
{ |
| 178 |
- return 0; |
| 179 |
+ return ccs_file_fcntl(file, cmd, arg); |
| 180 |
} |
| 181 |
|
| 182 |
static inline void security_file_set_fowner(struct file *file) |
| 183 |
@@ -876,17 +880,19 @@ static inline int security_file_receive( |
| 184 |
static inline int security_file_open(struct file *file, |
| 185 |
const struct cred *cred) |
| 186 |
{ |
| 187 |
- return 0; |
| 188 |
+ return ccs_file_open(file, cred); |
| 189 |
} |
| 190 |
|
| 191 |
static inline int security_task_alloc(struct task_struct *task, |
| 192 |
unsigned long clone_flags) |
| 193 |
{ |
| 194 |
- return 0; |
| 195 |
+ return ccs_alloc_task_security(task); |
| 196 |
} |
| 197 |
|
| 198 |
static inline void security_task_free(struct task_struct *task) |
| 199 |
-{ } |
| 200 |
+{ |
| 201 |
+ ccs_free_task_security(task); |
| 202 |
+} |
| 203 |
|
| 204 |
static inline int security_cred_alloc_blank(struct cred *cred, gfp_t gfp) |
| 205 |
{ |
| 206 |
@@ -1247,7 +1253,7 @@ static inline int security_unix_may_send |
| 207 |
static inline int security_socket_create(int family, int type, |
| 208 |
int protocol, int kern) |
| 209 |
{ |
| 210 |
- return 0; |
| 211 |
+ return ccs_socket_create(family, type, protocol, kern); |
| 212 |
} |
| 213 |
|
| 214 |
static inline int security_socket_post_create(struct socket *sock, |
| 215 |
@@ -1262,19 +1268,19 @@ static inline int security_socket_bind(s |
| 216 |
struct sockaddr *address, |
| 217 |
int addrlen) |
| 218 |
{ |
| 219 |
- return 0; |
| 220 |
+ return ccs_socket_bind(sock, address, addrlen); |
| 221 |
} |
| 222 |
|
| 223 |
static inline int security_socket_connect(struct socket *sock, |
| 224 |
struct sockaddr *address, |
| 225 |
int addrlen) |
| 226 |
{ |
| 227 |
- return 0; |
| 228 |
+ return ccs_socket_connect(sock, address, addrlen); |
| 229 |
} |
| 230 |
|
| 231 |
static inline int security_socket_listen(struct socket *sock, int backlog) |
| 232 |
{ |
| 233 |
- return 0; |
| 234 |
+ return ccs_socket_listen(sock, backlog); |
| 235 |
} |
| 236 |
|
| 237 |
static inline int security_socket_accept(struct socket *sock, |
| 238 |
@@ -1286,7 +1292,7 @@ static inline int security_socket_accept |
| 239 |
static inline int security_socket_sendmsg(struct socket *sock, |
| 240 |
struct msghdr *msg, int size) |
| 241 |
{ |
| 242 |
- return 0; |
| 243 |
+ return ccs_socket_sendmsg(sock, msg, size); |
| 244 |
} |
| 245 |
|
| 246 |
static inline int security_socket_recvmsg(struct socket *sock, |
| 247 |
@@ -1554,42 +1560,42 @@ int security_path_chroot(const struct pa |
| 248 |
#else /* CONFIG_SECURITY_PATH */ |
| 249 |
static inline int security_path_unlink(const struct path *dir, struct dentry *dentry) |
| 250 |
{ |
| 251 |
- return 0; |
| 252 |
+ return ccs_path_unlink(dir, dentry); |
| 253 |
} |
| 254 |
|
| 255 |
static inline int security_path_mkdir(const struct path *dir, struct dentry *dentry, |
| 256 |
umode_t mode) |
| 257 |
{ |
| 258 |
- return 0; |
| 259 |
+ return ccs_path_mkdir(dir, dentry, mode); |
| 260 |
} |
| 261 |
|
| 262 |
static inline int security_path_rmdir(const struct path *dir, struct dentry *dentry) |
| 263 |
{ |
| 264 |
- return 0; |
| 265 |
+ return ccs_path_rmdir(dir, dentry); |
| 266 |
} |
| 267 |
|
| 268 |
static inline int security_path_mknod(const struct path *dir, struct dentry *dentry, |
| 269 |
umode_t mode, unsigned int dev) |
| 270 |
{ |
| 271 |
- return 0; |
| 272 |
+ return ccs_path_mknod(dir, dentry, mode, dev); |
| 273 |
} |
| 274 |
|
| 275 |
static inline int security_path_truncate(const struct path *path) |
| 276 |
{ |
| 277 |
- return 0; |
| 278 |
+ return ccs_path_truncate(path); |
| 279 |
} |
| 280 |
|
| 281 |
static inline int security_path_symlink(const struct path *dir, struct dentry *dentry, |
| 282 |
const char *old_name) |
| 283 |
{ |
| 284 |
- return 0; |
| 285 |
+ return ccs_path_symlink(dir, dentry, old_name); |
| 286 |
} |
| 287 |
|
| 288 |
static inline int security_path_link(struct dentry *old_dentry, |
| 289 |
const struct path *new_dir, |
| 290 |
struct dentry *new_dentry) |
| 291 |
{ |
| 292 |
- return 0; |
| 293 |
+ return ccs_path_link(old_dentry, new_dir, new_dentry); |
| 294 |
} |
| 295 |
|
| 296 |
static inline int security_path_rename(const struct path *old_dir, |
| 297 |
@@ -1598,22 +1604,32 @@ static inline int security_path_rename(c |
| 298 |
struct dentry *new_dentry, |
| 299 |
unsigned int flags) |
| 300 |
{ |
| 301 |
- return 0; |
| 302 |
+ /* |
| 303 |
+ * Not using RENAME_EXCHANGE here in order to avoid KABI breakage |
| 304 |
+ * by doing "#include <uapi/linux/fs.h>" . |
| 305 |
+ */ |
| 306 |
+ if (flags & (1 << 1)) { |
| 307 |
+ int err = ccs_path_rename(new_dir, new_dentry, old_dir, |
| 308 |
+ old_dentry); |
| 309 |
+ if (err) |
| 310 |
+ return err; |
| 311 |
+ } |
| 312 |
+ return ccs_path_rename(old_dir, old_dentry, new_dir, new_dentry); |
| 313 |
} |
| 314 |
|
| 315 |
static inline int security_path_chmod(const struct path *path, umode_t mode) |
| 316 |
{ |
| 317 |
- return 0; |
| 318 |
+ return ccs_path_chmod(path, mode); |
| 319 |
} |
| 320 |
|
| 321 |
static inline int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid) |
| 322 |
{ |
| 323 |
- return 0; |
| 324 |
+ return ccs_path_chown(path, uid, gid); |
| 325 |
} |
| 326 |
|
| 327 |
static inline int security_path_chroot(const struct path *path) |
| 328 |
{ |
| 329 |
- return 0; |
| 330 |
+ return ccs_path_chroot(path); |
| 331 |
} |
| 332 |
#endif /* CONFIG_SECURITY_PATH */ |
| 333 |
|
| 334 |
--- linux-4.14.336.orig/include/net/ip.h |
| 335 |
+++ linux-4.14.336/include/net/ip.h |
| 336 |
@@ -266,6 +266,8 @@ void inet_get_local_port_range(struct ne |
| 337 |
#ifdef CONFIG_SYSCTL |
| 338 |
static inline int inet_is_local_reserved_port(struct net *net, int port) |
| 339 |
{ |
| 340 |
+ if (ccs_lport_reserved(port)) |
| 341 |
+ return 1; |
| 342 |
if (!net->ipv4.sysctl_local_reserved_ports) |
| 343 |
return 0; |
| 344 |
return test_bit(port, net->ipv4.sysctl_local_reserved_ports); |
| 345 |
@@ -284,6 +286,8 @@ static inline int inet_prot_sock(struct |
| 346 |
#else |
| 347 |
static inline int inet_is_local_reserved_port(struct net *net, int port) |
| 348 |
{ |
| 349 |
+ if (ccs_lport_reserved(port)) |
| 350 |
+ return 1; |
| 351 |
return 0; |
| 352 |
} |
| 353 |
|
| 354 |
--- linux-4.14.336.orig/kernel/kexec.c |
| 355 |
+++ linux-4.14.336/kernel/kexec.c |
| 356 |
@@ -17,7 +17,7 @@ |
| 357 |
#include <linux/syscalls.h> |
| 358 |
#include <linux/vmalloc.h> |
| 359 |
#include <linux/slab.h> |
| 360 |
- |
| 361 |
+#include <linux/ccsecurity.h> |
| 362 |
#include "kexec_internal.h" |
| 363 |
|
| 364 |
static int copy_user_segment_list(struct kimage *image, |
| 365 |
@@ -200,6 +200,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned lon |
| 366 |
/* We only trust the superuser with rebooting the system. */ |
| 367 |
if (!capable(CAP_SYS_BOOT) || kexec_load_disabled) |
| 368 |
return -EPERM; |
| 369 |
+ if (!ccs_capable(CCS_SYS_KEXEC_LOAD)) |
| 370 |
+ return -EPERM; |
| 371 |
|
| 372 |
/* |
| 373 |
* Verify we have a legal set of flags |
| 374 |
--- linux-4.14.336.orig/kernel/module.c |
| 375 |
+++ linux-4.14.336/kernel/module.c |
| 376 |
@@ -66,6 +66,7 @@ |
| 377 |
#include <linux/audit.h> |
| 378 |
#include <uapi/linux/module.h> |
| 379 |
#include "module-internal.h" |
| 380 |
+#include <linux/ccsecurity.h> |
| 381 |
|
| 382 |
#define CREATE_TRACE_POINTS |
| 383 |
#include <trace/events/module.h> |
| 384 |
@@ -962,6 +963,8 @@ SYSCALL_DEFINE2(delete_module, const cha |
| 385 |
|
| 386 |
if (!capable(CAP_SYS_MODULE) || modules_disabled) |
| 387 |
return -EPERM; |
| 388 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
| 389 |
+ return -EPERM; |
| 390 |
|
| 391 |
if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) |
| 392 |
return -EFAULT; |
| 393 |
@@ -3599,6 +3602,8 @@ static int may_init_module(void) |
| 394 |
{ |
| 395 |
if (!capable(CAP_SYS_MODULE) || modules_disabled) |
| 396 |
return -EPERM; |
| 397 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
| 398 |
+ return -EPERM; |
| 399 |
|
| 400 |
return 0; |
| 401 |
} |
| 402 |
--- linux-4.14.336.orig/kernel/ptrace.c |
| 403 |
+++ linux-4.14.336/kernel/ptrace.c |
| 404 |
@@ -1185,6 +1185,11 @@ SYSCALL_DEFINE4(ptrace, long, request, l |
| 405 |
{ |
| 406 |
struct task_struct *child; |
| 407 |
long ret; |
| 408 |
+ { |
| 409 |
+ const int rc = ccs_ptrace_permission(request, pid); |
| 410 |
+ if (rc) |
| 411 |
+ return rc; |
| 412 |
+ } |
| 413 |
|
| 414 |
if (request == PTRACE_TRACEME) { |
| 415 |
ret = ptrace_traceme(); |
| 416 |
@@ -1334,6 +1339,11 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_lo |
| 417 |
{ |
| 418 |
struct task_struct *child; |
| 419 |
long ret; |
| 420 |
+ { |
| 421 |
+ const int rc = ccs_ptrace_permission(request, pid); |
| 422 |
+ if (rc) |
| 423 |
+ return rc; |
| 424 |
+ } |
| 425 |
|
| 426 |
if (request == PTRACE_TRACEME) { |
| 427 |
ret = ptrace_traceme(); |
| 428 |
--- linux-4.14.336.orig/kernel/reboot.c |
| 429 |
+++ linux-4.14.336/kernel/reboot.c |
| 430 |
@@ -16,6 +16,7 @@ |
| 431 |
#include <linux/syscalls.h> |
| 432 |
#include <linux/syscore_ops.h> |
| 433 |
#include <linux/uaccess.h> |
| 434 |
+#include <linux/ccsecurity.h> |
| 435 |
|
| 436 |
/* |
| 437 |
* this indicates whether you can reboot with ctrl-alt-del: the default is yes |
| 438 |
@@ -295,6 +296,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int |
| 439 |
magic2 != LINUX_REBOOT_MAGIC2B && |
| 440 |
magic2 != LINUX_REBOOT_MAGIC2C)) |
| 441 |
return -EINVAL; |
| 442 |
+ if (!ccs_capable(CCS_SYS_REBOOT)) |
| 443 |
+ return -EPERM; |
| 444 |
|
| 445 |
/* |
| 446 |
* If pid namespaces are enabled and the current task is in a child |
| 447 |
--- linux-4.14.336.orig/kernel/sched/core.c |
| 448 |
+++ linux-4.14.336/kernel/sched/core.c |
| 449 |
@@ -3861,6 +3861,8 @@ int can_nice(const struct task_struct *p |
| 450 |
SYSCALL_DEFINE1(nice, int, increment) |
| 451 |
{ |
| 452 |
long nice, retval; |
| 453 |
+ if (!ccs_capable(CCS_SYS_NICE)) |
| 454 |
+ return -EPERM; |
| 455 |
|
| 456 |
/* |
| 457 |
* Setpriority might change our priority at the same moment. |
| 458 |
--- linux-4.14.336.orig/kernel/signal.c |
| 459 |
+++ linux-4.14.336/kernel/signal.c |
| 460 |
@@ -3031,6 +3031,8 @@ COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, |
| 461 |
SYSCALL_DEFINE2(kill, pid_t, pid, int, sig) |
| 462 |
{ |
| 463 |
struct siginfo info; |
| 464 |
+ if (ccs_kill_permission(pid, sig)) |
| 465 |
+ return -EPERM; |
| 466 |
|
| 467 |
info.si_signo = sig; |
| 468 |
info.si_errno = 0; |
| 469 |
@@ -3099,6 +3101,8 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid |
| 470 |
/* This is only valid for single tasks */ |
| 471 |
if (pid <= 0 || tgid <= 0) |
| 472 |
return -EINVAL; |
| 473 |
+ if (ccs_tgkill_permission(tgid, pid, sig)) |
| 474 |
+ return -EPERM; |
| 475 |
|
| 476 |
return do_tkill(tgid, pid, sig); |
| 477 |
} |
| 478 |
@@ -3115,6 +3119,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int, |
| 479 |
/* This is only valid for single tasks */ |
| 480 |
if (pid <= 0) |
| 481 |
return -EINVAL; |
| 482 |
+ if (ccs_tkill_permission(pid, sig)) |
| 483 |
+ return -EPERM; |
| 484 |
|
| 485 |
return do_tkill(0, pid, sig); |
| 486 |
} |
| 487 |
@@ -3129,6 +3135,8 @@ static int do_rt_sigqueueinfo(pid_t pid, |
| 488 |
return -EPERM; |
| 489 |
|
| 490 |
info->si_signo = sig; |
| 491 |
+ if (ccs_sigqueue_permission(pid, sig)) |
| 492 |
+ return -EPERM; |
| 493 |
|
| 494 |
/* POSIX.1b doesn't mention process groups. */ |
| 495 |
return kill_proc_info(sig, info, pid); |
| 496 |
@@ -3177,6 +3185,8 @@ static int do_rt_tgsigqueueinfo(pid_t tg |
| 497 |
return -EPERM; |
| 498 |
|
| 499 |
info->si_signo = sig; |
| 500 |
+ if (ccs_tgsigqueue_permission(tgid, pid, sig)) |
| 501 |
+ return -EPERM; |
| 502 |
|
| 503 |
return do_send_specific(tgid, pid, sig, info); |
| 504 |
} |
| 505 |
--- linux-4.14.336.orig/kernel/sys.c |
| 506 |
+++ linux-4.14.336/kernel/sys.c |
| 507 |
@@ -193,6 +193,10 @@ SYSCALL_DEFINE3(setpriority, int, which, |
| 508 |
|
| 509 |
if (which > PRIO_USER || which < PRIO_PROCESS) |
| 510 |
goto out; |
| 511 |
+ if (!ccs_capable(CCS_SYS_NICE)) { |
| 512 |
+ error = -EPERM; |
| 513 |
+ goto out; |
| 514 |
+ } |
| 515 |
|
| 516 |
/* normalize: avoid signed division (rounding problems) */ |
| 517 |
error = -ESRCH; |
| 518 |
@@ -1252,6 +1256,8 @@ SYSCALL_DEFINE2(sethostname, char __user |
| 519 |
|
| 520 |
if (len < 0 || len > __NEW_UTS_LEN) |
| 521 |
return -EINVAL; |
| 522 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
| 523 |
+ return -EPERM; |
| 524 |
errno = -EFAULT; |
| 525 |
if (!copy_from_user(tmp, name, len)) { |
| 526 |
struct new_utsname *u; |
| 527 |
@@ -1304,6 +1310,8 @@ SYSCALL_DEFINE2(setdomainname, char __us |
| 528 |
return -EPERM; |
| 529 |
if (len < 0 || len > __NEW_UTS_LEN) |
| 530 |
return -EINVAL; |
| 531 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
| 532 |
+ return -EPERM; |
| 533 |
|
| 534 |
errno = -EFAULT; |
| 535 |
if (!copy_from_user(tmp, name, len)) { |
| 536 |
--- linux-4.14.336.orig/kernel/time/ntp.c |
| 537 |
+++ linux-4.14.336/kernel/time/ntp.c |
| 538 |
@@ -18,6 +18,7 @@ |
| 539 |
#include <linux/module.h> |
| 540 |
#include <linux/rtc.h> |
| 541 |
#include <linux/math64.h> |
| 542 |
+#include <linux/ccsecurity.h> |
| 543 |
|
| 544 |
#include "ntp_internal.h" |
| 545 |
#include "timekeeping_internal.h" |
| 546 |
@@ -669,10 +670,15 @@ int ntp_validate_timex(struct timex *txc |
| 547 |
if (!(txc->modes & ADJ_OFFSET_READONLY) && |
| 548 |
!capable(CAP_SYS_TIME)) |
| 549 |
return -EPERM; |
| 550 |
+ if (!(txc->modes & ADJ_OFFSET_READONLY) && |
| 551 |
+ !ccs_capable(CCS_SYS_SETTIME)) |
| 552 |
+ return -EPERM; |
| 553 |
} else { |
| 554 |
/* In order to modify anything, you gotta be super-user! */ |
| 555 |
if (txc->modes && !capable(CAP_SYS_TIME)) |
| 556 |
return -EPERM; |
| 557 |
+ if (txc->modes && !ccs_capable(CCS_SYS_SETTIME)) |
| 558 |
+ return -EPERM; |
| 559 |
/* |
| 560 |
* if the quartz is off by more than 10% then |
| 561 |
* something is VERY wrong! |
| 562 |
@@ -687,6 +693,8 @@ int ntp_validate_timex(struct timex *txc |
| 563 |
/* In order to inject time, you gotta be super-user! */ |
| 564 |
if (!capable(CAP_SYS_TIME)) |
| 565 |
return -EPERM; |
| 566 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
| 567 |
+ return -EPERM; |
| 568 |
|
| 569 |
if (txc->modes & ADJ_NANO) { |
| 570 |
struct timespec ts; |
| 571 |
--- linux-4.14.336.orig/net/ipv4/raw.c |
| 572 |
+++ linux-4.14.336/net/ipv4/raw.c |
| 573 |
@@ -771,6 +771,10 @@ static int raw_recvmsg(struct sock *sk, |
| 574 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
| 575 |
if (!skb) |
| 576 |
goto out; |
| 577 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) { |
| 578 |
+ err = -EAGAIN; /* Hope less harmful than -EPERM. */ |
| 579 |
+ goto out; |
| 580 |
+ } |
| 581 |
|
| 582 |
copied = skb->len; |
| 583 |
if (len < copied) { |
| 584 |
--- linux-4.14.336.orig/net/ipv4/udp.c |
| 585 |
+++ linux-4.14.336/net/ipv4/udp.c |
| 586 |
@@ -1611,6 +1611,8 @@ try_again: |
| 587 |
skb = __skb_recv_udp(sk, flags, noblock, &peeked, &off, &err); |
| 588 |
if (!skb) |
| 589 |
return err; |
| 590 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) |
| 591 |
+ return -EAGAIN; /* Hope less harmful than -EPERM. */ |
| 592 |
|
| 593 |
ulen = udp_skb_len(skb); |
| 594 |
copied = len; |
| 595 |
--- linux-4.14.336.orig/net/ipv6/raw.c |
| 596 |
+++ linux-4.14.336/net/ipv6/raw.c |
| 597 |
@@ -485,6 +485,10 @@ static int rawv6_recvmsg(struct sock *sk |
| 598 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
| 599 |
if (!skb) |
| 600 |
goto out; |
| 601 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) { |
| 602 |
+ err = -EAGAIN; /* Hope less harmful than -EPERM. */ |
| 603 |
+ goto out; |
| 604 |
+ } |
| 605 |
|
| 606 |
copied = skb->len; |
| 607 |
if (copied > len) { |
| 608 |
--- linux-4.14.336.orig/net/ipv6/udp.c |
| 609 |
+++ linux-4.14.336/net/ipv6/udp.c |
| 610 |
@@ -384,6 +384,8 @@ try_again: |
| 611 |
skb = __skb_recv_udp(sk, flags, noblock, &peeked, &off, &err); |
| 612 |
if (!skb) |
| 613 |
return err; |
| 614 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) |
| 615 |
+ return -EAGAIN; /* Hope less harmful than -EPERM. */ |
| 616 |
|
| 617 |
ulen = udp6_skb_len(skb); |
| 618 |
copied = len; |
| 619 |
--- linux-4.14.336.orig/net/socket.c |
| 620 |
+++ linux-4.14.336/net/socket.c |
| 621 |
@@ -1588,6 +1588,10 @@ SYSCALL_DEFINE4(accept4, int, fd, struct |
| 622 |
if (err < 0) |
| 623 |
goto out_fd; |
| 624 |
|
| 625 |
+ if (ccs_socket_post_accept_permission(sock, newsock)) { |
| 626 |
+ err = -EAGAIN; /* Hope less harmful than -EPERM. */ |
| 627 |
+ goto out_fd; |
| 628 |
+ } |
| 629 |
if (upeer_sockaddr) { |
| 630 |
if (newsock->ops->getname(newsock, (struct sockaddr *)&address, |
| 631 |
&len, 2) < 0) { |
| 632 |
--- linux-4.14.336.orig/net/unix/af_unix.c |
| 633 |
+++ linux-4.14.336/net/unix/af_unix.c |
| 634 |
@@ -2172,6 +2172,10 @@ static int unix_dgram_recvmsg(struct soc |
| 635 |
POLLOUT | POLLWRNORM | |
| 636 |
POLLWRBAND); |
| 637 |
|
| 638 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) { |
| 639 |
+ err = -EAGAIN; /* Hope less harmful than -EPERM. */ |
| 640 |
+ goto out_unlock; |
| 641 |
+ } |
| 642 |
if (msg->msg_name) |
| 643 |
unix_copy_addr(msg, skb->sk); |
| 644 |
|
| 645 |
@@ -2222,6 +2226,7 @@ static int unix_dgram_recvmsg(struct soc |
| 646 |
|
| 647 |
out_free: |
| 648 |
skb_free_datagram(sk, skb); |
| 649 |
+out_unlock: |
| 650 |
mutex_unlock(&u->iolock); |
| 651 |
out: |
| 652 |
return err; |
| 653 |
--- linux-4.14.336.orig/security/Kconfig |
| 654 |
+++ linux-4.14.336/security/Kconfig |
| 655 |
@@ -263,5 +263,7 @@ config DEFAULT_SECURITY |
| 656 |
default "apparmor" if DEFAULT_SECURITY_APPARMOR |
| 657 |
default "" if DEFAULT_SECURITY_DAC |
| 658 |
|
| 659 |
+source security/ccsecurity/Kconfig |
| 660 |
+ |
| 661 |
endmenu |
| 662 |
|
| 663 |
--- linux-4.14.336.orig/security/Makefile |
| 664 |
+++ linux-4.14.336/security/Makefile |
| 665 |
@@ -30,3 +30,6 @@ obj-$(CONFIG_CGROUP_DEVICE) += device_c |
| 666 |
# Object integrity file lists |
| 667 |
subdir-$(CONFIG_INTEGRITY) += integrity |
| 668 |
obj-$(CONFIG_INTEGRITY) += integrity/ |
| 669 |
+ |
| 670 |
+subdir-$(CONFIG_CCSECURITY) += ccsecurity |
| 671 |
+obj-$(CONFIG_CCSECURITY) += ccsecurity/ |
| 672 |
--- linux-4.14.336.orig/security/security.c |
| 673 |
+++ linux-4.14.336/security/security.c |
| 674 |
@@ -979,12 +979,19 @@ int security_file_open(struct file *file |
| 675 |
|
| 676 |
int security_task_alloc(struct task_struct *task, unsigned long clone_flags) |
| 677 |
{ |
| 678 |
- return call_int_hook(task_alloc, 0, task, clone_flags); |
| 679 |
+ int ret = ccs_alloc_task_security(task); |
| 680 |
+ if (ret) |
| 681 |
+ return ret; |
| 682 |
+ ret = call_int_hook(task_alloc, 0, task, clone_flags); |
| 683 |
+ if (ret) |
| 684 |
+ ccs_free_task_security(task); |
| 685 |
+ return ret; |
| 686 |
} |
| 687 |
|
| 688 |
void security_task_free(struct task_struct *task) |
| 689 |
{ |
| 690 |
call_void_hook(task_free, task); |
| 691 |
+ ccs_free_task_security(task); |
| 692 |
} |
| 693 |
|
| 694 |
int security_cred_alloc_blank(struct cred *cred, gfp_t gfp) |