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