security.h 107 KB

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