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