security.h 116 KB

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