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