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