blob: 37713f7da14ee2fa938f46ae1409e7a1c18eeaf2 [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:
322 * Check for permission to change DAC's permission of a file or directory.
323 * @dentry contains the dentry structure.
324 * @mnt contains the vfsmnt structure.
325 * @mode contains DAC's mode.
326 * Return 0 if permission is granted.
327 * @path_chown:
328 * Check for permission to change owner/group of a file or directory.
329 * @path contains the path structure.
330 * @uid contains new owner's ID.
331 * @gid contains new group's ID.
332 * Return 0 if permission is granted.
333 * @path_chroot:
334 * Check for permission to change root directory.
335 * @path contains the path structure.
336 * Return 0 if permission is granted.
337 * @inode_readlink:
338 * Check the permission to read the symbolic link.
339 * @dentry contains the dentry structure for the file link.
340 * Return 0 if permission is granted.
341 * @inode_follow_link:
342 * Check permission to follow a symbolic link when looking up a pathname.
343 * @dentry contains the dentry structure for the link.
Linus Torvaldse22619a2015-06-27 13:26:03 -0700344 * @inode contains the inode, which itself is not stable in RCU-walk
345 * @rcu indicates whether we are in RCU-walk mode.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700346 * Return 0 if permission is granted.
347 * @inode_permission:
348 * Check permission before accessing an inode. This hook is called by the
349 * existing Linux permission function, so a security module can use it to
350 * provide additional checking for existing Linux permission checks.
351 * Notice that this hook is called when a file is opened (as well as many
352 * other operations), whereas the file_security_ops permission hook is
353 * called when the actual read/write operations are performed.
354 * @inode contains the inode structure to check.
355 * @mask contains the permission mask.
356 * Return 0 if permission is granted.
357 * @inode_setattr:
358 * Check permission before setting file attributes. Note that the kernel
359 * call to notify_change is performed from several locations, whenever
360 * file attributes change (such as when a file is truncated, chown/chmod
361 * operations, transferring disk quotas, etc).
362 * @dentry contains the dentry structure for the file.
363 * @attr is the iattr structure containing the new file attributes.
364 * Return 0 if permission is granted.
365 * @path_truncate:
366 * Check permission before truncating a file.
367 * @path contains the path structure for the file.
368 * Return 0 if permission is granted.
369 * @inode_getattr:
370 * Check permission before obtaining file attributes.
Mickaël Salaünb8aa8452016-12-22 00:32:25 +0100371 * @path contains the path structure for the file.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700372 * Return 0 if permission is granted.
373 * @inode_setxattr:
374 * Check permission before setting the extended attributes
375 * @value identified by @name for @dentry.
376 * Return 0 if permission is granted.
377 * @inode_post_setxattr:
378 * Update inode security field after successful setxattr operation.
379 * @value identified by @name for @dentry.
380 * @inode_getxattr:
381 * Check permission before obtaining the extended attributes
382 * identified by @name for @dentry.
383 * Return 0 if permission is granted.
384 * @inode_listxattr:
385 * Check permission before obtaining the list of extended attribute
386 * names for @dentry.
387 * Return 0 if permission is granted.
388 * @inode_removexattr:
389 * Check permission before removing the extended attribute
390 * identified by @name for @dentry.
391 * Return 0 if permission is granted.
392 * @inode_getsecurity:
393 * Retrieve a copy of the extended attribute representation of the
394 * security label associated with @name for @inode via @buffer. Note that
395 * @name is the remainder of the attribute name after the security prefix
396 * has been removed. @alloc is used to specify of the call should return a
397 * value via the buffer or just the value length Return size of buffer on
398 * success.
399 * @inode_setsecurity:
400 * Set the security label associated with @name for @inode from the
401 * extended attribute value @value. @size indicates the size of the
402 * @value in bytes. @flags may be XATTR_CREATE, XATTR_REPLACE, or 0.
403 * Note that @name is the remainder of the attribute name after the
404 * security. prefix has been removed.
405 * Return 0 on success.
406 * @inode_listsecurity:
407 * Copy the extended attribute names for the security labels
408 * associated with @inode into @buffer. The maximum size of @buffer
409 * is specified by @buffer_size. @buffer may be NULL to request
410 * the size of the buffer required.
411 * Returns number of bytes used/required on success.
412 * @inode_need_killpriv:
413 * Called when an inode has been changed.
414 * @dentry is the dentry being changed.
415 * Return <0 on error to abort the inode change operation.
416 * Return 0 if inode_killpriv does not need to be called.
417 * Return >0 if inode_killpriv does need to be called.
418 * @inode_killpriv:
419 * The setuid bit is being removed. Remove similar security labels.
420 * Called with the dentry->d_inode->i_mutex held.
421 * @dentry is the dentry being changed.
422 * Return 0 on success. If error is returned, then the operation
423 * causing setuid bit removal is failed.
424 * @inode_getsecid:
425 * Get the secid associated with the node.
426 * @inode contains a pointer to the inode.
427 * @secid contains a pointer to the location where result will be saved.
428 * In case of failure, @secid will be set to zero.
Vivek Goyald8ad8b42016-07-13 11:13:56 -0400429 * @inode_copy_up:
430 * A file is about to be copied up from lower layer to upper layer of
431 * overlay filesystem. Security module can prepare a set of new creds
432 * and modify as need be and return new creds. Caller will switch to
433 * new creds temporarily to create new file and release newly allocated
434 * creds.
435 * @src indicates the union dentry of file that is being copied up.
436 * @new pointer to pointer to return newly allocated creds.
437 * Returns 0 on success or a negative error code on error.
Vivek Goyal121ab822016-07-13 10:44:49 -0400438 * @inode_copy_up_xattr:
439 * Filter the xattrs being copied up when a unioned file is copied
440 * up from a lower layer to the union/overlay layer.
441 * @name indicates the name of the xattr.
442 * Returns 0 to accept the xattr, 1 to discard the xattr, -EOPNOTSUPP if
443 * security module does not know about attribute or a negative error code
444 * to abort the copy up. Note that the caller is responsible for reading
445 * and writing the xattrs as this hook is merely a filter.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700446 *
447 * Security hooks for file operations
448 *
449 * @file_permission:
450 * Check file permissions before accessing an open file. This hook is
451 * called by various operations that read or write files. A security
452 * module can use this hook to perform additional checking on these
453 * operations, e.g. to revalidate permissions on use to support privilege
454 * bracketing or policy changes. Notice that this hook is used when the
455 * actual read/write operations are performed, whereas the
456 * inode_security_ops hook is called when a file is opened (as well as
457 * many other operations).
458 * Caveat: Although this hook can be used to revalidate permissions for
459 * various system call operations that read or write files, it does not
460 * address the revalidation of permissions for memory-mapped files.
461 * Security modules must handle this separately if they need such
462 * revalidation.
463 * @file contains the file structure being accessed.
464 * @mask contains the requested permissions.
465 * Return 0 if permission is granted.
466 * @file_alloc_security:
467 * Allocate and attach a security structure to the file->f_security field.
468 * The security field is initialized to NULL when the structure is first
469 * created.
470 * @file contains the file structure to secure.
471 * Return 0 if the hook is successful and permission is granted.
472 * @file_free_security:
473 * Deallocate and free any security structures stored in file->f_security.
474 * @file contains the file structure being modified.
475 * @file_ioctl:
476 * @file contains the file structure.
477 * @cmd contains the operation to perform.
478 * @arg contains the operational arguments.
479 * Check permission for an ioctl operation on @file. Note that @arg
480 * sometimes represents a user space pointer; in other cases, it may be a
481 * simple integer value. When @arg represents a user space pointer, it
482 * should never be used by the security module.
483 * Return 0 if permission is granted.
484 * @mmap_addr :
485 * Check permissions for a mmap operation at @addr.
486 * @addr contains virtual address that will be used for the operation.
487 * Return 0 if permission is granted.
488 * @mmap_file :
489 * Check permissions for a mmap operation. The @file may be NULL, e.g.
490 * if mapping anonymous memory.
491 * @file contains the file structure for file to map (may be NULL).
492 * @reqprot contains the protection requested by the application.
493 * @prot contains the protection that will be applied by the kernel.
494 * @flags contains the operational flags.
495 * Return 0 if permission is granted.
496 * @file_mprotect:
497 * Check permissions before changing memory access permissions.
498 * @vma contains the memory region to modify.
499 * @reqprot contains the protection requested by the application.
500 * @prot contains the protection that will be applied by the kernel.
501 * Return 0 if permission is granted.
502 * @file_lock:
503 * Check permission before performing file locking operations.
504 * Note: this hook mediates both flock and fcntl style locks.
505 * @file contains the file structure.
506 * @cmd contains the posix-translated lock operation to perform
507 * (e.g. F_RDLCK, F_WRLCK).
508 * Return 0 if permission is granted.
509 * @file_fcntl:
510 * Check permission before allowing the file operation specified by @cmd
511 * from being performed on the file @file. Note that @arg sometimes
512 * represents a user space pointer; in other cases, it may be a simple
513 * integer value. When @arg represents a user space pointer, it should
514 * never be used by the security module.
515 * @file contains the file structure.
516 * @cmd contains the operation to be performed.
517 * @arg contains the operational arguments.
518 * Return 0 if permission is granted.
519 * @file_set_fowner:
520 * Save owner security information (typically from current->security) in
521 * file->f_security for later use by the send_sigiotask hook.
522 * @file contains the file structure to update.
523 * Return 0 on success.
524 * @file_send_sigiotask:
525 * Check permission for the file owner @fown to send SIGIO or SIGURG to the
526 * process @tsk. Note that this hook is sometimes called from interrupt.
527 * Note that the fown_struct, @fown, is never outside the context of a
528 * struct file, so the file structure (and associated security information)
Kees Cookf00f85a2017-05-13 04:51:42 -0700529 * can always be obtained: container_of(fown, struct file, f_owner)
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700530 * @tsk contains the structure of task receiving signal.
531 * @fown contains the file owner information.
532 * @sig is the signal that will be sent. When 0, kernel sends SIGIO.
533 * Return 0 if permission is granted.
534 * @file_receive:
535 * This hook allows security modules to control the ability of a process
536 * to receive an open file descriptor via socket IPC.
537 * @file contains the file structure being received.
538 * Return 0 if permission is granted.
Kees Cookf00f85a2017-05-13 04:51:42 -0700539 * @file_open:
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700540 * Save open-time permission checking state for later use upon
541 * file_permission, and recheck access if anything has changed
542 * since inode_permission.
543 *
544 * Security hooks for task operations.
545 *
Tetsuo Handae4e55b42017-03-24 20:46:33 +0900546 * @task_alloc:
547 * @task task being allocated.
548 * @clone_flags contains the flags indicating what should be shared.
549 * Handle allocation of task-related resources.
550 * Returns a zero on success, negative values on failure.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700551 * @task_free:
Tetsuo Handae4e55b42017-03-24 20:46:33 +0900552 * @task task about to be freed.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700553 * Handle release of task-related resources. (Note that this can be called
554 * from interrupt context.)
555 * @cred_alloc_blank:
556 * @cred points to the credentials.
557 * @gfp indicates the atomicity of any memory allocations.
558 * Only allocate sufficient memory and attach to @cred such that
559 * cred_transfer() will not get ENOMEM.
560 * @cred_free:
561 * @cred points to the credentials.
562 * Deallocate and clear the cred->security field in a set of credentials.
563 * @cred_prepare:
564 * @new points to the new credentials.
565 * @old points to the original credentials.
566 * @gfp indicates the atomicity of any memory allocations.
567 * Prepare a new set of credentials by copying the data from the old set.
568 * @cred_transfer:
569 * @new points to the new credentials.
570 * @old points to the original credentials.
571 * Transfer data from original creds to new creds
Matthew Garrett3ec30112018-01-08 13:36:19 -0800572 * @cred_getsecid:
573 * Retrieve the security identifier of the cred structure @c
574 * @c contains the credentials, secid will be placed into @secid.
575 * In case of failure, @secid will be set to zero.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700576 * @kernel_act_as:
577 * Set the credentials for a kernel service to act as (subjective context).
578 * @new points to the credentials to be modified.
579 * @secid specifies the security ID to be set
580 * The current task must be the one that nominated @secid.
581 * Return 0 if successful.
582 * @kernel_create_files_as:
583 * Set the file creation context in a set of credentials to be the same as
584 * the objective context of the specified inode.
585 * @new points to the credentials to be modified.
586 * @inode points to the inode to use as a reference.
587 * The current task must be the one that nominated @inode.
588 * Return 0 if successful.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700589 * @kernel_module_request:
590 * Ability to trigger the kernel to automatically upcall to userspace for
591 * userspace to load a kernel module with the given name.
592 * @kmod_name name of the module requested by the kernel
593 * Return 0 if successful.
Mimi Zohar377179c2018-07-13 14:05:56 -0400594 * @kernel_load_data:
595 * Load data provided by userspace.
596 * @id kernel load data identifier
597 * Return 0 if permission is granted.
Mimi Zohar39eeb4f2016-01-30 22:23:26 -0500598 * @kernel_read_file:
599 * Read a file specified by userspace.
600 * @file contains the file structure pointing to the file being read
601 * by the kernel.
602 * @id kernel read file identifier
603 * Return 0 if permission is granted.
Mimi Zoharb44a7df2015-12-28 16:02:29 -0500604 * @kernel_post_read_file:
605 * Read a file specified by userspace.
606 * @file contains the file structure pointing to the file being read
607 * by the kernel.
608 * @buf pointer to buffer containing the file contents.
609 * @size length of the file contents.
Mimi Zoharbc8ca5b2016-01-24 10:07:32 -0500610 * @id kernel read file identifier
Mimi Zoharb44a7df2015-12-28 16:02:29 -0500611 * Return 0 if permission is granted.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700612 * @task_fix_setuid:
613 * Update the module's state after setting one or more of the user
614 * identity attributes of the current process. The @flags parameter
615 * indicates which of the set*uid system calls invoked this hook. If
616 * @new is the set of credentials that will be installed. Modifications
617 * should be made to this rather than to @current->cred.
618 * @old is the set of credentials that are being replaces
619 * @flags contains one of the LSM_SETID_* values.
620 * Return 0 on success.
621 * @task_setpgid:
622 * Check permission before setting the process group identifier of the
623 * process @p to @pgid.
624 * @p contains the task_struct for process being modified.
625 * @pgid contains the new pgid.
626 * Return 0 if permission is granted.
627 * @task_getpgid:
628 * Check permission before getting the process group identifier of the
629 * process @p.
630 * @p contains the task_struct for the process.
631 * Return 0 if permission is granted.
632 * @task_getsid:
633 * Check permission before getting the session identifier of the process
634 * @p.
635 * @p contains the task_struct for the process.
636 * Return 0 if permission is granted.
637 * @task_getsecid:
638 * Retrieve the security identifier of the process @p.
639 * @p contains the task_struct for the process and place is into @secid.
640 * In case of failure, @secid will be set to zero.
641 *
642 * @task_setnice:
643 * Check permission before setting the nice value of @p to @nice.
644 * @p contains the task_struct of process.
645 * @nice contains the new nice value.
646 * Return 0 if permission is granted.
647 * @task_setioprio
648 * Check permission before setting the ioprio value of @p to @ioprio.
649 * @p contains the task_struct of process.
650 * @ioprio contains the new ioprio value
651 * Return 0 if permission is granted.
652 * @task_getioprio
653 * Check permission before getting the ioprio value of @p.
654 * @p contains the task_struct of process.
655 * Return 0 if permission is granted.
Stephen Smalley791ec492017-02-17 07:57:00 -0500656 * @task_prlimit:
657 * Check permission before getting and/or setting the resource limits of
658 * another task.
659 * @cred points to the cred structure for the current task.
660 * @tcred points to the cred structure for the target task.
661 * @flags contains the LSM_PRLIMIT_* flag bits indicating whether the
662 * resource limits are being read, modified, or both.
663 * Return 0 if permission is granted.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700664 * @task_setrlimit:
Stephen Smalley791ec492017-02-17 07:57:00 -0500665 * Check permission before setting the resource limits of process @p
666 * for @resource to @new_rlim. The old resource limit values can
667 * be examined by dereferencing (p->signal->rlim + resource).
668 * @p points to the task_struct for the target task's group leader.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700669 * @resource contains the resource whose limit is being set.
670 * @new_rlim contains the new limits for @resource.
671 * Return 0 if permission is granted.
672 * @task_setscheduler:
673 * Check permission before setting scheduling policy and/or parameters of
674 * process @p based on @policy and @lp.
675 * @p contains the task_struct for process.
676 * @policy contains the scheduling policy.
677 * @lp contains the scheduling parameters.
678 * Return 0 if permission is granted.
679 * @task_getscheduler:
680 * Check permission before obtaining scheduling information for process
681 * @p.
682 * @p contains the task_struct for process.
683 * Return 0 if permission is granted.
684 * @task_movememory
685 * Check permission before moving memory owned by process @p.
686 * @p contains the task_struct for process.
687 * Return 0 if permission is granted.
688 * @task_kill:
689 * Check permission before sending signal @sig to @p. @info can be NULL,
Eric W. Biedermanae7795b2018-09-25 11:27:20 +0200690 * the constant 1, or a pointer to a kernel_siginfo structure. If @info is 1 or
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700691 * SI_FROMKERNEL(info) is true, then the signal should be viewed as coming
692 * from the kernel and should typically be permitted.
693 * SIGIO signals are handled separately by the send_sigiotask hook in
694 * file_security_ops.
695 * @p contains the task_struct for process.
696 * @info contains the signal information.
697 * @sig contains the signal value.
Stephen Smalley6b4f3d02017-09-08 12:40:01 -0400698 * @cred contains the cred of the process where the signal originated, or
699 * NULL if the current task is the originator.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700700 * Return 0 if permission is granted.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700701 * @task_prctl:
702 * Check permission before performing a process control operation on the
703 * current process.
704 * @option contains the operation.
705 * @arg2 contains a argument.
706 * @arg3 contains a argument.
707 * @arg4 contains a argument.
708 * @arg5 contains a argument.
709 * Return -ENOSYS if no-one wanted to handle this op, any other value to
710 * cause prctl() to return immediately with that value.
711 * @task_to_inode:
712 * Set the security attributes for an inode based on an associated task's
713 * security attributes, e.g. for /proc/pid inodes.
714 * @p contains the task_struct for the task.
715 * @inode contains the inode structure for the inode.
716 *
717 * Security hooks for Netlink messaging.
718 *
719 * @netlink_send:
720 * Save security information for a netlink message so that permission
721 * checking can be performed when the message is processed. The security
722 * information can be saved using the eff_cap field of the
723 * netlink_skb_parms structure. Also may be used to provide fine
724 * grained control over message transmission.
725 * @sk associated sock of task sending the message.
726 * @skb contains the sk_buff structure for the netlink message.
727 * Return 0 if the information was successfully saved and message
728 * is allowed to be transmitted.
729 *
730 * Security hooks for Unix domain networking.
731 *
732 * @unix_stream_connect:
733 * Check permissions before establishing a Unix domain stream connection
734 * between @sock and @other.
735 * @sock contains the sock structure.
736 * @other contains the peer sock structure.
737 * @newsk contains the new sock structure.
738 * Return 0 if permission is granted.
739 * @unix_may_send:
740 * Check permissions before connecting or sending datagrams from @sock to
741 * @other.
742 * @sock contains the socket structure.
743 * @other contains the peer socket structure.
744 * Return 0 if permission is granted.
745 *
746 * The @unix_stream_connect and @unix_may_send hooks were necessary because
747 * Linux provides an alternative to the conventional file name space for Unix
748 * domain sockets. Whereas binding and connecting to sockets in the file name
749 * space is mediated by the typical file permissions (and caught by the mknod
750 * and permission hooks in inode_security_ops), binding and connecting to
751 * sockets in the abstract name space is completely unmediated. Sufficient
752 * control of Unix domain sockets in the abstract name space isn't possible
753 * using only the socket layer hooks, since we need to know the actual target
754 * socket, which is not looked up until we are inside the af_unix code.
755 *
756 * Security hooks for socket operations.
757 *
758 * @socket_create:
759 * Check permissions prior to creating a new socket.
760 * @family contains the requested protocol family.
761 * @type contains the requested communications type.
762 * @protocol contains the requested protocol.
763 * @kern set to 1 if a kernel socket.
764 * Return 0 if permission is granted.
765 * @socket_post_create:
766 * This hook allows a module to update or allocate a per-socket security
767 * structure. Note that the security field was not added directly to the
768 * socket structure, but rather, the socket security information is stored
769 * in the associated inode. Typically, the inode alloc_security hook will
770 * allocate and and attach security information to
771 * sock->inode->i_security. This hook may be used to update the
772 * sock->inode->i_security field with additional information that wasn't
773 * available when the inode was allocated.
774 * @sock contains the newly created socket structure.
775 * @family contains the requested protocol family.
776 * @type contains the requested communications type.
777 * @protocol contains the requested protocol.
778 * @kern set to 1 if a kernel socket.
David Herrmannaae7cfc2018-05-04 16:28:19 +0200779 * @socket_socketpair:
780 * Check permissions before creating a fresh pair of sockets.
781 * @socka contains the first socket structure.
782 * @sockb contains the second socket structure.
783 * Return 0 if permission is granted and the connection was established.
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700784 * @socket_bind:
785 * Check permission before socket protocol layer bind operation is
786 * performed and the socket @sock is bound to the address specified in the
787 * @address parameter.
788 * @sock contains the socket structure.
789 * @address contains the address to bind to.
790 * @addrlen contains the length of address.
791 * Return 0 if permission is granted.
792 * @socket_connect:
793 * Check permission before socket protocol layer connect operation
794 * attempts to connect socket @sock to a remote address, @address.
795 * @sock contains the socket structure.
796 * @address contains the address of remote endpoint.
797 * @addrlen contains the length of address.
798 * Return 0 if permission is granted.
799 * @socket_listen:
800 * Check permission before socket protocol layer listen operation.
801 * @sock contains the socket structure.
802 * @backlog contains the maximum length for the pending connection queue.
803 * Return 0 if permission is granted.
804 * @socket_accept:
805 * Check permission before accepting a new connection. Note that the new
806 * socket, @newsock, has been created and some information copied to it,
807 * but the accept operation has not actually been performed.
808 * @sock contains the listening socket structure.
809 * @newsock contains the newly created server socket for connection.
810 * Return 0 if permission is granted.
811 * @socket_sendmsg:
812 * Check permission before transmitting a message to another socket.
813 * @sock contains the socket structure.
814 * @msg contains the message to be transmitted.
815 * @size contains the size of message.
816 * Return 0 if permission is granted.
817 * @socket_recvmsg:
818 * Check permission before receiving a message from a socket.
819 * @sock contains the socket structure.
820 * @msg contains the message structure.
821 * @size contains the size of message structure.
822 * @flags contains the operational flags.
823 * Return 0 if permission is granted.
824 * @socket_getsockname:
825 * Check permission before the local address (name) of the socket object
826 * @sock is retrieved.
827 * @sock contains the socket structure.
828 * Return 0 if permission is granted.
829 * @socket_getpeername:
830 * Check permission before the remote address (name) of a socket object
831 * @sock is retrieved.
832 * @sock contains the socket structure.
833 * Return 0 if permission is granted.
834 * @socket_getsockopt:
835 * Check permissions before retrieving the options associated with socket
836 * @sock.
837 * @sock contains the socket structure.
838 * @level contains the protocol level to retrieve option from.
839 * @optname contains the name of option to retrieve.
840 * Return 0 if permission is granted.
841 * @socket_setsockopt:
842 * Check permissions before setting the options associated with socket
843 * @sock.
844 * @sock contains the socket structure.
845 * @level contains the protocol level to set options for.
846 * @optname contains the name of the option to set.
847 * Return 0 if permission is granted.
848 * @socket_shutdown:
849 * Checks permission before all or part of a connection on the socket
850 * @sock is shut down.
851 * @sock contains the socket structure.
852 * @how contains the flag indicating how future sends and receives
853 * are handled.
854 * Return 0 if permission is granted.
855 * @socket_sock_rcv_skb:
856 * Check permissions on incoming network packets. This hook is distinct
857 * from Netfilter's IP input hooks since it is the first time that the
858 * incoming sk_buff @skb has been associated with a particular socket, @sk.
859 * Must not sleep inside this hook because some callers hold spinlocks.
860 * @sk contains the sock (not socket) associated with the incoming sk_buff.
861 * @skb contains the incoming network data.
862 * @socket_getpeersec_stream:
863 * This hook allows the security module to provide peer socket security
864 * state for unix or connected tcp sockets to userspace via getsockopt
865 * SO_GETPEERSEC. For tcp sockets this can be meaningful if the
866 * socket is associated with an ipsec SA.
867 * @sock is the local socket.
868 * @optval userspace memory where the security state is to be copied.
869 * @optlen userspace int where the module should copy the actual length
870 * of the security state.
871 * @len as input is the maximum length to copy to userspace provided
872 * by the caller.
873 * Return 0 if all is well, otherwise, typical getsockopt return
874 * values.
875 * @socket_getpeersec_dgram:
876 * This hook allows the security module to provide peer socket security
877 * state for udp sockets on a per-packet basis to userspace via
878 * getsockopt SO_GETPEERSEC. The application must first have indicated
879 * the IP_PASSSEC option via getsockopt. It can then retrieve the
880 * security state returned by this hook for a packet via the SCM_SECURITY
881 * ancillary message type.
882 * @skb is the skbuff for the packet being queried
883 * @secdata is a pointer to a buffer in which to copy the security data
884 * @seclen is the maximum length for @secdata
885 * Return 0 on success, error on failure.
886 * @sk_alloc_security:
887 * Allocate and attach a security structure to the sk->sk_security field,
888 * which is used to copy security attributes between local stream sockets.
889 * @sk_free_security:
890 * Deallocate security structure.
891 * @sk_clone_security:
892 * Clone/copy security structure.
893 * @sk_getsecid:
894 * Retrieve the LSM-specific secid for the sock to enable caching
895 * of network authorizations.
896 * @sock_graft:
897 * Sets the socket's isec sid to the sock's sid.
898 * @inet_conn_request:
899 * Sets the openreq's sid to socket's sid with MLS portion taken
900 * from peer sid.
901 * @inet_csk_clone:
902 * Sets the new child socket's sid to the openreq sid.
903 * @inet_conn_established:
904 * Sets the connection's peersid to the secmark on skb.
905 * @secmark_relabel_packet:
906 * check if the process should be allowed to relabel packets to
907 * the given secid
908 * @security_secmark_refcount_inc
909 * tells the LSM to increment the number of secmark labeling rules loaded
910 * @security_secmark_refcount_dec
911 * tells the LSM to decrement the number of secmark labeling rules loaded
912 * @req_classify_flow:
913 * Sets the flow's sid to the openreq sid.
914 * @tun_dev_alloc_security:
915 * This hook allows a module to allocate a security structure for a TUN
916 * device.
917 * @security pointer to a security structure pointer.
918 * Returns a zero on success, negative values on failure.
919 * @tun_dev_free_security:
920 * This hook allows a module to free the security structure for a TUN
921 * device.
922 * @security pointer to the TUN device's security structure
923 * @tun_dev_create:
924 * Check permissions prior to creating a new TUN device.
925 * @tun_dev_attach_queue:
926 * Check permissions prior to attaching to a TUN device queue.
927 * @security pointer to the TUN device's security structure.
928 * @tun_dev_attach:
929 * This hook can be used by the module to update any security state
930 * associated with the TUN device's sock structure.
931 * @sk contains the existing sock structure.
932 * @security pointer to the TUN device's security structure.
933 * @tun_dev_open:
934 * This hook can be used by the module to update any security state
935 * associated with the TUN device's security structure.
936 * @security pointer to the TUN devices's security structure.
937 *
Richard Haines72e89f52018-02-13 20:53:21 +0000938 * Security hooks for SCTP
939 *
940 * @sctp_assoc_request:
941 * Passes the @ep and @chunk->skb of the association INIT packet to
942 * the security module.
943 * @ep pointer to sctp endpoint structure.
944 * @skb pointer to skbuff of association packet.
945 * Return 0 on success, error on failure.
946 * @sctp_bind_connect:
947 * Validiate permissions required for each address associated with sock
948 * @sk. Depending on @optname, the addresses will be treated as either
949 * for a connect or bind service. The @addrlen is calculated on each
950 * ipv4 and ipv6 address using sizeof(struct sockaddr_in) or
951 * sizeof(struct sockaddr_in6).
952 * @sk pointer to sock structure.
953 * @optname name of the option to validate.
954 * @address list containing one or more ipv4/ipv6 addresses.
955 * @addrlen total length of address(s).
956 * Return 0 on success, error on failure.
957 * @sctp_sk_clone:
958 * Called whenever a new socket is created by accept(2) (i.e. a TCP
959 * style socket) or when a socket is 'peeled off' e.g userspace
960 * calls sctp_peeloff(3).
961 * @ep pointer to current sctp endpoint structure.
962 * @sk pointer to current sock structure.
963 * @sk pointer to new sock structure.
964 *
Daniel Jurgensd291f1a2017-05-19 15:48:52 +0300965 * Security hooks for Infiniband
966 *
967 * @ib_pkey_access:
968 * Check permission to access a pkey when modifing a QP.
969 * @subnet_prefix the subnet prefix of the port being used.
970 * @pkey the pkey to be accessed.
971 * @sec pointer to a security structure.
Daniel Jurgens47a2b332017-05-19 15:48:54 +0300972 * @ib_endport_manage_subnet:
973 * Check permissions to send and receive SMPs on a end port.
974 * @dev_name the IB device name (i.e. mlx4_0).
975 * @port_num the port number.
976 * @sec pointer to a security structure.
Daniel Jurgensd291f1a2017-05-19 15:48:52 +0300977 * @ib_alloc_security:
978 * Allocate a security structure for Infiniband objects.
979 * @sec pointer to a security structure pointer.
980 * Returns 0 on success, non-zero on failure
981 * @ib_free_security:
982 * Deallocate an Infiniband security structure.
983 * @sec contains the security structure to be freed.
984 *
Casey Schauflerfe7bb272015-05-02 15:10:53 -0700985 * Security hooks for XFRM operations.
986 *
987 * @xfrm_policy_alloc_security:
988 * @ctxp is a pointer to the xfrm_sec_ctx being added to Security Policy
989 * Database used by the XFRM system.
990 * @sec_ctx contains the security context information being provided by
991 * the user-level policy update program (e.g., setkey).
992 * Allocate a security structure to the xp->security field; the security
993 * field is initialized to NULL when the xfrm_policy is allocated.
994 * Return 0 if operation was successful (memory to allocate, legal context)
995 * @gfp is to specify the context for the allocation
996 * @xfrm_policy_clone_security:
997 * @old_ctx contains an existing xfrm_sec_ctx.
998 * @new_ctxp contains a new xfrm_sec_ctx being cloned from old.
999 * Allocate a security structure in new_ctxp that contains the
1000 * information from the old_ctx structure.
1001 * Return 0 if operation was successful (memory to allocate).
1002 * @xfrm_policy_free_security:
1003 * @ctx contains the xfrm_sec_ctx
1004 * Deallocate xp->security.
1005 * @xfrm_policy_delete_security:
1006 * @ctx contains the xfrm_sec_ctx.
1007 * Authorize deletion of xp->security.
1008 * @xfrm_state_alloc:
1009 * @x contains the xfrm_state being added to the Security Association
1010 * Database by the XFRM system.
1011 * @sec_ctx contains the security context information being provided by
1012 * the user-level SA generation program (e.g., setkey or racoon).
1013 * Allocate a security structure to the x->security field; the security
1014 * field is initialized to NULL when the xfrm_state is allocated. Set the
1015 * context to correspond to sec_ctx. Return 0 if operation was successful
1016 * (memory to allocate, legal context).
1017 * @xfrm_state_alloc_acquire:
1018 * @x contains the xfrm_state being added to the Security Association
1019 * Database by the XFRM system.
1020 * @polsec contains the policy's security context.
1021 * @secid contains the secid from which to take the mls portion of the
1022 * context.
1023 * Allocate a security structure to the x->security field; the security
1024 * field is initialized to NULL when the xfrm_state is allocated. Set the
1025 * context to correspond to secid. Return 0 if operation was successful
1026 * (memory to allocate, legal context).
1027 * @xfrm_state_free_security:
1028 * @x contains the xfrm_state.
1029 * Deallocate x->security.
1030 * @xfrm_state_delete_security:
1031 * @x contains the xfrm_state.
1032 * Authorize deletion of x->security.
1033 * @xfrm_policy_lookup:
1034 * @ctx contains the xfrm_sec_ctx for which the access control is being
1035 * checked.
1036 * @fl_secid contains the flow security label that is used to authorize
1037 * access to the policy xp.
1038 * @dir contains the direction of the flow (input or output).
1039 * Check permission when a flow selects a xfrm_policy for processing
1040 * XFRMs on a packet. The hook is called when selecting either a
1041 * per-socket policy or a generic xfrm policy.
1042 * Return 0 if permission is granted, -ESRCH otherwise, or -errno
1043 * on other errors.
1044 * @xfrm_state_pol_flow_match:
1045 * @x contains the state to match.
1046 * @xp contains the policy to check for a match.
1047 * @fl contains the flow to check for a match.
1048 * Return 1 if there is a match.
1049 * @xfrm_decode_session:
1050 * @skb points to skb to decode.
1051 * @secid points to the flow key secid to set.
1052 * @ckall says if all xfrms used should be checked for same secid.
1053 * Return 0 if ckall is zero or all xfrms used have the same secid.
1054 *
1055 * Security hooks affecting all Key Management operations
1056 *
1057 * @key_alloc:
1058 * Permit allocation of a key and assign security data. Note that key does
1059 * not have a serial number assigned at this point.
1060 * @key points to the key.
1061 * @flags is the allocation flags
1062 * Return 0 if permission is granted, -ve error otherwise.
1063 * @key_free:
1064 * Notification of destruction; free security data.
1065 * @key points to the key.
1066 * No return value.
1067 * @key_permission:
1068 * See whether a specific operational right is granted to a process on a
1069 * key.
1070 * @key_ref refers to the key (key pointer + possession attribute bit).
1071 * @cred points to the credentials to provide the context against which to
1072 * evaluate the security data on the key.
1073 * @perm describes the combination of permissions required of this key.
1074 * Return 0 if permission is granted, -ve error otherwise.
1075 * @key_getsecurity:
1076 * Get a textual representation of the security context attached to a key
1077 * for the purposes of honouring KEYCTL_GETSECURITY. This function
1078 * allocates the storage for the NUL-terminated string and the caller
1079 * should free it.
1080 * @key points to the key to be queried.
1081 * @_buffer points to a pointer that should be set to point to the
1082 * resulting string (if no label or an error occurs).
1083 * Return the length of the string (including terminating NUL) or -ve if
1084 * an error.
1085 * May also return 0 (and a NULL buffer pointer) if there is no label.
1086 *
1087 * Security hooks affecting all System V IPC operations.
1088 *
1089 * @ipc_permission:
1090 * Check permissions for access to IPC
1091 * @ipcp contains the kernel IPC permission structure
1092 * @flag contains the desired (requested) permission set
1093 * Return 0 if permission is granted.
1094 * @ipc_getsecid:
1095 * Get the secid associated with the ipc object.
1096 * @ipcp contains the kernel IPC permission structure.
1097 * @secid contains a pointer to the location where result will be saved.
1098 * In case of failure, @secid will be set to zero.
1099 *
1100 * Security hooks for individual messages held in System V IPC message queues
1101 * @msg_msg_alloc_security:
1102 * Allocate and attach a security structure to the msg->security field.
1103 * The security field is initialized to NULL when the structure is first
1104 * created.
1105 * @msg contains the message structure to be modified.
1106 * Return 0 if operation was successful and permission is granted.
1107 * @msg_msg_free_security:
1108 * Deallocate the security structure for this message.
1109 * @msg contains the message structure to be modified.
1110 *
1111 * Security hooks for System V IPC Message Queues
1112 *
1113 * @msg_queue_alloc_security:
1114 * Allocate and attach a security structure to the
1115 * msq->q_perm.security field. The security field is initialized to
1116 * NULL when the structure is first created.
1117 * @msq contains the message queue structure to be modified.
1118 * Return 0 if operation was successful and permission is granted.
1119 * @msg_queue_free_security:
1120 * Deallocate security structure for this message queue.
1121 * @msq contains the message queue structure to be modified.
1122 * @msg_queue_associate:
1123 * Check permission when a message queue is requested through the
1124 * msgget system call. This hook is only called when returning the
1125 * message queue identifier for an existing message queue, not when a
1126 * new message queue is created.
1127 * @msq contains the message queue to act upon.
1128 * @msqflg contains the operation control flags.
1129 * Return 0 if permission is granted.
1130 * @msg_queue_msgctl:
1131 * Check permission when a message control operation specified by @cmd
1132 * is to be performed on the message queue @msq.
1133 * The @msq may be NULL, e.g. for IPC_INFO or MSG_INFO.
1134 * @msq contains the message queue to act upon. May be NULL.
1135 * @cmd contains the operation to be performed.
1136 * Return 0 if permission is granted.
1137 * @msg_queue_msgsnd:
1138 * Check permission before a message, @msg, is enqueued on the message
1139 * queue, @msq.
1140 * @msq contains the message queue to send message to.
1141 * @msg contains the message to be enqueued.
1142 * @msqflg contains operational flags.
1143 * Return 0 if permission is granted.
1144 * @msg_queue_msgrcv:
1145 * Check permission before a message, @msg, is removed from the message
1146 * queue, @msq. The @target task structure contains a pointer to the
1147 * process that will be receiving the message (not equal to the current
1148 * process when inline receives are being performed).
1149 * @msq contains the message queue to retrieve message from.
1150 * @msg contains the message destination.
1151 * @target contains the task structure for recipient process.
1152 * @type contains the type of message requested.
1153 * @mode contains the operational flags.
1154 * Return 0 if permission is granted.
1155 *
1156 * Security hooks for System V Shared Memory Segments
1157 *
1158 * @shm_alloc_security:
1159 * Allocate and attach a security structure to the shp->shm_perm.security
1160 * field. The security field is initialized to NULL when the structure is
1161 * first created.
1162 * @shp contains the shared memory structure to be modified.
1163 * Return 0 if operation was successful and permission is granted.
1164 * @shm_free_security:
1165 * Deallocate the security struct for this memory segment.
1166 * @shp contains the shared memory structure to be modified.
1167 * @shm_associate:
1168 * Check permission when a shared memory region is requested through the
1169 * shmget system call. This hook is only called when returning the shared
1170 * memory region identifier for an existing region, not when a new shared
1171 * memory region is created.
1172 * @shp contains the shared memory structure to be modified.
1173 * @shmflg contains the operation control flags.
1174 * Return 0 if permission is granted.
1175 * @shm_shmctl:
1176 * Check permission when a shared memory control operation specified by
1177 * @cmd is to be performed on the shared memory region @shp.
1178 * The @shp may be NULL, e.g. for IPC_INFO or SHM_INFO.
1179 * @shp contains shared memory structure to be modified.
1180 * @cmd contains the operation to be performed.
1181 * Return 0 if permission is granted.
1182 * @shm_shmat:
1183 * Check permissions prior to allowing the shmat system call to attach the
1184 * shared memory segment @shp to the data segment of the calling process.
1185 * The attaching address is specified by @shmaddr.
1186 * @shp contains the shared memory structure to be modified.
1187 * @shmaddr contains the address to attach memory region to.
1188 * @shmflg contains the operational flags.
1189 * Return 0 if permission is granted.
1190 *
1191 * Security hooks for System V Semaphores
1192 *
1193 * @sem_alloc_security:
1194 * Allocate and attach a security structure to the sma->sem_perm.security
1195 * field. The security field is initialized to NULL when the structure is
1196 * first created.
1197 * @sma contains the semaphore structure
1198 * Return 0 if operation was successful and permission is granted.
1199 * @sem_free_security:
1200 * deallocate security struct for this semaphore
1201 * @sma contains the semaphore structure.
1202 * @sem_associate:
1203 * Check permission when a semaphore is requested through the semget
1204 * system call. This hook is only called when returning the semaphore
1205 * identifier for an existing semaphore, not when a new one must be
1206 * created.
1207 * @sma contains the semaphore structure.
1208 * @semflg contains the operation control flags.
1209 * Return 0 if permission is granted.
1210 * @sem_semctl:
1211 * Check permission when a semaphore operation specified by @cmd is to be
1212 * performed on the semaphore @sma. The @sma may be NULL, e.g. for
1213 * IPC_INFO or SEM_INFO.
1214 * @sma contains the semaphore structure. May be NULL.
1215 * @cmd contains the operation to be performed.
1216 * Return 0 if permission is granted.
Kees Cookf00f85a2017-05-13 04:51:42 -07001217 * @sem_semop:
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001218 * Check permissions before performing operations on members of the
1219 * semaphore set @sma. If the @alter flag is nonzero, the semaphore set
1220 * may be modified.
1221 * @sma contains the semaphore structure.
1222 * @sops contains the operations to perform.
1223 * @nsops contains the number of operations to perform.
1224 * @alter contains the flag indicating whether changes are to be made.
1225 * Return 0 if permission is granted.
1226 *
Kees Cookf00f85a2017-05-13 04:51:42 -07001227 * @binder_set_context_mgr:
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001228 * Check whether @mgr is allowed to be the binder context manager.
1229 * @mgr contains the task_struct for the task being registered.
1230 * Return 0 if permission is granted.
Kees Cookf00f85a2017-05-13 04:51:42 -07001231 * @binder_transaction:
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001232 * Check whether @from is allowed to invoke a binder transaction call
1233 * to @to.
1234 * @from contains the task_struct for the sending task.
1235 * @to contains the task_struct for the receiving task.
Kees Cookf00f85a2017-05-13 04:51:42 -07001236 * @binder_transfer_binder:
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001237 * Check whether @from is allowed to transfer a binder reference to @to.
1238 * @from contains the task_struct for the sending task.
1239 * @to contains the task_struct for the receiving task.
Kees Cookf00f85a2017-05-13 04:51:42 -07001240 * @binder_transfer_file:
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001241 * Check whether @from is allowed to transfer @file to @to.
1242 * @from contains the task_struct for the sending task.
1243 * @file contains the struct file being transferred.
1244 * @to contains the task_struct for the receiving task.
1245 *
1246 * @ptrace_access_check:
1247 * Check permission before allowing the current process to trace the
1248 * @child process.
1249 * Security modules may also want to perform a process tracing check
1250 * during an execve in the set_security or apply_creds hooks of
1251 * tracing check during an execve in the bprm_set_creds hook of
1252 * binprm_security_ops if the process is being traced and its security
1253 * attributes would be changed by the execve.
1254 * @child contains the task_struct structure for the target process.
1255 * @mode contains the PTRACE_MODE flags indicating the form of access.
1256 * Return 0 if permission is granted.
1257 * @ptrace_traceme:
1258 * Check that the @parent process has sufficient permission to trace the
1259 * current process before allowing the current process to present itself
1260 * to the @parent process for tracing.
1261 * @parent contains the task_struct structure for debugger process.
1262 * Return 0 if permission is granted.
1263 * @capget:
1264 * Get the @effective, @inheritable, and @permitted capability sets for
1265 * the @target process. The hook may also perform permission checking to
1266 * determine if the current process is allowed to see the capability sets
1267 * of the @target process.
1268 * @target contains the task_struct structure for target process.
1269 * @effective contains the effective capability set.
1270 * @inheritable contains the inheritable capability set.
1271 * @permitted contains the permitted capability set.
1272 * Return 0 if the capability sets were successfully obtained.
1273 * @capset:
1274 * Set the @effective, @inheritable, and @permitted capability sets for
1275 * the current process.
1276 * @new contains the new credentials structure for target process.
1277 * @old contains the current credentials structure for target process.
1278 * @effective contains the effective capability set.
1279 * @inheritable contains the inheritable capability set.
1280 * @permitted contains the permitted capability set.
1281 * Return 0 and update @new if permission is granted.
1282 * @capable:
1283 * Check whether the @tsk process has the @cap capability in the indicated
1284 * credentials.
1285 * @cred contains the credentials to use.
1286 * @ns contains the user namespace we want the capability in
1287 * @cap contains the capability <include/linux/capability.h>.
Micah Mortonc1a85a02019-01-07 16:10:53 -08001288 * @opts contains options for the capable check <include/linux/security.h>
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001289 * Return 0 if the capability is granted for @tsk.
1290 * @syslog:
1291 * Check permission before accessing the kernel message ring or changing
1292 * logging to the console.
1293 * See the syslog(2) manual page for an explanation of the @type values.
Denis Efremov5f4b9752019-02-26 23:49:03 +03001294 * @type contains the SYSLOG_ACTION_* constant from <include/linux/syslog.h>
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001295 * Return 0 if permission is granted.
1296 * @settime:
1297 * Check permission to change the system time.
Baolin Wang457db292016-04-08 14:02:11 +08001298 * struct timespec64 is defined in include/linux/time64.h and timezone
1299 * is defined in include/linux/time.h
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001300 * @ts contains new time
1301 * @tz contains new timezone
1302 * Return 0 if permission is granted.
1303 * @vm_enough_memory:
1304 * Check permissions for allocating a new virtual mapping.
1305 * @mm contains the mm struct it is being added to.
1306 * @pages contains the number of pages.
1307 * Return 0 if permission is granted.
1308 *
1309 * @ismaclabel:
1310 * Check if the extended attribute specified by @name
1311 * represents a MAC label. Returns 1 if name is a MAC
1312 * attribute otherwise returns 0.
1313 * @name full extended attribute name to check against
1314 * LSM as a MAC label.
1315 *
1316 * @secid_to_secctx:
1317 * Convert secid to security context. If secdata is NULL the length of
1318 * the result will be returned in seclen, but no secdata will be returned.
1319 * This does mean that the length could change between calls to check the
1320 * length and the next call which actually allocates and returns the
1321 * secdata.
1322 * @secid contains the security ID.
1323 * @secdata contains the pointer that stores the converted security
1324 * context.
1325 * @seclen pointer which contains the length of the data
1326 * @secctx_to_secid:
1327 * Convert security context to secid.
1328 * @secid contains the pointer to the generated security ID.
1329 * @secdata contains the security context.
1330 *
1331 * @release_secctx:
1332 * Release the security context.
1333 * @secdata contains the security context.
1334 * @seclen contains the length of the security context.
1335 *
1336 * Security hooks for Audit
1337 *
1338 * @audit_rule_init:
1339 * Allocate and initialize an LSM audit rule structure.
1340 * @field contains the required Audit action.
1341 * Fields flags are defined in include/linux/audit.h
1342 * @op contains the operator the rule uses.
1343 * @rulestr contains the context where the rule will be applied to.
1344 * @lsmrule contains a pointer to receive the result.
1345 * Return 0 if @lsmrule has been successfully set,
1346 * -EINVAL in case of an invalid rule.
1347 *
1348 * @audit_rule_known:
1349 * Specifies whether given @rule contains any fields related to
1350 * current LSM.
1351 * @rule contains the audit rule of interest.
1352 * Return 1 in case of relation found, 0 otherwise.
1353 *
1354 * @audit_rule_match:
1355 * Determine if given @secid matches a rule previously approved
1356 * by @audit_rule_known.
1357 * @secid contains the security id in question.
1358 * @field contains the field which relates to current LSM.
1359 * @op contains the operator that will be used for matching.
1360 * @rule points to the audit rule that will be checked against.
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001361 * Return 1 if secid matches the rule, 0 if it does not, -ERRNO on failure.
1362 *
1363 * @audit_rule_free:
1364 * Deallocate the LSM audit rule structure previously allocated by
1365 * audit_rule_init.
1366 * @rule contains the allocated rule
1367 *
Andreas Gruenbacher6f3be9f2015-12-24 11:09:40 -05001368 * @inode_invalidate_secctx:
1369 * Notify the security module that it must revalidate the security context
1370 * of an inode.
1371 *
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001372 * @inode_notifysecctx:
1373 * Notify the security module of what the security context of an inode
1374 * should be. Initializes the incore security context managed by the
1375 * security module for this inode. Example usage: NFS client invokes
1376 * this hook to initialize the security context in its incore inode to the
1377 * value provided by the server for the file when the server returned the
1378 * file's attributes to the client.
1379 *
1380 * Must be called with inode->i_mutex locked.
1381 *
1382 * @inode we wish to set the security context of.
1383 * @ctx contains the string which we wish to set in the inode.
1384 * @ctxlen contains the length of @ctx.
1385 *
1386 * @inode_setsecctx:
1387 * Change the security context of an inode. Updates the
1388 * incore security context managed by the security module and invokes the
1389 * fs code as needed (via __vfs_setxattr_noperm) to update any backing
1390 * xattrs that represent the context. Example usage: NFS server invokes
1391 * this hook to change the security context in its incore inode and on the
1392 * backing filesystem to a value provided by the client on a SETATTR
1393 * operation.
1394 *
1395 * Must be called with inode->i_mutex locked.
1396 *
1397 * @dentry contains the inode we wish to set the security context of.
1398 * @ctx contains the string which we wish to set in the inode.
1399 * @ctxlen contains the length of @ctx.
1400 *
1401 * @inode_getsecctx:
1402 * On success, returns 0 and fills out @ctx and @ctxlen with the security
1403 * context for the given @inode.
1404 *
1405 * @inode we wish to get the security context of.
1406 * @ctx is a pointer in which to place the allocated security context.
1407 * @ctxlen points to the place to put the length of @ctx.
Chenbo Fengafdb09c2017-10-18 13:00:24 -07001408 *
1409 * Security hooks for using the eBPF maps and programs functionalities through
1410 * eBPF syscalls.
1411 *
1412 * @bpf:
1413 * Do a initial check for all bpf syscalls after the attribute is copied
1414 * into the kernel. The actual security module can implement their own
1415 * rules to check the specific cmd they need.
1416 *
1417 * @bpf_map:
1418 * Do a check when the kernel generate and return a file descriptor for
1419 * eBPF maps.
1420 *
1421 * @map: bpf map that we want to access
1422 * @mask: the access flags
1423 *
1424 * @bpf_prog:
1425 * Do a check when the kernel generate and return a file descriptor for
1426 * eBPF programs.
1427 *
1428 * @prog: bpf prog that userspace want to use.
1429 *
1430 * @bpf_map_alloc_security:
1431 * Initialize the security field inside bpf map.
1432 *
1433 * @bpf_map_free_security:
1434 * Clean up the security information stored inside bpf map.
1435 *
1436 * @bpf_prog_alloc_security:
1437 * Initialize the security field inside bpf program.
1438 *
1439 * @bpf_prog_free_security:
1440 * Clean up the security information stored inside bpf prog.
1441 *
Casey Schauflerfe7bb272015-05-02 15:10:53 -07001442 */
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001443union security_list_options {
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001444 int (*binder_set_context_mgr)(struct task_struct *mgr);
1445 int (*binder_transaction)(struct task_struct *from,
1446 struct task_struct *to);
1447 int (*binder_transfer_binder)(struct task_struct *from,
1448 struct task_struct *to);
1449 int (*binder_transfer_file)(struct task_struct *from,
1450 struct task_struct *to,
1451 struct file *file);
1452
1453 int (*ptrace_access_check)(struct task_struct *child,
1454 unsigned int mode);
1455 int (*ptrace_traceme)(struct task_struct *parent);
1456 int (*capget)(struct task_struct *target, kernel_cap_t *effective,
1457 kernel_cap_t *inheritable, kernel_cap_t *permitted);
1458 int (*capset)(struct cred *new, const struct cred *old,
1459 const kernel_cap_t *effective,
1460 const kernel_cap_t *inheritable,
1461 const kernel_cap_t *permitted);
Micah Mortonc1a85a02019-01-07 16:10:53 -08001462 int (*capable)(const struct cred *cred,
1463 struct user_namespace *ns,
1464 int cap,
1465 unsigned int opts);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001466 int (*quotactl)(int cmds, int type, int id, struct super_block *sb);
1467 int (*quota_on)(struct dentry *dentry);
1468 int (*syslog)(int type);
Baolin Wang457db292016-04-08 14:02:11 +08001469 int (*settime)(const struct timespec64 *ts, const struct timezone *tz);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001470 int (*vm_enough_memory)(struct mm_struct *mm, long pages);
1471
1472 int (*bprm_set_creds)(struct linux_binprm *bprm);
1473 int (*bprm_check_security)(struct linux_binprm *bprm);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001474 void (*bprm_committing_creds)(struct linux_binprm *bprm);
1475 void (*bprm_committed_creds)(struct linux_binprm *bprm);
1476
Al Viro0b520752018-12-23 16:02:47 -05001477 int (*fs_context_dup)(struct fs_context *fc, struct fs_context *src_sc);
David Howellsda2441f2018-11-01 23:07:24 +00001478 int (*fs_context_parse_param)(struct fs_context *fc, struct fs_parameter *param);
1479
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001480 int (*sb_alloc_security)(struct super_block *sb);
1481 void (*sb_free_security)(struct super_block *sb);
Al Viro204cc0c2018-12-13 13:41:47 -05001482 void (*sb_free_mnt_opts)(void *mnt_opts);
1483 int (*sb_eat_lsm_opts)(char *orig, void **mnt_opts);
1484 int (*sb_remount)(struct super_block *sb, void *mnt_opts);
Al Viroa10d7c22018-12-05 11:58:35 -05001485 int (*sb_kern_mount)(struct super_block *sb);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001486 int (*sb_show_options)(struct seq_file *m, struct super_block *sb);
1487 int (*sb_statfs)(struct dentry *dentry);
Al Viro8a04c432016-03-25 14:52:53 -04001488 int (*sb_mount)(const char *dev_name, const struct path *path,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001489 const char *type, unsigned long flags, void *data);
1490 int (*sb_umount)(struct vfsmount *mnt, int flags);
Al Viro3b73b682016-03-25 15:31:19 -04001491 int (*sb_pivotroot)(const struct path *old_path, const struct path *new_path);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001492 int (*sb_set_mnt_opts)(struct super_block *sb,
Al Viro204cc0c2018-12-13 13:41:47 -05001493 void *mnt_opts,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001494 unsigned long kern_flags,
1495 unsigned long *set_kern_flags);
1496 int (*sb_clone_mnt_opts)(const struct super_block *oldsb,
Scott Mayhew0b4d3452017-06-05 11:45:04 -04001497 struct super_block *newsb,
1498 unsigned long kern_flags,
1499 unsigned long *set_kern_flags);
Al Viro757cbe52018-12-14 23:42:21 -05001500 int (*sb_add_mnt_opt)(const char *option, const char *val, int len,
1501 void **mnt_opts);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001502 int (*dentry_init_security)(struct dentry *dentry, int mode,
Al Viro4f3ccd72016-07-20 16:06:15 -04001503 const struct qstr *name, void **ctx,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001504 u32 *ctxlen);
Vivek Goyal26026252016-07-13 10:44:52 -04001505 int (*dentry_create_files_as)(struct dentry *dentry, int mode,
1506 struct qstr *name,
1507 const struct cred *old,
1508 struct cred *new);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001509
1510
1511#ifdef CONFIG_SECURITY_PATH
Al Viro989f74e2016-03-25 15:13:39 -04001512 int (*path_unlink)(const struct path *dir, struct dentry *dentry);
Al Virod3607752016-03-25 15:21:09 -04001513 int (*path_mkdir)(const struct path *dir, struct dentry *dentry,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001514 umode_t mode);
Al Viro989f74e2016-03-25 15:13:39 -04001515 int (*path_rmdir)(const struct path *dir, struct dentry *dentry);
Al Virod3607752016-03-25 15:21:09 -04001516 int (*path_mknod)(const struct path *dir, struct dentry *dentry,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001517 umode_t mode, unsigned int dev);
Al Viro81f4c502016-03-25 14:22:01 -04001518 int (*path_truncate)(const struct path *path);
Al Virod3607752016-03-25 15:21:09 -04001519 int (*path_symlink)(const struct path *dir, struct dentry *dentry,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001520 const char *old_name);
Al Viro3ccee462016-03-25 15:27:45 -04001521 int (*path_link)(struct dentry *old_dentry, const struct path *new_dir,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001522 struct dentry *new_dentry);
Al Viro3ccee462016-03-25 15:27:45 -04001523 int (*path_rename)(const struct path *old_dir, struct dentry *old_dentry,
1524 const struct path *new_dir,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001525 struct dentry *new_dentry);
Al Virobe01f9f2016-03-25 14:56:23 -04001526 int (*path_chmod)(const struct path *path, umode_t mode);
Al Viro7fd25da2016-03-25 14:44:41 -04001527 int (*path_chown)(const struct path *path, kuid_t uid, kgid_t gid);
Al Viro77b286c2016-03-25 15:28:43 -04001528 int (*path_chroot)(const struct path *path);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001529#endif
1530
1531 int (*inode_alloc_security)(struct inode *inode);
1532 void (*inode_free_security)(struct inode *inode);
1533 int (*inode_init_security)(struct inode *inode, struct inode *dir,
1534 const struct qstr *qstr,
1535 const char **name, void **value,
1536 size_t *len);
1537 int (*inode_create)(struct inode *dir, struct dentry *dentry,
1538 umode_t mode);
1539 int (*inode_link)(struct dentry *old_dentry, struct inode *dir,
1540 struct dentry *new_dentry);
1541 int (*inode_unlink)(struct inode *dir, struct dentry *dentry);
1542 int (*inode_symlink)(struct inode *dir, struct dentry *dentry,
1543 const char *old_name);
1544 int (*inode_mkdir)(struct inode *dir, struct dentry *dentry,
1545 umode_t mode);
1546 int (*inode_rmdir)(struct inode *dir, struct dentry *dentry);
1547 int (*inode_mknod)(struct inode *dir, struct dentry *dentry,
1548 umode_t mode, dev_t dev);
1549 int (*inode_rename)(struct inode *old_dir, struct dentry *old_dentry,
1550 struct inode *new_dir,
1551 struct dentry *new_dentry);
1552 int (*inode_readlink)(struct dentry *dentry);
Linus Torvaldse22619a2015-06-27 13:26:03 -07001553 int (*inode_follow_link)(struct dentry *dentry, struct inode *inode,
1554 bool rcu);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001555 int (*inode_permission)(struct inode *inode, int mask);
1556 int (*inode_setattr)(struct dentry *dentry, struct iattr *attr);
1557 int (*inode_getattr)(const struct path *path);
1558 int (*inode_setxattr)(struct dentry *dentry, const char *name,
1559 const void *value, size_t size, int flags);
1560 void (*inode_post_setxattr)(struct dentry *dentry, const char *name,
1561 const void *value, size_t size,
1562 int flags);
1563 int (*inode_getxattr)(struct dentry *dentry, const char *name);
1564 int (*inode_listxattr)(struct dentry *dentry);
1565 int (*inode_removexattr)(struct dentry *dentry, const char *name);
1566 int (*inode_need_killpriv)(struct dentry *dentry);
1567 int (*inode_killpriv)(struct dentry *dentry);
Andreas Gruenbacherea861df2015-12-24 11:09:39 -05001568 int (*inode_getsecurity)(struct inode *inode, const char *name,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001569 void **buffer, bool alloc);
1570 int (*inode_setsecurity)(struct inode *inode, const char *name,
1571 const void *value, size_t size,
1572 int flags);
1573 int (*inode_listsecurity)(struct inode *inode, char *buffer,
1574 size_t buffer_size);
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -05001575 void (*inode_getsecid)(struct inode *inode, u32 *secid);
Vivek Goyald8ad8b42016-07-13 11:13:56 -04001576 int (*inode_copy_up)(struct dentry *src, struct cred **new);
Vivek Goyal121ab822016-07-13 10:44:49 -04001577 int (*inode_copy_up_xattr)(const char *name);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001578
1579 int (*file_permission)(struct file *file, int mask);
1580 int (*file_alloc_security)(struct file *file);
1581 void (*file_free_security)(struct file *file);
1582 int (*file_ioctl)(struct file *file, unsigned int cmd,
1583 unsigned long arg);
1584 int (*mmap_addr)(unsigned long addr);
1585 int (*mmap_file)(struct file *file, unsigned long reqprot,
1586 unsigned long prot, unsigned long flags);
1587 int (*file_mprotect)(struct vm_area_struct *vma, unsigned long reqprot,
1588 unsigned long prot);
1589 int (*file_lock)(struct file *file, unsigned int cmd);
1590 int (*file_fcntl)(struct file *file, unsigned int cmd,
1591 unsigned long arg);
1592 void (*file_set_fowner)(struct file *file);
1593 int (*file_send_sigiotask)(struct task_struct *tsk,
1594 struct fown_struct *fown, int sig);
1595 int (*file_receive)(struct file *file);
Al Viro94817692018-07-10 14:13:18 -04001596 int (*file_open)(struct file *file);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001597
Tetsuo Handae4e55b42017-03-24 20:46:33 +09001598 int (*task_alloc)(struct task_struct *task, unsigned long clone_flags);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001599 void (*task_free)(struct task_struct *task);
1600 int (*cred_alloc_blank)(struct cred *cred, gfp_t gfp);
1601 void (*cred_free)(struct cred *cred);
1602 int (*cred_prepare)(struct cred *new, const struct cred *old,
1603 gfp_t gfp);
1604 void (*cred_transfer)(struct cred *new, const struct cred *old);
Matthew Garrett3ec30112018-01-08 13:36:19 -08001605 void (*cred_getsecid)(const struct cred *c, u32 *secid);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001606 int (*kernel_act_as)(struct cred *new, u32 secid);
1607 int (*kernel_create_files_as)(struct cred *new, struct inode *inode);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001608 int (*kernel_module_request)(char *kmod_name);
Mimi Zohar377179c2018-07-13 14:05:56 -04001609 int (*kernel_load_data)(enum kernel_load_data_id id);
Mimi Zohar39eeb4f2016-01-30 22:23:26 -05001610 int (*kernel_read_file)(struct file *file, enum kernel_read_file_id id);
Mimi Zoharbc8ca5b2016-01-24 10:07:32 -05001611 int (*kernel_post_read_file)(struct file *file, char *buf, loff_t size,
1612 enum kernel_read_file_id id);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001613 int (*task_fix_setuid)(struct cred *new, const struct cred *old,
1614 int flags);
1615 int (*task_setpgid)(struct task_struct *p, pid_t pgid);
1616 int (*task_getpgid)(struct task_struct *p);
1617 int (*task_getsid)(struct task_struct *p);
1618 void (*task_getsecid)(struct task_struct *p, u32 *secid);
1619 int (*task_setnice)(struct task_struct *p, int nice);
1620 int (*task_setioprio)(struct task_struct *p, int ioprio);
1621 int (*task_getioprio)(struct task_struct *p);
Stephen Smalley791ec492017-02-17 07:57:00 -05001622 int (*task_prlimit)(const struct cred *cred, const struct cred *tcred,
1623 unsigned int flags);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001624 int (*task_setrlimit)(struct task_struct *p, unsigned int resource,
1625 struct rlimit *new_rlim);
1626 int (*task_setscheduler)(struct task_struct *p);
1627 int (*task_getscheduler)(struct task_struct *p);
1628 int (*task_movememory)(struct task_struct *p);
Eric W. Biedermanae7795b2018-09-25 11:27:20 +02001629 int (*task_kill)(struct task_struct *p, struct kernel_siginfo *info,
Stephen Smalley6b4f3d02017-09-08 12:40:01 -04001630 int sig, const struct cred *cred);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001631 int (*task_prctl)(int option, unsigned long arg2, unsigned long arg3,
1632 unsigned long arg4, unsigned long arg5);
1633 void (*task_to_inode)(struct task_struct *p, struct inode *inode);
1634
1635 int (*ipc_permission)(struct kern_ipc_perm *ipcp, short flag);
1636 void (*ipc_getsecid)(struct kern_ipc_perm *ipcp, u32 *secid);
1637
1638 int (*msg_msg_alloc_security)(struct msg_msg *msg);
1639 void (*msg_msg_free_security)(struct msg_msg *msg);
1640
Eric W. Biedermand8c6e852018-03-22 21:22:26 -05001641 int (*msg_queue_alloc_security)(struct kern_ipc_perm *msq);
1642 void (*msg_queue_free_security)(struct kern_ipc_perm *msq);
1643 int (*msg_queue_associate)(struct kern_ipc_perm *msq, int msqflg);
1644 int (*msg_queue_msgctl)(struct kern_ipc_perm *msq, int cmd);
1645 int (*msg_queue_msgsnd)(struct kern_ipc_perm *msq, struct msg_msg *msg,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001646 int msqflg);
Eric W. Biedermand8c6e852018-03-22 21:22:26 -05001647 int (*msg_queue_msgrcv)(struct kern_ipc_perm *msq, struct msg_msg *msg,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001648 struct task_struct *target, long type,
1649 int mode);
1650
Eric W. Biederman7191adf2018-03-22 21:08:27 -05001651 int (*shm_alloc_security)(struct kern_ipc_perm *shp);
1652 void (*shm_free_security)(struct kern_ipc_perm *shp);
1653 int (*shm_associate)(struct kern_ipc_perm *shp, int shmflg);
1654 int (*shm_shmctl)(struct kern_ipc_perm *shp, int cmd);
1655 int (*shm_shmat)(struct kern_ipc_perm *shp, char __user *shmaddr,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001656 int shmflg);
1657
Eric W. Biedermanaefad952018-03-22 20:52:43 -05001658 int (*sem_alloc_security)(struct kern_ipc_perm *sma);
1659 void (*sem_free_security)(struct kern_ipc_perm *sma);
1660 int (*sem_associate)(struct kern_ipc_perm *sma, int semflg);
1661 int (*sem_semctl)(struct kern_ipc_perm *sma, int cmd);
1662 int (*sem_semop)(struct kern_ipc_perm *sma, struct sembuf *sops,
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001663 unsigned nsops, int alter);
1664
1665 int (*netlink_send)(struct sock *sk, struct sk_buff *skb);
1666
1667 void (*d_instantiate)(struct dentry *dentry, struct inode *inode);
1668
1669 int (*getprocattr)(struct task_struct *p, char *name, char **value);
Stephen Smalleyb21507e2017-01-09 10:07:31 -05001670 int (*setprocattr)(const char *name, void *value, size_t size);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001671 int (*ismaclabel)(const char *name);
1672 int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
1673 int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid);
1674 void (*release_secctx)(char *secdata, u32 seclen);
1675
Andreas Gruenbacher6f3be9f2015-12-24 11:09:40 -05001676 void (*inode_invalidate_secctx)(struct inode *inode);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001677 int (*inode_notifysecctx)(struct inode *inode, void *ctx, u32 ctxlen);
1678 int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen);
1679 int (*inode_getsecctx)(struct inode *inode, void **ctx, u32 *ctxlen);
1680
1681#ifdef CONFIG_SECURITY_NETWORK
1682 int (*unix_stream_connect)(struct sock *sock, struct sock *other,
1683 struct sock *newsk);
1684 int (*unix_may_send)(struct socket *sock, struct socket *other);
1685
1686 int (*socket_create)(int family, int type, int protocol, int kern);
1687 int (*socket_post_create)(struct socket *sock, int family, int type,
1688 int protocol, int kern);
David Herrmannaae7cfc2018-05-04 16:28:19 +02001689 int (*socket_socketpair)(struct socket *socka, struct socket *sockb);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001690 int (*socket_bind)(struct socket *sock, struct sockaddr *address,
1691 int addrlen);
1692 int (*socket_connect)(struct socket *sock, struct sockaddr *address,
1693 int addrlen);
1694 int (*socket_listen)(struct socket *sock, int backlog);
1695 int (*socket_accept)(struct socket *sock, struct socket *newsock);
1696 int (*socket_sendmsg)(struct socket *sock, struct msghdr *msg,
1697 int size);
1698 int (*socket_recvmsg)(struct socket *sock, struct msghdr *msg,
1699 int size, int flags);
1700 int (*socket_getsockname)(struct socket *sock);
1701 int (*socket_getpeername)(struct socket *sock);
1702 int (*socket_getsockopt)(struct socket *sock, int level, int optname);
1703 int (*socket_setsockopt)(struct socket *sock, int level, int optname);
1704 int (*socket_shutdown)(struct socket *sock, int how);
1705 int (*socket_sock_rcv_skb)(struct sock *sk, struct sk_buff *skb);
1706 int (*socket_getpeersec_stream)(struct socket *sock,
1707 char __user *optval,
1708 int __user *optlen, unsigned len);
1709 int (*socket_getpeersec_dgram)(struct socket *sock,
1710 struct sk_buff *skb, u32 *secid);
1711 int (*sk_alloc_security)(struct sock *sk, int family, gfp_t priority);
1712 void (*sk_free_security)(struct sock *sk);
1713 void (*sk_clone_security)(const struct sock *sk, struct sock *newsk);
1714 void (*sk_getsecid)(struct sock *sk, u32 *secid);
1715 void (*sock_graft)(struct sock *sk, struct socket *parent);
1716 int (*inet_conn_request)(struct sock *sk, struct sk_buff *skb,
1717 struct request_sock *req);
1718 void (*inet_csk_clone)(struct sock *newsk,
1719 const struct request_sock *req);
1720 void (*inet_conn_established)(struct sock *sk, struct sk_buff *skb);
1721 int (*secmark_relabel_packet)(u32 secid);
1722 void (*secmark_refcount_inc)(void);
1723 void (*secmark_refcount_dec)(void);
1724 void (*req_classify_flow)(const struct request_sock *req,
1725 struct flowi *fl);
1726 int (*tun_dev_alloc_security)(void **security);
1727 void (*tun_dev_free_security)(void *security);
1728 int (*tun_dev_create)(void);
1729 int (*tun_dev_attach_queue)(void *security);
1730 int (*tun_dev_attach)(struct sock *sk, void *security);
1731 int (*tun_dev_open)(void *security);
Richard Haines72e89f52018-02-13 20:53:21 +00001732 int (*sctp_assoc_request)(struct sctp_endpoint *ep,
1733 struct sk_buff *skb);
1734 int (*sctp_bind_connect)(struct sock *sk, int optname,
1735 struct sockaddr *address, int addrlen);
1736 void (*sctp_sk_clone)(struct sctp_endpoint *ep, struct sock *sk,
1737 struct sock *newsk);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001738#endif /* CONFIG_SECURITY_NETWORK */
1739
Daniel Jurgensd291f1a2017-05-19 15:48:52 +03001740#ifdef CONFIG_SECURITY_INFINIBAND
1741 int (*ib_pkey_access)(void *sec, u64 subnet_prefix, u16 pkey);
Daniel Jurgens47a2b332017-05-19 15:48:54 +03001742 int (*ib_endport_manage_subnet)(void *sec, const char *dev_name,
1743 u8 port_num);
Daniel Jurgensd291f1a2017-05-19 15:48:52 +03001744 int (*ib_alloc_security)(void **sec);
1745 void (*ib_free_security)(void *sec);
1746#endif /* CONFIG_SECURITY_INFINIBAND */
1747
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001748#ifdef CONFIG_SECURITY_NETWORK_XFRM
1749 int (*xfrm_policy_alloc_security)(struct xfrm_sec_ctx **ctxp,
1750 struct xfrm_user_sec_ctx *sec_ctx,
1751 gfp_t gfp);
1752 int (*xfrm_policy_clone_security)(struct xfrm_sec_ctx *old_ctx,
1753 struct xfrm_sec_ctx **new_ctx);
1754 void (*xfrm_policy_free_security)(struct xfrm_sec_ctx *ctx);
1755 int (*xfrm_policy_delete_security)(struct xfrm_sec_ctx *ctx);
1756 int (*xfrm_state_alloc)(struct xfrm_state *x,
1757 struct xfrm_user_sec_ctx *sec_ctx);
1758 int (*xfrm_state_alloc_acquire)(struct xfrm_state *x,
1759 struct xfrm_sec_ctx *polsec,
1760 u32 secid);
1761 void (*xfrm_state_free_security)(struct xfrm_state *x);
1762 int (*xfrm_state_delete_security)(struct xfrm_state *x);
1763 int (*xfrm_policy_lookup)(struct xfrm_sec_ctx *ctx, u32 fl_secid,
1764 u8 dir);
1765 int (*xfrm_state_pol_flow_match)(struct xfrm_state *x,
1766 struct xfrm_policy *xp,
1767 const struct flowi *fl);
1768 int (*xfrm_decode_session)(struct sk_buff *skb, u32 *secid, int ckall);
1769#endif /* CONFIG_SECURITY_NETWORK_XFRM */
1770
1771 /* key management security hooks */
1772#ifdef CONFIG_KEYS
1773 int (*key_alloc)(struct key *key, const struct cred *cred,
1774 unsigned long flags);
1775 void (*key_free)(struct key *key);
1776 int (*key_permission)(key_ref_t key_ref, const struct cred *cred,
1777 unsigned perm);
1778 int (*key_getsecurity)(struct key *key, char **_buffer);
1779#endif /* CONFIG_KEYS */
1780
1781#ifdef CONFIG_AUDIT
1782 int (*audit_rule_init)(u32 field, u32 op, char *rulestr,
1783 void **lsmrule);
1784 int (*audit_rule_known)(struct audit_krule *krule);
Richard Guy Briggs90462a52019-01-31 11:52:11 -05001785 int (*audit_rule_match)(u32 secid, u32 field, u32 op, void *lsmrule);
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001786 void (*audit_rule_free)(void *lsmrule);
1787#endif /* CONFIG_AUDIT */
Chenbo Fengafdb09c2017-10-18 13:00:24 -07001788
1789#ifdef CONFIG_BPF_SYSCALL
1790 int (*bpf)(int cmd, union bpf_attr *attr,
1791 unsigned int size);
1792 int (*bpf_map)(struct bpf_map *map, fmode_t fmode);
1793 int (*bpf_prog)(struct bpf_prog *prog);
1794 int (*bpf_map_alloc_security)(struct bpf_map *map);
1795 void (*bpf_map_free_security)(struct bpf_map *map);
1796 int (*bpf_prog_alloc_security)(struct bpf_prog_aux *aux);
1797 void (*bpf_prog_free_security)(struct bpf_prog_aux *aux);
1798#endif /* CONFIG_BPF_SYSCALL */
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07001799};
1800
Casey Schauflere20b0432015-05-02 15:11:36 -07001801struct security_hook_heads {
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001802 struct hlist_head binder_set_context_mgr;
1803 struct hlist_head binder_transaction;
1804 struct hlist_head binder_transfer_binder;
1805 struct hlist_head binder_transfer_file;
1806 struct hlist_head ptrace_access_check;
1807 struct hlist_head ptrace_traceme;
1808 struct hlist_head capget;
1809 struct hlist_head capset;
1810 struct hlist_head capable;
1811 struct hlist_head quotactl;
1812 struct hlist_head quota_on;
1813 struct hlist_head syslog;
1814 struct hlist_head settime;
1815 struct hlist_head vm_enough_memory;
1816 struct hlist_head bprm_set_creds;
1817 struct hlist_head bprm_check_security;
1818 struct hlist_head bprm_committing_creds;
1819 struct hlist_head bprm_committed_creds;
Al Viro0b520752018-12-23 16:02:47 -05001820 struct hlist_head fs_context_dup;
David Howellsda2441f2018-11-01 23:07:24 +00001821 struct hlist_head fs_context_parse_param;
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001822 struct hlist_head sb_alloc_security;
1823 struct hlist_head sb_free_security;
Al Viro204cc0c2018-12-13 13:41:47 -05001824 struct hlist_head sb_free_mnt_opts;
Al Viro5b400232018-12-12 20:13:29 -05001825 struct hlist_head sb_eat_lsm_opts;
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001826 struct hlist_head sb_remount;
1827 struct hlist_head sb_kern_mount;
1828 struct hlist_head sb_show_options;
1829 struct hlist_head sb_statfs;
1830 struct hlist_head sb_mount;
1831 struct hlist_head sb_umount;
1832 struct hlist_head sb_pivotroot;
1833 struct hlist_head sb_set_mnt_opts;
1834 struct hlist_head sb_clone_mnt_opts;
Al Viro757cbe52018-12-14 23:42:21 -05001835 struct hlist_head sb_add_mnt_opt;
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001836 struct hlist_head dentry_init_security;
1837 struct hlist_head dentry_create_files_as;
Casey Schauflere20b0432015-05-02 15:11:36 -07001838#ifdef CONFIG_SECURITY_PATH
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001839 struct hlist_head path_unlink;
1840 struct hlist_head path_mkdir;
1841 struct hlist_head path_rmdir;
1842 struct hlist_head path_mknod;
1843 struct hlist_head path_truncate;
1844 struct hlist_head path_symlink;
1845 struct hlist_head path_link;
1846 struct hlist_head path_rename;
1847 struct hlist_head path_chmod;
1848 struct hlist_head path_chown;
1849 struct hlist_head path_chroot;
Casey Schauflere20b0432015-05-02 15:11:36 -07001850#endif
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001851 struct hlist_head inode_alloc_security;
1852 struct hlist_head inode_free_security;
1853 struct hlist_head inode_init_security;
1854 struct hlist_head inode_create;
1855 struct hlist_head inode_link;
1856 struct hlist_head inode_unlink;
1857 struct hlist_head inode_symlink;
1858 struct hlist_head inode_mkdir;
1859 struct hlist_head inode_rmdir;
1860 struct hlist_head inode_mknod;
1861 struct hlist_head inode_rename;
1862 struct hlist_head inode_readlink;
1863 struct hlist_head inode_follow_link;
1864 struct hlist_head inode_permission;
1865 struct hlist_head inode_setattr;
1866 struct hlist_head inode_getattr;
1867 struct hlist_head inode_setxattr;
1868 struct hlist_head inode_post_setxattr;
1869 struct hlist_head inode_getxattr;
1870 struct hlist_head inode_listxattr;
1871 struct hlist_head inode_removexattr;
1872 struct hlist_head inode_need_killpriv;
1873 struct hlist_head inode_killpriv;
1874 struct hlist_head inode_getsecurity;
1875 struct hlist_head inode_setsecurity;
1876 struct hlist_head inode_listsecurity;
1877 struct hlist_head inode_getsecid;
1878 struct hlist_head inode_copy_up;
1879 struct hlist_head inode_copy_up_xattr;
1880 struct hlist_head file_permission;
1881 struct hlist_head file_alloc_security;
1882 struct hlist_head file_free_security;
1883 struct hlist_head file_ioctl;
1884 struct hlist_head mmap_addr;
1885 struct hlist_head mmap_file;
1886 struct hlist_head file_mprotect;
1887 struct hlist_head file_lock;
1888 struct hlist_head file_fcntl;
1889 struct hlist_head file_set_fowner;
1890 struct hlist_head file_send_sigiotask;
1891 struct hlist_head file_receive;
1892 struct hlist_head file_open;
1893 struct hlist_head task_alloc;
1894 struct hlist_head task_free;
1895 struct hlist_head cred_alloc_blank;
1896 struct hlist_head cred_free;
1897 struct hlist_head cred_prepare;
1898 struct hlist_head cred_transfer;
Linus Torvaldsf8cf2f12018-04-07 16:53:59 -07001899 struct hlist_head cred_getsecid;
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001900 struct hlist_head kernel_act_as;
1901 struct hlist_head kernel_create_files_as;
Mimi Zohar377179c2018-07-13 14:05:56 -04001902 struct hlist_head kernel_load_data;
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001903 struct hlist_head kernel_read_file;
1904 struct hlist_head kernel_post_read_file;
1905 struct hlist_head kernel_module_request;
1906 struct hlist_head task_fix_setuid;
1907 struct hlist_head task_setpgid;
1908 struct hlist_head task_getpgid;
1909 struct hlist_head task_getsid;
1910 struct hlist_head task_getsecid;
1911 struct hlist_head task_setnice;
1912 struct hlist_head task_setioprio;
1913 struct hlist_head task_getioprio;
1914 struct hlist_head task_prlimit;
1915 struct hlist_head task_setrlimit;
1916 struct hlist_head task_setscheduler;
1917 struct hlist_head task_getscheduler;
1918 struct hlist_head task_movememory;
1919 struct hlist_head task_kill;
1920 struct hlist_head task_prctl;
1921 struct hlist_head task_to_inode;
1922 struct hlist_head ipc_permission;
1923 struct hlist_head ipc_getsecid;
1924 struct hlist_head msg_msg_alloc_security;
1925 struct hlist_head msg_msg_free_security;
1926 struct hlist_head msg_queue_alloc_security;
1927 struct hlist_head msg_queue_free_security;
1928 struct hlist_head msg_queue_associate;
1929 struct hlist_head msg_queue_msgctl;
1930 struct hlist_head msg_queue_msgsnd;
1931 struct hlist_head msg_queue_msgrcv;
1932 struct hlist_head shm_alloc_security;
1933 struct hlist_head shm_free_security;
1934 struct hlist_head shm_associate;
1935 struct hlist_head shm_shmctl;
1936 struct hlist_head shm_shmat;
1937 struct hlist_head sem_alloc_security;
1938 struct hlist_head sem_free_security;
1939 struct hlist_head sem_associate;
1940 struct hlist_head sem_semctl;
1941 struct hlist_head sem_semop;
1942 struct hlist_head netlink_send;
1943 struct hlist_head d_instantiate;
1944 struct hlist_head getprocattr;
1945 struct hlist_head setprocattr;
1946 struct hlist_head ismaclabel;
1947 struct hlist_head secid_to_secctx;
1948 struct hlist_head secctx_to_secid;
1949 struct hlist_head release_secctx;
1950 struct hlist_head inode_invalidate_secctx;
1951 struct hlist_head inode_notifysecctx;
1952 struct hlist_head inode_setsecctx;
1953 struct hlist_head inode_getsecctx;
Casey Schauflere20b0432015-05-02 15:11:36 -07001954#ifdef CONFIG_SECURITY_NETWORK
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001955 struct hlist_head unix_stream_connect;
1956 struct hlist_head unix_may_send;
1957 struct hlist_head socket_create;
1958 struct hlist_head socket_post_create;
David Herrmannaae7cfc2018-05-04 16:28:19 +02001959 struct hlist_head socket_socketpair;
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001960 struct hlist_head socket_bind;
1961 struct hlist_head socket_connect;
1962 struct hlist_head socket_listen;
1963 struct hlist_head socket_accept;
1964 struct hlist_head socket_sendmsg;
1965 struct hlist_head socket_recvmsg;
1966 struct hlist_head socket_getsockname;
1967 struct hlist_head socket_getpeername;
1968 struct hlist_head socket_getsockopt;
1969 struct hlist_head socket_setsockopt;
1970 struct hlist_head socket_shutdown;
1971 struct hlist_head socket_sock_rcv_skb;
1972 struct hlist_head socket_getpeersec_stream;
1973 struct hlist_head socket_getpeersec_dgram;
1974 struct hlist_head sk_alloc_security;
1975 struct hlist_head sk_free_security;
1976 struct hlist_head sk_clone_security;
1977 struct hlist_head sk_getsecid;
1978 struct hlist_head sock_graft;
1979 struct hlist_head inet_conn_request;
1980 struct hlist_head inet_csk_clone;
1981 struct hlist_head inet_conn_established;
1982 struct hlist_head secmark_relabel_packet;
1983 struct hlist_head secmark_refcount_inc;
1984 struct hlist_head secmark_refcount_dec;
1985 struct hlist_head req_classify_flow;
1986 struct hlist_head tun_dev_alloc_security;
1987 struct hlist_head tun_dev_free_security;
1988 struct hlist_head tun_dev_create;
1989 struct hlist_head tun_dev_attach_queue;
1990 struct hlist_head tun_dev_attach;
1991 struct hlist_head tun_dev_open;
Linus Torvalds36126052018-04-07 11:11:41 -07001992 struct hlist_head sctp_assoc_request;
1993 struct hlist_head sctp_bind_connect;
1994 struct hlist_head sctp_sk_clone;
Casey Schauflere20b0432015-05-02 15:11:36 -07001995#endif /* CONFIG_SECURITY_NETWORK */
Daniel Jurgensd291f1a2017-05-19 15:48:52 +03001996#ifdef CONFIG_SECURITY_INFINIBAND
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001997 struct hlist_head ib_pkey_access;
1998 struct hlist_head ib_endport_manage_subnet;
1999 struct hlist_head ib_alloc_security;
2000 struct hlist_head ib_free_security;
Daniel Jurgensd291f1a2017-05-19 15:48:52 +03002001#endif /* CONFIG_SECURITY_INFINIBAND */
Casey Schauflere20b0432015-05-02 15:11:36 -07002002#ifdef CONFIG_SECURITY_NETWORK_XFRM
Sargun Dhillondf0ce172018-03-29 01:28:23 +00002003 struct hlist_head xfrm_policy_alloc_security;
2004 struct hlist_head xfrm_policy_clone_security;
2005 struct hlist_head xfrm_policy_free_security;
2006 struct hlist_head xfrm_policy_delete_security;
2007 struct hlist_head xfrm_state_alloc;
2008 struct hlist_head xfrm_state_alloc_acquire;
2009 struct hlist_head xfrm_state_free_security;
2010 struct hlist_head xfrm_state_delete_security;
2011 struct hlist_head xfrm_policy_lookup;
2012 struct hlist_head xfrm_state_pol_flow_match;
2013 struct hlist_head xfrm_decode_session;
Casey Schauflere20b0432015-05-02 15:11:36 -07002014#endif /* CONFIG_SECURITY_NETWORK_XFRM */
2015#ifdef CONFIG_KEYS
Sargun Dhillondf0ce172018-03-29 01:28:23 +00002016 struct hlist_head key_alloc;
2017 struct hlist_head key_free;
2018 struct hlist_head key_permission;
2019 struct hlist_head key_getsecurity;
Casey Schauflere20b0432015-05-02 15:11:36 -07002020#endif /* CONFIG_KEYS */
2021#ifdef CONFIG_AUDIT
Sargun Dhillondf0ce172018-03-29 01:28:23 +00002022 struct hlist_head audit_rule_init;
2023 struct hlist_head audit_rule_known;
2024 struct hlist_head audit_rule_match;
2025 struct hlist_head audit_rule_free;
Casey Schauflere20b0432015-05-02 15:11:36 -07002026#endif /* CONFIG_AUDIT */
Chenbo Fengafdb09c2017-10-18 13:00:24 -07002027#ifdef CONFIG_BPF_SYSCALL
Sargun Dhillondf0ce172018-03-29 01:28:23 +00002028 struct hlist_head bpf;
2029 struct hlist_head bpf_map;
2030 struct hlist_head bpf_prog;
2031 struct hlist_head bpf_map_alloc_security;
2032 struct hlist_head bpf_map_free_security;
2033 struct hlist_head bpf_prog_alloc_security;
2034 struct hlist_head bpf_prog_free_security;
Chenbo Fengafdb09c2017-10-18 13:00:24 -07002035#endif /* CONFIG_BPF_SYSCALL */
Kees Cook3859a272016-10-28 01:22:25 -07002036} __randomize_layout;
Casey Schauflere20b0432015-05-02 15:11:36 -07002037
2038/*
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002039 * Security module hook list structure.
2040 * For use with generic list macros for common operations.
2041 */
2042struct security_hook_list {
Sargun Dhillondf0ce172018-03-29 01:28:23 +00002043 struct hlist_node list;
2044 struct hlist_head *head;
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002045 union security_list_options hook;
Casey Schauflerd69dece52017-01-18 17:09:05 -08002046 char *lsm;
Kees Cook3859a272016-10-28 01:22:25 -07002047} __randomize_layout;
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002048
2049/*
Casey Schauflerbbd36622018-11-12 09:30:56 -08002050 * Security blob size or offset data.
2051 */
2052struct lsm_blob_sizes {
2053 int lbs_cred;
Casey Schaufler33bf60c2018-11-12 12:02:49 -08002054 int lbs_file;
Casey Schauflerafb1cbe32018-09-21 17:19:29 -07002055 int lbs_inode;
Casey Schauflerecd5f822018-11-20 11:55:02 -08002056 int lbs_ipc;
2057 int lbs_msg_msg;
Casey Schauflerf4ad8f22018-09-21 17:19:37 -07002058 int lbs_task;
Casey Schauflerbbd36622018-11-12 09:30:56 -08002059};
2060
2061/*
Casey Schauflere20b0432015-05-02 15:11:36 -07002062 * Initializing a security_hook_list structure takes
2063 * up a lot of space in a source file. This macro takes
2064 * care of the common case and reduces the amount of
2065 * text involved.
Casey Schauflere20b0432015-05-02 15:11:36 -07002066 */
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002067#define LSM_HOOK_INIT(HEAD, HOOK) \
2068 { .head = &security_hook_heads.HEAD, .hook = { .HEAD = HOOK } }
Casey Schauflere20b0432015-05-02 15:11:36 -07002069
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002070extern struct security_hook_heads security_hook_heads;
Casey Schauflerd69dece52017-01-18 17:09:05 -08002071extern char *lsm_names;
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07002072
Casey Schauflerd69dece52017-01-18 17:09:05 -08002073extern void security_add_hooks(struct security_hook_list *hooks, int count,
2074 char *lsm);
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002075
Kees Cook47008e52018-09-19 16:13:25 -07002076#define LSM_FLAG_LEGACY_MAJOR BIT(0)
Kees Cook14bd99c2018-09-19 19:57:06 -07002077#define LSM_FLAG_EXCLUSIVE BIT(1)
Kees Cook47008e52018-09-19 16:13:25 -07002078
Kees Cooke2bc4452018-09-19 17:48:21 -07002079enum lsm_order {
2080 LSM_ORDER_FIRST = -1, /* This is only for capabilities. */
2081 LSM_ORDER_MUTABLE = 0,
2082};
2083
Kees Cook5b89c1b2018-10-10 17:18:21 -07002084struct lsm_info {
Kees Cook07aed2f2018-10-10 17:18:24 -07002085 const char *name; /* Required. */
Kees Cooke2bc4452018-09-19 17:48:21 -07002086 enum lsm_order order; /* Optional: default is LSM_ORDER_MUTABLE */
Kees Cook47008e52018-09-19 16:13:25 -07002087 unsigned long flags; /* Optional: flags describing LSM */
Kees Cooka8027fb2018-10-09 14:42:57 -07002088 int *enabled; /* Optional: controlled by CONFIG_LSM */
Kees Cook5b89c1b2018-10-10 17:18:21 -07002089 int (*init)(void); /* Required. */
Casey Schauflerbbd36622018-11-12 09:30:56 -08002090 struct lsm_blob_sizes *blobs; /* Optional: for blob sharing. */
Kees Cook5b89c1b2018-10-10 17:18:21 -07002091};
2092
2093extern struct lsm_info __start_lsm_info[], __end_lsm_info[];
2094
Kees Cook3d6e5f62018-10-10 17:18:23 -07002095#define DEFINE_LSM(lsm) \
Kees Cook5b89c1b2018-10-10 17:18:21 -07002096 static struct lsm_info __lsm_##lsm \
2097 __used __section(.lsm_info.init) \
Kees Cook3d6e5f62018-10-10 17:18:23 -07002098 __aligned(sizeof(unsigned long))
Kees Cook5b89c1b2018-10-10 17:18:21 -07002099
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002100#ifdef CONFIG_SECURITY_SELINUX_DISABLE
2101/*
2102 * Assuring the safety of deleting a security module is up to
2103 * the security module involved. This may entail ordering the
2104 * module's hook list in a particular way, refusing to disable
2105 * the module once a policy is loaded or any number of other
2106 * actions better imagined than described.
2107 *
2108 * The name of the configuration option reflects the only module
2109 * that currently uses the mechanism. Any developer who thinks
2110 * disabling their module is a good idea needs to be at least as
2111 * careful as the SELinux team.
2112 */
2113static inline void security_delete_hooks(struct security_hook_list *hooks,
2114 int count)
2115{
2116 int i;
2117
2118 for (i = 0; i < count; i++)
Sargun Dhillondf0ce172018-03-29 01:28:23 +00002119 hlist_del_rcu(&hooks[i].list);
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002120}
2121#endif /* CONFIG_SECURITY_SELINUX_DISABLE */
2122
James Morrisdd0859d2017-02-15 00:17:24 +11002123/* Currently required to handle SELinux runtime hook disable. */
2124#ifdef CONFIG_SECURITY_WRITABLE_HOOKS
2125#define __lsm_ro_after_init
2126#else
2127#define __lsm_ro_after_init __ro_after_init
2128#endif /* CONFIG_SECURITY_WRITABLE_HOOKS */
2129
Casey Schauflerafb1cbe32018-09-21 17:19:29 -07002130extern int lsm_inode_alloc(struct inode *inode);
2131
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -07002132#endif /* ! __LINUX_LSM_HOOKS_H */