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