security.h 94 KB

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