blob: 2f0990f0ed64f469058e12bcf10aab4f29ba148c [file] [log] [blame]
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001/*
2 * Linux Security Module interfaces
3 *
4 * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
5 * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com>
6 * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
7 * Copyright (C) 2001 James Morris <jmorris@intercode.com.au>
8 * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group)
9 * Copyright (C) 2015 Intel Corporation.
10 * Copyright (C) 2015 Casey Schaufler <casey@schaufler-ca.com>
Daniel Jurgensd291f1a2017-05-19 15:48:52 +030011 * Copyright (C) 2016 Mellanox Techonologies
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -070012 *
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>
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -070029#include <linux/init.h>
30#include <linux/rculist.h>
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -070031
Casey Schauflerfe7bb272015-05-02 15:10:53 -070032/**
Kees Cookf00f85a2017-05-13 04:51:42 -070033 * union security_list_options - Linux Security Module hook function list
34 *
Casey Schauflerfe7bb272015-05-02 15:10:53 -070035 * 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
Kees Cook2af62282017-07-18 15:25:29 -070046 * 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.
Casey Schauflerfe7bb272015-05-02 15:10:53 -070051 * @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().
Casey Schauflerfe7bb272015-05-02 15:10:53 -070078 *
David Howellsda2441f2018-11-01 23:07:24 +000079 * Security hooks for mount using fs_context.
80 * [See also Documentation/filesystems/mounting.txt]
81 *
Al Viro0b520752018-12-23 16:02:47 -050082 * @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.
David Howellsda2441f2018-11-01 23:07:24 +000087 * @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 *
Casey Schauflerfe7bb272015-05-02 15:10:53 -070095 * 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.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700130 * @orig the original mount data copied from userspace.
131 * @copy copied data which will be passed to the security module.
132 * Returns 0 if the copy was successful.
133 * @sb_remount:
134 * Extracts security system specific mount options and verifies no changes
135 * are being made to those options.
136 * @sb superblock being remounted
137 * @data contains the filesystem-specific data.
138 * Return 0 if permission is granted.
139 * @sb_umount:
140 * Check permission before the @mnt file system is unmounted.
141 * @mnt contains the mounted file system.
142 * @flags contains the unmount flags, e.g. MNT_FORCE.
143 * Return 0 if permission is granted.
144 * @sb_pivotroot:
145 * Check permission before pivoting the root filesystem.
146 * @old_path contains the path for the new location of the
147 * current root (put_old).
148 * @new_path contains the path for the new root (new_root).
149 * Return 0 if permission is granted.
150 * @sb_set_mnt_opts:
151 * Set the security relevant mount options used for a superblock
152 * @sb the superblock to set security mount options for
153 * @opts binary data structure containing all lsm mount data
154 * @sb_clone_mnt_opts:
155 * Copy all security options from a given superblock to another
156 * @oldsb old superblock which contain information to clone
157 * @newsb new superblock which needs filled in
158 * @sb_parse_opts_str:
159 * Parse a string of security data filling in the opts structure
160 * @options string containing all mount options known by the LSM
161 * @opts binary data structure usable by the LSM
162 * @dentry_init_security:
163 * Compute a context for a dentry as the inode is not yet available
164 * since NFSv4 has no label backed by an EA anyway.
165 * @dentry dentry to use in calculating the context.
166 * @mode mode used to determine resource type.
167 * @name name of the last path component used to create file
168 * @ctx pointer to place the pointer to the resulting context in.
169 * @ctxlen point to place the length of the resulting context.
Vivek Goyal26026252016-07-13 10:44:52 -0400170 * @dentry_create_files_as:
171 * Compute a context for a dentry as the inode is not yet available
172 * and set that context in passed in creds so that new files are
173 * created using that context. Context is calculated using the
174 * passed in creds and not the creds of the caller.
175 * @dentry dentry to use in calculating the context.
176 * @mode mode used to determine resource type.
177 * @name name of the last path component used to create file
178 * @old creds which should be used for context calculation
179 * @new creds to modify
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700180 *
181 *
182 * Security hooks for inode operations.
183 *
184 * @inode_alloc_security:
185 * Allocate and attach a security structure to @inode->i_security. The
186 * i_security field is initialized to NULL when the inode structure is
187 * allocated.
188 * @inode contains the inode structure.
189 * Return 0 if operation was successful.
190 * @inode_free_security:
191 * @inode contains the inode structure.
192 * Deallocate the inode security structure and set @inode->i_security to
193 * NULL.
194 * @inode_init_security:
195 * Obtain the security attribute name suffix and value to set on a newly
196 * created inode and set up the incore security field for the new inode.
197 * This hook is called by the fs code as part of the inode creation
198 * transaction and provides for atomic labeling of the inode, unlike
199 * the post_create/mkdir/... hooks called by the VFS. The hook function
200 * is expected to allocate the name and value via kmalloc, with the caller
201 * being responsible for calling kfree after using them.
202 * If the security module does not use security attributes or does
203 * not wish to put a security attribute on this particular inode,
204 * then it should return -EOPNOTSUPP to skip this processing.
205 * @inode contains the inode structure of the newly created inode.
206 * @dir contains the inode structure of the parent directory.
207 * @qstr contains the last path component of the new object
208 * @name will be set to the allocated name suffix (e.g. selinux).
209 * @value will be set to the allocated attribute value.
210 * @len will be set to the length of the value.
211 * Returns 0 if @name and @value have been successfully set,
Kees Cookf00f85a2017-05-13 04:51:42 -0700212 * -EOPNOTSUPP if no security attribute is needed, or
213 * -ENOMEM on memory allocation failure.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700214 * @inode_create:
215 * Check permission to create a regular file.
216 * @dir contains inode structure of the parent of the new file.
217 * @dentry contains the dentry structure for the file to be created.
218 * @mode contains the file mode of the file to be created.
219 * Return 0 if permission is granted.
220 * @inode_link:
221 * Check permission before creating a new hard link to a file.
222 * @old_dentry contains the dentry structure for an existing
223 * link to the file.
224 * @dir contains the inode structure of the parent directory
225 * of the new link.
226 * @new_dentry contains the dentry structure for the new link.
227 * Return 0 if permission is granted.
228 * @path_link:
229 * Check permission before creating a new hard link to a file.
230 * @old_dentry contains the dentry structure for an existing link
231 * to the file.
232 * @new_dir contains the path structure of the parent directory of
233 * the new link.
234 * @new_dentry contains the dentry structure for the new link.
235 * Return 0 if permission is granted.
236 * @inode_unlink:
237 * Check the permission to remove a hard link to a file.
238 * @dir contains the inode structure of parent directory of the file.
239 * @dentry contains the dentry structure for file to be unlinked.
240 * Return 0 if permission is granted.
241 * @path_unlink:
242 * Check the permission to remove a hard link to a file.
243 * @dir contains the path structure of parent directory of the file.
244 * @dentry contains the dentry structure for file to be unlinked.
245 * Return 0 if permission is granted.
246 * @inode_symlink:
247 * Check the permission to create a symbolic link to a file.
248 * @dir contains the inode structure of parent directory of
249 * the symbolic link.
250 * @dentry contains the dentry structure of the symbolic link.
251 * @old_name contains the pathname of file.
252 * Return 0 if permission is granted.
253 * @path_symlink:
254 * Check the permission to create a symbolic link to a file.
255 * @dir contains the path structure of parent directory of
256 * the symbolic link.
257 * @dentry contains the dentry structure of the symbolic link.
258 * @old_name contains the pathname of file.
259 * Return 0 if permission is granted.
260 * @inode_mkdir:
261 * Check permissions to create a new directory in the existing directory
262 * associated with inode structure @dir.
263 * @dir contains the inode structure of parent of the directory
264 * to be created.
265 * @dentry contains the dentry structure of new directory.
266 * @mode contains the mode of new directory.
267 * Return 0 if permission is granted.
268 * @path_mkdir:
269 * Check permissions to create a new directory in the existing directory
270 * associated with path structure @path.
271 * @dir contains the path structure of parent of the directory
272 * to be created.
273 * @dentry contains the dentry structure of new directory.
274 * @mode contains the mode of new directory.
275 * Return 0 if permission is granted.
276 * @inode_rmdir:
277 * Check the permission to remove a directory.
278 * @dir contains the inode structure of parent of the directory
279 * to be removed.
280 * @dentry contains the dentry structure of directory to be removed.
281 * Return 0 if permission is granted.
282 * @path_rmdir:
283 * Check the permission to remove a directory.
284 * @dir contains the path structure of parent of the directory to be
285 * removed.
286 * @dentry contains the dentry structure of directory to be removed.
287 * Return 0 if permission is granted.
288 * @inode_mknod:
289 * Check permissions when creating a special file (or a socket or a fifo
290 * file created via the mknod system call). Note that if mknod operation
291 * is being done for a regular file, then the create hook will be called
292 * and not this hook.
293 * @dir contains the inode structure of parent of the new file.
294 * @dentry contains the dentry structure of the new file.
295 * @mode contains the mode of the new file.
296 * @dev contains the device number.
297 * Return 0 if permission is granted.
298 * @path_mknod:
299 * Check permissions when creating a file. Note that this hook is called
300 * even if mknod operation is being done for a regular file.
301 * @dir contains the path structure of parent of the new file.
302 * @dentry contains the dentry structure of the new file.
303 * @mode contains the mode of the new file.
304 * @dev contains the undecoded device number. Use new_decode_dev() to get
305 * the decoded device number.
306 * Return 0 if permission is granted.
307 * @inode_rename:
308 * Check for permission to rename a file or directory.
309 * @old_dir contains the inode structure for parent of the old link.
310 * @old_dentry contains the dentry structure of the old link.
311 * @new_dir contains the inode structure for parent of the new link.
312 * @new_dentry contains the dentry structure of the new link.
313 * Return 0 if permission is granted.
314 * @path_rename:
315 * Check for permission to rename a file or directory.
316 * @old_dir contains the path structure for parent of the old link.
317 * @old_dentry contains the dentry structure of the old link.
318 * @new_dir contains the path structure for parent of the new link.
319 * @new_dentry contains the dentry structure of the new link.
320 * Return 0 if permission is granted.
321 * @path_chmod:
Denis Efremov6b6b6472019-02-26 23:49:07 +0300322 * Check for permission to change a mode of the file @path. The new
323 * mode is specified in @mode.
324 * @path contains the path structure of the file to change the mode.
325 * @mode contains the new DAC's permission, which is a bitmask of
326 * constants from <include/uapi/linux/stat.h>
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700327 * 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.
Linus Torvaldse22619a2015-06-27 13:26:03 -0700345 * @inode contains the inode, which itself is not stable in RCU-walk
346 * @rcu indicates whether we are in RCU-walk mode.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700347 * 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.
Mickaël Salaünb8aa8452016-12-22 00:32:25 +0100372 * @path contains the path structure for the file.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700373 * 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.
Vivek Goyald8ad8b42016-07-13 11:13:56 -0400430 * @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.
Vivek Goyal121ab822016-07-13 10:44:49 -0400439 * @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.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700447 *
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)
Kees Cookf00f85a2017-05-13 04:51:42 -0700530 * can always be obtained: container_of(fown, struct file, f_owner)
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700531 * @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.
Kees Cookf00f85a2017-05-13 04:51:42 -0700540 * @file_open:
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700541 * 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 *
Tetsuo Handae4e55b42017-03-24 20:46:33 +0900547 * @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.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700552 * @task_free:
Tetsuo Handae4e55b42017-03-24 20:46:33 +0900553 * @task task about to be freed.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700554 * 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
Matthew Garrett3ec30112018-01-08 13:36:19 -0800573 * @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.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700577 * @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.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700590 * @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.
Mimi Zohar377179c2018-07-13 14:05:56 -0400595 * @kernel_load_data:
596 * Load data provided by userspace.
597 * @id kernel load data identifier
598 * Return 0 if permission is granted.
Mimi Zohar39eeb4f2016-01-30 22:23:26 -0500599 * @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.
Mimi Zoharb44a7df2015-12-28 16:02:29 -0500605 * @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.
Mimi Zoharbc8ca5b2016-01-24 10:07:32 -0500611 * @id kernel read file identifier
Mimi Zoharb44a7df2015-12-28 16:02:29 -0500612 * Return 0 if permission is granted.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700613 * @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.
Stephen Smalley791ec492017-02-17 07:57:00 -0500657 * @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.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700665 * @task_setrlimit:
Stephen Smalley791ec492017-02-17 07:57:00 -0500666 * 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.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700670 * @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
Denis Efremova890e6372019-02-26 23:49:05 +0300675 * process @p.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700676 * @p contains the task_struct for process.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700677 * Return 0 if permission is granted.
678 * @task_getscheduler:
679 * Check permission before obtaining scheduling information for process
680 * @p.
681 * @p contains the task_struct for process.
682 * Return 0 if permission is granted.
683 * @task_movememory
684 * Check permission before moving memory owned by process @p.
685 * @p contains the task_struct for process.
686 * Return 0 if permission is granted.
687 * @task_kill:
688 * Check permission before sending signal @sig to @p. @info can be NULL,
Eric W. Biedermanae7795b2018-09-25 11:27:20 +0200689 * the constant 1, or a pointer to a kernel_siginfo structure. If @info is 1 or
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700690 * SI_FROMKERNEL(info) is true, then the signal should be viewed as coming
691 * from the kernel and should typically be permitted.
692 * SIGIO signals are handled separately by the send_sigiotask hook in
693 * file_security_ops.
694 * @p contains the task_struct for process.
695 * @info contains the signal information.
696 * @sig contains the signal value.
Stephen Smalley6b4f3d02017-09-08 12:40:01 -0400697 * @cred contains the cred of the process where the signal originated, or
698 * NULL if the current task is the originator.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700699 * Return 0 if permission is granted.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700700 * @task_prctl:
701 * Check permission before performing a process control operation on the
702 * current process.
703 * @option contains the operation.
704 * @arg2 contains a argument.
705 * @arg3 contains a argument.
706 * @arg4 contains a argument.
707 * @arg5 contains a argument.
708 * Return -ENOSYS if no-one wanted to handle this op, any other value to
709 * cause prctl() to return immediately with that value.
710 * @task_to_inode:
711 * Set the security attributes for an inode based on an associated task's
712 * security attributes, e.g. for /proc/pid inodes.
713 * @p contains the task_struct for the task.
714 * @inode contains the inode structure for the inode.
715 *
716 * Security hooks for Netlink messaging.
717 *
718 * @netlink_send:
719 * Save security information for a netlink message so that permission
720 * checking can be performed when the message is processed. The security
721 * information can be saved using the eff_cap field of the
722 * netlink_skb_parms structure. Also may be used to provide fine
723 * grained control over message transmission.
724 * @sk associated sock of task sending the message.
725 * @skb contains the sk_buff structure for the netlink message.
726 * Return 0 if the information was successfully saved and message
727 * is allowed to be transmitted.
728 *
729 * Security hooks for Unix domain networking.
730 *
731 * @unix_stream_connect:
732 * Check permissions before establishing a Unix domain stream connection
733 * between @sock and @other.
734 * @sock contains the sock structure.
735 * @other contains the peer sock structure.
736 * @newsk contains the new sock structure.
737 * Return 0 if permission is granted.
738 * @unix_may_send:
739 * Check permissions before connecting or sending datagrams from @sock to
740 * @other.
741 * @sock contains the socket structure.
742 * @other contains the peer socket structure.
743 * Return 0 if permission is granted.
744 *
745 * The @unix_stream_connect and @unix_may_send hooks were necessary because
746 * Linux provides an alternative to the conventional file name space for Unix
747 * domain sockets. Whereas binding and connecting to sockets in the file name
748 * space is mediated by the typical file permissions (and caught by the mknod
749 * and permission hooks in inode_security_ops), binding and connecting to
750 * sockets in the abstract name space is completely unmediated. Sufficient
751 * control of Unix domain sockets in the abstract name space isn't possible
752 * using only the socket layer hooks, since we need to know the actual target
753 * socket, which is not looked up until we are inside the af_unix code.
754 *
755 * Security hooks for socket operations.
756 *
757 * @socket_create:
758 * Check permissions prior to creating a new socket.
759 * @family contains the requested protocol family.
760 * @type contains the requested communications type.
761 * @protocol contains the requested protocol.
762 * @kern set to 1 if a kernel socket.
763 * Return 0 if permission is granted.
764 * @socket_post_create:
765 * This hook allows a module to update or allocate a per-socket security
766 * structure. Note that the security field was not added directly to the
767 * socket structure, but rather, the socket security information is stored
768 * in the associated inode. Typically, the inode alloc_security hook will
769 * allocate and and attach security information to
Denis Efremov68b3edb2019-02-26 23:49:04 +0300770 * SOCK_INODE(sock)->i_security. This hook may be used to update the
771 * SOCK_INODE(sock)->i_security field with additional information that
772 * wasn't available when the inode was allocated.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700773 * @sock contains the newly created socket structure.
774 * @family contains the requested protocol family.
775 * @type contains the requested communications type.
776 * @protocol contains the requested protocol.
777 * @kern set to 1 if a kernel socket.
David Herrmannaae7cfc2018-05-04 16:28:19 +0200778 * @socket_socketpair:
779 * Check permissions before creating a fresh pair of sockets.
780 * @socka contains the first socket structure.
781 * @sockb contains the second socket structure.
782 * Return 0 if permission is granted and the connection was established.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700783 * @socket_bind:
784 * Check permission before socket protocol layer bind operation is
785 * performed and the socket @sock is bound to the address specified in the
786 * @address parameter.
787 * @sock contains the socket structure.
788 * @address contains the address to bind to.
789 * @addrlen contains the length of address.
790 * Return 0 if permission is granted.
791 * @socket_connect:
792 * Check permission before socket protocol layer connect operation
793 * attempts to connect socket @sock to a remote address, @address.
794 * @sock contains the socket structure.
795 * @address contains the address of remote endpoint.
796 * @addrlen contains the length of address.
797 * Return 0 if permission is granted.
798 * @socket_listen:
799 * Check permission before socket protocol layer listen operation.
800 * @sock contains the socket structure.
801 * @backlog contains the maximum length for the pending connection queue.
802 * Return 0 if permission is granted.
803 * @socket_accept:
804 * Check permission before accepting a new connection. Note that the new
805 * socket, @newsock, has been created and some information copied to it,
806 * but the accept operation has not actually been performed.
807 * @sock contains the listening socket structure.
808 * @newsock contains the newly created server socket for connection.
809 * Return 0 if permission is granted.
810 * @socket_sendmsg:
811 * Check permission before transmitting a message to another socket.
812 * @sock contains the socket structure.
813 * @msg contains the message to be transmitted.
814 * @size contains the size of message.
815 * Return 0 if permission is granted.
816 * @socket_recvmsg:
817 * Check permission before receiving a message from a socket.
818 * @sock contains the socket structure.
819 * @msg contains the message structure.
820 * @size contains the size of message structure.
821 * @flags contains the operational flags.
822 * Return 0 if permission is granted.
823 * @socket_getsockname:
824 * Check permission before the local address (name) of the socket object
825 * @sock is retrieved.
826 * @sock contains the socket structure.
827 * Return 0 if permission is granted.
828 * @socket_getpeername:
829 * Check permission before the remote address (name) of a socket object
830 * @sock is retrieved.
831 * @sock contains the socket structure.
832 * Return 0 if permission is granted.
833 * @socket_getsockopt:
834 * Check permissions before retrieving the options associated with socket
835 * @sock.
836 * @sock contains the socket structure.
837 * @level contains the protocol level to retrieve option from.
838 * @optname contains the name of option to retrieve.
839 * Return 0 if permission is granted.
840 * @socket_setsockopt:
841 * Check permissions before setting the options associated with socket
842 * @sock.
843 * @sock contains the socket structure.
844 * @level contains the protocol level to set options for.
845 * @optname contains the name of the option to set.
846 * Return 0 if permission is granted.
847 * @socket_shutdown:
848 * Checks permission before all or part of a connection on the socket
849 * @sock is shut down.
850 * @sock contains the socket structure.
851 * @how contains the flag indicating how future sends and receives
852 * are handled.
853 * Return 0 if permission is granted.
854 * @socket_sock_rcv_skb:
855 * Check permissions on incoming network packets. This hook is distinct
856 * from Netfilter's IP input hooks since it is the first time that the
857 * incoming sk_buff @skb has been associated with a particular socket, @sk.
858 * Must not sleep inside this hook because some callers hold spinlocks.
859 * @sk contains the sock (not socket) associated with the incoming sk_buff.
860 * @skb contains the incoming network data.
861 * @socket_getpeersec_stream:
862 * This hook allows the security module to provide peer socket security
863 * state for unix or connected tcp sockets to userspace via getsockopt
864 * SO_GETPEERSEC. For tcp sockets this can be meaningful if the
865 * socket is associated with an ipsec SA.
866 * @sock is the local socket.
867 * @optval userspace memory where the security state is to be copied.
868 * @optlen userspace int where the module should copy the actual length
869 * of the security state.
870 * @len as input is the maximum length to copy to userspace provided
871 * by the caller.
872 * Return 0 if all is well, otherwise, typical getsockopt return
873 * values.
874 * @socket_getpeersec_dgram:
875 * This hook allows the security module to provide peer socket security
876 * state for udp sockets on a per-packet basis to userspace via
Denis Efremov2f991d72019-02-26 23:49:06 +0300877 * getsockopt SO_GETPEERSEC. The application must first have indicated
878 * the IP_PASSSEC option via getsockopt. It can then retrieve the
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700879 * security state returned by this hook for a packet via the SCM_SECURITY
880 * ancillary message type.
Denis Efremov2f991d72019-02-26 23:49:06 +0300881 * @sock contains the peer socket. May be NULL.
882 * @skb is the sk_buff for the packet being queried. May be NULL.
883 * @secid pointer to store the secid of the packet.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700884 * Return 0 on success, error on failure.
885 * @sk_alloc_security:
886 * Allocate and attach a security structure to the sk->sk_security field,
887 * which is used to copy security attributes between local stream sockets.
888 * @sk_free_security:
889 * Deallocate security structure.
890 * @sk_clone_security:
891 * Clone/copy security structure.
892 * @sk_getsecid:
893 * Retrieve the LSM-specific secid for the sock to enable caching
894 * of network authorizations.
895 * @sock_graft:
896 * Sets the socket's isec sid to the sock's sid.
897 * @inet_conn_request:
898 * Sets the openreq's sid to socket's sid with MLS portion taken
899 * from peer sid.
900 * @inet_csk_clone:
901 * Sets the new child socket's sid to the openreq sid.
902 * @inet_conn_established:
903 * Sets the connection's peersid to the secmark on skb.
904 * @secmark_relabel_packet:
905 * check if the process should be allowed to relabel packets to
906 * the given secid
907 * @security_secmark_refcount_inc
908 * tells the LSM to increment the number of secmark labeling rules loaded
909 * @security_secmark_refcount_dec
910 * tells the LSM to decrement the number of secmark labeling rules loaded
911 * @req_classify_flow:
912 * Sets the flow's sid to the openreq sid.
913 * @tun_dev_alloc_security:
914 * This hook allows a module to allocate a security structure for a TUN
915 * device.
916 * @security pointer to a security structure pointer.
917 * Returns a zero on success, negative values on failure.
918 * @tun_dev_free_security:
919 * This hook allows a module to free the security structure for a TUN
920 * device.
921 * @security pointer to the TUN device's security structure
922 * @tun_dev_create:
923 * Check permissions prior to creating a new TUN device.
924 * @tun_dev_attach_queue:
925 * Check permissions prior to attaching to a TUN device queue.
926 * @security pointer to the TUN device's security structure.
927 * @tun_dev_attach:
928 * This hook can be used by the module to update any security state
929 * associated with the TUN device's sock structure.
930 * @sk contains the existing sock structure.
931 * @security pointer to the TUN device's security structure.
932 * @tun_dev_open:
933 * This hook can be used by the module to update any security state
934 * associated with the TUN device's security structure.
935 * @security pointer to the TUN devices's security structure.
936 *
Richard Haines72e89f52018-02-13 20:53:21 +0000937 * Security hooks for SCTP
938 *
939 * @sctp_assoc_request:
940 * Passes the @ep and @chunk->skb of the association INIT packet to
941 * the security module.
942 * @ep pointer to sctp endpoint structure.
943 * @skb pointer to skbuff of association packet.
944 * Return 0 on success, error on failure.
945 * @sctp_bind_connect:
946 * Validiate permissions required for each address associated with sock
947 * @sk. Depending on @optname, the addresses will be treated as either
948 * for a connect or bind service. The @addrlen is calculated on each
949 * ipv4 and ipv6 address using sizeof(struct sockaddr_in) or
950 * sizeof(struct sockaddr_in6).
951 * @sk pointer to sock structure.
952 * @optname name of the option to validate.
953 * @address list containing one or more ipv4/ipv6 addresses.
954 * @addrlen total length of address(s).
955 * Return 0 on success, error on failure.
956 * @sctp_sk_clone:
957 * Called whenever a new socket is created by accept(2) (i.e. a TCP
958 * style socket) or when a socket is 'peeled off' e.g userspace
959 * calls sctp_peeloff(3).
960 * @ep pointer to current sctp endpoint structure.
961 * @sk pointer to current sock structure.
962 * @sk pointer to new sock structure.
963 *
Daniel Jurgensd291f1a2017-05-19 15:48:52 +0300964 * Security hooks for Infiniband
965 *
966 * @ib_pkey_access:
967 * Check permission to access a pkey when modifing a QP.
968 * @subnet_prefix the subnet prefix of the port being used.
969 * @pkey the pkey to be accessed.
970 * @sec pointer to a security structure.
Daniel Jurgens47a2b332017-05-19 15:48:54 +0300971 * @ib_endport_manage_subnet:
972 * Check permissions to send and receive SMPs on a end port.
973 * @dev_name the IB device name (i.e. mlx4_0).
974 * @port_num the port number.
975 * @sec pointer to a security structure.
Daniel Jurgensd291f1a2017-05-19 15:48:52 +0300976 * @ib_alloc_security:
977 * Allocate a security structure for Infiniband objects.
978 * @sec pointer to a security structure pointer.
979 * Returns 0 on success, non-zero on failure
980 * @ib_free_security:
981 * Deallocate an Infiniband security structure.
982 * @sec contains the security structure to be freed.
983 *
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700984 * Security hooks for XFRM operations.
985 *
986 * @xfrm_policy_alloc_security:
987 * @ctxp is a pointer to the xfrm_sec_ctx being added to Security Policy
988 * Database used by the XFRM system.
989 * @sec_ctx contains the security context information being provided by
990 * the user-level policy update program (e.g., setkey).
991 * Allocate a security structure to the xp->security field; the security
992 * field is initialized to NULL when the xfrm_policy is allocated.
993 * Return 0 if operation was successful (memory to allocate, legal context)
994 * @gfp is to specify the context for the allocation
995 * @xfrm_policy_clone_security:
996 * @old_ctx contains an existing xfrm_sec_ctx.
997 * @new_ctxp contains a new xfrm_sec_ctx being cloned from old.
998 * Allocate a security structure in new_ctxp that contains the
999 * information from the old_ctx structure.
1000 * Return 0 if operation was successful (memory to allocate).
1001 * @xfrm_policy_free_security:
1002 * @ctx contains the xfrm_sec_ctx
1003 * Deallocate xp->security.
1004 * @xfrm_policy_delete_security:
1005 * @ctx contains the xfrm_sec_ctx.
1006 * Authorize deletion of xp->security.
1007 * @xfrm_state_alloc:
1008 * @x contains the xfrm_state being added to the Security Association
1009 * Database by the XFRM system.
1010 * @sec_ctx contains the security context information being provided by
1011 * the user-level SA generation program (e.g., setkey or racoon).
1012 * Allocate a security structure to the x->security field; the security
1013 * field is initialized to NULL when the xfrm_state is allocated. Set the
1014 * context to correspond to sec_ctx. Return 0 if operation was successful
1015 * (memory to allocate, legal context).
1016 * @xfrm_state_alloc_acquire:
1017 * @x contains the xfrm_state being added to the Security Association
1018 * Database by the XFRM system.
1019 * @polsec contains the policy's security context.
1020 * @secid contains the secid from which to take the mls portion of the
1021 * context.
1022 * Allocate a security structure to the x->security field; the security
1023 * field is initialized to NULL when the xfrm_state is allocated. Set the
1024 * context to correspond to secid. Return 0 if operation was successful
1025 * (memory to allocate, legal context).
1026 * @xfrm_state_free_security:
1027 * @x contains the xfrm_state.
1028 * Deallocate x->security.
1029 * @xfrm_state_delete_security:
1030 * @x contains the xfrm_state.
1031 * Authorize deletion of x->security.
1032 * @xfrm_policy_lookup:
1033 * @ctx contains the xfrm_sec_ctx for which the access control is being
1034 * checked.
1035 * @fl_secid contains the flow security label that is used to authorize
1036 * access to the policy xp.
1037 * @dir contains the direction of the flow (input or output).
1038 * Check permission when a flow selects a xfrm_policy for processing
1039 * XFRMs on a packet. The hook is called when selecting either a
1040 * per-socket policy or a generic xfrm policy.
1041 * Return 0 if permission is granted, -ESRCH otherwise, or -errno
1042 * on other errors.
1043 * @xfrm_state_pol_flow_match:
1044 * @x contains the state to match.
1045 * @xp contains the policy to check for a match.
1046 * @fl contains the flow to check for a match.
1047 * Return 1 if there is a match.
1048 * @xfrm_decode_session:
1049 * @skb points to skb to decode.
1050 * @secid points to the flow key secid to set.
1051 * @ckall says if all xfrms used should be checked for same secid.
1052 * Return 0 if ckall is zero or all xfrms used have the same secid.
1053 *
1054 * Security hooks affecting all Key Management operations
1055 *
1056 * @key_alloc:
1057 * Permit allocation of a key and assign security data. Note that key does
1058 * not have a serial number assigned at this point.
1059 * @key points to the key.
1060 * @flags is the allocation flags
1061 * Return 0 if permission is granted, -ve error otherwise.
1062 * @key_free:
1063 * Notification of destruction; free security data.
1064 * @key points to the key.
1065 * No return value.
1066 * @key_permission:
1067 * See whether a specific operational right is granted to a process on a
1068 * key.
1069 * @key_ref refers to the key (key pointer + possession attribute bit).
1070 * @cred points to the credentials to provide the context against which to
1071 * evaluate the security data on the key.
1072 * @perm describes the combination of permissions required of this key.
1073 * Return 0 if permission is granted, -ve error otherwise.
1074 * @key_getsecurity:
1075 * Get a textual representation of the security context attached to a key
1076 * for the purposes of honouring KEYCTL_GETSECURITY. This function
1077 * allocates the storage for the NUL-terminated string and the caller
1078 * should free it.
1079 * @key points to the key to be queried.
1080 * @_buffer points to a pointer that should be set to point to the
1081 * resulting string (if no label or an error occurs).
1082 * Return the length of the string (including terminating NUL) or -ve if
1083 * an error.
1084 * May also return 0 (and a NULL buffer pointer) if there is no label.
1085 *
1086 * Security hooks affecting all System V IPC operations.
1087 *
1088 * @ipc_permission:
1089 * Check permissions for access to IPC
1090 * @ipcp contains the kernel IPC permission structure
1091 * @flag contains the desired (requested) permission set
1092 * Return 0 if permission is granted.
1093 * @ipc_getsecid:
1094 * Get the secid associated with the ipc object.
1095 * @ipcp contains the kernel IPC permission structure.
1096 * @secid contains a pointer to the location where result will be saved.
1097 * In case of failure, @secid will be set to zero.
1098 *
1099 * Security hooks for individual messages held in System V IPC message queues
1100 * @msg_msg_alloc_security:
1101 * Allocate and attach a security structure to the msg->security field.
1102 * The security field is initialized to NULL when the structure is first
1103 * created.
1104 * @msg contains the message structure to be modified.
1105 * Return 0 if operation was successful and permission is granted.
1106 * @msg_msg_free_security:
1107 * Deallocate the security structure for this message.
1108 * @msg contains the message structure to be modified.
1109 *
1110 * Security hooks for System V IPC Message Queues
1111 *
1112 * @msg_queue_alloc_security:
1113 * Allocate and attach a security structure to the
1114 * msq->q_perm.security field. The security field is initialized to
1115 * NULL when the structure is first created.
1116 * @msq contains the message queue structure to be modified.
1117 * Return 0 if operation was successful and permission is granted.
1118 * @msg_queue_free_security:
1119 * Deallocate security structure for this message queue.
1120 * @msq contains the message queue structure to be modified.
1121 * @msg_queue_associate:
1122 * Check permission when a message queue is requested through the
1123 * msgget system call. This hook is only called when returning the
1124 * message queue identifier for an existing message queue, not when a
1125 * new message queue is created.
1126 * @msq contains the message queue to act upon.
1127 * @msqflg contains the operation control flags.
1128 * Return 0 if permission is granted.
1129 * @msg_queue_msgctl:
1130 * Check permission when a message control operation specified by @cmd
1131 * is to be performed on the message queue @msq.
1132 * The @msq may be NULL, e.g. for IPC_INFO or MSG_INFO.
1133 * @msq contains the message queue to act upon. May be NULL.
1134 * @cmd contains the operation to be performed.
1135 * Return 0 if permission is granted.
1136 * @msg_queue_msgsnd:
1137 * Check permission before a message, @msg, is enqueued on the message
1138 * queue, @msq.
1139 * @msq contains the message queue to send message to.
1140 * @msg contains the message to be enqueued.
1141 * @msqflg contains operational flags.
1142 * Return 0 if permission is granted.
1143 * @msg_queue_msgrcv:
1144 * Check permission before a message, @msg, is removed from the message
1145 * queue, @msq. The @target task structure contains a pointer to the
1146 * process that will be receiving the message (not equal to the current
1147 * process when inline receives are being performed).
1148 * @msq contains the message queue to retrieve message from.
1149 * @msg contains the message destination.
1150 * @target contains the task structure for recipient process.
1151 * @type contains the type of message requested.
1152 * @mode contains the operational flags.
1153 * Return 0 if permission is granted.
1154 *
1155 * Security hooks for System V Shared Memory Segments
1156 *
1157 * @shm_alloc_security:
1158 * Allocate and attach a security structure to the shp->shm_perm.security
1159 * field. The security field is initialized to NULL when the structure is
1160 * first created.
1161 * @shp contains the shared memory structure to be modified.
1162 * Return 0 if operation was successful and permission is granted.
1163 * @shm_free_security:
1164 * Deallocate the security struct for this memory segment.
1165 * @shp contains the shared memory structure to be modified.
1166 * @shm_associate:
1167 * Check permission when a shared memory region is requested through the
1168 * shmget system call. This hook is only called when returning the shared
1169 * memory region identifier for an existing region, not when a new shared
1170 * memory region is created.
1171 * @shp contains the shared memory structure to be modified.
1172 * @shmflg contains the operation control flags.
1173 * Return 0 if permission is granted.
1174 * @shm_shmctl:
1175 * Check permission when a shared memory control operation specified by
1176 * @cmd is to be performed on the shared memory region @shp.
1177 * The @shp may be NULL, e.g. for IPC_INFO or SHM_INFO.
1178 * @shp contains shared memory structure to be modified.
1179 * @cmd contains the operation to be performed.
1180 * Return 0 if permission is granted.
1181 * @shm_shmat:
1182 * Check permissions prior to allowing the shmat system call to attach the
1183 * shared memory segment @shp to the data segment of the calling process.
1184 * The attaching address is specified by @shmaddr.
1185 * @shp contains the shared memory structure to be modified.
1186 * @shmaddr contains the address to attach memory region to.
1187 * @shmflg contains the operational flags.
1188 * Return 0 if permission is granted.
1189 *
1190 * Security hooks for System V Semaphores
1191 *
1192 * @sem_alloc_security:
1193 * Allocate and attach a security structure to the sma->sem_perm.security
1194 * field. The security field is initialized to NULL when the structure is
1195 * first created.
1196 * @sma contains the semaphore structure
1197 * Return 0 if operation was successful and permission is granted.
1198 * @sem_free_security:
1199 * deallocate security struct for this semaphore
1200 * @sma contains the semaphore structure.
1201 * @sem_associate:
1202 * Check permission when a semaphore is requested through the semget
1203 * system call. This hook is only called when returning the semaphore
1204 * identifier for an existing semaphore, not when a new one must be
1205 * created.
1206 * @sma contains the semaphore structure.
1207 * @semflg contains the operation control flags.
1208 * Return 0 if permission is granted.
1209 * @sem_semctl:
1210 * Check permission when a semaphore operation specified by @cmd is to be
1211 * performed on the semaphore @sma. The @sma may be NULL, e.g. for
1212 * IPC_INFO or SEM_INFO.
1213 * @sma contains the semaphore structure. May be NULL.
1214 * @cmd contains the operation to be performed.
1215 * Return 0 if permission is granted.
Kees Cookf00f85a2017-05-13 04:51:42 -07001216 * @sem_semop:
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001217 * Check permissions before performing operations on members of the
1218 * semaphore set @sma. If the @alter flag is nonzero, the semaphore set
1219 * may be modified.
1220 * @sma contains the semaphore structure.
1221 * @sops contains the operations to perform.
1222 * @nsops contains the number of operations to perform.
1223 * @alter contains the flag indicating whether changes are to be made.
1224 * Return 0 if permission is granted.
1225 *
Kees Cookf00f85a2017-05-13 04:51:42 -07001226 * @binder_set_context_mgr:
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001227 * Check whether @mgr is allowed to be the binder context manager.
1228 * @mgr contains the task_struct for the task being registered.
1229 * Return 0 if permission is granted.
Kees Cookf00f85a2017-05-13 04:51:42 -07001230 * @binder_transaction:
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001231 * Check whether @from is allowed to invoke a binder transaction call
1232 * to @to.
1233 * @from contains the task_struct for the sending task.
1234 * @to contains the task_struct for the receiving task.
Kees Cookf00f85a2017-05-13 04:51:42 -07001235 * @binder_transfer_binder:
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001236 * Check whether @from is allowed to transfer a binder reference to @to.
1237 * @from contains the task_struct for the sending task.
1238 * @to contains the task_struct for the receiving task.
Kees Cookf00f85a2017-05-13 04:51:42 -07001239 * @binder_transfer_file:
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001240 * Check whether @from is allowed to transfer @file to @to.
1241 * @from contains the task_struct for the sending task.
1242 * @file contains the struct file being transferred.
1243 * @to contains the task_struct for the receiving task.
1244 *
1245 * @ptrace_access_check:
1246 * Check permission before allowing the current process to trace the
1247 * @child process.
1248 * Security modules may also want to perform a process tracing check
1249 * during an execve in the set_security or apply_creds hooks of
1250 * tracing check during an execve in the bprm_set_creds hook of
1251 * binprm_security_ops if the process is being traced and its security
1252 * attributes would be changed by the execve.
1253 * @child contains the task_struct structure for the target process.
1254 * @mode contains the PTRACE_MODE flags indicating the form of access.
1255 * Return 0 if permission is granted.
1256 * @ptrace_traceme:
1257 * Check that the @parent process has sufficient permission to trace the
1258 * current process before allowing the current process to present itself
1259 * to the @parent process for tracing.
1260 * @parent contains the task_struct structure for debugger process.
1261 * Return 0 if permission is granted.
1262 * @capget:
1263 * Get the @effective, @inheritable, and @permitted capability sets for
1264 * the @target process. The hook may also perform permission checking to
1265 * determine if the current process is allowed to see the capability sets
1266 * of the @target process.
1267 * @target contains the task_struct structure for target process.
1268 * @effective contains the effective capability set.
1269 * @inheritable contains the inheritable capability set.
1270 * @permitted contains the permitted capability set.
1271 * Return 0 if the capability sets were successfully obtained.
1272 * @capset:
1273 * Set the @effective, @inheritable, and @permitted capability sets for
1274 * the current process.
1275 * @new contains the new credentials structure for target process.
1276 * @old contains the current credentials structure for target process.
1277 * @effective contains the effective capability set.
1278 * @inheritable contains the inheritable capability set.
1279 * @permitted contains the permitted capability set.
1280 * Return 0 and update @new if permission is granted.
1281 * @capable:
1282 * Check whether the @tsk process has the @cap capability in the indicated
1283 * credentials.
1284 * @cred contains the credentials to use.
1285 * @ns contains the user namespace we want the capability in
1286 * @cap contains the capability <include/linux/capability.h>.
Micah Mortonc1a85a02019-01-07 16:10:53 -08001287 * @opts contains options for the capable check <include/linux/security.h>
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001288 * Return 0 if the capability is granted for @tsk.
1289 * @syslog:
1290 * Check permission before accessing the kernel message ring or changing
1291 * logging to the console.
1292 * See the syslog(2) manual page for an explanation of the @type values.
Denis Efremov5f4b9752019-02-26 23:49:03 +03001293 * @type contains the SYSLOG_ACTION_* constant from <include/linux/syslog.h>
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001294 * Return 0 if permission is granted.
1295 * @settime:
1296 * Check permission to change the system time.
Baolin Wang457db292016-04-08 14:02:11 +08001297 * struct timespec64 is defined in include/linux/time64.h and timezone
1298 * is defined in include/linux/time.h
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001299 * @ts contains new time
1300 * @tz contains new timezone
1301 * Return 0 if permission is granted.
1302 * @vm_enough_memory:
1303 * Check permissions for allocating a new virtual mapping.
1304 * @mm contains the mm struct it is being added to.
1305 * @pages contains the number of pages.
1306 * Return 0 if permission is granted.
1307 *
1308 * @ismaclabel:
1309 * Check if the extended attribute specified by @name
1310 * represents a MAC label. Returns 1 if name is a MAC
1311 * attribute otherwise returns 0.
1312 * @name full extended attribute name to check against
1313 * LSM as a MAC label.
1314 *
1315 * @secid_to_secctx:
1316 * Convert secid to security context. If secdata is NULL the length of
1317 * the result will be returned in seclen, but no secdata will be returned.
1318 * This does mean that the length could change between calls to check the
1319 * length and the next call which actually allocates and returns the
1320 * secdata.
1321 * @secid contains the security ID.
1322 * @secdata contains the pointer that stores the converted security
1323 * context.
1324 * @seclen pointer which contains the length of the data
1325 * @secctx_to_secid:
1326 * Convert security context to secid.
1327 * @secid contains the pointer to the generated security ID.
1328 * @secdata contains the security context.
1329 *
1330 * @release_secctx:
1331 * Release the security context.
1332 * @secdata contains the security context.
1333 * @seclen contains the length of the security context.
1334 *
1335 * Security hooks for Audit
1336 *
1337 * @audit_rule_init:
1338 * Allocate and initialize an LSM audit rule structure.
1339 * @field contains the required Audit action.
1340 * Fields flags are defined in include/linux/audit.h
1341 * @op contains the operator the rule uses.
1342 * @rulestr contains the context where the rule will be applied to.
1343 * @lsmrule contains a pointer to receive the result.
1344 * Return 0 if @lsmrule has been successfully set,
1345 * -EINVAL in case of an invalid rule.
1346 *
1347 * @audit_rule_known:
Denis Efremov5fdd2682019-02-26 23:49:08 +03001348 * Specifies whether given @krule contains any fields related to
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001349 * current LSM.
Denis Efremov5fdd2682019-02-26 23:49:08 +03001350 * @krule contains the audit rule of interest.
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001351 * Return 1 in case of relation found, 0 otherwise.
1352 *
1353 * @audit_rule_match:
1354 * Determine if given @secid matches a rule previously approved
1355 * by @audit_rule_known.
1356 * @secid contains the security id in question.
1357 * @field contains the field which relates to current LSM.
1358 * @op contains the operator that will be used for matching.
Denis Efremov5fdd2682019-02-26 23:49:08 +03001359 * @lrule points to the audit rule that will be checked against.
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001360 * Return 1 if secid matches the rule, 0 if it does not, -ERRNO on failure.
1361 *
1362 * @audit_rule_free:
1363 * Deallocate the LSM audit rule structure previously allocated by
1364 * audit_rule_init.
Denis Efremov5fdd2682019-02-26 23:49:08 +03001365 * @lsmrule contains the allocated rule
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001366 *
Andreas Gruenbacher6f3be9f2015-12-24 11:09:40 -05001367 * @inode_invalidate_secctx:
1368 * Notify the security module that it must revalidate the security context
1369 * of an inode.
1370 *
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001371 * @inode_notifysecctx:
1372 * Notify the security module of what the security context of an inode
1373 * should be. Initializes the incore security context managed by the
1374 * security module for this inode. Example usage: NFS client invokes
1375 * this hook to initialize the security context in its incore inode to the
1376 * value provided by the server for the file when the server returned the
1377 * file's attributes to the client.
1378 *
1379 * Must be called with inode->i_mutex locked.
1380 *
1381 * @inode we wish to set the security context of.
1382 * @ctx contains the string which we wish to set in the inode.
1383 * @ctxlen contains the length of @ctx.
1384 *
1385 * @inode_setsecctx:
1386 * Change the security context of an inode. Updates the
1387 * incore security context managed by the security module and invokes the
1388 * fs code as needed (via __vfs_setxattr_noperm) to update any backing
1389 * xattrs that represent the context. Example usage: NFS server invokes
1390 * this hook to change the security context in its incore inode and on the
1391 * backing filesystem to a value provided by the client on a SETATTR
1392 * operation.
1393 *
1394 * Must be called with inode->i_mutex locked.
1395 *
1396 * @dentry contains the inode we wish to set the security context of.
1397 * @ctx contains the string which we wish to set in the inode.
1398 * @ctxlen contains the length of @ctx.
1399 *
1400 * @inode_getsecctx:
1401 * On success, returns 0 and fills out @ctx and @ctxlen with the security
1402 * context for the given @inode.
1403 *
1404 * @inode we wish to get the security context of.
1405 * @ctx is a pointer in which to place the allocated security context.
1406 * @ctxlen points to the place to put the length of @ctx.
Chenbo Fengafdb09c2017-10-18 13:00:24 -07001407 *
1408 * Security hooks for using the eBPF maps and programs functionalities through
1409 * eBPF syscalls.
1410 *
1411 * @bpf:
1412 * Do a initial check for all bpf syscalls after the attribute is copied
1413 * into the kernel. The actual security module can implement their own
1414 * rules to check the specific cmd they need.
1415 *
1416 * @bpf_map:
1417 * Do a check when the kernel generate and return a file descriptor for
1418 * eBPF maps.
1419 *
1420 * @map: bpf map that we want to access
1421 * @mask: the access flags
1422 *
1423 * @bpf_prog:
1424 * Do a check when the kernel generate and return a file descriptor for
1425 * eBPF programs.
1426 *
1427 * @prog: bpf prog that userspace want to use.
1428 *
1429 * @bpf_map_alloc_security:
1430 * Initialize the security field inside bpf map.
1431 *
1432 * @bpf_map_free_security:
1433 * Clean up the security information stored inside bpf map.
1434 *
1435 * @bpf_prog_alloc_security:
1436 * Initialize the security field inside bpf program.
1437 *
1438 * @bpf_prog_free_security:
1439 * Clean up the security information stored inside bpf prog.
1440 *
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001441 */
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001442union security_list_options {
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001443 int (*binder_set_context_mgr)(struct task_struct *mgr);
1444 int (*binder_transaction)(struct task_struct *from,
1445 struct task_struct *to);
1446 int (*binder_transfer_binder)(struct task_struct *from,
1447 struct task_struct *to);
1448 int (*binder_transfer_file)(struct task_struct *from,
1449 struct task_struct *to,
1450 struct file *file);
1451
1452 int (*ptrace_access_check)(struct task_struct *child,
1453 unsigned int mode);
1454 int (*ptrace_traceme)(struct task_struct *parent);
1455 int (*capget)(struct task_struct *target, kernel_cap_t *effective,
1456 kernel_cap_t *inheritable, kernel_cap_t *permitted);
1457 int (*capset)(struct cred *new, const struct cred *old,
1458 const kernel_cap_t *effective,
1459 const kernel_cap_t *inheritable,
1460 const kernel_cap_t *permitted);
Micah Mortonc1a85a02019-01-07 16:10:53 -08001461 int (*capable)(const struct cred *cred,
1462 struct user_namespace *ns,
1463 int cap,
1464 unsigned int opts);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001465 int (*quotactl)(int cmds, int type, int id, struct super_block *sb);
1466 int (*quota_on)(struct dentry *dentry);
1467 int (*syslog)(int type);
Baolin Wang457db292016-04-08 14:02:11 +08001468 int (*settime)(const struct timespec64 *ts, const struct timezone *tz);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001469 int (*vm_enough_memory)(struct mm_struct *mm, long pages);
1470
1471 int (*bprm_set_creds)(struct linux_binprm *bprm);
1472 int (*bprm_check_security)(struct linux_binprm *bprm);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001473 void (*bprm_committing_creds)(struct linux_binprm *bprm);
1474 void (*bprm_committed_creds)(struct linux_binprm *bprm);
1475
Al Viro0b520752018-12-23 16:02:47 -05001476 int (*fs_context_dup)(struct fs_context *fc, struct fs_context *src_sc);
David Howellsda2441f2018-11-01 23:07:24 +00001477 int (*fs_context_parse_param)(struct fs_context *fc, struct fs_parameter *param);
1478
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001479 int (*sb_alloc_security)(struct super_block *sb);
1480 void (*sb_free_security)(struct super_block *sb);
Al Viro204cc0c2018-12-13 13:41:47 -05001481 void (*sb_free_mnt_opts)(void *mnt_opts);
1482 int (*sb_eat_lsm_opts)(char *orig, void **mnt_opts);
1483 int (*sb_remount)(struct super_block *sb, void *mnt_opts);
Al Viroa10d7c22018-12-05 11:58:35 -05001484 int (*sb_kern_mount)(struct super_block *sb);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001485 int (*sb_show_options)(struct seq_file *m, struct super_block *sb);
1486 int (*sb_statfs)(struct dentry *dentry);
Al Viro8a04c432016-03-25 14:52:53 -04001487 int (*sb_mount)(const char *dev_name, const struct path *path,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001488 const char *type, unsigned long flags, void *data);
1489 int (*sb_umount)(struct vfsmount *mnt, int flags);
Al Viro3b73b682016-03-25 15:31:19 -04001490 int (*sb_pivotroot)(const struct path *old_path, const struct path *new_path);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001491 int (*sb_set_mnt_opts)(struct super_block *sb,
Al Viro204cc0c2018-12-13 13:41:47 -05001492 void *mnt_opts,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001493 unsigned long kern_flags,
1494 unsigned long *set_kern_flags);
1495 int (*sb_clone_mnt_opts)(const struct super_block *oldsb,
Scott Mayhew0b4d3452017-06-05 11:45:04 -04001496 struct super_block *newsb,
1497 unsigned long kern_flags,
1498 unsigned long *set_kern_flags);
Al Viro757cbe52018-12-14 23:42:21 -05001499 int (*sb_add_mnt_opt)(const char *option, const char *val, int len,
1500 void **mnt_opts);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001501 int (*dentry_init_security)(struct dentry *dentry, int mode,
Al Viro4f3ccd72016-07-20 16:06:15 -04001502 const struct qstr *name, void **ctx,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001503 u32 *ctxlen);
Vivek Goyal26026252016-07-13 10:44:52 -04001504 int (*dentry_create_files_as)(struct dentry *dentry, int mode,
1505 struct qstr *name,
1506 const struct cred *old,
1507 struct cred *new);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001508
1509
1510#ifdef CONFIG_SECURITY_PATH
Al Viro989f74e2016-03-25 15:13:39 -04001511 int (*path_unlink)(const struct path *dir, struct dentry *dentry);
Al Virod3607752016-03-25 15:21:09 -04001512 int (*path_mkdir)(const struct path *dir, struct dentry *dentry,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001513 umode_t mode);
Al Viro989f74e2016-03-25 15:13:39 -04001514 int (*path_rmdir)(const struct path *dir, struct dentry *dentry);
Al Virod3607752016-03-25 15:21:09 -04001515 int (*path_mknod)(const struct path *dir, struct dentry *dentry,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001516 umode_t mode, unsigned int dev);
Al Viro81f4c502016-03-25 14:22:01 -04001517 int (*path_truncate)(const struct path *path);
Al Virod3607752016-03-25 15:21:09 -04001518 int (*path_symlink)(const struct path *dir, struct dentry *dentry,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001519 const char *old_name);
Al Viro3ccee462016-03-25 15:27:45 -04001520 int (*path_link)(struct dentry *old_dentry, const struct path *new_dir,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001521 struct dentry *new_dentry);
Al Viro3ccee462016-03-25 15:27:45 -04001522 int (*path_rename)(const struct path *old_dir, struct dentry *old_dentry,
1523 const struct path *new_dir,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001524 struct dentry *new_dentry);
Al Virobe01f9f2016-03-25 14:56:23 -04001525 int (*path_chmod)(const struct path *path, umode_t mode);
Al Viro7fd25da2016-03-25 14:44:41 -04001526 int (*path_chown)(const struct path *path, kuid_t uid, kgid_t gid);
Al Viro77b286c2016-03-25 15:28:43 -04001527 int (*path_chroot)(const struct path *path);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001528#endif
1529
1530 int (*inode_alloc_security)(struct inode *inode);
1531 void (*inode_free_security)(struct inode *inode);
1532 int (*inode_init_security)(struct inode *inode, struct inode *dir,
1533 const struct qstr *qstr,
1534 const char **name, void **value,
1535 size_t *len);
1536 int (*inode_create)(struct inode *dir, struct dentry *dentry,
1537 umode_t mode);
1538 int (*inode_link)(struct dentry *old_dentry, struct inode *dir,
1539 struct dentry *new_dentry);
1540 int (*inode_unlink)(struct inode *dir, struct dentry *dentry);
1541 int (*inode_symlink)(struct inode *dir, struct dentry *dentry,
1542 const char *old_name);
1543 int (*inode_mkdir)(struct inode *dir, struct dentry *dentry,
1544 umode_t mode);
1545 int (*inode_rmdir)(struct inode *dir, struct dentry *dentry);
1546 int (*inode_mknod)(struct inode *dir, struct dentry *dentry,
1547 umode_t mode, dev_t dev);
1548 int (*inode_rename)(struct inode *old_dir, struct dentry *old_dentry,
1549 struct inode *new_dir,
1550 struct dentry *new_dentry);
1551 int (*inode_readlink)(struct dentry *dentry);
Linus Torvaldse22619a2015-06-27 13:26:03 -07001552 int (*inode_follow_link)(struct dentry *dentry, struct inode *inode,
1553 bool rcu);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001554 int (*inode_permission)(struct inode *inode, int mask);
1555 int (*inode_setattr)(struct dentry *dentry, struct iattr *attr);
1556 int (*inode_getattr)(const struct path *path);
1557 int (*inode_setxattr)(struct dentry *dentry, const char *name,
1558 const void *value, size_t size, int flags);
1559 void (*inode_post_setxattr)(struct dentry *dentry, const char *name,
1560 const void *value, size_t size,
1561 int flags);
1562 int (*inode_getxattr)(struct dentry *dentry, const char *name);
1563 int (*inode_listxattr)(struct dentry *dentry);
1564 int (*inode_removexattr)(struct dentry *dentry, const char *name);
1565 int (*inode_need_killpriv)(struct dentry *dentry);
1566 int (*inode_killpriv)(struct dentry *dentry);
Andreas Gruenbacherea861df2015-12-24 11:09:39 -05001567 int (*inode_getsecurity)(struct inode *inode, const char *name,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001568 void **buffer, bool alloc);
1569 int (*inode_setsecurity)(struct inode *inode, const char *name,
1570 const void *value, size_t size,
1571 int flags);
1572 int (*inode_listsecurity)(struct inode *inode, char *buffer,
1573 size_t buffer_size);
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -05001574 void (*inode_getsecid)(struct inode *inode, u32 *secid);
Vivek Goyald8ad8b42016-07-13 11:13:56 -04001575 int (*inode_copy_up)(struct dentry *src, struct cred **new);
Vivek Goyal121ab822016-07-13 10:44:49 -04001576 int (*inode_copy_up_xattr)(const char *name);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001577
1578 int (*file_permission)(struct file *file, int mask);
1579 int (*file_alloc_security)(struct file *file);
1580 void (*file_free_security)(struct file *file);
1581 int (*file_ioctl)(struct file *file, unsigned int cmd,
1582 unsigned long arg);
1583 int (*mmap_addr)(unsigned long addr);
1584 int (*mmap_file)(struct file *file, unsigned long reqprot,
1585 unsigned long prot, unsigned long flags);
1586 int (*file_mprotect)(struct vm_area_struct *vma, unsigned long reqprot,
1587 unsigned long prot);
1588 int (*file_lock)(struct file *file, unsigned int cmd);
1589 int (*file_fcntl)(struct file *file, unsigned int cmd,
1590 unsigned long arg);
1591 void (*file_set_fowner)(struct file *file);
1592 int (*file_send_sigiotask)(struct task_struct *tsk,
1593 struct fown_struct *fown, int sig);
1594 int (*file_receive)(struct file *file);
Al Viro94817692018-07-10 14:13:18 -04001595 int (*file_open)(struct file *file);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001596
Tetsuo Handae4e55b42017-03-24 20:46:33 +09001597 int (*task_alloc)(struct task_struct *task, unsigned long clone_flags);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001598 void (*task_free)(struct task_struct *task);
1599 int (*cred_alloc_blank)(struct cred *cred, gfp_t gfp);
1600 void (*cred_free)(struct cred *cred);
1601 int (*cred_prepare)(struct cred *new, const struct cred *old,
1602 gfp_t gfp);
1603 void (*cred_transfer)(struct cred *new, const struct cred *old);
Matthew Garrett3ec30112018-01-08 13:36:19 -08001604 void (*cred_getsecid)(const struct cred *c, u32 *secid);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001605 int (*kernel_act_as)(struct cred *new, u32 secid);
1606 int (*kernel_create_files_as)(struct cred *new, struct inode *inode);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001607 int (*kernel_module_request)(char *kmod_name);
Mimi Zohar377179c2018-07-13 14:05:56 -04001608 int (*kernel_load_data)(enum kernel_load_data_id id);
Mimi Zohar39eeb4f2016-01-30 22:23:26 -05001609 int (*kernel_read_file)(struct file *file, enum kernel_read_file_id id);
Mimi Zoharbc8ca5b2016-01-24 10:07:32 -05001610 int (*kernel_post_read_file)(struct file *file, char *buf, loff_t size,
1611 enum kernel_read_file_id id);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001612 int (*task_fix_setuid)(struct cred *new, const struct cred *old,
1613 int flags);
1614 int (*task_setpgid)(struct task_struct *p, pid_t pgid);
1615 int (*task_getpgid)(struct task_struct *p);
1616 int (*task_getsid)(struct task_struct *p);
1617 void (*task_getsecid)(struct task_struct *p, u32 *secid);
1618 int (*task_setnice)(struct task_struct *p, int nice);
1619 int (*task_setioprio)(struct task_struct *p, int ioprio);
1620 int (*task_getioprio)(struct task_struct *p);
Stephen Smalley791ec492017-02-17 07:57:00 -05001621 int (*task_prlimit)(const struct cred *cred, const struct cred *tcred,
1622 unsigned int flags);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001623 int (*task_setrlimit)(struct task_struct *p, unsigned int resource,
1624 struct rlimit *new_rlim);
1625 int (*task_setscheduler)(struct task_struct *p);
1626 int (*task_getscheduler)(struct task_struct *p);
1627 int (*task_movememory)(struct task_struct *p);
Eric W. Biedermanae7795b2018-09-25 11:27:20 +02001628 int (*task_kill)(struct task_struct *p, struct kernel_siginfo *info,
Stephen Smalley6b4f3d02017-09-08 12:40:01 -04001629 int sig, const struct cred *cred);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001630 int (*task_prctl)(int option, unsigned long arg2, unsigned long arg3,
1631 unsigned long arg4, unsigned long arg5);
1632 void (*task_to_inode)(struct task_struct *p, struct inode *inode);
1633
1634 int (*ipc_permission)(struct kern_ipc_perm *ipcp, short flag);
1635 void (*ipc_getsecid)(struct kern_ipc_perm *ipcp, u32 *secid);
1636
1637 int (*msg_msg_alloc_security)(struct msg_msg *msg);
1638 void (*msg_msg_free_security)(struct msg_msg *msg);
1639
Eric W. Biedermand8c6e852018-03-22 21:22:26 -05001640 int (*msg_queue_alloc_security)(struct kern_ipc_perm *msq);
1641 void (*msg_queue_free_security)(struct kern_ipc_perm *msq);
1642 int (*msg_queue_associate)(struct kern_ipc_perm *msq, int msqflg);
1643 int (*msg_queue_msgctl)(struct kern_ipc_perm *msq, int cmd);
1644 int (*msg_queue_msgsnd)(struct kern_ipc_perm *msq, struct msg_msg *msg,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001645 int msqflg);
Eric W. Biedermand8c6e852018-03-22 21:22:26 -05001646 int (*msg_queue_msgrcv)(struct kern_ipc_perm *msq, struct msg_msg *msg,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001647 struct task_struct *target, long type,
1648 int mode);
1649
Eric W. Biederman7191adf2018-03-22 21:08:27 -05001650 int (*shm_alloc_security)(struct kern_ipc_perm *shp);
1651 void (*shm_free_security)(struct kern_ipc_perm *shp);
1652 int (*shm_associate)(struct kern_ipc_perm *shp, int shmflg);
1653 int (*shm_shmctl)(struct kern_ipc_perm *shp, int cmd);
1654 int (*shm_shmat)(struct kern_ipc_perm *shp, char __user *shmaddr,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001655 int shmflg);
1656
Eric W. Biedermanaefad952018-03-22 20:52:43 -05001657 int (*sem_alloc_security)(struct kern_ipc_perm *sma);
1658 void (*sem_free_security)(struct kern_ipc_perm *sma);
1659 int (*sem_associate)(struct kern_ipc_perm *sma, int semflg);
1660 int (*sem_semctl)(struct kern_ipc_perm *sma, int cmd);
1661 int (*sem_semop)(struct kern_ipc_perm *sma, struct sembuf *sops,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001662 unsigned nsops, int alter);
1663
1664 int (*netlink_send)(struct sock *sk, struct sk_buff *skb);
1665
1666 void (*d_instantiate)(struct dentry *dentry, struct inode *inode);
1667
1668 int (*getprocattr)(struct task_struct *p, char *name, char **value);
Stephen Smalleyb21507e2017-01-09 10:07:31 -05001669 int (*setprocattr)(const char *name, void *value, size_t size);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001670 int (*ismaclabel)(const char *name);
1671 int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
1672 int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid);
1673 void (*release_secctx)(char *secdata, u32 seclen);
1674
Andreas Gruenbacher6f3be9f2015-12-24 11:09:40 -05001675 void (*inode_invalidate_secctx)(struct inode *inode);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001676 int (*inode_notifysecctx)(struct inode *inode, void *ctx, u32 ctxlen);
1677 int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen);
1678 int (*inode_getsecctx)(struct inode *inode, void **ctx, u32 *ctxlen);
1679
1680#ifdef CONFIG_SECURITY_NETWORK
1681 int (*unix_stream_connect)(struct sock *sock, struct sock *other,
1682 struct sock *newsk);
1683 int (*unix_may_send)(struct socket *sock, struct socket *other);
1684
1685 int (*socket_create)(int family, int type, int protocol, int kern);
1686 int (*socket_post_create)(struct socket *sock, int family, int type,
1687 int protocol, int kern);
David Herrmannaae7cfc2018-05-04 16:28:19 +02001688 int (*socket_socketpair)(struct socket *socka, struct socket *sockb);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001689 int (*socket_bind)(struct socket *sock, struct sockaddr *address,
1690 int addrlen);
1691 int (*socket_connect)(struct socket *sock, struct sockaddr *address,
1692 int addrlen);
1693 int (*socket_listen)(struct socket *sock, int backlog);
1694 int (*socket_accept)(struct socket *sock, struct socket *newsock);
1695 int (*socket_sendmsg)(struct socket *sock, struct msghdr *msg,
1696 int size);
1697 int (*socket_recvmsg)(struct socket *sock, struct msghdr *msg,
1698 int size, int flags);
1699 int (*socket_getsockname)(struct socket *sock);
1700 int (*socket_getpeername)(struct socket *sock);
1701 int (*socket_getsockopt)(struct socket *sock, int level, int optname);
1702 int (*socket_setsockopt)(struct socket *sock, int level, int optname);
1703 int (*socket_shutdown)(struct socket *sock, int how);
1704 int (*socket_sock_rcv_skb)(struct sock *sk, struct sk_buff *skb);
1705 int (*socket_getpeersec_stream)(struct socket *sock,
1706 char __user *optval,
1707 int __user *optlen, unsigned len);
1708 int (*socket_getpeersec_dgram)(struct socket *sock,
1709 struct sk_buff *skb, u32 *secid);
1710 int (*sk_alloc_security)(struct sock *sk, int family, gfp_t priority);
1711 void (*sk_free_security)(struct sock *sk);
1712 void (*sk_clone_security)(const struct sock *sk, struct sock *newsk);
1713 void (*sk_getsecid)(struct sock *sk, u32 *secid);
1714 void (*sock_graft)(struct sock *sk, struct socket *parent);
1715 int (*inet_conn_request)(struct sock *sk, struct sk_buff *skb,
1716 struct request_sock *req);
1717 void (*inet_csk_clone)(struct sock *newsk,
1718 const struct request_sock *req);
1719 void (*inet_conn_established)(struct sock *sk, struct sk_buff *skb);
1720 int (*secmark_relabel_packet)(u32 secid);
1721 void (*secmark_refcount_inc)(void);
1722 void (*secmark_refcount_dec)(void);
1723 void (*req_classify_flow)(const struct request_sock *req,
1724 struct flowi *fl);
1725 int (*tun_dev_alloc_security)(void **security);
1726 void (*tun_dev_free_security)(void *security);
1727 int (*tun_dev_create)(void);
1728 int (*tun_dev_attach_queue)(void *security);
1729 int (*tun_dev_attach)(struct sock *sk, void *security);
1730 int (*tun_dev_open)(void *security);
Richard Haines72e89f52018-02-13 20:53:21 +00001731 int (*sctp_assoc_request)(struct sctp_endpoint *ep,
1732 struct sk_buff *skb);
1733 int (*sctp_bind_connect)(struct sock *sk, int optname,
1734 struct sockaddr *address, int addrlen);
1735 void (*sctp_sk_clone)(struct sctp_endpoint *ep, struct sock *sk,
1736 struct sock *newsk);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001737#endif /* CONFIG_SECURITY_NETWORK */
1738
Daniel Jurgensd291f1a2017-05-19 15:48:52 +03001739#ifdef CONFIG_SECURITY_INFINIBAND
1740 int (*ib_pkey_access)(void *sec, u64 subnet_prefix, u16 pkey);
Daniel Jurgens47a2b332017-05-19 15:48:54 +03001741 int (*ib_endport_manage_subnet)(void *sec, const char *dev_name,
1742 u8 port_num);
Daniel Jurgensd291f1a2017-05-19 15:48:52 +03001743 int (*ib_alloc_security)(void **sec);
1744 void (*ib_free_security)(void *sec);
1745#endif /* CONFIG_SECURITY_INFINIBAND */
1746
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001747#ifdef CONFIG_SECURITY_NETWORK_XFRM
1748 int (*xfrm_policy_alloc_security)(struct xfrm_sec_ctx **ctxp,
1749 struct xfrm_user_sec_ctx *sec_ctx,
1750 gfp_t gfp);
1751 int (*xfrm_policy_clone_security)(struct xfrm_sec_ctx *old_ctx,
1752 struct xfrm_sec_ctx **new_ctx);
1753 void (*xfrm_policy_free_security)(struct xfrm_sec_ctx *ctx);
1754 int (*xfrm_policy_delete_security)(struct xfrm_sec_ctx *ctx);
1755 int (*xfrm_state_alloc)(struct xfrm_state *x,
1756 struct xfrm_user_sec_ctx *sec_ctx);
1757 int (*xfrm_state_alloc_acquire)(struct xfrm_state *x,
1758 struct xfrm_sec_ctx *polsec,
1759 u32 secid);
1760 void (*xfrm_state_free_security)(struct xfrm_state *x);
1761 int (*xfrm_state_delete_security)(struct xfrm_state *x);
1762 int (*xfrm_policy_lookup)(struct xfrm_sec_ctx *ctx, u32 fl_secid,
1763 u8 dir);
1764 int (*xfrm_state_pol_flow_match)(struct xfrm_state *x,
1765 struct xfrm_policy *xp,
1766 const struct flowi *fl);
1767 int (*xfrm_decode_session)(struct sk_buff *skb, u32 *secid, int ckall);
1768#endif /* CONFIG_SECURITY_NETWORK_XFRM */
1769
1770 /* key management security hooks */
1771#ifdef CONFIG_KEYS
1772 int (*key_alloc)(struct key *key, const struct cred *cred,
1773 unsigned long flags);
1774 void (*key_free)(struct key *key);
1775 int (*key_permission)(key_ref_t key_ref, const struct cred *cred,
1776 unsigned perm);
1777 int (*key_getsecurity)(struct key *key, char **_buffer);
1778#endif /* CONFIG_KEYS */
1779
1780#ifdef CONFIG_AUDIT
1781 int (*audit_rule_init)(u32 field, u32 op, char *rulestr,
1782 void **lsmrule);
1783 int (*audit_rule_known)(struct audit_krule *krule);
Richard Guy Briggs90462a52019-01-31 11:52:11 -05001784 int (*audit_rule_match)(u32 secid, u32 field, u32 op, void *lsmrule);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001785 void (*audit_rule_free)(void *lsmrule);
1786#endif /* CONFIG_AUDIT */
Chenbo Fengafdb09c2017-10-18 13:00:24 -07001787
1788#ifdef CONFIG_BPF_SYSCALL
1789 int (*bpf)(int cmd, union bpf_attr *attr,
1790 unsigned int size);
1791 int (*bpf_map)(struct bpf_map *map, fmode_t fmode);
1792 int (*bpf_prog)(struct bpf_prog *prog);
1793 int (*bpf_map_alloc_security)(struct bpf_map *map);
1794 void (*bpf_map_free_security)(struct bpf_map *map);
1795 int (*bpf_prog_alloc_security)(struct bpf_prog_aux *aux);
1796 void (*bpf_prog_free_security)(struct bpf_prog_aux *aux);
1797#endif /* CONFIG_BPF_SYSCALL */
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001798};
1799
Casey Schauflere20b0432015-05-02 15:11:36 -07001800struct security_hook_heads {
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001801 struct hlist_head binder_set_context_mgr;
1802 struct hlist_head binder_transaction;
1803 struct hlist_head binder_transfer_binder;
1804 struct hlist_head binder_transfer_file;
1805 struct hlist_head ptrace_access_check;
1806 struct hlist_head ptrace_traceme;
1807 struct hlist_head capget;
1808 struct hlist_head capset;
1809 struct hlist_head capable;
1810 struct hlist_head quotactl;
1811 struct hlist_head quota_on;
1812 struct hlist_head syslog;
1813 struct hlist_head settime;
1814 struct hlist_head vm_enough_memory;
1815 struct hlist_head bprm_set_creds;
1816 struct hlist_head bprm_check_security;
1817 struct hlist_head bprm_committing_creds;
1818 struct hlist_head bprm_committed_creds;
Al Viro0b520752018-12-23 16:02:47 -05001819 struct hlist_head fs_context_dup;
David Howellsda2441f2018-11-01 23:07:24 +00001820 struct hlist_head fs_context_parse_param;
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001821 struct hlist_head sb_alloc_security;
1822 struct hlist_head sb_free_security;
Al Viro204cc0c2018-12-13 13:41:47 -05001823 struct hlist_head sb_free_mnt_opts;
Al Viro5b400232018-12-12 20:13:29 -05001824 struct hlist_head sb_eat_lsm_opts;
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001825 struct hlist_head sb_remount;
1826 struct hlist_head sb_kern_mount;
1827 struct hlist_head sb_show_options;
1828 struct hlist_head sb_statfs;
1829 struct hlist_head sb_mount;
1830 struct hlist_head sb_umount;
1831 struct hlist_head sb_pivotroot;
1832 struct hlist_head sb_set_mnt_opts;
1833 struct hlist_head sb_clone_mnt_opts;
Al Viro757cbe52018-12-14 23:42:21 -05001834 struct hlist_head sb_add_mnt_opt;
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001835 struct hlist_head dentry_init_security;
1836 struct hlist_head dentry_create_files_as;
Casey Schauflere20b0432015-05-02 15:11:36 -07001837#ifdef CONFIG_SECURITY_PATH
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001838 struct hlist_head path_unlink;
1839 struct hlist_head path_mkdir;
1840 struct hlist_head path_rmdir;
1841 struct hlist_head path_mknod;
1842 struct hlist_head path_truncate;
1843 struct hlist_head path_symlink;
1844 struct hlist_head path_link;
1845 struct hlist_head path_rename;
1846 struct hlist_head path_chmod;
1847 struct hlist_head path_chown;
1848 struct hlist_head path_chroot;
Casey Schauflere20b0432015-05-02 15:11:36 -07001849#endif
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001850 struct hlist_head inode_alloc_security;
1851 struct hlist_head inode_free_security;
1852 struct hlist_head inode_init_security;
1853 struct hlist_head inode_create;
1854 struct hlist_head inode_link;
1855 struct hlist_head inode_unlink;
1856 struct hlist_head inode_symlink;
1857 struct hlist_head inode_mkdir;
1858 struct hlist_head inode_rmdir;
1859 struct hlist_head inode_mknod;
1860 struct hlist_head inode_rename;
1861 struct hlist_head inode_readlink;
1862 struct hlist_head inode_follow_link;
1863 struct hlist_head inode_permission;
1864 struct hlist_head inode_setattr;
1865 struct hlist_head inode_getattr;
1866 struct hlist_head inode_setxattr;
1867 struct hlist_head inode_post_setxattr;
1868 struct hlist_head inode_getxattr;
1869 struct hlist_head inode_listxattr;
1870 struct hlist_head inode_removexattr;
1871 struct hlist_head inode_need_killpriv;
1872 struct hlist_head inode_killpriv;
1873 struct hlist_head inode_getsecurity;
1874 struct hlist_head inode_setsecurity;
1875 struct hlist_head inode_listsecurity;
1876 struct hlist_head inode_getsecid;
1877 struct hlist_head inode_copy_up;
1878 struct hlist_head inode_copy_up_xattr;
1879 struct hlist_head file_permission;
1880 struct hlist_head file_alloc_security;
1881 struct hlist_head file_free_security;
1882 struct hlist_head file_ioctl;
1883 struct hlist_head mmap_addr;
1884 struct hlist_head mmap_file;
1885 struct hlist_head file_mprotect;
1886 struct hlist_head file_lock;
1887 struct hlist_head file_fcntl;
1888 struct hlist_head file_set_fowner;
1889 struct hlist_head file_send_sigiotask;
1890 struct hlist_head file_receive;
1891 struct hlist_head file_open;
1892 struct hlist_head task_alloc;
1893 struct hlist_head task_free;
1894 struct hlist_head cred_alloc_blank;
1895 struct hlist_head cred_free;
1896 struct hlist_head cred_prepare;
1897 struct hlist_head cred_transfer;
Linus Torvaldsf8cf2f12018-04-07 16:53:59 -07001898 struct hlist_head cred_getsecid;
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001899 struct hlist_head kernel_act_as;
1900 struct hlist_head kernel_create_files_as;
Mimi Zohar377179c2018-07-13 14:05:56 -04001901 struct hlist_head kernel_load_data;
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001902 struct hlist_head kernel_read_file;
1903 struct hlist_head kernel_post_read_file;
1904 struct hlist_head kernel_module_request;
1905 struct hlist_head task_fix_setuid;
1906 struct hlist_head task_setpgid;
1907 struct hlist_head task_getpgid;
1908 struct hlist_head task_getsid;
1909 struct hlist_head task_getsecid;
1910 struct hlist_head task_setnice;
1911 struct hlist_head task_setioprio;
1912 struct hlist_head task_getioprio;
1913 struct hlist_head task_prlimit;
1914 struct hlist_head task_setrlimit;
1915 struct hlist_head task_setscheduler;
1916 struct hlist_head task_getscheduler;
1917 struct hlist_head task_movememory;
1918 struct hlist_head task_kill;
1919 struct hlist_head task_prctl;
1920 struct hlist_head task_to_inode;
1921 struct hlist_head ipc_permission;
1922 struct hlist_head ipc_getsecid;
1923 struct hlist_head msg_msg_alloc_security;
1924 struct hlist_head msg_msg_free_security;
1925 struct hlist_head msg_queue_alloc_security;
1926 struct hlist_head msg_queue_free_security;
1927 struct hlist_head msg_queue_associate;
1928 struct hlist_head msg_queue_msgctl;
1929 struct hlist_head msg_queue_msgsnd;
1930 struct hlist_head msg_queue_msgrcv;
1931 struct hlist_head shm_alloc_security;
1932 struct hlist_head shm_free_security;
1933 struct hlist_head shm_associate;
1934 struct hlist_head shm_shmctl;
1935 struct hlist_head shm_shmat;
1936 struct hlist_head sem_alloc_security;
1937 struct hlist_head sem_free_security;
1938 struct hlist_head sem_associate;
1939 struct hlist_head sem_semctl;
1940 struct hlist_head sem_semop;
1941 struct hlist_head netlink_send;
1942 struct hlist_head d_instantiate;
1943 struct hlist_head getprocattr;
1944 struct hlist_head setprocattr;
1945 struct hlist_head ismaclabel;
1946 struct hlist_head secid_to_secctx;
1947 struct hlist_head secctx_to_secid;
1948 struct hlist_head release_secctx;
1949 struct hlist_head inode_invalidate_secctx;
1950 struct hlist_head inode_notifysecctx;
1951 struct hlist_head inode_setsecctx;
1952 struct hlist_head inode_getsecctx;
Casey Schauflere20b0432015-05-02 15:11:36 -07001953#ifdef CONFIG_SECURITY_NETWORK
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001954 struct hlist_head unix_stream_connect;
1955 struct hlist_head unix_may_send;
1956 struct hlist_head socket_create;
1957 struct hlist_head socket_post_create;
David Herrmannaae7cfc2018-05-04 16:28:19 +02001958 struct hlist_head socket_socketpair;
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001959 struct hlist_head socket_bind;
1960 struct hlist_head socket_connect;
1961 struct hlist_head socket_listen;
1962 struct hlist_head socket_accept;
1963 struct hlist_head socket_sendmsg;
1964 struct hlist_head socket_recvmsg;
1965 struct hlist_head socket_getsockname;
1966 struct hlist_head socket_getpeername;
1967 struct hlist_head socket_getsockopt;
1968 struct hlist_head socket_setsockopt;
1969 struct hlist_head socket_shutdown;
1970 struct hlist_head socket_sock_rcv_skb;
1971 struct hlist_head socket_getpeersec_stream;
1972 struct hlist_head socket_getpeersec_dgram;
1973 struct hlist_head sk_alloc_security;
1974 struct hlist_head sk_free_security;
1975 struct hlist_head sk_clone_security;
1976 struct hlist_head sk_getsecid;
1977 struct hlist_head sock_graft;
1978 struct hlist_head inet_conn_request;
1979 struct hlist_head inet_csk_clone;
1980 struct hlist_head inet_conn_established;
1981 struct hlist_head secmark_relabel_packet;
1982 struct hlist_head secmark_refcount_inc;
1983 struct hlist_head secmark_refcount_dec;
1984 struct hlist_head req_classify_flow;
1985 struct hlist_head tun_dev_alloc_security;
1986 struct hlist_head tun_dev_free_security;
1987 struct hlist_head tun_dev_create;
1988 struct hlist_head tun_dev_attach_queue;
1989 struct hlist_head tun_dev_attach;
1990 struct hlist_head tun_dev_open;
Linus Torvalds36126052018-04-07 11:11:41 -07001991 struct hlist_head sctp_assoc_request;
1992 struct hlist_head sctp_bind_connect;
1993 struct hlist_head sctp_sk_clone;
Casey Schauflere20b0432015-05-02 15:11:36 -07001994#endif /* CONFIG_SECURITY_NETWORK */
Daniel Jurgensd291f1a2017-05-19 15:48:52 +03001995#ifdef CONFIG_SECURITY_INFINIBAND
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001996 struct hlist_head ib_pkey_access;
1997 struct hlist_head ib_endport_manage_subnet;
1998 struct hlist_head ib_alloc_security;
1999 struct hlist_head ib_free_security;
Daniel Jurgensd291f1a2017-05-19 15:48:52 +03002000#endif /* CONFIG_SECURITY_INFINIBAND */
Casey Schauflere20b0432015-05-02 15:11:36 -07002001#ifdef CONFIG_SECURITY_NETWORK_XFRM
Sargun Dhillondf0ce172018-03-29 01:28:23 +00002002 struct hlist_head xfrm_policy_alloc_security;
2003 struct hlist_head xfrm_policy_clone_security;
2004 struct hlist_head xfrm_policy_free_security;
2005 struct hlist_head xfrm_policy_delete_security;
2006 struct hlist_head xfrm_state_alloc;
2007 struct hlist_head xfrm_state_alloc_acquire;
2008 struct hlist_head xfrm_state_free_security;
2009 struct hlist_head xfrm_state_delete_security;
2010 struct hlist_head xfrm_policy_lookup;
2011 struct hlist_head xfrm_state_pol_flow_match;
2012 struct hlist_head xfrm_decode_session;
Casey Schauflere20b0432015-05-02 15:11:36 -07002013#endif /* CONFIG_SECURITY_NETWORK_XFRM */
2014#ifdef CONFIG_KEYS
Sargun Dhillondf0ce172018-03-29 01:28:23 +00002015 struct hlist_head key_alloc;
2016 struct hlist_head key_free;
2017 struct hlist_head key_permission;
2018 struct hlist_head key_getsecurity;
Casey Schauflere20b0432015-05-02 15:11:36 -07002019#endif /* CONFIG_KEYS */
2020#ifdef CONFIG_AUDIT
Sargun Dhillondf0ce172018-03-29 01:28:23 +00002021 struct hlist_head audit_rule_init;
2022 struct hlist_head audit_rule_known;
2023 struct hlist_head audit_rule_match;
2024 struct hlist_head audit_rule_free;
Casey Schauflere20b0432015-05-02 15:11:36 -07002025#endif /* CONFIG_AUDIT */
Chenbo Fengafdb09c2017-10-18 13:00:24 -07002026#ifdef CONFIG_BPF_SYSCALL
Sargun Dhillondf0ce172018-03-29 01:28:23 +00002027 struct hlist_head bpf;
2028 struct hlist_head bpf_map;
2029 struct hlist_head bpf_prog;
2030 struct hlist_head bpf_map_alloc_security;
2031 struct hlist_head bpf_map_free_security;
2032 struct hlist_head bpf_prog_alloc_security;
2033 struct hlist_head bpf_prog_free_security;
Chenbo Fengafdb09c2017-10-18 13:00:24 -07002034#endif /* CONFIG_BPF_SYSCALL */
Kees Cook3859a272016-10-28 01:22:25 -07002035} __randomize_layout;
Casey Schauflere20b0432015-05-02 15:11:36 -07002036
2037/*
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002038 * Security module hook list structure.
2039 * For use with generic list macros for common operations.
2040 */
2041struct security_hook_list {
Sargun Dhillondf0ce172018-03-29 01:28:23 +00002042 struct hlist_node list;
2043 struct hlist_head *head;
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002044 union security_list_options hook;
Casey Schauflerd69dece52017-01-18 17:09:05 -08002045 char *lsm;
Kees Cook3859a272016-10-28 01:22:25 -07002046} __randomize_layout;
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002047
2048/*
Casey Schauflerbbd36622018-11-12 09:30:56 -08002049 * Security blob size or offset data.
2050 */
2051struct lsm_blob_sizes {
2052 int lbs_cred;
Casey Schaufler33bf60c2018-11-12 12:02:49 -08002053 int lbs_file;
Casey Schauflerafb1cbe32018-09-21 17:19:29 -07002054 int lbs_inode;
Casey Schauflerecd5f822018-11-20 11:55:02 -08002055 int lbs_ipc;
2056 int lbs_msg_msg;
Casey Schauflerf4ad8f22018-09-21 17:19:37 -07002057 int lbs_task;
Casey Schauflerbbd36622018-11-12 09:30:56 -08002058};
2059
2060/*
Casey Schauflere20b0432015-05-02 15:11:36 -07002061 * Initializing a security_hook_list structure takes
2062 * up a lot of space in a source file. This macro takes
2063 * care of the common case and reduces the amount of
2064 * text involved.
Casey Schauflere20b0432015-05-02 15:11:36 -07002065 */
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002066#define LSM_HOOK_INIT(HEAD, HOOK) \
2067 { .head = &security_hook_heads.HEAD, .hook = { .HEAD = HOOK } }
Casey Schauflere20b0432015-05-02 15:11:36 -07002068
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002069extern struct security_hook_heads security_hook_heads;
Casey Schauflerd69dece52017-01-18 17:09:05 -08002070extern char *lsm_names;
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07002071
Casey Schauflerd69dece52017-01-18 17:09:05 -08002072extern void security_add_hooks(struct security_hook_list *hooks, int count,
2073 char *lsm);
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002074
Kees Cook47008e52018-09-19 16:13:25 -07002075#define LSM_FLAG_LEGACY_MAJOR BIT(0)
Kees Cook14bd99c2018-09-19 19:57:06 -07002076#define LSM_FLAG_EXCLUSIVE BIT(1)
Kees Cook47008e52018-09-19 16:13:25 -07002077
Kees Cooke2bc4452018-09-19 17:48:21 -07002078enum lsm_order {
2079 LSM_ORDER_FIRST = -1, /* This is only for capabilities. */
2080 LSM_ORDER_MUTABLE = 0,
2081};
2082
Kees Cook5b89c1b2018-10-10 17:18:21 -07002083struct lsm_info {
Kees Cook07aed2f2018-10-10 17:18:24 -07002084 const char *name; /* Required. */
Kees Cooke2bc4452018-09-19 17:48:21 -07002085 enum lsm_order order; /* Optional: default is LSM_ORDER_MUTABLE */
Kees Cook47008e52018-09-19 16:13:25 -07002086 unsigned long flags; /* Optional: flags describing LSM */
Kees Cooka8027fb2018-10-09 14:42:57 -07002087 int *enabled; /* Optional: controlled by CONFIG_LSM */
Kees Cook5b89c1b2018-10-10 17:18:21 -07002088 int (*init)(void); /* Required. */
Casey Schauflerbbd36622018-11-12 09:30:56 -08002089 struct lsm_blob_sizes *blobs; /* Optional: for blob sharing. */
Kees Cook5b89c1b2018-10-10 17:18:21 -07002090};
2091
2092extern struct lsm_info __start_lsm_info[], __end_lsm_info[];
2093
Kees Cook3d6e5f62018-10-10 17:18:23 -07002094#define DEFINE_LSM(lsm) \
Kees Cook5b89c1b2018-10-10 17:18:21 -07002095 static struct lsm_info __lsm_##lsm \
2096 __used __section(.lsm_info.init) \
Kees Cook3d6e5f62018-10-10 17:18:23 -07002097 __aligned(sizeof(unsigned long))
Kees Cook5b89c1b2018-10-10 17:18:21 -07002098
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002099#ifdef CONFIG_SECURITY_SELINUX_DISABLE
2100/*
2101 * Assuring the safety of deleting a security module is up to
2102 * the security module involved. This may entail ordering the
2103 * module's hook list in a particular way, refusing to disable
2104 * the module once a policy is loaded or any number of other
2105 * actions better imagined than described.
2106 *
2107 * The name of the configuration option reflects the only module
2108 * that currently uses the mechanism. Any developer who thinks
2109 * disabling their module is a good idea needs to be at least as
2110 * careful as the SELinux team.
2111 */
2112static inline void security_delete_hooks(struct security_hook_list *hooks,
2113 int count)
2114{
2115 int i;
2116
2117 for (i = 0; i < count; i++)
Sargun Dhillondf0ce172018-03-29 01:28:23 +00002118 hlist_del_rcu(&hooks[i].list);
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002119}
2120#endif /* CONFIG_SECURITY_SELINUX_DISABLE */
2121
James Morrisdd0859d2017-02-15 00:17:24 +11002122/* Currently required to handle SELinux runtime hook disable. */
2123#ifdef CONFIG_SECURITY_WRITABLE_HOOKS
2124#define __lsm_ro_after_init
2125#else
2126#define __lsm_ro_after_init __ro_after_init
2127#endif /* CONFIG_SECURITY_WRITABLE_HOOKS */
2128
Casey Schauflerafb1cbe32018-09-21 17:19:29 -07002129extern int lsm_inode_alloc(struct inode *inode);
2130
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07002131#endif /* ! __LINUX_LSM_HOOKS_H */