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