security.h 113 KB

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