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