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