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