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