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