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