security.h 97 KB

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