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