avc.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  1. /*
  2. * Implementation of the kernel access vector cache (AVC).
  3. *
  4. * Authors: Stephen Smalley, <sds@tycho.nsa.gov>
  5. * James Morris <jmorris@redhat.com>
  6. *
  7. * Update: KaiGai, Kohei <kaigai@ak.jp.nec.com>
  8. * Replaced the avc_lock spinlock by RCU.
  9. *
  10. * Copyright (C) 2003 Red Hat, Inc., James Morris <jmorris@redhat.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2,
  14. * as published by the Free Software Foundation.
  15. */
  16. #include <linux/types.h>
  17. #include <linux/stddef.h>
  18. #include <linux/kernel.h>
  19. #include <linux/slab.h>
  20. #include <linux/fs.h>
  21. #include <linux/dcache.h>
  22. #include <linux/init.h>
  23. #include <linux/skbuff.h>
  24. #include <linux/percpu.h>
  25. #include <linux/list.h>
  26. #include <net/sock.h>
  27. #include <linux/un.h>
  28. #include <net/af_unix.h>
  29. #include <linux/ip.h>
  30. #include <linux/audit.h>
  31. #include <linux/ipv6.h>
  32. #include <net/ipv6.h>
  33. #include "avc.h"
  34. #include "avc_ss.h"
  35. #include "classmap.h"
  36. #define AVC_CACHE_SLOTS 512
  37. #define AVC_DEF_CACHE_THRESHOLD 512
  38. #define AVC_CACHE_RECLAIM 16
  39. #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
  40. #define avc_cache_stats_incr(field) this_cpu_inc(avc_cache_stats.field)
  41. #else
  42. #define avc_cache_stats_incr(field) do {} while (0)
  43. #endif
  44. struct avc_entry {
  45. u32 ssid;
  46. u32 tsid;
  47. u16 tclass;
  48. struct av_decision avd;
  49. struct avc_xperms_node *xp_node;
  50. };
  51. struct avc_node {
  52. struct avc_entry ae;
  53. struct hlist_node list; /* anchored in avc_cache->slots[i] */
  54. struct rcu_head rhead;
  55. };
  56. struct avc_xperms_decision_node {
  57. struct extended_perms_decision xpd;
  58. struct list_head xpd_list; /* list of extended_perms_decision */
  59. };
  60. struct avc_xperms_node {
  61. struct extended_perms xp;
  62. struct list_head xpd_head; /* list head of extended_perms_decision */
  63. };
  64. struct avc_cache {
  65. struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
  66. spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
  67. atomic_t lru_hint; /* LRU hint for reclaim scan */
  68. atomic_t active_nodes;
  69. u32 latest_notif; /* latest revocation notification */
  70. };
  71. struct avc_callback_node {
  72. int (*callback) (u32 event);
  73. u32 events;
  74. struct avc_callback_node *next;
  75. };
  76. #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
  77. DEFINE_PER_CPU(struct avc_cache_stats, avc_cache_stats) = { 0 };
  78. #endif
  79. struct selinux_avc {
  80. unsigned int avc_cache_threshold;
  81. struct avc_cache avc_cache;
  82. };
  83. static struct selinux_avc selinux_avc;
  84. void selinux_avc_init(struct selinux_avc **avc)
  85. {
  86. int i;
  87. selinux_avc.avc_cache_threshold = AVC_DEF_CACHE_THRESHOLD;
  88. for (i = 0; i < AVC_CACHE_SLOTS; i++) {
  89. INIT_HLIST_HEAD(&selinux_avc.avc_cache.slots[i]);
  90. spin_lock_init(&selinux_avc.avc_cache.slots_lock[i]);
  91. }
  92. atomic_set(&selinux_avc.avc_cache.active_nodes, 0);
  93. atomic_set(&selinux_avc.avc_cache.lru_hint, 0);
  94. *avc = &selinux_avc;
  95. }
  96. unsigned int avc_get_cache_threshold(struct selinux_avc *avc)
  97. {
  98. return avc->avc_cache_threshold;
  99. }
  100. void avc_set_cache_threshold(struct selinux_avc *avc,
  101. unsigned int cache_threshold)
  102. {
  103. avc->avc_cache_threshold = cache_threshold;
  104. }
  105. static struct avc_callback_node *avc_callbacks;
  106. static struct kmem_cache *avc_node_cachep;
  107. static struct kmem_cache *avc_xperms_data_cachep;
  108. static struct kmem_cache *avc_xperms_decision_cachep;
  109. static struct kmem_cache *avc_xperms_cachep;
  110. static inline int avc_hash(u32 ssid, u32 tsid, u16 tclass)
  111. {
  112. return (ssid ^ (tsid<<2) ^ (tclass<<4)) & (AVC_CACHE_SLOTS - 1);
  113. }
  114. /**
  115. * avc_dump_av - Display an access vector in human-readable form.
  116. * @tclass: target security class
  117. * @av: access vector
  118. */
  119. static void avc_dump_av(struct audit_buffer *ab, u16 tclass, u32 av)
  120. {
  121. const char **perms;
  122. int i, perm;
  123. if (av == 0) {
  124. audit_log_format(ab, " null");
  125. return;
  126. }
  127. BUG_ON(!tclass || tclass >= ARRAY_SIZE(secclass_map));
  128. perms = secclass_map[tclass-1].perms;
  129. audit_log_format(ab, " {");
  130. i = 0;
  131. perm = 1;
  132. while (i < (sizeof(av) * 8)) {
  133. if ((perm & av) && perms[i]) {
  134. audit_log_format(ab, " %s", perms[i]);
  135. av &= ~perm;
  136. }
  137. i++;
  138. perm <<= 1;
  139. }
  140. if (av)
  141. audit_log_format(ab, " 0x%x", av);
  142. audit_log_format(ab, " }");
  143. }
  144. /**
  145. * avc_dump_query - Display a SID pair and a class in human-readable form.
  146. * @ssid: source security identifier
  147. * @tsid: target security identifier
  148. * @tclass: target security class
  149. */
  150. static void avc_dump_query(struct audit_buffer *ab, struct selinux_state *state,
  151. u32 ssid, u32 tsid, u16 tclass)
  152. {
  153. int rc;
  154. char *scontext;
  155. u32 scontext_len;
  156. rc = security_sid_to_context(state, ssid, &scontext, &scontext_len);
  157. if (rc)
  158. audit_log_format(ab, "ssid=%d", ssid);
  159. else {
  160. audit_log_format(ab, "scontext=%s", scontext);
  161. kfree(scontext);
  162. }
  163. rc = security_sid_to_context(state, tsid, &scontext, &scontext_len);
  164. if (rc)
  165. audit_log_format(ab, " tsid=%d", tsid);
  166. else {
  167. audit_log_format(ab, " tcontext=%s", scontext);
  168. kfree(scontext);
  169. }
  170. BUG_ON(!tclass || tclass >= ARRAY_SIZE(secclass_map));
  171. audit_log_format(ab, " tclass=%s", secclass_map[tclass-1].name);
  172. }
  173. /**
  174. * avc_init - Initialize the AVC.
  175. *
  176. * Initialize the access vector cache.
  177. */
  178. void __init avc_init(void)
  179. {
  180. avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
  181. 0, SLAB_PANIC, NULL);
  182. avc_xperms_cachep = kmem_cache_create("avc_xperms_node",
  183. sizeof(struct avc_xperms_node),
  184. 0, SLAB_PANIC, NULL);
  185. avc_xperms_decision_cachep = kmem_cache_create(
  186. "avc_xperms_decision_node",
  187. sizeof(struct avc_xperms_decision_node),
  188. 0, SLAB_PANIC, NULL);
  189. avc_xperms_data_cachep = kmem_cache_create("avc_xperms_data",
  190. sizeof(struct extended_perms_data),
  191. 0, SLAB_PANIC, NULL);
  192. }
  193. int avc_get_hash_stats(struct selinux_avc *avc, char *page)
  194. {
  195. int i, chain_len, max_chain_len, slots_used;
  196. struct avc_node *node;
  197. struct hlist_head *head;
  198. rcu_read_lock();
  199. slots_used = 0;
  200. max_chain_len = 0;
  201. for (i = 0; i < AVC_CACHE_SLOTS; i++) {
  202. head = &avc->avc_cache.slots[i];
  203. if (!hlist_empty(head)) {
  204. slots_used++;
  205. chain_len = 0;
  206. hlist_for_each_entry_rcu(node, head, list)
  207. chain_len++;
  208. if (chain_len > max_chain_len)
  209. max_chain_len = chain_len;
  210. }
  211. }
  212. rcu_read_unlock();
  213. return scnprintf(page, PAGE_SIZE, "entries: %d\nbuckets used: %d/%d\n"
  214. "longest chain: %d\n",
  215. atomic_read(&avc->avc_cache.active_nodes),
  216. slots_used, AVC_CACHE_SLOTS, max_chain_len);
  217. }
  218. /*
  219. * using a linked list for extended_perms_decision lookup because the list is
  220. * always small. i.e. less than 5, typically 1
  221. */
  222. static struct extended_perms_decision *avc_xperms_decision_lookup(u8 driver,
  223. struct avc_xperms_node *xp_node)
  224. {
  225. struct avc_xperms_decision_node *xpd_node;
  226. list_for_each_entry(xpd_node, &xp_node->xpd_head, xpd_list) {
  227. if (xpd_node->xpd.driver == driver)
  228. return &xpd_node->xpd;
  229. }
  230. return NULL;
  231. }
  232. static inline unsigned int
  233. avc_xperms_has_perm(struct extended_perms_decision *xpd,
  234. u8 perm, u8 which)
  235. {
  236. unsigned int rc = 0;
  237. if ((which == XPERMS_ALLOWED) &&
  238. (xpd->used & XPERMS_ALLOWED))
  239. rc = security_xperm_test(xpd->allowed->p, perm);
  240. else if ((which == XPERMS_AUDITALLOW) &&
  241. (xpd->used & XPERMS_AUDITALLOW))
  242. rc = security_xperm_test(xpd->auditallow->p, perm);
  243. else if ((which == XPERMS_DONTAUDIT) &&
  244. (xpd->used & XPERMS_DONTAUDIT))
  245. rc = security_xperm_test(xpd->dontaudit->p, perm);
  246. return rc;
  247. }
  248. static void avc_xperms_allow_perm(struct avc_xperms_node *xp_node,
  249. u8 driver, u8 perm)
  250. {
  251. struct extended_perms_decision *xpd;
  252. security_xperm_set(xp_node->xp.drivers.p, driver);
  253. xpd = avc_xperms_decision_lookup(driver, xp_node);
  254. if (xpd && xpd->allowed)
  255. security_xperm_set(xpd->allowed->p, perm);
  256. }
  257. static void avc_xperms_decision_free(struct avc_xperms_decision_node *xpd_node)
  258. {
  259. struct extended_perms_decision *xpd;
  260. xpd = &xpd_node->xpd;
  261. if (xpd->allowed)
  262. kmem_cache_free(avc_xperms_data_cachep, xpd->allowed);
  263. if (xpd->auditallow)
  264. kmem_cache_free(avc_xperms_data_cachep, xpd->auditallow);
  265. if (xpd->dontaudit)
  266. kmem_cache_free(avc_xperms_data_cachep, xpd->dontaudit);
  267. kmem_cache_free(avc_xperms_decision_cachep, xpd_node);
  268. }
  269. static void avc_xperms_free(struct avc_xperms_node *xp_node)
  270. {
  271. struct avc_xperms_decision_node *xpd_node, *tmp;
  272. if (!xp_node)
  273. return;
  274. list_for_each_entry_safe(xpd_node, tmp, &xp_node->xpd_head, xpd_list) {
  275. list_del(&xpd_node->xpd_list);
  276. avc_xperms_decision_free(xpd_node);
  277. }
  278. kmem_cache_free(avc_xperms_cachep, xp_node);
  279. }
  280. static void avc_copy_xperms_decision(struct extended_perms_decision *dest,
  281. struct extended_perms_decision *src)
  282. {
  283. dest->driver = src->driver;
  284. dest->used = src->used;
  285. if (dest->used & XPERMS_ALLOWED)
  286. memcpy(dest->allowed->p, src->allowed->p,
  287. sizeof(src->allowed->p));
  288. if (dest->used & XPERMS_AUDITALLOW)
  289. memcpy(dest->auditallow->p, src->auditallow->p,
  290. sizeof(src->auditallow->p));
  291. if (dest->used & XPERMS_DONTAUDIT)
  292. memcpy(dest->dontaudit->p, src->dontaudit->p,
  293. sizeof(src->dontaudit->p));
  294. }
  295. /*
  296. * similar to avc_copy_xperms_decision, but only copy decision
  297. * information relevant to this perm
  298. */
  299. static inline void avc_quick_copy_xperms_decision(u8 perm,
  300. struct extended_perms_decision *dest,
  301. struct extended_perms_decision *src)
  302. {
  303. /*
  304. * compute index of the u32 of the 256 bits (8 u32s) that contain this
  305. * command permission
  306. */
  307. u8 i = perm >> 5;
  308. dest->used = src->used;
  309. if (dest->used & XPERMS_ALLOWED)
  310. dest->allowed->p[i] = src->allowed->p[i];
  311. if (dest->used & XPERMS_AUDITALLOW)
  312. dest->auditallow->p[i] = src->auditallow->p[i];
  313. if (dest->used & XPERMS_DONTAUDIT)
  314. dest->dontaudit->p[i] = src->dontaudit->p[i];
  315. }
  316. static struct avc_xperms_decision_node
  317. *avc_xperms_decision_alloc(u8 which)
  318. {
  319. struct avc_xperms_decision_node *xpd_node;
  320. struct extended_perms_decision *xpd;
  321. xpd_node = kmem_cache_zalloc(avc_xperms_decision_cachep,
  322. GFP_NOWAIT | __GFP_NOWARN);
  323. if (!xpd_node)
  324. return NULL;
  325. xpd = &xpd_node->xpd;
  326. if (which & XPERMS_ALLOWED) {
  327. xpd->allowed = kmem_cache_zalloc(avc_xperms_data_cachep,
  328. GFP_NOWAIT | __GFP_NOWARN);
  329. if (!xpd->allowed)
  330. goto error;
  331. }
  332. if (which & XPERMS_AUDITALLOW) {
  333. xpd->auditallow = kmem_cache_zalloc(avc_xperms_data_cachep,
  334. GFP_NOWAIT | __GFP_NOWARN);
  335. if (!xpd->auditallow)
  336. goto error;
  337. }
  338. if (which & XPERMS_DONTAUDIT) {
  339. xpd->dontaudit = kmem_cache_zalloc(avc_xperms_data_cachep,
  340. GFP_NOWAIT | __GFP_NOWARN);
  341. if (!xpd->dontaudit)
  342. goto error;
  343. }
  344. return xpd_node;
  345. error:
  346. avc_xperms_decision_free(xpd_node);
  347. return NULL;
  348. }
  349. static int avc_add_xperms_decision(struct avc_node *node,
  350. struct extended_perms_decision *src)
  351. {
  352. struct avc_xperms_decision_node *dest_xpd;
  353. node->ae.xp_node->xp.len++;
  354. dest_xpd = avc_xperms_decision_alloc(src->used);
  355. if (!dest_xpd)
  356. return -ENOMEM;
  357. avc_copy_xperms_decision(&dest_xpd->xpd, src);
  358. list_add(&dest_xpd->xpd_list, &node->ae.xp_node->xpd_head);
  359. return 0;
  360. }
  361. static struct avc_xperms_node *avc_xperms_alloc(void)
  362. {
  363. struct avc_xperms_node *xp_node;
  364. xp_node = kmem_cache_zalloc(avc_xperms_cachep, GFP_NOWAIT | __GFP_NOWARN);
  365. if (!xp_node)
  366. return xp_node;
  367. INIT_LIST_HEAD(&xp_node->xpd_head);
  368. return xp_node;
  369. }
  370. static int avc_xperms_populate(struct avc_node *node,
  371. struct avc_xperms_node *src)
  372. {
  373. struct avc_xperms_node *dest;
  374. struct avc_xperms_decision_node *dest_xpd;
  375. struct avc_xperms_decision_node *src_xpd;
  376. if (src->xp.len == 0)
  377. return 0;
  378. dest = avc_xperms_alloc();
  379. if (!dest)
  380. return -ENOMEM;
  381. memcpy(dest->xp.drivers.p, src->xp.drivers.p, sizeof(dest->xp.drivers.p));
  382. dest->xp.len = src->xp.len;
  383. /* for each source xpd allocate a destination xpd and copy */
  384. list_for_each_entry(src_xpd, &src->xpd_head, xpd_list) {
  385. dest_xpd = avc_xperms_decision_alloc(src_xpd->xpd.used);
  386. if (!dest_xpd)
  387. goto error;
  388. avc_copy_xperms_decision(&dest_xpd->xpd, &src_xpd->xpd);
  389. list_add(&dest_xpd->xpd_list, &dest->xpd_head);
  390. }
  391. node->ae.xp_node = dest;
  392. return 0;
  393. error:
  394. avc_xperms_free(dest);
  395. return -ENOMEM;
  396. }
  397. static inline u32 avc_xperms_audit_required(u32 requested,
  398. struct av_decision *avd,
  399. struct extended_perms_decision *xpd,
  400. u8 perm,
  401. int result,
  402. u32 *deniedp)
  403. {
  404. u32 denied, audited;
  405. denied = requested & ~avd->allowed;
  406. if (unlikely(denied)) {
  407. audited = denied & avd->auditdeny;
  408. if (audited && xpd) {
  409. if (avc_xperms_has_perm(xpd, perm, XPERMS_DONTAUDIT))
  410. audited &= ~requested;
  411. }
  412. } else if (result) {
  413. audited = denied = requested;
  414. } else {
  415. audited = requested & avd->auditallow;
  416. if (audited && xpd) {
  417. if (!avc_xperms_has_perm(xpd, perm, XPERMS_AUDITALLOW))
  418. audited &= ~requested;
  419. }
  420. }
  421. *deniedp = denied;
  422. return audited;
  423. }
  424. static inline int avc_xperms_audit(struct selinux_state *state,
  425. u32 ssid, u32 tsid, u16 tclass,
  426. u32 requested, struct av_decision *avd,
  427. struct extended_perms_decision *xpd,
  428. u8 perm, int result,
  429. struct common_audit_data *ad)
  430. {
  431. u32 audited, denied;
  432. audited = avc_xperms_audit_required(
  433. requested, avd, xpd, perm, result, &denied);
  434. if (likely(!audited))
  435. return 0;
  436. return slow_avc_audit(state, ssid, tsid, tclass, requested,
  437. audited, denied, result, ad, 0);
  438. }
  439. static void avc_node_free(struct rcu_head *rhead)
  440. {
  441. struct avc_node *node = container_of(rhead, struct avc_node, rhead);
  442. avc_xperms_free(node->ae.xp_node);
  443. kmem_cache_free(avc_node_cachep, node);
  444. avc_cache_stats_incr(frees);
  445. }
  446. static void avc_node_delete(struct selinux_avc *avc, struct avc_node *node)
  447. {
  448. hlist_del_rcu(&node->list);
  449. call_rcu(&node->rhead, avc_node_free);
  450. atomic_dec(&avc->avc_cache.active_nodes);
  451. }
  452. static void avc_node_kill(struct selinux_avc *avc, struct avc_node *node)
  453. {
  454. avc_xperms_free(node->ae.xp_node);
  455. kmem_cache_free(avc_node_cachep, node);
  456. avc_cache_stats_incr(frees);
  457. atomic_dec(&avc->avc_cache.active_nodes);
  458. }
  459. static void avc_node_replace(struct selinux_avc *avc,
  460. struct avc_node *new, struct avc_node *old)
  461. {
  462. hlist_replace_rcu(&old->list, &new->list);
  463. call_rcu(&old->rhead, avc_node_free);
  464. atomic_dec(&avc->avc_cache.active_nodes);
  465. }
  466. static inline int avc_reclaim_node(struct selinux_avc *avc)
  467. {
  468. struct avc_node *node;
  469. int hvalue, try, ecx;
  470. unsigned long flags;
  471. struct hlist_head *head;
  472. spinlock_t *lock;
  473. for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
  474. hvalue = atomic_inc_return(&avc->avc_cache.lru_hint) &
  475. (AVC_CACHE_SLOTS - 1);
  476. head = &avc->avc_cache.slots[hvalue];
  477. lock = &avc->avc_cache.slots_lock[hvalue];
  478. if (!spin_trylock_irqsave(lock, flags))
  479. continue;
  480. rcu_read_lock();
  481. hlist_for_each_entry(node, head, list) {
  482. avc_node_delete(avc, node);
  483. avc_cache_stats_incr(reclaims);
  484. ecx++;
  485. if (ecx >= AVC_CACHE_RECLAIM) {
  486. rcu_read_unlock();
  487. spin_unlock_irqrestore(lock, flags);
  488. goto out;
  489. }
  490. }
  491. rcu_read_unlock();
  492. spin_unlock_irqrestore(lock, flags);
  493. }
  494. out:
  495. return ecx;
  496. }
  497. static struct avc_node *avc_alloc_node(struct selinux_avc *avc)
  498. {
  499. struct avc_node *node;
  500. node = kmem_cache_zalloc(avc_node_cachep, GFP_NOWAIT | __GFP_NOWARN);
  501. if (!node)
  502. goto out;
  503. INIT_HLIST_NODE(&node->list);
  504. avc_cache_stats_incr(allocations);
  505. if (atomic_inc_return(&avc->avc_cache.active_nodes) >
  506. avc->avc_cache_threshold)
  507. avc_reclaim_node(avc);
  508. out:
  509. return node;
  510. }
  511. static void avc_node_populate(struct avc_node *node, u32 ssid, u32 tsid, u16 tclass, struct av_decision *avd)
  512. {
  513. node->ae.ssid = ssid;
  514. node->ae.tsid = tsid;
  515. node->ae.tclass = tclass;
  516. memcpy(&node->ae.avd, avd, sizeof(node->ae.avd));
  517. }
  518. static inline struct avc_node *avc_search_node(struct selinux_avc *avc,
  519. u32 ssid, u32 tsid, u16 tclass)
  520. {
  521. struct avc_node *node, *ret = NULL;
  522. int hvalue;
  523. struct hlist_head *head;
  524. hvalue = avc_hash(ssid, tsid, tclass);
  525. head = &avc->avc_cache.slots[hvalue];
  526. hlist_for_each_entry_rcu(node, head, list) {
  527. if (ssid == node->ae.ssid &&
  528. tclass == node->ae.tclass &&
  529. tsid == node->ae.tsid) {
  530. ret = node;
  531. break;
  532. }
  533. }
  534. return ret;
  535. }
  536. /**
  537. * avc_lookup - Look up an AVC entry.
  538. * @ssid: source security identifier
  539. * @tsid: target security identifier
  540. * @tclass: target security class
  541. *
  542. * Look up an AVC entry that is valid for the
  543. * (@ssid, @tsid), interpreting the permissions
  544. * based on @tclass. If a valid AVC entry exists,
  545. * then this function returns the avc_node.
  546. * Otherwise, this function returns NULL.
  547. */
  548. static struct avc_node *avc_lookup(struct selinux_avc *avc,
  549. u32 ssid, u32 tsid, u16 tclass)
  550. {
  551. struct avc_node *node;
  552. avc_cache_stats_incr(lookups);
  553. node = avc_search_node(avc, ssid, tsid, tclass);
  554. if (node)
  555. return node;
  556. avc_cache_stats_incr(misses);
  557. return NULL;
  558. }
  559. static int avc_latest_notif_update(struct selinux_avc *avc,
  560. int seqno, int is_insert)
  561. {
  562. int ret = 0;
  563. static DEFINE_SPINLOCK(notif_lock);
  564. unsigned long flag;
  565. spin_lock_irqsave(&notif_lock, flag);
  566. if (is_insert) {
  567. if (seqno < avc->avc_cache.latest_notif) {
  568. printk(KERN_WARNING "SELinux: avc: seqno %d < latest_notif %d\n",
  569. seqno, avc->avc_cache.latest_notif);
  570. ret = -EAGAIN;
  571. }
  572. } else {
  573. if (seqno > avc->avc_cache.latest_notif)
  574. avc->avc_cache.latest_notif = seqno;
  575. }
  576. spin_unlock_irqrestore(&notif_lock, flag);
  577. return ret;
  578. }
  579. /**
  580. * avc_insert - Insert an AVC entry.
  581. * @ssid: source security identifier
  582. * @tsid: target security identifier
  583. * @tclass: target security class
  584. * @avd: resulting av decision
  585. * @xp_node: resulting extended permissions
  586. *
  587. * Insert an AVC entry for the SID pair
  588. * (@ssid, @tsid) and class @tclass.
  589. * The access vectors and the sequence number are
  590. * normally provided by the security server in
  591. * response to a security_compute_av() call. If the
  592. * sequence number @avd->seqno is not less than the latest
  593. * revocation notification, then the function copies
  594. * the access vectors into a cache entry, returns
  595. * avc_node inserted. Otherwise, this function returns NULL.
  596. */
  597. static struct avc_node *avc_insert(struct selinux_avc *avc,
  598. u32 ssid, u32 tsid, u16 tclass,
  599. struct av_decision *avd,
  600. struct avc_xperms_node *xp_node)
  601. {
  602. struct avc_node *pos, *node = NULL;
  603. int hvalue;
  604. unsigned long flag;
  605. spinlock_t *lock;
  606. struct hlist_head *head;
  607. if (avc_latest_notif_update(avc, avd->seqno, 1))
  608. return NULL;
  609. node = avc_alloc_node(avc);
  610. if (!node)
  611. return NULL;
  612. avc_node_populate(node, ssid, tsid, tclass, avd);
  613. if (avc_xperms_populate(node, xp_node)) {
  614. avc_node_kill(avc, node);
  615. return NULL;
  616. }
  617. hvalue = avc_hash(ssid, tsid, tclass);
  618. head = &avc->avc_cache.slots[hvalue];
  619. lock = &avc->avc_cache.slots_lock[hvalue];
  620. spin_lock_irqsave(lock, flag);
  621. hlist_for_each_entry(pos, head, list) {
  622. if (pos->ae.ssid == ssid &&
  623. pos->ae.tsid == tsid &&
  624. pos->ae.tclass == tclass) {
  625. avc_node_replace(avc, node, pos);
  626. goto found;
  627. }
  628. }
  629. hlist_add_head_rcu(&node->list, head);
  630. found:
  631. spin_unlock_irqrestore(lock, flag);
  632. return node;
  633. }
  634. /**
  635. * avc_audit_pre_callback - SELinux specific information
  636. * will be called by generic audit code
  637. * @ab: the audit buffer
  638. * @a: audit_data
  639. */
  640. static void avc_audit_pre_callback(struct audit_buffer *ab, void *a)
  641. {
  642. struct common_audit_data *ad = a;
  643. audit_log_format(ab, "avc: %s ",
  644. ad->selinux_audit_data->denied ? "denied" : "granted");
  645. avc_dump_av(ab, ad->selinux_audit_data->tclass,
  646. ad->selinux_audit_data->audited);
  647. audit_log_format(ab, " for ");
  648. }
  649. /**
  650. * avc_audit_post_callback - SELinux specific information
  651. * will be called by generic audit code
  652. * @ab: the audit buffer
  653. * @a: audit_data
  654. */
  655. static void avc_audit_post_callback(struct audit_buffer *ab, void *a)
  656. {
  657. struct common_audit_data *ad = a;
  658. audit_log_format(ab, " ");
  659. avc_dump_query(ab, ad->selinux_audit_data->state,
  660. ad->selinux_audit_data->ssid,
  661. ad->selinux_audit_data->tsid,
  662. ad->selinux_audit_data->tclass);
  663. if (ad->selinux_audit_data->denied) {
  664. audit_log_format(ab, " permissive=%u",
  665. ad->selinux_audit_data->result ? 0 : 1);
  666. #ifdef CONFIG_MTK_SELINUX_AEE_WARNING
  667. {
  668. struct nlmsghdr *nlh;
  669. char *selinux_data;
  670. if (enforcing_enabled(ad->selinux_audit_data->state)
  671. && ab) {
  672. nlh = nlmsg_hdr(audit_get_skb(ab));
  673. selinux_data = nlmsg_data(nlh);
  674. if (mtk_audit_hook
  675. && nlh->nlmsg_type != AUDIT_EOE
  676. && nlh->nlmsg_type == 1400)
  677. mtk_audit_hook(selinux_data);
  678. }
  679. }
  680. #endif
  681. }
  682. }
  683. /* This is the slow part of avc audit with big stack footprint */
  684. noinline int slow_avc_audit(struct selinux_state *state,
  685. u32 ssid, u32 tsid, u16 tclass,
  686. u32 requested, u32 audited, u32 denied, int result,
  687. struct common_audit_data *a,
  688. unsigned int flags)
  689. {
  690. struct common_audit_data stack_data;
  691. struct selinux_audit_data sad;
  692. if (!a) {
  693. a = &stack_data;
  694. a->type = LSM_AUDIT_DATA_NONE;
  695. }
  696. /*
  697. * When in a RCU walk do the audit on the RCU retry. This is because
  698. * the collection of the dname in an inode audit message is not RCU
  699. * safe. Note this may drop some audits when the situation changes
  700. * during retry. However this is logically just as if the operation
  701. * happened a little later.
  702. */
  703. if ((a->type == LSM_AUDIT_DATA_INODE) &&
  704. (flags & MAY_NOT_BLOCK))
  705. return -ECHILD;
  706. sad.tclass = tclass;
  707. sad.requested = requested;
  708. sad.ssid = ssid;
  709. sad.tsid = tsid;
  710. sad.audited = audited;
  711. sad.denied = denied;
  712. sad.result = result;
  713. sad.state = state;
  714. a->selinux_audit_data = &sad;
  715. common_lsm_audit(a, avc_audit_pre_callback, avc_audit_post_callback);
  716. return 0;
  717. }
  718. /**
  719. * avc_add_callback - Register a callback for security events.
  720. * @callback: callback function
  721. * @events: security events
  722. *
  723. * Register a callback function for events in the set @events.
  724. * Returns %0 on success or -%ENOMEM if insufficient memory
  725. * exists to add the callback.
  726. */
  727. int __init avc_add_callback(int (*callback)(u32 event), u32 events)
  728. {
  729. struct avc_callback_node *c;
  730. int rc = 0;
  731. c = kmalloc(sizeof(*c), GFP_KERNEL);
  732. if (!c) {
  733. rc = -ENOMEM;
  734. goto out;
  735. }
  736. c->callback = callback;
  737. c->events = events;
  738. c->next = avc_callbacks;
  739. avc_callbacks = c;
  740. out:
  741. return rc;
  742. }
  743. /**
  744. * avc_update_node Update an AVC entry
  745. * @event : Updating event
  746. * @perms : Permission mask bits
  747. * @ssid,@tsid,@tclass : identifier of an AVC entry
  748. * @seqno : sequence number when decision was made
  749. * @xpd: extended_perms_decision to be added to the node
  750. *
  751. * if a valid AVC entry doesn't exist,this function returns -ENOENT.
  752. * if kmalloc() called internal returns NULL, this function returns -ENOMEM.
  753. * otherwise, this function updates the AVC entry. The original AVC-entry object
  754. * will release later by RCU.
  755. */
  756. static int avc_update_node(struct selinux_avc *avc,
  757. u32 event, u32 perms, u8 driver, u8 xperm, u32 ssid,
  758. u32 tsid, u16 tclass, u32 seqno,
  759. struct extended_perms_decision *xpd,
  760. u32 flags)
  761. {
  762. int hvalue, rc = 0;
  763. unsigned long flag;
  764. struct avc_node *pos, *node, *orig = NULL;
  765. struct hlist_head *head;
  766. spinlock_t *lock;
  767. node = avc_alloc_node(avc);
  768. if (!node) {
  769. rc = -ENOMEM;
  770. goto out;
  771. }
  772. /* Lock the target slot */
  773. hvalue = avc_hash(ssid, tsid, tclass);
  774. head = &avc->avc_cache.slots[hvalue];
  775. lock = &avc->avc_cache.slots_lock[hvalue];
  776. spin_lock_irqsave(lock, flag);
  777. hlist_for_each_entry(pos, head, list) {
  778. if (ssid == pos->ae.ssid &&
  779. tsid == pos->ae.tsid &&
  780. tclass == pos->ae.tclass &&
  781. seqno == pos->ae.avd.seqno){
  782. orig = pos;
  783. break;
  784. }
  785. }
  786. if (!orig) {
  787. rc = -ENOENT;
  788. avc_node_kill(avc, node);
  789. goto out_unlock;
  790. }
  791. /*
  792. * Copy and replace original node.
  793. */
  794. avc_node_populate(node, ssid, tsid, tclass, &orig->ae.avd);
  795. if (orig->ae.xp_node) {
  796. rc = avc_xperms_populate(node, orig->ae.xp_node);
  797. if (rc) {
  798. avc_node_kill(avc, node);
  799. goto out_unlock;
  800. }
  801. }
  802. switch (event) {
  803. case AVC_CALLBACK_GRANT:
  804. node->ae.avd.allowed |= perms;
  805. if (node->ae.xp_node && (flags & AVC_EXTENDED_PERMS))
  806. avc_xperms_allow_perm(node->ae.xp_node, driver, xperm);
  807. break;
  808. case AVC_CALLBACK_TRY_REVOKE:
  809. case AVC_CALLBACK_REVOKE:
  810. node->ae.avd.allowed &= ~perms;
  811. break;
  812. case AVC_CALLBACK_AUDITALLOW_ENABLE:
  813. node->ae.avd.auditallow |= perms;
  814. break;
  815. case AVC_CALLBACK_AUDITALLOW_DISABLE:
  816. node->ae.avd.auditallow &= ~perms;
  817. break;
  818. case AVC_CALLBACK_AUDITDENY_ENABLE:
  819. node->ae.avd.auditdeny |= perms;
  820. break;
  821. case AVC_CALLBACK_AUDITDENY_DISABLE:
  822. node->ae.avd.auditdeny &= ~perms;
  823. break;
  824. case AVC_CALLBACK_ADD_XPERMS:
  825. avc_add_xperms_decision(node, xpd);
  826. break;
  827. }
  828. avc_node_replace(avc, node, orig);
  829. out_unlock:
  830. spin_unlock_irqrestore(lock, flag);
  831. out:
  832. return rc;
  833. }
  834. /**
  835. * avc_flush - Flush the cache
  836. */
  837. static void avc_flush(struct selinux_avc *avc)
  838. {
  839. struct hlist_head *head;
  840. struct avc_node *node;
  841. spinlock_t *lock;
  842. unsigned long flag;
  843. int i;
  844. for (i = 0; i < AVC_CACHE_SLOTS; i++) {
  845. head = &avc->avc_cache.slots[i];
  846. lock = &avc->avc_cache.slots_lock[i];
  847. spin_lock_irqsave(lock, flag);
  848. /*
  849. * With preemptable RCU, the outer spinlock does not
  850. * prevent RCU grace periods from ending.
  851. */
  852. rcu_read_lock();
  853. hlist_for_each_entry(node, head, list)
  854. avc_node_delete(avc, node);
  855. rcu_read_unlock();
  856. spin_unlock_irqrestore(lock, flag);
  857. }
  858. }
  859. /**
  860. * avc_ss_reset - Flush the cache and revalidate migrated permissions.
  861. * @seqno: policy sequence number
  862. */
  863. int avc_ss_reset(struct selinux_avc *avc, u32 seqno)
  864. {
  865. struct avc_callback_node *c;
  866. int rc = 0, tmprc;
  867. avc_flush(avc);
  868. for (c = avc_callbacks; c; c = c->next) {
  869. if (c->events & AVC_CALLBACK_RESET) {
  870. tmprc = c->callback(AVC_CALLBACK_RESET);
  871. /* save the first error encountered for the return
  872. value and continue processing the callbacks */
  873. if (!rc)
  874. rc = tmprc;
  875. }
  876. }
  877. avc_latest_notif_update(avc, seqno, 0);
  878. return rc;
  879. }
  880. /*
  881. * Slow-path helper function for avc_has_perm_noaudit,
  882. * when the avc_node lookup fails. We get called with
  883. * the RCU read lock held, and need to return with it
  884. * still held, but drop if for the security compute.
  885. *
  886. * Don't inline this, since it's the slow-path and just
  887. * results in a bigger stack frame.
  888. */
  889. static noinline
  890. struct avc_node *avc_compute_av(struct selinux_state *state,
  891. u32 ssid, u32 tsid,
  892. u16 tclass, struct av_decision *avd,
  893. struct avc_xperms_node *xp_node)
  894. {
  895. rcu_read_unlock();
  896. INIT_LIST_HEAD(&xp_node->xpd_head);
  897. security_compute_av(state, ssid, tsid, tclass, avd, &xp_node->xp);
  898. rcu_read_lock();
  899. return avc_insert(state->avc, ssid, tsid, tclass, avd, xp_node);
  900. }
  901. static noinline int avc_denied(struct selinux_state *state,
  902. u32 ssid, u32 tsid,
  903. u16 tclass, u32 requested,
  904. u8 driver, u8 xperm, unsigned int flags,
  905. struct av_decision *avd)
  906. {
  907. if (flags & AVC_STRICT)
  908. return -EACCES;
  909. if (enforcing_enabled(state) &&
  910. !(avd->flags & AVD_FLAGS_PERMISSIVE))
  911. return -EACCES;
  912. avc_update_node(state->avc, AVC_CALLBACK_GRANT, requested, driver,
  913. xperm, ssid, tsid, tclass, avd->seqno, NULL, flags);
  914. return 0;
  915. }
  916. /*
  917. * The avc extended permissions logic adds an additional 256 bits of
  918. * permissions to an avc node when extended permissions for that node are
  919. * specified in the avtab. If the additional 256 permissions is not adequate,
  920. * as-is the case with ioctls, then multiple may be chained together and the
  921. * driver field is used to specify which set contains the permission.
  922. */
  923. int avc_has_extended_perms(struct selinux_state *state,
  924. u32 ssid, u32 tsid, u16 tclass, u32 requested,
  925. u8 driver, u8 xperm, struct common_audit_data *ad)
  926. {
  927. struct avc_node *node;
  928. struct av_decision avd;
  929. u32 denied;
  930. struct extended_perms_decision local_xpd;
  931. struct extended_perms_decision *xpd = NULL;
  932. struct extended_perms_data allowed;
  933. struct extended_perms_data auditallow;
  934. struct extended_perms_data dontaudit;
  935. struct avc_xperms_node local_xp_node;
  936. struct avc_xperms_node *xp_node;
  937. int rc = 0, rc2;
  938. xp_node = &local_xp_node;
  939. BUG_ON(!requested);
  940. rcu_read_lock();
  941. node = avc_lookup(state->avc, ssid, tsid, tclass);
  942. if (unlikely(!node)) {
  943. node = avc_compute_av(state, ssid, tsid, tclass, &avd, xp_node);
  944. } else {
  945. memcpy(&avd, &node->ae.avd, sizeof(avd));
  946. xp_node = node->ae.xp_node;
  947. }
  948. /* if extended permissions are not defined, only consider av_decision */
  949. if (!xp_node || !xp_node->xp.len)
  950. goto decision;
  951. local_xpd.allowed = &allowed;
  952. local_xpd.auditallow = &auditallow;
  953. local_xpd.dontaudit = &dontaudit;
  954. xpd = avc_xperms_decision_lookup(driver, xp_node);
  955. if (unlikely(!xpd)) {
  956. /*
  957. * Compute the extended_perms_decision only if the driver
  958. * is flagged
  959. */
  960. if (!security_xperm_test(xp_node->xp.drivers.p, driver)) {
  961. avd.allowed &= ~requested;
  962. goto decision;
  963. }
  964. rcu_read_unlock();
  965. security_compute_xperms_decision(state, ssid, tsid, tclass,
  966. driver, &local_xpd);
  967. rcu_read_lock();
  968. avc_update_node(state->avc, AVC_CALLBACK_ADD_XPERMS, requested,
  969. driver, xperm, ssid, tsid, tclass, avd.seqno,
  970. &local_xpd, 0);
  971. } else {
  972. avc_quick_copy_xperms_decision(xperm, &local_xpd, xpd);
  973. }
  974. xpd = &local_xpd;
  975. if (!avc_xperms_has_perm(xpd, xperm, XPERMS_ALLOWED))
  976. avd.allowed &= ~requested;
  977. decision:
  978. denied = requested & ~(avd.allowed);
  979. if (unlikely(denied))
  980. rc = avc_denied(state, ssid, tsid, tclass, requested,
  981. driver, xperm, AVC_EXTENDED_PERMS, &avd);
  982. rcu_read_unlock();
  983. rc2 = avc_xperms_audit(state, ssid, tsid, tclass, requested,
  984. &avd, xpd, xperm, rc, ad);
  985. if (rc2)
  986. return rc2;
  987. return rc;
  988. }
  989. /**
  990. * avc_has_perm_noaudit - Check permissions but perform no auditing.
  991. * @ssid: source security identifier
  992. * @tsid: target security identifier
  993. * @tclass: target security class
  994. * @requested: requested permissions, interpreted based on @tclass
  995. * @flags: AVC_STRICT or 0
  996. * @avd: access vector decisions
  997. *
  998. * Check the AVC to determine whether the @requested permissions are granted
  999. * for the SID pair (@ssid, @tsid), interpreting the permissions
  1000. * based on @tclass, and call the security server on a cache miss to obtain
  1001. * a new decision and add it to the cache. Return a copy of the decisions
  1002. * in @avd. Return %0 if all @requested permissions are granted,
  1003. * -%EACCES if any permissions are denied, or another -errno upon
  1004. * other errors. This function is typically called by avc_has_perm(),
  1005. * but may also be called directly to separate permission checking from
  1006. * auditing, e.g. in cases where a lock must be held for the check but
  1007. * should be released for the auditing.
  1008. */
  1009. inline int avc_has_perm_noaudit(struct selinux_state *state,
  1010. u32 ssid, u32 tsid,
  1011. u16 tclass, u32 requested,
  1012. unsigned int flags,
  1013. struct av_decision *avd)
  1014. {
  1015. struct avc_node *node;
  1016. struct avc_xperms_node xp_node;
  1017. int rc = 0;
  1018. u32 denied;
  1019. BUG_ON(!requested);
  1020. rcu_read_lock();
  1021. node = avc_lookup(state->avc, ssid, tsid, tclass);
  1022. if (unlikely(!node))
  1023. node = avc_compute_av(state, ssid, tsid, tclass, avd, &xp_node);
  1024. else
  1025. memcpy(avd, &node->ae.avd, sizeof(*avd));
  1026. denied = requested & ~(avd->allowed);
  1027. if (unlikely(denied))
  1028. rc = avc_denied(state, ssid, tsid, tclass, requested, 0, 0,
  1029. flags, avd);
  1030. rcu_read_unlock();
  1031. return rc;
  1032. }
  1033. /**
  1034. * avc_has_perm - Check permissions and perform any appropriate auditing.
  1035. * @ssid: source security identifier
  1036. * @tsid: target security identifier
  1037. * @tclass: target security class
  1038. * @requested: requested permissions, interpreted based on @tclass
  1039. * @auditdata: auxiliary audit data
  1040. *
  1041. * Check the AVC to determine whether the @requested permissions are granted
  1042. * for the SID pair (@ssid, @tsid), interpreting the permissions
  1043. * based on @tclass, and call the security server on a cache miss to obtain
  1044. * a new decision and add it to the cache. Audit the granting or denial of
  1045. * permissions in accordance with the policy. Return %0 if all @requested
  1046. * permissions are granted, -%EACCES if any permissions are denied, or
  1047. * another -errno upon other errors.
  1048. */
  1049. int avc_has_perm(struct selinux_state *state, u32 ssid, u32 tsid, u16 tclass,
  1050. u32 requested, struct common_audit_data *auditdata)
  1051. {
  1052. struct av_decision avd;
  1053. int rc, rc2;
  1054. rc = avc_has_perm_noaudit(state, ssid, tsid, tclass, requested, 0,
  1055. &avd);
  1056. rc2 = avc_audit(state, ssid, tsid, tclass, requested, &avd, rc,
  1057. auditdata, 0);
  1058. if (rc2)
  1059. return rc2;
  1060. return rc;
  1061. }
  1062. int avc_has_perm_flags(struct selinux_state *state,
  1063. u32 ssid, u32 tsid, u16 tclass, u32 requested,
  1064. struct common_audit_data *auditdata,
  1065. int flags)
  1066. {
  1067. struct av_decision avd;
  1068. int rc, rc2;
  1069. rc = avc_has_perm_noaudit(state, ssid, tsid, tclass, requested, 0,
  1070. &avd);
  1071. rc2 = avc_audit(state, ssid, tsid, tclass, requested, &avd, rc,
  1072. auditdata, flags);
  1073. if (rc2)
  1074. return rc2;
  1075. return rc;
  1076. }
  1077. u32 avc_policy_seqno(struct selinux_state *state)
  1078. {
  1079. return state->avc->avc_cache.latest_notif;
  1080. }
  1081. void avc_disable(void)
  1082. {
  1083. /*
  1084. * If you are looking at this because you have realized that we are
  1085. * not destroying the avc_node_cachep it might be easy to fix, but
  1086. * I don't know the memory barrier semantics well enough to know. It's
  1087. * possible that some other task dereferenced security_ops when
  1088. * it still pointed to selinux operations. If that is the case it's
  1089. * possible that it is about to use the avc and is about to need the
  1090. * avc_node_cachep. I know I could wrap the security.c security_ops call
  1091. * in an rcu_lock, but seriously, it's not worth it. Instead I just flush
  1092. * the cache and get that memory back.
  1093. */
  1094. if (avc_node_cachep) {
  1095. avc_flush(selinux_state.avc);
  1096. /* kmem_cache_destroy(avc_node_cachep); */
  1097. }
  1098. }