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