security.h 108 KB

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