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