1 /* 2 * Linux Security Module interfaces 3 * 4 * Copyright (C) 2001 WireX Communications, Inc <[email protected]> 5 * Copyright (C) 2001 Greg Kroah-Hartman <[email protected]> 6 * Copyright (C) 2001 Networks Associates Technology, Inc <[email protected]> 7 * Copyright (C) 2001 James Morris <[email protected]> 8 * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group) 9 * Copyright (C) 2015 Intel Corporation. 10 * Copyright (C) 2015 Casey Schaufler <[email protected]> 11 * Copyright (C) 2016 Mellanox Techonologies 12 * 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation; either version 2 of the License, or 16 * (at your option) any later version. 17 * 18 * Due to this file being licensed under the GPL there is controversy over 19 * whether this permits you to write a module that #includes this file 20 * without placing your module under the GPL. Please consult a lawyer for 21 * advice before doing this. 22 * 23 */ 24 25 #ifndef __LINUX_LSM_HOOKS_H 26 #define __LINUX_LSM_HOOKS_H 27 28 #include <linux/security.h> 29 #include <linux/init.h> 30 #include <linux/rculist.h> 31 32 /** 33 * union security_list_options - Linux Security Module hook function list 34 * 35 * Security hooks for program execution operations. 36 * 37 * @bprm_set_creds: 38 * Save security information in the bprm->security field, typically based 39 * on information about the bprm->file, for later use by the apply_creds 40 * hook. This hook may also optionally check permissions (e.g. for 41 * transitions between security domains). 42 * This hook may be called multiple times during a single execve, e.g. for 43 * interpreters. The hook can tell whether it has already been called by 44 * checking to see if @bprm->security is non-NULL. If so, then the hook 45 * may decide either to retain the security information saved earlier or 46 * to replace it. 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_free_mnt_opts: 107 * Free memory associated with @mnt_ops. 108 * @sb_eat_lsm_opts: 109 * Eat (scan @orig options) and save them in @mnt_opts. 110 * @sb_statfs: 111 * Check permission before obtaining filesystem statistics for the @mnt 112 * mountpoint. 113 * @dentry is a handle on the superblock for the filesystem. 114 * Return 0 if permission is granted. 115 * @sb_mount: 116 * Check permission before an object specified by @dev_name is mounted on 117 * the mount point named by @nd. For an ordinary mount, @dev_name 118 * identifies a device if the file system type requires a device. For a 119 * remount (@flags & MS_REMOUNT), @dev_name is irrelevant. For a 120 * loopback/bind mount (@flags & MS_BIND), @dev_name identifies the 121 * pathname of the object being mounted. 122 * @dev_name contains the name for object being mounted. 123 * @path contains the path for mount point object. 124 * @type contains the filesystem type. 125 * @flags contains the mount flags. 126 * @data contains the filesystem-specific data. 127 * Return 0 if permission is granted. 128 * @sb_copy_data: 129 * Allow mount option data to be copied prior to parsing by the filesystem, 130 * so that the security module can extract security-specific mount 131 * options cleanly (a filesystem may modify the data e.g. with strsep()). 132 * This also allows the original mount data to be stripped of security- 133 * specific options to avoid having to make filesystems aware of them. 134 * @orig the original mount data copied from userspace. 135 * @copy copied data which will be passed to the security module. 136 * Returns 0 if the copy was successful. 137 * @sb_remount: 138 * Extracts security system specific mount options and verifies no changes 139 * are being made to those options. 140 * @sb superblock being remounted 141 * @data contains the filesystem-specific data. 142 * Return 0 if permission is granted. 143 * @sb_kern_mount: 144 * Mount this @sb if allowed by permissions. 145 * @sb_show_options: 146 * Show (print on @m) mount options for this @sb. 147 * @sb_umount: 148 * Check permission before the @mnt file system is unmounted. 149 * @mnt contains the mounted file system. 150 * @flags contains the unmount flags, e.g. MNT_FORCE. 151 * Return 0 if permission is granted. 152 * @sb_pivotroot: 153 * Check permission before pivoting the root filesystem. 154 * @old_path contains the path for the new location of the 155 * current root (put_old). 156 * @new_path contains the path for the new root (new_root). 157 * Return 0 if permission is granted. 158 * @sb_set_mnt_opts: 159 * Set the security relevant mount options used for a superblock 160 * @sb the superblock to set security mount options for 161 * @opts binary data structure containing all lsm mount data 162 * @sb_clone_mnt_opts: 163 * Copy all security options from a given superblock to another 164 * @oldsb old superblock which contain information to clone 165 * @newsb new superblock which needs filled in 166 * @sb_add_mnt_opt: 167 * Add one mount @option to @mnt_opts. 168 * @sb_parse_opts_str: 169 * Parse a string of security data filling in the opts structure 170 * @options string containing all mount options known by the LSM 171 * @opts binary data structure usable by the LSM 172 * @move_mount: 173 * Check permission before a mount is moved. 174 * @from_path indicates the mount that is going to be moved. 175 * @to_path indicates the mountpoint that will be mounted upon. 176 * @dentry_init_security: 177 * Compute a context for a dentry as the inode is not yet available 178 * since NFSv4 has no label backed by an EA anyway. 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 * @ctx pointer to place the pointer to the resulting context in. 183 * @ctxlen point to place the length of the resulting context. 184 * @dentry_create_files_as: 185 * Compute a context for a dentry as the inode is not yet available 186 * and set that context in passed in creds so that new files are 187 * created using that context. Context is calculated using the 188 * passed in creds and not the creds of the caller. 189 * @dentry dentry to use in calculating the context. 190 * @mode mode used to determine resource type. 191 * @name name of the last path component used to create file 192 * @old creds which should be used for context calculation 193 * @new creds to modify 194 * 195 * 196 * Security hooks for inode operations. 197 * 198 * @inode_alloc_security: 199 * Allocate and attach a security structure to @inode->i_security. The 200 * i_security field is initialized to NULL when the inode structure is 201 * allocated. 202 * @inode contains the inode structure. 203 * Return 0 if operation was successful. 204 * @inode_free_security: 205 * @inode contains the inode structure. 206 * Deallocate the inode security structure and set @inode->i_security to 207 * NULL. 208 * @inode_init_security: 209 * Obtain the security attribute name suffix and value to set on a newly 210 * created inode and set up the incore security field for the new inode. 211 * This hook is called by the fs code as part of the inode creation 212 * transaction and provides for atomic labeling of the inode, unlike 213 * the post_create/mkdir/... hooks called by the VFS. The hook function 214 * is expected to allocate the name and value via kmalloc, with the caller 215 * being responsible for calling kfree after using them. 216 * If the security module does not use security attributes or does 217 * not wish to put a security attribute on this particular inode, 218 * then it should return -EOPNOTSUPP to skip this processing. 219 * @inode contains the inode structure of the newly created inode. 220 * @dir contains the inode structure of the parent directory. 221 * @qstr contains the last path component of the new object 222 * @name will be set to the allocated name suffix (e.g. selinux). 223 * @value will be set to the allocated attribute value. 224 * @len will be set to the length of the value. 225 * Returns 0 if @name and @value have been successfully set, 226 * -EOPNOTSUPP if no security attribute is needed, or 227 * -ENOMEM on memory allocation failure. 228 * @inode_create: 229 * Check permission to create a regular file. 230 * @dir contains inode structure of the parent of the new file. 231 * @dentry contains the dentry structure for the file to be created. 232 * @mode contains the file mode of the file to be created. 233 * Return 0 if permission is granted. 234 * @inode_link: 235 * Check permission before creating a new hard link to a file. 236 * @old_dentry contains the dentry structure for an existing 237 * link to the file. 238 * @dir contains the inode structure of the parent directory 239 * of the new link. 240 * @new_dentry contains the dentry structure for the new link. 241 * Return 0 if permission is granted. 242 * @path_link: 243 * Check permission before creating a new hard link to a file. 244 * @old_dentry contains the dentry structure for an existing link 245 * to the file. 246 * @new_dir contains the path structure of the parent directory of 247 * the new link. 248 * @new_dentry contains the dentry structure for the new link. 249 * Return 0 if permission is granted. 250 * @inode_unlink: 251 * Check the permission to remove a hard link to a file. 252 * @dir contains the inode structure of parent directory of the file. 253 * @dentry contains the dentry structure for file to be unlinked. 254 * Return 0 if permission is granted. 255 * @path_unlink: 256 * Check the permission to remove a hard link to a file. 257 * @dir contains the path structure of parent directory of the file. 258 * @dentry contains the dentry structure for file to be unlinked. 259 * Return 0 if permission is granted. 260 * @inode_symlink: 261 * Check the permission to create a symbolic link to a file. 262 * @dir contains the inode structure of parent directory of 263 * the symbolic link. 264 * @dentry contains the dentry structure of the symbolic link. 265 * @old_name contains the pathname of file. 266 * Return 0 if permission is granted. 267 * @path_symlink: 268 * Check the permission to create a symbolic link to a file. 269 * @dir contains the path structure of parent directory of 270 * the symbolic link. 271 * @dentry contains the dentry structure of the symbolic link. 272 * @old_name contains the pathname of file. 273 * Return 0 if permission is granted. 274 * @inode_mkdir: 275 * Check permissions to create a new directory in the existing directory 276 * associated with inode structure @dir. 277 * @dir contains the inode structure of parent of the directory 278 * to be created. 279 * @dentry contains the dentry structure of new directory. 280 * @mode contains the mode of new directory. 281 * Return 0 if permission is granted. 282 * @path_mkdir: 283 * Check permissions to create a new directory in the existing directory 284 * associated with path structure @path. 285 * @dir contains the path structure of parent of the directory 286 * to be created. 287 * @dentry contains the dentry structure of new directory. 288 * @mode contains the mode of new directory. 289 * Return 0 if permission is granted. 290 * @inode_rmdir: 291 * Check the permission to remove a directory. 292 * @dir contains the inode structure of parent of the directory 293 * to be removed. 294 * @dentry contains the dentry structure of directory to be removed. 295 * Return 0 if permission is granted. 296 * @path_rmdir: 297 * Check the permission to remove a directory. 298 * @dir contains the path structure of parent of the directory to be 299 * removed. 300 * @dentry contains the dentry structure of directory to be removed. 301 * Return 0 if permission is granted. 302 * @inode_mknod: 303 * Check permissions when creating a special file (or a socket or a fifo 304 * file created via the mknod system call). Note that if mknod operation 305 * is being done for a regular file, then the create hook will be called 306 * and not this hook. 307 * @dir contains the inode structure of parent of the new file. 308 * @dentry contains the dentry structure of the new file. 309 * @mode contains the mode of the new file. 310 * @dev contains the device number. 311 * Return 0 if permission is granted. 312 * @path_mknod: 313 * Check permissions when creating a file. Note that this hook is called 314 * even if mknod operation is being done for a regular file. 315 * @dir contains the path structure of parent of the new file. 316 * @dentry contains the dentry structure of the new file. 317 * @mode contains the mode of the new file. 318 * @dev contains the undecoded device number. Use new_decode_dev() to get 319 * the decoded device number. 320 * Return 0 if permission is granted. 321 * @inode_rename: 322 * Check for permission to rename a file or directory. 323 * @old_dir contains the inode structure for parent of the old link. 324 * @old_dentry contains the dentry structure of the old link. 325 * @new_dir contains the inode structure for parent of the new link. 326 * @new_dentry contains the dentry structure of the new link. 327 * Return 0 if permission is granted. 328 * @path_rename: 329 * Check for permission to rename a file or directory. 330 * @old_dir contains the path structure for parent of the old link. 331 * @old_dentry contains the dentry structure of the old link. 332 * @new_dir contains the path structure for parent of the new link. 333 * @new_dentry contains the dentry structure of the new link. 334 * Return 0 if permission is granted. 335 * @path_chmod: 336 * Check for permission to change a mode of the file @path. The new 337 * mode is specified in @mode. 338 * @path contains the path structure of the file to change the mode. 339 * @mode contains the new DAC's permission, which is a bitmask of 340 * constants from <include/uapi/linux/stat.h> 341 * Return 0 if permission is granted. 342 * @path_chown: 343 * Check for permission to change owner/group of a file or directory. 344 * @path contains the path structure. 345 * @uid contains new owner's ID. 346 * @gid contains new group's ID. 347 * Return 0 if permission is granted. 348 * @path_chroot: 349 * Check for permission to change root directory. 350 * @path contains the path structure. 351 * Return 0 if permission is granted. 352 * @path_notify: 353 * Check permissions before setting a watch on events as defined by @mask, 354 * on an object at @path, whose type is defined by @obj_type. 355 * @inode_readlink: 356 * Check the permission to read the symbolic link. 357 * @dentry contains the dentry structure for the file link. 358 * Return 0 if permission is granted. 359 * @inode_follow_link: 360 * Check permission to follow a symbolic link when looking up a pathname. 361 * @dentry contains the dentry structure for the link. 362 * @inode contains the inode, which itself is not stable in RCU-walk 363 * @rcu indicates whether we are in RCU-walk mode. 364 * Return 0 if permission is granted. 365 * @inode_permission: 366 * Check permission before accessing an inode. This hook is called by the 367 * existing Linux permission function, so a security module can use it to 368 * provide additional checking for existing Linux permission checks. 369 * Notice that this hook is called when a file is opened (as well as many 370 * other operations), whereas the file_security_ops permission hook is 371 * called when the actual read/write operations are performed. 372 * @inode contains the inode structure to check. 373 * @mask contains the permission mask. 374 * Return 0 if permission is granted. 375 * @inode_setattr: 376 * Check permission before setting file attributes. Note that the kernel 377 * call to notify_change is performed from several locations, whenever 378 * file attributes change (such as when a file is truncated, chown/chmod 379 * operations, transferring disk quotas, etc). 380 * @dentry contains the dentry structure for the file. 381 * @attr is the iattr structure containing the new file attributes. 382 * Return 0 if permission is granted. 383 * @path_truncate: 384 * Check permission before truncating a file. 385 * @path contains the path structure for the file. 386 * Return 0 if permission is granted. 387 * @inode_getattr: 388 * Check permission before obtaining file attributes. 389 * @path contains the path structure for the file. 390 * Return 0 if permission is granted. 391 * @inode_setxattr: 392 * Check permission before setting the extended attributes 393 * @value identified by @name for @dentry. 394 * Return 0 if permission is granted. 395 * @inode_post_setxattr: 396 * Update inode security field after successful setxattr operation. 397 * @value identified by @name for @dentry. 398 * @inode_getxattr: 399 * Check permission before obtaining the extended attributes 400 * identified by @name for @dentry. 401 * Return 0 if permission is granted. 402 * @inode_listxattr: 403 * Check permission before obtaining the list of extended attribute 404 * names for @dentry. 405 * Return 0 if permission is granted. 406 * @inode_removexattr: 407 * Check permission before removing the extended attribute 408 * identified by @name for @dentry. 409 * Return 0 if permission is granted. 410 * @inode_getsecurity: 411 * Retrieve a copy of the extended attribute representation of the 412 * security label associated with @name for @inode via @buffer. Note that 413 * @name is the remainder of the attribute name after the security prefix 414 * has been removed. @alloc is used to specify of the call should return a 415 * value via the buffer or just the value length Return size of buffer on 416 * success. 417 * @inode_setsecurity: 418 * Set the security label associated with @name for @inode from the 419 * extended attribute value @value. @size indicates the size of the 420 * @value in bytes. @flags may be XATTR_CREATE, XATTR_REPLACE, or 0. 421 * Note that @name is the remainder of the attribute name after the 422 * security. prefix has been removed. 423 * Return 0 on success. 424 * @inode_listsecurity: 425 * Copy the extended attribute names for the security labels 426 * associated with @inode into @buffer. The maximum size of @buffer 427 * is specified by @buffer_size. @buffer may be NULL to request 428 * the size of the buffer required. 429 * Returns number of bytes used/required on success. 430 * @inode_need_killpriv: 431 * Called when an inode has been changed. 432 * @dentry is the dentry being changed. 433 * Return <0 on error to abort the inode change operation. 434 * Return 0 if inode_killpriv does not need to be called. 435 * Return >0 if inode_killpriv does need to be called. 436 * @inode_killpriv: 437 * The setuid bit is being removed. Remove similar security labels. 438 * Called with the dentry->d_inode->i_mutex held. 439 * @dentry is the dentry being changed. 440 * Return 0 on success. If error is returned, then the operation 441 * causing setuid bit removal is failed. 442 * @inode_getsecid: 443 * Get the secid associated with the node. 444 * @inode contains a pointer to the inode. 445 * @secid contains a pointer to the location where result will be saved. 446 * In case of failure, @secid will be set to zero. 447 * @inode_copy_up: 448 * A file is about to be copied up from lower layer to upper layer of 449 * overlay filesystem. Security module can prepare a set of new creds 450 * and modify as need be and return new creds. Caller will switch to 451 * new creds temporarily to create new file and release newly allocated 452 * creds. 453 * @src indicates the union dentry of file that is being copied up. 454 * @new pointer to pointer to return newly allocated creds. 455 * Returns 0 on success or a negative error code on error. 456 * @inode_copy_up_xattr: 457 * Filter the xattrs being copied up when a unioned file is copied 458 * up from a lower layer to the union/overlay layer. 459 * @name indicates the name of the xattr. 460 * Returns 0 to accept the xattr, 1 to discard the xattr, -EOPNOTSUPP if 461 * security module does not know about attribute or a negative error code 462 * to abort the copy up. Note that the caller is responsible for reading 463 * and writing the xattrs as this hook is merely a filter. 464 * @d_instantiate: 465 * Fill in @inode security information for a @dentry if allowed. 466 * @getprocattr: 467 * Read attribute @name for process @p and store it into @value if allowed. 468 * @setprocattr: 469 * Write (set) attribute @name to @value, size @size if allowed. 470 * 471 * Security hooks for kernfs node operations 472 * 473 * @kernfs_init_security: 474 * Initialize the security context of a newly created kernfs node based 475 * on its own and its parent's attributes. 476 * 477 * @kn_dir the parent kernfs node 478 * @kn the new child kernfs node 479 * 480 * Security hooks for file operations 481 * 482 * @file_permission: 483 * Check file permissions before accessing an open file. This hook is 484 * called by various operations that read or write files. A security 485 * module can use this hook to perform additional checking on these 486 * operations, e.g. to revalidate permissions on use to support privilege 487 * bracketing or policy changes. Notice that this hook is used when the 488 * actual read/write operations are performed, whereas the 489 * inode_security_ops hook is called when a file is opened (as well as 490 * many other operations). 491 * Caveat: Although this hook can be used to revalidate permissions for 492 * various system call operations that read or write files, it does not 493 * address the revalidation of permissions for memory-mapped files. 494 * Security modules must handle this separately if they need such 495 * revalidation. 496 * @file contains the file structure being accessed. 497 * @mask contains the requested permissions. 498 * Return 0 if permission is granted. 499 * @file_alloc_security: 500 * Allocate and attach a security structure to the file->f_security field. 501 * The security field is initialized to NULL when the structure is first 502 * created. 503 * @file contains the file structure to secure. 504 * Return 0 if the hook is successful and permission is granted. 505 * @file_free_security: 506 * Deallocate and free any security structures stored in file->f_security. 507 * @file contains the file structure being modified. 508 * @file_ioctl: 509 * @file contains the file structure. 510 * @cmd contains the operation to perform. 511 * @arg contains the operational arguments. 512 * Check permission for an ioctl operation on @file. Note that @arg 513 * sometimes represents a user space pointer; in other cases, it may be a 514 * simple integer value. When @arg represents a user space pointer, it 515 * should never be used by the security module. 516 * Return 0 if permission is granted. 517 * @mmap_addr : 518 * Check permissions for a mmap operation at @addr. 519 * @addr contains virtual address that will be used for the operation. 520 * Return 0 if permission is granted. 521 * @mmap_file : 522 * Check permissions for a mmap operation. The @file may be NULL, e.g. 523 * if mapping anonymous memory. 524 * @file contains the file structure for file to map (may be NULL). 525 * @reqprot contains the protection requested by the application. 526 * @prot contains the protection that will be applied by the kernel. 527 * @flags contains the operational flags. 528 * Return 0 if permission is granted. 529 * @file_mprotect: 530 * Check permissions before changing memory access permissions. 531 * @vma contains the memory region to modify. 532 * @reqprot contains the protection requested by the application. 533 * @prot contains the protection that will be applied by the kernel. 534 * Return 0 if permission is granted. 535 * @file_lock: 536 * Check permission before performing file locking operations. 537 * Note the hook mediates both flock and fcntl style locks. 538 * @file contains the file structure. 539 * @cmd contains the posix-translated lock operation to perform 540 * (e.g. F_RDLCK, F_WRLCK). 541 * Return 0 if permission is granted. 542 * @file_fcntl: 543 * Check permission before allowing the file operation specified by @cmd 544 * from being performed on the file @file. Note that @arg sometimes 545 * represents a user space pointer; in other cases, it may be a simple 546 * integer value. When @arg represents a user space pointer, it should 547 * never be used by the security module. 548 * @file contains the file structure. 549 * @cmd contains the operation to be performed. 550 * @arg contains the operational arguments. 551 * Return 0 if permission is granted. 552 * @file_set_fowner: 553 * Save owner security information (typically from current->security) in 554 * file->f_security for later use by the send_sigiotask hook. 555 * @file contains the file structure to update. 556 * Return 0 on success. 557 * @file_send_sigiotask: 558 * Check permission for the file owner @fown to send SIGIO or SIGURG to the 559 * process @tsk. Note that this hook is sometimes called from interrupt. 560 * Note that the fown_struct, @fown, is never outside the context of a 561 * struct file, so the file structure (and associated security information) 562 * can always be obtained: container_of(fown, struct file, f_owner) 563 * @tsk contains the structure of task receiving signal. 564 * @fown contains the file owner information. 565 * @sig is the signal that will be sent. When 0, kernel sends SIGIO. 566 * Return 0 if permission is granted. 567 * @file_receive: 568 * This hook allows security modules to control the ability of a process 569 * to receive an open file descriptor via socket IPC. 570 * @file contains the file structure being received. 571 * Return 0 if permission is granted. 572 * @file_open: 573 * Save open-time permission checking state for later use upon 574 * file_permission, and recheck access if anything has changed 575 * since inode_permission. 576 * 577 * Security hooks for task operations. 578 * 579 * @task_alloc: 580 * @task task being allocated. 581 * @clone_flags contains the flags indicating what should be shared. 582 * Handle allocation of task-related resources. 583 * Returns a zero on success, negative values on failure. 584 * @task_free: 585 * @task task about to be freed. 586 * Handle release of task-related resources. (Note that this can be called 587 * from interrupt context.) 588 * @cred_alloc_blank: 589 * @cred points to the credentials. 590 * @gfp indicates the atomicity of any memory allocations. 591 * Only allocate sufficient memory and attach to @cred such that 592 * cred_transfer() will not get ENOMEM. 593 * @cred_free: 594 * @cred points to the credentials. 595 * Deallocate and clear the cred->security field in a set of credentials. 596 * @cred_prepare: 597 * @new points to the new credentials. 598 * @old points to the original credentials. 599 * @gfp indicates the atomicity of any memory allocations. 600 * Prepare a new set of credentials by copying the data from the old set. 601 * @cred_transfer: 602 * @new points to the new credentials. 603 * @old points to the original credentials. 604 * Transfer data from original creds to new creds 605 * @cred_getsecid: 606 * Retrieve the security identifier of the cred structure @c 607 * @c contains the credentials, secid will be placed into @secid. 608 * In case of failure, @secid will be set to zero. 609 * @kernel_act_as: 610 * Set the credentials for a kernel service to act as (subjective context). 611 * @new points to the credentials to be modified. 612 * @secid specifies the security ID to be set 613 * The current task must be the one that nominated @secid. 614 * Return 0 if successful. 615 * @kernel_create_files_as: 616 * Set the file creation context in a set of credentials to be the same as 617 * the objective context of the specified inode. 618 * @new points to the credentials to be modified. 619 * @inode points to the inode to use as a reference. 620 * The current task must be the one that nominated @inode. 621 * Return 0 if successful. 622 * @kernel_module_request: 623 * Ability to trigger the kernel to automatically upcall to userspace for 624 * userspace to load a kernel module with the given name. 625 * @kmod_name name of the module requested by the kernel 626 * Return 0 if successful. 627 * @kernel_load_data: 628 * Load data provided by userspace. 629 * @id kernel load data identifier 630 * Return 0 if permission is granted. 631 * @kernel_read_file: 632 * Read a file specified by userspace. 633 * @file contains the file structure pointing to the file being read 634 * by the kernel. 635 * @id kernel read file identifier 636 * Return 0 if permission is granted. 637 * @kernel_post_read_file: 638 * Read a file specified by userspace. 639 * @file contains the file structure pointing to the file being read 640 * by the kernel. 641 * @buf pointer to buffer containing the file contents. 642 * @size length of the file contents. 643 * @id kernel read file identifier 644 * Return 0 if permission is granted. 645 * @task_fix_setuid: 646 * Update the module's state after setting one or more of the user 647 * identity attributes of the current process. The @flags parameter 648 * indicates which of the set*uid system calls invoked this hook. If 649 * @new is the set of credentials that will be installed. Modifications 650 * should be made to this rather than to @current->cred. 651 * @old is the set of credentials that are being replaces 652 * @flags contains one of the LSM_SETID_* values. 653 * Return 0 on success. 654 * @task_setpgid: 655 * Check permission before setting the process group identifier of the 656 * process @p to @pgid. 657 * @p contains the task_struct for process being modified. 658 * @pgid contains the new pgid. 659 * Return 0 if permission is granted. 660 * @task_getpgid: 661 * Check permission before getting the process group identifier of the 662 * process @p. 663 * @p contains the task_struct for the process. 664 * Return 0 if permission is granted. 665 * @task_getsid: 666 * Check permission before getting the session identifier of the process 667 * @p. 668 * @p contains the task_struct for the process. 669 * Return 0 if permission is granted. 670 * @task_getsecid: 671 * Retrieve the security identifier of the process @p. 672 * @p contains the task_struct for the process and place is into @secid. 673 * In case of failure, @secid will be set to zero. 674 * 675 * @task_setnice: 676 * Check permission before setting the nice value of @p to @nice. 677 * @p contains the task_struct of process. 678 * @nice contains the new nice value. 679 * Return 0 if permission is granted. 680 * @task_setioprio: 681 * Check permission before setting the ioprio value of @p to @ioprio. 682 * @p contains the task_struct of process. 683 * @ioprio contains the new ioprio value 684 * Return 0 if permission is granted. 685 * @task_getioprio: 686 * Check permission before getting the ioprio value of @p. 687 * @p contains the task_struct of process. 688 * Return 0 if permission is granted. 689 * @task_prlimit: 690 * Check permission before getting and/or setting the resource limits of 691 * another task. 692 * @cred points to the cred structure for the current task. 693 * @tcred points to the cred structure for the target task. 694 * @flags contains the LSM_PRLIMIT_* flag bits indicating whether the 695 * resource limits are being read, modified, or both. 696 * Return 0 if permission is granted. 697 * @task_setrlimit: 698 * Check permission before setting the resource limits of process @p 699 * for @resource to @new_rlim. The old resource limit values can 700 * be examined by dereferencing (p->signal->rlim + resource). 701 * @p points to the task_struct for the target task's group leader. 702 * @resource contains the resource whose limit is being set. 703 * @new_rlim contains the new limits for @resource. 704 * Return 0 if permission is granted. 705 * @task_setscheduler: 706 * Check permission before setting scheduling policy and/or parameters of 707 * process @p. 708 * @p contains the task_struct for process. 709 * Return 0 if permission is granted. 710 * @task_getscheduler: 711 * Check permission before obtaining scheduling information for process 712 * @p. 713 * @p contains the task_struct for process. 714 * Return 0 if permission is granted. 715 * @task_movememory: 716 * Check permission before moving memory owned by process @p. 717 * @p contains the task_struct for process. 718 * Return 0 if permission is granted. 719 * @task_kill: 720 * Check permission before sending signal @sig to @p. @info can be NULL, 721 * the constant 1, or a pointer to a kernel_siginfo structure. If @info is 1 or 722 * SI_FROMKERNEL(info) is true, then the signal should be viewed as coming 723 * from the kernel and should typically be permitted. 724 * SIGIO signals are handled separately by the send_sigiotask hook in 725 * file_security_ops. 726 * @p contains the task_struct for process. 727 * @info contains the signal information. 728 * @sig contains the signal value. 729 * @cred contains the cred of the process where the signal originated, or 730 * NULL if the current task is the originator. 731 * Return 0 if permission is granted. 732 * @task_prctl: 733 * Check permission before performing a process control operation on the 734 * current process. 735 * @option contains the operation. 736 * @arg2 contains a argument. 737 * @arg3 contains a argument. 738 * @arg4 contains a argument. 739 * @arg5 contains a argument. 740 * Return -ENOSYS if no-one wanted to handle this op, any other value to 741 * cause prctl() to return immediately with that value. 742 * @task_to_inode: 743 * Set the security attributes for an inode based on an associated task's 744 * security attributes, e.g. for /proc/pid inodes. 745 * @p contains the task_struct for the task. 746 * @inode contains the inode structure for the inode. 747 * 748 * Security hooks for Netlink messaging. 749 * 750 * @netlink_send: 751 * Save security information for a netlink message so that permission 752 * checking can be performed when the message is processed. The security 753 * information can be saved using the eff_cap field of the 754 * netlink_skb_parms structure. Also may be used to provide fine 755 * grained control over message transmission. 756 * @sk associated sock of task sending the message. 757 * @skb contains the sk_buff structure for the netlink message. 758 * Return 0 if the information was successfully saved and message 759 * is allowed to be transmitted. 760 * 761 * Security hooks for Unix domain networking. 762 * 763 * @unix_stream_connect: 764 * Check permissions before establishing a Unix domain stream connection 765 * between @sock and @other. 766 * @sock contains the sock structure. 767 * @other contains the peer sock structure. 768 * @newsk contains the new sock structure. 769 * Return 0 if permission is granted. 770 * @unix_may_send: 771 * Check permissions before connecting or sending datagrams from @sock to 772 * @other. 773 * @sock contains the socket structure. 774 * @other contains the peer socket structure. 775 * Return 0 if permission is granted. 776 * 777 * The @unix_stream_connect and @unix_may_send hooks were necessary because 778 * Linux provides an alternative to the conventional file name space for Unix 779 * domain sockets. Whereas binding and connecting to sockets in the file name 780 * space is mediated by the typical file permissions (and caught by the mknod 781 * and permission hooks in inode_security_ops), binding and connecting to 782 * sockets in the abstract name space is completely unmediated. Sufficient 783 * control of Unix domain sockets in the abstract name space isn't possible 784 * using only the socket layer hooks, since we need to know the actual target 785 * socket, which is not looked up until we are inside the af_unix code. 786 * 787 * Security hooks for socket operations. 788 * 789 * @socket_create: 790 * Check permissions prior to creating a new socket. 791 * @family contains the requested protocol family. 792 * @type contains the requested communications type. 793 * @protocol contains the requested protocol. 794 * @kern set to 1 if a kernel socket. 795 * Return 0 if permission is granted. 796 * @socket_post_create: 797 * This hook allows a module to update or allocate a per-socket security 798 * structure. Note that the security field was not added directly to the 799 * socket structure, but rather, the socket security information is stored 800 * in the associated inode. Typically, the inode alloc_security hook will 801 * allocate and and attach security information to 802 * SOCK_INODE(sock)->i_security. This hook may be used to update the 803 * SOCK_INODE(sock)->i_security field with additional information that 804 * wasn't available when the inode was allocated. 805 * @sock contains the newly created socket structure. 806 * @family contains the requested protocol family. 807 * @type contains the requested communications type. 808 * @protocol contains the requested protocol. 809 * @kern set to 1 if a kernel socket. 810 * @socket_socketpair: 811 * Check permissions before creating a fresh pair of sockets. 812 * @socka contains the first socket structure. 813 * @sockb contains the second socket structure. 814 * Return 0 if permission is granted and the connection was established. 815 * @socket_bind: 816 * Check permission before socket protocol layer bind operation is 817 * performed and the socket @sock is bound to the address specified in the 818 * @address parameter. 819 * @sock contains the socket structure. 820 * @address contains the address to bind to. 821 * @addrlen contains the length of address. 822 * Return 0 if permission is granted. 823 * @socket_connect: 824 * Check permission before socket protocol layer connect operation 825 * attempts to connect socket @sock to a remote address, @address. 826 * @sock contains the socket structure. 827 * @address contains the address of remote endpoint. 828 * @addrlen contains the length of address. 829 * Return 0 if permission is granted. 830 * @socket_listen: 831 * Check permission before socket protocol layer listen operation. 832 * @sock contains the socket structure. 833 * @backlog contains the maximum length for the pending connection queue. 834 * Return 0 if permission is granted. 835 * @socket_accept: 836 * Check permission before accepting a new connection. Note that the new 837 * socket, @newsock, has been created and some information copied to it, 838 * but the accept operation has not actually been performed. 839 * @sock contains the listening socket structure. 840 * @newsock contains the newly created server socket for connection. 841 * Return 0 if permission is granted. 842 * @socket_sendmsg: 843 * Check permission before transmitting a message to another socket. 844 * @sock contains the socket structure. 845 * @msg contains the message to be transmitted. 846 * @size contains the size of message. 847 * Return 0 if permission is granted. 848 * @socket_recvmsg: 849 * Check permission before receiving a message from a socket. 850 * @sock contains the socket structure. 851 * @msg contains the message structure. 852 * @size contains the size of message structure. 853 * @flags contains the operational flags. 854 * Return 0 if permission is granted. 855 * @socket_getsockname: 856 * Check permission before the local address (name) of the socket object 857 * @sock is retrieved. 858 * @sock contains the socket structure. 859 * Return 0 if permission is granted. 860 * @socket_getpeername: 861 * Check permission before the remote address (name) of a socket object 862 * @sock is retrieved. 863 * @sock contains the socket structure. 864 * Return 0 if permission is granted. 865 * @socket_getsockopt: 866 * Check permissions before retrieving the options associated with socket 867 * @sock. 868 * @sock contains the socket structure. 869 * @level contains the protocol level to retrieve option from. 870 * @optname contains the name of option to retrieve. 871 * Return 0 if permission is granted. 872 * @socket_setsockopt: 873 * Check permissions before setting the options associated with socket 874 * @sock. 875 * @sock contains the socket structure. 876 * @level contains the protocol level to set options for. 877 * @optname contains the name of the option to set. 878 * Return 0 if permission is granted. 879 * @socket_shutdown: 880 * Checks permission before all or part of a connection on the socket 881 * @sock is shut down. 882 * @sock contains the socket structure. 883 * @how contains the flag indicating how future sends and receives 884 * are handled. 885 * Return 0 if permission is granted. 886 * @socket_sock_rcv_skb: 887 * Check permissions on incoming network packets. This hook is distinct 888 * from Netfilter's IP input hooks since it is the first time that the 889 * incoming sk_buff @skb has been associated with a particular socket, @sk. 890 * Must not sleep inside this hook because some callers hold spinlocks. 891 * @sk contains the sock (not socket) associated with the incoming sk_buff. 892 * @skb contains the incoming network data. 893 * @socket_getpeersec_stream: 894 * This hook allows the security module to provide peer socket security 895 * state for unix or connected tcp sockets to userspace via getsockopt 896 * SO_GETPEERSEC. For tcp sockets this can be meaningful if the 897 * socket is associated with an ipsec SA. 898 * @sock is the local socket. 899 * @optval userspace memory where the security state is to be copied. 900 * @optlen userspace int where the module should copy the actual length 901 * of the security state. 902 * @len as input is the maximum length to copy to userspace provided 903 * by the caller. 904 * Return 0 if all is well, otherwise, typical getsockopt return 905 * values. 906 * @socket_getpeersec_dgram: 907 * This hook allows the security module to provide peer socket security 908 * state for udp sockets on a per-packet basis to userspace via 909 * getsockopt SO_GETPEERSEC. The application must first have indicated 910 * the IP_PASSSEC option via getsockopt. It can then retrieve the 911 * security state returned by this hook for a packet via the SCM_SECURITY 912 * ancillary message type. 913 * @sock contains the peer socket. May be NULL. 914 * @skb is the sk_buff for the packet being queried. May be NULL. 915 * @secid pointer to store the secid of the packet. 916 * Return 0 on success, error on failure. 917 * @sk_alloc_security: 918 * Allocate and attach a security structure to the sk->sk_security field, 919 * which is used to copy security attributes between local stream sockets. 920 * @sk_free_security: 921 * Deallocate security structure. 922 * @sk_clone_security: 923 * Clone/copy security structure. 924 * @sk_getsecid: 925 * Retrieve the LSM-specific secid for the sock to enable caching 926 * of network authorizations. 927 * @sock_graft: 928 * Sets the socket's isec sid to the sock's sid. 929 * @inet_conn_request: 930 * Sets the openreq's sid to socket's sid with MLS portion taken 931 * from peer sid. 932 * @inet_csk_clone: 933 * Sets the new child socket's sid to the openreq sid. 934 * @inet_conn_established: 935 * Sets the connection's peersid to the secmark on skb. 936 * @secmark_relabel_packet: 937 * check if the process should be allowed to relabel packets to 938 * the given secid 939 * @secmark_refcount_inc: 940 * tells the LSM to increment the number of secmark labeling rules loaded 941 * @secmark_refcount_dec: 942 * tells the LSM to decrement the number of secmark labeling rules loaded 943 * @req_classify_flow: 944 * Sets the flow's sid to the openreq sid. 945 * @tun_dev_alloc_security: 946 * This hook allows a module to allocate a security structure for a TUN 947 * device. 948 * @security pointer to a security structure pointer. 949 * Returns a zero on success, negative values on failure. 950 * @tun_dev_free_security: 951 * This hook allows a module to free the security structure for a TUN 952 * device. 953 * @security pointer to the TUN device's security structure 954 * @tun_dev_create: 955 * Check permissions prior to creating a new TUN device. 956 * @tun_dev_attach_queue: 957 * Check permissions prior to attaching to a TUN device queue. 958 * @security pointer to the TUN device's security structure. 959 * @tun_dev_attach: 960 * This hook can be used by the module to update any security state 961 * associated with the TUN device's sock structure. 962 * @sk contains the existing sock structure. 963 * @security pointer to the TUN device's security structure. 964 * @tun_dev_open: 965 * This hook can be used by the module to update any security state 966 * associated with the TUN device's security structure. 967 * @security pointer to the TUN devices's security structure. 968 * 969 * Security hooks for SCTP 970 * 971 * @sctp_assoc_request: 972 * Passes the @ep and @chunk->skb of the association INIT packet to 973 * the security module. 974 * @ep pointer to sctp endpoint structure. 975 * @skb pointer to skbuff of association packet. 976 * Return 0 on success, error on failure. 977 * @sctp_bind_connect: 978 * Validiate permissions required for each address associated with sock 979 * @sk. Depending on @optname, the addresses will be treated as either 980 * for a connect or bind service. The @addrlen is calculated on each 981 * ipv4 and ipv6 address using sizeof(struct sockaddr_in) or 982 * sizeof(struct sockaddr_in6). 983 * @sk pointer to sock structure. 984 * @optname name of the option to validate. 985 * @address list containing one or more ipv4/ipv6 addresses. 986 * @addrlen total length of address(s). 987 * Return 0 on success, error on failure. 988 * @sctp_sk_clone: 989 * Called whenever a new socket is created by accept(2) (i.e. a TCP 990 * style socket) or when a socket is 'peeled off' e.g userspace 991 * calls sctp_peeloff(3). 992 * @ep pointer to current sctp endpoint structure. 993 * @sk pointer to current sock structure. 994 * @sk pointer to new sock structure. 995 * 996 * Security hooks for Infiniband 997 * 998 * @ib_pkey_access: 999 * Check permission to access a pkey when modifing a QP. 1000 * @subnet_prefix the subnet prefix of the port being used. 1001 * @pkey the pkey to be accessed. 1002 * @sec pointer to a security structure. 1003 * @ib_endport_manage_subnet: 1004 * Check permissions to send and receive SMPs on a end port. 1005 * @dev_name the IB device name (i.e. mlx4_0). 1006 * @port_num the port number. 1007 * @sec pointer to a security structure. 1008 * @ib_alloc_security: 1009 * Allocate a security structure for Infiniband objects. 1010 * @sec pointer to a security structure pointer. 1011 * Returns 0 on success, non-zero on failure 1012 * @ib_free_security: 1013 * Deallocate an Infiniband security structure. 1014 * @sec contains the security structure to be freed. 1015 * 1016 * Security hooks for XFRM operations. 1017 * 1018 * @xfrm_policy_alloc_security: 1019 * @ctxp is a pointer to the xfrm_sec_ctx being added to Security Policy 1020 * Database used by the XFRM system. 1021 * @sec_ctx contains the security context information being provided by 1022 * the user-level policy update program (e.g., setkey). 1023 * Allocate a security structure to the xp->security field; the security 1024 * field is initialized to NULL when the xfrm_policy is allocated. 1025 * Return 0 if operation was successful (memory to allocate, legal context) 1026 * @gfp is to specify the context for the allocation 1027 * @xfrm_policy_clone_security: 1028 * @old_ctx contains an existing xfrm_sec_ctx. 1029 * @new_ctxp contains a new xfrm_sec_ctx being cloned from old. 1030 * Allocate a security structure in new_ctxp that contains the 1031 * information from the old_ctx structure. 1032 * Return 0 if operation was successful (memory to allocate). 1033 * @xfrm_policy_free_security: 1034 * @ctx contains the xfrm_sec_ctx 1035 * Deallocate xp->security. 1036 * @xfrm_policy_delete_security: 1037 * @ctx contains the xfrm_sec_ctx. 1038 * Authorize deletion of xp->security. 1039 * @xfrm_state_alloc: 1040 * @x contains the xfrm_state being added to the Security Association 1041 * Database by the XFRM system. 1042 * @sec_ctx contains the security context information being provided by 1043 * the user-level SA generation program (e.g., setkey or racoon). 1044 * Allocate a security structure to the x->security field; the security 1045 * field is initialized to NULL when the xfrm_state is allocated. Set the 1046 * context to correspond to sec_ctx. Return 0 if operation was successful 1047 * (memory to allocate, legal context). 1048 * @xfrm_state_alloc_acquire: 1049 * @x contains the xfrm_state being added to the Security Association 1050 * Database by the XFRM system. 1051 * @polsec contains the policy's security context. 1052 * @secid contains the secid from which to take the mls portion of the 1053 * context. 1054 * Allocate a security structure to the x->security field; the security 1055 * field is initialized to NULL when the xfrm_state is allocated. Set the 1056 * context to correspond to secid. Return 0 if operation was successful 1057 * (memory to allocate, legal context). 1058 * @xfrm_state_free_security: 1059 * @x contains the xfrm_state. 1060 * Deallocate x->security. 1061 * @xfrm_state_delete_security: 1062 * @x contains the xfrm_state. 1063 * Authorize deletion of x->security. 1064 * @xfrm_policy_lookup: 1065 * @ctx contains the xfrm_sec_ctx for which the access control is being 1066 * checked. 1067 * @fl_secid contains the flow security label that is used to authorize 1068 * access to the policy xp. 1069 * @dir contains the direction of the flow (input or output). 1070 * Check permission when a flow selects a xfrm_policy for processing 1071 * XFRMs on a packet. The hook is called when selecting either a 1072 * per-socket policy or a generic xfrm policy. 1073 * Return 0 if permission is granted, -ESRCH otherwise, or -errno 1074 * on other errors. 1075 * @xfrm_state_pol_flow_match: 1076 * @x contains the state to match. 1077 * @xp contains the policy to check for a match. 1078 * @fl contains the flow to check for a match. 1079 * Return 1 if there is a match. 1080 * @xfrm_decode_session: 1081 * @skb points to skb to decode. 1082 * @secid points to the flow key secid to set. 1083 * @ckall says if all xfrms used should be checked for same secid. 1084 * Return 0 if ckall is zero or all xfrms used have the same secid. 1085 * 1086 * Security hooks affecting all Key Management operations 1087 * 1088 * @key_alloc: 1089 * Permit allocation of a key and assign security data. Note that key does 1090 * not have a serial number assigned at this point. 1091 * @key points to the key. 1092 * @flags is the allocation flags 1093 * Return 0 if permission is granted, -ve error otherwise. 1094 * @key_free: 1095 * Notification of destruction; free security data. 1096 * @key points to the key. 1097 * No return value. 1098 * @key_permission: 1099 * See whether a specific operational right is granted to a process on a 1100 * key. 1101 * @key_ref refers to the key (key pointer + possession attribute bit). 1102 * @cred points to the credentials to provide the context against which to 1103 * evaluate the security data on the key. 1104 * @perm describes the combination of permissions required of this key. 1105 * Return 0 if permission is granted, -ve error otherwise. 1106 * @key_getsecurity: 1107 * Get a textual representation of the security context attached to a key 1108 * for the purposes of honouring KEYCTL_GETSECURITY. This function 1109 * allocates the storage for the NUL-terminated string and the caller 1110 * should free it. 1111 * @key points to the key to be queried. 1112 * @_buffer points to a pointer that should be set to point to the 1113 * resulting string (if no label or an error occurs). 1114 * Return the length of the string (including terminating NUL) or -ve if 1115 * an error. 1116 * May also return 0 (and a NULL buffer pointer) if there is no label. 1117 * 1118 * Security hooks affecting all System V IPC operations. 1119 * 1120 * @ipc_permission: 1121 * Check permissions for access to IPC 1122 * @ipcp contains the kernel IPC permission structure 1123 * @flag contains the desired (requested) permission set 1124 * Return 0 if permission is granted. 1125 * @ipc_getsecid: 1126 * Get the secid associated with the ipc object. 1127 * @ipcp contains the kernel IPC permission structure. 1128 * @secid contains a pointer to the location where result will be saved. 1129 * In case of failure, @secid will be set to zero. 1130 * 1131 * Security hooks for individual messages held in System V IPC message queues 1132 * 1133 * @msg_msg_alloc_security: 1134 * Allocate and attach a security structure to the msg->security field. 1135 * The security field is initialized to NULL when the structure is first 1136 * created. 1137 * @msg contains the message structure to be modified. 1138 * Return 0 if operation was successful and permission is granted. 1139 * @msg_msg_free_security: 1140 * Deallocate the security structure for this message. 1141 * @msg contains the message structure to be modified. 1142 * 1143 * Security hooks for System V IPC Message Queues 1144 * 1145 * @msg_queue_alloc_security: 1146 * Allocate and attach a security structure to the 1147 * @perm->security field. The security field is initialized to 1148 * NULL when the structure is first created. 1149 * @perm contains the IPC permissions of the message queue. 1150 * Return 0 if operation was successful and permission is granted. 1151 * @msg_queue_free_security: 1152 * Deallocate security field @perm->security for the message queue. 1153 * @perm contains the IPC permissions of the message queue. 1154 * @msg_queue_associate: 1155 * Check permission when a message queue is requested through the 1156 * msgget system call. This hook is only called when returning the 1157 * message queue identifier for an existing message queue, not when a 1158 * new message queue is created. 1159 * @perm contains the IPC permissions of the message queue. 1160 * @msqflg contains the operation control flags. 1161 * Return 0 if permission is granted. 1162 * @msg_queue_msgctl: 1163 * Check permission when a message control operation specified by @cmd 1164 * is to be performed on the message queue with permissions @perm. 1165 * The @perm may be NULL, e.g. for IPC_INFO or MSG_INFO. 1166 * @perm contains the IPC permissions of the msg queue. May be NULL. 1167 * @cmd contains the operation to be performed. 1168 * Return 0 if permission is granted. 1169 * @msg_queue_msgsnd: 1170 * Check permission before a message, @msg, is enqueued on the message 1171 * queue with permissions @perm. 1172 * @perm contains the IPC permissions of the message queue. 1173 * @msg contains the message to be enqueued. 1174 * @msqflg contains operational flags. 1175 * Return 0 if permission is granted. 1176 * @msg_queue_msgrcv: 1177 * Check permission before a message, @msg, is removed from the message 1178 * queue. The @target task structure contains a pointer to the 1179 * process that will be receiving the message (not equal to the current 1180 * process when inline receives are being performed). 1181 * @perm contains the IPC permissions of the message queue. 1182 * @msg contains the message destination. 1183 * @target contains the task structure for recipient process. 1184 * @type contains the type of message requested. 1185 * @mode contains the operational flags. 1186 * Return 0 if permission is granted. 1187 * 1188 * Security hooks for System V Shared Memory Segments 1189 * 1190 * @shm_alloc_security: 1191 * Allocate and attach a security structure to the @perm->security 1192 * field. The security field is initialized to NULL when the structure is 1193 * first created. 1194 * @perm contains the IPC permissions of the shared memory structure. 1195 * Return 0 if operation was successful and permission is granted. 1196 * @shm_free_security: 1197 * Deallocate the security structure @perm->security for the memory segment. 1198 * @perm contains the IPC permissions of the shared memory structure. 1199 * @shm_associate: 1200 * Check permission when a shared memory region is requested through the 1201 * shmget system call. This hook is only called when returning the shared 1202 * memory region identifier for an existing region, not when a new shared 1203 * memory region is created. 1204 * @perm contains the IPC permissions of the shared memory structure. 1205 * @shmflg contains the operation control flags. 1206 * Return 0 if permission is granted. 1207 * @shm_shmctl: 1208 * Check permission when a shared memory control operation specified by 1209 * @cmd is to be performed on the shared memory region with permissions @perm. 1210 * The @perm may be NULL, e.g. for IPC_INFO or SHM_INFO. 1211 * @perm contains the IPC permissions of the shared memory structure. 1212 * @cmd contains the operation to be performed. 1213 * Return 0 if permission is granted. 1214 * @shm_shmat: 1215 * Check permissions prior to allowing the shmat system call to attach the 1216 * shared memory segment with permissions @perm to the data segment of the 1217 * calling process. The attaching address is specified by @shmaddr. 1218 * @perm contains the IPC permissions of the shared memory structure. 1219 * @shmaddr contains the address to attach memory region to. 1220 * @shmflg contains the operational flags. 1221 * Return 0 if permission is granted. 1222 * 1223 * Security hooks for System V Semaphores 1224 * 1225 * @sem_alloc_security: 1226 * Allocate and attach a security structure to the @perm->security 1227 * field. The security field is initialized to NULL when the structure is 1228 * first created. 1229 * @perm contains the IPC permissions of the semaphore. 1230 * Return 0 if operation was successful and permission is granted. 1231 * @sem_free_security: 1232 * Deallocate security structure @perm->security for the semaphore. 1233 * @perm contains the IPC permissions of the semaphore. 1234 * @sem_associate: 1235 * Check permission when a semaphore is requested through the semget 1236 * system call. This hook is only called when returning the semaphore 1237 * identifier for an existing semaphore, not when a new one must be 1238 * created. 1239 * @perm contains the IPC permissions of the semaphore. 1240 * @semflg contains the operation control flags. 1241 * Return 0 if permission is granted. 1242 * @sem_semctl: 1243 * Check permission when a semaphore operation specified by @cmd is to be 1244 * performed on the semaphore. The @perm may be NULL, e.g. for 1245 * IPC_INFO or SEM_INFO. 1246 * @perm contains the IPC permissions of the semaphore. May be NULL. 1247 * @cmd contains the operation to be performed. 1248 * Return 0 if permission is granted. 1249 * @sem_semop: 1250 * Check permissions before performing operations on members of the 1251 * semaphore set. If the @alter flag is nonzero, the semaphore set 1252 * may be modified. 1253 * @perm contains the IPC permissions of the semaphore. 1254 * @sops contains the operations to perform. 1255 * @nsops contains the number of operations to perform. 1256 * @alter contains the flag indicating whether changes are to be made. 1257 * Return 0 if permission is granted. 1258 * 1259 * @binder_set_context_mgr: 1260 * Check whether @mgr is allowed to be the binder context manager. 1261 * @mgr contains the task_struct for the task being registered. 1262 * Return 0 if permission is granted. 1263 * @binder_transaction: 1264 * Check whether @from is allowed to invoke a binder transaction call 1265 * to @to. 1266 * @from contains the task_struct for the sending task. 1267 * @to contains the task_struct for the receiving task. 1268 * @binder_transfer_binder: 1269 * Check whether @from is allowed to transfer a binder reference to @to. 1270 * @from contains the task_struct for the sending task. 1271 * @to contains the task_struct for the receiving task. 1272 * @binder_transfer_file: 1273 * Check whether @from is allowed to transfer @file to @to. 1274 * @from contains the task_struct for the sending task. 1275 * @file contains the struct file being transferred. 1276 * @to contains the task_struct for the receiving task. 1277 * 1278 * @ptrace_access_check: 1279 * Check permission before allowing the current process to trace the 1280 * @child process. 1281 * Security modules may also want to perform a process tracing check 1282 * during an execve in the set_security or apply_creds hooks of 1283 * tracing check during an execve in the bprm_set_creds hook of 1284 * binprm_security_ops if the process is being traced and its security 1285 * attributes would be changed by the execve. 1286 * @child contains the task_struct structure for the target process. 1287 * @mode contains the PTRACE_MODE flags indicating the form of access. 1288 * Return 0 if permission is granted. 1289 * @ptrace_traceme: 1290 * Check that the @parent process has sufficient permission to trace the 1291 * current process before allowing the current process to present itself 1292 * to the @parent process for tracing. 1293 * @parent contains the task_struct structure for debugger process. 1294 * Return 0 if permission is granted. 1295 * @capget: 1296 * Get the @effective, @inheritable, and @permitted capability sets for 1297 * the @target process. The hook may also perform permission checking to 1298 * determine if the current process is allowed to see the capability sets 1299 * of the @target process. 1300 * @target contains the task_struct structure for target process. 1301 * @effective contains the effective capability set. 1302 * @inheritable contains the inheritable capability set. 1303 * @permitted contains the permitted capability set. 1304 * Return 0 if the capability sets were successfully obtained. 1305 * @capset: 1306 * Set the @effective, @inheritable, and @permitted capability sets for 1307 * the current process. 1308 * @new contains the new credentials structure for target process. 1309 * @old contains the current credentials structure for target process. 1310 * @effective contains the effective capability set. 1311 * @inheritable contains the inheritable capability set. 1312 * @permitted contains the permitted capability set. 1313 * Return 0 and update @new if permission is granted. 1314 * @capable: 1315 * Check whether the @tsk process has the @cap capability in the indicated 1316 * credentials. 1317 * @cred contains the credentials to use. 1318 * @ns contains the user namespace we want the capability in 1319 * @cap contains the capability <include/linux/capability.h>. 1320 * @opts contains options for the capable check <include/linux/security.h> 1321 * Return 0 if the capability is granted for @tsk. 1322 * @quotactl: 1323 * Check whether the quotactl syscall is allowed for this @sb. 1324 * @quota_on: 1325 * Check whether QUOTAON is allowed for this @dentry. 1326 * @syslog: 1327 * Check permission before accessing the kernel message ring or changing 1328 * logging to the console. 1329 * See the syslog(2) manual page for an explanation of the @type values. 1330 * @type contains the SYSLOG_ACTION_* constant from <include/linux/syslog.h> 1331 * Return 0 if permission is granted. 1332 * @settime: 1333 * Check permission to change the system time. 1334 * struct timespec64 is defined in <include/linux/time64.h> and timezone 1335 * is defined in <include/linux/time.h> 1336 * @ts contains new time 1337 * @tz contains new timezone 1338 * Return 0 if permission is granted. 1339 * @vm_enough_memory: 1340 * Check permissions for allocating a new virtual mapping. 1341 * @mm contains the mm struct it is being added to. 1342 * @pages contains the number of pages. 1343 * Return 0 if permission is granted. 1344 * 1345 * @ismaclabel: 1346 * Check if the extended attribute specified by @name 1347 * represents a MAC label. Returns 1 if name is a MAC 1348 * attribute otherwise returns 0. 1349 * @name full extended attribute name to check against 1350 * LSM as a MAC label. 1351 * 1352 * @secid_to_secctx: 1353 * Convert secid to security context. If secdata is NULL the length of 1354 * the result will be returned in seclen, but no secdata will be returned. 1355 * This does mean that the length could change between calls to check the 1356 * length and the next call which actually allocates and returns the 1357 * secdata. 1358 * @secid contains the security ID. 1359 * @secdata contains the pointer that stores the converted security 1360 * context. 1361 * @seclen pointer which contains the length of the data 1362 * @secctx_to_secid: 1363 * Convert security context to secid. 1364 * @secid contains the pointer to the generated security ID. 1365 * @secdata contains the security context. 1366 * 1367 * @release_secctx: 1368 * Release the security context. 1369 * @secdata contains the security context. 1370 * @seclen contains the length of the security context. 1371 * 1372 * Security hooks for Audit 1373 * 1374 * @audit_rule_init: 1375 * Allocate and initialize an LSM audit rule structure. 1376 * @field contains the required Audit action. 1377 * Fields flags are defined in <include/linux/audit.h> 1378 * @op contains the operator the rule uses. 1379 * @rulestr contains the context where the rule will be applied to. 1380 * @lsmrule contains a pointer to receive the result. 1381 * Return 0 if @lsmrule has been successfully set, 1382 * -EINVAL in case of an invalid rule. 1383 * 1384 * @audit_rule_known: 1385 * Specifies whether given @krule contains any fields related to 1386 * current LSM. 1387 * @krule contains the audit rule of interest. 1388 * Return 1 in case of relation found, 0 otherwise. 1389 * 1390 * @audit_rule_match: 1391 * Determine if given @secid matches a rule previously approved 1392 * by @audit_rule_known. 1393 * @secid contains the security id in question. 1394 * @field contains the field which relates to current LSM. 1395 * @op contains the operator that will be used for matching. 1396 * @lrule points to the audit rule that will be checked against. 1397 * Return 1 if secid matches the rule, 0 if it does not, -ERRNO on failure. 1398 * 1399 * @audit_rule_free: 1400 * Deallocate the LSM audit rule structure previously allocated by 1401 * audit_rule_init. 1402 * @lsmrule contains the allocated rule 1403 * 1404 * @inode_invalidate_secctx: 1405 * Notify the security module that it must revalidate the security context 1406 * of an inode. 1407 * 1408 * @inode_notifysecctx: 1409 * Notify the security module of what the security context of an inode 1410 * should be. Initializes the incore security context managed by the 1411 * security module for this inode. Example usage: NFS client invokes 1412 * this hook to initialize the security context in its incore inode to the 1413 * value provided by the server for the file when the server returned the 1414 * file's attributes to the client. 1415 * Must be called with inode->i_mutex locked. 1416 * @inode we wish to set the security context of. 1417 * @ctx contains the string which we wish to set in the inode. 1418 * @ctxlen contains the length of @ctx. 1419 * 1420 * @inode_setsecctx: 1421 * Change the security context of an inode. Updates the 1422 * incore security context managed by the security module and invokes the 1423 * fs code as needed (via __vfs_setxattr_noperm) to update any backing 1424 * xattrs that represent the context. Example usage: NFS server invokes 1425 * this hook to change the security context in its incore inode and on the 1426 * backing filesystem to a value provided by the client on a SETATTR 1427 * operation. 1428 * Must be called with inode->i_mutex locked. 1429 * @dentry contains the inode we wish to set the security context of. 1430 * @ctx contains the string which we wish to set in the inode. 1431 * @ctxlen contains the length of @ctx. 1432 * 1433 * @inode_getsecctx: 1434 * On success, returns 0 and fills out @ctx and @ctxlen with the security 1435 * context for the given @inode. 1436 * @inode we wish to get the security context of. 1437 * @ctx is a pointer in which to place the allocated security context. 1438 * @ctxlen points to the place to put the length of @ctx. 1439 * 1440 * Security hooks for using the eBPF maps and programs functionalities through 1441 * eBPF syscalls. 1442 * 1443 * @bpf: 1444 * Do a initial check for all bpf syscalls after the attribute is copied 1445 * into the kernel. The actual security module can implement their own 1446 * rules to check the specific cmd they need. 1447 * 1448 * @bpf_map: 1449 * Do a check when the kernel generate and return a file descriptor for 1450 * eBPF maps. 1451 * 1452 * @map: bpf map that we want to access 1453 * @mask: the access flags 1454 * 1455 * @bpf_prog: 1456 * Do a check when the kernel generate and return a file descriptor for 1457 * eBPF programs. 1458 * 1459 * @prog: bpf prog that userspace want to use. 1460 * 1461 * @bpf_map_alloc_security: 1462 * Initialize the security field inside bpf map. 1463 * 1464 * @bpf_map_free_security: 1465 * Clean up the security information stored inside bpf map. 1466 * 1467 * @bpf_prog_alloc_security: 1468 * Initialize the security field inside bpf program. 1469 * 1470 * @bpf_prog_free_security: 1471 * Clean up the security information stored inside bpf prog. 1472 * 1473 * @locked_down: 1474 * Determine whether a kernel feature that potentially enables arbitrary 1475 * code execution in kernel space should be permitted. 1476 * 1477 * @what: kernel feature being accessed 1478 * 1479 * Security hooks for perf events 1480 * 1481 * @perf_event_open: 1482 * Check whether the @type of perf_event_open syscall is allowed. 1483 * @perf_event_alloc: 1484 * Allocate and save perf_event security info. 1485 * @perf_event_free: 1486 * Release (free) perf_event security info. 1487 * @perf_event_read: 1488 * Read perf_event security info if allowed. 1489 * @perf_event_write: 1490 * Write perf_event security info if allowed. 1491 */ 1492 union security_list_options { 1493 #define LSM_HOOK(RET, DEFAULT, NAME, ...) RET (*NAME)(__VA_ARGS__); 1494 #include "lsm_hook_defs.h" 1495 #undef LSM_HOOK 1496 }; 1497 1498 struct security_hook_heads { 1499 #define LSM_HOOK(RET, DEFAULT, NAME, ...) struct hlist_head NAME; 1500 #include "lsm_hook_defs.h" 1501 #undef LSM_HOOK 1502 } __randomize_layout; 1503 1504 /* 1505 * Security module hook list structure. 1506 * For use with generic list macros for common operations. 1507 */ 1508 struct security_hook_list { 1509 struct hlist_node list; 1510 struct hlist_head *head; 1511 union security_list_options hook; 1512 char *lsm; 1513 } __randomize_layout; 1514 1515 /* 1516 * Security blob size or offset data. 1517 */ 1518 struct lsm_blob_sizes { 1519 int lbs_cred; 1520 int lbs_file; 1521 int lbs_inode; 1522 int lbs_ipc; 1523 int lbs_msg_msg; 1524 int lbs_task; 1525 }; 1526 1527 /* 1528 * LSM_RET_VOID is used as the default value in LSM_HOOK definitions for void 1529 * LSM hooks (in include/linux/lsm_hook_defs.h). 1530 */ 1531 #define LSM_RET_VOID ((void) 0) 1532 1533 /* 1534 * Initializing a security_hook_list structure takes 1535 * up a lot of space in a source file. This macro takes 1536 * care of the common case and reduces the amount of 1537 * text involved. 1538 */ 1539 #define LSM_HOOK_INIT(HEAD, HOOK) \ 1540 { .head = &security_hook_heads.HEAD, .hook = { .HEAD = HOOK } } 1541 1542 extern struct security_hook_heads security_hook_heads; 1543 extern char *lsm_names; 1544 1545 extern void security_add_hooks(struct security_hook_list *hooks, int count, 1546 char *lsm); 1547 1548 #define LSM_FLAG_LEGACY_MAJOR BIT(0) 1549 #define LSM_FLAG_EXCLUSIVE BIT(1) 1550 1551 enum lsm_order { 1552 LSM_ORDER_FIRST = -1, /* This is only for capabilities. */ 1553 LSM_ORDER_MUTABLE = 0, 1554 }; 1555 1556 struct lsm_info { 1557 const char *name; /* Required. */ 1558 enum lsm_order order; /* Optional: default is LSM_ORDER_MUTABLE */ 1559 unsigned long flags; /* Optional: flags describing LSM */ 1560 int *enabled; /* Optional: controlled by CONFIG_LSM */ 1561 int (*init)(void); /* Required. */ 1562 struct lsm_blob_sizes *blobs; /* Optional: for blob sharing. */ 1563 }; 1564 1565 extern struct lsm_info __start_lsm_info[], __end_lsm_info[]; 1566 extern struct lsm_info __start_early_lsm_info[], __end_early_lsm_info[]; 1567 1568 #define DEFINE_LSM(lsm) \ 1569 static struct lsm_info __lsm_##lsm \ 1570 __used __section(.lsm_info.init) \ 1571 __aligned(sizeof(unsigned long)) 1572 1573 #define DEFINE_EARLY_LSM(lsm) \ 1574 static struct lsm_info __early_lsm_##lsm \ 1575 __used __section(.early_lsm_info.init) \ 1576 __aligned(sizeof(unsigned long)) 1577 1578 #ifdef CONFIG_SECURITY_SELINUX_DISABLE 1579 /* 1580 * Assuring the safety of deleting a security module is up to 1581 * the security module involved. This may entail ordering the 1582 * module's hook list in a particular way, refusing to disable 1583 * the module once a policy is loaded or any number of other 1584 * actions better imagined than described. 1585 * 1586 * The name of the configuration option reflects the only module 1587 * that currently uses the mechanism. Any developer who thinks 1588 * disabling their module is a good idea needs to be at least as 1589 * careful as the SELinux team. 1590 */ 1591 static inline void security_delete_hooks(struct security_hook_list *hooks, 1592 int count) 1593 { 1594 int i; 1595 1596 for (i = 0; i < count; i++) 1597 hlist_del_rcu(&hooks[i].list); 1598 } 1599 #endif /* CONFIG_SECURITY_SELINUX_DISABLE */ 1600 1601 /* Currently required to handle SELinux runtime hook disable. */ 1602 #ifdef CONFIG_SECURITY_WRITABLE_HOOKS 1603 #define __lsm_ro_after_init 1604 #else 1605 #define __lsm_ro_after_init __ro_after_init 1606 #endif /* CONFIG_SECURITY_WRITABLE_HOOKS */ 1607 1608 extern int lsm_inode_alloc(struct inode *inode); 1609 1610 #endif /* ! __LINUX_LSM_HOOKS_H */ 1611