security.h 98 KB

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