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