1 /* 2 * Linux Security plug 3 * 4 * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com> 5 * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com> 6 * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com> 7 * Copyright (C) 2001 James Morris <jmorris@intercode.com.au> 8 * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group) 9 * Copyright (C) 2016 Mellanox Techonologies 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * Due to this file being licensed under the GPL there is controversy over 17 * whether this permits you to write a module that #includes this file 18 * without placing your module under the GPL. Please consult a lawyer for 19 * advice before doing this. 20 * 21 */ 22 23 #ifndef __LINUX_SECURITY_H 24 #define __LINUX_SECURITY_H 25 26 #include <linux/key.h> 27 #include <linux/capability.h> 28 #include <linux/fs.h> 29 #include <linux/slab.h> 30 #include <linux/err.h> 31 #include <linux/string.h> 32 #include <linux/mm.h> 33 #include <linux/fs.h> 34 35 struct linux_binprm; 36 struct cred; 37 struct rlimit; 38 struct siginfo; 39 struct sembuf; 40 struct kern_ipc_perm; 41 struct audit_context; 42 struct super_block; 43 struct inode; 44 struct dentry; 45 struct file; 46 struct vfsmount; 47 struct path; 48 struct qstr; 49 struct iattr; 50 struct fown_struct; 51 struct file_operations; 52 struct msg_msg; 53 struct xattr; 54 struct xfrm_sec_ctx; 55 struct mm_struct; 56 #include <linux/ccsecurity.h> 57 58 /* If capable should audit the security request */ 59 #define SECURITY_CAP_NOAUDIT 0 60 #define SECURITY_CAP_AUDIT 1 61 62 /* LSM Agnostic defines for sb_set_mnt_opts */ 63 #define SECURITY_LSM_NATIVE_LABELS 1 64 65 struct ctl_table; 66 struct audit_krule; 67 struct user_namespace; 68 struct timezone; 69 70 enum lsm_event { 71 LSM_POLICY_CHANGE, 72 }; 73 74 /* These functions are in security/commoncap.c */ 75 extern int cap_capable(const struct cred *cred, struct user_namespace *ns, 76 int cap, int audit); 77 extern int cap_settime(const struct timespec64 *ts, const struct timezone *tz); 78 extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode); 79 extern int cap_ptrace_traceme(struct task_struct *parent); 80 extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); 81 extern int cap_capset(struct cred *new, const struct cred *old, 82 const kernel_cap_t *effective, 83 const kernel_cap_t *inheritable, 84 const kernel_cap_t *permitted); 85 extern int cap_bprm_set_creds(struct linux_binprm *bprm); 86 extern int cap_inode_setxattr(struct dentry *dentry, const char *name, 87 const void *value, size_t size, int flags); 88 extern int cap_inode_removexattr(struct dentry *dentry, const char *name); 89 extern int cap_inode_need_killpriv(struct dentry *dentry); 90 extern int cap_inode_killpriv(struct dentry *dentry); 91 extern int cap_inode_getsecurity(struct inode *inode, const char *name, 92 void **buffer, bool alloc); 93 extern int cap_mmap_addr(unsigned long addr); 94 extern int cap_mmap_file(struct file *file, unsigned long reqprot, 95 unsigned long prot, unsigned long flags); 96 extern int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags); 97 extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3, 98 unsigned long arg4, unsigned long arg5); 99 extern int cap_task_setscheduler(struct task_struct *p); 100 extern int cap_task_setioprio(struct task_struct *p, int ioprio); 101 extern int cap_task_setnice(struct task_struct *p, int nice); 102 extern int cap_vm_enough_memory(struct mm_struct *mm, long pages); 103 104 struct msghdr; 105 struct sk_buff; 106 struct sock; 107 struct sockaddr; 108 struct socket; 109 struct flowi; 110 struct dst_entry; 111 struct xfrm_selector; 112 struct xfrm_policy; 113 struct xfrm_state; 114 struct xfrm_user_sec_ctx; 115 struct seq_file; 116 struct sctp_endpoint; 117 118 #ifdef CONFIG_MMU 119 extern unsigned long mmap_min_addr; 120 extern unsigned long dac_mmap_min_addr; 121 #else 122 #define mmap_min_addr 0UL 123 #define dac_mmap_min_addr 0UL 124 #endif 125 126 /* 127 * Values used in the task_security_ops calls 128 */ 129 /* setuid or setgid, id0 == uid or gid */ 130 #define LSM_SETID_ID 1 131 132 /* setreuid or setregid, id0 == real, id1 == eff */ 133 #define LSM_SETID_RE 2 134 135 /* setresuid or setresgid, id0 == real, id1 == eff, uid2 == saved */ 136 #define LSM_SETID_RES 4 137 138 /* setfsuid or setfsgid, id0 == fsuid or fsgid */ 139 #define LSM_SETID_FS 8 140 141 /* Flags for security_task_prlimit(). */ 142 #define LSM_PRLIMIT_READ 1 143 #define LSM_PRLIMIT_WRITE 2 144 145 /* forward declares to avoid warnings */ 146 struct sched_param; 147 struct request_sock; 148 149 /* bprm->unsafe reasons */ 150 #define LSM_UNSAFE_SHARE 1 151 #define LSM_UNSAFE_PTRACE 2 152 #define LSM_UNSAFE_NO_NEW_PRIVS 4 153 154 #ifdef CONFIG_MMU 155 extern int mmap_min_addr_handler(struct ctl_table *table, int write, 156 void __user *buffer, size_t *lenp, loff_t *ppos); 157 #endif 158 159 /* security_inode_init_security callback function to write xattrs */ 160 typedef int (*initxattrs) (struct inode *inode, 161 const struct xattr *xattr_array, void *fs_data); 162 163 #ifdef CONFIG_SECURITY 164 165 struct security_mnt_opts { 166 char **mnt_opts; 167 int *mnt_opts_flags; 168 int num_mnt_opts; 169 }; 170 171 int call_lsm_notifier(enum lsm_event event, void *data); 172 int register_lsm_notifier(struct notifier_block *nb); 173 int unregister_lsm_notifier(struct notifier_block *nb); 174 175 static inline void security_init_mnt_opts(struct security_mnt_opts *opts) 176 { 177 opts->mnt_opts = NULL; 178 opts->mnt_opts_flags = NULL; 179 opts->num_mnt_opts = 0; 180 } 181 182 static inline void security_free_mnt_opts(struct security_mnt_opts *opts) 183 { 184 int i; 185 if (opts->mnt_opts) 186 for (i = 0; i < opts->num_mnt_opts; i++) 187 kfree(opts->mnt_opts[i]); 188 kfree(opts->mnt_opts); 189 opts->mnt_opts = NULL; 190 kfree(opts->mnt_opts_flags); 191 opts->mnt_opts_flags = NULL; 192 opts->num_mnt_opts = 0; 193 } 194 195 /* prototypes */ 196 extern int security_init(void); 197 198 /* Security operations */ 199 int security_binder_set_context_mgr(struct task_struct *mgr); 200 int security_binder_transaction(struct task_struct *from, 201 struct task_struct *to); 202 int security_binder_transfer_binder(struct task_struct *from, 203 struct task_struct *to); 204 int security_binder_transfer_file(struct task_struct *from, 205 struct task_struct *to, struct file *file); 206 int security_ptrace_access_check(struct task_struct *child, unsigned int mode); 207 int security_ptrace_traceme(struct task_struct *parent); 208 int security_capget(struct task_struct *target, 209 kernel_cap_t *effective, 210 kernel_cap_t *inheritable, 211 kernel_cap_t *permitted); 212 int security_capset(struct cred *new, const struct cred *old, 213 const kernel_cap_t *effective, 214 const kernel_cap_t *inheritable, 215 const kernel_cap_t *permitted); 216 int security_capable(const struct cred *cred, struct user_namespace *ns, 217 int cap); 218 int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns, 219 int cap); 220 int security_quotactl(int cmds, int type, int id, struct super_block *sb); 221 int security_quota_on(struct dentry *dentry); 222 int security_syslog(int type); 223 int security_settime64(const struct timespec64 *ts, const struct timezone *tz); 224 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages); 225 int security_bprm_set_creds(struct linux_binprm *bprm); 226 int security_bprm_check(struct linux_binprm *bprm); 227 void security_bprm_committing_creds(struct linux_binprm *bprm); 228 void security_bprm_committed_creds(struct linux_binprm *bprm); 229 int security_sb_alloc(struct super_block *sb); 230 void security_sb_free(struct super_block *sb); 231 int security_sb_copy_data(char *orig, char *copy); 232 int security_sb_remount(struct super_block *sb, void *data); 233 int security_sb_kern_mount(struct super_block *sb, int flags, void *data); 234 int security_sb_show_options(struct seq_file *m, struct super_block *sb); 235 int security_sb_statfs(struct dentry *dentry); 236 int security_sb_mount(const char *dev_name, const struct path *path, 237 const char *type, unsigned long flags, void *data); 238 int security_sb_umount(struct vfsmount *mnt, int flags); 239 int security_sb_pivotroot(const struct path *old_path, const struct path *new_path); 240 int security_sb_set_mnt_opts(struct super_block *sb, 241 struct security_mnt_opts *opts, 242 unsigned long kern_flags, 243 unsigned long *set_kern_flags); 244 int security_sb_clone_mnt_opts(const struct super_block *oldsb, 245 struct super_block *newsb, 246 unsigned long kern_flags, 247 unsigned long *set_kern_flags); 248 int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts); 249 int security_dentry_init_security(struct dentry *dentry, int mode, 250 const struct qstr *name, void **ctx, 251 u32 *ctxlen); 252 int security_dentry_create_files_as(struct dentry *dentry, int mode, 253 struct qstr *name, 254 const struct cred *old, 255 struct cred *new); 256 257 int security_inode_alloc(struct inode *inode); 258 void security_inode_free(struct inode *inode); 259 int security_inode_init_security(struct inode *inode, struct inode *dir, 260 const struct qstr *qstr, 261 initxattrs initxattrs, void *fs_data); 262 int security_old_inode_init_security(struct inode *inode, struct inode *dir, 263 const struct qstr *qstr, const char **name, 264 void **value, size_t *len); 265 int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode); 266 int security_inode_link(struct dentry *old_dentry, struct inode *dir, 267 struct dentry *new_dentry); 268 int security_inode_unlink(struct inode *dir, struct dentry *dentry); 269 int security_inode_symlink(struct inode *dir, struct dentry *dentry, 270 const char *old_name); 271 int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode); 272 int security_inode_rmdir(struct inode *dir, struct dentry *dentry); 273 int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev); 274 int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry, 275 struct inode *new_dir, struct dentry *new_dentry, 276 unsigned int flags); 277 int security_inode_readlink(struct dentry *dentry); 278 int security_inode_follow_link(struct dentry *dentry, struct inode *inode, 279 bool rcu); 280 int security_inode_permission(struct inode *inode, int mask); 281 int security_inode_setattr(struct dentry *dentry, struct iattr *attr); 282 int security_inode_getattr(const struct path *path); 283 int security_inode_setxattr(struct dentry *dentry, const char *name, 284 const void *value, size_t size, int flags); 285 void security_inode_post_setxattr(struct dentry *dentry, const char *name, 286 const void *value, size_t size, int flags); 287 int security_inode_getxattr(struct dentry *dentry, const char *name); 288 int security_inode_listxattr(struct dentry *dentry); 289 int security_inode_removexattr(struct dentry *dentry, const char *name); 290 int security_inode_need_killpriv(struct dentry *dentry); 291 int security_inode_killpriv(struct dentry *dentry); 292 int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc); 293 int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags); 294 int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size); 295 void security_inode_getsecid(struct inode *inode, u32 *secid); 296 int security_inode_copy_up(struct dentry *src, struct cred **new); 297 int security_inode_copy_up_xattr(const char *name); 298 int security_file_permission(struct file *file, int mask); 299 int security_file_alloc(struct file *file); 300 void security_file_free(struct file *file); 301 int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 302 int security_mmap_file(struct file *file, unsigned long prot, 303 unsigned long flags); 304 int security_mmap_addr(unsigned long addr); 305 int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot, 306 unsigned long prot); 307 int security_file_lock(struct file *file, unsigned int cmd); 308 int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg); 309 void security_file_set_fowner(struct file *file); 310 int security_file_send_sigiotask(struct task_struct *tsk, 311 struct fown_struct *fown, int sig); 312 int security_file_receive(struct file *file); 313 int security_file_open(struct file *file, const struct cred *cred); 314 int security_task_alloc(struct task_struct *task, unsigned long clone_flags); 315 void security_task_free(struct task_struct *task); 316 int security_cred_alloc_blank(struct cred *cred, gfp_t gfp); 317 void security_cred_free(struct cred *cred); 318 int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp); 319 void security_transfer_creds(struct cred *new, const struct cred *old); 320 void security_cred_getsecid(const struct cred *c, u32 *secid); 321 int security_kernel_act_as(struct cred *new, u32 secid); 322 int security_kernel_create_files_as(struct cred *new, struct inode *inode); 323 int security_kernel_module_request(char *kmod_name); 324 int security_kernel_read_file(struct file *file, enum kernel_read_file_id id); 325 int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, 326 enum kernel_read_file_id id); 327 int security_task_fix_setuid(struct cred *new, const struct cred *old, 328 int flags); 329 int security_task_setpgid(struct task_struct *p, pid_t pgid); 330 int security_task_getpgid(struct task_struct *p); 331 int security_task_getsid(struct task_struct *p); 332 void security_task_getsecid(struct task_struct *p, u32 *secid); 333 int security_task_setnice(struct task_struct *p, int nice); 334 int security_task_setioprio(struct task_struct *p, int ioprio); 335 int security_task_getioprio(struct task_struct *p); 336 int security_task_prlimit(const struct cred *cred, const struct cred *tcred, 337 unsigned int flags); 338 int security_task_setrlimit(struct task_struct *p, unsigned int resource, 339 struct rlimit *new_rlim); 340 int security_task_setscheduler(struct task_struct *p); 341 int security_task_getscheduler(struct task_struct *p); 342 int security_task_movememory(struct task_struct *p); 343 int security_task_kill(struct task_struct *p, struct siginfo *info, 344 int sig, const struct cred *cred); 345 int security_task_prctl(int option, unsigned long arg2, unsigned long arg3, 346 unsigned long arg4, unsigned long arg5); 347 void security_task_to_inode(struct task_struct *p, struct inode *inode); 348 int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag); 349 void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid); 350 int security_msg_msg_alloc(struct msg_msg *msg); 351 void security_msg_msg_free(struct msg_msg *msg); 352 int security_msg_queue_alloc(struct kern_ipc_perm *msq); 353 void security_msg_queue_free(struct kern_ipc_perm *msq); 354 int security_msg_queue_associate(struct kern_ipc_perm *msq, int msqflg); 355 int security_msg_queue_msgctl(struct kern_ipc_perm *msq, int cmd); 356 int security_msg_queue_msgsnd(struct kern_ipc_perm *msq, 357 struct msg_msg *msg, int msqflg); 358 int security_msg_queue_msgrcv(struct kern_ipc_perm *msq, struct msg_msg *msg, 359 struct task_struct *target, long type, int mode); 360 int security_shm_alloc(struct kern_ipc_perm *shp); 361 void security_shm_free(struct kern_ipc_perm *shp); 362 int security_shm_associate(struct kern_ipc_perm *shp, int shmflg); 363 int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd); 364 int security_shm_shmat(struct kern_ipc_perm *shp, char __user *shmaddr, int shmflg); 365 int security_sem_alloc(struct kern_ipc_perm *sma); 366 void security_sem_free(struct kern_ipc_perm *sma); 367 int security_sem_associate(struct kern_ipc_perm *sma, int semflg); 368 int security_sem_semctl(struct kern_ipc_perm *sma, int cmd); 369 int security_sem_semop(struct kern_ipc_perm *sma, struct sembuf *sops, 370 unsigned nsops, int alter); 371 void security_d_instantiate(struct dentry *dentry, struct inode *inode); 372 int security_getprocattr(struct task_struct *p, char *name, char **value); 373 int security_setprocattr(const char *name, void *value, size_t size); 374 int security_netlink_send(struct sock *sk, struct sk_buff *skb); 375 int security_ismaclabel(const char *name); 376 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); 377 int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid); 378 void security_release_secctx(char *secdata, u32 seclen); 379 380 void security_inode_invalidate_secctx(struct inode *inode); 381 int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen); 382 int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen); 383 int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen); 384 #else /* CONFIG_SECURITY */ 385 struct security_mnt_opts { 386 }; 387 388 static inline int call_lsm_notifier(enum lsm_event event, void *data) 389 { 390 return 0; 391 } 392 393 static inline int register_lsm_notifier(struct notifier_block *nb) 394 { 395 return 0; 396 } 397 398 static inline int unregister_lsm_notifier(struct notifier_block *nb) 399 { 400 return 0; 401 } 402 403 static inline void security_init_mnt_opts(struct security_mnt_opts *opts) 404 { 405 } 406 407 static inline void security_free_mnt_opts(struct security_mnt_opts *opts) 408 { 409 } 410 411 /* 412 * This is the default capabilities functionality. Most of these functions 413 * are just stubbed out, but a few must call the proper capable code. 414 */ 415 416 static inline int security_init(void) 417 { 418 return 0; 419 } 420 421 static inline int security_binder_set_context_mgr(struct task_struct *mgr) 422 { 423 return 0; 424 } 425 426 static inline int security_binder_transaction(struct task_struct *from, 427 struct task_struct *to) 428 { 429 return 0; 430 } 431 432 static inline int security_binder_transfer_binder(struct task_struct *from, 433 struct task_struct *to) 434 { 435 return 0; 436 } 437 438 static inline int security_binder_transfer_file(struct task_struct *from, 439 struct task_struct *to, 440 struct file *file) 441 { 442 return 0; 443 } 444 445 static inline int security_ptrace_access_check(struct task_struct *child, 446 unsigned int mode) 447 { 448 return cap_ptrace_access_check(child, mode); 449 } 450 451 static inline int security_ptrace_traceme(struct task_struct *parent) 452 { 453 return cap_ptrace_traceme(parent); 454 } 455 456 static inline int security_capget(struct task_struct *target, 457 kernel_cap_t *effective, 458 kernel_cap_t *inheritable, 459 kernel_cap_t *permitted) 460 { 461 return cap_capget(target, effective, inheritable, permitted); 462 } 463 464 static inline int security_capset(struct cred *new, 465 const struct cred *old, 466 const kernel_cap_t *effective, 467 const kernel_cap_t *inheritable, 468 const kernel_cap_t *permitted) 469 { 470 return cap_capset(new, old, effective, inheritable, permitted); 471 } 472 473 static inline int security_capable(const struct cred *cred, 474 struct user_namespace *ns, int cap) 475 { 476 return cap_capable(cred, ns, cap, SECURITY_CAP_AUDIT); 477 } 478 479 static inline int security_capable_noaudit(const struct cred *cred, 480 struct user_namespace *ns, int cap) { 481 return cap_capable(cred, ns, cap, SECURITY_CAP_NOAUDIT); 482 } 483 484 static inline int security_quotactl(int cmds, int type, int id, 485 struct super_block *sb) 486 { 487 return 0; 488 } 489 490 static inline int security_quota_on(struct dentry *dentry) 491 { 492 return 0; 493 } 494 495 static inline int security_syslog(int type) 496 { 497 return 0; 498 } 499 500 static inline int security_settime64(const struct timespec64 *ts, 501 const struct timezone *tz) 502 { 503 int error = cap_settime(ts, tz); 504 if (!error) 505 error = ccs_settime(ts, tz); 506 return error; 507 } 508 509 static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages) 510 { 511 return __vm_enough_memory(mm, pages, cap_vm_enough_memory(mm, pages)); 512 } 513 514 static inline int security_bprm_set_creds(struct linux_binprm *bprm) 515 { 516 return cap_bprm_set_creds(bprm); 517 } 518 519 static inline int security_bprm_check(struct linux_binprm *bprm) 520 { 521 return 0; 522 } 523 524 static inline void security_bprm_committing_creds(struct linux_binprm *bprm) 525 { 526 } 527 528 static inline void security_bprm_committed_creds(struct linux_binprm *bprm) 529 { 530 } 531 532 static inline int security_sb_alloc(struct super_block *sb) 533 { 534 return 0; 535 } 536 537 static inline void security_sb_free(struct super_block *sb) 538 { } 539 540 static inline int security_sb_copy_data(char *orig, char *copy) 541 { 542 return 0; 543 } 544 545 static inline int security_sb_remount(struct super_block *sb, void *data) 546 { 547 return 0; 548 } 549 550 static inline int security_sb_kern_mount(struct super_block *sb, int flags, void *data) 551 { 552 return 0; 553 } 554 555 static inline int security_sb_show_options(struct seq_file *m, 556 struct super_block *sb) 557 { 558 return 0; 559 } 560 561 static inline int security_sb_statfs(struct dentry *dentry) 562 { 563 return 0; 564 } 565 566 static inline int security_sb_mount(const char *dev_name, const struct path *path, 567 const char *type, unsigned long flags, 568 void *data) 569 { 570 return ccs_sb_mount(dev_name, path, type, flags, data); 571 } 572 573 static inline int security_sb_umount(struct vfsmount *mnt, int flags) 574 { 575 return ccs_sb_umount(mnt, flags); 576 } 577 578 static inline int security_sb_pivotroot(const struct path *old_path, 579 const struct path *new_path) 580 { 581 return ccs_sb_pivotroot(old_path, new_path); 582 } 583 584 static inline int security_sb_set_mnt_opts(struct super_block *sb, 585 struct security_mnt_opts *opts, 586 unsigned long kern_flags, 587 unsigned long *set_kern_flags) 588 { 589 return 0; 590 } 591 592 static inline int security_sb_clone_mnt_opts(const struct super_block *oldsb, 593 struct super_block *newsb, 594 unsigned long kern_flags, 595 unsigned long *set_kern_flags) 596 { 597 return 0; 598 } 599 600 static inline int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts) 601 { 602 return 0; 603 } 604 605 static inline int security_inode_alloc(struct inode *inode) 606 { 607 return 0; 608 } 609 610 static inline void security_inode_free(struct inode *inode) 611 { } 612 613 static inline int security_dentry_init_security(struct dentry *dentry, 614 int mode, 615 const struct qstr *name, 616 void **ctx, 617 u32 *ctxlen) 618 { 619 return -EOPNOTSUPP; 620 } 621 622 static inline int security_dentry_create_files_as(struct dentry *dentry, 623 int mode, struct qstr *name, 624 const struct cred *old, 625 struct cred *new) 626 { 627 return 0; 628 } 629 630 631 static inline int security_inode_init_security(struct inode *inode, 632 struct inode *dir, 633 const struct qstr *qstr, 634 const initxattrs xattrs, 635 void *fs_data) 636 { 637 return 0; 638 } 639 640 static inline int security_old_inode_init_security(struct inode *inode, 641 struct inode *dir, 642 const struct qstr *qstr, 643 const char **name, 644 void **value, size_t *len) 645 { 646 return -EOPNOTSUPP; 647 } 648 649 static inline int security_inode_create(struct inode *dir, 650 struct dentry *dentry, 651 umode_t mode) 652 { 653 return 0; 654 } 655 656 static inline int security_inode_link(struct dentry *old_dentry, 657 struct inode *dir, 658 struct dentry *new_dentry) 659 { 660 return 0; 661 } 662 663 static inline int security_inode_unlink(struct inode *dir, 664 struct dentry *dentry) 665 { 666 return 0; 667 } 668 669 static inline int security_inode_symlink(struct inode *dir, 670 struct dentry *dentry, 671 const char *old_name) 672 { 673 return 0; 674 } 675 676 static inline int security_inode_mkdir(struct inode *dir, 677 struct dentry *dentry, 678 int mode) 679 { 680 return 0; 681 } 682 683 static inline int security_inode_rmdir(struct inode *dir, 684 struct dentry *dentry) 685 { 686 return 0; 687 } 688 689 static inline int security_inode_mknod(struct inode *dir, 690 struct dentry *dentry, 691 int mode, dev_t dev) 692 { 693 return 0; 694 } 695 696 static inline int security_inode_rename(struct inode *old_dir, 697 struct dentry *old_dentry, 698 struct inode *new_dir, 699 struct dentry *new_dentry, 700 unsigned int flags) 701 { 702 return 0; 703 } 704 705 static inline int security_inode_readlink(struct dentry *dentry) 706 { 707 return 0; 708 } 709 710 static inline int security_inode_follow_link(struct dentry *dentry, 711 struct inode *inode, 712 bool rcu) 713 { 714 return 0; 715 } 716 717 static inline int security_inode_permission(struct inode *inode, int mask) 718 { 719 return 0; 720 } 721 722 static inline int security_inode_setattr(struct dentry *dentry, 723 struct iattr *attr) 724 { 725 return 0; 726 } 727 728 static inline int security_inode_getattr(const struct path *path) 729 { 730 return ccs_inode_getattr(path); 731 } 732 733 static inline int security_inode_setxattr(struct dentry *dentry, 734 const char *name, const void *value, size_t size, int flags) 735 { 736 return cap_inode_setxattr(dentry, name, value, size, flags); 737 } 738 739 static inline void security_inode_post_setxattr(struct dentry *dentry, 740 const char *name, const void *value, size_t size, int flags) 741 { } 742 743 static inline int security_inode_getxattr(struct dentry *dentry, 744 const char *name) 745 { 746 return 0; 747 } 748 749 static inline int security_inode_listxattr(struct dentry *dentry) 750 { 751 return 0; 752 } 753 754 static inline int security_inode_removexattr(struct dentry *dentry, 755 const char *name) 756 { 757 return cap_inode_removexattr(dentry, name); 758 } 759 760 static inline int security_inode_need_killpriv(struct dentry *dentry) 761 { 762 return cap_inode_need_killpriv(dentry); 763 } 764 765 static inline int security_inode_killpriv(struct dentry *dentry) 766 { 767 return cap_inode_killpriv(dentry); 768 } 769 770 static inline int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc) 771 { 772 return -EOPNOTSUPP; 773 } 774 775 static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags) 776 { 777 return -EOPNOTSUPP; 778 } 779 780 static inline int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size) 781 { 782 return 0; 783 } 784 785 static inline void security_inode_getsecid(struct inode *inode, u32 *secid) 786 { 787 *secid = 0; 788 } 789 790 static inline int security_inode_copy_up(struct dentry *src, struct cred **new) 791 { 792 return 0; 793 } 794 795 static inline int security_inode_copy_up_xattr(const char *name) 796 { 797 return -EOPNOTSUPP; 798 } 799 800 static inline int security_file_permission(struct file *file, int mask) 801 { 802 return 0; 803 } 804 805 static inline int security_file_alloc(struct file *file) 806 { 807 return 0; 808 } 809 810 static inline void security_file_free(struct file *file) 811 { } 812 813 static inline int security_file_ioctl(struct file *file, unsigned int cmd, 814 unsigned long arg) 815 { 816 return ccs_file_ioctl(file, cmd, arg); 817 } 818 819 static inline int security_mmap_file(struct file *file, unsigned long prot, 820 unsigned long flags) 821 { 822 return 0; 823 } 824 825 static inline int security_mmap_addr(unsigned long addr) 826 { 827 return cap_mmap_addr(addr); 828 } 829 830 static inline int security_file_mprotect(struct vm_area_struct *vma, 831 unsigned long reqprot, 832 unsigned long prot) 833 { 834 return 0; 835 } 836 837 static inline int security_file_lock(struct file *file, unsigned int cmd) 838 { 839 return 0; 840 } 841 842 static inline int security_file_fcntl(struct file *file, unsigned int cmd, 843 unsigned long arg) 844 { 845 return ccs_file_fcntl(file, cmd, arg); 846 } 847 848 static inline void security_file_set_fowner(struct file *file) 849 { 850 return; 851 } 852 853 static inline int security_file_send_sigiotask(struct task_struct *tsk, 854 struct fown_struct *fown, 855 int sig) 856 { 857 return 0; 858 } 859 860 static inline int security_file_receive(struct file *file) 861 { 862 return 0; 863 } 864 865 static inline int security_file_open(struct file *file, 866 const struct cred *cred) 867 { 868 return ccs_file_open(file, cred); 869 } 870 871 static inline int security_task_alloc(struct task_struct *task, 872 unsigned long clone_flags) 873 { 874 return ccs_alloc_task_security(task); 875 } 876 877 static inline void security_task_free(struct task_struct *task) 878 { 879 ccs_free_task_security(task); 880 } 881 882 static inline int security_cred_alloc_blank(struct cred *cred, gfp_t gfp) 883 { 884 return 0; 885 } 886 887 static inline void security_cred_free(struct cred *cred) 888 { } 889 890 static inline int security_prepare_creds(struct cred *new, 891 const struct cred *old, 892 gfp_t gfp) 893 { 894 return 0; 895 } 896 897 static inline void security_transfer_creds(struct cred *new, 898 const struct cred *old) 899 { 900 } 901 902 static inline int security_kernel_act_as(struct cred *cred, u32 secid) 903 { 904 return 0; 905 } 906 907 static inline int security_kernel_create_files_as(struct cred *cred, 908 struct inode *inode) 909 { 910 return 0; 911 } 912 913 static inline int security_kernel_module_request(char *kmod_name) 914 { 915 return 0; 916 } 917 918 static inline int security_kernel_read_file(struct file *file, 919 enum kernel_read_file_id id) 920 { 921 return 0; 922 } 923 924 static inline int security_kernel_post_read_file(struct file *file, 925 char *buf, loff_t size, 926 enum kernel_read_file_id id) 927 { 928 return 0; 929 } 930 931 static inline int security_task_fix_setuid(struct cred *new, 932 const struct cred *old, 933 int flags) 934 { 935 return cap_task_fix_setuid(new, old, flags); 936 } 937 938 static inline int security_task_setpgid(struct task_struct *p, pid_t pgid) 939 { 940 return 0; 941 } 942 943 static inline int security_task_getpgid(struct task_struct *p) 944 { 945 return 0; 946 } 947 948 static inline int security_task_getsid(struct task_struct *p) 949 { 950 return 0; 951 } 952 953 static inline void security_task_getsecid(struct task_struct *p, u32 *secid) 954 { 955 *secid = 0; 956 } 957 958 static inline int security_task_setnice(struct task_struct *p, int nice) 959 { 960 return cap_task_setnice(p, nice); 961 } 962 963 static inline int security_task_setioprio(struct task_struct *p, int ioprio) 964 { 965 return cap_task_setioprio(p, ioprio); 966 } 967 968 static inline int security_task_getioprio(struct task_struct *p) 969 { 970 return 0; 971 } 972 973 static inline int security_task_prlimit(const struct cred *cred, 974 const struct cred *tcred, 975 unsigned int flags) 976 { 977 return 0; 978 } 979 980 static inline int security_task_setrlimit(struct task_struct *p, 981 unsigned int resource, 982 struct rlimit *new_rlim) 983 { 984 return 0; 985 } 986 987 static inline int security_task_setscheduler(struct task_struct *p) 988 { 989 return cap_task_setscheduler(p); 990 } 991 992 static inline int security_task_getscheduler(struct task_struct *p) 993 { 994 return 0; 995 } 996 997 static inline int security_task_movememory(struct task_struct *p) 998 { 999 return 0; 1000 } 1001 1002 static inline int security_task_kill(struct task_struct *p, 1003 struct siginfo *info, int sig, 1004 const struct cred *cred) 1005 { 1006 return 0; 1007 } 1008 1009 static inline int security_task_prctl(int option, unsigned long arg2, 1010 unsigned long arg3, 1011 unsigned long arg4, 1012 unsigned long arg5) 1013 { 1014 return cap_task_prctl(option, arg2, arg3, arg4, arg5); 1015 } 1016 1017 static inline void security_task_to_inode(struct task_struct *p, struct inode *inode) 1018 { } 1019 1020 static inline int security_ipc_permission(struct kern_ipc_perm *ipcp, 1021 short flag) 1022 { 1023 return 0; 1024 } 1025 1026 static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) 1027 { 1028 *secid = 0; 1029 } 1030 1031 static inline int security_msg_msg_alloc(struct msg_msg *msg) 1032 { 1033 return 0; 1034 } 1035 1036 static inline void security_msg_msg_free(struct msg_msg *msg) 1037 { } 1038 1039 static inline int security_msg_queue_alloc(struct kern_ipc_perm *msq) 1040 { 1041 return 0; 1042 } 1043 1044 static inline void security_msg_queue_free(struct kern_ipc_perm *msq) 1045 { } 1046 1047 static inline int security_msg_queue_associate(struct kern_ipc_perm *msq, 1048 int msqflg) 1049 { 1050 return 0; 1051 } 1052 1053 static inline int security_msg_queue_msgctl(struct kern_ipc_perm *msq, int cmd) 1054 { 1055 return 0; 1056 } 1057 1058 static inline int security_msg_queue_msgsnd(struct kern_ipc_perm *msq, 1059 struct msg_msg *msg, int msqflg) 1060 { 1061 return 0; 1062 } 1063 1064 static inline int security_msg_queue_msgrcv(struct kern_ipc_perm *msq, 1065 struct msg_msg *msg, 1066 struct task_struct *target, 1067 long type, int mode) 1068 { 1069 return 0; 1070 } 1071 1072 static inline int security_shm_alloc(struct kern_ipc_perm *shp) 1073 { 1074 return 0; 1075 } 1076 1077 static inline void security_shm_free(struct kern_ipc_perm *shp) 1078 { } 1079 1080 static inline int security_shm_associate(struct kern_ipc_perm *shp, 1081 int shmflg) 1082 { 1083 return 0; 1084 } 1085 1086 static inline int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd) 1087 { 1088 return 0; 1089 } 1090 1091 static inline int security_shm_shmat(struct kern_ipc_perm *shp, 1092 char __user *shmaddr, int shmflg) 1093 { 1094 return 0; 1095 } 1096 1097 static inline int security_sem_alloc(struct kern_ipc_perm *sma) 1098 { 1099 return 0; 1100 } 1101 1102 static inline void security_sem_free(struct kern_ipc_perm *sma) 1103 { } 1104 1105 static inline int security_sem_associate(struct kern_ipc_perm *sma, int semflg) 1106 { 1107 return 0; 1108 } 1109 1110 static inline int security_sem_semctl(struct kern_ipc_perm *sma, int cmd) 1111 { 1112 return 0; 1113 } 1114 1115 static inline int security_sem_semop(struct kern_ipc_perm *sma, 1116 struct sembuf *sops, unsigned nsops, 1117 int alter) 1118 { 1119 return 0; 1120 } 1121 1122 static inline void security_d_instantiate(struct dentry *dentry, struct inode *inode) 1123 { } 1124 1125 static inline int security_getprocattr(struct task_struct *p, char *name, char **value) 1126 { 1127 return -EINVAL; 1128 } 1129 1130 static inline int security_setprocattr(char *name, void *value, size_t size) 1131 { 1132 return -EINVAL; 1133 } 1134 1135 static inline int security_netlink_send(struct sock *sk, struct sk_buff *skb) 1136 { 1137 return 0; 1138 } 1139 1140 static inline int security_ismaclabel(const char *name) 1141 { 1142 return 0; 1143 } 1144 1145 static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) 1146 { 1147 return -EOPNOTSUPP; 1148 } 1149 1150 static inline int security_secctx_to_secid(const char *secdata, 1151 u32 seclen, 1152 u32 *secid) 1153 { 1154 return -EOPNOTSUPP; 1155 } 1156 1157 static inline void security_release_secctx(char *secdata, u32 seclen) 1158 { 1159 } 1160 1161 static inline void security_inode_invalidate_secctx(struct inode *inode) 1162 { 1163 } 1164 1165 static inline int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) 1166 { 1167 return -EOPNOTSUPP; 1168 } 1169 static inline int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) 1170 { 1171 return -EOPNOTSUPP; 1172 } 1173 static inline int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) 1174 { 1175 return -EOPNOTSUPP; 1176 } 1177 #endif /* CONFIG_SECURITY */ 1178 1179 #ifdef CONFIG_SECURITY_NETWORK 1180 1181 int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk); 1182 int security_unix_may_send(struct socket *sock, struct socket *other); 1183 int security_socket_create(int family, int type, int protocol, int kern); 1184 int security_socket_post_create(struct socket *sock, int family, 1185 int type, int protocol, int kern); 1186 int security_socket_socketpair(struct socket *socka, struct socket *sockb); 1187 int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen); 1188 int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen); 1189 int security_socket_listen(struct socket *sock, int backlog); 1190 int security_socket_accept(struct socket *sock, struct socket *newsock); 1191 int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size); 1192 int security_socket_recvmsg(struct socket *sock, struct msghdr *msg, 1193 int size, int flags); 1194 int security_socket_getsockname(struct socket *sock); 1195 int security_socket_getpeername(struct socket *sock); 1196 int security_socket_getsockopt(struct socket *sock, int level, int optname); 1197 int security_socket_setsockopt(struct socket *sock, int level, int optname); 1198 int security_socket_shutdown(struct socket *sock, int how); 1199 int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb); 1200 int security_socket_getpeersec_stream(struct socket *sock, char __user *optval, 1201 int __user *optlen, unsigned len); 1202 int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid); 1203 int security_sk_alloc(struct sock *sk, int family, gfp_t priority); 1204 void security_sk_free(struct sock *sk); 1205 void security_sk_clone(const struct sock *sk, struct sock *newsk); 1206 void security_sk_classify_flow(struct sock *sk, struct flowi *fl); 1207 void security_req_classify_flow(const struct request_sock *req, struct flowi *fl); 1208 void security_sock_graft(struct sock*sk, struct socket *parent); 1209 int security_inet_conn_request(struct sock *sk, 1210 struct sk_buff *skb, struct request_sock *req); 1211 void security_inet_csk_clone(struct sock *newsk, 1212 const struct request_sock *req); 1213 void security_inet_conn_established(struct sock *sk, 1214 struct sk_buff *skb); 1215 int security_secmark_relabel_packet(u32 secid); 1216 void security_secmark_refcount_inc(void); 1217 void security_secmark_refcount_dec(void); 1218 int security_tun_dev_alloc_security(void **security); 1219 void security_tun_dev_free_security(void *security); 1220 int security_tun_dev_create(void); 1221 int security_tun_dev_attach_queue(void *security); 1222 int security_tun_dev_attach(struct sock *sk, void *security); 1223 int security_tun_dev_open(void *security); 1224 int security_sctp_assoc_request(struct sctp_endpoint *ep, struct sk_buff *skb); 1225 int security_sctp_bind_connect(struct sock *sk, int optname, 1226 struct sockaddr *address, int addrlen); 1227 void security_sctp_sk_clone(struct sctp_endpoint *ep, struct sock *sk, 1228 struct sock *newsk); 1229 1230 #else /* CONFIG_SECURITY_NETWORK */ 1231 static inline int security_unix_stream_connect(struct sock *sock, 1232 struct sock *other, 1233 struct sock *newsk) 1234 { 1235 return 0; 1236 } 1237 1238 static inline int security_unix_may_send(struct socket *sock, 1239 struct socket *other) 1240 { 1241 return 0; 1242 } 1243 1244 static inline int security_socket_create(int family, int type, 1245 int protocol, int kern) 1246 { 1247 return ccs_socket_create(family, type, protocol, kern); 1248 } 1249 1250 static inline int security_socket_post_create(struct socket *sock, 1251 int family, 1252 int type, 1253 int protocol, int kern) 1254 { 1255 return 0; 1256 } 1257 1258 static inline int security_socket_socketpair(struct socket *socka, 1259 struct socket *sockb) 1260 { 1261 return 0; 1262 } 1263 1264 static inline int security_socket_bind(struct socket *sock, 1265 struct sockaddr *address, 1266 int addrlen) 1267 { 1268 return ccs_socket_bind(sock, address, addrlen); 1269 } 1270 1271 static inline int security_socket_connect(struct socket *sock, 1272 struct sockaddr *address, 1273 int addrlen) 1274 { 1275 return ccs_socket_connect(sock, address, addrlen); 1276 } 1277 1278 static inline int security_socket_listen(struct socket *sock, int backlog) 1279 { 1280 return ccs_socket_listen(sock, backlog); 1281 } 1282 1283 static inline int security_socket_accept(struct socket *sock, 1284 struct socket *newsock) 1285 { 1286 return 0; 1287 } 1288 1289 static inline int security_socket_sendmsg(struct socket *sock, 1290 struct msghdr *msg, int size) 1291 { 1292 return ccs_socket_sendmsg(sock, msg, size); 1293 } 1294 1295 static inline int security_socket_recvmsg(struct socket *sock, 1296 struct msghdr *msg, int size, 1297 int flags) 1298 { 1299 return 0; 1300 } 1301 1302 static inline int security_socket_getsockname(struct socket *sock) 1303 { 1304 return 0; 1305 } 1306 1307 static inline int security_socket_getpeername(struct socket *sock) 1308 { 1309 return 0; 1310 } 1311 1312 static inline int security_socket_getsockopt(struct socket *sock, 1313 int level, int optname) 1314 { 1315 return 0; 1316 } 1317 1318 static inline int security_socket_setsockopt(struct socket *sock, 1319 int level, int optname) 1320 { 1321 return 0; 1322 } 1323 1324 static inline int security_socket_shutdown(struct socket *sock, int how) 1325 { 1326 return 0; 1327 } 1328 static inline int security_sock_rcv_skb(struct sock *sk, 1329 struct sk_buff *skb) 1330 { 1331 return 0; 1332 } 1333 1334 static inline int security_socket_getpeersec_stream(struct socket *sock, char __user *optval, 1335 int __user *optlen, unsigned len) 1336 { 1337 return -ENOPROTOOPT; 1338 } 1339 1340 static inline int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid) 1341 { 1342 return -ENOPROTOOPT; 1343 } 1344 1345 static inline int security_sk_alloc(struct sock *sk, int family, gfp_t priority) 1346 { 1347 return 0; 1348 } 1349 1350 static inline void security_sk_free(struct sock *sk) 1351 { 1352 } 1353 1354 static inline void security_sk_clone(const struct sock *sk, struct sock *newsk) 1355 { 1356 } 1357 1358 static inline void security_sk_classify_flow(struct sock *sk, struct flowi *fl) 1359 { 1360 } 1361 1362 static inline void security_req_classify_flow(const struct request_sock *req, struct flowi *fl) 1363 { 1364 } 1365 1366 static inline void security_sock_graft(struct sock *sk, struct socket *parent) 1367 { 1368 } 1369 1370 static inline int security_inet_conn_request(struct sock *sk, 1371 struct sk_buff *skb, struct request_sock *req) 1372 { 1373 return 0; 1374 } 1375 1376 static inline void security_inet_csk_clone(struct sock *newsk, 1377 const struct request_sock *req) 1378 { 1379 } 1380 1381 static inline void security_inet_conn_established(struct sock *sk, 1382 struct sk_buff *skb) 1383 { 1384 } 1385 1386 static inline int security_secmark_relabel_packet(u32 secid) 1387 { 1388 return 0; 1389 } 1390 1391 static inline void security_secmark_refcount_inc(void) 1392 { 1393 } 1394 1395 static inline void security_secmark_refcount_dec(void) 1396 { 1397 } 1398 1399 static inline int security_tun_dev_alloc_security(void **security) 1400 { 1401 return 0; 1402 } 1403 1404 static inline void security_tun_dev_free_security(void *security) 1405 { 1406 } 1407 1408 static inline int security_tun_dev_create(void) 1409 { 1410 return 0; 1411 } 1412 1413 static inline int security_tun_dev_attach_queue(void *security) 1414 { 1415 return 0; 1416 } 1417 1418 static inline int security_tun_dev_attach(struct sock *sk, void *security) 1419 { 1420 return 0; 1421 } 1422 1423 static inline int security_tun_dev_open(void *security) 1424 { 1425 return 0; 1426 } 1427 1428 static inline int security_sctp_assoc_request(struct sctp_endpoint *ep, 1429 struct sk_buff *skb) 1430 { 1431 return 0; 1432 } 1433 1434 static inline int security_sctp_bind_connect(struct sock *sk, int optname, 1435 struct sockaddr *address, 1436 int addrlen) 1437 { 1438 return 0; 1439 } 1440 1441 static inline void security_sctp_sk_clone(struct sctp_endpoint *ep, 1442 struct sock *sk, 1443 struct sock *newsk) 1444 { 1445 } 1446 #endif /* CONFIG_SECURITY_NETWORK */ 1447 1448 #ifdef CONFIG_SECURITY_INFINIBAND 1449 int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey); 1450 int security_ib_endport_manage_subnet(void *sec, const char *name, u8 port_num); 1451 int security_ib_alloc_security(void **sec); 1452 void security_ib_free_security(void *sec); 1453 #else /* CONFIG_SECURITY_INFINIBAND */ 1454 static inline int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey) 1455 { 1456 return 0; 1457 } 1458 1459 static inline int security_ib_endport_manage_subnet(void *sec, const char *dev_name, u8 port_num) 1460 { 1461 return 0; 1462 } 1463 1464 static inline int security_ib_alloc_security(void **sec) 1465 { 1466 return 0; 1467 } 1468 1469 static inline void security_ib_free_security(void *sec) 1470 { 1471 } 1472 #endif /* CONFIG_SECURITY_INFINIBAND */ 1473 1474 #ifdef CONFIG_SECURITY_NETWORK_XFRM 1475 1476 int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, 1477 struct xfrm_user_sec_ctx *sec_ctx, gfp_t gfp); 1478 int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctxp); 1479 void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx); 1480 int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx); 1481 int security_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *sec_ctx); 1482 int security_xfrm_state_alloc_acquire(struct xfrm_state *x, 1483 struct xfrm_sec_ctx *polsec, u32 secid); 1484 int security_xfrm_state_delete(struct xfrm_state *x); 1485 void security_xfrm_state_free(struct xfrm_state *x); 1486 int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir); 1487 int security_xfrm_state_pol_flow_match(struct xfrm_state *x, 1488 struct xfrm_policy *xp, 1489 const struct flowi *fl); 1490 int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid); 1491 void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl); 1492 1493 #else /* CONFIG_SECURITY_NETWORK_XFRM */ 1494 1495 static inline int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, 1496 struct xfrm_user_sec_ctx *sec_ctx, 1497 gfp_t gfp) 1498 { 1499 return 0; 1500 } 1501 1502 static inline int security_xfrm_policy_clone(struct xfrm_sec_ctx *old, struct xfrm_sec_ctx **new_ctxp) 1503 { 1504 return 0; 1505 } 1506 1507 static inline void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx) 1508 { 1509 } 1510 1511 static inline int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx) 1512 { 1513 return 0; 1514 } 1515 1516 static inline int security_xfrm_state_alloc(struct xfrm_state *x, 1517 struct xfrm_user_sec_ctx *sec_ctx) 1518 { 1519 return 0; 1520 } 1521 1522 static inline int security_xfrm_state_alloc_acquire(struct xfrm_state *x, 1523 struct xfrm_sec_ctx *polsec, u32 secid) 1524 { 1525 return 0; 1526 } 1527 1528 static inline void security_xfrm_state_free(struct xfrm_state *x) 1529 { 1530 } 1531 1532 static inline int security_xfrm_state_delete(struct xfrm_state *x) 1533 { 1534 return 0; 1535 } 1536 1537 static inline int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir) 1538 { 1539 return 0; 1540 } 1541 1542 static inline int security_xfrm_state_pol_flow_match(struct xfrm_state *x, 1543 struct xfrm_policy *xp, const struct flowi *fl) 1544 { 1545 return 1; 1546 } 1547 1548 static inline int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid) 1549 { 1550 return 0; 1551 } 1552 1553 static inline void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl) 1554 { 1555 } 1556 1557 #endif /* CONFIG_SECURITY_NETWORK_XFRM */ 1558 1559 #ifdef CONFIG_SECURITY_PATH 1560 int security_path_unlink(const struct path *dir, struct dentry *dentry); 1561 int security_path_mkdir(const struct path *dir, struct dentry *dentry, umode_t mode); 1562 int security_path_rmdir(const struct path *dir, struct dentry *dentry); 1563 int security_path_mknod(const struct path *dir, struct dentry *dentry, umode_t mode, 1564 unsigned int dev); 1565 int security_path_truncate(const struct path *path); 1566 int security_path_symlink(const struct path *dir, struct dentry *dentry, 1567 const char *old_name); 1568 int security_path_link(struct dentry *old_dentry, const struct path *new_dir, 1569 struct dentry *new_dentry); 1570 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry, 1571 const struct path *new_dir, struct dentry *new_dentry, 1572 unsigned int flags); 1573 int security_path_chmod(const struct path *path, umode_t mode); 1574 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid); 1575 int security_path_chroot(const struct path *path); 1576 #else /* CONFIG_SECURITY_PATH */ 1577 static inline int security_path_unlink(const struct path *dir, struct dentry *dentry) 1578 { 1579 return ccs_path_unlink(dir, dentry); 1580 } 1581 1582 static inline int security_path_mkdir(const struct path *dir, struct dentry *dentry, 1583 umode_t mode) 1584 { 1585 return ccs_path_mkdir(dir, dentry, mode); 1586 } 1587 1588 static inline int security_path_rmdir(const struct path *dir, struct dentry *dentry) 1589 { 1590 return ccs_path_rmdir(dir, dentry); 1591 } 1592 1593 static inline int security_path_mknod(const struct path *dir, struct dentry *dentry, 1594 umode_t mode, unsigned int dev) 1595 { 1596 return ccs_path_mknod(dir, dentry, mode, dev); 1597 } 1598 1599 static inline int security_path_truncate(const struct path *path) 1600 { 1601 return ccs_path_truncate(path); 1602 } 1603 1604 static inline int security_path_symlink(const struct path *dir, struct dentry *dentry, 1605 const char *old_name) 1606 { 1607 return ccs_path_symlink(dir, dentry, old_name); 1608 } 1609 1610 static inline int security_path_link(struct dentry *old_dentry, 1611 const struct path *new_dir, 1612 struct dentry *new_dentry) 1613 { 1614 return ccs_path_link(old_dentry, new_dir, new_dentry); 1615 } 1616 1617 static inline int security_path_rename(const struct path *old_dir, 1618 struct dentry *old_dentry, 1619 const struct path *new_dir, 1620 struct dentry *new_dentry, 1621 unsigned int flags) 1622 { 1623 /* 1624 * Not using RENAME_EXCHANGE here in order to avoid KABI breakage 1625 * by doing "#include <uapi/linux/fs.h>" . 1626 */ 1627 if (flags & (1 << 1)) { 1628 int err = ccs_path_rename(new_dir, new_dentry, old_dir, 1629 old_dentry); 1630 if (err) 1631 return err; 1632 } 1633 return ccs_path_rename(old_dir, old_dentry, new_dir, new_dentry); 1634 } 1635 1636 static inline int security_path_chmod(const struct path *path, umode_t mode) 1637 { 1638 return ccs_path_chmod(path, mode); 1639 } 1640 1641 static inline int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid) 1642 { 1643 return ccs_path_chown(path, uid, gid); 1644 } 1645 1646 static inline int security_path_chroot(const struct path *path) 1647 { 1648 return ccs_path_chroot(path); 1649 } 1650 #endif /* CONFIG_SECURITY_PATH */ 1651 1652 #ifdef CONFIG_KEYS 1653 #ifdef CONFIG_SECURITY 1654 1655 int security_key_alloc(struct key *key, const struct cred *cred, unsigned long flags); 1656 void security_key_free(struct key *key); 1657 int security_key_permission(key_ref_t key_ref, 1658 const struct cred *cred, unsigned perm); 1659 int security_key_getsecurity(struct key *key, char **_buffer); 1660 1661 #else 1662 1663 static inline int security_key_alloc(struct key *key, 1664 const struct cred *cred, 1665 unsigned long flags) 1666 { 1667 return 0; 1668 } 1669 1670 static inline void security_key_free(struct key *key) 1671 { 1672 } 1673 1674 static inline int security_key_permission(key_ref_t key_ref, 1675 const struct cred *cred, 1676 unsigned perm) 1677 { 1678 return 0; 1679 } 1680 1681 static inline int security_key_getsecurity(struct key *key, char **_buffer) 1682 { 1683 *_buffer = NULL; 1684 return 0; 1685 } 1686 1687 #endif 1688 #endif /* CONFIG_KEYS */ 1689 1690 #ifdef CONFIG_AUDIT 1691 #ifdef CONFIG_SECURITY 1692 int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule); 1693 int security_audit_rule_known(struct audit_krule *krule); 1694 int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule, 1695 struct audit_context *actx); 1696 void security_audit_rule_free(void *lsmrule); 1697 1698 #else 1699 1700 static inline int security_audit_rule_init(u32 field, u32 op, char *rulestr, 1701 void **lsmrule) 1702 { 1703 return 0; 1704 } 1705 1706 static inline int security_audit_rule_known(struct audit_krule *krule) 1707 { 1708 return 0; 1709 } 1710 1711 static inline int security_audit_rule_match(u32 secid, u32 field, u32 op, 1712 void *lsmrule, struct audit_context *actx) 1713 { 1714 return 0; 1715 } 1716 1717 static inline void security_audit_rule_free(void *lsmrule) 1718 { } 1719 1720 #endif /* CONFIG_SECURITY */ 1721 #endif /* CONFIG_AUDIT */ 1722 1723 #ifdef CONFIG_SECURITYFS 1724 1725 extern struct dentry *securityfs_create_file(const char *name, umode_t mode, 1726 struct dentry *parent, void *data, 1727 const struct file_operations *fops); 1728 extern struct dentry *securityfs_create_dir(const char *name, struct dentry *parent); 1729 struct dentry *securityfs_create_symlink(const char *name, 1730 struct dentry *parent, 1731 const char *target, 1732 const struct inode_operations *iops); 1733 extern void securityfs_remove(struct dentry *dentry); 1734 1735 #else /* CONFIG_SECURITYFS */ 1736 1737 static inline struct dentry *securityfs_create_dir(const char *name, 1738 struct dentry *parent) 1739 { 1740 return ERR_PTR(-ENODEV); 1741 } 1742 1743 static inline struct dentry *securityfs_create_file(const char *name, 1744 umode_t mode, 1745 struct dentry *parent, 1746 void *data, 1747 const struct file_operations *fops) 1748 { 1749 return ERR_PTR(-ENODEV); 1750 } 1751 1752 static inline struct dentry *securityfs_create_symlink(const char *name, 1753 struct dentry *parent, 1754 const char *target, 1755 const struct inode_operations *iops) 1756 { 1757 return ERR_PTR(-ENODEV); 1758 } 1759 1760 static inline void securityfs_remove(struct dentry *dentry) 1761 {} 1762 1763 #endif 1764 1765 #ifdef CONFIG_BPF_SYSCALL 1766 union bpf_attr; 1767 struct bpf_map; 1768 struct bpf_prog; 1769 struct bpf_prog_aux; 1770 #ifdef CONFIG_SECURITY 1771 extern int security_bpf(int cmd, union bpf_attr *attr, unsigned int size); 1772 extern int security_bpf_map(struct bpf_map *map, fmode_t fmode); 1773 extern int security_bpf_prog(struct bpf_prog *prog); 1774 extern int security_bpf_map_alloc(struct bpf_map *map); 1775 extern void security_bpf_map_free(struct bpf_map *map); 1776 extern int security_bpf_prog_alloc(struct bpf_prog_aux *aux); 1777 extern void security_bpf_prog_free(struct bpf_prog_aux *aux); 1778 #else 1779 static inline int security_bpf(int cmd, union bpf_attr *attr, 1780 unsigned int size) 1781 { 1782 return 0; 1783 } 1784 1785 static inline int security_bpf_map(struct bpf_map *map, fmode_t fmode) 1786 { 1787 return 0; 1788 } 1789 1790 static inline int security_bpf_prog(struct bpf_prog *prog) 1791 { 1792 return 0; 1793 } 1794 1795 static inline int security_bpf_map_alloc(struct bpf_map *map) 1796 { 1797 return 0; 1798 } 1799 1800 static inline void security_bpf_map_free(struct bpf_map *map) 1801 { } 1802 1803 static inline int security_bpf_prog_alloc(struct bpf_prog_aux *aux) 1804 { 1805 return 0; 1806 } 1807 1808 static inline void security_bpf_prog_free(struct bpf_prog_aux *aux) 1809 { } 1810 #endif /* CONFIG_SECURITY */ 1811 #endif /* CONFIG_BPF_SYSCALL */ 1812 1813 #ifdef CONFIG_SECURITY 1814 1815 static inline char *alloc_secdata(void) 1816 { 1817 return (char *)get_zeroed_page(GFP_KERNEL); 1818 } 1819 1820 static inline void free_secdata(void *secdata) 1821 { 1822 free_page((unsigned long)secdata); 1823 } 1824 1825 #else 1826 1827 static inline char *alloc_secdata(void) 1828 { 1829 return (char *)1; 1830 } 1831 1832 static inline void free_secdata(void *secdata) 1833 { } 1834 #endif /* CONFIG_SECURITY */ 1835 1836 #endif /* ! __LINUX_SECURITY_H */ 1837 1838
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.