security.h 106 KB

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