security.h 108 KB

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