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