lsm_hooks.h 84 KB

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