security.h 115 KB

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