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