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