security.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Security plug functions
  4. *
  5. * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
  6. * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
  7. * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
  8. * Copyright (C) 2016 Mellanox Technologies
  9. */
  10. #define pr_fmt(fmt) "LSM: " fmt
  11. #include <linux/bpf.h>
  12. #include <linux/capability.h>
  13. #include <linux/dcache.h>
  14. #include <linux/export.h>
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <linux/kernel_read_file.h>
  18. #include <linux/lsm_hooks.h>
  19. #include <linux/integrity.h>
  20. #include <linux/ima.h>
  21. #include <linux/evm.h>
  22. #include <linux/fsnotify.h>
  23. #include <linux/mman.h>
  24. #include <linux/mount.h>
  25. #include <linux/personality.h>
  26. #include <linux/backing-dev.h>
  27. #include <linux/string.h>
  28. #include <linux/msg.h>
  29. #include <net/flow.h>
  30. #define MAX_LSM_EVM_XATTR 2
  31. /* How many LSMs were built into the kernel? */
  32. #define LSM_COUNT (__end_lsm_info - __start_lsm_info)
  33. struct security_hook_heads security_hook_heads __lsm_ro_after_init;
  34. static BLOCKING_NOTIFIER_HEAD(blocking_lsm_notifier_chain);
  35. static struct kmem_cache *lsm_file_cache;
  36. static struct kmem_cache *lsm_inode_cache;
  37. char *lsm_names;
  38. static struct lsm_blob_sizes blob_sizes __lsm_ro_after_init;
  39. /* Boot-time LSM user choice */
  40. static __initdata const char *chosen_lsm_order;
  41. static __initdata const char *chosen_major_lsm;
  42. static __initconst const char * const builtin_lsm_order = CONFIG_LSM;
  43. /* Ordered list of LSMs to initialize. */
  44. static __initdata struct lsm_info **ordered_lsms;
  45. static __initdata struct lsm_info *exclusive;
  46. static __initdata bool debug;
  47. #define init_debug(...) \
  48. do { \
  49. if (debug) \
  50. pr_info(__VA_ARGS__); \
  51. } while (0)
  52. static bool __init is_enabled(struct lsm_info *lsm)
  53. {
  54. if (!lsm->enabled)
  55. return false;
  56. return *lsm->enabled;
  57. }
  58. /* Mark an LSM's enabled flag. */
  59. static int lsm_enabled_true __initdata = 1;
  60. static int lsm_enabled_false __initdata = 0;
  61. static void __init set_enabled(struct lsm_info *lsm, bool enabled)
  62. {
  63. /*
  64. * When an LSM hasn't configured an enable variable, we can use
  65. * a hard-coded location for storing the default enabled state.
  66. */
  67. if (!lsm->enabled) {
  68. if (enabled)
  69. lsm->enabled = &lsm_enabled_true;
  70. else
  71. lsm->enabled = &lsm_enabled_false;
  72. } else if (lsm->enabled == &lsm_enabled_true) {
  73. if (!enabled)
  74. lsm->enabled = &lsm_enabled_false;
  75. } else if (lsm->enabled == &lsm_enabled_false) {
  76. if (enabled)
  77. lsm->enabled = &lsm_enabled_true;
  78. } else {
  79. *lsm->enabled = enabled;
  80. }
  81. }
  82. /* Is an LSM already listed in the ordered LSMs list? */
  83. static bool __init exists_ordered_lsm(struct lsm_info *lsm)
  84. {
  85. struct lsm_info **check;
  86. for (check = ordered_lsms; *check; check++)
  87. if (*check == lsm)
  88. return true;
  89. return false;
  90. }
  91. /* Append an LSM to the list of ordered LSMs to initialize. */
  92. static int last_lsm __initdata;
  93. static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from)
  94. {
  95. /* Ignore duplicate selections. */
  96. if (exists_ordered_lsm(lsm))
  97. return;
  98. if (WARN(last_lsm == LSM_COUNT, "%s: out of LSM slots!?\n", from))
  99. return;
  100. /* Enable this LSM, if it is not already set. */
  101. if (!lsm->enabled)
  102. lsm->enabled = &lsm_enabled_true;
  103. ordered_lsms[last_lsm++] = lsm;
  104. init_debug("%s ordering: %s (%sabled)\n", from, lsm->name,
  105. is_enabled(lsm) ? "en" : "dis");
  106. }
  107. /* Is an LSM allowed to be initialized? */
  108. static bool __init lsm_allowed(struct lsm_info *lsm)
  109. {
  110. /* Skip if the LSM is disabled. */
  111. if (!is_enabled(lsm))
  112. return false;
  113. /* Not allowed if another exclusive LSM already initialized. */
  114. if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && exclusive) {
  115. init_debug("exclusive disabled: %s\n", lsm->name);
  116. return false;
  117. }
  118. return true;
  119. }
  120. static void __init lsm_set_blob_size(int *need, int *lbs)
  121. {
  122. int offset;
  123. if (*need > 0) {
  124. offset = *lbs;
  125. *lbs += *need;
  126. *need = offset;
  127. }
  128. }
  129. static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
  130. {
  131. if (!needed)
  132. return;
  133. lsm_set_blob_size(&needed->lbs_cred, &blob_sizes.lbs_cred);
  134. lsm_set_blob_size(&needed->lbs_file, &blob_sizes.lbs_file);
  135. /*
  136. * The inode blob gets an rcu_head in addition to
  137. * what the modules might need.
  138. */
  139. if (needed->lbs_inode && blob_sizes.lbs_inode == 0)
  140. blob_sizes.lbs_inode = sizeof(struct rcu_head);
  141. lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode);
  142. lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc);
  143. lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg);
  144. lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task);
  145. }
  146. /* Prepare LSM for initialization. */
  147. static void __init prepare_lsm(struct lsm_info *lsm)
  148. {
  149. int enabled = lsm_allowed(lsm);
  150. /* Record enablement (to handle any following exclusive LSMs). */
  151. set_enabled(lsm, enabled);
  152. /* If enabled, do pre-initialization work. */
  153. if (enabled) {
  154. if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) {
  155. exclusive = lsm;
  156. init_debug("exclusive chosen: %s\n", lsm->name);
  157. }
  158. lsm_set_blob_sizes(lsm->blobs);
  159. }
  160. }
  161. /* Initialize a given LSM, if it is enabled. */
  162. static void __init initialize_lsm(struct lsm_info *lsm)
  163. {
  164. if (is_enabled(lsm)) {
  165. int ret;
  166. init_debug("initializing %s\n", lsm->name);
  167. ret = lsm->init();
  168. WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret);
  169. }
  170. }
  171. /* Populate ordered LSMs list from comma-separated LSM name list. */
  172. static void __init ordered_lsm_parse(const char *order, const char *origin)
  173. {
  174. struct lsm_info *lsm;
  175. char *sep, *name, *next;
  176. /* LSM_ORDER_FIRST is always first. */
  177. for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
  178. if (lsm->order == LSM_ORDER_FIRST)
  179. append_ordered_lsm(lsm, "first");
  180. }
  181. /* Process "security=", if given. */
  182. if (chosen_major_lsm) {
  183. struct lsm_info *major;
  184. /*
  185. * To match the original "security=" behavior, this
  186. * explicitly does NOT fallback to another Legacy Major
  187. * if the selected one was separately disabled: disable
  188. * all non-matching Legacy Major LSMs.
  189. */
  190. for (major = __start_lsm_info; major < __end_lsm_info;
  191. major++) {
  192. if ((major->flags & LSM_FLAG_LEGACY_MAJOR) &&
  193. strcmp(major->name, chosen_major_lsm) != 0) {
  194. set_enabled(major, false);
  195. init_debug("security=%s disabled: %s\n",
  196. chosen_major_lsm, major->name);
  197. }
  198. }
  199. }
  200. sep = kstrdup(order, GFP_KERNEL);
  201. next = sep;
  202. /* Walk the list, looking for matching LSMs. */
  203. while ((name = strsep(&next, ",")) != NULL) {
  204. bool found = false;
  205. for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
  206. if (lsm->order == LSM_ORDER_MUTABLE &&
  207. strcmp(lsm->name, name) == 0) {
  208. append_ordered_lsm(lsm, origin);
  209. found = true;
  210. }
  211. }
  212. if (!found)
  213. init_debug("%s ignored: %s\n", origin, name);
  214. }
  215. /* Process "security=", if given. */
  216. if (chosen_major_lsm) {
  217. for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
  218. if (exists_ordered_lsm(lsm))
  219. continue;
  220. if (strcmp(lsm->name, chosen_major_lsm) == 0)
  221. append_ordered_lsm(lsm, "security=");
  222. }
  223. }
  224. /* Disable all LSMs not in the ordered list. */
  225. for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
  226. if (exists_ordered_lsm(lsm))
  227. continue;
  228. set_enabled(lsm, false);
  229. init_debug("%s disabled: %s\n", origin, lsm->name);
  230. }
  231. kfree(sep);
  232. }
  233. static void __init lsm_early_cred(struct cred *cred);
  234. static void __init lsm_early_task(struct task_struct *task);
  235. static int lsm_append(const char *new, char **result);
  236. static void __init ordered_lsm_init(void)
  237. {
  238. struct lsm_info **lsm;
  239. ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms),
  240. GFP_KERNEL);
  241. if (chosen_lsm_order) {
  242. if (chosen_major_lsm) {
  243. pr_info("security= is ignored because it is superseded by lsm=\n");
  244. chosen_major_lsm = NULL;
  245. }
  246. ordered_lsm_parse(chosen_lsm_order, "cmdline");
  247. } else
  248. ordered_lsm_parse(builtin_lsm_order, "builtin");
  249. for (lsm = ordered_lsms; *lsm; lsm++)
  250. prepare_lsm(*lsm);
  251. init_debug("cred blob size = %d\n", blob_sizes.lbs_cred);
  252. init_debug("file blob size = %d\n", blob_sizes.lbs_file);
  253. init_debug("inode blob size = %d\n", blob_sizes.lbs_inode);
  254. init_debug("ipc blob size = %d\n", blob_sizes.lbs_ipc);
  255. init_debug("msg_msg blob size = %d\n", blob_sizes.lbs_msg_msg);
  256. init_debug("task blob size = %d\n", blob_sizes.lbs_task);
  257. /*
  258. * Create any kmem_caches needed for blobs
  259. */
  260. if (blob_sizes.lbs_file)
  261. lsm_file_cache = kmem_cache_create("lsm_file_cache",
  262. blob_sizes.lbs_file, 0,
  263. SLAB_PANIC, NULL);
  264. if (blob_sizes.lbs_inode)
  265. lsm_inode_cache = kmem_cache_create("lsm_inode_cache",
  266. blob_sizes.lbs_inode, 0,
  267. SLAB_PANIC, NULL);
  268. lsm_early_cred((struct cred *) current->cred);
  269. lsm_early_task(current);
  270. for (lsm = ordered_lsms; *lsm; lsm++)
  271. initialize_lsm(*lsm);
  272. kfree(ordered_lsms);
  273. }
  274. int __init early_security_init(void)
  275. {
  276. int i;
  277. struct hlist_head *list = (struct hlist_head *) &security_hook_heads;
  278. struct lsm_info *lsm;
  279. for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct hlist_head);
  280. i++)
  281. INIT_HLIST_HEAD(&list[i]);
  282. for (lsm = __start_early_lsm_info; lsm < __end_early_lsm_info; lsm++) {
  283. if (!lsm->enabled)
  284. lsm->enabled = &lsm_enabled_true;
  285. prepare_lsm(lsm);
  286. initialize_lsm(lsm);
  287. }
  288. return 0;
  289. }
  290. /**
  291. * security_init - initializes the security framework
  292. *
  293. * This should be called early in the kernel initialization sequence.
  294. */
  295. int __init security_init(void)
  296. {
  297. struct lsm_info *lsm;
  298. pr_info("Security Framework initializing\n");
  299. /*
  300. * Append the names of the early LSM modules now that kmalloc() is
  301. * available
  302. */
  303. for (lsm = __start_early_lsm_info; lsm < __end_early_lsm_info; lsm++) {
  304. if (lsm->enabled)
  305. lsm_append(lsm->name, &lsm_names);
  306. }
  307. /* Load LSMs in specified order. */
  308. ordered_lsm_init();
  309. return 0;
  310. }
  311. /* Save user chosen LSM */
  312. static int __init choose_major_lsm(char *str)
  313. {
  314. chosen_major_lsm = str;
  315. return 1;
  316. }
  317. __setup("security=", choose_major_lsm);
  318. /* Explicitly choose LSM initialization order. */
  319. static int __init choose_lsm_order(char *str)
  320. {
  321. chosen_lsm_order = str;
  322. return 1;
  323. }
  324. __setup("lsm=", choose_lsm_order);
  325. /* Enable LSM order debugging. */
  326. static int __init enable_debug(char *str)
  327. {
  328. debug = true;
  329. return 1;
  330. }
  331. __setup("lsm.debug", enable_debug);
  332. static bool match_last_lsm(const char *list, const char *lsm)
  333. {
  334. const char *last;
  335. if (WARN_ON(!list || !lsm))
  336. return false;
  337. last = strrchr(list, ',');
  338. if (last)
  339. /* Pass the comma, strcmp() will check for '\0' */
  340. last++;
  341. else
  342. last = list;
  343. return !strcmp(last, lsm);
  344. }
  345. static int lsm_append(const char *new, char **result)
  346. {
  347. char *cp;
  348. if (*result == NULL) {
  349. *result = kstrdup(new, GFP_KERNEL);
  350. if (*result == NULL)
  351. return -ENOMEM;
  352. } else {
  353. /* Check if it is the last registered name */
  354. if (match_last_lsm(*result, new))
  355. return 0;
  356. cp = kasprintf(GFP_KERNEL, "%s,%s", *result, new);
  357. if (cp == NULL)
  358. return -ENOMEM;
  359. kfree(*result);
  360. *result = cp;
  361. }
  362. return 0;
  363. }
  364. /**
  365. * security_add_hooks - Add a modules hooks to the hook lists.
  366. * @hooks: the hooks to add
  367. * @count: the number of hooks to add
  368. * @lsm: the name of the security module
  369. *
  370. * Each LSM has to register its hooks with the infrastructure.
  371. */
  372. void __init security_add_hooks(struct security_hook_list *hooks, int count,
  373. char *lsm)
  374. {
  375. int i;
  376. for (i = 0; i < count; i++) {
  377. hooks[i].lsm = lsm;
  378. hlist_add_tail_rcu(&hooks[i].list, hooks[i].head);
  379. }
  380. /*
  381. * Don't try to append during early_security_init(), we'll come back
  382. * and fix this up afterwards.
  383. */
  384. if (slab_is_available()) {
  385. if (lsm_append(lsm, &lsm_names) < 0)
  386. panic("%s - Cannot get early memory.\n", __func__);
  387. }
  388. }
  389. int call_blocking_lsm_notifier(enum lsm_event event, void *data)
  390. {
  391. return blocking_notifier_call_chain(&blocking_lsm_notifier_chain,
  392. event, data);
  393. }
  394. EXPORT_SYMBOL(call_blocking_lsm_notifier);
  395. int register_blocking_lsm_notifier(struct notifier_block *nb)
  396. {
  397. return blocking_notifier_chain_register(&blocking_lsm_notifier_chain,
  398. nb);
  399. }
  400. EXPORT_SYMBOL(register_blocking_lsm_notifier);
  401. int unregister_blocking_lsm_notifier(struct notifier_block *nb)
  402. {
  403. return blocking_notifier_chain_unregister(&blocking_lsm_notifier_chain,
  404. nb);
  405. }
  406. EXPORT_SYMBOL(unregister_blocking_lsm_notifier);
  407. /**
  408. * lsm_cred_alloc - allocate a composite cred blob
  409. * @cred: the cred that needs a blob
  410. * @gfp: allocation type
  411. *
  412. * Allocate the cred blob for all the modules
  413. *
  414. * Returns 0, or -ENOMEM if memory can't be allocated.
  415. */
  416. static int lsm_cred_alloc(struct cred *cred, gfp_t gfp)
  417. {
  418. if (blob_sizes.lbs_cred == 0) {
  419. cred->security = NULL;
  420. return 0;
  421. }
  422. cred->security = kzalloc(blob_sizes.lbs_cred, gfp);
  423. if (cred->security == NULL)
  424. return -ENOMEM;
  425. return 0;
  426. }
  427. /**
  428. * lsm_early_cred - during initialization allocate a composite cred blob
  429. * @cred: the cred that needs a blob
  430. *
  431. * Allocate the cred blob for all the modules
  432. */
  433. static void __init lsm_early_cred(struct cred *cred)
  434. {
  435. int rc = lsm_cred_alloc(cred, GFP_KERNEL);
  436. if (rc)
  437. panic("%s: Early cred alloc failed.\n", __func__);
  438. }
  439. /**
  440. * lsm_file_alloc - allocate a composite file blob
  441. * @file: the file that needs a blob
  442. *
  443. * Allocate the file blob for all the modules
  444. *
  445. * Returns 0, or -ENOMEM if memory can't be allocated.
  446. */
  447. static int lsm_file_alloc(struct file *file)
  448. {
  449. if (!lsm_file_cache) {
  450. file->f_security = NULL;
  451. return 0;
  452. }
  453. file->f_security = kmem_cache_zalloc(lsm_file_cache, GFP_KERNEL);
  454. if (file->f_security == NULL)
  455. return -ENOMEM;
  456. return 0;
  457. }
  458. /**
  459. * lsm_inode_alloc - allocate a composite inode blob
  460. * @inode: the inode that needs a blob
  461. *
  462. * Allocate the inode blob for all the modules
  463. *
  464. * Returns 0, or -ENOMEM if memory can't be allocated.
  465. */
  466. int lsm_inode_alloc(struct inode *inode)
  467. {
  468. if (!lsm_inode_cache) {
  469. inode->i_security = NULL;
  470. return 0;
  471. }
  472. inode->i_security = kmem_cache_zalloc(lsm_inode_cache, GFP_NOFS);
  473. if (inode->i_security == NULL)
  474. return -ENOMEM;
  475. return 0;
  476. }
  477. /**
  478. * lsm_task_alloc - allocate a composite task blob
  479. * @task: the task that needs a blob
  480. *
  481. * Allocate the task blob for all the modules
  482. *
  483. * Returns 0, or -ENOMEM if memory can't be allocated.
  484. */
  485. static int lsm_task_alloc(struct task_struct *task)
  486. {
  487. if (blob_sizes.lbs_task == 0) {
  488. task->security = NULL;
  489. return 0;
  490. }
  491. task->security = kzalloc(blob_sizes.lbs_task, GFP_KERNEL);
  492. if (task->security == NULL)
  493. return -ENOMEM;
  494. return 0;
  495. }
  496. /**
  497. * lsm_ipc_alloc - allocate a composite ipc blob
  498. * @kip: the ipc that needs a blob
  499. *
  500. * Allocate the ipc blob for all the modules
  501. *
  502. * Returns 0, or -ENOMEM if memory can't be allocated.
  503. */
  504. static int lsm_ipc_alloc(struct kern_ipc_perm *kip)
  505. {
  506. if (blob_sizes.lbs_ipc == 0) {
  507. kip->security = NULL;
  508. return 0;
  509. }
  510. kip->security = kzalloc(blob_sizes.lbs_ipc, GFP_KERNEL);
  511. if (kip->security == NULL)
  512. return -ENOMEM;
  513. return 0;
  514. }
  515. /**
  516. * lsm_msg_msg_alloc - allocate a composite msg_msg blob
  517. * @mp: the msg_msg that needs a blob
  518. *
  519. * Allocate the ipc blob for all the modules
  520. *
  521. * Returns 0, or -ENOMEM if memory can't be allocated.
  522. */
  523. static int lsm_msg_msg_alloc(struct msg_msg *mp)
  524. {
  525. if (blob_sizes.lbs_msg_msg == 0) {
  526. mp->security = NULL;
  527. return 0;
  528. }
  529. mp->security = kzalloc(blob_sizes.lbs_msg_msg, GFP_KERNEL);
  530. if (mp->security == NULL)
  531. return -ENOMEM;
  532. return 0;
  533. }
  534. /**
  535. * lsm_early_task - during initialization allocate a composite task blob
  536. * @task: the task that needs a blob
  537. *
  538. * Allocate the task blob for all the modules
  539. */
  540. static void __init lsm_early_task(struct task_struct *task)
  541. {
  542. int rc = lsm_task_alloc(task);
  543. if (rc)
  544. panic("%s: Early task alloc failed.\n", __func__);
  545. }
  546. /*
  547. * The default value of the LSM hook is defined in linux/lsm_hook_defs.h and
  548. * can be accessed with:
  549. *
  550. * LSM_RET_DEFAULT(<hook_name>)
  551. *
  552. * The macros below define static constants for the default value of each
  553. * LSM hook.
  554. */
  555. #define LSM_RET_DEFAULT(NAME) (NAME##_default)
  556. #define DECLARE_LSM_RET_DEFAULT_void(DEFAULT, NAME)
  557. #define DECLARE_LSM_RET_DEFAULT_int(DEFAULT, NAME) \
  558. static const int LSM_RET_DEFAULT(NAME) = (DEFAULT);
  559. #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
  560. DECLARE_LSM_RET_DEFAULT_##RET(DEFAULT, NAME)
  561. #include <linux/lsm_hook_defs.h>
  562. #undef LSM_HOOK
  563. /*
  564. * Hook list operation macros.
  565. *
  566. * call_void_hook:
  567. * This is a hook that does not return a value.
  568. *
  569. * call_int_hook:
  570. * This is a hook that returns a value.
  571. */
  572. #define call_void_hook(FUNC, ...) \
  573. do { \
  574. struct security_hook_list *P; \
  575. \
  576. hlist_for_each_entry(P, &security_hook_heads.FUNC, list) \
  577. P->hook.FUNC(__VA_ARGS__); \
  578. } while (0)
  579. #define call_int_hook(FUNC, IRC, ...) ({ \
  580. int RC = IRC; \
  581. do { \
  582. struct security_hook_list *P; \
  583. \
  584. hlist_for_each_entry(P, &security_hook_heads.FUNC, list) { \
  585. RC = P->hook.FUNC(__VA_ARGS__); \
  586. if (RC != 0) \
  587. break; \
  588. } \
  589. } while (0); \
  590. RC; \
  591. })
  592. /* Security operations */
  593. int security_binder_set_context_mgr(const struct cred *mgr)
  594. {
  595. return call_int_hook(binder_set_context_mgr, 0, mgr);
  596. }
  597. int security_binder_transaction(const struct cred *from,
  598. const struct cred *to)
  599. {
  600. return call_int_hook(binder_transaction, 0, from, to);
  601. }
  602. int security_binder_transfer_binder(const struct cred *from,
  603. const struct cred *to)
  604. {
  605. return call_int_hook(binder_transfer_binder, 0, from, to);
  606. }
  607. int security_binder_transfer_file(const struct cred *from,
  608. const struct cred *to, struct file *file)
  609. {
  610. return call_int_hook(binder_transfer_file, 0, from, to, file);
  611. }
  612. int security_ptrace_access_check(struct task_struct *child, unsigned int mode)
  613. {
  614. return call_int_hook(ptrace_access_check, 0, child, mode);
  615. }
  616. int security_ptrace_traceme(struct task_struct *parent)
  617. {
  618. return call_int_hook(ptrace_traceme, 0, parent);
  619. }
  620. int security_capget(struct task_struct *target,
  621. kernel_cap_t *effective,
  622. kernel_cap_t *inheritable,
  623. kernel_cap_t *permitted)
  624. {
  625. return call_int_hook(capget, 0, target,
  626. effective, inheritable, permitted);
  627. }
  628. int security_capset(struct cred *new, const struct cred *old,
  629. const kernel_cap_t *effective,
  630. const kernel_cap_t *inheritable,
  631. const kernel_cap_t *permitted)
  632. {
  633. return call_int_hook(capset, 0, new, old,
  634. effective, inheritable, permitted);
  635. }
  636. int security_capable(const struct cred *cred,
  637. struct user_namespace *ns,
  638. int cap,
  639. unsigned int opts)
  640. {
  641. return call_int_hook(capable, 0, cred, ns, cap, opts);
  642. }
  643. int security_quotactl(int cmds, int type, int id, struct super_block *sb)
  644. {
  645. return call_int_hook(quotactl, 0, cmds, type, id, sb);
  646. }
  647. int security_quota_on(struct dentry *dentry)
  648. {
  649. return call_int_hook(quota_on, 0, dentry);
  650. }
  651. int security_syslog(int type)
  652. {
  653. return call_int_hook(syslog, 0, type);
  654. }
  655. int security_settime64(const struct timespec64 *ts, const struct timezone *tz)
  656. {
  657. return call_int_hook(settime, 0, ts, tz);
  658. }
  659. int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
  660. {
  661. struct security_hook_list *hp;
  662. int cap_sys_admin = 1;
  663. int rc;
  664. /*
  665. * The module will respond with a positive value if
  666. * it thinks the __vm_enough_memory() call should be
  667. * made with the cap_sys_admin set. If all of the modules
  668. * agree that it should be set it will. If any module
  669. * thinks it should not be set it won't.
  670. */
  671. hlist_for_each_entry(hp, &security_hook_heads.vm_enough_memory, list) {
  672. rc = hp->hook.vm_enough_memory(mm, pages);
  673. if (rc <= 0) {
  674. cap_sys_admin = 0;
  675. break;
  676. }
  677. }
  678. return __vm_enough_memory(mm, pages, cap_sys_admin);
  679. }
  680. int security_bprm_creds_for_exec(struct linux_binprm *bprm)
  681. {
  682. return call_int_hook(bprm_creds_for_exec, 0, bprm);
  683. }
  684. int security_bprm_creds_from_file(struct linux_binprm *bprm, struct file *file)
  685. {
  686. return call_int_hook(bprm_creds_from_file, 0, bprm, file);
  687. }
  688. int security_bprm_check(struct linux_binprm *bprm)
  689. {
  690. int ret;
  691. ret = call_int_hook(bprm_check_security, 0, bprm);
  692. if (ret)
  693. return ret;
  694. return ima_bprm_check(bprm);
  695. }
  696. void security_bprm_committing_creds(struct linux_binprm *bprm)
  697. {
  698. call_void_hook(bprm_committing_creds, bprm);
  699. }
  700. void security_bprm_committed_creds(struct linux_binprm *bprm)
  701. {
  702. call_void_hook(bprm_committed_creds, bprm);
  703. }
  704. int security_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc)
  705. {
  706. return call_int_hook(fs_context_dup, 0, fc, src_fc);
  707. }
  708. int security_fs_context_parse_param(struct fs_context *fc,
  709. struct fs_parameter *param)
  710. {
  711. struct security_hook_list *hp;
  712. int trc;
  713. int rc = -ENOPARAM;
  714. hlist_for_each_entry(hp, &security_hook_heads.fs_context_parse_param,
  715. list) {
  716. trc = hp->hook.fs_context_parse_param(fc, param);
  717. if (trc == 0)
  718. rc = 0;
  719. else if (trc != -ENOPARAM)
  720. return trc;
  721. }
  722. return rc;
  723. }
  724. int security_sb_alloc(struct super_block *sb)
  725. {
  726. return call_int_hook(sb_alloc_security, 0, sb);
  727. }
  728. void security_sb_free(struct super_block *sb)
  729. {
  730. call_void_hook(sb_free_security, sb);
  731. }
  732. void security_free_mnt_opts(void **mnt_opts)
  733. {
  734. if (!*mnt_opts)
  735. return;
  736. call_void_hook(sb_free_mnt_opts, *mnt_opts);
  737. *mnt_opts = NULL;
  738. }
  739. EXPORT_SYMBOL(security_free_mnt_opts);
  740. int security_sb_eat_lsm_opts(char *options, void **mnt_opts)
  741. {
  742. return call_int_hook(sb_eat_lsm_opts, 0, options, mnt_opts);
  743. }
  744. EXPORT_SYMBOL(security_sb_eat_lsm_opts);
  745. int security_sb_remount(struct super_block *sb,
  746. void *mnt_opts)
  747. {
  748. return call_int_hook(sb_remount, 0, sb, mnt_opts);
  749. }
  750. EXPORT_SYMBOL(security_sb_remount);
  751. int security_sb_kern_mount(struct super_block *sb)
  752. {
  753. return call_int_hook(sb_kern_mount, 0, sb);
  754. }
  755. int security_sb_show_options(struct seq_file *m, struct super_block *sb)
  756. {
  757. return call_int_hook(sb_show_options, 0, m, sb);
  758. }
  759. int security_sb_statfs(struct dentry *dentry)
  760. {
  761. return call_int_hook(sb_statfs, 0, dentry);
  762. }
  763. int security_sb_mount(const char *dev_name, const struct path *path,
  764. const char *type, unsigned long flags, void *data)
  765. {
  766. return call_int_hook(sb_mount, 0, dev_name, path, type, flags, data);
  767. }
  768. int security_sb_umount(struct vfsmount *mnt, int flags)
  769. {
  770. return call_int_hook(sb_umount, 0, mnt, flags);
  771. }
  772. int security_sb_pivotroot(const struct path *old_path, const struct path *new_path)
  773. {
  774. return call_int_hook(sb_pivotroot, 0, old_path, new_path);
  775. }
  776. int security_sb_set_mnt_opts(struct super_block *sb,
  777. void *mnt_opts,
  778. unsigned long kern_flags,
  779. unsigned long *set_kern_flags)
  780. {
  781. return call_int_hook(sb_set_mnt_opts,
  782. mnt_opts ? -EOPNOTSUPP : 0, sb,
  783. mnt_opts, kern_flags, set_kern_flags);
  784. }
  785. EXPORT_SYMBOL(security_sb_set_mnt_opts);
  786. int security_sb_clone_mnt_opts(const struct super_block *oldsb,
  787. struct super_block *newsb,
  788. unsigned long kern_flags,
  789. unsigned long *set_kern_flags)
  790. {
  791. return call_int_hook(sb_clone_mnt_opts, 0, oldsb, newsb,
  792. kern_flags, set_kern_flags);
  793. }
  794. EXPORT_SYMBOL(security_sb_clone_mnt_opts);
  795. int security_add_mnt_opt(const char *option, const char *val, int len,
  796. void **mnt_opts)
  797. {
  798. return call_int_hook(sb_add_mnt_opt, -EINVAL,
  799. option, val, len, mnt_opts);
  800. }
  801. EXPORT_SYMBOL(security_add_mnt_opt);
  802. int security_move_mount(const struct path *from_path, const struct path *to_path)
  803. {
  804. return call_int_hook(move_mount, 0, from_path, to_path);
  805. }
  806. int security_path_notify(const struct path *path, u64 mask,
  807. unsigned int obj_type)
  808. {
  809. return call_int_hook(path_notify, 0, path, mask, obj_type);
  810. }
  811. int security_inode_alloc(struct inode *inode)
  812. {
  813. int rc = lsm_inode_alloc(inode);
  814. if (unlikely(rc))
  815. return rc;
  816. rc = call_int_hook(inode_alloc_security, 0, inode);
  817. if (unlikely(rc))
  818. security_inode_free(inode);
  819. return rc;
  820. }
  821. static void inode_free_by_rcu(struct rcu_head *head)
  822. {
  823. /*
  824. * The rcu head is at the start of the inode blob
  825. */
  826. kmem_cache_free(lsm_inode_cache, head);
  827. }
  828. void security_inode_free(struct inode *inode)
  829. {
  830. integrity_inode_free(inode);
  831. call_void_hook(inode_free_security, inode);
  832. /*
  833. * The inode may still be referenced in a path walk and
  834. * a call to security_inode_permission() can be made
  835. * after inode_free_security() is called. Ideally, the VFS
  836. * wouldn't do this, but fixing that is a much harder
  837. * job. For now, simply free the i_security via RCU, and
  838. * leave the current inode->i_security pointer intact.
  839. * The inode will be freed after the RCU grace period too.
  840. */
  841. if (inode->i_security)
  842. call_rcu((struct rcu_head *)inode->i_security,
  843. inode_free_by_rcu);
  844. }
  845. int security_dentry_init_security(struct dentry *dentry, int mode,
  846. const struct qstr *name, void **ctx,
  847. u32 *ctxlen)
  848. {
  849. return call_int_hook(dentry_init_security, -EOPNOTSUPP, dentry, mode,
  850. name, ctx, ctxlen);
  851. }
  852. EXPORT_SYMBOL(security_dentry_init_security);
  853. int security_dentry_create_files_as(struct dentry *dentry, int mode,
  854. struct qstr *name,
  855. const struct cred *old, struct cred *new)
  856. {
  857. return call_int_hook(dentry_create_files_as, 0, dentry, mode,
  858. name, old, new);
  859. }
  860. EXPORT_SYMBOL(security_dentry_create_files_as);
  861. int security_inode_init_security(struct inode *inode, struct inode *dir,
  862. const struct qstr *qstr,
  863. const initxattrs initxattrs, void *fs_data)
  864. {
  865. struct xattr new_xattrs[MAX_LSM_EVM_XATTR + 1];
  866. struct xattr *lsm_xattr, *evm_xattr, *xattr;
  867. int ret;
  868. if (unlikely(IS_PRIVATE(inode)))
  869. return 0;
  870. if (!initxattrs)
  871. return call_int_hook(inode_init_security, -EOPNOTSUPP, inode,
  872. dir, qstr, NULL, NULL, NULL);
  873. memset(new_xattrs, 0, sizeof(new_xattrs));
  874. lsm_xattr = new_xattrs;
  875. ret = call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir, qstr,
  876. &lsm_xattr->name,
  877. &lsm_xattr->value,
  878. &lsm_xattr->value_len);
  879. if (ret)
  880. goto out;
  881. evm_xattr = lsm_xattr + 1;
  882. ret = evm_inode_init_security(inode, lsm_xattr, evm_xattr);
  883. if (ret)
  884. goto out;
  885. ret = initxattrs(inode, new_xattrs, fs_data);
  886. out:
  887. for (xattr = new_xattrs; xattr->value != NULL; xattr++)
  888. kfree(xattr->value);
  889. return (ret == -EOPNOTSUPP) ? 0 : ret;
  890. }
  891. EXPORT_SYMBOL(security_inode_init_security);
  892. int security_inode_init_security_anon(struct inode *inode,
  893. const struct qstr *name,
  894. const struct inode *context_inode)
  895. {
  896. return call_int_hook(inode_init_security_anon, 0, inode, name,
  897. context_inode);
  898. }
  899. int security_old_inode_init_security(struct inode *inode, struct inode *dir,
  900. const struct qstr *qstr, const char **name,
  901. void **value, size_t *len)
  902. {
  903. if (unlikely(IS_PRIVATE(inode)))
  904. return -EOPNOTSUPP;
  905. return call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir,
  906. qstr, name, value, len);
  907. }
  908. EXPORT_SYMBOL(security_old_inode_init_security);
  909. #ifdef CONFIG_SECURITY_PATH
  910. int security_path_mknod(const struct path *dir, struct dentry *dentry, umode_t mode,
  911. unsigned int dev)
  912. {
  913. if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
  914. return 0;
  915. return call_int_hook(path_mknod, 0, dir, dentry, mode, dev);
  916. }
  917. EXPORT_SYMBOL(security_path_mknod);
  918. int security_path_mkdir(const struct path *dir, struct dentry *dentry, umode_t mode)
  919. {
  920. if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
  921. return 0;
  922. return call_int_hook(path_mkdir, 0, dir, dentry, mode);
  923. }
  924. EXPORT_SYMBOL(security_path_mkdir);
  925. int security_path_rmdir(const struct path *dir, struct dentry *dentry)
  926. {
  927. if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
  928. return 0;
  929. return call_int_hook(path_rmdir, 0, dir, dentry);
  930. }
  931. int security_path_unlink(const struct path *dir, struct dentry *dentry)
  932. {
  933. if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
  934. return 0;
  935. return call_int_hook(path_unlink, 0, dir, dentry);
  936. }
  937. EXPORT_SYMBOL(security_path_unlink);
  938. int security_path_symlink(const struct path *dir, struct dentry *dentry,
  939. const char *old_name)
  940. {
  941. if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
  942. return 0;
  943. return call_int_hook(path_symlink, 0, dir, dentry, old_name);
  944. }
  945. int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
  946. struct dentry *new_dentry)
  947. {
  948. if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
  949. return 0;
  950. return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
  951. }
  952. int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
  953. const struct path *new_dir, struct dentry *new_dentry,
  954. unsigned int flags)
  955. {
  956. if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
  957. (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
  958. return 0;
  959. if (flags & RENAME_EXCHANGE) {
  960. int err = call_int_hook(path_rename, 0, new_dir, new_dentry,
  961. old_dir, old_dentry);
  962. if (err)
  963. return err;
  964. }
  965. return call_int_hook(path_rename, 0, old_dir, old_dentry, new_dir,
  966. new_dentry);
  967. }
  968. EXPORT_SYMBOL(security_path_rename);
  969. int security_path_truncate(const struct path *path)
  970. {
  971. if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
  972. return 0;
  973. return call_int_hook(path_truncate, 0, path);
  974. }
  975. int security_path_chmod(const struct path *path, umode_t mode)
  976. {
  977. if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
  978. return 0;
  979. return call_int_hook(path_chmod, 0, path, mode);
  980. }
  981. int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
  982. {
  983. if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
  984. return 0;
  985. return call_int_hook(path_chown, 0, path, uid, gid);
  986. }
  987. int security_path_chroot(const struct path *path)
  988. {
  989. return call_int_hook(path_chroot, 0, path);
  990. }
  991. #endif
  992. int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode)
  993. {
  994. if (unlikely(IS_PRIVATE(dir)))
  995. return 0;
  996. return call_int_hook(inode_create, 0, dir, dentry, mode);
  997. }
  998. EXPORT_SYMBOL_GPL(security_inode_create);
  999. int security_inode_link(struct dentry *old_dentry, struct inode *dir,
  1000. struct dentry *new_dentry)
  1001. {
  1002. if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
  1003. return 0;
  1004. return call_int_hook(inode_link, 0, old_dentry, dir, new_dentry);
  1005. }
  1006. int security_inode_unlink(struct inode *dir, struct dentry *dentry)
  1007. {
  1008. if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
  1009. return 0;
  1010. return call_int_hook(inode_unlink, 0, dir, dentry);
  1011. }
  1012. int security_inode_symlink(struct inode *dir, struct dentry *dentry,
  1013. const char *old_name)
  1014. {
  1015. if (unlikely(IS_PRIVATE(dir)))
  1016. return 0;
  1017. return call_int_hook(inode_symlink, 0, dir, dentry, old_name);
  1018. }
  1019. int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
  1020. {
  1021. if (unlikely(IS_PRIVATE(dir)))
  1022. return 0;
  1023. return call_int_hook(inode_mkdir, 0, dir, dentry, mode);
  1024. }
  1025. EXPORT_SYMBOL_GPL(security_inode_mkdir);
  1026. int security_inode_rmdir(struct inode *dir, struct dentry *dentry)
  1027. {
  1028. if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
  1029. return 0;
  1030. return call_int_hook(inode_rmdir, 0, dir, dentry);
  1031. }
  1032. int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
  1033. {
  1034. if (unlikely(IS_PRIVATE(dir)))
  1035. return 0;
  1036. return call_int_hook(inode_mknod, 0, dir, dentry, mode, dev);
  1037. }
  1038. int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
  1039. struct inode *new_dir, struct dentry *new_dentry,
  1040. unsigned int flags)
  1041. {
  1042. if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
  1043. (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
  1044. return 0;
  1045. if (flags & RENAME_EXCHANGE) {
  1046. int err = call_int_hook(inode_rename, 0, new_dir, new_dentry,
  1047. old_dir, old_dentry);
  1048. if (err)
  1049. return err;
  1050. }
  1051. return call_int_hook(inode_rename, 0, old_dir, old_dentry,
  1052. new_dir, new_dentry);
  1053. }
  1054. int security_inode_readlink(struct dentry *dentry)
  1055. {
  1056. if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
  1057. return 0;
  1058. return call_int_hook(inode_readlink, 0, dentry);
  1059. }
  1060. int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
  1061. bool rcu)
  1062. {
  1063. if (unlikely(IS_PRIVATE(inode)))
  1064. return 0;
  1065. return call_int_hook(inode_follow_link, 0, dentry, inode, rcu);
  1066. }
  1067. int security_inode_permission(struct inode *inode, int mask)
  1068. {
  1069. if (unlikely(IS_PRIVATE(inode)))
  1070. return 0;
  1071. return call_int_hook(inode_permission, 0, inode, mask);
  1072. }
  1073. int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
  1074. {
  1075. int ret;
  1076. if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
  1077. return 0;
  1078. ret = call_int_hook(inode_setattr, 0, dentry, attr);
  1079. if (ret)
  1080. return ret;
  1081. return evm_inode_setattr(dentry, attr);
  1082. }
  1083. EXPORT_SYMBOL_GPL(security_inode_setattr);
  1084. int security_inode_getattr(const struct path *path)
  1085. {
  1086. if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
  1087. return 0;
  1088. return call_int_hook(inode_getattr, 0, path);
  1089. }
  1090. int security_inode_setxattr(struct dentry *dentry, const char *name,
  1091. const void *value, size_t size, int flags)
  1092. {
  1093. int ret;
  1094. if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
  1095. return 0;
  1096. /*
  1097. * SELinux and Smack integrate the cap call,
  1098. * so assume that all LSMs supplying this call do so.
  1099. */
  1100. ret = call_int_hook(inode_setxattr, 1, dentry, name, value, size,
  1101. flags);
  1102. if (ret == 1)
  1103. ret = cap_inode_setxattr(dentry, name, value, size, flags);
  1104. if (ret)
  1105. return ret;
  1106. ret = ima_inode_setxattr(dentry, name, value, size);
  1107. if (ret)
  1108. return ret;
  1109. return evm_inode_setxattr(dentry, name, value, size);
  1110. }
  1111. void security_inode_post_setxattr(struct dentry *dentry, const char *name,
  1112. const void *value, size_t size, int flags)
  1113. {
  1114. if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
  1115. return;
  1116. call_void_hook(inode_post_setxattr, dentry, name, value, size, flags);
  1117. evm_inode_post_setxattr(dentry, name, value, size);
  1118. }
  1119. int security_inode_getxattr(struct dentry *dentry, const char *name)
  1120. {
  1121. if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
  1122. return 0;
  1123. return call_int_hook(inode_getxattr, 0, dentry, name);
  1124. }
  1125. int security_inode_listxattr(struct dentry *dentry)
  1126. {
  1127. if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
  1128. return 0;
  1129. return call_int_hook(inode_listxattr, 0, dentry);
  1130. }
  1131. int security_inode_removexattr(struct dentry *dentry, const char *name)
  1132. {
  1133. int ret;
  1134. if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
  1135. return 0;
  1136. /*
  1137. * SELinux and Smack integrate the cap call,
  1138. * so assume that all LSMs supplying this call do so.
  1139. */
  1140. ret = call_int_hook(inode_removexattr, 1, dentry, name);
  1141. if (ret == 1)
  1142. ret = cap_inode_removexattr(dentry, name);
  1143. if (ret)
  1144. return ret;
  1145. ret = ima_inode_removexattr(dentry, name);
  1146. if (ret)
  1147. return ret;
  1148. return evm_inode_removexattr(dentry, name);
  1149. }
  1150. int security_inode_need_killpriv(struct dentry *dentry)
  1151. {
  1152. return call_int_hook(inode_need_killpriv, 0, dentry);
  1153. }
  1154. int security_inode_killpriv(struct dentry *dentry)
  1155. {
  1156. return call_int_hook(inode_killpriv, 0, dentry);
  1157. }
  1158. int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc)
  1159. {
  1160. struct security_hook_list *hp;
  1161. int rc;
  1162. if (unlikely(IS_PRIVATE(inode)))
  1163. return LSM_RET_DEFAULT(inode_getsecurity);
  1164. /*
  1165. * Only one module will provide an attribute with a given name.
  1166. */
  1167. hlist_for_each_entry(hp, &security_hook_heads.inode_getsecurity, list) {
  1168. rc = hp->hook.inode_getsecurity(inode, name, buffer, alloc);
  1169. if (rc != LSM_RET_DEFAULT(inode_getsecurity))
  1170. return rc;
  1171. }
  1172. return LSM_RET_DEFAULT(inode_getsecurity);
  1173. }
  1174. int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
  1175. {
  1176. struct security_hook_list *hp;
  1177. int rc;
  1178. if (unlikely(IS_PRIVATE(inode)))
  1179. return LSM_RET_DEFAULT(inode_setsecurity);
  1180. /*
  1181. * Only one module will provide an attribute with a given name.
  1182. */
  1183. hlist_for_each_entry(hp, &security_hook_heads.inode_setsecurity, list) {
  1184. rc = hp->hook.inode_setsecurity(inode, name, value, size,
  1185. flags);
  1186. if (rc != LSM_RET_DEFAULT(inode_setsecurity))
  1187. return rc;
  1188. }
  1189. return LSM_RET_DEFAULT(inode_setsecurity);
  1190. }
  1191. int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
  1192. {
  1193. if (unlikely(IS_PRIVATE(inode)))
  1194. return 0;
  1195. return call_int_hook(inode_listsecurity, 0, inode, buffer, buffer_size);
  1196. }
  1197. EXPORT_SYMBOL(security_inode_listsecurity);
  1198. void security_inode_getsecid(struct inode *inode, u32 *secid)
  1199. {
  1200. call_void_hook(inode_getsecid, inode, secid);
  1201. }
  1202. int security_inode_copy_up(struct dentry *src, struct cred **new)
  1203. {
  1204. return call_int_hook(inode_copy_up, 0, src, new);
  1205. }
  1206. EXPORT_SYMBOL(security_inode_copy_up);
  1207. int security_inode_copy_up_xattr(const char *name)
  1208. {
  1209. struct security_hook_list *hp;
  1210. int rc;
  1211. /*
  1212. * The implementation can return 0 (accept the xattr), 1 (discard the
  1213. * xattr), -EOPNOTSUPP if it does not know anything about the xattr or
  1214. * any other error code incase of an error.
  1215. */
  1216. hlist_for_each_entry(hp,
  1217. &security_hook_heads.inode_copy_up_xattr, list) {
  1218. rc = hp->hook.inode_copy_up_xattr(name);
  1219. if (rc != LSM_RET_DEFAULT(inode_copy_up_xattr))
  1220. return rc;
  1221. }
  1222. return LSM_RET_DEFAULT(inode_copy_up_xattr);
  1223. }
  1224. EXPORT_SYMBOL(security_inode_copy_up_xattr);
  1225. int security_kernfs_init_security(struct kernfs_node *kn_dir,
  1226. struct kernfs_node *kn)
  1227. {
  1228. return call_int_hook(kernfs_init_security, 0, kn_dir, kn);
  1229. }
  1230. int security_file_permission(struct file *file, int mask)
  1231. {
  1232. int ret;
  1233. ret = call_int_hook(file_permission, 0, file, mask);
  1234. if (ret)
  1235. return ret;
  1236. return fsnotify_perm(file, mask);
  1237. }
  1238. int security_file_alloc(struct file *file)
  1239. {
  1240. int rc = lsm_file_alloc(file);
  1241. if (rc)
  1242. return rc;
  1243. rc = call_int_hook(file_alloc_security, 0, file);
  1244. if (unlikely(rc))
  1245. security_file_free(file);
  1246. return rc;
  1247. }
  1248. void security_file_free(struct file *file)
  1249. {
  1250. void *blob;
  1251. call_void_hook(file_free_security, file);
  1252. blob = file->f_security;
  1253. if (blob) {
  1254. file->f_security = NULL;
  1255. kmem_cache_free(lsm_file_cache, blob);
  1256. }
  1257. }
  1258. int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  1259. {
  1260. return call_int_hook(file_ioctl, 0, file, cmd, arg);
  1261. }
  1262. EXPORT_SYMBOL_GPL(security_file_ioctl);
  1263. static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
  1264. {
  1265. /*
  1266. * Does we have PROT_READ and does the application expect
  1267. * it to imply PROT_EXEC? If not, nothing to talk about...
  1268. */
  1269. if ((prot & (PROT_READ | PROT_EXEC)) != PROT_READ)
  1270. return prot;
  1271. if (!(current->personality & READ_IMPLIES_EXEC))
  1272. return prot;
  1273. /*
  1274. * if that's an anonymous mapping, let it.
  1275. */
  1276. if (!file)
  1277. return prot | PROT_EXEC;
  1278. /*
  1279. * ditto if it's not on noexec mount, except that on !MMU we need
  1280. * NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case
  1281. */
  1282. if (!path_noexec(&file->f_path)) {
  1283. #ifndef CONFIG_MMU
  1284. if (file->f_op->mmap_capabilities) {
  1285. unsigned caps = file->f_op->mmap_capabilities(file);
  1286. if (!(caps & NOMMU_MAP_EXEC))
  1287. return prot;
  1288. }
  1289. #endif
  1290. return prot | PROT_EXEC;
  1291. }
  1292. /* anything on noexec mount won't get PROT_EXEC */
  1293. return prot;
  1294. }
  1295. int security_mmap_file(struct file *file, unsigned long prot,
  1296. unsigned long flags)
  1297. {
  1298. int ret;
  1299. ret = call_int_hook(mmap_file, 0, file, prot,
  1300. mmap_prot(file, prot), flags);
  1301. if (ret)
  1302. return ret;
  1303. return ima_file_mmap(file, prot);
  1304. }
  1305. int security_mmap_addr(unsigned long addr)
  1306. {
  1307. return call_int_hook(mmap_addr, 0, addr);
  1308. }
  1309. int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
  1310. unsigned long prot)
  1311. {
  1312. int ret;
  1313. ret = call_int_hook(file_mprotect, 0, vma, reqprot, prot);
  1314. if (ret)
  1315. return ret;
  1316. return ima_file_mprotect(vma, prot);
  1317. }
  1318. int security_file_lock(struct file *file, unsigned int cmd)
  1319. {
  1320. return call_int_hook(file_lock, 0, file, cmd);
  1321. }
  1322. int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
  1323. {
  1324. return call_int_hook(file_fcntl, 0, file, cmd, arg);
  1325. }
  1326. void security_file_set_fowner(struct file *file)
  1327. {
  1328. call_void_hook(file_set_fowner, file);
  1329. }
  1330. int security_file_send_sigiotask(struct task_struct *tsk,
  1331. struct fown_struct *fown, int sig)
  1332. {
  1333. return call_int_hook(file_send_sigiotask, 0, tsk, fown, sig);
  1334. }
  1335. int security_file_receive(struct file *file)
  1336. {
  1337. return call_int_hook(file_receive, 0, file);
  1338. }
  1339. int security_file_open(struct file *file)
  1340. {
  1341. int ret;
  1342. ret = call_int_hook(file_open, 0, file);
  1343. if (ret)
  1344. return ret;
  1345. return fsnotify_perm(file, MAY_OPEN);
  1346. }
  1347. int security_task_alloc(struct task_struct *task, unsigned long clone_flags)
  1348. {
  1349. int rc = lsm_task_alloc(task);
  1350. if (rc)
  1351. return rc;
  1352. rc = call_int_hook(task_alloc, 0, task, clone_flags);
  1353. if (unlikely(rc))
  1354. security_task_free(task);
  1355. return rc;
  1356. }
  1357. void security_task_free(struct task_struct *task)
  1358. {
  1359. call_void_hook(task_free, task);
  1360. kfree(task->security);
  1361. task->security = NULL;
  1362. }
  1363. int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
  1364. {
  1365. int rc = lsm_cred_alloc(cred, gfp);
  1366. if (rc)
  1367. return rc;
  1368. rc = call_int_hook(cred_alloc_blank, 0, cred, gfp);
  1369. if (unlikely(rc))
  1370. security_cred_free(cred);
  1371. return rc;
  1372. }
  1373. void security_cred_free(struct cred *cred)
  1374. {
  1375. /*
  1376. * There is a failure case in prepare_creds() that
  1377. * may result in a call here with ->security being NULL.
  1378. */
  1379. if (unlikely(cred->security == NULL))
  1380. return;
  1381. call_void_hook(cred_free, cred);
  1382. kfree(cred->security);
  1383. cred->security = NULL;
  1384. }
  1385. int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp)
  1386. {
  1387. int rc = lsm_cred_alloc(new, gfp);
  1388. if (rc)
  1389. return rc;
  1390. rc = call_int_hook(cred_prepare, 0, new, old, gfp);
  1391. if (unlikely(rc))
  1392. security_cred_free(new);
  1393. return rc;
  1394. }
  1395. void security_transfer_creds(struct cred *new, const struct cred *old)
  1396. {
  1397. call_void_hook(cred_transfer, new, old);
  1398. }
  1399. void security_cred_getsecid(const struct cred *c, u32 *secid)
  1400. {
  1401. *secid = 0;
  1402. call_void_hook(cred_getsecid, c, secid);
  1403. }
  1404. EXPORT_SYMBOL(security_cred_getsecid);
  1405. int security_kernel_act_as(struct cred *new, u32 secid)
  1406. {
  1407. return call_int_hook(kernel_act_as, 0, new, secid);
  1408. }
  1409. int security_kernel_create_files_as(struct cred *new, struct inode *inode)
  1410. {
  1411. return call_int_hook(kernel_create_files_as, 0, new, inode);
  1412. }
  1413. int security_kernel_module_request(char *kmod_name)
  1414. {
  1415. int ret;
  1416. ret = call_int_hook(kernel_module_request, 0, kmod_name);
  1417. if (ret)
  1418. return ret;
  1419. return integrity_kernel_module_request(kmod_name);
  1420. }
  1421. int security_kernel_read_file(struct file *file, enum kernel_read_file_id id,
  1422. bool contents)
  1423. {
  1424. int ret;
  1425. ret = call_int_hook(kernel_read_file, 0, file, id, contents);
  1426. if (ret)
  1427. return ret;
  1428. return ima_read_file(file, id, contents);
  1429. }
  1430. EXPORT_SYMBOL_GPL(security_kernel_read_file);
  1431. int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
  1432. enum kernel_read_file_id id)
  1433. {
  1434. int ret;
  1435. ret = call_int_hook(kernel_post_read_file, 0, file, buf, size, id);
  1436. if (ret)
  1437. return ret;
  1438. return ima_post_read_file(file, buf, size, id);
  1439. }
  1440. EXPORT_SYMBOL_GPL(security_kernel_post_read_file);
  1441. int security_kernel_load_data(enum kernel_load_data_id id, bool contents)
  1442. {
  1443. int ret;
  1444. ret = call_int_hook(kernel_load_data, 0, id, contents);
  1445. if (ret)
  1446. return ret;
  1447. return ima_load_data(id, contents);
  1448. }
  1449. EXPORT_SYMBOL_GPL(security_kernel_load_data);
  1450. int security_kernel_post_load_data(char *buf, loff_t size,
  1451. enum kernel_load_data_id id,
  1452. char *description)
  1453. {
  1454. int ret;
  1455. ret = call_int_hook(kernel_post_load_data, 0, buf, size, id,
  1456. description);
  1457. if (ret)
  1458. return ret;
  1459. return ima_post_load_data(buf, size, id, description);
  1460. }
  1461. EXPORT_SYMBOL_GPL(security_kernel_post_load_data);
  1462. int security_task_fix_setuid(struct cred *new, const struct cred *old,
  1463. int flags)
  1464. {
  1465. return call_int_hook(task_fix_setuid, 0, new, old, flags);
  1466. }
  1467. int security_task_fix_setgid(struct cred *new, const struct cred *old,
  1468. int flags)
  1469. {
  1470. return call_int_hook(task_fix_setgid, 0, new, old, flags);
  1471. }
  1472. int security_task_setpgid(struct task_struct *p, pid_t pgid)
  1473. {
  1474. return call_int_hook(task_setpgid, 0, p, pgid);
  1475. }
  1476. int security_task_getpgid(struct task_struct *p)
  1477. {
  1478. return call_int_hook(task_getpgid, 0, p);
  1479. }
  1480. int security_task_getsid(struct task_struct *p)
  1481. {
  1482. return call_int_hook(task_getsid, 0, p);
  1483. }
  1484. void security_task_getsecid(struct task_struct *p, u32 *secid)
  1485. {
  1486. *secid = 0;
  1487. call_void_hook(task_getsecid, p, secid);
  1488. }
  1489. EXPORT_SYMBOL(security_task_getsecid);
  1490. int security_task_setnice(struct task_struct *p, int nice)
  1491. {
  1492. return call_int_hook(task_setnice, 0, p, nice);
  1493. }
  1494. int security_task_setioprio(struct task_struct *p, int ioprio)
  1495. {
  1496. return call_int_hook(task_setioprio, 0, p, ioprio);
  1497. }
  1498. int security_task_getioprio(struct task_struct *p)
  1499. {
  1500. return call_int_hook(task_getioprio, 0, p);
  1501. }
  1502. int security_task_prlimit(const struct cred *cred, const struct cred *tcred,
  1503. unsigned int flags)
  1504. {
  1505. return call_int_hook(task_prlimit, 0, cred, tcred, flags);
  1506. }
  1507. int security_task_setrlimit(struct task_struct *p, unsigned int resource,
  1508. struct rlimit *new_rlim)
  1509. {
  1510. return call_int_hook(task_setrlimit, 0, p, resource, new_rlim);
  1511. }
  1512. int security_task_setscheduler(struct task_struct *p)
  1513. {
  1514. return call_int_hook(task_setscheduler, 0, p);
  1515. }
  1516. int security_task_getscheduler(struct task_struct *p)
  1517. {
  1518. return call_int_hook(task_getscheduler, 0, p);
  1519. }
  1520. int security_task_movememory(struct task_struct *p)
  1521. {
  1522. return call_int_hook(task_movememory, 0, p);
  1523. }
  1524. int security_task_kill(struct task_struct *p, struct kernel_siginfo *info,
  1525. int sig, const struct cred *cred)
  1526. {
  1527. return call_int_hook(task_kill, 0, p, info, sig, cred);
  1528. }
  1529. int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
  1530. unsigned long arg4, unsigned long arg5)
  1531. {
  1532. int thisrc;
  1533. int rc = LSM_RET_DEFAULT(task_prctl);
  1534. struct security_hook_list *hp;
  1535. hlist_for_each_entry(hp, &security_hook_heads.task_prctl, list) {
  1536. thisrc = hp->hook.task_prctl(option, arg2, arg3, arg4, arg5);
  1537. if (thisrc != LSM_RET_DEFAULT(task_prctl)) {
  1538. rc = thisrc;
  1539. if (thisrc != 0)
  1540. break;
  1541. }
  1542. }
  1543. return rc;
  1544. }
  1545. void security_task_to_inode(struct task_struct *p, struct inode *inode)
  1546. {
  1547. call_void_hook(task_to_inode, p, inode);
  1548. }
  1549. int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
  1550. {
  1551. return call_int_hook(ipc_permission, 0, ipcp, flag);
  1552. }
  1553. void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
  1554. {
  1555. *secid = 0;
  1556. call_void_hook(ipc_getsecid, ipcp, secid);
  1557. }
  1558. int security_msg_msg_alloc(struct msg_msg *msg)
  1559. {
  1560. int rc = lsm_msg_msg_alloc(msg);
  1561. if (unlikely(rc))
  1562. return rc;
  1563. rc = call_int_hook(msg_msg_alloc_security, 0, msg);
  1564. if (unlikely(rc))
  1565. security_msg_msg_free(msg);
  1566. return rc;
  1567. }
  1568. void security_msg_msg_free(struct msg_msg *msg)
  1569. {
  1570. call_void_hook(msg_msg_free_security, msg);
  1571. kfree(msg->security);
  1572. msg->security = NULL;
  1573. }
  1574. int security_msg_queue_alloc(struct kern_ipc_perm *msq)
  1575. {
  1576. int rc = lsm_ipc_alloc(msq);
  1577. if (unlikely(rc))
  1578. return rc;
  1579. rc = call_int_hook(msg_queue_alloc_security, 0, msq);
  1580. if (unlikely(rc))
  1581. security_msg_queue_free(msq);
  1582. return rc;
  1583. }
  1584. void security_msg_queue_free(struct kern_ipc_perm *msq)
  1585. {
  1586. call_void_hook(msg_queue_free_security, msq);
  1587. kfree(msq->security);
  1588. msq->security = NULL;
  1589. }
  1590. int security_msg_queue_associate(struct kern_ipc_perm *msq, int msqflg)
  1591. {
  1592. return call_int_hook(msg_queue_associate, 0, msq, msqflg);
  1593. }
  1594. int security_msg_queue_msgctl(struct kern_ipc_perm *msq, int cmd)
  1595. {
  1596. return call_int_hook(msg_queue_msgctl, 0, msq, cmd);
  1597. }
  1598. int security_msg_queue_msgsnd(struct kern_ipc_perm *msq,
  1599. struct msg_msg *msg, int msqflg)
  1600. {
  1601. return call_int_hook(msg_queue_msgsnd, 0, msq, msg, msqflg);
  1602. }
  1603. int security_msg_queue_msgrcv(struct kern_ipc_perm *msq, struct msg_msg *msg,
  1604. struct task_struct *target, long type, int mode)
  1605. {
  1606. return call_int_hook(msg_queue_msgrcv, 0, msq, msg, target, type, mode);
  1607. }
  1608. int security_shm_alloc(struct kern_ipc_perm *shp)
  1609. {
  1610. int rc = lsm_ipc_alloc(shp);
  1611. if (unlikely(rc))
  1612. return rc;
  1613. rc = call_int_hook(shm_alloc_security, 0, shp);
  1614. if (unlikely(rc))
  1615. security_shm_free(shp);
  1616. return rc;
  1617. }
  1618. void security_shm_free(struct kern_ipc_perm *shp)
  1619. {
  1620. call_void_hook(shm_free_security, shp);
  1621. kfree(shp->security);
  1622. shp->security = NULL;
  1623. }
  1624. int security_shm_associate(struct kern_ipc_perm *shp, int shmflg)
  1625. {
  1626. return call_int_hook(shm_associate, 0, shp, shmflg);
  1627. }
  1628. int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd)
  1629. {
  1630. return call_int_hook(shm_shmctl, 0, shp, cmd);
  1631. }
  1632. int security_shm_shmat(struct kern_ipc_perm *shp, char __user *shmaddr, int shmflg)
  1633. {
  1634. return call_int_hook(shm_shmat, 0, shp, shmaddr, shmflg);
  1635. }
  1636. int security_sem_alloc(struct kern_ipc_perm *sma)
  1637. {
  1638. int rc = lsm_ipc_alloc(sma);
  1639. if (unlikely(rc))
  1640. return rc;
  1641. rc = call_int_hook(sem_alloc_security, 0, sma);
  1642. if (unlikely(rc))
  1643. security_sem_free(sma);
  1644. return rc;
  1645. }
  1646. void security_sem_free(struct kern_ipc_perm *sma)
  1647. {
  1648. call_void_hook(sem_free_security, sma);
  1649. kfree(sma->security);
  1650. sma->security = NULL;
  1651. }
  1652. int security_sem_associate(struct kern_ipc_perm *sma, int semflg)
  1653. {
  1654. return call_int_hook(sem_associate, 0, sma, semflg);
  1655. }
  1656. int security_sem_semctl(struct kern_ipc_perm *sma, int cmd)
  1657. {
  1658. return call_int_hook(sem_semctl, 0, sma, cmd);
  1659. }
  1660. int security_sem_semop(struct kern_ipc_perm *sma, struct sembuf *sops,
  1661. unsigned nsops, int alter)
  1662. {
  1663. return call_int_hook(sem_semop, 0, sma, sops, nsops, alter);
  1664. }
  1665. void security_d_instantiate(struct dentry *dentry, struct inode *inode)
  1666. {
  1667. if (unlikely(inode && IS_PRIVATE(inode)))
  1668. return;
  1669. call_void_hook(d_instantiate, dentry, inode);
  1670. }
  1671. EXPORT_SYMBOL(security_d_instantiate);
  1672. int security_getprocattr(struct task_struct *p, const char *lsm, char *name,
  1673. char **value)
  1674. {
  1675. struct security_hook_list *hp;
  1676. hlist_for_each_entry(hp, &security_hook_heads.getprocattr, list) {
  1677. if (lsm != NULL && strcmp(lsm, hp->lsm))
  1678. continue;
  1679. return hp->hook.getprocattr(p, name, value);
  1680. }
  1681. return LSM_RET_DEFAULT(getprocattr);
  1682. }
  1683. int security_setprocattr(const char *lsm, const char *name, void *value,
  1684. size_t size)
  1685. {
  1686. struct security_hook_list *hp;
  1687. hlist_for_each_entry(hp, &security_hook_heads.setprocattr, list) {
  1688. if (lsm != NULL && strcmp(lsm, hp->lsm))
  1689. continue;
  1690. return hp->hook.setprocattr(name, value, size);
  1691. }
  1692. return LSM_RET_DEFAULT(setprocattr);
  1693. }
  1694. int security_netlink_send(struct sock *sk, struct sk_buff *skb)
  1695. {
  1696. return call_int_hook(netlink_send, 0, sk, skb);
  1697. }
  1698. int security_ismaclabel(const char *name)
  1699. {
  1700. return call_int_hook(ismaclabel, 0, name);
  1701. }
  1702. EXPORT_SYMBOL(security_ismaclabel);
  1703. int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
  1704. {
  1705. struct security_hook_list *hp;
  1706. int rc;
  1707. /*
  1708. * Currently, only one LSM can implement secid_to_secctx (i.e this
  1709. * LSM hook is not "stackable").
  1710. */
  1711. hlist_for_each_entry(hp, &security_hook_heads.secid_to_secctx, list) {
  1712. rc = hp->hook.secid_to_secctx(secid, secdata, seclen);
  1713. if (rc != LSM_RET_DEFAULT(secid_to_secctx))
  1714. return rc;
  1715. }
  1716. return LSM_RET_DEFAULT(secid_to_secctx);
  1717. }
  1718. EXPORT_SYMBOL(security_secid_to_secctx);
  1719. int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
  1720. {
  1721. *secid = 0;
  1722. return call_int_hook(secctx_to_secid, 0, secdata, seclen, secid);
  1723. }
  1724. EXPORT_SYMBOL(security_secctx_to_secid);
  1725. void security_release_secctx(char *secdata, u32 seclen)
  1726. {
  1727. call_void_hook(release_secctx, secdata, seclen);
  1728. }
  1729. EXPORT_SYMBOL(security_release_secctx);
  1730. void security_inode_invalidate_secctx(struct inode *inode)
  1731. {
  1732. call_void_hook(inode_invalidate_secctx, inode);
  1733. }
  1734. EXPORT_SYMBOL(security_inode_invalidate_secctx);
  1735. int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
  1736. {
  1737. return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen);
  1738. }
  1739. EXPORT_SYMBOL(security_inode_notifysecctx);
  1740. int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
  1741. {
  1742. return call_int_hook(inode_setsecctx, 0, dentry, ctx, ctxlen);
  1743. }
  1744. EXPORT_SYMBOL(security_inode_setsecctx);
  1745. int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
  1746. {
  1747. return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen);
  1748. }
  1749. EXPORT_SYMBOL(security_inode_getsecctx);
  1750. #ifdef CONFIG_WATCH_QUEUE
  1751. int security_post_notification(const struct cred *w_cred,
  1752. const struct cred *cred,
  1753. struct watch_notification *n)
  1754. {
  1755. return call_int_hook(post_notification, 0, w_cred, cred, n);
  1756. }
  1757. #endif /* CONFIG_WATCH_QUEUE */
  1758. #ifdef CONFIG_KEY_NOTIFICATIONS
  1759. int security_watch_key(struct key *key)
  1760. {
  1761. return call_int_hook(watch_key, 0, key);
  1762. }
  1763. #endif
  1764. #ifdef CONFIG_SECURITY_NETWORK
  1765. int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk)
  1766. {
  1767. return call_int_hook(unix_stream_connect, 0, sock, other, newsk);
  1768. }
  1769. EXPORT_SYMBOL(security_unix_stream_connect);
  1770. int security_unix_may_send(struct socket *sock, struct socket *other)
  1771. {
  1772. return call_int_hook(unix_may_send, 0, sock, other);
  1773. }
  1774. EXPORT_SYMBOL(security_unix_may_send);
  1775. int security_socket_create(int family, int type, int protocol, int kern)
  1776. {
  1777. return call_int_hook(socket_create, 0, family, type, protocol, kern);
  1778. }
  1779. int security_socket_post_create(struct socket *sock, int family,
  1780. int type, int protocol, int kern)
  1781. {
  1782. return call_int_hook(socket_post_create, 0, sock, family, type,
  1783. protocol, kern);
  1784. }
  1785. int security_socket_socketpair(struct socket *socka, struct socket *sockb)
  1786. {
  1787. return call_int_hook(socket_socketpair, 0, socka, sockb);
  1788. }
  1789. EXPORT_SYMBOL(security_socket_socketpair);
  1790. int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
  1791. {
  1792. return call_int_hook(socket_bind, 0, sock, address, addrlen);
  1793. }
  1794. int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
  1795. {
  1796. return call_int_hook(socket_connect, 0, sock, address, addrlen);
  1797. }
  1798. int security_socket_listen(struct socket *sock, int backlog)
  1799. {
  1800. return call_int_hook(socket_listen, 0, sock, backlog);
  1801. }
  1802. int security_socket_accept(struct socket *sock, struct socket *newsock)
  1803. {
  1804. return call_int_hook(socket_accept, 0, sock, newsock);
  1805. }
  1806. int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
  1807. {
  1808. return call_int_hook(socket_sendmsg, 0, sock, msg, size);
  1809. }
  1810. int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
  1811. int size, int flags)
  1812. {
  1813. return call_int_hook(socket_recvmsg, 0, sock, msg, size, flags);
  1814. }
  1815. int security_socket_getsockname(struct socket *sock)
  1816. {
  1817. return call_int_hook(socket_getsockname, 0, sock);
  1818. }
  1819. int security_socket_getpeername(struct socket *sock)
  1820. {
  1821. return call_int_hook(socket_getpeername, 0, sock);
  1822. }
  1823. int security_socket_getsockopt(struct socket *sock, int level, int optname)
  1824. {
  1825. return call_int_hook(socket_getsockopt, 0, sock, level, optname);
  1826. }
  1827. int security_socket_setsockopt(struct socket *sock, int level, int optname)
  1828. {
  1829. return call_int_hook(socket_setsockopt, 0, sock, level, optname);
  1830. }
  1831. int security_socket_shutdown(struct socket *sock, int how)
  1832. {
  1833. return call_int_hook(socket_shutdown, 0, sock, how);
  1834. }
  1835. int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
  1836. {
  1837. return call_int_hook(socket_sock_rcv_skb, 0, sk, skb);
  1838. }
  1839. EXPORT_SYMBOL(security_sock_rcv_skb);
  1840. int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
  1841. int __user *optlen, unsigned len)
  1842. {
  1843. return call_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock,
  1844. optval, optlen, len);
  1845. }
  1846. int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
  1847. {
  1848. return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock,
  1849. skb, secid);
  1850. }
  1851. EXPORT_SYMBOL(security_socket_getpeersec_dgram);
  1852. int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
  1853. {
  1854. return call_int_hook(sk_alloc_security, 0, sk, family, priority);
  1855. }
  1856. void security_sk_free(struct sock *sk)
  1857. {
  1858. call_void_hook(sk_free_security, sk);
  1859. }
  1860. void security_sk_clone(const struct sock *sk, struct sock *newsk)
  1861. {
  1862. call_void_hook(sk_clone_security, sk, newsk);
  1863. }
  1864. EXPORT_SYMBOL(security_sk_clone);
  1865. void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
  1866. {
  1867. call_void_hook(sk_getsecid, sk, &fl->flowi_secid);
  1868. }
  1869. EXPORT_SYMBOL(security_sk_classify_flow);
  1870. void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
  1871. {
  1872. call_void_hook(req_classify_flow, req, fl);
  1873. }
  1874. EXPORT_SYMBOL(security_req_classify_flow);
  1875. void security_sock_graft(struct sock *sk, struct socket *parent)
  1876. {
  1877. call_void_hook(sock_graft, sk, parent);
  1878. }
  1879. EXPORT_SYMBOL(security_sock_graft);
  1880. int security_inet_conn_request(struct sock *sk,
  1881. struct sk_buff *skb, struct request_sock *req)
  1882. {
  1883. return call_int_hook(inet_conn_request, 0, sk, skb, req);
  1884. }
  1885. EXPORT_SYMBOL(security_inet_conn_request);
  1886. void security_inet_csk_clone(struct sock *newsk,
  1887. const struct request_sock *req)
  1888. {
  1889. call_void_hook(inet_csk_clone, newsk, req);
  1890. }
  1891. void security_inet_conn_established(struct sock *sk,
  1892. struct sk_buff *skb)
  1893. {
  1894. call_void_hook(inet_conn_established, sk, skb);
  1895. }
  1896. EXPORT_SYMBOL(security_inet_conn_established);
  1897. int security_secmark_relabel_packet(u32 secid)
  1898. {
  1899. return call_int_hook(secmark_relabel_packet, 0, secid);
  1900. }
  1901. EXPORT_SYMBOL(security_secmark_relabel_packet);
  1902. void security_secmark_refcount_inc(void)
  1903. {
  1904. call_void_hook(secmark_refcount_inc);
  1905. }
  1906. EXPORT_SYMBOL(security_secmark_refcount_inc);
  1907. void security_secmark_refcount_dec(void)
  1908. {
  1909. call_void_hook(secmark_refcount_dec);
  1910. }
  1911. EXPORT_SYMBOL(security_secmark_refcount_dec);
  1912. int security_tun_dev_alloc_security(void **security)
  1913. {
  1914. return call_int_hook(tun_dev_alloc_security, 0, security);
  1915. }
  1916. EXPORT_SYMBOL(security_tun_dev_alloc_security);
  1917. void security_tun_dev_free_security(void *security)
  1918. {
  1919. call_void_hook(tun_dev_free_security, security);
  1920. }
  1921. EXPORT_SYMBOL(security_tun_dev_free_security);
  1922. int security_tun_dev_create(void)
  1923. {
  1924. return call_int_hook(tun_dev_create, 0);
  1925. }
  1926. EXPORT_SYMBOL(security_tun_dev_create);
  1927. int security_tun_dev_attach_queue(void *security)
  1928. {
  1929. return call_int_hook(tun_dev_attach_queue, 0, security);
  1930. }
  1931. EXPORT_SYMBOL(security_tun_dev_attach_queue);
  1932. int security_tun_dev_attach(struct sock *sk, void *security)
  1933. {
  1934. return call_int_hook(tun_dev_attach, 0, sk, security);
  1935. }
  1936. EXPORT_SYMBOL(security_tun_dev_attach);
  1937. int security_tun_dev_open(void *security)
  1938. {
  1939. return call_int_hook(tun_dev_open, 0, security);
  1940. }
  1941. EXPORT_SYMBOL(security_tun_dev_open);
  1942. int security_sctp_assoc_request(struct sctp_endpoint *ep, struct sk_buff *skb)
  1943. {
  1944. return call_int_hook(sctp_assoc_request, 0, ep, skb);
  1945. }
  1946. EXPORT_SYMBOL(security_sctp_assoc_request);
  1947. int security_sctp_bind_connect(struct sock *sk, int optname,
  1948. struct sockaddr *address, int addrlen)
  1949. {
  1950. return call_int_hook(sctp_bind_connect, 0, sk, optname,
  1951. address, addrlen);
  1952. }
  1953. EXPORT_SYMBOL(security_sctp_bind_connect);
  1954. void security_sctp_sk_clone(struct sctp_endpoint *ep, struct sock *sk,
  1955. struct sock *newsk)
  1956. {
  1957. call_void_hook(sctp_sk_clone, ep, sk, newsk);
  1958. }
  1959. EXPORT_SYMBOL(security_sctp_sk_clone);
  1960. #endif /* CONFIG_SECURITY_NETWORK */
  1961. #ifdef CONFIG_SECURITY_INFINIBAND
  1962. int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey)
  1963. {
  1964. return call_int_hook(ib_pkey_access, 0, sec, subnet_prefix, pkey);
  1965. }
  1966. EXPORT_SYMBOL(security_ib_pkey_access);
  1967. int security_ib_endport_manage_subnet(void *sec, const char *dev_name, u8 port_num)
  1968. {
  1969. return call_int_hook(ib_endport_manage_subnet, 0, sec, dev_name, port_num);
  1970. }
  1971. EXPORT_SYMBOL(security_ib_endport_manage_subnet);
  1972. int security_ib_alloc_security(void **sec)
  1973. {
  1974. return call_int_hook(ib_alloc_security, 0, sec);
  1975. }
  1976. EXPORT_SYMBOL(security_ib_alloc_security);
  1977. void security_ib_free_security(void *sec)
  1978. {
  1979. call_void_hook(ib_free_security, sec);
  1980. }
  1981. EXPORT_SYMBOL(security_ib_free_security);
  1982. #endif /* CONFIG_SECURITY_INFINIBAND */
  1983. #ifdef CONFIG_SECURITY_NETWORK_XFRM
  1984. int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
  1985. struct xfrm_user_sec_ctx *sec_ctx,
  1986. gfp_t gfp)
  1987. {
  1988. return call_int_hook(xfrm_policy_alloc_security, 0, ctxp, sec_ctx, gfp);
  1989. }
  1990. EXPORT_SYMBOL(security_xfrm_policy_alloc);
  1991. int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
  1992. struct xfrm_sec_ctx **new_ctxp)
  1993. {
  1994. return call_int_hook(xfrm_policy_clone_security, 0, old_ctx, new_ctxp);
  1995. }
  1996. void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
  1997. {
  1998. call_void_hook(xfrm_policy_free_security, ctx);
  1999. }
  2000. EXPORT_SYMBOL(security_xfrm_policy_free);
  2001. int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
  2002. {
  2003. return call_int_hook(xfrm_policy_delete_security, 0, ctx);
  2004. }
  2005. int security_xfrm_state_alloc(struct xfrm_state *x,
  2006. struct xfrm_user_sec_ctx *sec_ctx)
  2007. {
  2008. return call_int_hook(xfrm_state_alloc, 0, x, sec_ctx);
  2009. }
  2010. EXPORT_SYMBOL(security_xfrm_state_alloc);
  2011. int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
  2012. struct xfrm_sec_ctx *polsec, u32 secid)
  2013. {
  2014. return call_int_hook(xfrm_state_alloc_acquire, 0, x, polsec, secid);
  2015. }
  2016. int security_xfrm_state_delete(struct xfrm_state *x)
  2017. {
  2018. return call_int_hook(xfrm_state_delete_security, 0, x);
  2019. }
  2020. EXPORT_SYMBOL(security_xfrm_state_delete);
  2021. void security_xfrm_state_free(struct xfrm_state *x)
  2022. {
  2023. call_void_hook(xfrm_state_free_security, x);
  2024. }
  2025. int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
  2026. {
  2027. return call_int_hook(xfrm_policy_lookup, 0, ctx, fl_secid, dir);
  2028. }
  2029. int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
  2030. struct xfrm_policy *xp,
  2031. const struct flowi *fl)
  2032. {
  2033. struct security_hook_list *hp;
  2034. int rc = LSM_RET_DEFAULT(xfrm_state_pol_flow_match);
  2035. /*
  2036. * Since this function is expected to return 0 or 1, the judgment
  2037. * becomes difficult if multiple LSMs supply this call. Fortunately,
  2038. * we can use the first LSM's judgment because currently only SELinux
  2039. * supplies this call.
  2040. *
  2041. * For speed optimization, we explicitly break the loop rather than
  2042. * using the macro
  2043. */
  2044. hlist_for_each_entry(hp, &security_hook_heads.xfrm_state_pol_flow_match,
  2045. list) {
  2046. rc = hp->hook.xfrm_state_pol_flow_match(x, xp, fl);
  2047. break;
  2048. }
  2049. return rc;
  2050. }
  2051. int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
  2052. {
  2053. return call_int_hook(xfrm_decode_session, 0, skb, secid, 1);
  2054. }
  2055. void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
  2056. {
  2057. int rc = call_int_hook(xfrm_decode_session, 0, skb, &fl->flowi_secid,
  2058. 0);
  2059. BUG_ON(rc);
  2060. }
  2061. EXPORT_SYMBOL(security_skb_classify_flow);
  2062. #endif /* CONFIG_SECURITY_NETWORK_XFRM */
  2063. #ifdef CONFIG_KEYS
  2064. int security_key_alloc(struct key *key, const struct cred *cred,
  2065. unsigned long flags)
  2066. {
  2067. return call_int_hook(key_alloc, 0, key, cred, flags);
  2068. }
  2069. void security_key_free(struct key *key)
  2070. {
  2071. call_void_hook(key_free, key);
  2072. }
  2073. int security_key_permission(key_ref_t key_ref, const struct cred *cred,
  2074. enum key_need_perm need_perm)
  2075. {
  2076. return call_int_hook(key_permission, 0, key_ref, cred, need_perm);
  2077. }
  2078. int security_key_getsecurity(struct key *key, char **_buffer)
  2079. {
  2080. *_buffer = NULL;
  2081. return call_int_hook(key_getsecurity, 0, key, _buffer);
  2082. }
  2083. #endif /* CONFIG_KEYS */
  2084. #ifdef CONFIG_AUDIT
  2085. int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule)
  2086. {
  2087. return call_int_hook(audit_rule_init, 0, field, op, rulestr, lsmrule);
  2088. }
  2089. int security_audit_rule_known(struct audit_krule *krule)
  2090. {
  2091. return call_int_hook(audit_rule_known, 0, krule);
  2092. }
  2093. void security_audit_rule_free(void *lsmrule)
  2094. {
  2095. call_void_hook(audit_rule_free, lsmrule);
  2096. }
  2097. int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule)
  2098. {
  2099. return call_int_hook(audit_rule_match, 0, secid, field, op, lsmrule);
  2100. }
  2101. #endif /* CONFIG_AUDIT */
  2102. #ifdef CONFIG_BPF_SYSCALL
  2103. int security_bpf(int cmd, union bpf_attr *attr, unsigned int size)
  2104. {
  2105. return call_int_hook(bpf, 0, cmd, attr, size);
  2106. }
  2107. int security_bpf_map(struct bpf_map *map, fmode_t fmode)
  2108. {
  2109. return call_int_hook(bpf_map, 0, map, fmode);
  2110. }
  2111. int security_bpf_prog(struct bpf_prog *prog)
  2112. {
  2113. return call_int_hook(bpf_prog, 0, prog);
  2114. }
  2115. int security_bpf_map_alloc(struct bpf_map *map)
  2116. {
  2117. return call_int_hook(bpf_map_alloc_security, 0, map);
  2118. }
  2119. int security_bpf_prog_alloc(struct bpf_prog_aux *aux)
  2120. {
  2121. return call_int_hook(bpf_prog_alloc_security, 0, aux);
  2122. }
  2123. void security_bpf_map_free(struct bpf_map *map)
  2124. {
  2125. call_void_hook(bpf_map_free_security, map);
  2126. }
  2127. void security_bpf_prog_free(struct bpf_prog_aux *aux)
  2128. {
  2129. call_void_hook(bpf_prog_free_security, aux);
  2130. }
  2131. #endif /* CONFIG_BPF_SYSCALL */
  2132. int security_locked_down(enum lockdown_reason what)
  2133. {
  2134. return call_int_hook(locked_down, 0, what);
  2135. }
  2136. EXPORT_SYMBOL(security_locked_down);
  2137. #ifdef CONFIG_PERF_EVENTS
  2138. int security_perf_event_open(struct perf_event_attr *attr, int type)
  2139. {
  2140. return call_int_hook(perf_event_open, 0, attr, type);
  2141. }
  2142. int security_perf_event_alloc(struct perf_event *event)
  2143. {
  2144. return call_int_hook(perf_event_alloc, 0, event);
  2145. }
  2146. void security_perf_event_free(struct perf_event *event)
  2147. {
  2148. call_void_hook(perf_event_free, event);
  2149. }
  2150. int security_perf_event_read(struct perf_event *event)
  2151. {
  2152. return call_int_hook(perf_event_read, 0, event);
  2153. }
  2154. int security_perf_event_write(struct perf_event *event)
  2155. {
  2156. return call_int_hook(perf_event_write, 0, event);
  2157. }
  2158. #endif /* CONFIG_PERF_EVENTS */