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