security.h 108 KB

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