security.h 92 KB

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