lsm_hooks.h 74 KB

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