security.h 99 KB

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