1/* 2 * Linux Security Module interfaces 3 * 4 * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com> 5 * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com> 6 * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com> 7 * Copyright (C) 2001 James Morris <jmorris@intercode.com.au> 8 * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group) 9 * Copyright (C) 2015 Intel Corporation. 10 * Copyright (C) 2015 Casey Schaufler <casey@schaufler-ca.com> 11 * Copyright (C) 2016 Mellanox Techonologies 12 * 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation; either version 2 of the License, or 16 * (at your option) any later version. 17 * 18 * Due to this file being licensed under the GPL there is controversy over 19 * whether this permits you to write a module that #includes this file 20 * without placing your module under the GPL. Please consult a lawyer for 21 * advice before doing this. 22 * 23 */ 24 25#ifndef __LINUX_LSM_HOOKS_H 26#define __LINUX_LSM_HOOKS_H 27 28#include <linux/security.h> 29#include <linux/init.h> 30#include <linux/rculist.h> 31 32/** 33 * union security_list_options - Linux Security Module hook function list 34 * 35 * Security hooks for program execution operations. 36 * 37 * @bprm_set_creds: 38 * Save security information in the bprm->security field, typically based 39 * on information about the bprm->file, for later use by the apply_creds 40 * hook. This hook may also optionally check permissions (e.g. for 41 * transitions between security domains). 42 * This hook may be called multiple times during a single execve, e.g. for 43 * interpreters. The hook can tell whether it has already been called by 44 * checking to see if @bprm->security is non-NULL. If so, then the hook 45 * may decide either to retain the security information saved earlier or 46 * to replace it. The hook must set @bprm->secureexec to 1 if a "secure 47 * exec" has happened as a result of this hook call. The flag is used to 48 * indicate the need for a sanitized execution environment, and is also 49 * passed in the ELF auxiliary table on the initial stack to indicate 50 * whether libc should enable secure mode. 51 * @bprm contains the linux_binprm structure. 52 * Return 0 if the hook is successful and permission is granted. 53 * @bprm_check_security: 54 * This hook mediates the point when a search for a binary handler will 55 * begin. It allows a check the @bprm->security value which is set in the 56 * preceding set_creds call. The primary difference from set_creds is 57 * that the argv list and envp list are reliably available in @bprm. This 58 * hook may be called multiple times during a single execve; and in each 59 * pass set_creds is called first. 60 * @bprm contains the linux_binprm structure. 61 * Return 0 if the hook is successful and permission is granted. 62 * @bprm_committing_creds: 63 * Prepare to install the new security attributes of a process being 64 * transformed by an execve operation, based on the old credentials 65 * pointed to by @current->cred and the information set in @bprm->cred by 66 * the bprm_set_creds hook. @bprm points to the linux_binprm structure. 67 * This hook is a good place to perform state changes on the process such 68 * as closing open file descriptors to which access will no longer be 69 * granted when the attributes are changed. This is called immediately 70 * before commit_creds(). 71 * @bprm_committed_creds: 72 * Tidy up after the installation of the new security attributes of a 73 * process being transformed by an execve operation. The new credentials 74 * have, by this point, been set to @current->cred. @bprm points to the 75 * linux_binprm structure. This hook is a good place to perform state 76 * changes on the process such as clearing out non-inheritable signal 77 * state. This is called immediately after commit_creds(). 78 * 79 * Security hooks for filesystem operations. 80 * 81 * @sb_alloc_security: 82 * Allocate and attach a security structure to the sb->s_security field. 83 * The s_security field is initialized to NULL when the structure is 84 * allocated. 85 * @sb contains the super_block structure to be modified. 86 * Return 0 if operation was successful. 87 * @sb_free_security: 88 * Deallocate and clear the sb->s_security field. 89 * @sb contains the super_block structure to be modified. 90 * @sb_statfs: 91 * Check permission before obtaining filesystem statistics for the @mnt 92 * mountpoint. 93 * @dentry is a handle on the superblock for the filesystem. 94 * Return 0 if permission is granted. 95 * @sb_mount: 96 * Check permission before an object specified by @dev_name is mounted on 97 * the mount point named by @nd. For an ordinary mount, @dev_name 98 * identifies a device if the file system type requires a device. For a 99 * remount (@flags & MS_REMOUNT), @dev_name is irrelevant. For a 100 * loopback/bind mount (@flags & MS_BIND), @dev_name identifies the 101 * pathname of the object being mounted. 102 * @dev_name contains the name for object being mounted. 103 * @path contains the path for mount point object. 104 * @type contains the filesystem type. 105 * @flags contains the mount flags. 106 * @data contains the filesystem-specific data. 107 * Return 0 if permission is granted. 108 * @sb_copy_data: 109 * Allow mount option data to be copied prior to parsing by the filesystem, 110 * so that the security module can extract security-specific mount 111 * options cleanly (a filesystem may modify the data e.g. with strsep()). 112 * This also allows the original mount data to be stripped of security- 113 * specific options to avoid having to make filesystems aware of them. 114 * @type the type of filesystem being mounted. 115 * @orig the original mount data copied from userspace. 116 * @copy copied data which will be passed to the security module. 117 * Returns 0 if the copy was successful. 118 * @sb_remount: 119 * Extracts security system specific mount options and verifies no changes 120 * are being made to those options. 121 * @sb superblock being remounted 122 * @data contains the filesystem-specific data. 123 * Return 0 if permission is granted. 124 * @sb_umount: 125 * Check permission before the @mnt file system is unmounted. 126 * @mnt contains the mounted file system. 127 * @flags contains the unmount flags, e.g. MNT_FORCE. 128 * Return 0 if permission is granted. 129 * @sb_pivotroot: 130 * Check permission before pivoting the root filesystem. 131 * @old_path contains the path for the new location of the 132 * current root (put_old). 133 * @new_path contains the path for the new root (new_root). 134 * Return 0 if permission is granted. 135 * @sb_set_mnt_opts: 136 * Set the security relevant mount options used for a superblock 137 * @sb the superblock to set security mount options for 138 * @opts binary data structure containing all lsm mount data 139 * @sb_clone_mnt_opts: 140 * Copy all security options from a given superblock to another 141 * @oldsb old superblock which contain information to clone 142 * @newsb new superblock which needs filled in 143 * @sb_parse_opts_str: 144 * Parse a string of security data filling in the opts structure 145 * @options string containing all mount options known by the LSM 146 * @opts binary data structure usable by the LSM 147 * @dentry_init_security: 148 * Compute a context for a dentry as the inode is not yet available 149 * since NFSv4 has no label backed by an EA anyway. 150 * @dentry dentry to use in calculating the context. 151 * @mode mode used to determine resource type. 152 * @name name of the last path component used to create file 153 * @ctx pointer to place the pointer to the resulting context in. 154 * @ctxlen point to place the length of the resulting context. 155 * @dentry_create_files_as: 156 * Compute a context for a dentry as the inode is not yet available 157 * and set that context in passed in creds so that new files are 158 * created using that context. Context is calculated using the 159 * passed in creds and not the creds of the caller. 160 * @dentry dentry to use in calculating the context. 161 * @mode mode used to determine resource type. 162 * @name name of the last path component used to create file 163 * @old creds which should be used for context calculation 164 * @new creds to modify 165 * 166 * 167 * Security hooks for inode operations. 168 * 169 * @inode_alloc_security: 170 * Allocate and attach a security structure to @inode->i_security. The 171 * i_security field is initialized to NULL when the inode structure is 172 * allocated. 173 * @inode contains the inode structure. 174 * Return 0 if operation was successful. 175 * @inode_free_security: 176 * @inode contains the inode structure. 177 * Deallocate the inode security structure and set @inode->i_security to 178 * NULL. 179 * @inode_init_security: 180 * Obtain the security attribute name suffix and value to set on a newly 181 * created inode and set up the incore security field for the new inode. 182 * This hook is called by the fs code as part of the inode creation 183 * transaction and provides for atomic labeling of the inode, unlike 184 * the post_create/mkdir/... hooks called by the VFS. The hook function 185 * is expected to allocate the name and value via kmalloc, with the caller 186 * being responsible for calling kfree after using them. 187 * If the security module does not use security attributes or does 188 * not wish to put a security attribute on this particular inode, 189 * then it should return -EOPNOTSUPP to skip this processing. 190 * @inode contains the inode structure of the newly created inode. 191 * @dir contains the inode structure of the parent directory. 192 * @qstr contains the last path component of the new object 193 * @name will be set to the allocated name suffix (e.g. selinux). 194 * @value will be set to the allocated attribute value. 195 * @len will be set to the length of the value. 196 * Returns 0 if @name and @value have been successfully set, 197 * -EOPNOTSUPP if no security attribute is needed, or 198 * -ENOMEM on memory allocation failure. 199 * @inode_create: 200 * Check permission to create a regular file. 201 * @dir contains inode structure of the parent of the new file. 202 * @dentry contains the dentry structure for the file to be created. 203 * @mode contains the file mode of the file to be created. 204 * Return 0 if permission is granted. 205 * @inode_link: 206 * Check permission before creating a new hard link to a file. 207 * @old_dentry contains the dentry structure for an existing 208 * link to the file. 209 * @dir contains the inode structure of the parent directory 210 * of the new link. 211 * @new_dentry contains the dentry structure for the new link. 212 * Return 0 if permission is granted. 213 * @path_link: 214 * Check permission before creating a new hard link to a file. 215 * @old_dentry contains the dentry structure for an existing link 216 * to the file. 217 * @new_dir contains the path structure of the parent directory of 218 * the new link. 219 * @new_dentry contains the dentry structure for the new link. 220 * Return 0 if permission is granted. 221 * @inode_unlink: 222 * Check the permission to remove a hard link to a file. 223 * @dir contains the inode structure of parent directory of the file. 224 * @dentry contains the dentry structure for file to be unlinked. 225 * Return 0 if permission is granted. 226 * @path_unlink: 227 * Check the permission to remove a hard link to a file. 228 * @dir contains the path structure of parent directory of the file. 229 * @dentry contains the dentry structure for file to be unlinked. 230 * Return 0 if permission is granted. 231 * @inode_symlink: 232 * Check the permission to create a symbolic link to a file. 233 * @dir contains the inode structure of parent directory of 234 * the symbolic link. 235 * @dentry contains the dentry structure of the symbolic link. 236 * @old_name contains the pathname of file. 237 * Return 0 if permission is granted. 238 * @path_symlink: 239 * Check the permission to create a symbolic link to a file. 240 * @dir contains the path structure of parent directory of 241 * the symbolic link. 242 * @dentry contains the dentry structure of the symbolic link. 243 * @old_name contains the pathname of file. 244 * Return 0 if permission is granted. 245 * @inode_mkdir: 246 * Check permissions to create a new directory in the existing directory 247 * associated with inode structure @dir. 248 * @dir contains the inode structure of parent of the directory 249 * to be created. 250 * @dentry contains the dentry structure of new directory. 251 * @mode contains the mode of new directory. 252 * Return 0 if permission is granted. 253 * @path_mkdir: 254 * Check permissions to create a new directory in the existing directory 255 * associated with path structure @path. 256 * @dir contains the path structure of parent of the directory 257 * to be created. 258 * @dentry contains the dentry structure of new directory. 259 * @mode contains the mode of new directory. 260 * Return 0 if permission is granted. 261 * @inode_rmdir: 262 * Check the permission to remove a directory. 263 * @dir contains the inode structure of parent of the directory 264 * to be removed. 265 * @dentry contains the dentry structure of directory to be removed. 266 * Return 0 if permission is granted. 267 * @path_rmdir: 268 * Check the permission to remove a directory. 269 * @dir contains the path structure of parent of the directory to be 270 * removed. 271 * @dentry contains the dentry structure of directory to be removed. 272 * Return 0 if permission is granted. 273 * @inode_mknod: 274 * Check permissions when creating a special file (or a socket or a fifo 275 * file created via the mknod system call). Note that if mknod operation 276 * is being done for a regular file, then the create hook will be called 277 * and not this hook. 278 * @dir contains the inode structure of parent of the new file. 279 * @dentry contains the dentry structure of the new file. 280 * @mode contains the mode of the new file. 281 * @dev contains the device number. 282 * Return 0 if permission is granted. 283 * @path_mknod: 284 * Check permissions when creating a file. Note that this hook is called 285 * even if mknod operation is being done for a regular file. 286 * @dir contains the path structure of parent of the new file. 287 * @dentry contains the dentry structure of the new file. 288 * @mode contains the mode of the new file. 289 * @dev contains the undecoded device number. Use new_decode_dev() to get 290 * the decoded device number. 291 * Return 0 if permission is granted. 292 * @inode_rename: 293 * Check for permission to rename a file or directory. 294 * @old_dir contains the inode structure for parent of the old link. 295 * @old_dentry contains the dentry structure of the old link. 296 * @new_dir contains the inode structure for parent of the new link. 297 * @new_dentry contains the dentry structure of the new link. 298 * Return 0 if permission is granted. 299 * @path_rename: 300 * Check for permission to rename a file or directory. 301 * @old_dir contains the path structure for parent of the old link. 302 * @old_dentry contains the dentry structure of the old link. 303 * @new_dir contains the path structure for parent of the new link. 304 * @new_dentry contains the dentry structure of the new link. 305 * Return 0 if permission is granted. 306 * @path_chmod: 307 * Check for permission to change DAC's permission of a file or directory. 308 * @dentry contains the dentry structure. 309 * @mnt contains the vfsmnt structure. 310 * @mode contains DAC's mode. 311 * Return 0 if permission is granted. 312 * @path_chown: 313 * Check for permission to change owner/group of a file or directory. 314 * @path contains the path structure. 315 * @uid contains new owner's ID. 316 * @gid contains new group's ID. 317 * Return 0 if permission is granted. 318 * @path_chroot: 319 * Check for permission to change root directory. 320 * @path contains the path structure. 321 * Return 0 if permission is granted. 322 * @inode_readlink: 323 * Check the permission to read the symbolic link. 324 * @dentry contains the dentry structure for the file link. 325 * Return 0 if permission is granted. 326 * @inode_follow_link: 327 * Check permission to follow a symbolic link when looking up a pathname. 328 * @dentry contains the dentry structure for the link. 329 * @inode contains the inode, which itself is not stable in RCU-walk 330 * @rcu indicates whether we are in RCU-walk mode. 331 * Return 0 if permission is granted. 332 * @inode_permission: 333 * Check permission before accessing an inode. This hook is called by the 334 * existing Linux permission function, so a security module can use it to 335 * provide additional checking for existing Linux permission checks. 336 * Notice that this hook is called when a file is opened (as well as many 337 * other operations), whereas the file_security_ops permission hook is 338 * called when the actual read/write operations are performed. 339 * @inode contains the inode structure to check. 340 * @mask contains the permission mask. 341 * Return 0 if permission is granted. 342 * @inode_setattr: 343 * Check permission before setting file attributes. Note that the kernel 344 * call to notify_change is performed from several locations, whenever 345 * file attributes change (such as when a file is truncated, chown/chmod 346 * operations, transferring disk quotas, etc). 347 * @dentry contains the dentry structure for the file. 348 * @attr is the iattr structure containing the new file attributes. 349 * Return 0 if permission is granted. 350 * @path_truncate: 351 * Check permission before truncating a file. 352 * @path contains the path structure for the file. 353 * Return 0 if permission is granted. 354 * @inode_getattr: 355 * Check permission before obtaining file attributes. 356 * @path contains the path structure for the file. 357 * Return 0 if permission is granted. 358 * @inode_setxattr: 359 * Check permission before setting the extended attributes 360 * @value identified by @name for @dentry. 361 * Return 0 if permission is granted. 362 * @inode_post_setxattr: 363 * Update inode security field after successful setxattr operation. 364 * @value identified by @name for @dentry. 365 * @inode_getxattr: 366 * Check permission before obtaining the extended attributes 367 * identified by @name for @dentry. 368 * Return 0 if permission is granted. 369 * @inode_listxattr: 370 * Check permission before obtaining the list of extended attribute 371 * names for @dentry. 372 * Return 0 if permission is granted. 373 * @inode_removexattr: 374 * Check permission before removing the extended attribute 375 * identified by @name for @dentry. 376 * Return 0 if permission is granted. 377 * @inode_getsecurity: 378 * Retrieve a copy of the extended attribute representation of the 379 * security label associated with @name for @inode via @buffer. Note that 380 * @name is the remainder of the attribute name after the security prefix 381 * has been removed. @alloc is used to specify of the call should return a 382 * value via the buffer or just the value length Return size of buffer on 383 * success. 384 * @inode_setsecurity: 385 * Set the security label associated with @name for @inode from the 386 * extended attribute value @value. @size indicates the size of the 387 * @value in bytes. @flags may be XATTR_CREATE, XATTR_REPLACE, or 0. 388 * Note that @name is the remainder of the attribute name after the 389 * security. prefix has been removed. 390 * Return 0 on success. 391 * @inode_listsecurity: 392 * Copy the extended attribute names for the security labels 393 * associated with @inode into @buffer. The maximum size of @buffer 394 * is specified by @buffer_size. @buffer may be NULL to request 395 * the size of the buffer required. 396 * Returns number of bytes used/required on success. 397 * @inode_need_killpriv: 398 * Called when an inode has been changed. 399 * @dentry is the dentry being changed. 400 * Return <0 on error to abort the inode change operation. 401 * Return 0 if inode_killpriv does not need to be called. 402 * Return >0 if inode_killpriv does need to be called. 403 * @inode_killpriv: 404 * The setuid bit is being removed. Remove similar security labels. 405 * Called with the dentry->d_inode->i_mutex held. 406 * @dentry is the dentry being changed. 407 * Return 0 on success. If error is returned, then the operation 408 * causing setuid bit removal is failed. 409 * @inode_getsecid: 410 * Get the secid associated with the node. 411 * @inode contains a pointer to the inode. 412 * @secid contains a pointer to the location where result will be saved. 413 * In case of failure, @secid will be set to zero. 414 * @inode_copy_up: 415 * A file is about to be copied up from lower layer to upper layer of 416 * overlay filesystem. Security module can prepare a set of new creds 417 * and modify as need be and return new creds. Caller will switch to 418 * new creds temporarily to create new file and release newly allocated 419 * creds. 420 * @src indicates the union dentry of file that is being copied up. 421 * @new pointer to pointer to return newly allocated creds. 422 * Returns 0 on success or a negative error code on error. 423 * @inode_copy_up_xattr: 424 * Filter the xattrs being copied up when a unioned file is copied 425 * up from a lower layer to the union/overlay layer. 426 * @name indicates the name of the xattr. 427 * Returns 0 to accept the xattr, 1 to discard the xattr, -EOPNOTSUPP if 428 * security module does not know about attribute or a negative error code 429 * to abort the copy up. Note that the caller is responsible for reading 430 * and writing the xattrs as this hook is merely a filter. 431 * 432 * Security hooks for file operations 433 * 434 * @file_permission: 435 * Check file permissions before accessing an open file. This hook is 436 * called by various operations that read or write files. A security 437 * module can use this hook to perform additional checking on these 438 * operations, e.g. to revalidate permissions on use to support privilege 439 * bracketing or policy changes. Notice that this hook is used when the 440 * actual read/write operations are performed, whereas the 441 * inode_security_ops hook is called when a file is opened (as well as 442 * many other operations). 443 * Caveat: Although this hook can be used to revalidate permissions for 444 * various system call operations that read or write files, it does not 445 * address the revalidation of permissions for memory-mapped files. 446 * Security modules must handle this separately if they need such 447 * revalidation. 448 * @file contains the file structure being accessed. 449 * @mask contains the requested permissions. 450 * Return 0 if permission is granted. 451 * @file_alloc_security: 452 * Allocate and attach a security structure to the file->f_security field. 453 * The security field is initialized to NULL when the structure is first 454 * created. 455 * @file contains the file structure to secure. 456 * Return 0 if the hook is successful and permission is granted. 457 * @file_free_security: 458 * Deallocate and free any security structures stored in file->f_security. 459 * @file contains the file structure being modified. 460 * @file_ioctl: 461 * @file contains the file structure. 462 * @cmd contains the operation to perform. 463 * @arg contains the operational arguments. 464 * Check permission for an ioctl operation on @file. Note that @arg 465 * sometimes represents a user space pointer; in other cases, it may be a 466 * simple integer value. When @arg represents a user space pointer, it 467 * should never be used by the security module. 468 * Return 0 if permission is granted. 469 * @mmap_addr : 470 * Check permissions for a mmap operation at @addr. 471 * @addr contains virtual address that will be used for the operation. 472 * Return 0 if permission is granted. 473 * @mmap_file : 474 * Check permissions for a mmap operation. The @file may be NULL, e.g. 475 * if mapping anonymous memory. 476 * @file contains the file structure for file to map (may be NULL). 477 * @reqprot contains the protection requested by the application. 478 * @prot contains the protection that will be applied by the kernel. 479 * @flags contains the operational flags. 480 * Return 0 if permission is granted. 481 * @file_mprotect: 482 * Check permissions before changing memory access permissions. 483 * @vma contains the memory region to modify. 484 * @reqprot contains the protection requested by the application. 485 * @prot contains the protection that will be applied by the kernel. 486 * Return 0 if permission is granted. 487 * @file_lock: 488 * Check permission before performing file locking operations. 489 * Note: this hook mediates both flock and fcntl style locks. 490 * @file contains the file structure. 491 * @cmd contains the posix-translated lock operation to perform 492 * (e.g. F_RDLCK, F_WRLCK). 493 * Return 0 if permission is granted. 494 * @file_fcntl: 495 * Check permission before allowing the file operation specified by @cmd 496 * from being performed on the file @file. Note that @arg sometimes 497 * represents a user space pointer; in other cases, it may be a simple 498 * integer value. When @arg represents a user space pointer, it should 499 * never be used by the security module. 500 * @file contains the file structure. 501 * @cmd contains the operation to be performed. 502 * @arg contains the operational arguments. 503 * Return 0 if permission is granted. 504 * @file_set_fowner: 505 * Save owner security information (typically from current->security) in 506 * file->f_security for later use by the send_sigiotask hook. 507 * @file contains the file structure to update. 508 * Return 0 on success. 509 * @file_send_sigiotask: 510 * Check permission for the file owner @fown to send SIGIO or SIGURG to the 511 * process @tsk. Note that this hook is sometimes called from interrupt. 512 * Note that the fown_struct, @fown, is never outside the context of a 513 * struct file, so the file structure (and associated security information) 514 * can always be obtained: container_of(fown, struct file, f_owner) 515 * @tsk contains the structure of task receiving signal. 516 * @fown contains the file owner information. 517 * @sig is the signal that will be sent. When 0, kernel sends SIGIO. 518 * Return 0 if permission is granted. 519 * @file_receive: 520 * This hook allows security modules to control the ability of a process 521 * to receive an open file descriptor via socket IPC. 522 * @file contains the file structure being received. 523 * Return 0 if permission is granted. 524 * @file_open: 525 * Save open-time permission checking state for later use upon 526 * file_permission, and recheck access if anything has changed 527 * since inode_permission. 528 * 529 * Security hooks for task operations. 530 * 531 * @task_alloc: 532 * @task task being allocated. 533 * @clone_flags contains the flags indicating what should be shared. 534 * Handle allocation of task-related resources. 535 * Returns a zero on success, negative values on failure. 536 * @task_free: 537 * @task task about to be freed. 538 * Handle release of task-related resources. (Note that this can be called 539 * from interrupt context.) 540 * @cred_alloc_blank: 541 * @cred points to the credentials. 542 * @gfp indicates the atomicity of any memory allocations. 543 * Only allocate sufficient memory and attach to @cred such that 544 * cred_transfer() will not get ENOMEM. 545 * @cred_free: 546 * @cred points to the credentials. 547 * Deallocate and clear the cred->security field in a set of credentials. 548 * @cred_prepare: 549 * @new points to the new credentials. 550 * @old points to the original credentials. 551 * @gfp indicates the atomicity of any memory allocations. 552 * Prepare a new set of credentials by copying the data from the old set. 553 * @cred_transfer: 554 * @new points to the new credentials. 555 * @old points to the original credentials. 556 * Transfer data from original creds to new creds 557 * @cred_getsecid: 558 * Retrieve the security identifier of the cred structure @c 559 * @c contains the credentials, secid will be placed into @secid. 560 * In case of failure, @secid will be set to zero. 561 * @kernel_act_as: 562 * Set the credentials for a kernel service to act as (subjective context). 563 * @new points to the credentials to be modified. 564 * @secid specifies the security ID to be set 565 * The current task must be the one that nominated @secid. 566 * Return 0 if successful. 567 * @kernel_create_files_as: 568 * Set the file creation context in a set of credentials to be the same as 569 * the objective context of the specified inode. 570 * @new points to the credentials to be modified. 571 * @inode points to the inode to use as a reference. 572 * The current task must be the one that nominated @inode. 573 * Return 0 if successful. 574 * @kernel_module_request: 575 * Ability to trigger the kernel to automatically upcall to userspace for 576 * userspace to load a kernel module with the given name. 577 * @kmod_name name of the module requested by the kernel 578 * Return 0 if successful. 579 * @kernel_read_file: 580 * Read a file specified by userspace. 581 * @file contains the file structure pointing to the file being read 582 * by the kernel. 583 * @id kernel read file identifier 584 * Return 0 if permission is granted. 585 * @kernel_post_read_file: 586 * Read a file specified by userspace. 587 * @file contains the file structure pointing to the file being read 588 * by the kernel. 589 * @buf pointer to buffer containing the file contents. 590 * @size length of the file contents. 591 * @id kernel read file identifier 592 * Return 0 if permission is granted. 593 * @task_fix_setuid: 594 * Update the module's state after setting one or more of the user 595 * identity attributes of the current process. The @flags parameter 596 * indicates which of the set*uid system calls invoked this hook. If 597 * @new is the set of credentials that will be installed. Modifications 598 * should be made to this rather than to @current->cred. 599 * @old is the set of credentials that are being replaces 600 * @flags contains one of the LSM_SETID_* values. 601 * Return 0 on success. 602 * @task_setpgid: 603 * Check permission before setting the process group identifier of the 604 * process @p to @pgid. 605 * @p contains the task_struct for process being modified. 606 * @pgid contains the new pgid. 607 * Return 0 if permission is granted. 608 * @task_getpgid: 609 * Check permission before getting the process group identifier of the 610 * process @p. 611 * @p contains the task_struct for the process. 612 * Return 0 if permission is granted. 613 * @task_getsid: 614 * Check permission before getting the session identifier of the process 615 * @p. 616 * @p contains the task_struct for the process. 617 * Return 0 if permission is granted. 618 * @task_getsecid: 619 * Retrieve the security identifier of the process @p. 620 * @p contains the task_struct for the process and place is into @secid. 621 * In case of failure, @secid will be set to zero. 622 * 623 * @task_setnice: 624 * Check permission before setting the nice value of @p to @nice. 625 * @p contains the task_struct of process. 626 * @nice contains the new nice value. 627 * Return 0 if permission is granted. 628 * @task_setioprio 629 * Check permission before setting the ioprio value of @p to @ioprio. 630 * @p contains the task_struct of process. 631 * @ioprio contains the new ioprio value 632 * Return 0 if permission is granted. 633 * @task_getioprio 634 * Check permission before getting the ioprio value of @p. 635 * @p contains the task_struct of process. 636 * Return 0 if permission is granted. 637 * @task_prlimit: 638 * Check permission before getting and/or setting the resource limits of 639 * another task. 640 * @cred points to the cred structure for the current task. 641 * @tcred points to the cred structure for the target task. 642 * @flags contains the LSM_PRLIMIT_* flag bits indicating whether the 643 * resource limits are being read, modified, or both. 644 * Return 0 if permission is granted. 645 * @task_setrlimit: 646 * Check permission before setting the resource limits of process @p 647 * for @resource to @new_rlim. The old resource limit values can 648 * be examined by dereferencing (p->signal->rlim + resource). 649 * @p points to the task_struct for the target task's group leader. 650 * @resource contains the resource whose limit is being set. 651 * @new_rlim contains the new limits for @resource. 652 * Return 0 if permission is granted. 653 * @task_setscheduler: 654 * Check permission before setting scheduling policy and/or parameters of 655 * process @p based on @policy and @lp. 656 * @p contains the task_struct for process. 657 * @policy contains the scheduling policy. 658 * @lp contains the scheduling parameters. 659 * Return 0 if permission is granted. 660 * @task_getscheduler: 661 * Check permission before obtaining scheduling information for process 662 * @p. 663 * @p contains the task_struct for process. 664 * Return 0 if permission is granted. 665 * @task_movememory 666 * Check permission before moving memory owned by process @p. 667 * @p contains the task_struct for process. 668 * Return 0 if permission is granted. 669 * @task_kill: 670 * Check permission before sending signal @sig to @p. @info can be NULL, 671 * the constant 1, or a pointer to a siginfo structure. If @info is 1 or 672 * SI_FROMKERNEL(info) is true, then the signal should be viewed as coming 673 * from the kernel and should typically be permitted. 674 * SIGIO signals are handled separately by the send_sigiotask hook in 675 * file_security_ops. 676 * @p contains the task_struct for process. 677 * @info contains the signal information. 678 * @sig contains the signal value. 679 * @cred contains the cred of the process where the signal originated, or 680 * NULL if the current task is the originator. 681 * Return 0 if permission is granted. 682 * @task_prctl: 683 * Check permission before performing a process control operation on the 684 * current process. 685 * @option contains the operation. 686 * @arg2 contains a argument. 687 * @arg3 contains a argument. 688 * @arg4 contains a argument. 689 * @arg5 contains a argument. 690 * Return -ENOSYS if no-one wanted to handle this op, any other value to 691 * cause prctl() to return immediately with that value. 692 * @task_to_inode: 693 * Set the security attributes for an inode based on an associated task's 694 * security attributes, e.g. for /proc/pid inodes. 695 * @p contains the task_struct for the task. 696 * @inode contains the inode structure for the inode. 697 * 698 * Security hooks for Netlink messaging. 699 * 700 * @netlink_send: 701 * Save security information for a netlink message so that permission 702 * checking can be performed when the message is processed. The security 703 * information can be saved using the eff_cap field of the 704 * netlink_skb_parms structure. Also may be used to provide fine 705 * grained control over message transmission. 706 * @sk associated sock of task sending the message. 707 * @skb contains the sk_buff structure for the netlink message. 708 * Return 0 if the information was successfully saved and message 709 * is allowed to be transmitted. 710 * 711 * Security hooks for Unix domain networking. 712 * 713 * @unix_stream_connect: 714 * Check permissions before establishing a Unix domain stream connection 715 * between @sock and @other. 716 * @sock contains the sock structure. 717 * @other contains the peer sock structure. 718 * @newsk contains the new sock structure. 719 * Return 0 if permission is granted. 720 * @unix_may_send: 721 * Check permissions before connecting or sending datagrams from @sock to 722 * @other. 723 * @sock contains the socket structure. 724 * @other contains the peer socket structure. 725 * Return 0 if permission is granted. 726 * 727 * The @unix_stream_connect and @unix_may_send hooks were necessary because 728 * Linux provides an alternative to the conventional file name space for Unix 729 * domain sockets. Whereas binding and connecting to sockets in the file name 730 * space is mediated by the typical file permissions (and caught by the mknod 731 * and permission hooks in inode_security_ops), binding and connecting to 732 * sockets in the abstract name space is completely unmediated. Sufficient 733 * control of Unix domain sockets in the abstract name space isn't possible 734 * using only the socket layer hooks, since we need to know the actual target 735 * socket, which is not looked up until we are inside the af_unix code. 736 * 737 * Security hooks for socket operations. 738 * 739 * @socket_create: 740 * Check permissions prior to creating a new socket. 741 * @family contains the requested protocol family. 742 * @type contains the requested communications type. 743 * @protocol contains the requested protocol. 744 * @kern set to 1 if a kernel socket. 745 * Return 0 if permission is granted. 746 * @socket_post_create: 747 * This hook allows a module to update or allocate a per-socket security 748 * structure. Note that the security field was not added directly to the 749 * socket structure, but rather, the socket security information is stored 750 * in the associated inode. Typically, the inode alloc_security hook will 751 * allocate and and attach security information to 752 * sock->inode->i_security. This hook may be used to update the 753 * sock->inode->i_security field with additional information that wasn't 754 * available when the inode was allocated. 755 * @sock contains the newly created socket structure. 756 * @family contains the requested protocol family. 757 * @type contains the requested communications type. 758 * @protocol contains the requested protocol. 759 * @kern set to 1 if a kernel socket. 760 * @socket_bind: 761 * Check permission before socket protocol layer bind operation is 762 * performed and the socket @sock is bound to the address specified in the 763 * @address parameter. 764 * @sock contains the socket structure. 765 * @address contains the address to bind to. 766 * @addrlen contains the length of address. 767 * Return 0 if permission is granted. 768 * @socket_connect: 769 * Check permission before socket protocol layer connect operation 770 * attempts to connect socket @sock to a remote address, @address. 771 * @sock contains the socket structure. 772 * @address contains the address of remote endpoint. 773 * @addrlen contains the length of address. 774 * Return 0 if permission is granted. 775 * @socket_listen: 776 * Check permission before socket protocol layer listen operation. 777 * @sock contains the socket structure. 778 * @backlog contains the maximum length for the pending connection queue. 779 * Return 0 if permission is granted. 780 * @socket_accept: 781 * Check permission before accepting a new connection. Note that the new 782 * socket, @newsock, has been created and some information copied to it, 783 * but the accept operation has not actually been performed. 784 * @sock contains the listening socket structure. 785 * @newsock contains the newly created server socket for connection. 786 * Return 0 if permission is granted. 787 * @socket_sendmsg: 788 * Check permission before transmitting a message to another socket. 789 * @sock contains the socket structure. 790 * @msg contains the message to be transmitted. 791 * @size contains the size of message. 792 * Return 0 if permission is granted. 793 * @socket_recvmsg: 794 * Check permission before receiving a message from a socket. 795 * @sock contains the socket structure. 796 * @msg contains the message structure. 797 * @size contains the size of message structure. 798 * @flags contains the operational flags. 799 * Return 0 if permission is granted. 800 * @socket_getsockname: 801 * Check permission before the local address (name) of the socket object 802 * @sock is retrieved. 803 * @sock contains the socket structure. 804 * Return 0 if permission is granted. 805 * @socket_getpeername: 806 * Check permission before the remote address (name) of a socket object 807 * @sock is retrieved. 808 * @sock contains the socket structure. 809 * Return 0 if permission is granted. 810 * @socket_getsockopt: 811 * Check permissions before retrieving the options associated with socket 812 * @sock. 813 * @sock contains the socket structure. 814 * @level contains the protocol level to retrieve option from. 815 * @optname contains the name of option to retrieve. 816 * Return 0 if permission is granted. 817 * @socket_setsockopt: 818 * Check permissions before setting the options associated with socket 819 * @sock. 820 * @sock contains the socket structure. 821 * @level contains the protocol level to set options for. 822 * @optname contains the name of the option to set. 823 * Return 0 if permission is granted. 824 * @socket_shutdown: 825 * Checks permission before all or part of a connection on the socket 826 * @sock is shut down. 827 * @sock contains the socket structure. 828 * @how contains the flag indicating how future sends and receives 829 * are handled. 830 * Return 0 if permission is granted. 831 * @socket_sock_rcv_skb: 832 * Check permissions on incoming network packets. This hook is distinct 833 * from Netfilter's IP input hooks since it is the first time that the 834 * incoming sk_buff @skb has been associated with a particular socket, @sk. 835 * Must not sleep inside this hook because some callers hold spinlocks. 836 * @sk contains the sock (not socket) associated with the incoming sk_buff. 837 * @skb contains the incoming network data. 838 * @socket_getpeersec_stream: 839 * This hook allows the security module to provide peer socket security 840 * state for unix or connected tcp sockets to userspace via getsockopt 841 * SO_GETPEERSEC. For tcp sockets this can be meaningful if the 842 * socket is associated with an ipsec SA. 843 * @sock is the local socket. 844 * @optval userspace memory where the security state is to be copied. 845 * @optlen userspace int where the module should copy the actual length 846 * of the security state. 847 * @len as input is the maximum length to copy to userspace provided 848 * by the caller. 849 * Return 0 if all is well, otherwise, typical getsockopt return 850 * values. 851 * @socket_getpeersec_dgram: 852 * This hook allows the security module to provide peer socket security 853 * state for udp sockets on a per-packet basis to userspace via 854 * getsockopt SO_GETPEERSEC. The application must first have indicated 855 * the IP_PASSSEC option via getsockopt. It can then retrieve the 856 * security state returned by this hook for a packet via the SCM_SECURITY 857 * ancillary message type. 858 * @skb is the skbuff for the packet being queried 859 * @secdata is a pointer to a buffer in which to copy the security data 860 * @seclen is the maximum length for @secdata 861 * Return 0 on success, error on failure. 862 * @sk_alloc_security: 863 * Allocate and attach a security structure to the sk->sk_security field, 864 * which is used to copy security attributes between local stream sockets. 865 * @sk_free_security: 866 * Deallocate security structure. 867 * @sk_clone_security: 868 * Clone/copy security structure. 869 * @sk_getsecid: 870 * Retrieve the LSM-specific secid for the sock to enable caching 871 * of network authorizations. 872 * @sock_graft: 873 * Sets the socket's isec sid to the sock's sid. 874 * @inet_conn_request: 875 * Sets the openreq's sid to socket's sid with MLS portion taken 876 * from peer sid. 877 * @inet_csk_clone: 878 * Sets the new child socket's sid to the openreq sid. 879 * @inet_conn_established: 880 * Sets the connection's peersid to the secmark on skb. 881 * @secmark_relabel_packet: 882 * check if the process should be allowed to relabel packets to 883 * the given secid 884 * @security_secmark_refcount_inc 885 * tells the LSM to increment the number of secmark labeling rules loaded 886 * @security_secmark_refcount_dec 887 * tells the LSM to decrement the number of secmark labeling rules loaded 888 * @req_classify_flow: 889 * Sets the flow's sid to the openreq sid. 890 * @tun_dev_alloc_security: 891 * This hook allows a module to allocate a security structure for a TUN 892 * device. 893 * @security pointer to a security structure pointer. 894 * Returns a zero on success, negative values on failure. 895 * @tun_dev_free_security: 896 * This hook allows a module to free the security structure for a TUN 897 * device. 898 * @security pointer to the TUN device's security structure 899 * @tun_dev_create: 900 * Check permissions prior to creating a new TUN device. 901 * @tun_dev_attach_queue: 902 * Check permissions prior to attaching to a TUN device queue. 903 * @security pointer to the TUN device's security structure. 904 * @tun_dev_attach: 905 * This hook can be used by the module to update any security state 906 * associated with the TUN device's sock structure. 907 * @sk contains the existing sock structure. 908 * @security pointer to the TUN device's security structure. 909 * @tun_dev_open: 910 * This hook can be used by the module to update any security state 911 * associated with the TUN device's security structure. 912 * @security pointer to the TUN devices's security structure. 913 * 914 * Security hooks for SCTP 915 * 916 * @sctp_assoc_request: 917 * Passes the @ep and @chunk->skb of the association INIT packet to 918 * the security module. 919 * @ep pointer to sctp endpoint structure. 920 * @skb pointer to skbuff of association packet. 921 * Return 0 on success, error on failure. 922 * @sctp_bind_connect: 923 * Validiate permissions required for each address associated with sock 924 * @sk. Depending on @optname, the addresses will be treated as either 925 * for a connect or bind service. The @addrlen is calculated on each 926 * ipv4 and ipv6 address using sizeof(struct sockaddr_in) or 927 * sizeof(struct sockaddr_in6). 928 * @sk pointer to sock structure. 929 * @optname name of the option to validate. 930 * @address list containing one or more ipv4/ipv6 addresses. 931 * @addrlen total length of address(s). 932 * Return 0 on success, error on failure. 933 * @sctp_sk_clone: 934 * Called whenever a new socket is created by accept(2) (i.e. a TCP 935 * style socket) or when a socket is 'peeled off' e.g userspace 936 * calls sctp_peeloff(3). 937 * @ep pointer to current sctp endpoint structure. 938 * @sk pointer to current sock structure. 939 * @sk pointer to new sock structure. 940 * 941 * Security hooks for Infiniband 942 * 943 * @ib_pkey_access: 944 * Check permission to access a pkey when modifing a QP. 945 * @subnet_prefix the subnet prefix of the port being used. 946 * @pkey the pkey to be accessed. 947 * @sec pointer to a security structure. 948 * @ib_endport_manage_subnet: 949 * Check permissions to send and receive SMPs on a end port. 950 * @dev_name the IB device name (i.e. mlx4_0). 951 * @port_num the port number. 952 * @sec pointer to a security structure. 953 * @ib_alloc_security: 954 * Allocate a security structure for Infiniband objects. 955 * @sec pointer to a security structure pointer. 956 * Returns 0 on success, non-zero on failure 957 * @ib_free_security: 958 * Deallocate an Infiniband security structure. 959 * @sec contains the security structure to be freed. 960 * 961 * Security hooks for XFRM operations. 962 * 963 * @xfrm_policy_alloc_security: 964 * @ctxp is a pointer to the xfrm_sec_ctx being added to Security Policy 965 * Database used by the XFRM system. 966 * @sec_ctx contains the security context information being provided by 967 * the user-level policy update program (e.g., setkey). 968 * Allocate a security structure to the xp->security field; the security 969 * field is initialized to NULL when the xfrm_policy is allocated. 970 * Return 0 if operation was successful (memory to allocate, legal context) 971 * @gfp is to specify the context for the allocation 972 * @xfrm_policy_clone_security: 973 * @old_ctx contains an existing xfrm_sec_ctx. 974 * @new_ctxp contains a new xfrm_sec_ctx being cloned from old. 975 * Allocate a security structure in new_ctxp that contains the 976 * information from the old_ctx structure. 977 * Return 0 if operation was successful (memory to allocate). 978 * @xfrm_policy_free_security: 979 * @ctx contains the xfrm_sec_ctx 980 * Deallocate xp->security. 981 * @xfrm_policy_delete_security: 982 * @ctx contains the xfrm_sec_ctx. 983 * Authorize deletion of xp->security. 984 * @xfrm_state_alloc: 985 * @x contains the xfrm_state being added to the Security Association 986 * Database by the XFRM system. 987 * @sec_ctx contains the security context information being provided by 988 * the user-level SA generation program (e.g., setkey or racoon). 989 * Allocate a security structure to the x->security field; the security 990 * field is initialized to NULL when the xfrm_state is allocated. Set the 991 * context to correspond to sec_ctx. Return 0 if operation was successful 992 * (memory to allocate, legal context). 993 * @xfrm_state_alloc_acquire: 994 * @x contains the xfrm_state being added to the Security Association 995 * Database by the XFRM system. 996 * @polsec contains the policy's security context. 997 * @secid contains the secid from which to take the mls portion of the 998 * context. 999 * Allocate a security structure to the x->security field; the security 1000 * field is initialized to NULL when the xfrm_state is allocated. Set the
1001 * context to correspond to secid. Return 0 if operation was successful 1002 * (memory to allocate, legal context). 1003 * @xfrm_state_free_security: 1004 * @x contains the xfrm_state. 1005 * Deallocate x->security. 1006 * @xfrm_state_delete_security: 1007 * @x contains the xfrm_state. 1008 * Authorize deletion of x->security. 1009 * @xfrm_policy_lookup: 1010 * @ctx contains the xfrm_sec_ctx for which the access control is being 1011 * checked. 1012 * @fl_secid contains the flow security label that is used to authorize 1013 * access to the policy xp. 1014 * @dir contains the direction of the flow (input or output). 1015 * Check permission when a flow selects a xfrm_policy for processing 1016 * XFRMs on a packet. The hook is called when selecting either a 1017 * per-socket policy or a generic xfrm policy. 1018 * Return 0 if permission is granted, -ESRCH otherwise, or -errno 1019 * on other errors. 1020 * @xfrm_state_pol_flow_match: 1021 * @x contains the state to match. 1022 * @xp contains the policy to check for a match. 1023 * @fl contains the flow to check for a match. 1024 * Return 1 if there is a match. 1025 * @xfrm_decode_session: 1026 * @skb points to skb to decode. 1027 * @secid points to the flow key secid to set. 1028 * @ckall says if all xfrms used should be checked for same secid. 1029 * Return 0 if ckall is zero or all xfrms used have the same secid. 1030 * 1031 * Security hooks affecting all Key Management operations 1032 * 1033 * @key_alloc: 1034 * Permit allocation of a key and assign security data. Note that key does 1035 * not have a serial number assigned at this point. 1036 * @key points to the key. 1037 * @flags is the allocation flags 1038 * Return 0 if permission is granted, -ve error otherwise. 1039 * @key_free: 1040 * Notification of destruction; free security data. 1041 * @key points to the key. 1042 * No return value. 1043 * @key_permission: 1044 * See whether a specific operational right is granted to a process on a 1045 * key. 1046 * @key_ref refers to the key (key pointer + possession attribute bit). 1047 * @cred points to the credentials to provide the context against which to 1048 * evaluate the security data on the key. 1049 * @perm describes the combination of permissions required of this key. 1050 * Return 0 if permission is granted, -ve error otherwise. 1051 * @key_getsecurity: 1052 * Get a textual representation of the security context attached to a key 1053 * for the purposes of honouring KEYCTL_GETSECURITY. This function 1054 * allocates the storage for the NUL-terminated string and the caller 1055 * should free it. 1056 * @key points to the key to be queried. 1057 * @_buffer points to a pointer that should be set to point to the 1058 * resulting string (if no label or an error occurs). 1059 * Return the length of the string (including terminating NUL) or -ve if 1060 * an error. 1061 * May also return 0 (and a NULL buffer pointer) if there is no label. 1062 * 1063 * Security hooks affecting all System V IPC operations. 1064 * 1065 * @ipc_permission: 1066 * Check permissions for access to IPC 1067 * @ipcp contains the kernel IPC permission structure 1068 * @flag contains the desired (requested) permission set 1069 * Return 0 if permission is granted. 1070 * @ipc_getsecid: 1071 * Get the secid associated with the ipc object. 1072 * @ipcp contains the kernel IPC permission structure. 1073 * @secid contains a pointer to the location where result will be saved. 1074 * In case of failure, @secid will be set to zero. 1075 * 1076 * Security hooks for individual messages held in System V IPC message queues 1077 * @msg_msg_alloc_security: 1078 * Allocate and attach a security structure to the msg->security field. 1079 * The security field is initialized to NULL when the structure is first 1080 * created. 1081 * @msg contains the message structure to be modified. 1082 * Return 0 if operation was successful and permission is granted. 1083 * @msg_msg_free_security: 1084 * Deallocate the security structure for this message. 1085 * @msg contains the message structure to be modified. 1086 * 1087 * Security hooks for System V IPC Message Queues 1088 * 1089 * @msg_queue_alloc_security: 1090 * Allocate and attach a security structure to the 1091 * msq->q_perm.security field. The security field is initialized to 1092 * NULL when the structure is first created. 1093 * @msq contains the message queue structure to be modified. 1094 * Return 0 if operation was successful and permission is granted. 1095 * @msg_queue_free_security: 1096 * Deallocate security structure for this message queue. 1097 * @msq contains the message queue structure to be modified. 1098 * @msg_queue_associate: 1099 * Check permission when a message queue is requested through the 1100 * msgget system call. This hook is only called when returning the 1101 * message queue identifier for an existing message queue, not when a 1102 * new message queue is created. 1103 * @msq contains the message queue to act upon. 1104 * @msqflg contains the operation control flags. 1105 * Return 0 if permission is granted. 1106 * @msg_queue_msgctl: 1107 * Check permission when a message control operation specified by @cmd 1108 * is to be performed on the message queue @msq. 1109 * The @msq may be NULL, e.g. for IPC_INFO or MSG_INFO. 1110 * @msq contains the message queue to act upon. May be NULL. 1111 * @cmd contains the operation to be performed. 1112 * Return 0 if permission is granted. 1113 * @msg_queue_msgsnd: 1114 * Check permission before a message, @msg, is enqueued on the message 1115 * queue, @msq. 1116 * @msq contains the message queue to send message to. 1117 * @msg contains the message to be enqueued. 1118 * @msqflg contains operational flags. 1119 * Return 0 if permission is granted. 1120 * @msg_queue_msgrcv: 1121 * Check permission before a message, @msg, is removed from the message 1122 * queue, @msq. The @target task structure contains a pointer to the 1123 * process that will be receiving the message (not equal to the current 1124 * process when inline receives are being performed). 1125 * @msq contains the message queue to retrieve message from. 1126 * @msg contains the message destination. 1127 * @target contains the task structure for recipient process. 1128 * @type contains the type of message requested. 1129 * @mode contains the operational flags. 1130 * Return 0 if permission is granted. 1131 * 1132 * Security hooks for System V Shared Memory Segments 1133 * 1134 * @shm_alloc_security: 1135 * Allocate and attach a security structure to the shp->shm_perm.security 1136 * field. The security field is initialized to NULL when the structure is 1137 * first created. 1138 * @shp contains the shared memory structure to be modified. 1139 * Return 0 if operation was successful and permission is granted. 1140 * @shm_free_security: 1141 * Deallocate the security struct for this memory segment. 1142 * @shp contains the shared memory structure to be modified. 1143 * @shm_associate: 1144 * Check permission when a shared memory region is requested through the 1145 * shmget system call. This hook is only called when returning the shared 1146 * memory region identifier for an existing region, not when a new shared 1147 * memory region is created. 1148 * @shp contains the shared memory structure to be modified. 1149 * @shmflg contains the operation control flags. 1150 * Return 0 if permission is granted. 1151 * @shm_shmctl: 1152 * Check permission when a shared memory control operation specified by 1153 * @cmd is to be performed on the shared memory region @shp. 1154 * The @shp may be NULL, e.g. for IPC_INFO or SHM_INFO. 1155 * @shp contains shared memory structure to be modified. 1156 * @cmd contains the operation to be performed. 1157 * Return 0 if permission is granted. 1158 * @shm_shmat: 1159 * Check permissions prior to allowing the shmat system call to attach the 1160 * shared memory segment @shp to the data segment of the calling process. 1161 * The attaching address is specified by @shmaddr. 1162 * @shp contains the shared memory structure to be modified. 1163 * @shmaddr contains the address to attach memory region to. 1164 * @shmflg contains the operational flags. 1165 * Return 0 if permission is granted. 1166 * 1167 * Security hooks for System V Semaphores 1168 * 1169 * @sem_alloc_security: 1170 * Allocate and attach a security structure to the sma->sem_perm.security 1171 * field. The security field is initialized to NULL when the structure is 1172 * first created. 1173 * @sma contains the semaphore structure 1174 * Return 0 if operation was successful and permission is granted. 1175 * @sem_free_security: 1176 * deallocate security struct for this semaphore 1177 * @sma contains the semaphore structure. 1178 * @sem_associate: 1179 * Check permission when a semaphore is requested through the semget 1180 * system call. This hook is only called when returning the semaphore 1181 * identifier for an existing semaphore, not when a new one must be 1182 * created. 1183 * @sma contains the semaphore structure. 1184 * @semflg contains the operation control flags. 1185 * Return 0 if permission is granted. 1186 * @sem_semctl: 1187 * Check permission when a semaphore operation specified by @cmd is to be 1188 * performed on the semaphore @sma. The @sma may be NULL, e.g. for 1189 * IPC_INFO or SEM_INFO. 1190 * @sma contains the semaphore structure. May be NULL. 1191 * @cmd contains the operation to be performed. 1192 * Return 0 if permission is granted. 1193 * @sem_semop: 1194 * Check permissions before performing operations on members of the 1195 * semaphore set @sma. If the @alter flag is nonzero, the semaphore set 1196 * may be modified. 1197 * @sma contains the semaphore structure. 1198 * @sops contains the operations to perform. 1199 * @nsops contains the number of operations to perform. 1200 * @alter contains the flag indicating whether changes are to be made. 1201 * Return 0 if permission is granted. 1202 * 1203 * @binder_set_context_mgr: 1204 * Check whether @mgr is allowed to be the binder context manager. 1205 * @mgr contains the task_struct for the task being registered. 1206 * Return 0 if permission is granted. 1207 * @binder_transaction: 1208 * Check whether @from is allowed to invoke a binder transaction call 1209 * to @to. 1210 * @from contains the task_struct for the sending task. 1211 * @to contains the task_struct for the receiving task. 1212 * @binder_transfer_binder: 1213 * Check whether @from is allowed to transfer a binder reference to @to. 1214 * @from contains the task_struct for the sending task. 1215 * @to contains the task_struct for the receiving task. 1216 * @binder_transfer_file: 1217 * Check whether @from is allowed to transfer @file to @to. 1218 * @from contains the task_struct for the sending task. 1219 * @file contains the struct file being transferred. 1220 * @to contains the task_struct for the receiving task. 1221 * 1222 * @ptrace_access_check: 1223 * Check permission before allowing the current process to trace the 1224 * @child process. 1225 * Security modules may also want to perform a process tracing check 1226 * during an execve in the set_security or apply_creds hooks of 1227 * tracing check during an execve in the bprm_set_creds hook of 1228 * binprm_security_ops if the process is being traced and its security 1229 * attributes would be changed by the execve. 1230 * @child contains the task_struct structure for the target process. 1231 * @mode contains the PTRACE_MODE flags indicating the form of access. 1232 * Return 0 if permission is granted. 1233 * @ptrace_traceme: 1234 * Check that the @parent process has sufficient permission to trace the 1235 * current process before allowing the current process to present itself 1236 * to the @parent process for tracing. 1237 * @parent contains the task_struct structure for debugger process. 1238 * Return 0 if permission is granted. 1239 * @capget: 1240 * Get the @effective, @inheritable, and @permitted capability sets for 1241 * the @target process. The hook may also perform permission checking to 1242 * determine if the current process is allowed to see the capability sets 1243 * of the @target process. 1244 * @target contains the task_struct structure for target process. 1245 * @effective contains the effective capability set. 1246 * @inheritable contains the inheritable capability set. 1247 * @permitted contains the permitted capability set. 1248 * Return 0 if the capability sets were successfully obtained. 1249 * @capset: 1250 * Set the @effective, @inheritable, and @permitted capability sets for 1251 * the current process. 1252 * @new contains the new credentials structure for target process. 1253 * @old contains the current credentials structure for target process. 1254 * @effective contains the effective capability set. 1255 * @inheritable contains the inheritable capability set. 1256 * @permitted contains the permitted capability set. 1257 * Return 0 and update @new if permission is granted. 1258 * @capable: 1259 * Check whether the @tsk process has the @cap capability in the indicated 1260 * credentials. 1261 * @cred contains the credentials to use. 1262 * @ns contains the user namespace we want the capability in 1263 * @cap contains the capability <include/linux/capability.h>. 1264 * @audit contains whether to write an audit message or not 1265 * Return 0 if the capability is granted for @tsk. 1266 * @syslog: 1267 * Check permission before accessing the kernel message ring or changing 1268 * logging to the console. 1269 * See the syslog(2) manual page for an explanation of the @type values. 1270 * @type contains the type of action. 1271 * @from_file indicates the context of action (if it came from /proc). 1272 * Return 0 if permission is granted. 1273 * @settime: 1274 * Check permission to change the system time. 1275 * struct timespec64 is defined in include/linux/time64.h and timezone 1276 * is defined in include/linux/time.h 1277 * @ts contains new time 1278 * @tz contains new timezone 1279 * Return 0 if permission is granted. 1280 * @vm_enough_memory: 1281 * Check permissions for allocating a new virtual mapping. 1282 * @mm contains the mm struct it is being added to. 1283 * @pages contains the number of pages. 1284 * Return 0 if permission is granted. 1285 * 1286 * @ismaclabel: 1287 * Check if the extended attribute specified by @name 1288 * represents a MAC label. Returns 1 if name is a MAC 1289 * attribute otherwise returns 0. 1290 * @name full extended attribute name to check against 1291 * LSM as a MAC label. 1292 * 1293 * @secid_to_secctx: 1294 * Convert secid to security context. If secdata is NULL the length of 1295 * the result will be returned in seclen, but no secdata will be returned. 1296 * This does mean that the length could change between calls to check the 1297 * length and the next call which actually allocates and returns the 1298 * secdata. 1299 * @secid contains the security ID. 1300 * @secdata contains the pointer that stores the converted security 1301 * context. 1302 * @seclen pointer which contains the length of the data 1303 * @secctx_to_secid: 1304 * Convert security context to secid. 1305 * @secid contains the pointer to the generated security ID. 1306 * @secdata contains the security context. 1307 * 1308 * @release_secctx: 1309 * Release the security context. 1310 * @secdata contains the security context. 1311 * @seclen contains the length of the security context. 1312 * 1313 * Security hooks for Audit 1314 * 1315 * @audit_rule_init: 1316 * Allocate and initialize an LSM audit rule structure. 1317 * @field contains the required Audit action. 1318 * Fields flags are defined in include/linux/audit.h 1319 * @op contains the operator the rule uses. 1320 * @rulestr contains the context where the rule will be applied to. 1321 * @lsmrule contains a pointer to receive the result. 1322 * Return 0 if @lsmrule has been successfully set, 1323 * -EINVAL in case of an invalid rule. 1324 * 1325 * @audit_rule_known: 1326 * Specifies whether given @rule contains any fields related to 1327 * current LSM. 1328 * @rule contains the audit rule of interest. 1329 * Return 1 in case of relation found, 0 otherwise. 1330 * 1331 * @audit_rule_match: 1332 * Determine if given @secid matches a rule previously approved 1333 * by @audit_rule_known. 1334 * @secid contains the security id in question. 1335 * @field contains the field which relates to current LSM. 1336 * @op contains the operator that will be used for matching. 1337 * @rule points to the audit rule that will be checked against. 1338 * @actx points to the audit context associated with the check. 1339 * Return 1 if secid matches the rule, 0 if it does not, -ERRNO on failure. 1340 * 1341 * @audit_rule_free: 1342 * Deallocate the LSM audit rule structure previously allocated by 1343 * audit_rule_init. 1344 * @rule contains the allocated rule 1345 * 1346 * @inode_invalidate_secctx: 1347 * Notify the security module that it must revalidate the security context 1348 * of an inode. 1349 * 1350 * @inode_notifysecctx: 1351 * Notify the security module of what the security context of an inode 1352 * should be. Initializes the incore security context managed by the 1353 * security module for this inode. Example usage: NFS client invokes 1354 * this hook to initialize the security context in its incore inode to the 1355 * value provided by the server for the file when the server returned the 1356 * file's attributes to the client. 1357 * 1358 * Must be called with inode->i_mutex locked. 1359 * 1360 * @inode we wish to set the security context of. 1361 * @ctx contains the string which we wish to set in the inode. 1362 * @ctxlen contains the length of @ctx. 1363 * 1364 * @inode_setsecctx: 1365 * Change the security context of an inode. Updates the 1366 * incore security context managed by the security module and invokes the 1367 * fs code as needed (via __vfs_setxattr_noperm) to update any backing 1368 * xattrs that represent the context. Example usage: NFS server invokes 1369 * this hook to change the security context in its incore inode and on the 1370 * backing filesystem to a value provided by the client on a SETATTR 1371 * operation. 1372 * 1373 * Must be called with inode->i_mutex locked. 1374 * 1375 * @dentry contains the inode we wish to set the security context of. 1376 * @ctx contains the string which we wish to set in the inode. 1377 * @ctxlen contains the length of @ctx. 1378 * 1379 * @inode_getsecctx: 1380 * On success, returns 0 and fills out @ctx and @ctxlen with the security 1381 * context for the given @inode. 1382 * 1383 * @inode we wish to get the security context of. 1384 * @ctx is a pointer in which to place the allocated security context. 1385 * @ctxlen points to the place to put the length of @ctx. 1386 * 1387 * Security hooks for using the eBPF maps and programs functionalities through 1388 * eBPF syscalls. 1389 * 1390 * @bpf: 1391 * Do a initial check for all bpf syscalls after the attribute is copied 1392 * into the kernel. The actual security module can implement their own 1393 * rules to check the specific cmd they need. 1394 * 1395 * @bpf_map: 1396 * Do a check when the kernel generate and return a file descriptor for 1397 * eBPF maps. 1398 * 1399 * @map: bpf map that we want to access 1400 * @mask: the access flags 1401 * 1402 * @bpf_prog: 1403 * Do a check when the kernel generate and return a file descriptor for 1404 * eBPF programs. 1405 * 1406 * @prog: bpf prog that userspace want to use. 1407 * 1408 * @bpf_map_alloc_security: 1409 * Initialize the security field inside bpf map. 1410 * 1411 * @bpf_map_free_security: 1412 * Clean up the security information stored inside bpf map. 1413 * 1414 * @bpf_prog_alloc_security: 1415 * Initialize the security field inside bpf program. 1416 * 1417 * @bpf_prog_free_security: 1418 * Clean up the security information stored inside bpf prog. 1419 * 1420 */ 1421union security_list_options { 1422 int (*binder_set_context_mgr)(struct task_struct *mgr); 1423 int (*binder_transaction)(struct task_struct *from, 1424 struct task_struct *to); 1425 int (*binder_transfer_binder)(struct task_struct *from, 1426 struct task_struct *to); 1427 int (*binder_transfer_file)(struct task_struct *from, 1428 struct task_struct *to, 1429 struct file *file); 1430 1431 int (*ptrace_access_check)(struct task_struct *child, 1432 unsigned int mode); 1433 int (*ptrace_traceme)(struct task_struct *parent); 1434 int (*capget)(struct task_struct *target, kernel_cap_t *effective, 1435 kernel_cap_t *inheritable, kernel_cap_t *permitted); 1436 int (*capset)(struct cred *new, const struct cred *old, 1437 const kernel_cap_t *effective, 1438 const kernel_cap_t *inheritable, 1439 const kernel_cap_t *permitted); 1440 int (*capable)(const struct cred *cred, struct user_namespace *ns, 1441 int cap, int audit); 1442 int (*quotactl)(int cmds, int type, int id, struct super_block *sb); 1443 int (*quota_on)(struct dentry *dentry); 1444 int (*syslog)(int type); 1445 int (*settime)(const struct timespec64 *ts, const struct timezone *tz); 1446 int (*vm_enough_memory)(struct mm_struct *mm, long pages); 1447 1448 int (*bprm_set_creds)(struct linux_binprm *bprm); 1449 int (*bprm_check_security)(struct linux_binprm *bprm); 1450 void (*bprm_committing_creds)(struct linux_binprm *bprm); 1451 void (*bprm_committed_creds)(struct linux_binprm *bprm); 1452 1453 int (*sb_alloc_security)(struct super_block *sb); 1454 void (*sb_free_security)(struct super_block *sb); 1455 int (*sb_copy_data)(char *orig, char *copy); 1456 int (*sb_remount)(struct super_block *sb, void *data); 1457 int (*sb_kern_mount)(struct super_block *sb, int flags, void *data); 1458 int (*sb_show_options)(struct seq_file *m, struct super_block *sb); 1459 int (*sb_statfs)(struct dentry *dentry); 1460 int (*sb_mount)(const char *dev_name, const struct path *path, 1461 const char *type, unsigned long flags, void *data); 1462 int (*sb_umount)(struct vfsmount *mnt, int flags); 1463 int (*sb_pivotroot)(const struct path *old_path, const struct path *new_path); 1464 int (*sb_set_mnt_opts)(struct super_block *sb, 1465 struct security_mnt_opts *opts, 1466 unsigned long kern_flags, 1467 unsigned long *set_kern_flags); 1468 int (*sb_clone_mnt_opts)(const struct super_block *oldsb, 1469 struct super_block *newsb, 1470 unsigned long kern_flags, 1471 unsigned long *set_kern_flags); 1472 int (*sb_parse_opts_str)(char *options, struct security_mnt_opts *opts); 1473 int (*dentry_init_security)(struct dentry *dentry, int mode, 1474 const struct qstr *name, void **ctx, 1475 u32 *ctxlen); 1476 int (*dentry_create_files_as)(struct dentry *dentry, int mode, 1477 struct qstr *name, 1478 const struct cred *old, 1479 struct cred *new); 1480 1481 1482#ifdef CONFIG_SECURITY_PATH 1483 int (*path_unlink)(const struct path *dir, struct dentry *dentry); 1484 int (*path_mkdir)(const struct path *dir, struct dentry *dentry, 1485 umode_t mode); 1486 int (*path_rmdir)(const struct path *dir, struct dentry *dentry); 1487 int (*path_mknod)(const struct path *dir, struct dentry *dentry, 1488 umode_t mode, unsigned int dev); 1489 int (*path_truncate)(const struct path *path); 1490 int (*path_symlink)(const struct path *dir, struct dentry *dentry, 1491 const char *old_name); 1492 int (*path_link)(struct dentry *old_dentry, const struct path *new_dir, 1493 struct dentry *new_dentry); 1494 int (*path_rename)(const struct path *old_dir, struct dentry *old_dentry, 1495 const struct path *new_dir, 1496 struct dentry *new_dentry); 1497 int (*path_chmod)(const struct path *path, umode_t mode); 1498 int (*path_chown)(const struct path *path, kuid_t uid, kgid_t gid); 1499 int (*path_chroot)(const struct path *path); 1500#endif 1501 1502 int (*inode_alloc_security)(struct inode *inode); 1503 void (*inode_free_security)(struct inode *inode); 1504 int (*inode_init_security)(struct inode *inode, struct inode *dir, 1505 const struct qstr *qstr, 1506 const char **name, void **value, 1507 size_t *len); 1508 int (*inode_create)(struct inode *dir, struct dentry *dentry, 1509 umode_t mode); 1510 int (*inode_link)(struct dentry *old_dentry, struct inode *dir, 1511 struct dentry *new_dentry); 1512 int (*inode_unlink)(struct inode *dir, struct dentry *dentry); 1513 int (*inode_symlink)(struct inode *dir, struct dentry *dentry, 1514 const char *old_name); 1515 int (*inode_mkdir)(struct inode *dir, struct dentry *dentry, 1516 umode_t mode); 1517 int (*inode_rmdir)(struct inode *dir, struct dentry *dentry); 1518 int (*inode_mknod)(struct inode *dir, struct dentry *dentry, 1519 umode_t mode, dev_t dev); 1520 int (*inode_rename)(struct inode *old_dir, struct dentry *old_dentry, 1521 struct inode *new_dir, 1522 struct dentry *new_dentry); 1523 int (*inode_readlink)(struct dentry *dentry); 1524 int (*inode_follow_link)(struct dentry *dentry, struct inode *inode, 1525 bool rcu); 1526 int (*inode_permission)(struct inode *inode, int mask); 1527 int (*inode_setattr)(struct dentry *dentry, struct iattr *attr); 1528 int (*inode_getattr)(const struct path *path); 1529 int (*inode_setxattr)(struct dentry *dentry, const char *name, 1530 const void *value, size_t size, int flags); 1531 void (*inode_post_setxattr)(struct dentry *dentry, const char *name, 1532 const void *value, size_t size, 1533 int flags); 1534 int (*inode_getxattr)(struct dentry *dentry, const char *name); 1535 int (*inode_listxattr)(struct dentry *dentry); 1536 int (*inode_removexattr)(struct dentry *dentry, const char *name); 1537 int (*inode_need_killpriv)(struct dentry *dentry); 1538 int (*inode_killpriv)(struct dentry *dentry); 1539 int (*inode_getsecurity)(struct inode *inode, const char *name, 1540 void **buffer, bool alloc); 1541 int (*inode_setsecurity)(struct inode *inode, const char *name, 1542 const void *value, size_t size, 1543 int flags); 1544 int (*inode_listsecurity)(struct inode *inode, char *buffer, 1545 size_t buffer_size); 1546 void (*inode_getsecid)(struct inode *inode, u32 *secid); 1547 int (*inode_copy_up)(struct dentry *src, struct cred **new); 1548 int (*inode_copy_up_xattr)(const char *name); 1549 1550 int (*file_permission)(struct file *file, int mask); 1551 int (*file_alloc_security)(struct file *file); 1552 void (*file_free_security)(struct file *file); 1553 int (*file_ioctl)(struct file *file, unsigned int cmd, 1554 unsigned long arg); 1555 int (*mmap_addr)(unsigned long addr); 1556 int (*mmap_file)(struct file *file, unsigned long reqprot, 1557 unsigned long prot, unsigned long flags); 1558 int (*file_mprotect)(struct vm_area_struct *vma, unsigned long reqprot, 1559 unsigned long prot); 1560 int (*file_lock)(struct file *file, unsigned int cmd); 1561 int (*file_fcntl)(struct file *file, unsigned int cmd, 1562 unsigned long arg); 1563 void (*file_set_fowner)(struct file *file); 1564 int (*file_send_sigiotask)(struct task_struct *tsk, 1565 struct fown_struct *fown, int sig); 1566 int (*file_receive)(struct file *file); 1567 int (*file_open)(struct file *file, const struct cred *cred); 1568 1569 int (*task_alloc)(struct task_struct *task, unsigned long clone_flags); 1570 void (*task_free)(struct task_struct *task); 1571 int (*cred_alloc_blank)(struct cred *cred, gfp_t gfp); 1572 void (*cred_free)(struct cred *cred); 1573 int (*cred_prepare)(struct cred *new, const struct cred *old, 1574 gfp_t gfp); 1575 void (*cred_transfer)(struct cred *new, const struct cred *old); 1576 void (*cred_getsecid)(const struct cred *c, u32 *secid); 1577 int (*kernel_act_as)(struct cred *new, u32 secid); 1578 int (*kernel_create_files_as)(struct cred *new, struct inode *inode); 1579 int (*kernel_module_request)(char *kmod_name); 1580 int (*kernel_read_file)(struct file *file, enum kernel_read_file_id id); 1581 int (*kernel_post_read_file)(struct file *file, char *buf, loff_t size, 1582 enum kernel_read_file_id id); 1583 int (*task_fix_setuid)(struct cred *new, const struct cred *old, 1584 int flags); 1585 int (*task_setpgid)(struct task_struct *p, pid_t pgid); 1586 int (*task_getpgid)(struct task_struct *p); 1587 int (*task_getsid)(struct task_struct *p); 1588 void (*task_getsecid)(struct task_struct *p, u32 *secid); 1589 int (*task_setnice)(struct task_struct *p, int nice); 1590 int (*task_setioprio)(struct task_struct *p, int ioprio); 1591 int (*task_getioprio)(struct task_struct *p); 1592 int (*task_prlimit)(const struct cred *cred, const struct cred *tcred, 1593 unsigned int flags); 1594 int (*task_setrlimit)(struct task_struct *p, unsigned int resource, 1595 struct rlimit *new_rlim); 1596 int (*task_setscheduler)(struct task_struct *p); 1597 int (*task_getscheduler)(struct task_struct *p); 1598 int (*task_movememory)(struct task_struct *p); 1599 int (*task_kill)(struct task_struct *p, struct siginfo *info, 1600 int sig, const struct cred *cred); 1601 int (*task_prctl)(int option, unsigned long arg2, unsigned long arg3, 1602 unsigned long arg4, unsigned long arg5); 1603 void (*task_to_inode)(struct task_struct *p, struct inode *inode); 1604 1605 int (*ipc_permission)(struct kern_ipc_perm *ipcp, short flag); 1606 void (*ipc_getsecid)(struct kern_ipc_perm *ipcp, u32 *secid); 1607 1608 int (*msg_msg_alloc_security)(struct msg_msg *msg); 1609 void (*msg_msg_free_security)(struct msg_msg *msg); 1610 1611 int (*msg_queue_alloc_security)(struct kern_ipc_perm *msq); 1612 void (*msg_queue_free_security)(struct kern_ipc_perm *msq); 1613 int (*msg_queue_associate)(struct kern_ipc_perm *msq, int msqflg); 1614 int (*msg_queue_msgctl)(struct kern_ipc_perm *msq, int cmd); 1615 int (*msg_queue_msgsnd)(struct kern_ipc_perm *msq, struct msg_msg *msg, 1616 int msqflg); 1617 int (*msg_queue_msgrcv)(struct kern_ipc_perm *msq, struct msg_msg *msg, 1618 struct task_struct *target, long type, 1619 int mode); 1620 1621 int (*shm_alloc_security)(struct kern_ipc_perm *shp); 1622 void (*shm_free_security)(struct kern_ipc_perm *shp); 1623 int (*shm_associate)(struct kern_ipc_perm *shp, int shmflg); 1624 int (*shm_shmctl)(struct kern_ipc_perm *shp, int cmd); 1625 int (*shm_shmat)(struct kern_ipc_perm *shp, char __user *shmaddr, 1626 int shmflg); 1627 1628 int (*sem_alloc_security)(struct kern_ipc_perm *sma); 1629 void (*sem_free_security)(struct kern_ipc_perm *sma); 1630 int (*sem_associate)(struct kern_ipc_perm *sma, int semflg); 1631 int (*sem_semctl)(struct kern_ipc_perm *sma, int cmd); 1632 int (*sem_semop)(struct kern_ipc_perm *sma, struct sembuf *sops, 1633 unsigned nsops, int alter); 1634 1635 int (*netlink_send)(struct sock *sk, struct sk_buff *skb); 1636 1637 void (*d_instantiate)(struct dentry *dentry, struct inode *inode); 1638 1639 int (*getprocattr)(struct task_struct *p, char *name, char **value); 1640 int (*setprocattr)(const char *name, void *value, size_t size); 1641 int (*ismaclabel)(const char *name); 1642 int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen); 1643 int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid); 1644 void (*release_secctx)(char *secdata, u32 seclen); 1645 1646 void (*inode_invalidate_secctx)(struct inode *inode); 1647 int (*inode_notifysecctx)(struct inode *inode, void *ctx, u32 ctxlen); 1648 int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen); 1649 int (*inode_getsecctx)(struct inode *inode, void **ctx, u32 *ctxlen); 1650 1651#ifdef CONFIG_SECURITY_NETWORK 1652 int (*unix_stream_connect)(struct sock *sock, struct sock *other, 1653 struct sock *newsk); 1654 int (*unix_may_send)(struct socket *sock, struct socket *other); 1655 1656 int (*socket_create)(int family, int type, int protocol, int kern); 1657 int (*socket_post_create)(struct socket *sock, int family, int type, 1658 int protocol, int kern); 1659 int (*socket_bind)(struct socket *sock, struct sockaddr *address, 1660 int addrlen); 1661 int (*socket_connect)(struct socket *sock, struct sockaddr *address, 1662 int addrlen); 1663 int (*socket_listen)(struct socket *sock, int backlog); 1664 int (*socket_accept)(struct socket *sock, struct socket *newsock); 1665 int (*socket_sendmsg)(struct socket *sock, struct msghdr *msg, 1666 int size); 1667 int (*socket_recvmsg)(struct socket *sock, struct msghdr *msg, 1668 int size, int flags); 1669 int (*socket_getsockname)(struct socket *sock); 1670 int (*socket_getpeername)(struct socket *sock); 1671 int (*socket_getsockopt)(struct socket *sock, int level, int optname); 1672 int (*socket_setsockopt)(struct socket *sock, int level, int optname); 1673 int (*socket_shutdown)(struct socket *sock, int how); 1674 int (*socket_sock_rcv_skb)(struct sock *sk, struct sk_buff *skb); 1675 int (*socket_getpeersec_stream)(struct socket *sock, 1676 char __user *optval, 1677 int __user *optlen, unsigned len); 1678 int (*socket_getpeersec_dgram)(struct socket *sock, 1679 struct sk_buff *skb, u32 *secid); 1680 int (*sk_alloc_security)(struct sock *sk, int family, gfp_t priority); 1681 void (*sk_free_security)(struct sock *sk); 1682 void (*sk_clone_security)(const struct sock *sk, struct sock *newsk); 1683 void (*sk_getsecid)(struct sock *sk, u32 *secid); 1684 void (*sock_graft)(struct sock *sk, struct socket *parent); 1685 int (*inet_conn_request)(struct sock *sk, struct sk_buff *skb, 1686 struct request_sock *req); 1687 void (*inet_csk_clone)(struct sock *newsk, 1688 const struct request_sock *req); 1689 void (*inet_conn_established)(struct sock *sk, struct sk_buff *skb); 1690 int (*secmark_relabel_packet)(u32 secid); 1691 void (*secmark_refcount_inc)(void); 1692 void (*secmark_refcount_dec)(void); 1693 void (*req_classify_flow)(const struct request_sock *req, 1694 struct flowi *fl); 1695 int (*tun_dev_alloc_security)(void **security); 1696 void (*tun_dev_free_security)(void *security); 1697 int (*tun_dev_create)(void); 1698 int (*tun_dev_attach_queue)(void *security); 1699 int (*tun_dev_attach)(struct sock *sk, void *security); 1700 int (*tun_dev_open)(void *security); 1701 int (*sctp_assoc_request)(struct sctp_endpoint *ep, 1702 struct sk_buff *skb); 1703 int (*sctp_bind_connect)(struct sock *sk, int optname, 1704 struct sockaddr *address, int addrlen); 1705 void (*sctp_sk_clone)(struct sctp_endpoint *ep, struct sock *sk, 1706 struct sock *newsk); 1707#endif /* CONFIG_SECURITY_NETWORK */ 1708 1709#ifdef CONFIG_SECURITY_INFINIBAND 1710 int (*ib_pkey_access)(void *sec, u64 subnet_prefix, u16 pkey); 1711 int (*ib_endport_manage_subnet)(void *sec, const char *dev_name, 1712 u8 port_num); 1713 int (*ib_alloc_security)(void **sec); 1714 void (*ib_free_security)(void *sec); 1715#endif /* CONFIG_SECURITY_INFINIBAND */ 1716 1717#ifdef CONFIG_SECURITY_NETWORK_XFRM 1718 int (*xfrm_policy_alloc_security)(struct xfrm_sec_ctx **ctxp, 1719 struct xfrm_user_sec_ctx *sec_ctx, 1720 gfp_t gfp); 1721 int (*xfrm_policy_clone_security)(struct xfrm_sec_ctx *old_ctx, 1722 struct xfrm_sec_ctx **new_ctx); 1723 void (*xfrm_policy_free_security)(struct xfrm_sec_ctx *ctx); 1724 int (*xfrm_policy_delete_security)(struct xfrm_sec_ctx *ctx); 1725 int (*xfrm_state_alloc)(struct xfrm_state *x, 1726 struct xfrm_user_sec_ctx *sec_ctx); 1727 int (*xfrm_state_alloc_acquire)(struct xfrm_state *x, 1728 struct xfrm_sec_ctx *polsec, 1729 u32 secid); 1730 void (*xfrm_state_free_security)(struct xfrm_state *x); 1731 int (*xfrm_state_delete_security)(struct xfrm_state *x); 1732 int (*xfrm_policy_lookup)(struct xfrm_sec_ctx *ctx, u32 fl_secid, 1733 u8 dir); 1734 int (*xfrm_state_pol_flow_match)(struct xfrm_state *x, 1735 struct xfrm_policy *xp, 1736 const struct flowi *fl); 1737 int (*xfrm_decode_session)(struct sk_buff *skb, u32 *secid, int ckall); 1738#endif /* CONFIG_SECURITY_NETWORK_XFRM */ 1739 1740 /* key management security hooks */ 1741#ifdef CONFIG_KEYS 1742 int (*key_alloc)(struct key *key, const struct cred *cred, 1743 unsigned long flags); 1744 void (*key_free)(struct key *key); 1745 int (*key_permission)(key_ref_t key_ref, const struct cred *cred, 1746 unsigned perm); 1747 int (*key_getsecurity)(struct key *key, char **_buffer); 1748#endif /* CONFIG_KEYS */ 1749 1750#ifdef CONFIG_AUDIT 1751 int (*audit_rule_init)(u32 field, u32 op, char *rulestr, 1752 void **lsmrule); 1753 int (*audit_rule_known)(struct audit_krule *krule); 1754 int (*audit_rule_match)(u32 secid, u32 field, u32 op, void *lsmrule, 1755 struct audit_context *actx); 1756 void (*audit_rule_free)(void *lsmrule); 1757#endif /* CONFIG_AUDIT */ 1758 1759#ifdef CONFIG_BPF_SYSCALL 1760 int (*bpf)(int cmd, union bpf_attr *attr, 1761 unsigned int size); 1762 int (*bpf_map)(struct bpf_map *map, fmode_t fmode); 1763 int (*bpf_prog)(struct bpf_prog *prog); 1764 int (*bpf_map_alloc_security)(struct bpf_map *map); 1765 void (*bpf_map_free_security)(struct bpf_map *map); 1766 int (*bpf_prog_alloc_security)(struct bpf_prog_aux *aux); 1767 void (*bpf_prog_free_security)(struct bpf_prog_aux *aux); 1768#endif /* CONFIG_BPF_SYSCALL */ 1769}; 1770 1771struct security_hook_heads { 1772 struct hlist_head binder_set_context_mgr; 1773 struct hlist_head binder_transaction; 1774 struct hlist_head binder_transfer_binder; 1775 struct hlist_head binder_transfer_file; 1776 struct hlist_head ptrace_access_check; 1777 struct hlist_head ptrace_traceme; 1778 struct hlist_head capget; 1779 struct hlist_head capset; 1780 struct hlist_head capable; 1781 struct hlist_head quotactl; 1782 struct hlist_head quota_on; 1783 struct hlist_head syslog; 1784 struct hlist_head settime; 1785 struct hlist_head vm_enough_memory; 1786 struct hlist_head bprm_set_creds; 1787 struct hlist_head bprm_check_security; 1788 struct hlist_head bprm_committing_creds; 1789 struct hlist_head bprm_committed_creds; 1790 struct hlist_head sb_alloc_security; 1791 struct hlist_head sb_free_security; 1792 struct hlist_head sb_copy_data; 1793 struct hlist_head sb_remount; 1794 struct hlist_head sb_kern_mount; 1795 struct hlist_head sb_show_options; 1796 struct hlist_head sb_statfs; 1797 struct hlist_head sb_mount; 1798 struct hlist_head sb_umount; 1799 struct hlist_head sb_pivotroot; 1800 struct hlist_head sb_set_mnt_opts; 1801 struct hlist_head sb_clone_mnt_opts; 1802 struct hlist_head sb_parse_opts_str; 1803 struct hlist_head dentry_init_security; 1804 struct hlist_head dentry_create_files_as; 1805#ifdef CONFIG_SECURITY_PATH 1806 struct hlist_head path_unlink; 1807 struct hlist_head path_mkdir; 1808 struct hlist_head path_rmdir; 1809 struct hlist_head path_mknod; 1810 struct hlist_head path_truncate; 1811 struct hlist_head path_symlink; 1812 struct hlist_head path_link; 1813 struct hlist_head path_rename; 1814 struct hlist_head path_chmod; 1815 struct hlist_head path_chown; 1816 struct hlist_head path_chroot; 1817#endif 1818 struct hlist_head inode_alloc_security; 1819 struct hlist_head inode_free_security; 1820 struct hlist_head inode_init_security; 1821 struct hlist_head inode_create; 1822 struct hlist_head inode_link; 1823 struct hlist_head inode_unlink; 1824 struct hlist_head inode_symlink; 1825 struct hlist_head inode_mkdir; 1826 struct hlist_head inode_rmdir; 1827 struct hlist_head inode_mknod; 1828 struct hlist_head inode_rename; 1829 struct hlist_head inode_readlink; 1830 struct hlist_head inode_follow_link; 1831 struct hlist_head inode_permission; 1832 struct hlist_head inode_setattr; 1833 struct hlist_head inode_getattr; 1834 struct hlist_head inode_setxattr; 1835 struct hlist_head inode_post_setxattr; 1836 struct hlist_head inode_getxattr; 1837 struct hlist_head inode_listxattr; 1838 struct hlist_head inode_removexattr; 1839 struct hlist_head inode_need_killpriv; 1840 struct hlist_head inode_killpriv; 1841 struct hlist_head inode_getsecurity; 1842 struct hlist_head inode_setsecurity; 1843 struct hlist_head inode_listsecurity; 1844 struct hlist_head inode_getsecid; 1845 struct hlist_head inode_copy_up; 1846 struct hlist_head inode_copy_up_xattr; 1847 struct hlist_head file_permission; 1848 struct hlist_head file_alloc_security; 1849 struct hlist_head file_free_security; 1850 struct hlist_head file_ioctl; 1851 struct hlist_head mmap_addr; 1852 struct hlist_head mmap_file; 1853 struct hlist_head file_mprotect; 1854 struct hlist_head file_lock; 1855 struct hlist_head file_fcntl; 1856 struct hlist_head file_set_fowner; 1857 struct hlist_head file_send_sigiotask; 1858 struct hlist_head file_receive; 1859 struct hlist_head file_open; 1860 struct hlist_head task_alloc; 1861 struct hlist_head task_free; 1862 struct hlist_head cred_alloc_blank; 1863 struct hlist_head cred_free; 1864 struct hlist_head cred_prepare; 1865 struct hlist_head cred_transfer; 1866 struct hlist_head cred_getsecid; 1867 struct hlist_head kernel_act_as; 1868 struct hlist_head kernel_create_files_as; 1869 struct hlist_head kernel_read_file; 1870 struct hlist_head kernel_post_read_file; 1871 struct hlist_head kernel_module_request; 1872 struct hlist_head task_fix_setuid; 1873 struct hlist_head task_setpgid; 1874 struct hlist_head task_getpgid; 1875 struct hlist_head task_getsid; 1876 struct hlist_head task_getsecid; 1877 struct hlist_head task_setnice; 1878 struct hlist_head task_setioprio; 1879 struct hlist_head task_getioprio; 1880 struct hlist_head task_prlimit; 1881 struct hlist_head task_setrlimit; 1882 struct hlist_head task_setscheduler; 1883 struct hlist_head task_getscheduler; 1884 struct hlist_head task_movememory; 1885 struct hlist_head task_kill; 1886 struct hlist_head task_prctl; 1887 struct hlist_head task_to_inode; 1888 struct hlist_head ipc_permission; 1889 struct hlist_head ipc_getsecid; 1890 struct hlist_head msg_msg_alloc_security; 1891 struct hlist_head msg_msg_free_security; 1892 struct hlist_head msg_queue_alloc_security; 1893 struct hlist_head msg_queue_free_security; 1894 struct hlist_head msg_queue_associate; 1895 struct hlist_head msg_queue_msgctl; 1896 struct hlist_head msg_queue_msgsnd; 1897 struct hlist_head msg_queue_msgrcv; 1898 struct hlist_head shm_alloc_security; 1899 struct hlist_head shm_free_security; 1900 struct hlist_head shm_associate; 1901 struct hlist_head shm_shmctl; 1902 struct hlist_head shm_shmat; 1903 struct hlist_head sem_alloc_security; 1904 struct hlist_head sem_free_security; 1905 struct hlist_head sem_associate; 1906 struct hlist_head sem_semctl; 1907 struct hlist_head sem_semop; 1908 struct hlist_head netlink_send; 1909 struct hlist_head d_instantiate; 1910 struct hlist_head getprocattr; 1911 struct hlist_head setprocattr; 1912 struct hlist_head ismaclabel; 1913 struct hlist_head secid_to_secctx; 1914 struct hlist_head secctx_to_secid; 1915 struct hlist_head release_secctx; 1916 struct hlist_head inode_invalidate_secctx; 1917 struct hlist_head inode_notifysecctx; 1918 struct hlist_head inode_setsecctx; 1919 struct hlist_head inode_getsecctx; 1920#ifdef CONFIG_SECURITY_NETWORK 1921 struct hlist_head unix_stream_connect; 1922 struct hlist_head unix_may_send; 1923 struct hlist_head socket_create; 1924 struct hlist_head socket_post_create; 1925 struct hlist_head socket_bind; 1926 struct hlist_head socket_connect; 1927 struct hlist_head socket_listen; 1928 struct hlist_head socket_accept; 1929 struct hlist_head socket_sendmsg; 1930 struct hlist_head socket_recvmsg; 1931 struct hlist_head socket_getsockname; 1932 struct hlist_head socket_getpeername; 1933 struct hlist_head socket_getsockopt; 1934 struct hlist_head socket_setsockopt; 1935 struct hlist_head socket_shutdown; 1936 struct hlist_head socket_sock_rcv_skb; 1937 struct hlist_head socket_getpeersec_stream; 1938 struct hlist_head socket_getpeersec_dgram; 1939 struct hlist_head sk_alloc_security; 1940 struct hlist_head sk_free_security; 1941 struct hlist_head sk_clone_security; 1942 struct hlist_head sk_getsecid; 1943 struct hlist_head sock_graft; 1944 struct hlist_head inet_conn_request; 1945 struct hlist_head inet_csk_clone; 1946 struct hlist_head inet_conn_established; 1947 struct hlist_head secmark_relabel_packet; 1948 struct hlist_head secmark_refcount_inc; 1949 struct hlist_head secmark_refcount_dec; 1950 struct hlist_head req_classify_flow; 1951 struct hlist_head tun_dev_alloc_security; 1952 struct hlist_head tun_dev_free_security; 1953 struct hlist_head tun_dev_create; 1954 struct hlist_head tun_dev_attach_queue; 1955 struct hlist_head tun_dev_attach; 1956 struct hlist_head tun_dev_open; 1957 struct hlist_head sctp_assoc_request; 1958 struct hlist_head sctp_bind_connect; 1959 struct hlist_head sctp_sk_clone; 1960#endif /* CONFIG_SECURITY_NETWORK */ 1961#ifdef CONFIG_SECURITY_INFINIBAND 1962 struct hlist_head ib_pkey_access; 1963 struct hlist_head ib_endport_manage_subnet; 1964 struct hlist_head ib_alloc_security; 1965 struct hlist_head ib_free_security; 1966#endif /* CONFIG_SECURITY_INFINIBAND */ 1967#ifdef CONFIG_SECURITY_NETWORK_XFRM 1968 struct hlist_head xfrm_policy_alloc_security; 1969 struct hlist_head xfrm_policy_clone_security; 1970 struct hlist_head xfrm_policy_free_security; 1971 struct hlist_head xfrm_policy_delete_security; 1972 struct hlist_head xfrm_state_alloc; 1973 struct hlist_head xfrm_state_alloc_acquire; 1974 struct hlist_head xfrm_state_free_security; 1975 struct hlist_head xfrm_state_delete_security; 1976 struct hlist_head xfrm_policy_lookup; 1977 struct hlist_head xfrm_state_pol_flow_match; 1978 struct hlist_head xfrm_decode_session; 1979#endif /* CONFIG_SECURITY_NETWORK_XFRM */ 1980#ifdef CONFIG_KEYS 1981 struct hlist_head key_alloc; 1982 struct hlist_head key_free; 1983 struct hlist_head key_permission; 1984 struct hlist_head key_getsecurity; 1985#endif /* CONFIG_KEYS */ 1986#ifdef CONFIG_AUDIT 1987 struct hlist_head audit_rule_init; 1988 struct hlist_head audit_rule_known; 1989 struct hlist_head audit_rule_match; 1990 struct hlist_head audit_rule_free; 1991#endif /* CONFIG_AUDIT */ 1992#ifdef CONFIG_BPF_SYSCALL 1993 struct hlist_head bpf; 1994 struct hlist_head bpf_map; 1995 struct hlist_head bpf_prog; 1996 struct hlist_head bpf_map_alloc_security; 1997 struct hlist_head bpf_map_free_security; 1998 struct hlist_head bpf_prog_alloc_security; 1999 struct hlist_head bpf_prog_free_security; 2000#endif /* CONFIG_BPF_SYSCALL */
2001} __randomize_layout; 2002 2003/* 2004 * Security module hook list structure. 2005 * For use with generic list macros for common operations. 2006 */ 2007struct security_hook_list { 2008 struct hlist_node list; 2009 struct hlist_head *head; 2010 union security_list_options hook; 2011 char *lsm; 2012} __randomize_layout; 2013 2014/* 2015 * Initializing a security_hook_list structure takes 2016 * up a lot of space in a source file. This macro takes 2017 * care of the common case and reduces the amount of 2018 * text involved. 2019 */ 2020#define LSM_HOOK_INIT(HEAD, HOOK) \ 2021 { .head = &security_hook_heads.HEAD, .hook = { .HEAD = HOOK } } 2022 2023extern struct security_hook_heads security_hook_heads; 2024extern char *lsm_names; 2025 2026extern void security_add_hooks(struct security_hook_list *hooks, int count, 2027 char *lsm); 2028 2029#ifdef CONFIG_SECURITY_SELINUX_DISABLE 2030/* 2031 * Assuring the safety of deleting a security module is up to 2032 * the security module involved. This may entail ordering the 2033 * module's hook list in a particular way, refusing to disable 2034 * the module once a policy is loaded or any number of other 2035 * actions better imagined than described. 2036 * 2037 * The name of the configuration option reflects the only module 2038 * that currently uses the mechanism. Any developer who thinks 2039 * disabling their module is a good idea needs to be at least as 2040 * careful as the SELinux team. 2041 */ 2042static inline void security_delete_hooks(struct security_hook_list *hooks, 2043 int count) 2044{ 2045 int i; 2046 2047 for (i = 0; i < count; i++) 2048 hlist_del_rcu(&hooks[i].list); 2049} 2050#endif /* CONFIG_SECURITY_SELINUX_DISABLE */ 2051 2052/* Currently required to handle SELinux runtime hook disable. */ 2053#ifdef CONFIG_SECURITY_WRITABLE_HOOKS 2054#define __lsm_ro_after_init 2055#else 2056#define __lsm_ro_after_init __ro_after_init 2057#endif /* CONFIG_SECURITY_WRITABLE_HOOKS */ 2058 2059extern int __init security_module_enable(const char *module); 2060extern void __init capability_add_hooks(void); 2061#ifdef CONFIG_SECURITY_YAMA 2062extern void __init yama_add_hooks(void); 2063#else 2064static inline void __init yama_add_hooks(void) { } 2065#endif 2066#ifdef CONFIG_SECURITY_LOADPIN 2067void __init loadpin_add_hooks(void); 2068#else 2069static inline void loadpin_add_hooks(void) { }; 2070#endif 2071 2072#endif /* ! __LINUX_LSM_HOOKS_H */ 2073