lsm_hooks.h 73 KB

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