security.h 109 KB

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