security.h 115 KB

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