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