security.h 99 KB

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