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