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