security.h 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860
  1. /*
  2. * Linux Security plug
  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. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * Due to this file being licensed under the GPL there is controversy over
  16. * whether this permits you to write a module that #includes this file
  17. * without placing your module under the GPL. Please consult a lawyer for
  18. * advice before doing this.
  19. *
  20. */
  21. #ifndef __LINUX_SECURITY_H
  22. #define __LINUX_SECURITY_H
  23. #include <linux/fs.h>
  24. #include <linux/binfmts.h>
  25. #include <linux/signal.h>
  26. #include <linux/resource.h>
  27. #include <linux/sem.h>
  28. #include <linux/shm.h>
  29. #include <linux/msg.h>
  30. #include <linux/sched.h>
  31. struct ctl_table;
  32. /*
  33. * These functions are in security/capability.c and are used
  34. * as the default capabilities functions
  35. */
  36. extern int cap_capable (struct task_struct *tsk, int cap);
  37. extern int cap_settime (struct timespec *ts, struct timezone *tz);
  38. extern int cap_ptrace (struct task_struct *parent, struct task_struct *child);
  39. extern int cap_capget (struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
  40. extern int cap_capset_check (struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
  41. extern void cap_capset_set (struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
  42. extern int cap_bprm_set_security (struct linux_binprm *bprm);
  43. extern void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe);
  44. extern int cap_bprm_secureexec(struct linux_binprm *bprm);
  45. extern int cap_inode_setxattr(struct dentry *dentry, char *name, void *value, size_t size, int flags);
  46. extern int cap_inode_removexattr(struct dentry *dentry, char *name);
  47. extern int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid, int flags);
  48. extern void cap_task_reparent_to_init (struct task_struct *p);
  49. extern int cap_syslog (int type);
  50. extern int cap_vm_enough_memory (long pages);
  51. struct msghdr;
  52. struct sk_buff;
  53. struct sock;
  54. struct sockaddr;
  55. struct socket;
  56. extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
  57. extern int cap_netlink_recv(struct sk_buff *skb);
  58. /*
  59. * Values used in the task_security_ops calls
  60. */
  61. /* setuid or setgid, id0 == uid or gid */
  62. #define LSM_SETID_ID 1
  63. /* setreuid or setregid, id0 == real, id1 == eff */
  64. #define LSM_SETID_RE 2
  65. /* setresuid or setresgid, id0 == real, id1 == eff, uid2 == saved */
  66. #define LSM_SETID_RES 4
  67. /* setfsuid or setfsgid, id0 == fsuid or fsgid */
  68. #define LSM_SETID_FS 8
  69. /* forward declares to avoid warnings */
  70. struct nfsctl_arg;
  71. struct sched_param;
  72. struct swap_info_struct;
  73. /* bprm_apply_creds unsafe reasons */
  74. #define LSM_UNSAFE_SHARE 1
  75. #define LSM_UNSAFE_PTRACE 2
  76. #define LSM_UNSAFE_PTRACE_CAP 4
  77. #ifdef CONFIG_SECURITY
  78. /**
  79. * struct security_operations - main security structure
  80. *
  81. * Security hooks for program execution operations.
  82. *
  83. * @bprm_alloc_security:
  84. * Allocate and attach a security structure to the @bprm->security field.
  85. * The security field is initialized to NULL when the bprm structure is
  86. * allocated.
  87. * @bprm contains the linux_binprm structure to be modified.
  88. * Return 0 if operation was successful.
  89. * @bprm_free_security:
  90. * @bprm contains the linux_binprm structure to be modified.
  91. * Deallocate and clear the @bprm->security field.
  92. * @bprm_apply_creds:
  93. * Compute and set the security attributes of a process being transformed
  94. * by an execve operation based on the old attributes (current->security)
  95. * and the information saved in @bprm->security by the set_security hook.
  96. * Since this hook function (and its caller) are void, this hook can not
  97. * return an error. However, it can leave the security attributes of the
  98. * process unchanged if an access failure occurs at this point.
  99. * bprm_apply_creds is called under task_lock. @unsafe indicates various
  100. * reasons why it may be unsafe to change security state.
  101. * @bprm contains the linux_binprm structure.
  102. * @bprm_post_apply_creds:
  103. * Runs after bprm_apply_creds with the task_lock dropped, so that
  104. * functions which cannot be called safely under the task_lock can
  105. * be used. This hook is a good place to perform state changes on
  106. * the process such as closing open file descriptors to which access
  107. * is no longer granted if the attributes were changed.
  108. * Note that a security module might need to save state between
  109. * bprm_apply_creds and bprm_post_apply_creds to store the decision
  110. * on whether the process may proceed.
  111. * @bprm contains the linux_binprm structure.
  112. * @bprm_set_security:
  113. * Save security information in the bprm->security field, typically based
  114. * on information about the bprm->file, for later use by the apply_creds
  115. * hook. This hook may also optionally check permissions (e.g. for
  116. * transitions between security domains).
  117. * This hook may be called multiple times during a single execve, e.g. for
  118. * interpreters. The hook can tell whether it has already been called by
  119. * checking to see if @bprm->security is non-NULL. If so, then the hook
  120. * may decide either to retain the security information saved earlier or
  121. * to replace it.
  122. * @bprm contains the linux_binprm structure.
  123. * Return 0 if the hook is successful and permission is granted.
  124. * @bprm_check_security:
  125. * This hook mediates the point when a search for a binary handler will
  126. * begin. It allows a check the @bprm->security value which is set in
  127. * the preceding set_security call. The primary difference from
  128. * set_security is that the argv list and envp list are reliably
  129. * available in @bprm. This hook may be called multiple times
  130. * during a single execve; and in each pass set_security is called
  131. * first.
  132. * @bprm contains the linux_binprm structure.
  133. * Return 0 if the hook is successful and permission is granted.
  134. * @bprm_secureexec:
  135. * Return a boolean value (0 or 1) indicating whether a "secure exec"
  136. * is required. The flag is passed in the auxiliary table
  137. * on the initial stack to the ELF interpreter to indicate whether libc
  138. * should enable secure mode.
  139. * @bprm contains the linux_binprm structure.
  140. *
  141. * Security hooks for filesystem operations.
  142. *
  143. * @sb_alloc_security:
  144. * Allocate and attach a security structure to the sb->s_security field.
  145. * The s_security field is initialized to NULL when the structure is
  146. * allocated.
  147. * @sb contains the super_block structure to be modified.
  148. * Return 0 if operation was successful.
  149. * @sb_free_security:
  150. * Deallocate and clear the sb->s_security field.
  151. * @sb contains the super_block structure to be modified.
  152. * @sb_statfs:
  153. * Check permission before obtaining filesystem statistics for the @sb
  154. * filesystem.
  155. * @sb contains the super_block structure for the filesystem.
  156. * Return 0 if permission is granted.
  157. * @sb_mount:
  158. * Check permission before an object specified by @dev_name is mounted on
  159. * the mount point named by @nd. For an ordinary mount, @dev_name
  160. * identifies a device if the file system type requires a device. For a
  161. * remount (@flags & MS_REMOUNT), @dev_name is irrelevant. For a
  162. * loopback/bind mount (@flags & MS_BIND), @dev_name identifies the
  163. * pathname of the object being mounted.
  164. * @dev_name contains the name for object being mounted.
  165. * @nd contains the nameidata structure for mount point object.
  166. * @type contains the filesystem type.
  167. * @flags contains the mount flags.
  168. * @data contains the filesystem-specific data.
  169. * Return 0 if permission is granted.
  170. * @sb_copy_data:
  171. * Allow mount option data to be copied prior to parsing by the filesystem,
  172. * so that the security module can extract security-specific mount
  173. * options cleanly (a filesystem may modify the data e.g. with strsep()).
  174. * This also allows the original mount data to be stripped of security-
  175. * specific options to avoid having to make filesystems aware of them.
  176. * @type the type of filesystem being mounted.
  177. * @orig the original mount data copied from userspace.
  178. * @copy copied data which will be passed to the security module.
  179. * Returns 0 if the copy was successful.
  180. * @sb_check_sb:
  181. * Check permission before the device with superblock @mnt->sb is mounted
  182. * on the mount point named by @nd.
  183. * @mnt contains the vfsmount for device being mounted.
  184. * @nd contains the nameidata object for the mount point.
  185. * Return 0 if permission is granted.
  186. * @sb_umount:
  187. * Check permission before the @mnt file system is unmounted.
  188. * @mnt contains the mounted file system.
  189. * @flags contains the unmount flags, e.g. MNT_FORCE.
  190. * Return 0 if permission is granted.
  191. * @sb_umount_close:
  192. * Close any files in the @mnt mounted filesystem that are held open by
  193. * the security module. This hook is called during an umount operation
  194. * prior to checking whether the filesystem is still busy.
  195. * @mnt contains the mounted filesystem.
  196. * @sb_umount_busy:
  197. * Handle a failed umount of the @mnt mounted filesystem, e.g. re-opening
  198. * any files that were closed by umount_close. This hook is called during
  199. * an umount operation if the umount fails after a call to the
  200. * umount_close hook.
  201. * @mnt contains the mounted filesystem.
  202. * @sb_post_remount:
  203. * Update the security module's state when a filesystem is remounted.
  204. * This hook is only called if the remount was successful.
  205. * @mnt contains the mounted file system.
  206. * @flags contains the new filesystem flags.
  207. * @data contains the filesystem-specific data.
  208. * @sb_post_mountroot:
  209. * Update the security module's state when the root filesystem is mounted.
  210. * This hook is only called if the mount was successful.
  211. * @sb_post_addmount:
  212. * Update the security module's state when a filesystem is mounted.
  213. * This hook is called any time a mount is successfully grafetd to
  214. * the tree.
  215. * @mnt contains the mounted filesystem.
  216. * @mountpoint_nd contains the nameidata structure for the mount point.
  217. * @sb_pivotroot:
  218. * Check permission before pivoting the root filesystem.
  219. * @old_nd contains the nameidata structure for the new location of the current root (put_old).
  220. * @new_nd contains the nameidata structure for the new root (new_root).
  221. * Return 0 if permission is granted.
  222. * @sb_post_pivotroot:
  223. * Update module state after a successful pivot.
  224. * @old_nd contains the nameidata structure for the old root.
  225. * @new_nd contains the nameidata structure for the new root.
  226. *
  227. * Security hooks for inode operations.
  228. *
  229. * @inode_alloc_security:
  230. * Allocate and attach a security structure to @inode->i_security. The
  231. * i_security field is initialized to NULL when the inode structure is
  232. * allocated.
  233. * @inode contains the inode structure.
  234. * Return 0 if operation was successful.
  235. * @inode_free_security:
  236. * @inode contains the inode structure.
  237. * Deallocate the inode security structure and set @inode->i_security to
  238. * NULL.
  239. * @inode_create:
  240. * Check permission to create a regular file.
  241. * @dir contains inode structure of the parent of the new file.
  242. * @dentry contains the dentry structure for the file to be created.
  243. * @mode contains the file mode of the file to be created.
  244. * Return 0 if permission is granted.
  245. * @inode_post_create:
  246. * Set the security attributes on a newly created regular file. This hook
  247. * is called after a file has been successfully created.
  248. * @dir contains the inode structure of the parent directory of the new file.
  249. * @dentry contains the the dentry structure for the newly created file.
  250. * @mode contains the file mode.
  251. * @inode_link:
  252. * Check permission before creating a new hard link to a file.
  253. * @old_dentry contains the dentry structure for an existing link to the file.
  254. * @dir contains the inode structure of the parent directory of the new link.
  255. * @new_dentry contains the dentry structure for the new link.
  256. * Return 0 if permission is granted.
  257. * @inode_post_link:
  258. * Set security attributes for a new hard link to a file.
  259. * @old_dentry contains the dentry structure for the existing link.
  260. * @dir contains the inode structure of the parent directory of the new file.
  261. * @new_dentry contains the dentry structure for the new file link.
  262. * @inode_unlink:
  263. * Check the permission to remove a hard link to a file.
  264. * @dir contains the inode structure of parent directory of the file.
  265. * @dentry contains the dentry structure for file to be unlinked.
  266. * Return 0 if permission is granted.
  267. * @inode_symlink:
  268. * Check the permission to create a symbolic link to a file.
  269. * @dir contains the inode structure of parent directory of the symbolic link.
  270. * @dentry contains the dentry structure of the symbolic link.
  271. * @old_name contains the pathname of file.
  272. * Return 0 if permission is granted.
  273. * @inode_post_symlink:
  274. * @dir contains the inode structure of the parent directory of the new link.
  275. * @dentry contains the dentry structure of new symbolic link.
  276. * @old_name contains the pathname of file.
  277. * Set security attributes for a newly created symbolic link. Note that
  278. * @dentry->d_inode may be NULL, since the filesystem might not
  279. * instantiate the dentry (e.g. NFS).
  280. * @inode_mkdir:
  281. * Check permissions to create a new directory in the existing directory
  282. * associated with inode strcture @dir.
  283. * @dir containst the inode structure of parent of the directory to be created.
  284. * @dentry contains the dentry structure of new directory.
  285. * @mode contains the mode of new directory.
  286. * Return 0 if permission is granted.
  287. * @inode_post_mkdir:
  288. * Set security attributes on a newly created directory.
  289. * @dir contains the inode structure of parent of the directory to be created.
  290. * @dentry contains the dentry structure of new directory.
  291. * @mode contains the mode of new directory.
  292. * @inode_rmdir:
  293. * Check the permission to remove a directory.
  294. * @dir contains the inode structure of parent of the directory to be removed.
  295. * @dentry contains the dentry structure of directory to be removed.
  296. * Return 0 if permission is granted.
  297. * @inode_mknod:
  298. * Check permissions when creating a special file (or a socket or a fifo
  299. * file created via the mknod system call). Note that if mknod operation
  300. * is being done for a regular file, then the create hook will be called
  301. * and not this hook.
  302. * @dir contains the inode structure of parent of the new file.
  303. * @dentry contains the dentry structure of the new file.
  304. * @mode contains the mode of the new file.
  305. * @dev contains the the device number.
  306. * Return 0 if permission is granted.
  307. * @inode_post_mknod:
  308. * Set security attributes on a newly created special file (or socket or
  309. * fifo file created via the mknod system call).
  310. * @dir contains the inode structure of parent of the new node.
  311. * @dentry contains the dentry structure of the new node.
  312. * @mode contains the mode of the new node.
  313. * @dev contains the the device number.
  314. * @inode_rename:
  315. * Check for permission to rename a file or directory.
  316. * @old_dir contains the inode structure for parent of the old link.
  317. * @old_dentry contains the dentry structure of the old link.
  318. * @new_dir contains the inode structure for parent of the new link.
  319. * @new_dentry contains the dentry structure of the new link.
  320. * Return 0 if permission is granted.
  321. * @inode_post_rename:
  322. * Set security attributes on a renamed file or directory.
  323. * @old_dir contains the inode structure for parent of the old link.
  324. * @old_dentry contains the dentry structure of the old link.
  325. * @new_dir contains the inode structure for parent of the new link.
  326. * @new_dentry contains the dentry structure of the new link.
  327. * @inode_readlink:
  328. * Check the permission to read the symbolic link.
  329. * @dentry contains the dentry structure for the file link.
  330. * Return 0 if permission is granted.
  331. * @inode_follow_link:
  332. * Check permission to follow a symbolic link when looking up a pathname.
  333. * @dentry contains the dentry structure for the link.
  334. * @nd contains the nameidata structure for the parent directory.
  335. * Return 0 if permission is granted.
  336. * @inode_permission:
  337. * Check permission before accessing an inode. This hook is called by the
  338. * existing Linux permission function, so a security module can use it to
  339. * provide additional checking for existing Linux permission checks.
  340. * Notice that this hook is called when a file is opened (as well as many
  341. * other operations), whereas the file_security_ops permission hook is
  342. * called when the actual read/write operations are performed.
  343. * @inode contains the inode structure to check.
  344. * @mask contains the permission mask.
  345. * @nd contains the nameidata (may be NULL).
  346. * Return 0 if permission is granted.
  347. * @inode_setattr:
  348. * Check permission before setting file attributes. Note that the kernel
  349. * call to notify_change is performed from several locations, whenever
  350. * file attributes change (such as when a file is truncated, chown/chmod
  351. * operations, transferring disk quotas, etc).
  352. * @dentry contains the dentry structure for the file.
  353. * @attr is the iattr structure containing the new file attributes.
  354. * Return 0 if permission is granted.
  355. * @inode_getattr:
  356. * Check permission before obtaining file attributes.
  357. * @mnt is the vfsmount where the dentry was looked up
  358. * @dentry contains the dentry structure for the file.
  359. * Return 0 if permission is granted.
  360. * @inode_delete:
  361. * @inode contains the inode structure for deleted inode.
  362. * This hook is called when a deleted inode is released (i.e. an inode
  363. * with no hard links has its use count drop to zero). A security module
  364. * can use this hook to release any persistent label associated with the
  365. * inode.
  366. * @inode_setxattr:
  367. * Check permission before setting the extended attributes
  368. * @value identified by @name for @dentry.
  369. * Return 0 if permission is granted.
  370. * @inode_post_setxattr:
  371. * Update inode security field after successful setxattr operation.
  372. * @value identified by @name for @dentry.
  373. * @inode_getxattr:
  374. * Check permission before obtaining the extended attributes
  375. * identified by @name for @dentry.
  376. * Return 0 if permission is granted.
  377. * @inode_listxattr:
  378. * Check permission before obtaining the list of extended attribute
  379. * names for @dentry.
  380. * Return 0 if permission is granted.
  381. * @inode_removexattr:
  382. * Check permission before removing the extended attribute
  383. * identified by @name for @dentry.
  384. * Return 0 if permission is granted.
  385. * @inode_getsecurity:
  386. * Copy the extended attribute representation of the security label
  387. * associated with @name for @inode into @buffer. @buffer may be
  388. * NULL to request the size of the buffer required. @size indicates
  389. * the size of @buffer in bytes. Note that @name is the remainder
  390. * of the attribute name after the security. prefix has been removed.
  391. * Return number of bytes used/required on success.
  392. * @inode_setsecurity:
  393. * Set the security label associated with @name for @inode from the
  394. * extended attribute value @value. @size indicates the size of the
  395. * @value in bytes. @flags may be XATTR_CREATE, XATTR_REPLACE, or 0.
  396. * Note that @name is the remainder of the attribute name after the
  397. * security. prefix has been removed.
  398. * Return 0 on success.
  399. * @inode_listsecurity:
  400. * Copy the extended attribute names for the security labels
  401. * associated with @inode into @buffer. The maximum size of @buffer
  402. * is specified by @buffer_size. @buffer may be NULL to request
  403. * the size of the buffer required.
  404. * Returns number of bytes used/required on success.
  405. *
  406. * Security hooks for file operations
  407. *
  408. * @file_permission:
  409. * Check file permissions before accessing an open file. This hook is
  410. * called by various operations that read or write files. A security
  411. * module can use this hook to perform additional checking on these
  412. * operations, e.g. to revalidate permissions on use to support privilege
  413. * bracketing or policy changes. Notice that this hook is used when the
  414. * actual read/write operations are performed, whereas the
  415. * inode_security_ops hook is called when a file is opened (as well as
  416. * many other operations).
  417. * Caveat: Although this hook can be used to revalidate permissions for
  418. * various system call operations that read or write files, it does not
  419. * address the revalidation of permissions for memory-mapped files.
  420. * Security modules must handle this separately if they need such
  421. * revalidation.
  422. * @file contains the file structure being accessed.
  423. * @mask contains the requested permissions.
  424. * Return 0 if permission is granted.
  425. * @file_alloc_security:
  426. * Allocate and attach a security structure to the file->f_security field.
  427. * The security field is initialized to NULL when the structure is first
  428. * created.
  429. * @file contains the file structure to secure.
  430. * Return 0 if the hook is successful and permission is granted.
  431. * @file_free_security:
  432. * Deallocate and free any security structures stored in file->f_security.
  433. * @file contains the file structure being modified.
  434. * @file_ioctl:
  435. * @file contains the file structure.
  436. * @cmd contains the operation to perform.
  437. * @arg contains the operational arguments.
  438. * Check permission for an ioctl operation on @file. Note that @arg can
  439. * sometimes represents a user space pointer; in other cases, it may be a
  440. * simple integer value. When @arg represents a user space pointer, it
  441. * should never be used by the security module.
  442. * Return 0 if permission is granted.
  443. * @file_mmap :
  444. * Check permissions for a mmap operation. The @file may be NULL, e.g.
  445. * if mapping anonymous memory.
  446. * @file contains the file structure for file to map (may be NULL).
  447. * @reqprot contains the protection requested by the application.
  448. * @prot contains the protection that will be applied by the kernel.
  449. * @flags contains the operational flags.
  450. * Return 0 if permission is granted.
  451. * @file_mprotect:
  452. * Check permissions before changing memory access permissions.
  453. * @vma contains the memory region to modify.
  454. * @reqprot contains the protection requested by the application.
  455. * @prot contains the protection that will be applied by the kernel.
  456. * Return 0 if permission is granted.
  457. * @file_lock:
  458. * Check permission before performing file locking operations.
  459. * Note: this hook mediates both flock and fcntl style locks.
  460. * @file contains the file structure.
  461. * @cmd contains the posix-translated lock operation to perform
  462. * (e.g. F_RDLCK, F_WRLCK).
  463. * Return 0 if permission is granted.
  464. * @file_fcntl:
  465. * Check permission before allowing the file operation specified by @cmd
  466. * from being performed on the file @file. Note that @arg can sometimes
  467. * represents a user space pointer; in other cases, it may be a simple
  468. * integer value. When @arg represents a user space pointer, it should
  469. * never be used by the security module.
  470. * @file contains the file structure.
  471. * @cmd contains the operation to be performed.
  472. * @arg contains the operational arguments.
  473. * Return 0 if permission is granted.
  474. * @file_set_fowner:
  475. * Save owner security information (typically from current->security) in
  476. * file->f_security for later use by the send_sigiotask hook.
  477. * @file contains the file structure to update.
  478. * Return 0 on success.
  479. * @file_send_sigiotask:
  480. * Check permission for the file owner @fown to send SIGIO or SIGURG to the
  481. * process @tsk. Note that this hook is sometimes called from interrupt.
  482. * Note that the fown_struct, @fown, is never outside the context of a
  483. * struct file, so the file structure (and associated security information)
  484. * can always be obtained:
  485. * (struct file *)((long)fown - offsetof(struct file,f_owner));
  486. * @tsk contains the structure of task receiving signal.
  487. * @fown contains the file owner information.
  488. * @sig is the signal that will be sent. When 0, kernel sends SIGIO.
  489. * Return 0 if permission is granted.
  490. * @file_receive:
  491. * This hook allows security modules to control the ability of a process
  492. * to receive an open file descriptor via socket IPC.
  493. * @file contains the file structure being received.
  494. * Return 0 if permission is granted.
  495. *
  496. * Security hooks for task operations.
  497. *
  498. * @task_create:
  499. * Check permission before creating a child process. See the clone(2)
  500. * manual page for definitions of the @clone_flags.
  501. * @clone_flags contains the flags indicating what should be shared.
  502. * Return 0 if permission is granted.
  503. * @task_alloc_security:
  504. * @p contains the task_struct for child process.
  505. * Allocate and attach a security structure to the p->security field. The
  506. * security field is initialized to NULL when the task structure is
  507. * allocated.
  508. * Return 0 if operation was successful.
  509. * @task_free_security:
  510. * @p contains the task_struct for process.
  511. * Deallocate and clear the p->security field.
  512. * @task_setuid:
  513. * Check permission before setting one or more of the user identity
  514. * attributes of the current process. The @flags parameter indicates
  515. * which of the set*uid system calls invoked this hook and how to
  516. * interpret the @id0, @id1, and @id2 parameters. See the LSM_SETID
  517. * definitions at the beginning of this file for the @flags values and
  518. * their meanings.
  519. * @id0 contains a uid.
  520. * @id1 contains a uid.
  521. * @id2 contains a uid.
  522. * @flags contains one of the LSM_SETID_* values.
  523. * Return 0 if permission is granted.
  524. * @task_post_setuid:
  525. * Update the module's state after setting one or more of the user
  526. * identity attributes of the current process. The @flags parameter
  527. * indicates which of the set*uid system calls invoked this hook. If
  528. * @flags is LSM_SETID_FS, then @old_ruid is the old fs uid and the other
  529. * parameters are not used.
  530. * @old_ruid contains the old real uid (or fs uid if LSM_SETID_FS).
  531. * @old_euid contains the old effective uid (or -1 if LSM_SETID_FS).
  532. * @old_suid contains the old saved uid (or -1 if LSM_SETID_FS).
  533. * @flags contains one of the LSM_SETID_* values.
  534. * Return 0 on success.
  535. * @task_setgid:
  536. * Check permission before setting one or more of the group identity
  537. * attributes of the current process. The @flags parameter indicates
  538. * which of the set*gid system calls invoked this hook and how to
  539. * interpret the @id0, @id1, and @id2 parameters. See the LSM_SETID
  540. * definitions at the beginning of this file for the @flags values and
  541. * their meanings.
  542. * @id0 contains a gid.
  543. * @id1 contains a gid.
  544. * @id2 contains a gid.
  545. * @flags contains one of the LSM_SETID_* values.
  546. * Return 0 if permission is granted.
  547. * @task_setpgid:
  548. * Check permission before setting the process group identifier of the
  549. * process @p to @pgid.
  550. * @p contains the task_struct for process being modified.
  551. * @pgid contains the new pgid.
  552. * Return 0 if permission is granted.
  553. * @task_getpgid:
  554. * Check permission before getting the process group identifier of the
  555. * process @p.
  556. * @p contains the task_struct for the process.
  557. * Return 0 if permission is granted.
  558. * @task_getsid:
  559. * Check permission before getting the session identifier of the process
  560. * @p.
  561. * @p contains the task_struct for the process.
  562. * Return 0 if permission is granted.
  563. * @task_setgroups:
  564. * Check permission before setting the supplementary group set of the
  565. * current process.
  566. * @group_info contains the new group information.
  567. * Return 0 if permission is granted.
  568. * @task_setnice:
  569. * Check permission before setting the nice value of @p to @nice.
  570. * @p contains the task_struct of process.
  571. * @nice contains the new nice value.
  572. * Return 0 if permission is granted.
  573. * @task_setrlimit:
  574. * Check permission before setting the resource limits of the current
  575. * process for @resource to @new_rlim. The old resource limit values can
  576. * be examined by dereferencing (current->signal->rlim + resource).
  577. * @resource contains the resource whose limit is being set.
  578. * @new_rlim contains the new limits for @resource.
  579. * Return 0 if permission is granted.
  580. * @task_setscheduler:
  581. * Check permission before setting scheduling policy and/or parameters of
  582. * process @p based on @policy and @lp.
  583. * @p contains the task_struct for process.
  584. * @policy contains the scheduling policy.
  585. * @lp contains the scheduling parameters.
  586. * Return 0 if permission is granted.
  587. * @task_getscheduler:
  588. * Check permission before obtaining scheduling information for process
  589. * @p.
  590. * @p contains the task_struct for process.
  591. * Return 0 if permission is granted.
  592. * @task_kill:
  593. * Check permission before sending signal @sig to @p. @info can be NULL,
  594. * the constant 1, or a pointer to a siginfo structure. If @info is 1 or
  595. * SI_FROMKERNEL(info) is true, then the signal should be viewed as coming
  596. * from the kernel and should typically be permitted.
  597. * SIGIO signals are handled separately by the send_sigiotask hook in
  598. * file_security_ops.
  599. * @p contains the task_struct for process.
  600. * @info contains the signal information.
  601. * @sig contains the signal value.
  602. * Return 0 if permission is granted.
  603. * @task_wait:
  604. * Check permission before allowing a process to reap a child process @p
  605. * and collect its status information.
  606. * @p contains the task_struct for process.
  607. * Return 0 if permission is granted.
  608. * @task_prctl:
  609. * Check permission before performing a process control operation on the
  610. * current process.
  611. * @option contains the operation.
  612. * @arg2 contains a argument.
  613. * @arg3 contains a argument.
  614. * @arg4 contains a argument.
  615. * @arg5 contains a argument.
  616. * Return 0 if permission is granted.
  617. * @task_reparent_to_init:
  618. * Set the security attributes in @p->security for a kernel thread that
  619. * is being reparented to the init task.
  620. * @p contains the task_struct for the kernel thread.
  621. * @task_to_inode:
  622. * Set the security attributes for an inode based on an associated task's
  623. * security attributes, e.g. for /proc/pid inodes.
  624. * @p contains the task_struct for the task.
  625. * @inode contains the inode structure for the inode.
  626. *
  627. * Security hooks for Netlink messaging.
  628. *
  629. * @netlink_send:
  630. * Save security information for a netlink message so that permission
  631. * checking can be performed when the message is processed. The security
  632. * information can be saved using the eff_cap field of the
  633. * netlink_skb_parms structure. Also may be used to provide fine
  634. * grained control over message transmission.
  635. * @sk associated sock of task sending the message.,
  636. * @skb contains the sk_buff structure for the netlink message.
  637. * Return 0 if the information was successfully saved and message
  638. * is allowed to be transmitted.
  639. * @netlink_recv:
  640. * Check permission before processing the received netlink message in
  641. * @skb.
  642. * @skb contains the sk_buff structure for the netlink message.
  643. * Return 0 if permission is granted.
  644. *
  645. * Security hooks for Unix domain networking.
  646. *
  647. * @unix_stream_connect:
  648. * Check permissions before establishing a Unix domain stream connection
  649. * between @sock and @other.
  650. * @sock contains the socket structure.
  651. * @other contains the peer socket structure.
  652. * Return 0 if permission is granted.
  653. * @unix_may_send:
  654. * Check permissions before connecting or sending datagrams from @sock to
  655. * @other.
  656. * @sock contains the socket structure.
  657. * @sock contains the peer socket structure.
  658. * Return 0 if permission is granted.
  659. *
  660. * The @unix_stream_connect and @unix_may_send hooks were necessary because
  661. * Linux provides an alternative to the conventional file name space for Unix
  662. * domain sockets. Whereas binding and connecting to sockets in the file name
  663. * space is mediated by the typical file permissions (and caught by the mknod
  664. * and permission hooks in inode_security_ops), binding and connecting to
  665. * sockets in the abstract name space is completely unmediated. Sufficient
  666. * control of Unix domain sockets in the abstract name space isn't possible
  667. * using only the socket layer hooks, since we need to know the actual target
  668. * socket, which is not looked up until we are inside the af_unix code.
  669. *
  670. * Security hooks for socket operations.
  671. *
  672. * @socket_create:
  673. * Check permissions prior to creating a new socket.
  674. * @family contains the requested protocol family.
  675. * @type contains the requested communications type.
  676. * @protocol contains the requested protocol.
  677. * @kern set to 1 if a kernel socket.
  678. * Return 0 if permission is granted.
  679. * @socket_post_create:
  680. * This hook allows a module to update or allocate a per-socket security
  681. * structure. Note that the security field was not added directly to the
  682. * socket structure, but rather, the socket security information is stored
  683. * in the associated inode. Typically, the inode alloc_security hook will
  684. * allocate and and attach security information to
  685. * sock->inode->i_security. This hook may be used to update the
  686. * sock->inode->i_security field with additional information that wasn't
  687. * available when the inode was allocated.
  688. * @sock contains the newly created socket structure.
  689. * @family contains the requested protocol family.
  690. * @type contains the requested communications type.
  691. * @protocol contains the requested protocol.
  692. * @kern set to 1 if a kernel socket.
  693. * @socket_bind:
  694. * Check permission before socket protocol layer bind operation is
  695. * performed and the socket @sock is bound to the address specified in the
  696. * @address parameter.
  697. * @sock contains the socket structure.
  698. * @address contains the address to bind to.
  699. * @addrlen contains the length of address.
  700. * Return 0 if permission is granted.
  701. * @socket_connect:
  702. * Check permission before socket protocol layer connect operation
  703. * attempts to connect socket @sock to a remote address, @address.
  704. * @sock contains the socket structure.
  705. * @address contains the address of remote endpoint.
  706. * @addrlen contains the length of address.
  707. * Return 0 if permission is granted.
  708. * @socket_listen:
  709. * Check permission before socket protocol layer listen operation.
  710. * @sock contains the socket structure.
  711. * @backlog contains the maximum length for the pending connection queue.
  712. * Return 0 if permission is granted.
  713. * @socket_accept:
  714. * Check permission before accepting a new connection. Note that the new
  715. * socket, @newsock, has been created and some information copied to it,
  716. * but the accept operation has not actually been performed.
  717. * @sock contains the listening socket structure.
  718. * @newsock contains the newly created server socket for connection.
  719. * Return 0 if permission is granted.
  720. * @socket_post_accept:
  721. * This hook allows a security module to copy security
  722. * information into the newly created socket's inode.
  723. * @sock contains the listening socket structure.
  724. * @newsock contains the newly created server socket for connection.
  725. * @socket_sendmsg:
  726. * Check permission before transmitting a message to another socket.
  727. * @sock contains the socket structure.
  728. * @msg contains the message to be transmitted.
  729. * @size contains the size of message.
  730. * Return 0 if permission is granted.
  731. * @socket_recvmsg:
  732. * Check permission before receiving a message from a socket.
  733. * @sock contains the socket structure.
  734. * @msg contains the message structure.
  735. * @size contains the size of message structure.
  736. * @flags contains the operational flags.
  737. * Return 0 if permission is granted.
  738. * @socket_getsockname:
  739. * Check permission before the local address (name) of the socket object
  740. * @sock is retrieved.
  741. * @sock contains the socket structure.
  742. * Return 0 if permission is granted.
  743. * @socket_getpeername:
  744. * Check permission before the remote address (name) of a socket object
  745. * @sock is retrieved.
  746. * @sock contains the socket structure.
  747. * Return 0 if permission is granted.
  748. * @socket_getsockopt:
  749. * Check permissions before retrieving the options associated with socket
  750. * @sock.
  751. * @sock contains the socket structure.
  752. * @level contains the protocol level to retrieve option from.
  753. * @optname contains the name of option to retrieve.
  754. * Return 0 if permission is granted.
  755. * @socket_setsockopt:
  756. * Check permissions before setting the options associated with socket
  757. * @sock.
  758. * @sock contains the socket structure.
  759. * @level contains the protocol level to set options for.
  760. * @optname contains the name of the option to set.
  761. * Return 0 if permission is granted.
  762. * @socket_shutdown:
  763. * Checks permission before all or part of a connection on the socket
  764. * @sock is shut down.
  765. * @sock contains the socket structure.
  766. * @how contains the flag indicating how future sends and receives are handled.
  767. * Return 0 if permission is granted.
  768. * @socket_sock_rcv_skb:
  769. * Check permissions on incoming network packets. This hook is distinct
  770. * from Netfilter's IP input hooks since it is the first time that the
  771. * incoming sk_buff @skb has been associated with a particular socket, @sk.
  772. * @sk contains the sock (not socket) associated with the incoming sk_buff.
  773. * @skb contains the incoming network data.
  774. * @socket_getpeersec:
  775. * This hook allows the security module to provide peer socket security
  776. * state to userspace via getsockopt SO_GETPEERSEC.
  777. * @sock is the local socket.
  778. * @optval userspace memory where the security state is to be copied.
  779. * @optlen userspace int where the module should copy the actual length
  780. * of the security state.
  781. * @len as input is the maximum length to copy to userspace provided
  782. * by the caller.
  783. * Return 0 if all is well, otherwise, typical getsockopt return
  784. * values.
  785. * @sk_alloc_security:
  786. * Allocate and attach a security structure to the sk->sk_security field,
  787. * which is used to copy security attributes between local stream sockets.
  788. * @sk_free_security:
  789. * Deallocate security structure.
  790. *
  791. * Security hooks affecting all System V IPC operations.
  792. *
  793. * @ipc_permission:
  794. * Check permissions for access to IPC
  795. * @ipcp contains the kernel IPC permission structure
  796. * @flag contains the desired (requested) permission set
  797. * Return 0 if permission is granted.
  798. *
  799. * Security hooks for individual messages held in System V IPC message queues
  800. * @msg_msg_alloc_security:
  801. * Allocate and attach a security structure to the msg->security field.
  802. * The security field is initialized to NULL when the structure is first
  803. * created.
  804. * @msg contains the message structure to be modified.
  805. * Return 0 if operation was successful and permission is granted.
  806. * @msg_msg_free_security:
  807. * Deallocate the security structure for this message.
  808. * @msg contains the message structure to be modified.
  809. *
  810. * Security hooks for System V IPC Message Queues
  811. *
  812. * @msg_queue_alloc_security:
  813. * Allocate and attach a security structure to the
  814. * msq->q_perm.security field. The security field is initialized to
  815. * NULL when the structure is first created.
  816. * @msq contains the message queue structure to be modified.
  817. * Return 0 if operation was successful and permission is granted.
  818. * @msg_queue_free_security:
  819. * Deallocate security structure for this message queue.
  820. * @msq contains the message queue structure to be modified.
  821. * @msg_queue_associate:
  822. * Check permission when a message queue is requested through the
  823. * msgget system call. This hook is only called when returning the
  824. * message queue identifier for an existing message queue, not when a
  825. * new message queue is created.
  826. * @msq contains the message queue to act upon.
  827. * @msqflg contains the operation control flags.
  828. * Return 0 if permission is granted.
  829. * @msg_queue_msgctl:
  830. * Check permission when a message control operation specified by @cmd
  831. * is to be performed on the message queue @msq.
  832. * The @msq may be NULL, e.g. for IPC_INFO or MSG_INFO.
  833. * @msq contains the message queue to act upon. May be NULL.
  834. * @cmd contains the operation to be performed.
  835. * Return 0 if permission is granted.
  836. * @msg_queue_msgsnd:
  837. * Check permission before a message, @msg, is enqueued on the message
  838. * queue, @msq.
  839. * @msq contains the message queue to send message to.
  840. * @msg contains the message to be enqueued.
  841. * @msqflg contains operational flags.
  842. * Return 0 if permission is granted.
  843. * @msg_queue_msgrcv:
  844. * Check permission before a message, @msg, is removed from the message
  845. * queue, @msq. The @target task structure contains a pointer to the
  846. * process that will be receiving the message (not equal to the current
  847. * process when inline receives are being performed).
  848. * @msq contains the message queue to retrieve message from.
  849. * @msg contains the message destination.
  850. * @target contains the task structure for recipient process.
  851. * @type contains the type of message requested.
  852. * @mode contains the operational flags.
  853. * Return 0 if permission is granted.
  854. *
  855. * Security hooks for System V Shared Memory Segments
  856. *
  857. * @shm_alloc_security:
  858. * Allocate and attach a security structure to the shp->shm_perm.security
  859. * field. The security field is initialized to NULL when the structure is
  860. * first created.
  861. * @shp contains the shared memory structure to be modified.
  862. * Return 0 if operation was successful and permission is granted.
  863. * @shm_free_security:
  864. * Deallocate the security struct for this memory segment.
  865. * @shp contains the shared memory structure to be modified.
  866. * @shm_associate:
  867. * Check permission when a shared memory region is requested through the
  868. * shmget system call. This hook is only called when returning the shared
  869. * memory region identifier for an existing region, not when a new shared
  870. * memory region is created.
  871. * @shp contains the shared memory structure to be modified.
  872. * @shmflg contains the operation control flags.
  873. * Return 0 if permission is granted.
  874. * @shm_shmctl:
  875. * Check permission when a shared memory control operation specified by
  876. * @cmd is to be performed on the shared memory region @shp.
  877. * The @shp may be NULL, e.g. for IPC_INFO or SHM_INFO.
  878. * @shp contains shared memory structure to be modified.
  879. * @cmd contains the operation to be performed.
  880. * Return 0 if permission is granted.
  881. * @shm_shmat:
  882. * Check permissions prior to allowing the shmat system call to attach the
  883. * shared memory segment @shp to the data segment of the calling process.
  884. * The attaching address is specified by @shmaddr.
  885. * @shp contains the shared memory structure to be modified.
  886. * @shmaddr contains the address to attach memory region to.
  887. * @shmflg contains the operational flags.
  888. * Return 0 if permission is granted.
  889. *
  890. * Security hooks for System V Semaphores
  891. *
  892. * @sem_alloc_security:
  893. * Allocate and attach a security structure to the sma->sem_perm.security
  894. * field. The security field is initialized to NULL when the structure is
  895. * first created.
  896. * @sma contains the semaphore structure
  897. * Return 0 if operation was successful and permission is granted.
  898. * @sem_free_security:
  899. * deallocate security struct for this semaphore
  900. * @sma contains the semaphore structure.
  901. * @sem_associate:
  902. * Check permission when a semaphore is requested through the semget
  903. * system call. This hook is only called when returning the semaphore
  904. * identifier for an existing semaphore, not when a new one must be
  905. * created.
  906. * @sma contains the semaphore structure.
  907. * @semflg contains the operation control flags.
  908. * Return 0 if permission is granted.
  909. * @sem_semctl:
  910. * Check permission when a semaphore operation specified by @cmd is to be
  911. * performed on the semaphore @sma. The @sma may be NULL, e.g. for
  912. * IPC_INFO or SEM_INFO.
  913. * @sma contains the semaphore structure. May be NULL.
  914. * @cmd contains the operation to be performed.
  915. * Return 0 if permission is granted.
  916. * @sem_semop
  917. * Check permissions before performing operations on members of the
  918. * semaphore set @sma. If the @alter flag is nonzero, the semaphore set
  919. * may be modified.
  920. * @sma contains the semaphore structure.
  921. * @sops contains the operations to perform.
  922. * @nsops contains the number of operations to perform.
  923. * @alter contains the flag indicating whether changes are to be made.
  924. * Return 0 if permission is granted.
  925. *
  926. * @ptrace:
  927. * Check permission before allowing the @parent process to trace the
  928. * @child process.
  929. * Security modules may also want to perform a process tracing check
  930. * during an execve in the set_security or apply_creds hooks of
  931. * binprm_security_ops if the process is being traced and its security
  932. * attributes would be changed by the execve.
  933. * @parent contains the task_struct structure for parent process.
  934. * @child contains the task_struct structure for child process.
  935. * Return 0 if permission is granted.
  936. * @capget:
  937. * Get the @effective, @inheritable, and @permitted capability sets for
  938. * the @target process. The hook may also perform permission checking to
  939. * determine if the current process is allowed to see the capability sets
  940. * of the @target process.
  941. * @target contains the task_struct structure for target process.
  942. * @effective contains the effective capability set.
  943. * @inheritable contains the inheritable capability set.
  944. * @permitted contains the permitted capability set.
  945. * Return 0 if the capability sets were successfully obtained.
  946. * @capset_check:
  947. * Check permission before setting the @effective, @inheritable, and
  948. * @permitted capability sets for the @target process.
  949. * Caveat: @target is also set to current if a set of processes is
  950. * specified (i.e. all processes other than current and init or a
  951. * particular process group). Hence, the capset_set hook may need to
  952. * revalidate permission to the actual target process.
  953. * @target contains the task_struct structure for target process.
  954. * @effective contains the effective capability set.
  955. * @inheritable contains the inheritable capability set.
  956. * @permitted contains the permitted capability set.
  957. * Return 0 if permission is granted.
  958. * @capset_set:
  959. * Set the @effective, @inheritable, and @permitted capability sets for
  960. * the @target process. Since capset_check cannot always check permission
  961. * to the real @target process, this hook may also perform permission
  962. * checking to determine if the current process is allowed to set the
  963. * capability sets of the @target process. However, this hook has no way
  964. * of returning an error due to the structure of the sys_capset code.
  965. * @target contains the task_struct structure for target process.
  966. * @effective contains the effective capability set.
  967. * @inheritable contains the inheritable capability set.
  968. * @permitted contains the permitted capability set.
  969. * @acct:
  970. * Check permission before enabling or disabling process accounting. If
  971. * accounting is being enabled, then @file refers to the open file used to
  972. * store accounting records. If accounting is being disabled, then @file
  973. * is NULL.
  974. * @file contains the file structure for the accounting file (may be NULL).
  975. * Return 0 if permission is granted.
  976. * @sysctl:
  977. * Check permission before accessing the @table sysctl variable in the
  978. * manner specified by @op.
  979. * @table contains the ctl_table structure for the sysctl variable.
  980. * @op contains the operation (001 = search, 002 = write, 004 = read).
  981. * Return 0 if permission is granted.
  982. * @capable:
  983. * Check whether the @tsk process has the @cap capability.
  984. * @tsk contains the task_struct for the process.
  985. * @cap contains the capability <include/linux/capability.h>.
  986. * Return 0 if the capability is granted for @tsk.
  987. * @syslog:
  988. * Check permission before accessing the kernel message ring or changing
  989. * logging to the console.
  990. * See the syslog(2) manual page for an explanation of the @type values.
  991. * @type contains the type of action.
  992. * Return 0 if permission is granted.
  993. * @settime:
  994. * Check permission to change the system time.
  995. * struct timespec and timezone are defined in include/linux/time.h
  996. * @ts contains new time
  997. * @tz contains new timezone
  998. * Return 0 if permission is granted.
  999. * @vm_enough_memory:
  1000. * Check permissions for allocating a new virtual mapping.
  1001. * @pages contains the number of pages.
  1002. * Return 0 if permission is granted.
  1003. *
  1004. * @register_security:
  1005. * allow module stacking.
  1006. * @name contains the name of the security module being stacked.
  1007. * @ops contains a pointer to the struct security_operations of the module to stack.
  1008. * @unregister_security:
  1009. * remove a stacked module.
  1010. * @name contains the name of the security module being unstacked.
  1011. * @ops contains a pointer to the struct security_operations of the module to unstack.
  1012. *
  1013. * This is the main security structure.
  1014. */
  1015. struct security_operations {
  1016. int (*ptrace) (struct task_struct * parent, struct task_struct * child);
  1017. int (*capget) (struct task_struct * target,
  1018. kernel_cap_t * effective,
  1019. kernel_cap_t * inheritable, kernel_cap_t * permitted);
  1020. int (*capset_check) (struct task_struct * target,
  1021. kernel_cap_t * effective,
  1022. kernel_cap_t * inheritable,
  1023. kernel_cap_t * permitted);
  1024. void (*capset_set) (struct task_struct * target,
  1025. kernel_cap_t * effective,
  1026. kernel_cap_t * inheritable,
  1027. kernel_cap_t * permitted);
  1028. int (*acct) (struct file * file);
  1029. int (*sysctl) (struct ctl_table * table, int op);
  1030. int (*capable) (struct task_struct * tsk, int cap);
  1031. int (*quotactl) (int cmds, int type, int id, struct super_block * sb);
  1032. int (*quota_on) (struct dentry * dentry);
  1033. int (*syslog) (int type);
  1034. int (*settime) (struct timespec *ts, struct timezone *tz);
  1035. int (*vm_enough_memory) (long pages);
  1036. int (*bprm_alloc_security) (struct linux_binprm * bprm);
  1037. void (*bprm_free_security) (struct linux_binprm * bprm);
  1038. void (*bprm_apply_creds) (struct linux_binprm * bprm, int unsafe);
  1039. void (*bprm_post_apply_creds) (struct linux_binprm * bprm);
  1040. int (*bprm_set_security) (struct linux_binprm * bprm);
  1041. int (*bprm_check_security) (struct linux_binprm * bprm);
  1042. int (*bprm_secureexec) (struct linux_binprm * bprm);
  1043. int (*sb_alloc_security) (struct super_block * sb);
  1044. void (*sb_free_security) (struct super_block * sb);
  1045. int (*sb_copy_data)(struct file_system_type *type,
  1046. void *orig, void *copy);
  1047. int (*sb_kern_mount) (struct super_block *sb, void *data);
  1048. int (*sb_statfs) (struct super_block * sb);
  1049. int (*sb_mount) (char *dev_name, struct nameidata * nd,
  1050. char *type, unsigned long flags, void *data);
  1051. int (*sb_check_sb) (struct vfsmount * mnt, struct nameidata * nd);
  1052. int (*sb_umount) (struct vfsmount * mnt, int flags);
  1053. void (*sb_umount_close) (struct vfsmount * mnt);
  1054. void (*sb_umount_busy) (struct vfsmount * mnt);
  1055. void (*sb_post_remount) (struct vfsmount * mnt,
  1056. unsigned long flags, void *data);
  1057. void (*sb_post_mountroot) (void);
  1058. void (*sb_post_addmount) (struct vfsmount * mnt,
  1059. struct nameidata * mountpoint_nd);
  1060. int (*sb_pivotroot) (struct nameidata * old_nd,
  1061. struct nameidata * new_nd);
  1062. void (*sb_post_pivotroot) (struct nameidata * old_nd,
  1063. struct nameidata * new_nd);
  1064. int (*inode_alloc_security) (struct inode *inode);
  1065. void (*inode_free_security) (struct inode *inode);
  1066. int (*inode_create) (struct inode *dir,
  1067. struct dentry *dentry, int mode);
  1068. void (*inode_post_create) (struct inode *dir,
  1069. struct dentry *dentry, int mode);
  1070. int (*inode_link) (struct dentry *old_dentry,
  1071. struct inode *dir, struct dentry *new_dentry);
  1072. void (*inode_post_link) (struct dentry *old_dentry,
  1073. struct inode *dir, struct dentry *new_dentry);
  1074. int (*inode_unlink) (struct inode *dir, struct dentry *dentry);
  1075. int (*inode_symlink) (struct inode *dir,
  1076. struct dentry *dentry, const char *old_name);
  1077. void (*inode_post_symlink) (struct inode *dir,
  1078. struct dentry *dentry,
  1079. const char *old_name);
  1080. int (*inode_mkdir) (struct inode *dir, struct dentry *dentry, int mode);
  1081. void (*inode_post_mkdir) (struct inode *dir, struct dentry *dentry,
  1082. int mode);
  1083. int (*inode_rmdir) (struct inode *dir, struct dentry *dentry);
  1084. int (*inode_mknod) (struct inode *dir, struct dentry *dentry,
  1085. int mode, dev_t dev);
  1086. void (*inode_post_mknod) (struct inode *dir, struct dentry *dentry,
  1087. int mode, dev_t dev);
  1088. int (*inode_rename) (struct inode *old_dir, struct dentry *old_dentry,
  1089. struct inode *new_dir, struct dentry *new_dentry);
  1090. void (*inode_post_rename) (struct inode *old_dir,
  1091. struct dentry *old_dentry,
  1092. struct inode *new_dir,
  1093. struct dentry *new_dentry);
  1094. int (*inode_readlink) (struct dentry *dentry);
  1095. int (*inode_follow_link) (struct dentry *dentry, struct nameidata *nd);
  1096. int (*inode_permission) (struct inode *inode, int mask, struct nameidata *nd);
  1097. int (*inode_setattr) (struct dentry *dentry, struct iattr *attr);
  1098. int (*inode_getattr) (struct vfsmount *mnt, struct dentry *dentry);
  1099. void (*inode_delete) (struct inode *inode);
  1100. int (*inode_setxattr) (struct dentry *dentry, char *name, void *value,
  1101. size_t size, int flags);
  1102. void (*inode_post_setxattr) (struct dentry *dentry, char *name, void *value,
  1103. size_t size, int flags);
  1104. int (*inode_getxattr) (struct dentry *dentry, char *name);
  1105. int (*inode_listxattr) (struct dentry *dentry);
  1106. int (*inode_removexattr) (struct dentry *dentry, char *name);
  1107. int (*inode_getsecurity)(struct inode *inode, const char *name, void *buffer, size_t size);
  1108. int (*inode_setsecurity)(struct inode *inode, const char *name, const void *value, size_t size, int flags);
  1109. int (*inode_listsecurity)(struct inode *inode, char *buffer, size_t buffer_size);
  1110. int (*file_permission) (struct file * file, int mask);
  1111. int (*file_alloc_security) (struct file * file);
  1112. void (*file_free_security) (struct file * file);
  1113. int (*file_ioctl) (struct file * file, unsigned int cmd,
  1114. unsigned long arg);
  1115. int (*file_mmap) (struct file * file,
  1116. unsigned long reqprot,
  1117. unsigned long prot, unsigned long flags);
  1118. int (*file_mprotect) (struct vm_area_struct * vma,
  1119. unsigned long reqprot,
  1120. unsigned long prot);
  1121. int (*file_lock) (struct file * file, unsigned int cmd);
  1122. int (*file_fcntl) (struct file * file, unsigned int cmd,
  1123. unsigned long arg);
  1124. int (*file_set_fowner) (struct file * file);
  1125. int (*file_send_sigiotask) (struct task_struct * tsk,
  1126. struct fown_struct * fown, int sig);
  1127. int (*file_receive) (struct file * file);
  1128. int (*task_create) (unsigned long clone_flags);
  1129. int (*task_alloc_security) (struct task_struct * p);
  1130. void (*task_free_security) (struct task_struct * p);
  1131. int (*task_setuid) (uid_t id0, uid_t id1, uid_t id2, int flags);
  1132. int (*task_post_setuid) (uid_t old_ruid /* or fsuid */ ,
  1133. uid_t old_euid, uid_t old_suid, int flags);
  1134. int (*task_setgid) (gid_t id0, gid_t id1, gid_t id2, int flags);
  1135. int (*task_setpgid) (struct task_struct * p, pid_t pgid);
  1136. int (*task_getpgid) (struct task_struct * p);
  1137. int (*task_getsid) (struct task_struct * p);
  1138. int (*task_setgroups) (struct group_info *group_info);
  1139. int (*task_setnice) (struct task_struct * p, int nice);
  1140. int (*task_setrlimit) (unsigned int resource, struct rlimit * new_rlim);
  1141. int (*task_setscheduler) (struct task_struct * p, int policy,
  1142. struct sched_param * lp);
  1143. int (*task_getscheduler) (struct task_struct * p);
  1144. int (*task_kill) (struct task_struct * p,
  1145. struct siginfo * info, int sig);
  1146. int (*task_wait) (struct task_struct * p);
  1147. int (*task_prctl) (int option, unsigned long arg2,
  1148. unsigned long arg3, unsigned long arg4,
  1149. unsigned long arg5);
  1150. void (*task_reparent_to_init) (struct task_struct * p);
  1151. void (*task_to_inode)(struct task_struct *p, struct inode *inode);
  1152. int (*ipc_permission) (struct kern_ipc_perm * ipcp, short flag);
  1153. int (*msg_msg_alloc_security) (struct msg_msg * msg);
  1154. void (*msg_msg_free_security) (struct msg_msg * msg);
  1155. int (*msg_queue_alloc_security) (struct msg_queue * msq);
  1156. void (*msg_queue_free_security) (struct msg_queue * msq);
  1157. int (*msg_queue_associate) (struct msg_queue * msq, int msqflg);
  1158. int (*msg_queue_msgctl) (struct msg_queue * msq, int cmd);
  1159. int (*msg_queue_msgsnd) (struct msg_queue * msq,
  1160. struct msg_msg * msg, int msqflg);
  1161. int (*msg_queue_msgrcv) (struct msg_queue * msq,
  1162. struct msg_msg * msg,
  1163. struct task_struct * target,
  1164. long type, int mode);
  1165. int (*shm_alloc_security) (struct shmid_kernel * shp);
  1166. void (*shm_free_security) (struct shmid_kernel * shp);
  1167. int (*shm_associate) (struct shmid_kernel * shp, int shmflg);
  1168. int (*shm_shmctl) (struct shmid_kernel * shp, int cmd);
  1169. int (*shm_shmat) (struct shmid_kernel * shp,
  1170. char __user *shmaddr, int shmflg);
  1171. int (*sem_alloc_security) (struct sem_array * sma);
  1172. void (*sem_free_security) (struct sem_array * sma);
  1173. int (*sem_associate) (struct sem_array * sma, int semflg);
  1174. int (*sem_semctl) (struct sem_array * sma, int cmd);
  1175. int (*sem_semop) (struct sem_array * sma,
  1176. struct sembuf * sops, unsigned nsops, int alter);
  1177. int (*netlink_send) (struct sock * sk, struct sk_buff * skb);
  1178. int (*netlink_recv) (struct sk_buff * skb);
  1179. /* allow module stacking */
  1180. int (*register_security) (const char *name,
  1181. struct security_operations *ops);
  1182. int (*unregister_security) (const char *name,
  1183. struct security_operations *ops);
  1184. void (*d_instantiate) (struct dentry *dentry, struct inode *inode);
  1185. int (*getprocattr)(struct task_struct *p, char *name, void *value, size_t size);
  1186. int (*setprocattr)(struct task_struct *p, char *name, void *value, size_t size);
  1187. #ifdef CONFIG_SECURITY_NETWORK
  1188. int (*unix_stream_connect) (struct socket * sock,
  1189. struct socket * other, struct sock * newsk);
  1190. int (*unix_may_send) (struct socket * sock, struct socket * other);
  1191. int (*socket_create) (int family, int type, int protocol, int kern);
  1192. void (*socket_post_create) (struct socket * sock, int family,
  1193. int type, int protocol, int kern);
  1194. int (*socket_bind) (struct socket * sock,
  1195. struct sockaddr * address, int addrlen);
  1196. int (*socket_connect) (struct socket * sock,
  1197. struct sockaddr * address, int addrlen);
  1198. int (*socket_listen) (struct socket * sock, int backlog);
  1199. int (*socket_accept) (struct socket * sock, struct socket * newsock);
  1200. void (*socket_post_accept) (struct socket * sock,
  1201. struct socket * newsock);
  1202. int (*socket_sendmsg) (struct socket * sock,
  1203. struct msghdr * msg, int size);
  1204. int (*socket_recvmsg) (struct socket * sock,
  1205. struct msghdr * msg, int size, int flags);
  1206. int (*socket_getsockname) (struct socket * sock);
  1207. int (*socket_getpeername) (struct socket * sock);
  1208. int (*socket_getsockopt) (struct socket * sock, int level, int optname);
  1209. int (*socket_setsockopt) (struct socket * sock, int level, int optname);
  1210. int (*socket_shutdown) (struct socket * sock, int how);
  1211. int (*socket_sock_rcv_skb) (struct sock * sk, struct sk_buff * skb);
  1212. int (*socket_getpeersec) (struct socket *sock, char __user *optval, int __user *optlen, unsigned len);
  1213. int (*sk_alloc_security) (struct sock *sk, int family, int priority);
  1214. void (*sk_free_security) (struct sock *sk);
  1215. #endif /* CONFIG_SECURITY_NETWORK */
  1216. };
  1217. /* global variables */
  1218. extern struct security_operations *security_ops;
  1219. /* inline stuff */
  1220. static inline int security_ptrace (struct task_struct * parent, struct task_struct * child)
  1221. {
  1222. return security_ops->ptrace (parent, child);
  1223. }
  1224. static inline int security_capget (struct task_struct *target,
  1225. kernel_cap_t *effective,
  1226. kernel_cap_t *inheritable,
  1227. kernel_cap_t *permitted)
  1228. {
  1229. return security_ops->capget (target, effective, inheritable, permitted);
  1230. }
  1231. static inline int security_capset_check (struct task_struct *target,
  1232. kernel_cap_t *effective,
  1233. kernel_cap_t *inheritable,
  1234. kernel_cap_t *permitted)
  1235. {
  1236. return security_ops->capset_check (target, effective, inheritable, permitted);
  1237. }
  1238. static inline void security_capset_set (struct task_struct *target,
  1239. kernel_cap_t *effective,
  1240. kernel_cap_t *inheritable,
  1241. kernel_cap_t *permitted)
  1242. {
  1243. security_ops->capset_set (target, effective, inheritable, permitted);
  1244. }
  1245. static inline int security_acct (struct file *file)
  1246. {
  1247. return security_ops->acct (file);
  1248. }
  1249. static inline int security_sysctl(struct ctl_table *table, int op)
  1250. {
  1251. return security_ops->sysctl(table, op);
  1252. }
  1253. static inline int security_quotactl (int cmds, int type, int id,
  1254. struct super_block *sb)
  1255. {
  1256. return security_ops->quotactl (cmds, type, id, sb);
  1257. }
  1258. static inline int security_quota_on (struct dentry * dentry)
  1259. {
  1260. return security_ops->quota_on (dentry);
  1261. }
  1262. static inline int security_syslog(int type)
  1263. {
  1264. return security_ops->syslog(type);
  1265. }
  1266. static inline int security_settime(struct timespec *ts, struct timezone *tz)
  1267. {
  1268. return security_ops->settime(ts, tz);
  1269. }
  1270. static inline int security_vm_enough_memory(long pages)
  1271. {
  1272. return security_ops->vm_enough_memory(pages);
  1273. }
  1274. static inline int security_bprm_alloc (struct linux_binprm *bprm)
  1275. {
  1276. return security_ops->bprm_alloc_security (bprm);
  1277. }
  1278. static inline void security_bprm_free (struct linux_binprm *bprm)
  1279. {
  1280. security_ops->bprm_free_security (bprm);
  1281. }
  1282. static inline void security_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
  1283. {
  1284. security_ops->bprm_apply_creds (bprm, unsafe);
  1285. }
  1286. static inline void security_bprm_post_apply_creds (struct linux_binprm *bprm)
  1287. {
  1288. security_ops->bprm_post_apply_creds (bprm);
  1289. }
  1290. static inline int security_bprm_set (struct linux_binprm *bprm)
  1291. {
  1292. return security_ops->bprm_set_security (bprm);
  1293. }
  1294. static inline int security_bprm_check (struct linux_binprm *bprm)
  1295. {
  1296. return security_ops->bprm_check_security (bprm);
  1297. }
  1298. static inline int security_bprm_secureexec (struct linux_binprm *bprm)
  1299. {
  1300. return security_ops->bprm_secureexec (bprm);
  1301. }
  1302. static inline int security_sb_alloc (struct super_block *sb)
  1303. {
  1304. return security_ops->sb_alloc_security (sb);
  1305. }
  1306. static inline void security_sb_free (struct super_block *sb)
  1307. {
  1308. security_ops->sb_free_security (sb);
  1309. }
  1310. static inline int security_sb_copy_data (struct file_system_type *type,
  1311. void *orig, void *copy)
  1312. {
  1313. return security_ops->sb_copy_data (type, orig, copy);
  1314. }
  1315. static inline int security_sb_kern_mount (struct super_block *sb, void *data)
  1316. {
  1317. return security_ops->sb_kern_mount (sb, data);
  1318. }
  1319. static inline int security_sb_statfs (struct super_block *sb)
  1320. {
  1321. return security_ops->sb_statfs (sb);
  1322. }
  1323. static inline int security_sb_mount (char *dev_name, struct nameidata *nd,
  1324. char *type, unsigned long flags,
  1325. void *data)
  1326. {
  1327. return security_ops->sb_mount (dev_name, nd, type, flags, data);
  1328. }
  1329. static inline int security_sb_check_sb (struct vfsmount *mnt,
  1330. struct nameidata *nd)
  1331. {
  1332. return security_ops->sb_check_sb (mnt, nd);
  1333. }
  1334. static inline int security_sb_umount (struct vfsmount *mnt, int flags)
  1335. {
  1336. return security_ops->sb_umount (mnt, flags);
  1337. }
  1338. static inline void security_sb_umount_close (struct vfsmount *mnt)
  1339. {
  1340. security_ops->sb_umount_close (mnt);
  1341. }
  1342. static inline void security_sb_umount_busy (struct vfsmount *mnt)
  1343. {
  1344. security_ops->sb_umount_busy (mnt);
  1345. }
  1346. static inline void security_sb_post_remount (struct vfsmount *mnt,
  1347. unsigned long flags, void *data)
  1348. {
  1349. security_ops->sb_post_remount (mnt, flags, data);
  1350. }
  1351. static inline void security_sb_post_mountroot (void)
  1352. {
  1353. security_ops->sb_post_mountroot ();
  1354. }
  1355. static inline void security_sb_post_addmount (struct vfsmount *mnt,
  1356. struct nameidata *mountpoint_nd)
  1357. {
  1358. security_ops->sb_post_addmount (mnt, mountpoint_nd);
  1359. }
  1360. static inline int security_sb_pivotroot (struct nameidata *old_nd,
  1361. struct nameidata *new_nd)
  1362. {
  1363. return security_ops->sb_pivotroot (old_nd, new_nd);
  1364. }
  1365. static inline void security_sb_post_pivotroot (struct nameidata *old_nd,
  1366. struct nameidata *new_nd)
  1367. {
  1368. security_ops->sb_post_pivotroot (old_nd, new_nd);
  1369. }
  1370. static inline int security_inode_alloc (struct inode *inode)
  1371. {
  1372. if (unlikely (IS_PRIVATE (inode)))
  1373. return 0;
  1374. return security_ops->inode_alloc_security (inode);
  1375. }
  1376. static inline void security_inode_free (struct inode *inode)
  1377. {
  1378. if (unlikely (IS_PRIVATE (inode)))
  1379. return;
  1380. security_ops->inode_free_security (inode);
  1381. }
  1382. static inline int security_inode_create (struct inode *dir,
  1383. struct dentry *dentry,
  1384. int mode)
  1385. {
  1386. if (unlikely (IS_PRIVATE (dir)))
  1387. return 0;
  1388. return security_ops->inode_create (dir, dentry, mode);
  1389. }
  1390. static inline void security_inode_post_create (struct inode *dir,
  1391. struct dentry *dentry,
  1392. int mode)
  1393. {
  1394. if (dentry->d_inode && unlikely (IS_PRIVATE (dentry->d_inode)))
  1395. return;
  1396. security_ops->inode_post_create (dir, dentry, mode);
  1397. }
  1398. static inline int security_inode_link (struct dentry *old_dentry,
  1399. struct inode *dir,
  1400. struct dentry *new_dentry)
  1401. {
  1402. if (unlikely (IS_PRIVATE (old_dentry->d_inode)))
  1403. return 0;
  1404. return security_ops->inode_link (old_dentry, dir, new_dentry);
  1405. }
  1406. static inline void security_inode_post_link (struct dentry *old_dentry,
  1407. struct inode *dir,
  1408. struct dentry *new_dentry)
  1409. {
  1410. if (new_dentry->d_inode && unlikely (IS_PRIVATE (new_dentry->d_inode)))
  1411. return;
  1412. security_ops->inode_post_link (old_dentry, dir, new_dentry);
  1413. }
  1414. static inline int security_inode_unlink (struct inode *dir,
  1415. struct dentry *dentry)
  1416. {
  1417. if (unlikely (IS_PRIVATE (dentry->d_inode)))
  1418. return 0;
  1419. return security_ops->inode_unlink (dir, dentry);
  1420. }
  1421. static inline int security_inode_symlink (struct inode *dir,
  1422. struct dentry *dentry,
  1423. const char *old_name)
  1424. {
  1425. if (unlikely (IS_PRIVATE (dir)))
  1426. return 0;
  1427. return security_ops->inode_symlink (dir, dentry, old_name);
  1428. }
  1429. static inline void security_inode_post_symlink (struct inode *dir,
  1430. struct dentry *dentry,
  1431. const char *old_name)
  1432. {
  1433. if (dentry->d_inode && unlikely (IS_PRIVATE (dentry->d_inode)))
  1434. return;
  1435. security_ops->inode_post_symlink (dir, dentry, old_name);
  1436. }
  1437. static inline int security_inode_mkdir (struct inode *dir,
  1438. struct dentry *dentry,
  1439. int mode)
  1440. {
  1441. if (unlikely (IS_PRIVATE (dir)))
  1442. return 0;
  1443. return security_ops->inode_mkdir (dir, dentry, mode);
  1444. }
  1445. static inline void security_inode_post_mkdir (struct inode *dir,
  1446. struct dentry *dentry,
  1447. int mode)
  1448. {
  1449. if (dentry->d_inode && unlikely (IS_PRIVATE (dentry->d_inode)))
  1450. return;
  1451. security_ops->inode_post_mkdir (dir, dentry, mode);
  1452. }
  1453. static inline int security_inode_rmdir (struct inode *dir,
  1454. struct dentry *dentry)
  1455. {
  1456. if (unlikely (IS_PRIVATE (dentry->d_inode)))
  1457. return 0;
  1458. return security_ops->inode_rmdir (dir, dentry);
  1459. }
  1460. static inline int security_inode_mknod (struct inode *dir,
  1461. struct dentry *dentry,
  1462. int mode, dev_t dev)
  1463. {
  1464. if (unlikely (IS_PRIVATE (dir)))
  1465. return 0;
  1466. return security_ops->inode_mknod (dir, dentry, mode, dev);
  1467. }
  1468. static inline void security_inode_post_mknod (struct inode *dir,
  1469. struct dentry *dentry,
  1470. int mode, dev_t dev)
  1471. {
  1472. if (dentry->d_inode && unlikely (IS_PRIVATE (dentry->d_inode)))
  1473. return;
  1474. security_ops->inode_post_mknod (dir, dentry, mode, dev);
  1475. }
  1476. static inline int security_inode_rename (struct inode *old_dir,
  1477. struct dentry *old_dentry,
  1478. struct inode *new_dir,
  1479. struct dentry *new_dentry)
  1480. {
  1481. if (unlikely (IS_PRIVATE (old_dentry->d_inode) ||
  1482. (new_dentry->d_inode && IS_PRIVATE (new_dentry->d_inode))))
  1483. return 0;
  1484. return security_ops->inode_rename (old_dir, old_dentry,
  1485. new_dir, new_dentry);
  1486. }
  1487. static inline void security_inode_post_rename (struct inode *old_dir,
  1488. struct dentry *old_dentry,
  1489. struct inode *new_dir,
  1490. struct dentry *new_dentry)
  1491. {
  1492. if (unlikely (IS_PRIVATE (old_dentry->d_inode) ||
  1493. (new_dentry->d_inode && IS_PRIVATE (new_dentry->d_inode))))
  1494. return;
  1495. security_ops->inode_post_rename (old_dir, old_dentry,
  1496. new_dir, new_dentry);
  1497. }
  1498. static inline int security_inode_readlink (struct dentry *dentry)
  1499. {
  1500. if (unlikely (IS_PRIVATE (dentry->d_inode)))
  1501. return 0;
  1502. return security_ops->inode_readlink (dentry);
  1503. }
  1504. static inline int security_inode_follow_link (struct dentry *dentry,
  1505. struct nameidata *nd)
  1506. {
  1507. if (unlikely (IS_PRIVATE (dentry->d_inode)))
  1508. return 0;
  1509. return security_ops->inode_follow_link (dentry, nd);
  1510. }
  1511. static inline int security_inode_permission (struct inode *inode, int mask,
  1512. struct nameidata *nd)
  1513. {
  1514. if (unlikely (IS_PRIVATE (inode)))
  1515. return 0;
  1516. return security_ops->inode_permission (inode, mask, nd);
  1517. }
  1518. static inline int security_inode_setattr (struct dentry *dentry,
  1519. struct iattr *attr)
  1520. {
  1521. if (unlikely (IS_PRIVATE (dentry->d_inode)))
  1522. return 0;
  1523. return security_ops->inode_setattr (dentry, attr);
  1524. }
  1525. static inline int security_inode_getattr (struct vfsmount *mnt,
  1526. struct dentry *dentry)
  1527. {
  1528. if (unlikely (IS_PRIVATE (dentry->d_inode)))
  1529. return 0;
  1530. return security_ops->inode_getattr (mnt, dentry);
  1531. }
  1532. static inline void security_inode_delete (struct inode *inode)
  1533. {
  1534. if (unlikely (IS_PRIVATE (inode)))
  1535. return;
  1536. security_ops->inode_delete (inode);
  1537. }
  1538. static inline int security_inode_setxattr (struct dentry *dentry, char *name,
  1539. void *value, size_t size, int flags)
  1540. {
  1541. if (unlikely (IS_PRIVATE (dentry->d_inode)))
  1542. return 0;
  1543. return security_ops->inode_setxattr (dentry, name, value, size, flags);
  1544. }
  1545. static inline void security_inode_post_setxattr (struct dentry *dentry, char *name,
  1546. void *value, size_t size, int flags)
  1547. {
  1548. if (unlikely (IS_PRIVATE (dentry->d_inode)))
  1549. return;
  1550. security_ops->inode_post_setxattr (dentry, name, value, size, flags);
  1551. }
  1552. static inline int security_inode_getxattr (struct dentry *dentry, char *name)
  1553. {
  1554. if (unlikely (IS_PRIVATE (dentry->d_inode)))
  1555. return 0;
  1556. return security_ops->inode_getxattr (dentry, name);
  1557. }
  1558. static inline int security_inode_listxattr (struct dentry *dentry)
  1559. {
  1560. if (unlikely (IS_PRIVATE (dentry->d_inode)))
  1561. return 0;
  1562. return security_ops->inode_listxattr (dentry);
  1563. }
  1564. static inline int security_inode_removexattr (struct dentry *dentry, char *name)
  1565. {
  1566. if (unlikely (IS_PRIVATE (dentry->d_inode)))
  1567. return 0;
  1568. return security_ops->inode_removexattr (dentry, name);
  1569. }
  1570. static inline int security_inode_getsecurity(struct inode *inode, const char *name, void *buffer, size_t size)
  1571. {
  1572. if (unlikely (IS_PRIVATE (inode)))
  1573. return 0;
  1574. return security_ops->inode_getsecurity(inode, name, buffer, size);
  1575. }
  1576. static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
  1577. {
  1578. if (unlikely (IS_PRIVATE (inode)))
  1579. return 0;
  1580. return security_ops->inode_setsecurity(inode, name, value, size, flags);
  1581. }
  1582. static inline int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
  1583. {
  1584. if (unlikely (IS_PRIVATE (inode)))
  1585. return 0;
  1586. return security_ops->inode_listsecurity(inode, buffer, buffer_size);
  1587. }
  1588. static inline int security_file_permission (struct file *file, int mask)
  1589. {
  1590. return security_ops->file_permission (file, mask);
  1591. }
  1592. static inline int security_file_alloc (struct file *file)
  1593. {
  1594. return security_ops->file_alloc_security (file);
  1595. }
  1596. static inline void security_file_free (struct file *file)
  1597. {
  1598. security_ops->file_free_security (file);
  1599. }
  1600. static inline int security_file_ioctl (struct file *file, unsigned int cmd,
  1601. unsigned long arg)
  1602. {
  1603. return security_ops->file_ioctl (file, cmd, arg);
  1604. }
  1605. static inline int security_file_mmap (struct file *file, unsigned long reqprot,
  1606. unsigned long prot,
  1607. unsigned long flags)
  1608. {
  1609. return security_ops->file_mmap (file, reqprot, prot, flags);
  1610. }
  1611. static inline int security_file_mprotect (struct vm_area_struct *vma,
  1612. unsigned long reqprot,
  1613. unsigned long prot)
  1614. {
  1615. return security_ops->file_mprotect (vma, reqprot, prot);
  1616. }
  1617. static inline int security_file_lock (struct file *file, unsigned int cmd)
  1618. {
  1619. return security_ops->file_lock (file, cmd);
  1620. }
  1621. static inline int security_file_fcntl (struct file *file, unsigned int cmd,
  1622. unsigned long arg)
  1623. {
  1624. return security_ops->file_fcntl (file, cmd, arg);
  1625. }
  1626. static inline int security_file_set_fowner (struct file *file)
  1627. {
  1628. return security_ops->file_set_fowner (file);
  1629. }
  1630. static inline int security_file_send_sigiotask (struct task_struct *tsk,
  1631. struct fown_struct *fown,
  1632. int sig)
  1633. {
  1634. return security_ops->file_send_sigiotask (tsk, fown, sig);
  1635. }
  1636. static inline int security_file_receive (struct file *file)
  1637. {
  1638. return security_ops->file_receive (file);
  1639. }
  1640. static inline int security_task_create (unsigned long clone_flags)
  1641. {
  1642. return security_ops->task_create (clone_flags);
  1643. }
  1644. static inline int security_task_alloc (struct task_struct *p)
  1645. {
  1646. return security_ops->task_alloc_security (p);
  1647. }
  1648. static inline void security_task_free (struct task_struct *p)
  1649. {
  1650. security_ops->task_free_security (p);
  1651. }
  1652. static inline int security_task_setuid (uid_t id0, uid_t id1, uid_t id2,
  1653. int flags)
  1654. {
  1655. return security_ops->task_setuid (id0, id1, id2, flags);
  1656. }
  1657. static inline int security_task_post_setuid (uid_t old_ruid, uid_t old_euid,
  1658. uid_t old_suid, int flags)
  1659. {
  1660. return security_ops->task_post_setuid (old_ruid, old_euid, old_suid, flags);
  1661. }
  1662. static inline int security_task_setgid (gid_t id0, gid_t id1, gid_t id2,
  1663. int flags)
  1664. {
  1665. return security_ops->task_setgid (id0, id1, id2, flags);
  1666. }
  1667. static inline int security_task_setpgid (struct task_struct *p, pid_t pgid)
  1668. {
  1669. return security_ops->task_setpgid (p, pgid);
  1670. }
  1671. static inline int security_task_getpgid (struct task_struct *p)
  1672. {
  1673. return security_ops->task_getpgid (p);
  1674. }
  1675. static inline int security_task_getsid (struct task_struct *p)
  1676. {
  1677. return security_ops->task_getsid (p);
  1678. }
  1679. static inline int security_task_setgroups (struct group_info *group_info)
  1680. {
  1681. return security_ops->task_setgroups (group_info);
  1682. }
  1683. static inline int security_task_setnice (struct task_struct *p, int nice)
  1684. {
  1685. return security_ops->task_setnice (p, nice);
  1686. }
  1687. static inline int security_task_setrlimit (unsigned int resource,
  1688. struct rlimit *new_rlim)
  1689. {
  1690. return security_ops->task_setrlimit (resource, new_rlim);
  1691. }
  1692. static inline int security_task_setscheduler (struct task_struct *p,
  1693. int policy,
  1694. struct sched_param *lp)
  1695. {
  1696. return security_ops->task_setscheduler (p, policy, lp);
  1697. }
  1698. static inline int security_task_getscheduler (struct task_struct *p)
  1699. {
  1700. return security_ops->task_getscheduler (p);
  1701. }
  1702. static inline int security_task_kill (struct task_struct *p,
  1703. struct siginfo *info, int sig)
  1704. {
  1705. return security_ops->task_kill (p, info, sig);
  1706. }
  1707. static inline int security_task_wait (struct task_struct *p)
  1708. {
  1709. return security_ops->task_wait (p);
  1710. }
  1711. static inline int security_task_prctl (int option, unsigned long arg2,
  1712. unsigned long arg3,
  1713. unsigned long arg4,
  1714. unsigned long arg5)
  1715. {
  1716. return security_ops->task_prctl (option, arg2, arg3, arg4, arg5);
  1717. }
  1718. static inline void security_task_reparent_to_init (struct task_struct *p)
  1719. {
  1720. security_ops->task_reparent_to_init (p);
  1721. }
  1722. static inline void security_task_to_inode(struct task_struct *p, struct inode *inode)
  1723. {
  1724. security_ops->task_to_inode(p, inode);
  1725. }
  1726. static inline int security_ipc_permission (struct kern_ipc_perm *ipcp,
  1727. short flag)
  1728. {
  1729. return security_ops->ipc_permission (ipcp, flag);
  1730. }
  1731. static inline int security_msg_msg_alloc (struct msg_msg * msg)
  1732. {
  1733. return security_ops->msg_msg_alloc_security (msg);
  1734. }
  1735. static inline void security_msg_msg_free (struct msg_msg * msg)
  1736. {
  1737. security_ops->msg_msg_free_security(msg);
  1738. }
  1739. static inline int security_msg_queue_alloc (struct msg_queue *msq)
  1740. {
  1741. return security_ops->msg_queue_alloc_security (msq);
  1742. }
  1743. static inline void security_msg_queue_free (struct msg_queue *msq)
  1744. {
  1745. security_ops->msg_queue_free_security (msq);
  1746. }
  1747. static inline int security_msg_queue_associate (struct msg_queue * msq,
  1748. int msqflg)
  1749. {
  1750. return security_ops->msg_queue_associate (msq, msqflg);
  1751. }
  1752. static inline int security_msg_queue_msgctl (struct msg_queue * msq, int cmd)
  1753. {
  1754. return security_ops->msg_queue_msgctl (msq, cmd);
  1755. }
  1756. static inline int security_msg_queue_msgsnd (struct msg_queue * msq,
  1757. struct msg_msg * msg, int msqflg)
  1758. {
  1759. return security_ops->msg_queue_msgsnd (msq, msg, msqflg);
  1760. }
  1761. static inline int security_msg_queue_msgrcv (struct msg_queue * msq,
  1762. struct msg_msg * msg,
  1763. struct task_struct * target,
  1764. long type, int mode)
  1765. {
  1766. return security_ops->msg_queue_msgrcv (msq, msg, target, type, mode);
  1767. }
  1768. static inline int security_shm_alloc (struct shmid_kernel *shp)
  1769. {
  1770. return security_ops->shm_alloc_security (shp);
  1771. }
  1772. static inline void security_shm_free (struct shmid_kernel *shp)
  1773. {
  1774. security_ops->shm_free_security (shp);
  1775. }
  1776. static inline int security_shm_associate (struct shmid_kernel * shp,
  1777. int shmflg)
  1778. {
  1779. return security_ops->shm_associate(shp, shmflg);
  1780. }
  1781. static inline int security_shm_shmctl (struct shmid_kernel * shp, int cmd)
  1782. {
  1783. return security_ops->shm_shmctl (shp, cmd);
  1784. }
  1785. static inline int security_shm_shmat (struct shmid_kernel * shp,
  1786. char __user *shmaddr, int shmflg)
  1787. {
  1788. return security_ops->shm_shmat(shp, shmaddr, shmflg);
  1789. }
  1790. static inline int security_sem_alloc (struct sem_array *sma)
  1791. {
  1792. return security_ops->sem_alloc_security (sma);
  1793. }
  1794. static inline void security_sem_free (struct sem_array *sma)
  1795. {
  1796. security_ops->sem_free_security (sma);
  1797. }
  1798. static inline int security_sem_associate (struct sem_array * sma, int semflg)
  1799. {
  1800. return security_ops->sem_associate (sma, semflg);
  1801. }
  1802. static inline int security_sem_semctl (struct sem_array * sma, int cmd)
  1803. {
  1804. return security_ops->sem_semctl(sma, cmd);
  1805. }
  1806. static inline int security_sem_semop (struct sem_array * sma,
  1807. struct sembuf * sops, unsigned nsops,
  1808. int alter)
  1809. {
  1810. return security_ops->sem_semop(sma, sops, nsops, alter);
  1811. }
  1812. static inline void security_d_instantiate (struct dentry *dentry, struct inode *inode)
  1813. {
  1814. if (unlikely (inode && IS_PRIVATE (inode)))
  1815. return;
  1816. security_ops->d_instantiate (dentry, inode);
  1817. }
  1818. static inline int security_getprocattr(struct task_struct *p, char *name, void *value, size_t size)
  1819. {
  1820. return security_ops->getprocattr(p, name, value, size);
  1821. }
  1822. static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
  1823. {
  1824. return security_ops->setprocattr(p, name, value, size);
  1825. }
  1826. static inline int security_netlink_send(struct sock *sk, struct sk_buff * skb)
  1827. {
  1828. return security_ops->netlink_send(sk, skb);
  1829. }
  1830. static inline int security_netlink_recv(struct sk_buff * skb)
  1831. {
  1832. return security_ops->netlink_recv(skb);
  1833. }
  1834. /* prototypes */
  1835. extern int security_init (void);
  1836. extern int register_security (struct security_operations *ops);
  1837. extern int unregister_security (struct security_operations *ops);
  1838. extern int mod_reg_security (const char *name, struct security_operations *ops);
  1839. extern int mod_unreg_security (const char *name, struct security_operations *ops);
  1840. #else /* CONFIG_SECURITY */
  1841. /*
  1842. * This is the default capabilities functionality. Most of these functions
  1843. * are just stubbed out, but a few must call the proper capable code.
  1844. */
  1845. static inline int security_init(void)
  1846. {
  1847. return 0;
  1848. }
  1849. static inline int security_ptrace (struct task_struct *parent, struct task_struct * child)
  1850. {
  1851. return cap_ptrace (parent, child);
  1852. }
  1853. static inline int security_capget (struct task_struct *target,
  1854. kernel_cap_t *effective,
  1855. kernel_cap_t *inheritable,
  1856. kernel_cap_t *permitted)
  1857. {
  1858. return cap_capget (target, effective, inheritable, permitted);
  1859. }
  1860. static inline int security_capset_check (struct task_struct *target,
  1861. kernel_cap_t *effective,
  1862. kernel_cap_t *inheritable,
  1863. kernel_cap_t *permitted)
  1864. {
  1865. return cap_capset_check (target, effective, inheritable, permitted);
  1866. }
  1867. static inline void security_capset_set (struct task_struct *target,
  1868. kernel_cap_t *effective,
  1869. kernel_cap_t *inheritable,
  1870. kernel_cap_t *permitted)
  1871. {
  1872. cap_capset_set (target, effective, inheritable, permitted);
  1873. }
  1874. static inline int security_acct (struct file *file)
  1875. {
  1876. return 0;
  1877. }
  1878. static inline int security_sysctl(struct ctl_table *table, int op)
  1879. {
  1880. return 0;
  1881. }
  1882. static inline int security_quotactl (int cmds, int type, int id,
  1883. struct super_block * sb)
  1884. {
  1885. return 0;
  1886. }
  1887. static inline int security_quota_on (struct dentry * dentry)
  1888. {
  1889. return 0;
  1890. }
  1891. static inline int security_syslog(int type)
  1892. {
  1893. return cap_syslog(type);
  1894. }
  1895. static inline int security_settime(struct timespec *ts, struct timezone *tz)
  1896. {
  1897. return cap_settime(ts, tz);
  1898. }
  1899. static inline int security_vm_enough_memory(long pages)
  1900. {
  1901. return cap_vm_enough_memory(pages);
  1902. }
  1903. static inline int security_bprm_alloc (struct linux_binprm *bprm)
  1904. {
  1905. return 0;
  1906. }
  1907. static inline void security_bprm_free (struct linux_binprm *bprm)
  1908. { }
  1909. static inline void security_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
  1910. {
  1911. cap_bprm_apply_creds (bprm, unsafe);
  1912. }
  1913. static inline void security_bprm_post_apply_creds (struct linux_binprm *bprm)
  1914. {
  1915. return;
  1916. }
  1917. static inline int security_bprm_set (struct linux_binprm *bprm)
  1918. {
  1919. return cap_bprm_set_security (bprm);
  1920. }
  1921. static inline int security_bprm_check (struct linux_binprm *bprm)
  1922. {
  1923. return 0;
  1924. }
  1925. static inline int security_bprm_secureexec (struct linux_binprm *bprm)
  1926. {
  1927. return cap_bprm_secureexec(bprm);
  1928. }
  1929. static inline int security_sb_alloc (struct super_block *sb)
  1930. {
  1931. return 0;
  1932. }
  1933. static inline void security_sb_free (struct super_block *sb)
  1934. { }
  1935. static inline int security_sb_copy_data (struct file_system_type *type,
  1936. void *orig, void *copy)
  1937. {
  1938. return 0;
  1939. }
  1940. static inline int security_sb_kern_mount (struct super_block *sb, void *data)
  1941. {
  1942. return 0;
  1943. }
  1944. static inline int security_sb_statfs (struct super_block *sb)
  1945. {
  1946. return 0;
  1947. }
  1948. static inline int security_sb_mount (char *dev_name, struct nameidata *nd,
  1949. char *type, unsigned long flags,
  1950. void *data)
  1951. {
  1952. return 0;
  1953. }
  1954. static inline int security_sb_check_sb (struct vfsmount *mnt,
  1955. struct nameidata *nd)
  1956. {
  1957. return 0;
  1958. }
  1959. static inline int security_sb_umount (struct vfsmount *mnt, int flags)
  1960. {
  1961. return 0;
  1962. }
  1963. static inline void security_sb_umount_close (struct vfsmount *mnt)
  1964. { }
  1965. static inline void security_sb_umount_busy (struct vfsmount *mnt)
  1966. { }
  1967. static inline void security_sb_post_remount (struct vfsmount *mnt,
  1968. unsigned long flags, void *data)
  1969. { }
  1970. static inline void security_sb_post_mountroot (void)
  1971. { }
  1972. static inline void security_sb_post_addmount (struct vfsmount *mnt,
  1973. struct nameidata *mountpoint_nd)
  1974. { }
  1975. static inline int security_sb_pivotroot (struct nameidata *old_nd,
  1976. struct nameidata *new_nd)
  1977. {
  1978. return 0;
  1979. }
  1980. static inline void security_sb_post_pivotroot (struct nameidata *old_nd,
  1981. struct nameidata *new_nd)
  1982. { }
  1983. static inline int security_inode_alloc (struct inode *inode)
  1984. {
  1985. return 0;
  1986. }
  1987. static inline void security_inode_free (struct inode *inode)
  1988. { }
  1989. static inline int security_inode_create (struct inode *dir,
  1990. struct dentry *dentry,
  1991. int mode)
  1992. {
  1993. return 0;
  1994. }
  1995. static inline void security_inode_post_create (struct inode *dir,
  1996. struct dentry *dentry,
  1997. int mode)
  1998. { }
  1999. static inline int security_inode_link (struct dentry *old_dentry,
  2000. struct inode *dir,
  2001. struct dentry *new_dentry)
  2002. {
  2003. return 0;
  2004. }
  2005. static inline void security_inode_post_link (struct dentry *old_dentry,
  2006. struct inode *dir,
  2007. struct dentry *new_dentry)
  2008. { }
  2009. static inline int security_inode_unlink (struct inode *dir,
  2010. struct dentry *dentry)
  2011. {
  2012. return 0;
  2013. }
  2014. static inline int security_inode_symlink (struct inode *dir,
  2015. struct dentry *dentry,
  2016. const char *old_name)
  2017. {
  2018. return 0;
  2019. }
  2020. static inline void security_inode_post_symlink (struct inode *dir,
  2021. struct dentry *dentry,
  2022. const char *old_name)
  2023. { }
  2024. static inline int security_inode_mkdir (struct inode *dir,
  2025. struct dentry *dentry,
  2026. int mode)
  2027. {
  2028. return 0;
  2029. }
  2030. static inline void security_inode_post_mkdir (struct inode *dir,
  2031. struct dentry *dentry,
  2032. int mode)
  2033. { }
  2034. static inline int security_inode_rmdir (struct inode *dir,
  2035. struct dentry *dentry)
  2036. {
  2037. return 0;
  2038. }
  2039. static inline int security_inode_mknod (struct inode *dir,
  2040. struct dentry *dentry,
  2041. int mode, dev_t dev)
  2042. {
  2043. return 0;
  2044. }
  2045. static inline void security_inode_post_mknod (struct inode *dir,
  2046. struct dentry *dentry,
  2047. int mode, dev_t dev)
  2048. { }
  2049. static inline int security_inode_rename (struct inode *old_dir,
  2050. struct dentry *old_dentry,
  2051. struct inode *new_dir,
  2052. struct dentry *new_dentry)
  2053. {
  2054. return 0;
  2055. }
  2056. static inline void security_inode_post_rename (struct inode *old_dir,
  2057. struct dentry *old_dentry,
  2058. struct inode *new_dir,
  2059. struct dentry *new_dentry)
  2060. { }
  2061. static inline int security_inode_readlink (struct dentry *dentry)
  2062. {
  2063. return 0;
  2064. }
  2065. static inline int security_inode_follow_link (struct dentry *dentry,
  2066. struct nameidata *nd)
  2067. {
  2068. return 0;
  2069. }
  2070. static inline int security_inode_permission (struct inode *inode, int mask,
  2071. struct nameidata *nd)
  2072. {
  2073. return 0;
  2074. }
  2075. static inline int security_inode_setattr (struct dentry *dentry,
  2076. struct iattr *attr)
  2077. {
  2078. return 0;
  2079. }
  2080. static inline int security_inode_getattr (struct vfsmount *mnt,
  2081. struct dentry *dentry)
  2082. {
  2083. return 0;
  2084. }
  2085. static inline void security_inode_delete (struct inode *inode)
  2086. { }
  2087. static inline int security_inode_setxattr (struct dentry *dentry, char *name,
  2088. void *value, size_t size, int flags)
  2089. {
  2090. return cap_inode_setxattr(dentry, name, value, size, flags);
  2091. }
  2092. static inline void security_inode_post_setxattr (struct dentry *dentry, char *name,
  2093. void *value, size_t size, int flags)
  2094. { }
  2095. static inline int security_inode_getxattr (struct dentry *dentry, char *name)
  2096. {
  2097. return 0;
  2098. }
  2099. static inline int security_inode_listxattr (struct dentry *dentry)
  2100. {
  2101. return 0;
  2102. }
  2103. static inline int security_inode_removexattr (struct dentry *dentry, char *name)
  2104. {
  2105. return cap_inode_removexattr(dentry, name);
  2106. }
  2107. static inline int security_inode_getsecurity(struct inode *inode, const char *name, void *buffer, size_t size)
  2108. {
  2109. return -EOPNOTSUPP;
  2110. }
  2111. static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
  2112. {
  2113. return -EOPNOTSUPP;
  2114. }
  2115. static inline int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
  2116. {
  2117. return 0;
  2118. }
  2119. static inline int security_file_permission (struct file *file, int mask)
  2120. {
  2121. return 0;
  2122. }
  2123. static inline int security_file_alloc (struct file *file)
  2124. {
  2125. return 0;
  2126. }
  2127. static inline void security_file_free (struct file *file)
  2128. { }
  2129. static inline int security_file_ioctl (struct file *file, unsigned int cmd,
  2130. unsigned long arg)
  2131. {
  2132. return 0;
  2133. }
  2134. static inline int security_file_mmap (struct file *file, unsigned long reqprot,
  2135. unsigned long prot,
  2136. unsigned long flags)
  2137. {
  2138. return 0;
  2139. }
  2140. static inline int security_file_mprotect (struct vm_area_struct *vma,
  2141. unsigned long reqprot,
  2142. unsigned long prot)
  2143. {
  2144. return 0;
  2145. }
  2146. static inline int security_file_lock (struct file *file, unsigned int cmd)
  2147. {
  2148. return 0;
  2149. }
  2150. static inline int security_file_fcntl (struct file *file, unsigned int cmd,
  2151. unsigned long arg)
  2152. {
  2153. return 0;
  2154. }
  2155. static inline int security_file_set_fowner (struct file *file)
  2156. {
  2157. return 0;
  2158. }
  2159. static inline int security_file_send_sigiotask (struct task_struct *tsk,
  2160. struct fown_struct *fown,
  2161. int sig)
  2162. {
  2163. return 0;
  2164. }
  2165. static inline int security_file_receive (struct file *file)
  2166. {
  2167. return 0;
  2168. }
  2169. static inline int security_task_create (unsigned long clone_flags)
  2170. {
  2171. return 0;
  2172. }
  2173. static inline int security_task_alloc (struct task_struct *p)
  2174. {
  2175. return 0;
  2176. }
  2177. static inline void security_task_free (struct task_struct *p)
  2178. { }
  2179. static inline int security_task_setuid (uid_t id0, uid_t id1, uid_t id2,
  2180. int flags)
  2181. {
  2182. return 0;
  2183. }
  2184. static inline int security_task_post_setuid (uid_t old_ruid, uid_t old_euid,
  2185. uid_t old_suid, int flags)
  2186. {
  2187. return cap_task_post_setuid (old_ruid, old_euid, old_suid, flags);
  2188. }
  2189. static inline int security_task_setgid (gid_t id0, gid_t id1, gid_t id2,
  2190. int flags)
  2191. {
  2192. return 0;
  2193. }
  2194. static inline int security_task_setpgid (struct task_struct *p, pid_t pgid)
  2195. {
  2196. return 0;
  2197. }
  2198. static inline int security_task_getpgid (struct task_struct *p)
  2199. {
  2200. return 0;
  2201. }
  2202. static inline int security_task_getsid (struct task_struct *p)
  2203. {
  2204. return 0;
  2205. }
  2206. static inline int security_task_setgroups (struct group_info *group_info)
  2207. {
  2208. return 0;
  2209. }
  2210. static inline int security_task_setnice (struct task_struct *p, int nice)
  2211. {
  2212. return 0;
  2213. }
  2214. static inline int security_task_setrlimit (unsigned int resource,
  2215. struct rlimit *new_rlim)
  2216. {
  2217. return 0;
  2218. }
  2219. static inline int security_task_setscheduler (struct task_struct *p,
  2220. int policy,
  2221. struct sched_param *lp)
  2222. {
  2223. return 0;
  2224. }
  2225. static inline int security_task_getscheduler (struct task_struct *p)
  2226. {
  2227. return 0;
  2228. }
  2229. static inline int security_task_kill (struct task_struct *p,
  2230. struct siginfo *info, int sig)
  2231. {
  2232. return 0;
  2233. }
  2234. static inline int security_task_wait (struct task_struct *p)
  2235. {
  2236. return 0;
  2237. }
  2238. static inline int security_task_prctl (int option, unsigned long arg2,
  2239. unsigned long arg3,
  2240. unsigned long arg4,
  2241. unsigned long arg5)
  2242. {
  2243. return 0;
  2244. }
  2245. static inline void security_task_reparent_to_init (struct task_struct *p)
  2246. {
  2247. cap_task_reparent_to_init (p);
  2248. }
  2249. static inline void security_task_to_inode(struct task_struct *p, struct inode *inode)
  2250. { }
  2251. static inline int security_ipc_permission (struct kern_ipc_perm *ipcp,
  2252. short flag)
  2253. {
  2254. return 0;
  2255. }
  2256. static inline int security_msg_msg_alloc (struct msg_msg * msg)
  2257. {
  2258. return 0;
  2259. }
  2260. static inline void security_msg_msg_free (struct msg_msg * msg)
  2261. { }
  2262. static inline int security_msg_queue_alloc (struct msg_queue *msq)
  2263. {
  2264. return 0;
  2265. }
  2266. static inline void security_msg_queue_free (struct msg_queue *msq)
  2267. { }
  2268. static inline int security_msg_queue_associate (struct msg_queue * msq,
  2269. int msqflg)
  2270. {
  2271. return 0;
  2272. }
  2273. static inline int security_msg_queue_msgctl (struct msg_queue * msq, int cmd)
  2274. {
  2275. return 0;
  2276. }
  2277. static inline int security_msg_queue_msgsnd (struct msg_queue * msq,
  2278. struct msg_msg * msg, int msqflg)
  2279. {
  2280. return 0;
  2281. }
  2282. static inline int security_msg_queue_msgrcv (struct msg_queue * msq,
  2283. struct msg_msg * msg,
  2284. struct task_struct * target,
  2285. long type, int mode)
  2286. {
  2287. return 0;
  2288. }
  2289. static inline int security_shm_alloc (struct shmid_kernel *shp)
  2290. {
  2291. return 0;
  2292. }
  2293. static inline void security_shm_free (struct shmid_kernel *shp)
  2294. { }
  2295. static inline int security_shm_associate (struct shmid_kernel * shp,
  2296. int shmflg)
  2297. {
  2298. return 0;
  2299. }
  2300. static inline int security_shm_shmctl (struct shmid_kernel * shp, int cmd)
  2301. {
  2302. return 0;
  2303. }
  2304. static inline int security_shm_shmat (struct shmid_kernel * shp,
  2305. char __user *shmaddr, int shmflg)
  2306. {
  2307. return 0;
  2308. }
  2309. static inline int security_sem_alloc (struct sem_array *sma)
  2310. {
  2311. return 0;
  2312. }
  2313. static inline void security_sem_free (struct sem_array *sma)
  2314. { }
  2315. static inline int security_sem_associate (struct sem_array * sma, int semflg)
  2316. {
  2317. return 0;
  2318. }
  2319. static inline int security_sem_semctl (struct sem_array * sma, int cmd)
  2320. {
  2321. return 0;
  2322. }
  2323. static inline int security_sem_semop (struct sem_array * sma,
  2324. struct sembuf * sops, unsigned nsops,
  2325. int alter)
  2326. {
  2327. return 0;
  2328. }
  2329. static inline void security_d_instantiate (struct dentry *dentry, struct inode *inode)
  2330. { }
  2331. static inline int security_getprocattr(struct task_struct *p, char *name, void *value, size_t size)
  2332. {
  2333. return -EINVAL;
  2334. }
  2335. static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
  2336. {
  2337. return -EINVAL;
  2338. }
  2339. static inline int security_netlink_send (struct sock *sk, struct sk_buff *skb)
  2340. {
  2341. return cap_netlink_send (sk, skb);
  2342. }
  2343. static inline int security_netlink_recv (struct sk_buff *skb)
  2344. {
  2345. return cap_netlink_recv (skb);
  2346. }
  2347. #endif /* CONFIG_SECURITY */
  2348. #ifdef CONFIG_SECURITY_NETWORK
  2349. static inline int security_unix_stream_connect(struct socket * sock,
  2350. struct socket * other,
  2351. struct sock * newsk)
  2352. {
  2353. return security_ops->unix_stream_connect(sock, other, newsk);
  2354. }
  2355. static inline int security_unix_may_send(struct socket * sock,
  2356. struct socket * other)
  2357. {
  2358. return security_ops->unix_may_send(sock, other);
  2359. }
  2360. static inline int security_socket_create (int family, int type,
  2361. int protocol, int kern)
  2362. {
  2363. return security_ops->socket_create(family, type, protocol, kern);
  2364. }
  2365. static inline void security_socket_post_create(struct socket * sock,
  2366. int family,
  2367. int type,
  2368. int protocol, int kern)
  2369. {
  2370. security_ops->socket_post_create(sock, family, type,
  2371. protocol, kern);
  2372. }
  2373. static inline int security_socket_bind(struct socket * sock,
  2374. struct sockaddr * address,
  2375. int addrlen)
  2376. {
  2377. return security_ops->socket_bind(sock, address, addrlen);
  2378. }
  2379. static inline int security_socket_connect(struct socket * sock,
  2380. struct sockaddr * address,
  2381. int addrlen)
  2382. {
  2383. return security_ops->socket_connect(sock, address, addrlen);
  2384. }
  2385. static inline int security_socket_listen(struct socket * sock, int backlog)
  2386. {
  2387. return security_ops->socket_listen(sock, backlog);
  2388. }
  2389. static inline int security_socket_accept(struct socket * sock,
  2390. struct socket * newsock)
  2391. {
  2392. return security_ops->socket_accept(sock, newsock);
  2393. }
  2394. static inline void security_socket_post_accept(struct socket * sock,
  2395. struct socket * newsock)
  2396. {
  2397. security_ops->socket_post_accept(sock, newsock);
  2398. }
  2399. static inline int security_socket_sendmsg(struct socket * sock,
  2400. struct msghdr * msg, int size)
  2401. {
  2402. return security_ops->socket_sendmsg(sock, msg, size);
  2403. }
  2404. static inline int security_socket_recvmsg(struct socket * sock,
  2405. struct msghdr * msg, int size,
  2406. int flags)
  2407. {
  2408. return security_ops->socket_recvmsg(sock, msg, size, flags);
  2409. }
  2410. static inline int security_socket_getsockname(struct socket * sock)
  2411. {
  2412. return security_ops->socket_getsockname(sock);
  2413. }
  2414. static inline int security_socket_getpeername(struct socket * sock)
  2415. {
  2416. return security_ops->socket_getpeername(sock);
  2417. }
  2418. static inline int security_socket_getsockopt(struct socket * sock,
  2419. int level, int optname)
  2420. {
  2421. return security_ops->socket_getsockopt(sock, level, optname);
  2422. }
  2423. static inline int security_socket_setsockopt(struct socket * sock,
  2424. int level, int optname)
  2425. {
  2426. return security_ops->socket_setsockopt(sock, level, optname);
  2427. }
  2428. static inline int security_socket_shutdown(struct socket * sock, int how)
  2429. {
  2430. return security_ops->socket_shutdown(sock, how);
  2431. }
  2432. static inline int security_sock_rcv_skb (struct sock * sk,
  2433. struct sk_buff * skb)
  2434. {
  2435. return security_ops->socket_sock_rcv_skb (sk, skb);
  2436. }
  2437. static inline int security_socket_getpeersec(struct socket *sock, char __user *optval,
  2438. int __user *optlen, unsigned len)
  2439. {
  2440. return security_ops->socket_getpeersec(sock, optval, optlen, len);
  2441. }
  2442. static inline int security_sk_alloc(struct sock *sk, int family,
  2443. unsigned int __nocast priority)
  2444. {
  2445. return security_ops->sk_alloc_security(sk, family, priority);
  2446. }
  2447. static inline void security_sk_free(struct sock *sk)
  2448. {
  2449. return security_ops->sk_free_security(sk);
  2450. }
  2451. #else /* CONFIG_SECURITY_NETWORK */
  2452. static inline int security_unix_stream_connect(struct socket * sock,
  2453. struct socket * other,
  2454. struct sock * newsk)
  2455. {
  2456. return 0;
  2457. }
  2458. static inline int security_unix_may_send(struct socket * sock,
  2459. struct socket * other)
  2460. {
  2461. return 0;
  2462. }
  2463. static inline int security_socket_create (int family, int type,
  2464. int protocol, int kern)
  2465. {
  2466. return 0;
  2467. }
  2468. static inline void security_socket_post_create(struct socket * sock,
  2469. int family,
  2470. int type,
  2471. int protocol, int kern)
  2472. {
  2473. }
  2474. static inline int security_socket_bind(struct socket * sock,
  2475. struct sockaddr * address,
  2476. int addrlen)
  2477. {
  2478. return 0;
  2479. }
  2480. static inline int security_socket_connect(struct socket * sock,
  2481. struct sockaddr * address,
  2482. int addrlen)
  2483. {
  2484. return 0;
  2485. }
  2486. static inline int security_socket_listen(struct socket * sock, int backlog)
  2487. {
  2488. return 0;
  2489. }
  2490. static inline int security_socket_accept(struct socket * sock,
  2491. struct socket * newsock)
  2492. {
  2493. return 0;
  2494. }
  2495. static inline void security_socket_post_accept(struct socket * sock,
  2496. struct socket * newsock)
  2497. {
  2498. }
  2499. static inline int security_socket_sendmsg(struct socket * sock,
  2500. struct msghdr * msg, int size)
  2501. {
  2502. return 0;
  2503. }
  2504. static inline int security_socket_recvmsg(struct socket * sock,
  2505. struct msghdr * msg, int size,
  2506. int flags)
  2507. {
  2508. return 0;
  2509. }
  2510. static inline int security_socket_getsockname(struct socket * sock)
  2511. {
  2512. return 0;
  2513. }
  2514. static inline int security_socket_getpeername(struct socket * sock)
  2515. {
  2516. return 0;
  2517. }
  2518. static inline int security_socket_getsockopt(struct socket * sock,
  2519. int level, int optname)
  2520. {
  2521. return 0;
  2522. }
  2523. static inline int security_socket_setsockopt(struct socket * sock,
  2524. int level, int optname)
  2525. {
  2526. return 0;
  2527. }
  2528. static inline int security_socket_shutdown(struct socket * sock, int how)
  2529. {
  2530. return 0;
  2531. }
  2532. static inline int security_sock_rcv_skb (struct sock * sk,
  2533. struct sk_buff * skb)
  2534. {
  2535. return 0;
  2536. }
  2537. static inline int security_socket_getpeersec(struct socket *sock, char __user *optval,
  2538. int __user *optlen, unsigned len)
  2539. {
  2540. return -ENOPROTOOPT;
  2541. }
  2542. static inline int security_sk_alloc(struct sock *sk, int family,
  2543. unsigned int __nocast priority)
  2544. {
  2545. return 0;
  2546. }
  2547. static inline void security_sk_free(struct sock *sk)
  2548. {
  2549. }
  2550. #endif /* CONFIG_SECURITY_NETWORK */
  2551. #endif /* ! __LINUX_SECURITY_H */