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