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