2 * Linux Security Module interfaces
8 * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group)
9 * Copyright (C) 2015 Intel Corporation.
11 * Copyright (C) 2016 Mellanox Techonologies
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.
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.
25 #ifndef __LINUX_LSM_HOOKS_H
26 #define __LINUX_LSM_HOOKS_H
28 #include <linux/security.h>
29 #include <linux/init.h>
30 #include <linux/rculist.h>
33 * union security_list_options - Linux Security Module hook function list
35 * Security hooks for program execution operations.
37 * @bprm_creds_for_exec:
38 * If the setup in prepare_exec_creds did not setup @bprm->cred->security
39 * properly for executing @bprm->file, update the LSM's portion of
40 * @bprm->cred->security to be what commit_creds needs to install for the
41 * new program. This hook may also optionally check permissions
42 * (e.g. for transitions between security domains).
43 * The hook must set @bprm->secureexec to 1 if AT_SECURE should be set to
44 * request libc enable secure mode.
45 * @bprm contains the linux_binprm structure.
46 * Return 0 if the hook is successful and permission is granted.
47 * @bprm_creds_from_file:
48 * If @file is setpcap, suid, sgid or otherwise marked to change
49 * privilege upon exec, update @bprm->cred to reflect that change.
50 * This is called after finding the binary that will be executed.
51 * without an interpreter. This ensures that the credentials will not
52 * be derived from a script that the binary will need to reopen, which
53 * when reopend may end up being a completely different file. This
54 * hook may also optionally check permissions (e.g. for transitions
55 * between security domains).
56 * The hook must set @bprm->secureexec to 1 if AT_SECURE should be set to
57 * request libc enable secure mode.
58 * The hook must add to @bprm->per_clear any personality flags that
59 * should be cleared from current->personality.
60 * @bprm contains the linux_binprm structure.
61 * Return 0 if the hook is successful and permission is granted.
62 * @bprm_check_security:
63 * This hook mediates the point when a search for a binary handler will
64 * begin. It allows a check against the @bprm->cred->security value
65 * which was set in the preceding creds_for_exec call. The argv list and
66 * envp list are reliably available in @bprm. This hook may be called
67 * multiple times during a single execve.
68 * @bprm contains the linux_binprm structure.
69 * Return 0 if the hook is successful and permission is granted.
70 * @bprm_committing_creds:
71 * Prepare to install the new security attributes of a process being
72 * transformed by an execve operation, based on the old credentials
73 * pointed to by @current->cred and the information set in @bprm->cred by
74 * the bprm_creds_for_exec hook. @bprm points to the linux_binprm
75 * structure. This hook is a good place to perform state changes on the
76 * process such as closing open file descriptors to which access will no
77 * longer be granted when the attributes are changed. This is called
78 * immediately before commit_creds().
79 * @bprm_committed_creds:
80 * Tidy up after the installation of the new security attributes of a
81 * process being transformed by an execve operation. The new credentials
82 * have, by this point, been set to @current->cred. @bprm points to the
83 * linux_binprm structure. This hook is a good place to perform state
84 * changes on the process such as clearing out non-inheritable signal
85 * state. This is called immediately after commit_creds().
87 * Security hooks for mount using fs_context.
88 * [See also Documentation/filesystems/mount_api.rst]
91 * Allocate and attach a security structure to sc->security. This pointer
92 * is initialised to NULL by the caller.
93 * @fc indicates the new filesystem context.
94 * @src_fc indicates the original filesystem context.
95 * @fs_context_parse_param:
96 * Userspace provided a parameter to configure a superblock. The LSM may
97 * reject it with an error and may use it for itself, in which case it
98 * should return 0; otherwise it should return -ENOPARAM to pass it on to
100 * @fc indicates the filesystem context.
101 * @param The parameter
103 * Security hooks for filesystem operations.
105 * @sb_alloc_security:
106 * Allocate and attach a security structure to the sb->s_security field.
107 * The s_security field is initialized to NULL when the structure is
109 * @sb contains the super_block structure to be modified.
110 * Return 0 if operation was successful.
112 * Release objects tied to a superblock (e.g. inodes).
113 * @sb contains the super_block structure being released.
115 * Deallocate and clear the sb->s_security field.
116 * @sb contains the super_block structure to be modified.
118 * Free memory associated with @mnt_ops.
120 * Eat (scan @orig options) and save them in @mnt_opts.
122 * Check permission before obtaining filesystem statistics for the @mnt
124 * @dentry is a handle on the superblock for the filesystem.
125 * Return 0 if permission is granted.
127 * Check permission before an object specified by @dev_name is mounted on
128 * the mount point named by @nd. For an ordinary mount, @dev_name
129 * identifies a device if the file system type requires a device. For a
130 * remount (@flags & MS_REMOUNT), @dev_name is irrelevant. For a
131 * loopback/bind mount (@flags & MS_BIND), @dev_name identifies the
132 * pathname of the object being mounted.
133 * @dev_name contains the name for object being mounted.
134 * @path contains the path for mount point object.
135 * @type contains the filesystem type.
136 * @flags contains the mount flags.
137 * @data contains the filesystem-specific data.
138 * Return 0 if permission is granted.
140 * Allow mount option data to be copied prior to parsing by the filesystem,
141 * so that the security module can extract security-specific mount
142 * options cleanly (a filesystem may modify the data e.g. with strsep()).
143 * This also allows the original mount data to be stripped of security-
144 * specific options to avoid having to make filesystems aware of them.
145 * @orig the original mount data copied from userspace.
146 * @copy copied data which will be passed to the security module.
147 * Returns 0 if the copy was successful.
148 * @sb_mnt_opts_compat:
149 * Determine if the new mount options in @mnt_opts are allowed given
150 * the existing mounted filesystem at @sb.
151 * @sb superblock being compared
152 * @mnt_opts new mount options
153 * Return 0 if options are compatible.
155 * Extracts security system specific mount options and verifies no changes
156 * are being made to those options.
157 * @sb superblock being remounted
158 * @data contains the filesystem-specific data.
159 * Return 0 if permission is granted.
161 * Mount this @sb if allowed by permissions.
163 * Show (print on @m) mount options for this @sb.
165 * Check permission before the @mnt file system is unmounted.
166 * @mnt contains the mounted file system.
167 * @flags contains the unmount flags, e.g. MNT_FORCE.
168 * Return 0 if permission is granted.
170 * Check permission before pivoting the root filesystem.
171 * @old_path contains the path for the new location of the
172 * current root (put_old).
173 * @new_path contains the path for the new root (new_root).
174 * Return 0 if permission is granted.
176 * Set the security relevant mount options used for a superblock
177 * @sb the superblock to set security mount options for
178 * @opts binary data structure containing all lsm mount data
179 * @sb_clone_mnt_opts:
180 * Copy all security options from a given superblock to another
181 * @oldsb old superblock which contain information to clone
182 * @newsb new superblock which needs filled in
183 * @sb_parse_opts_str:
184 * Parse a string of security data filling in the opts structure
185 * @options string containing all mount options known by the LSM
186 * @opts binary data structure usable by the LSM
188 * Check permission before a mount is moved.
189 * @from_path indicates the mount that is going to be moved.
190 * @to_path indicates the mountpoint that will be mounted upon.
191 * @dentry_init_security:
192 * Compute a context for a dentry as the inode is not yet available
193 * since NFSv4 has no label backed by an EA anyway.
194 * @dentry dentry to use in calculating the context.
195 * @mode mode used to determine resource type.
196 * @name name of the last path component used to create file
197 * @xattr_name pointer to place the pointer to security xattr name.
198 * Caller does not have to free the resulting pointer. Its
199 * a pointer to static string.
200 * @ctx pointer to place the pointer to the resulting context in.
201 * @ctxlen point to place the length of the resulting context.
202 * @dentry_create_files_as:
203 * Compute a context for a dentry as the inode is not yet available
204 * and set that context in passed in creds so that new files are
205 * created using that context. Context is calculated using the
206 * passed in creds and not the creds of the caller.
207 * @dentry dentry to use in calculating the context.
208 * @mode mode used to determine resource type.
209 * @name name of the last path component used to create file
210 * @old creds which should be used for context calculation
211 * @new creds to modify
214 * Security hooks for inode operations.
216 * @inode_alloc_security:
217 * Allocate and attach a security structure to @inode->i_security. The
218 * i_security field is initialized to NULL when the inode structure is
220 * @inode contains the inode structure.
221 * Return 0 if operation was successful.
222 * @inode_free_security:
223 * @inode contains the inode structure.
224 * Deallocate the inode security structure and set @inode->i_security to
226 * @inode_init_security:
227 * Obtain the security attribute name suffix and value to set on a newly
228 * created inode and set up the incore security field for the new inode.
229 * This hook is called by the fs code as part of the inode creation
230 * transaction and provides for atomic labeling of the inode, unlike
231 * the post_create/mkdir/... hooks called by the VFS. The hook function
232 * is expected to allocate the name and value via kmalloc, with the caller
233 * being responsible for calling kfree after using them.
234 * If the security module does not use security attributes or does
235 * not wish to put a security attribute on this particular inode,
236 * then it should return -EOPNOTSUPP to skip this processing.
237 * @inode contains the inode structure of the newly created inode.
238 * @dir contains the inode structure of the parent directory.
239 * @qstr contains the last path component of the new object
240 * @name will be set to the allocated name suffix (e.g. selinux).
241 * @value will be set to the allocated attribute value.
242 * @len will be set to the length of the value.
243 * Returns 0 if @name and @value have been successfully set,
244 * -EOPNOTSUPP if no security attribute is needed, or
245 * -ENOMEM on memory allocation failure.
246 * @inode_init_security_anon:
247 * Set up the incore security field for the new anonymous inode
248 * and return whether the inode creation is permitted by the security
250 * @inode contains the inode structure
251 * @name name of the anonymous inode class
252 * @context_inode optional related inode
253 * Returns 0 on success, -EACCES if the security module denies the
254 * creation of this inode, or another -errno upon other errors.
256 * Check permission to create a regular file.
257 * @dir contains inode structure of the parent of the new file.
258 * @dentry contains the dentry structure for the file to be created.
259 * @mode contains the file mode of the file to be created.
260 * Return 0 if permission is granted.
262 * Check permission before creating a new hard link to a file.
263 * @old_dentry contains the dentry structure for an existing
265 * @dir contains the inode structure of the parent directory
267 * @new_dentry contains the dentry structure for the new link.
268 * Return 0 if permission is granted.
270 * Check permission before creating a new hard link to a file.
271 * @old_dentry contains the dentry structure for an existing link
273 * @new_dir contains the path structure of the parent directory of
275 * @new_dentry contains the dentry structure for the new link.
276 * Return 0 if permission is granted.
278 * Check the permission to remove a hard link to a file.
279 * @dir contains the inode structure of parent directory of the file.
280 * @dentry contains the dentry structure for file to be unlinked.
281 * Return 0 if permission is granted.
283 * Check the permission to remove a hard link to a file.
284 * @dir contains the path structure of parent directory of the file.
285 * @dentry contains the dentry structure for file to be unlinked.
286 * Return 0 if permission is granted.
288 * Check the permission to create a symbolic link to a file.
289 * @dir contains the inode structure of parent directory of
291 * @dentry contains the dentry structure of the symbolic link.
292 * @old_name contains the pathname of file.
293 * Return 0 if permission is granted.
295 * Check the permission to create a symbolic link to a file.
296 * @dir contains the path structure of parent directory of
298 * @dentry contains the dentry structure of the symbolic link.
299 * @old_name contains the pathname of file.
300 * Return 0 if permission is granted.
302 * Check permissions to create a new directory in the existing directory
303 * associated with inode structure @dir.
304 * @dir contains the inode structure of parent of the directory
306 * @dentry contains the dentry structure of new directory.
307 * @mode contains the mode of new directory.
308 * Return 0 if permission is granted.
310 * Check permissions to create a new directory in the existing directory
311 * associated with path structure @path.
312 * @dir contains the path structure of parent of the directory
314 * @dentry contains the dentry structure of new directory.
315 * @mode contains the mode of new directory.
316 * Return 0 if permission is granted.
318 * Check the permission to remove a directory.
319 * @dir contains the inode structure of parent of the directory
321 * @dentry contains the dentry structure of directory to be removed.
322 * Return 0 if permission is granted.
324 * Check the permission to remove a directory.
325 * @dir contains the path structure of parent of the directory to be
327 * @dentry contains the dentry structure of directory to be removed.
328 * Return 0 if permission is granted.
330 * Check permissions when creating a special file (or a socket or a fifo
331 * file created via the mknod system call). Note that if mknod operation
332 * is being done for a regular file, then the create hook will be called
334 * @dir contains the inode structure of parent of the new file.
335 * @dentry contains the dentry structure of the new file.
336 * @mode contains the mode of the new file.
337 * @dev contains the device number.
338 * Return 0 if permission is granted.
340 * Check permissions when creating a file. Note that this hook is called
341 * even if mknod operation is being done for a regular file.
342 * @dir contains the path structure of parent of the new file.
343 * @dentry contains the dentry structure of the new file.
344 * @mode contains the mode of the new file.
345 * @dev contains the undecoded device number. Use new_decode_dev() to get
346 * the decoded device number.
347 * Return 0 if permission is granted.
349 * Check for permission to rename a file or directory.
350 * @old_dir contains the inode structure for parent of the old link.
351 * @old_dentry contains the dentry structure of the old link.
352 * @new_dir contains the inode structure for parent of the new link.
353 * @new_dentry contains the dentry structure of the new link.
354 * Return 0 if permission is granted.
356 * Check for permission to rename a file or directory.
357 * @old_dir contains the path structure for parent of the old link.
358 * @old_dentry contains the dentry structure of the old link.
359 * @new_dir contains the path structure for parent of the new link.
360 * @new_dentry contains the dentry structure of the new link.
361 * Return 0 if permission is granted.
363 * Check for permission to change a mode of the file @path. The new
364 * mode is specified in @mode.
365 * @path contains the path structure of the file to change the mode.
366 * @mode contains the new DAC's permission, which is a bitmask of
367 * constants from <include/uapi/linux/stat.h>
368 * Return 0 if permission is granted.
370 * Check for permission to change owner/group of a file or directory.
371 * @path contains the path structure.
372 * @uid contains new owner's ID.
373 * @gid contains new group's ID.
374 * Return 0 if permission is granted.
376 * Check for permission to change root directory.
377 * @path contains the path structure.
378 * Return 0 if permission is granted.
380 * Check permissions before setting a watch on events as defined by @mask,
381 * on an object at @path, whose type is defined by @obj_type.
383 * Check the permission to read the symbolic link.
384 * @dentry contains the dentry structure for the file link.
385 * Return 0 if permission is granted.
386 * @inode_follow_link:
387 * Check permission to follow a symbolic link when looking up a pathname.
388 * @dentry contains the dentry structure for the link.
389 * @inode contains the inode, which itself is not stable in RCU-walk
390 * @rcu indicates whether we are in RCU-walk mode.
391 * Return 0 if permission is granted.
393 * Check permission before accessing an inode. This hook is called by the
394 * existing Linux permission function, so a security module can use it to
395 * provide additional checking for existing Linux permission checks.
396 * Notice that this hook is called when a file is opened (as well as many
397 * other operations), whereas the file_security_ops permission hook is
398 * called when the actual read/write operations are performed.
399 * @inode contains the inode structure to check.
400 * @mask contains the permission mask.
401 * Return 0 if permission is granted.
403 * Check permission before setting file attributes. Note that the kernel
404 * call to notify_change is performed from several locations, whenever
405 * file attributes change (such as when a file is truncated, chown/chmod
406 * operations, transferring disk quotas, etc).
407 * @dentry contains the dentry structure for the file.
408 * @attr is the iattr structure containing the new file attributes.
409 * Return 0 if permission is granted.
411 * Check permission before truncating a file.
412 * @path contains the path structure for the file.
413 * Return 0 if permission is granted.
415 * Check permission before obtaining file attributes.
416 * @path contains the path structure for the file.
417 * Return 0 if permission is granted.
419 * Check permission before setting the extended attributes
420 * @value identified by @name for @dentry.
421 * Return 0 if permission is granted.
422 * @inode_post_setxattr:
423 * Update inode security field after successful setxattr operation.
424 * @value identified by @name for @dentry.
426 * Check permission before obtaining the extended attributes
427 * identified by @name for @dentry.
428 * Return 0 if permission is granted.
430 * Check permission before obtaining the list of extended attribute
432 * Return 0 if permission is granted.
433 * @inode_removexattr:
434 * Check permission before removing the extended attribute
435 * identified by @name for @dentry.
436 * Return 0 if permission is granted.
437 * @inode_getsecurity:
438 * Retrieve a copy of the extended attribute representation of the
439 * security label associated with @name for @inode via @buffer. Note that
440 * @name is the remainder of the attribute name after the security prefix
441 * has been removed. @alloc is used to specify of the call should return a
442 * value via the buffer or just the value length Return size of buffer on
444 * @inode_setsecurity:
445 * Set the security label associated with @name for @inode from the
446 * extended attribute value @value. @size indicates the size of the
447 * @value in bytes. @flags may be XATTR_CREATE, XATTR_REPLACE, or 0.
448 * Note that @name is the remainder of the attribute name after the
449 * security. prefix has been removed.
450 * Return 0 on success.
451 * @inode_listsecurity:
452 * Copy the extended attribute names for the security labels
453 * associated with @inode into @buffer. The maximum size of @buffer
454 * is specified by @buffer_size. @buffer may be NULL to request
455 * the size of the buffer required.
456 * Returns number of bytes used/required on success.
457 * @inode_need_killpriv:
458 * Called when an inode has been changed.
459 * @dentry is the dentry being changed.
460 * Return <0 on error to abort the inode change operation.
461 * Return 0 if inode_killpriv does not need to be called.
462 * Return >0 if inode_killpriv does need to be called.
464 * The setuid bit is being removed. Remove similar security labels.
465 * Called with the dentry->d_inode->i_mutex held.
466 * @mnt_userns: user namespace of the mount
467 * @dentry is the dentry being changed.
468 * Return 0 on success. If error is returned, then the operation
469 * causing setuid bit removal is failed.
471 * Get the secid associated with the node.
472 * @inode contains a pointer to the inode.
473 * @secid contains a pointer to the location where result will be saved.
474 * In case of failure, @secid will be set to zero.
476 * A file is about to be copied up from lower layer to upper layer of
477 * overlay filesystem. Security module can prepare a set of new creds
478 * and modify as need be and return new creds. Caller will switch to
479 * new creds temporarily to create new file and release newly allocated
481 * @src indicates the union dentry of file that is being copied up.
482 * @new pointer to pointer to return newly allocated creds.
483 * Returns 0 on success or a negative error code on error.
484 * @inode_copy_up_xattr:
485 * Filter the xattrs being copied up when a unioned file is copied
486 * up from a lower layer to the union/overlay layer.
487 * @name indicates the name of the xattr.
488 * Returns 0 to accept the xattr, 1 to discard the xattr, -EOPNOTSUPP if
489 * security module does not know about attribute or a negative error code
490 * to abort the copy up. Note that the caller is responsible for reading
491 * and writing the xattrs as this hook is merely a filter.
493 * Fill in @inode security information for a @dentry if allowed.
495 * Read attribute @name for process @p and store it into @value if allowed.
497 * Write (set) attribute @name to @value, size @size if allowed.
499 * Security hooks for kernfs node operations
501 * @kernfs_init_security:
502 * Initialize the security context of a newly created kernfs node based
503 * on its own and its parent's attributes.
505 * @kn_dir the parent kernfs node
506 * @kn the new child kernfs node
508 * Security hooks for file operations
511 * Check file permissions before accessing an open file. This hook is
512 * called by various operations that read or write files. A security
513 * module can use this hook to perform additional checking on these
514 * operations, e.g. to revalidate permissions on use to support privilege
515 * bracketing or policy changes. Notice that this hook is used when the
516 * actual read/write operations are performed, whereas the
517 * inode_security_ops hook is called when a file is opened (as well as
518 * many other operations).
519 * Caveat: Although this hook can be used to revalidate permissions for
520 * various system call operations that read or write files, it does not
521 * address the revalidation of permissions for memory-mapped files.
522 * Security modules must handle this separately if they need such
524 * @file contains the file structure being accessed.
525 * @mask contains the requested permissions.
526 * Return 0 if permission is granted.
527 * @file_alloc_security:
528 * Allocate and attach a security structure to the file->f_security field.
529 * The security field is initialized to NULL when the structure is first
531 * @file contains the file structure to secure.
532 * Return 0 if the hook is successful and permission is granted.
533 * @file_free_security:
534 * Deallocate and free any security structures stored in file->f_security.
535 * @file contains the file structure being modified.
537 * @file contains the file structure.
538 * @cmd contains the operation to perform.
539 * @arg contains the operational arguments.
540 * Check permission for an ioctl operation on @file. Note that @arg
541 * sometimes represents a user space pointer; in other cases, it may be a
542 * simple integer value. When @arg represents a user space pointer, it
543 * should never be used by the security module.
544 * Return 0 if permission is granted.
546 * Check permissions for a mmap operation at @addr.
547 * @addr contains virtual address that will be used for the operation.
548 * Return 0 if permission is granted.
550 * Check permissions for a mmap operation. The @file may be NULL, e.g.
551 * if mapping anonymous memory.
552 * @file contains the file structure for file to map (may be NULL).
553 * @reqprot contains the protection requested by the application.
554 * @prot contains the protection that will be applied by the kernel.
555 * @flags contains the operational flags.
556 * Return 0 if permission is granted.
558 * Check permissions before changing memory access permissions.
559 * @vma contains the memory region to modify.
560 * @reqprot contains the protection requested by the application.
561 * @prot contains the protection that will be applied by the kernel.
562 * Return 0 if permission is granted.
564 * Check permission before performing file locking operations.
565 * Note the hook mediates both flock and fcntl style locks.
566 * @file contains the file structure.
567 * @cmd contains the posix-translated lock operation to perform
568 * (e.g. F_RDLCK, F_WRLCK).
569 * Return 0 if permission is granted.
571 * Check permission before allowing the file operation specified by @cmd
572 * from being performed on the file @file. Note that @arg sometimes
573 * represents a user space pointer; in other cases, it may be a simple
574 * integer value. When @arg represents a user space pointer, it should
575 * never be used by the security module.
576 * @file contains the file structure.
577 * @cmd contains the operation to be performed.
578 * @arg contains the operational arguments.
579 * Return 0 if permission is granted.
581 * Save owner security information (typically from current->security) in
582 * file->f_security for later use by the send_sigiotask hook.
583 * @file contains the file structure to update.
584 * Return 0 on success.
585 * @file_send_sigiotask:
586 * Check permission for the file owner @fown to send SIGIO or SIGURG to the
587 * process @tsk. Note that this hook is sometimes called from interrupt.
588 * Note that the fown_struct, @fown, is never outside the context of a
589 * struct file, so the file structure (and associated security information)
590 * can always be obtained: container_of(fown, struct file, f_owner)
591 * @tsk contains the structure of task receiving signal.
592 * @fown contains the file owner information.
593 * @sig is the signal that will be sent. When 0, kernel sends SIGIO.
594 * Return 0 if permission is granted.
596 * This hook allows security modules to control the ability of a process
597 * to receive an open file descriptor via socket IPC.
598 * @file contains the file structure being received.
599 * Return 0 if permission is granted.
601 * Save open-time permission checking state for later use upon
602 * file_permission, and recheck access if anything has changed
603 * since inode_permission.
605 * Security hooks for task operations.
608 * @task task being allocated.
609 * @clone_flags contains the flags indicating what should be shared.
610 * Handle allocation of task-related resources.
611 * Returns a zero on success, negative values on failure.
613 * @task task about to be freed.
614 * Handle release of task-related resources. (Note that this can be called
615 * from interrupt context.)
617 * @cred points to the credentials.
618 * @gfp indicates the atomicity of any memory allocations.
619 * Only allocate sufficient memory and attach to @cred such that
620 * cred_transfer() will not get ENOMEM.
622 * @cred points to the credentials.
623 * Deallocate and clear the cred->security field in a set of credentials.
625 * @new points to the new credentials.
626 * @old points to the original credentials.
627 * @gfp indicates the atomicity of any memory allocations.
628 * Prepare a new set of credentials by copying the data from the old set.
630 * @new points to the new credentials.
631 * @old points to the original credentials.
632 * Transfer data from original creds to new creds
634 * Retrieve the security identifier of the cred structure @c
635 * @c contains the credentials, secid will be placed into @secid.
636 * In case of failure, @secid will be set to zero.
638 * Set the credentials for a kernel service to act as (subjective context).
639 * @new points to the credentials to be modified.
640 * @secid specifies the security ID to be set
641 * The current task must be the one that nominated @secid.
642 * Return 0 if successful.
643 * @kernel_create_files_as:
644 * Set the file creation context in a set of credentials to be the same as
645 * the objective context of the specified inode.
646 * @new points to the credentials to be modified.
647 * @inode points to the inode to use as a reference.
648 * The current task must be the one that nominated @inode.
649 * Return 0 if successful.
650 * @kernel_module_request:
651 * Ability to trigger the kernel to automatically upcall to userspace for
652 * userspace to load a kernel module with the given name.
653 * @kmod_name name of the module requested by the kernel
654 * Return 0 if successful.
656 * Load data provided by userspace.
657 * @id kernel load data identifier
658 * @contents if a subsequent @kernel_post_load_data will be called.
659 * Return 0 if permission is granted.
660 * @kernel_post_load_data:
661 * Load data provided by a non-file source (usually userspace buffer).
662 * @buf pointer to buffer containing the data contents.
663 * @size length of the data contents.
664 * @id kernel load data identifier
665 * @description a text description of what was loaded, @id-specific
666 * Return 0 if permission is granted.
667 * This must be paired with a prior @kernel_load_data call that had
668 * @contents set to true.
670 * Read a file specified by userspace.
671 * @file contains the file structure pointing to the file being read
673 * @id kernel read file identifier
674 * @contents if a subsequent @kernel_post_read_file will be called.
675 * Return 0 if permission is granted.
676 * @kernel_post_read_file:
677 * Read a file specified by userspace.
678 * @file contains the file structure pointing to the file being read
680 * @buf pointer to buffer containing the file contents.
681 * @size length of the file contents.
682 * @id kernel read file identifier
683 * This must be paired with a prior @kernel_read_file call that had
684 * @contents set to true.
685 * Return 0 if permission is granted.
687 * Update the module's state after setting one or more of the user
688 * identity attributes of the current process. The @flags parameter
689 * indicates which of the set*uid system calls invoked this hook. If
690 * @new is the set of credentials that will be installed. Modifications
691 * should be made to this rather than to @current->cred.
692 * @old is the set of credentials that are being replaces
693 * @flags contains one of the LSM_SETID_* values.
694 * Return 0 on success.
696 * Update the module's state after setting one or more of the group
697 * identity attributes of the current process. The @flags parameter
698 * indicates which of the set*gid system calls invoked this hook.
699 * @new is the set of credentials that will be installed. Modifications
700 * should be made to this rather than to @current->cred.
701 * @old is the set of credentials that are being replaced.
702 * @flags contains one of the LSM_SETID_* values.
703 * Return 0 on success.
705 * Check permission before setting the process group identifier of the
706 * process @p to @pgid.
707 * @p contains the task_struct for process being modified.
708 * @pgid contains the new pgid.
709 * Return 0 if permission is granted.
711 * Check permission before getting the process group identifier of the
713 * @p contains the task_struct for the process.
714 * Return 0 if permission is granted.
716 * Check permission before getting the session identifier of the process
718 * @p contains the task_struct for the process.
719 * Return 0 if permission is granted.
720 * @current_getsecid_subj:
721 * Retrieve the subjective security identifier of the current task and
722 * return it in @secid.
723 * In case of failure, @secid will be set to zero.
724 * @task_getsecid_obj:
725 * Retrieve the objective security identifier of the task_struct in @p
726 * and return it in @secid.
727 * In case of failure, @secid will be set to zero.
730 * Check permission before setting the nice value of @p to @nice.
731 * @p contains the task_struct of process.
732 * @nice contains the new nice value.
733 * Return 0 if permission is granted.
735 * Check permission before setting the ioprio value of @p to @ioprio.
736 * @p contains the task_struct of process.
737 * @ioprio contains the new ioprio value
738 * Return 0 if permission is granted.
740 * Check permission before getting the ioprio value of @p.
741 * @p contains the task_struct of process.
742 * Return 0 if permission is granted.
744 * Check permission before getting and/or setting the resource limits of
746 * @cred points to the cred structure for the current task.
747 * @tcred points to the cred structure for the target task.
748 * @flags contains the LSM_PRLIMIT_* flag bits indicating whether the
749 * resource limits are being read, modified, or both.
750 * Return 0 if permission is granted.
752 * Check permission before setting the resource limits of process @p
753 * for @resource to @new_rlim. The old resource limit values can
754 * be examined by dereferencing (p->signal->rlim + resource).
755 * @p points to the task_struct for the target task's group leader.
756 * @resource contains the resource whose limit is being set.
757 * @new_rlim contains the new limits for @resource.
758 * Return 0 if permission is granted.
759 * @task_setscheduler:
760 * Check permission before setting scheduling policy and/or parameters of
762 * @p contains the task_struct for process.
763 * Return 0 if permission is granted.
764 * @task_getscheduler:
765 * Check permission before obtaining scheduling information for process
767 * @p contains the task_struct for process.
768 * Return 0 if permission is granted.
770 * Check permission before moving memory owned by process @p.
771 * @p contains the task_struct for process.
772 * Return 0 if permission is granted.
774 * Check permission before sending signal @sig to @p. @info can be NULL,
775 * the constant 1, or a pointer to a kernel_siginfo structure. If @info is 1 or
776 * SI_FROMKERNEL(info) is true, then the signal should be viewed as coming
777 * from the kernel and should typically be permitted.
778 * SIGIO signals are handled separately by the send_sigiotask hook in
780 * @p contains the task_struct for process.
781 * @info contains the signal information.
782 * @sig contains the signal value.
783 * @cred contains the cred of the process where the signal originated, or
784 * NULL if the current task is the originator.
785 * Return 0 if permission is granted.
787 * Check permission before performing a process control operation on the
789 * @option contains the operation.
790 * @arg2 contains a argument.
791 * @arg3 contains a argument.
792 * @arg4 contains a argument.
793 * @arg5 contains a argument.
794 * Return -ENOSYS if no-one wanted to handle this op, any other value to
795 * cause prctl() to return immediately with that value.
797 * Set the security attributes for an inode based on an associated task's
798 * security attributes, e.g. for /proc/pid inodes.
799 * @p contains the task_struct for the task.
800 * @inode contains the inode structure for the inode.
802 * Security hooks for Netlink messaging.
805 * Save security information for a netlink message so that permission
806 * checking can be performed when the message is processed. The security
807 * information can be saved using the eff_cap field of the
808 * netlink_skb_parms structure. Also may be used to provide fine
809 * grained control over message transmission.
810 * @sk associated sock of task sending the message.
811 * @skb contains the sk_buff structure for the netlink message.
812 * Return 0 if the information was successfully saved and message
813 * is allowed to be transmitted.
815 * Security hooks for Unix domain networking.
817 * @unix_stream_connect:
818 * Check permissions before establishing a Unix domain stream connection
819 * between @sock and @other.
820 * @sock contains the sock structure.
821 * @other contains the peer sock structure.
822 * @newsk contains the new sock structure.
823 * Return 0 if permission is granted.
825 * Check permissions before connecting or sending datagrams from @sock to
827 * @sock contains the socket structure.
828 * @other contains the peer socket structure.
829 * Return 0 if permission is granted.
831 * The @unix_stream_connect and @unix_may_send hooks were necessary because
832 * Linux provides an alternative to the conventional file name space for Unix
833 * domain sockets. Whereas binding and connecting to sockets in the file name
834 * space is mediated by the typical file permissions (and caught by the mknod
835 * and permission hooks in inode_security_ops), binding and connecting to
836 * sockets in the abstract name space is completely unmediated. Sufficient
837 * control of Unix domain sockets in the abstract name space isn't possible
838 * using only the socket layer hooks, since we need to know the actual target
839 * socket, which is not looked up until we are inside the af_unix code.
841 * Security hooks for socket operations.
844 * Check permissions prior to creating a new socket.
845 * @family contains the requested protocol family.
846 * @type contains the requested communications type.
847 * @protocol contains the requested protocol.
848 * @kern set to 1 if a kernel socket.
849 * Return 0 if permission is granted.
850 * @socket_post_create:
851 * This hook allows a module to update or allocate a per-socket security
852 * structure. Note that the security field was not added directly to the
853 * socket structure, but rather, the socket security information is stored
854 * in the associated inode. Typically, the inode alloc_security hook will
855 * allocate and attach security information to
856 * SOCK_INODE(sock)->i_security. This hook may be used to update the
857 * SOCK_INODE(sock)->i_security field with additional information that
858 * wasn't available when the inode was allocated.
859 * @sock contains the newly created socket structure.
860 * @family contains the requested protocol family.
861 * @type contains the requested communications type.
862 * @protocol contains the requested protocol.
863 * @kern set to 1 if a kernel socket.
864 * @socket_socketpair:
865 * Check permissions before creating a fresh pair of sockets.
866 * @socka contains the first socket structure.
867 * @sockb contains the second socket structure.
868 * Return 0 if permission is granted and the connection was established.
870 * Check permission before socket protocol layer bind operation is
871 * performed and the socket @sock is bound to the address specified in the
872 * @address parameter.
873 * @sock contains the socket structure.
874 * @address contains the address to bind to.
875 * @addrlen contains the length of address.
876 * Return 0 if permission is granted.
878 * Check permission before socket protocol layer connect operation
879 * attempts to connect socket @sock to a remote address, @address.
880 * @sock contains the socket structure.
881 * @address contains the address of remote endpoint.
882 * @addrlen contains the length of address.
883 * Return 0 if permission is granted.
885 * Check permission before socket protocol layer listen operation.
886 * @sock contains the socket structure.
887 * @backlog contains the maximum length for the pending connection queue.
888 * Return 0 if permission is granted.
890 * Check permission before accepting a new connection. Note that the new
891 * socket, @newsock, has been created and some information copied to it,
892 * but the accept operation has not actually been performed.
893 * @sock contains the listening socket structure.
894 * @newsock contains the newly created server socket for connection.
895 * Return 0 if permission is granted.
897 * Check permission before transmitting a message to another socket.
898 * @sock contains the socket structure.
899 * @msg contains the message to be transmitted.
900 * @size contains the size of message.
901 * Return 0 if permission is granted.
903 * Check permission before receiving a message from a socket.
904 * @sock contains the socket structure.
905 * @msg contains the message structure.
906 * @size contains the size of message structure.
907 * @flags contains the operational flags.
908 * Return 0 if permission is granted.
909 * @socket_getsockname:
910 * Check permission before the local address (name) of the socket object
911 * @sock is retrieved.
912 * @sock contains the socket structure.
913 * Return 0 if permission is granted.
914 * @socket_getpeername:
915 * Check permission before the remote address (name) of a socket object
916 * @sock is retrieved.
917 * @sock contains the socket structure.
918 * Return 0 if permission is granted.
919 * @socket_getsockopt:
920 * Check permissions before retrieving the options associated with socket
922 * @sock contains the socket structure.
923 * @level contains the protocol level to retrieve option from.
924 * @optname contains the name of option to retrieve.
925 * Return 0 if permission is granted.
926 * @socket_setsockopt:
927 * Check permissions before setting the options associated with socket
929 * @sock contains the socket structure.
930 * @level contains the protocol level to set options for.
931 * @optname contains the name of the option to set.
932 * Return 0 if permission is granted.
934 * Checks permission before all or part of a connection on the socket
935 * @sock is shut down.
936 * @sock contains the socket structure.
937 * @how contains the flag indicating how future sends and receives
939 * Return 0 if permission is granted.
940 * @socket_sock_rcv_skb:
941 * Check permissions on incoming network packets. This hook is distinct
942 * from Netfilter's IP input hooks since it is the first time that the
943 * incoming sk_buff @skb has been associated with a particular socket, @sk.
944 * Must not sleep inside this hook because some callers hold spinlocks.
945 * @sk contains the sock (not socket) associated with the incoming sk_buff.
946 * @skb contains the incoming network data.
947 * @socket_getpeersec_stream:
948 * This hook allows the security module to provide peer socket security
949 * state for unix or connected tcp sockets to userspace via getsockopt
950 * SO_GETPEERSEC. For tcp sockets this can be meaningful if the
951 * socket is associated with an ipsec SA.
952 * @sock is the local socket.
953 * @optval userspace memory where the security state is to be copied.
954 * @optlen userspace int where the module should copy the actual length
955 * of the security state.
956 * @len as input is the maximum length to copy to userspace provided
958 * Return 0 if all is well, otherwise, typical getsockopt return
960 * @socket_getpeersec_dgram:
961 * This hook allows the security module to provide peer socket security
962 * state for udp sockets on a per-packet basis to userspace via
963 * getsockopt SO_GETPEERSEC. The application must first have indicated
964 * the IP_PASSSEC option via getsockopt. It can then retrieve the
965 * security state returned by this hook for a packet via the SCM_SECURITY
966 * ancillary message type.
967 * @sock contains the peer socket. May be NULL.
968 * @skb is the sk_buff for the packet being queried. May be NULL.
969 * @secid pointer to store the secid of the packet.
970 * Return 0 on success, error on failure.
971 * @sk_alloc_security:
972 * Allocate and attach a security structure to the sk->sk_security field,
973 * which is used to copy security attributes between local stream sockets.
975 * Deallocate security structure.
976 * @sk_clone_security:
977 * Clone/copy security structure.
979 * Retrieve the LSM-specific secid for the sock to enable caching
980 * of network authorizations.
982 * Sets the socket's isec sid to the sock's sid.
983 * @inet_conn_request:
984 * Sets the openreq's sid to socket's sid with MLS portion taken
987 * Sets the new child socket's sid to the openreq sid.
988 * @inet_conn_established:
989 * Sets the connection's peersid to the secmark on skb.
990 * @secmark_relabel_packet:
991 * check if the process should be allowed to relabel packets to
993 * @secmark_refcount_inc:
994 * tells the LSM to increment the number of secmark labeling rules loaded
995 * @secmark_refcount_dec:
996 * tells the LSM to decrement the number of secmark labeling rules loaded
997 * @req_classify_flow:
998 * Sets the flow's sid to the openreq sid.
999 * @tun_dev_alloc_security:
1000 * This hook allows a module to allocate a security structure for a TUN
1002 * @security pointer to a security structure pointer.
1003 * Returns a zero on success, negative values on failure.
1004 * @tun_dev_free_security:
1005 * This hook allows a module to free the security structure for a TUN
1007 * @security pointer to the TUN device's security structure
1009 * Check permissions prior to creating a new TUN device.
1010 * @tun_dev_attach_queue:
1011 * Check permissions prior to attaching to a TUN device queue.
1012 * @security pointer to the TUN device's security structure.
1014 * This hook can be used by the module to update any security state
1015 * associated with the TUN device's sock structure.
1016 * @sk contains the existing sock structure.
1017 * @security pointer to the TUN device's security structure.
1019 * This hook can be used by the module to update any security state
1020 * associated with the TUN device's security structure.
1021 * @security pointer to the TUN devices's security structure.
1023 * Security hooks for SCTP
1025 * @sctp_assoc_request:
1026 * Passes the @asoc and @chunk->skb of the association INIT packet to
1027 * the security module.
1028 * @asoc pointer to sctp association structure.
1029 * @skb pointer to skbuff of association packet.
1030 * Return 0 on success, error on failure.
1031 * @sctp_bind_connect:
1032 * Validiate permissions required for each address associated with sock
1033 * @sk. Depending on @optname, the addresses will be treated as either
1034 * for a connect or bind service. The @addrlen is calculated on each
1035 * ipv4 and ipv6 address using sizeof(struct sockaddr_in) or
1036 * sizeof(struct sockaddr_in6).
1037 * @sk pointer to sock structure.
1038 * @optname name of the option to validate.
1039 * @address list containing one or more ipv4/ipv6 addresses.
1040 * @addrlen total length of address(s).
1041 * Return 0 on success, error on failure.
1043 * Called whenever a new socket is created by accept(2) (i.e. a TCP
1044 * style socket) or when a socket is 'peeled off' e.g userspace
1045 * calls sctp_peeloff(3).
1046 * @asoc pointer to current sctp association structure.
1047 * @sk pointer to current sock structure.
1048 * @newsk pointer to new sock structure.
1049 * @sctp_assoc_established:
1050 * Passes the @asoc and @chunk->skb of the association COOKIE_ACK packet
1051 * to the security module.
1052 * @asoc pointer to sctp association structure.
1053 * @skb pointer to skbuff of association packet.
1055 * Security hooks for Infiniband
1058 * Check permission to access a pkey when modifing a QP.
1059 * @subnet_prefix the subnet prefix of the port being used.
1060 * @pkey the pkey to be accessed.
1061 * @sec pointer to a security structure.
1062 * @ib_endport_manage_subnet:
1063 * Check permissions to send and receive SMPs on a end port.
1064 * @dev_name the IB device name (i.e. mlx4_0).
1065 * @port_num the port number.
1066 * @sec pointer to a security structure.
1067 * @ib_alloc_security:
1068 * Allocate a security structure for Infiniband objects.
1069 * @sec pointer to a security structure pointer.
1070 * Returns 0 on success, non-zero on failure
1071 * @ib_free_security:
1072 * Deallocate an Infiniband security structure.
1073 * @sec contains the security structure to be freed.
1075 * Security hooks for XFRM operations.
1077 * @xfrm_policy_alloc_security:
1078 * @ctxp is a pointer to the xfrm_sec_ctx being added to Security Policy
1079 * Database used by the XFRM system.
1080 * @sec_ctx contains the security context information being provided by
1081 * the user-level policy update program (e.g., setkey).
1082 * Allocate a security structure to the xp->security field; the security
1083 * field is initialized to NULL when the xfrm_policy is allocated.
1084 * Return 0 if operation was successful (memory to allocate, legal context)
1085 * @gfp is to specify the context for the allocation
1086 * @xfrm_policy_clone_security:
1087 * @old_ctx contains an existing xfrm_sec_ctx.
1088 * @new_ctxp contains a new xfrm_sec_ctx being cloned from old.
1089 * Allocate a security structure in new_ctxp that contains the
1090 * information from the old_ctx structure.
1091 * Return 0 if operation was successful (memory to allocate).
1092 * @xfrm_policy_free_security:
1093 * @ctx contains the xfrm_sec_ctx
1094 * Deallocate xp->security.
1095 * @xfrm_policy_delete_security:
1096 * @ctx contains the xfrm_sec_ctx.
1097 * Authorize deletion of xp->security.
1098 * @xfrm_state_alloc:
1099 * @x contains the xfrm_state being added to the Security Association
1100 * Database by the XFRM system.
1101 * @sec_ctx contains the security context information being provided by
1102 * the user-level SA generation program (e.g., setkey or racoon).
1103 * Allocate a security structure to the x->security field; the security
1104 * field is initialized to NULL when the xfrm_state is allocated. Set the
1105 * context to correspond to sec_ctx. Return 0 if operation was successful
1106 * (memory to allocate, legal context).
1107 * @xfrm_state_alloc_acquire:
1108 * @x contains the xfrm_state being added to the Security Association
1109 * Database by the XFRM system.
1110 * @polsec contains the policy's security context.
1111 * @secid contains the secid from which to take the mls portion of the
1113 * Allocate a security structure to the x->security field; the security
1114 * field is initialized to NULL when the xfrm_state is allocated. Set the
1115 * context to correspond to secid. Return 0 if operation was successful
1116 * (memory to allocate, legal context).
1117 * @xfrm_state_free_security:
1118 * @x contains the xfrm_state.
1119 * Deallocate x->security.
1120 * @xfrm_state_delete_security:
1121 * @x contains the xfrm_state.
1122 * Authorize deletion of x->security.
1123 * @xfrm_policy_lookup:
1124 * @ctx contains the xfrm_sec_ctx for which the access control is being
1126 * @fl_secid contains the flow security label that is used to authorize
1127 * access to the policy xp.
1128 * @dir contains the direction of the flow (input or output).
1129 * Check permission when a flow selects a xfrm_policy for processing
1130 * XFRMs on a packet. The hook is called when selecting either a
1131 * per-socket policy or a generic xfrm policy.
1132 * Return 0 if permission is granted, -ESRCH otherwise, or -errno
1134 * @xfrm_state_pol_flow_match:
1135 * @x contains the state to match.
1136 * @xp contains the policy to check for a match.
1137 * @flic contains the flowi_common struct to check for a match.
1138 * Return 1 if there is a match.
1139 * @xfrm_decode_session:
1140 * @skb points to skb to decode.
1141 * @secid points to the flow key secid to set.
1142 * @ckall says if all xfrms used should be checked for same secid.
1143 * Return 0 if ckall is zero or all xfrms used have the same secid.
1145 * Security hooks affecting all Key Management operations
1148 * Permit allocation of a key and assign security data. Note that key does
1149 * not have a serial number assigned at this point.
1150 * @key points to the key.
1151 * @flags is the allocation flags
1152 * Return 0 if permission is granted, -ve error otherwise.
1154 * Notification of destruction; free security data.
1155 * @key points to the key.
1158 * See whether a specific operational right is granted to a process on a
1160 * @key_ref refers to the key (key pointer + possession attribute bit).
1161 * @cred points to the credentials to provide the context against which to
1162 * evaluate the security data on the key.
1163 * @perm describes the combination of permissions required of this key.
1164 * Return 0 if permission is granted, -ve error otherwise.
1166 * Get a textual representation of the security context attached to a key
1167 * for the purposes of honouring KEYCTL_GETSECURITY. This function
1168 * allocates the storage for the NUL-terminated string and the caller
1170 * @key points to the key to be queried.
1171 * @_buffer points to a pointer that should be set to point to the
1172 * resulting string (if no label or an error occurs).
1173 * Return the length of the string (including terminating NUL) or -ve if
1175 * May also return 0 (and a NULL buffer pointer) if there is no label.
1177 * Security hooks affecting all System V IPC operations.
1180 * Check permissions for access to IPC
1181 * @ipcp contains the kernel IPC permission structure
1182 * @flag contains the desired (requested) permission set
1183 * Return 0 if permission is granted.
1185 * Get the secid associated with the ipc object.
1186 * @ipcp contains the kernel IPC permission structure.
1187 * @secid contains a pointer to the location where result will be saved.
1188 * In case of failure, @secid will be set to zero.
1190 * Security hooks for individual messages held in System V IPC message queues
1192 * @msg_msg_alloc_security:
1193 * Allocate and attach a security structure to the msg->security field.
1194 * The security field is initialized to NULL when the structure is first
1196 * @msg contains the message structure to be modified.
1197 * Return 0 if operation was successful and permission is granted.
1198 * @msg_msg_free_security:
1199 * Deallocate the security structure for this message.
1200 * @msg contains the message structure to be modified.
1202 * Security hooks for System V IPC Message Queues
1204 * @msg_queue_alloc_security:
1205 * Allocate and attach a security structure to the
1206 * @perm->security field. The security field is initialized to
1207 * NULL when the structure is first created.
1208 * @perm contains the IPC permissions of the message queue.
1209 * Return 0 if operation was successful and permission is granted.
1210 * @msg_queue_free_security:
1211 * Deallocate security field @perm->security for the message queue.
1212 * @perm contains the IPC permissions of the message queue.
1213 * @msg_queue_associate:
1214 * Check permission when a message queue is requested through the
1215 * msgget system call. This hook is only called when returning the
1216 * message queue identifier for an existing message queue, not when a
1217 * new message queue is created.
1218 * @perm contains the IPC permissions of the message queue.
1219 * @msqflg contains the operation control flags.
1220 * Return 0 if permission is granted.
1221 * @msg_queue_msgctl:
1222 * Check permission when a message control operation specified by @cmd
1223 * is to be performed on the message queue with permissions @perm.
1224 * The @perm may be NULL, e.g. for IPC_INFO or MSG_INFO.
1225 * @perm contains the IPC permissions of the msg queue. May be NULL.
1226 * @cmd contains the operation to be performed.
1227 * Return 0 if permission is granted.
1228 * @msg_queue_msgsnd:
1229 * Check permission before a message, @msg, is enqueued on the message
1230 * queue with permissions @perm.
1231 * @perm contains the IPC permissions of the message queue.
1232 * @msg contains the message to be enqueued.
1233 * @msqflg contains operational flags.
1234 * Return 0 if permission is granted.
1235 * @msg_queue_msgrcv:
1236 * Check permission before a message, @msg, is removed from the message
1237 * queue. The @target task structure contains a pointer to the
1238 * process that will be receiving the message (not equal to the current
1239 * process when inline receives are being performed).
1240 * @perm contains the IPC permissions of the message queue.
1241 * @msg contains the message destination.
1242 * @target contains the task structure for recipient process.
1243 * @type contains the type of message requested.
1244 * @mode contains the operational flags.
1245 * Return 0 if permission is granted.
1247 * Security hooks for System V Shared Memory Segments
1249 * @shm_alloc_security:
1250 * Allocate and attach a security structure to the @perm->security
1251 * field. The security field is initialized to NULL when the structure is
1253 * @perm contains the IPC permissions of the shared memory structure.
1254 * Return 0 if operation was successful and permission is granted.
1255 * @shm_free_security:
1256 * Deallocate the security structure @perm->security for the memory segment.
1257 * @perm contains the IPC permissions of the shared memory structure.
1259 * Check permission when a shared memory region is requested through the
1260 * shmget system call. This hook is only called when returning the shared
1261 * memory region identifier for an existing region, not when a new shared
1262 * memory region is created.
1263 * @perm contains the IPC permissions of the shared memory structure.
1264 * @shmflg contains the operation control flags.
1265 * Return 0 if permission is granted.
1267 * Check permission when a shared memory control operation specified by
1268 * @cmd is to be performed on the shared memory region with permissions @perm.
1269 * The @perm may be NULL, e.g. for IPC_INFO or SHM_INFO.
1270 * @perm contains the IPC permissions of the shared memory structure.
1271 * @cmd contains the operation to be performed.
1272 * Return 0 if permission is granted.
1274 * Check permissions prior to allowing the shmat system call to attach the
1275 * shared memory segment with permissions @perm to the data segment of the
1276 * calling process. The attaching address is specified by @shmaddr.
1277 * @perm contains the IPC permissions of the shared memory structure.
1278 * @shmaddr contains the address to attach memory region to.
1279 * @shmflg contains the operational flags.
1280 * Return 0 if permission is granted.
1282 * Security hooks for System V Semaphores
1284 * @sem_alloc_security:
1285 * Allocate and attach a security structure to the @perm->security
1286 * field. The security field is initialized to NULL when the structure is
1288 * @perm contains the IPC permissions of the semaphore.
1289 * Return 0 if operation was successful and permission is granted.
1290 * @sem_free_security:
1291 * Deallocate security structure @perm->security for the semaphore.
1292 * @perm contains the IPC permissions of the semaphore.
1294 * Check permission when a semaphore is requested through the semget
1295 * system call. This hook is only called when returning the semaphore
1296 * identifier for an existing semaphore, not when a new one must be
1298 * @perm contains the IPC permissions of the semaphore.
1299 * @semflg contains the operation control flags.
1300 * Return 0 if permission is granted.
1302 * Check permission when a semaphore operation specified by @cmd is to be
1303 * performed on the semaphore. The @perm may be NULL, e.g. for
1304 * IPC_INFO or SEM_INFO.
1305 * @perm contains the IPC permissions of the semaphore. May be NULL.
1306 * @cmd contains the operation to be performed.
1307 * Return 0 if permission is granted.
1309 * Check permissions before performing operations on members of the
1310 * semaphore set. If the @alter flag is nonzero, the semaphore set
1312 * @perm contains the IPC permissions of the semaphore.
1313 * @sops contains the operations to perform.
1314 * @nsops contains the number of operations to perform.
1315 * @alter contains the flag indicating whether changes are to be made.
1316 * Return 0 if permission is granted.
1318 * @binder_set_context_mgr:
1319 * Check whether @mgr is allowed to be the binder context manager.
1320 * @mgr contains the struct cred for the current binder process.
1321 * Return 0 if permission is granted.
1322 * @binder_transaction:
1323 * Check whether @from is allowed to invoke a binder transaction call
1325 * @from contains the struct cred for the sending process.
1326 * @to contains the struct cred for the receiving process.
1327 * @binder_transfer_binder:
1328 * Check whether @from is allowed to transfer a binder reference to @to.
1329 * @from contains the struct cred for the sending process.
1330 * @to contains the struct cred for the receiving process.
1331 * @binder_transfer_file:
1332 * Check whether @from is allowed to transfer @file to @to.
1333 * @from contains the struct cred for the sending process.
1334 * @file contains the struct file being transferred.
1335 * @to contains the struct cred for the receiving process.
1337 * @ptrace_access_check:
1338 * Check permission before allowing the current process to trace the
1340 * Security modules may also want to perform a process tracing check
1341 * during an execve in the set_security or apply_creds hooks of
1342 * tracing check during an execve in the bprm_set_creds hook of
1343 * binprm_security_ops if the process is being traced and its security
1344 * attributes would be changed by the execve.
1345 * @child contains the task_struct structure for the target process.
1346 * @mode contains the PTRACE_MODE flags indicating the form of access.
1347 * Return 0 if permission is granted.
1349 * Check that the @parent process has sufficient permission to trace the
1350 * current process before allowing the current process to present itself
1351 * to the @parent process for tracing.
1352 * @parent contains the task_struct structure for debugger process.
1353 * Return 0 if permission is granted.
1355 * Get the @effective, @inheritable, and @permitted capability sets for
1356 * the @target process. The hook may also perform permission checking to
1357 * determine if the current process is allowed to see the capability sets
1358 * of the @target process.
1359 * @target contains the task_struct structure for target process.
1360 * @effective contains the effective capability set.
1361 * @inheritable contains the inheritable capability set.
1362 * @permitted contains the permitted capability set.
1363 * Return 0 if the capability sets were successfully obtained.
1365 * Set the @effective, @inheritable, and @permitted capability sets for
1366 * the current process.
1367 * @new contains the new credentials structure for target process.
1368 * @old contains the current credentials structure for target process.
1369 * @effective contains the effective capability set.
1370 * @inheritable contains the inheritable capability set.
1371 * @permitted contains the permitted capability set.
1372 * Return 0 and update @new if permission is granted.
1374 * Check whether the @tsk process has the @cap capability in the indicated
1376 * @cred contains the credentials to use.
1377 * @ns contains the user namespace we want the capability in
1378 * @cap contains the capability <include/linux/capability.h>.
1379 * @opts contains options for the capable check <include/linux/security.h>
1380 * Return 0 if the capability is granted for @tsk.
1382 * Check whether the quotactl syscall is allowed for this @sb.
1384 * Check whether QUOTAON is allowed for this @dentry.
1386 * Check permission before accessing the kernel message ring or changing
1387 * logging to the console.
1388 * See the syslog(2) manual page for an explanation of the @type values.
1389 * @type contains the SYSLOG_ACTION_* constant from <include/linux/syslog.h>
1390 * Return 0 if permission is granted.
1392 * Check permission to change the system time.
1393 * struct timespec64 is defined in <include/linux/time64.h> and timezone
1394 * is defined in <include/linux/time.h>
1395 * @ts contains new time
1396 * @tz contains new timezone
1397 * Return 0 if permission is granted.
1398 * @vm_enough_memory:
1399 * Check permissions for allocating a new virtual mapping.
1400 * @mm contains the mm struct it is being added to.
1401 * @pages contains the number of pages.
1402 * Return 0 if permission is granted.
1405 * Check if the extended attribute specified by @name
1406 * represents a MAC label. Returns 1 if name is a MAC
1407 * attribute otherwise returns 0.
1408 * @name full extended attribute name to check against
1409 * LSM as a MAC label.
1412 * Convert secid to security context. If secdata is NULL the length of
1413 * the result will be returned in seclen, but no secdata will be returned.
1414 * This does mean that the length could change between calls to check the
1415 * length and the next call which actually allocates and returns the
1417 * @secid contains the security ID.
1418 * @secdata contains the pointer that stores the converted security
1420 * @seclen pointer which contains the length of the data
1422 * Convert security context to secid.
1423 * @secid contains the pointer to the generated security ID.
1424 * @secdata contains the security context.
1427 * Release the security context.
1428 * @secdata contains the security context.
1429 * @seclen contains the length of the security context.
1431 * Security hooks for Audit
1434 * Allocate and initialize an LSM audit rule structure.
1435 * @field contains the required Audit action.
1436 * Fields flags are defined in <include/linux/audit.h>
1437 * @op contains the operator the rule uses.
1438 * @rulestr contains the context where the rule will be applied to.
1439 * @lsmrule contains a pointer to receive the result.
1440 * Return 0 if @lsmrule has been successfully set,
1441 * -EINVAL in case of an invalid rule.
1443 * @audit_rule_known:
1444 * Specifies whether given @krule contains any fields related to
1446 * @krule contains the audit rule of interest.
1447 * Return 1 in case of relation found, 0 otherwise.
1449 * @audit_rule_match:
1450 * Determine if given @secid matches a rule previously approved
1451 * by @audit_rule_known.
1452 * @secid contains the security id in question.
1453 * @field contains the field which relates to current LSM.
1454 * @op contains the operator that will be used for matching.
1455 * @lrule points to the audit rule that will be checked against.
1456 * Return 1 if secid matches the rule, 0 if it does not, -ERRNO on failure.
1459 * Deallocate the LSM audit rule structure previously allocated by
1461 * @lsmrule contains the allocated rule
1463 * @inode_invalidate_secctx:
1464 * Notify the security module that it must revalidate the security context
1467 * @inode_notifysecctx:
1468 * Notify the security module of what the security context of an inode
1469 * should be. Initializes the incore security context managed by the
1470 * security module for this inode. Example usage: NFS client invokes
1471 * this hook to initialize the security context in its incore inode to the
1472 * value provided by the server for the file when the server returned the
1473 * file's attributes to the client.
1474 * Must be called with inode->i_mutex locked.
1475 * @inode we wish to set the security context of.
1476 * @ctx contains the string which we wish to set in the inode.
1477 * @ctxlen contains the length of @ctx.
1480 * Change the security context of an inode. Updates the
1481 * incore security context managed by the security module and invokes the
1482 * fs code as needed (via __vfs_setxattr_noperm) to update any backing
1483 * xattrs that represent the context. Example usage: NFS server invokes
1484 * this hook to change the security context in its incore inode and on the
1485 * backing filesystem to a value provided by the client on a SETATTR
1487 * Must be called with inode->i_mutex locked.
1488 * @dentry contains the inode we wish to set the security context of.
1489 * @ctx contains the string which we wish to set in the inode.
1490 * @ctxlen contains the length of @ctx.
1493 * On success, returns 0 and fills out @ctx and @ctxlen with the security
1494 * context for the given @inode.
1495 * @inode we wish to get the security context of.
1496 * @ctx is a pointer in which to place the allocated security context.
1497 * @ctxlen points to the place to put the length of @ctx.
1499 * Security hooks for the general notification queue:
1501 * @post_notification:
1502 * Check to see if a watch notification can be posted to a particular
1504 * @w_cred: The credentials of the whoever set the watch.
1505 * @cred: The event-triggerer's credentials
1506 * @n: The notification being posted
1509 * Check to see if a process is allowed to watch for event notifications
1510 * from a key or keyring.
1511 * @key: The key to watch.
1513 * Security hooks for using the eBPF maps and programs functionalities through
1517 * Do a initial check for all bpf syscalls after the attribute is copied
1518 * into the kernel. The actual security module can implement their own
1519 * rules to check the specific cmd they need.
1522 * Do a check when the kernel generate and return a file descriptor for
1525 * @map: bpf map that we want to access
1526 * @mask: the access flags
1529 * Do a check when the kernel generate and return a file descriptor for
1532 * @prog: bpf prog that userspace want to use.
1534 * @bpf_map_alloc_security:
1535 * Initialize the security field inside bpf map.
1537 * @bpf_map_free_security:
1538 * Clean up the security information stored inside bpf map.
1540 * @bpf_prog_alloc_security:
1541 * Initialize the security field inside bpf program.
1543 * @bpf_prog_free_security:
1544 * Clean up the security information stored inside bpf prog.
1547 * Determine whether a kernel feature that potentially enables arbitrary
1548 * code execution in kernel space should be permitted.
1550 * @what: kernel feature being accessed
1552 * Security hooks for perf events
1555 * Check whether the @type of perf_event_open syscall is allowed.
1556 * @perf_event_alloc:
1557 * Allocate and save perf_event security info.
1559 * Release (free) perf_event security info.
1561 * Read perf_event security info if allowed.
1562 * @perf_event_write:
1563 * Write perf_event security info if allowed.
1565 * Security hooks for io_uring
1567 * @uring_override_creds:
1568 * Check if the current task, executing an io_uring operation, is allowed
1569 * to override it's credentials with @new.
1571 * @new: the new creds to use
1574 * Check whether the current task is allowed to spawn a io_uring polling
1575 * thread (IORING_SETUP_SQPOLL).
1578 union security_list_options {
1579 #define LSM_HOOK(RET, DEFAULT, NAME, ...) RET (*NAME)(__VA_ARGS__);
1580 #include "lsm_hook_defs.h"
1584 struct security_hook_heads {
1585 #define LSM_HOOK(RET, DEFAULT, NAME, ...) struct hlist_head NAME;
1586 #include "lsm_hook_defs.h"
1588 } __randomize_layout;
1591 * Security module hook list structure.
1592 * For use with generic list macros for common operations.
1594 struct security_hook_list {
1595 struct hlist_node list;
1596 struct hlist_head *head;
1597 union security_list_options hook;
1599 } __randomize_layout;
1602 * Security blob size or offset data.
1604 struct lsm_blob_sizes {
1615 * LSM_RET_VOID is used as the default value in LSM_HOOK definitions for void
1616 * LSM hooks (in include/linux/lsm_hook_defs.h).
1618 #define LSM_RET_VOID ((void) 0)
1621 * Initializing a security_hook_list structure takes
1622 * up a lot of space in a source file. This macro takes
1623 * care of the common case and reduces the amount of
1626 #define LSM_HOOK_INIT(HEAD, HOOK) \
1627 { .head = &security_hook_heads.HEAD, .hook = { .HEAD = HOOK } }
1629 extern struct security_hook_heads security_hook_heads;
1630 extern char *lsm_names;
1632 extern void security_add_hooks(struct security_hook_list *hooks, int count,
1635 #define LSM_FLAG_LEGACY_MAJOR BIT(0)
1636 #define LSM_FLAG_EXCLUSIVE BIT(1)
1639 LSM_ORDER_FIRST = -1, /* This is only for capabilities. */
1640 LSM_ORDER_MUTABLE = 0,
1644 const char *name; /* Required. */
1645 enum lsm_order order; /* Optional: default is LSM_ORDER_MUTABLE */
1646 unsigned long flags; /* Optional: flags describing LSM */
1647 int *enabled; /* Optional: controlled by CONFIG_LSM */
1648 int (*init)(void); /* Required. */
1649 struct lsm_blob_sizes *blobs; /* Optional: for blob sharing. */
1652 extern struct lsm_info __start_lsm_info[], __end_lsm_info[];
1653 extern struct lsm_info __start_early_lsm_info[], __end_early_lsm_info[];
1655 #define DEFINE_LSM(lsm) \
1656 static struct lsm_info __lsm_##lsm \
1657 __used __section(".lsm_info.init") \
1658 __aligned(sizeof(unsigned long))
1660 #define DEFINE_EARLY_LSM(lsm) \
1661 static struct lsm_info __early_lsm_##lsm \
1662 __used __section(".early_lsm_info.init") \
1663 __aligned(sizeof(unsigned long))
1665 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
1667 * Assuring the safety of deleting a security module is up to
1668 * the security module involved. This may entail ordering the
1669 * module's hook list in a particular way, refusing to disable
1670 * the module once a policy is loaded or any number of other
1671 * actions better imagined than described.
1673 * The name of the configuration option reflects the only module
1674 * that currently uses the mechanism. Any developer who thinks
1675 * disabling their module is a good idea needs to be at least as
1676 * careful as the SELinux team.
1678 static inline void security_delete_hooks(struct security_hook_list *hooks,
1683 for (i = 0; i < count; i++)
1684 hlist_del_rcu(&hooks[i].list);
1686 #endif /* CONFIG_SECURITY_SELINUX_DISABLE */
1688 /* Currently required to handle SELinux runtime hook disable. */
1689 #ifdef CONFIG_SECURITY_WRITABLE_HOOKS
1690 #define __lsm_ro_after_init
1692 #define __lsm_ro_after_init __ro_after_init
1693 #endif /* CONFIG_SECURITY_WRITABLE_HOOKS */
1695 extern int lsm_inode_alloc(struct inode *inode);
1697 #endif /* ! __LINUX_LSM_HOOKS_H */