avtab.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /*
  2. * Implementation of the access vector table type.
  3. *
  4. * Author : Stephen Smalley, <[email protected]>
  5. */
  6. /* Updated: Frank Mayer <[email protected]> and Karl MacMillan <[email protected]>
  7. *
  8. * Added conditional policy language extensions
  9. *
  10. * Copyright (C) 2003 Tresys Technology, LLC
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation, version 2.
  14. *
  15. * Updated: Yuichi Nakamura <[email protected]>
  16. * Tuned number of hash slots for avtab to reduce memory usage
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/slab.h>
  20. #include <linux/errno.h>
  21. #include "avtab.h"
  22. #include "policydb.h"
  23. static struct kmem_cache *avtab_node_cachep __ro_after_init;
  24. static struct kmem_cache *avtab_xperms_cachep __ro_after_init;
  25. /* Based on MurmurHash3, written by Austin Appleby and placed in the
  26. * public domain.
  27. */
  28. static inline int avtab_hash(const struct avtab_key *keyp, u32 mask)
  29. {
  30. static const u32 c1 = 0xcc9e2d51;
  31. static const u32 c2 = 0x1b873593;
  32. static const u32 r1 = 15;
  33. static const u32 r2 = 13;
  34. static const u32 m = 5;
  35. static const u32 n = 0xe6546b64;
  36. u32 hash = 0;
  37. #define mix(input) do { \
  38. u32 v = input; \
  39. v *= c1; \
  40. v = (v << r1) | (v >> (32 - r1)); \
  41. v *= c2; \
  42. hash ^= v; \
  43. hash = (hash << r2) | (hash >> (32 - r2)); \
  44. hash = hash * m + n; \
  45. } while (0)
  46. mix(keyp->target_class);
  47. mix(keyp->target_type);
  48. mix(keyp->source_type);
  49. #undef mix
  50. hash ^= hash >> 16;
  51. hash *= 0x85ebca6b;
  52. hash ^= hash >> 13;
  53. hash *= 0xc2b2ae35;
  54. hash ^= hash >> 16;
  55. return hash & mask;
  56. }
  57. static struct avtab_node*
  58. avtab_insert_node(struct avtab *h, int hvalue,
  59. struct avtab_node *prev,
  60. const struct avtab_key *key, const struct avtab_datum *datum)
  61. {
  62. struct avtab_node *newnode;
  63. struct avtab_extended_perms *xperms;
  64. newnode = kmem_cache_zalloc(avtab_node_cachep, GFP_KERNEL);
  65. if (newnode == NULL)
  66. return NULL;
  67. newnode->key = *key;
  68. if (key->specified & AVTAB_XPERMS) {
  69. xperms = kmem_cache_zalloc(avtab_xperms_cachep, GFP_KERNEL);
  70. if (xperms == NULL) {
  71. kmem_cache_free(avtab_node_cachep, newnode);
  72. return NULL;
  73. }
  74. *xperms = *(datum->u.xperms);
  75. newnode->datum.u.xperms = xperms;
  76. } else {
  77. newnode->datum.u.data = datum->u.data;
  78. }
  79. if (prev) {
  80. newnode->next = prev->next;
  81. prev->next = newnode;
  82. } else {
  83. struct avtab_node **n = &h->htable[hvalue];
  84. newnode->next = *n;
  85. *n = newnode;
  86. }
  87. h->nel++;
  88. return newnode;
  89. }
  90. static int avtab_insert(struct avtab *h, const struct avtab_key *key,
  91. const struct avtab_datum *datum)
  92. {
  93. int hvalue;
  94. struct avtab_node *prev, *cur, *newnode;
  95. u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD);
  96. if (!h || !h->nslot)
  97. return -EINVAL;
  98. hvalue = avtab_hash(key, h->mask);
  99. for (prev = NULL, cur = h->htable[hvalue];
  100. cur;
  101. prev = cur, cur = cur->next) {
  102. if (key->source_type == cur->key.source_type &&
  103. key->target_type == cur->key.target_type &&
  104. key->target_class == cur->key.target_class &&
  105. (specified & cur->key.specified)) {
  106. /* extended perms may not be unique */
  107. if (specified & AVTAB_XPERMS)
  108. break;
  109. return -EEXIST;
  110. }
  111. if (key->source_type < cur->key.source_type)
  112. break;
  113. if (key->source_type == cur->key.source_type &&
  114. key->target_type < cur->key.target_type)
  115. break;
  116. if (key->source_type == cur->key.source_type &&
  117. key->target_type == cur->key.target_type &&
  118. key->target_class < cur->key.target_class)
  119. break;
  120. }
  121. newnode = avtab_insert_node(h, hvalue, prev, key, datum);
  122. if (!newnode)
  123. return -ENOMEM;
  124. return 0;
  125. }
  126. /* Unlike avtab_insert(), this function allow multiple insertions of the same
  127. * key/specified mask into the table, as needed by the conditional avtab.
  128. * It also returns a pointer to the node inserted.
  129. */
  130. struct avtab_node *avtab_insert_nonunique(struct avtab *h,
  131. const struct avtab_key *key,
  132. const struct avtab_datum *datum)
  133. {
  134. int hvalue;
  135. struct avtab_node *prev, *cur;
  136. u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD);
  137. if (!h || !h->nslot)
  138. return NULL;
  139. hvalue = avtab_hash(key, h->mask);
  140. for (prev = NULL, cur = h->htable[hvalue];
  141. cur;
  142. prev = cur, cur = cur->next) {
  143. if (key->source_type == cur->key.source_type &&
  144. key->target_type == cur->key.target_type &&
  145. key->target_class == cur->key.target_class &&
  146. (specified & cur->key.specified))
  147. break;
  148. if (key->source_type < cur->key.source_type)
  149. break;
  150. if (key->source_type == cur->key.source_type &&
  151. key->target_type < cur->key.target_type)
  152. break;
  153. if (key->source_type == cur->key.source_type &&
  154. key->target_type == cur->key.target_type &&
  155. key->target_class < cur->key.target_class)
  156. break;
  157. }
  158. return avtab_insert_node(h, hvalue, prev, key, datum);
  159. }
  160. struct avtab_datum *avtab_search(struct avtab *h, const struct avtab_key *key)
  161. {
  162. int hvalue;
  163. struct avtab_node *cur;
  164. u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD);
  165. if (!h || !h->nslot)
  166. return NULL;
  167. hvalue = avtab_hash(key, h->mask);
  168. for (cur = h->htable[hvalue]; cur;
  169. cur = cur->next) {
  170. if (key->source_type == cur->key.source_type &&
  171. key->target_type == cur->key.target_type &&
  172. key->target_class == cur->key.target_class &&
  173. (specified & cur->key.specified))
  174. return &cur->datum;
  175. if (key->source_type < cur->key.source_type)
  176. break;
  177. if (key->source_type == cur->key.source_type &&
  178. key->target_type < cur->key.target_type)
  179. break;
  180. if (key->source_type == cur->key.source_type &&
  181. key->target_type == cur->key.target_type &&
  182. key->target_class < cur->key.target_class)
  183. break;
  184. }
  185. return NULL;
  186. }
  187. /* This search function returns a node pointer, and can be used in
  188. * conjunction with avtab_search_next_node()
  189. */
  190. struct avtab_node *avtab_search_node(struct avtab *h,
  191. const struct avtab_key *key)
  192. {
  193. int hvalue;
  194. struct avtab_node *cur;
  195. u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD);
  196. if (!h || !h->nslot)
  197. return NULL;
  198. hvalue = avtab_hash(key, h->mask);
  199. for (cur = h->htable[hvalue]; cur;
  200. cur = cur->next) {
  201. if (key->source_type == cur->key.source_type &&
  202. key->target_type == cur->key.target_type &&
  203. key->target_class == cur->key.target_class &&
  204. (specified & cur->key.specified))
  205. return cur;
  206. if (key->source_type < cur->key.source_type)
  207. break;
  208. if (key->source_type == cur->key.source_type &&
  209. key->target_type < cur->key.target_type)
  210. break;
  211. if (key->source_type == cur->key.source_type &&
  212. key->target_type == cur->key.target_type &&
  213. key->target_class < cur->key.target_class)
  214. break;
  215. }
  216. return NULL;
  217. }
  218. struct avtab_node*
  219. avtab_search_node_next(struct avtab_node *node, int specified)
  220. {
  221. struct avtab_node *cur;
  222. if (!node)
  223. return NULL;
  224. specified &= ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD);
  225. for (cur = node->next; cur; cur = cur->next) {
  226. if (node->key.source_type == cur->key.source_type &&
  227. node->key.target_type == cur->key.target_type &&
  228. node->key.target_class == cur->key.target_class &&
  229. (specified & cur->key.specified))
  230. return cur;
  231. if (node->key.source_type < cur->key.source_type)
  232. break;
  233. if (node->key.source_type == cur->key.source_type &&
  234. node->key.target_type < cur->key.target_type)
  235. break;
  236. if (node->key.source_type == cur->key.source_type &&
  237. node->key.target_type == cur->key.target_type &&
  238. node->key.target_class < cur->key.target_class)
  239. break;
  240. }
  241. return NULL;
  242. }
  243. void avtab_destroy(struct avtab *h)
  244. {
  245. int i;
  246. struct avtab_node *cur, *temp;
  247. if (!h)
  248. return;
  249. for (i = 0; i < h->nslot; i++) {
  250. cur = h->htable[i];
  251. while (cur) {
  252. temp = cur;
  253. cur = cur->next;
  254. if (temp->key.specified & AVTAB_XPERMS)
  255. kmem_cache_free(avtab_xperms_cachep,
  256. temp->datum.u.xperms);
  257. kmem_cache_free(avtab_node_cachep, temp);
  258. }
  259. }
  260. kvfree(h->htable);
  261. h->htable = NULL;
  262. h->nel = 0;
  263. h->nslot = 0;
  264. h->mask = 0;
  265. }
  266. void avtab_init(struct avtab *h)
  267. {
  268. h->htable = NULL;
  269. h->nel = 0;
  270. h->nslot = 0;
  271. h->mask = 0;
  272. }
  273. static int avtab_alloc_common(struct avtab *h, u32 nslot)
  274. {
  275. if (!nslot)
  276. return 0;
  277. h->htable = kvcalloc(nslot, sizeof(void *), GFP_KERNEL);
  278. if (!h->htable)
  279. return -ENOMEM;
  280. h->nslot = nslot;
  281. h->mask = nslot - 1;
  282. return 0;
  283. }
  284. int avtab_alloc(struct avtab *h, u32 nrules)
  285. {
  286. int rc;
  287. u32 nslot = 0;
  288. if (nrules != 0) {
  289. u32 shift = 1;
  290. u32 work = nrules >> 3;
  291. while (work) {
  292. work >>= 1;
  293. shift++;
  294. }
  295. nslot = 1 << shift;
  296. if (nslot > MAX_AVTAB_HASH_BUCKETS)
  297. nslot = MAX_AVTAB_HASH_BUCKETS;
  298. rc = avtab_alloc_common(h, nslot);
  299. if (rc)
  300. return rc;
  301. }
  302. pr_debug("SELinux: %d avtab hash slots, %d rules.\n", nslot, nrules);
  303. return 0;
  304. }
  305. int avtab_alloc_dup(struct avtab *new, const struct avtab *orig)
  306. {
  307. return avtab_alloc_common(new, orig->nslot);
  308. }
  309. void avtab_hash_eval(struct avtab *h, char *tag)
  310. {
  311. int i, chain_len, slots_used, max_chain_len;
  312. unsigned long long chain2_len_sum;
  313. struct avtab_node *cur;
  314. slots_used = 0;
  315. max_chain_len = 0;
  316. chain2_len_sum = 0;
  317. for (i = 0; i < h->nslot; i++) {
  318. cur = h->htable[i];
  319. if (cur) {
  320. slots_used++;
  321. chain_len = 0;
  322. while (cur) {
  323. chain_len++;
  324. cur = cur->next;
  325. }
  326. if (chain_len > max_chain_len)
  327. max_chain_len = chain_len;
  328. chain2_len_sum += chain_len * chain_len;
  329. }
  330. }
  331. pr_debug("SELinux: %s: %d entries and %d/%d buckets used, "
  332. "longest chain length %d sum of chain length^2 %llu\n",
  333. tag, h->nel, slots_used, h->nslot, max_chain_len,
  334. chain2_len_sum);
  335. }
  336. static const uint16_t spec_order[] = {
  337. AVTAB_ALLOWED,
  338. AVTAB_AUDITDENY,
  339. AVTAB_AUDITALLOW,
  340. AVTAB_TRANSITION,
  341. AVTAB_CHANGE,
  342. AVTAB_MEMBER,
  343. AVTAB_XPERMS_ALLOWED,
  344. AVTAB_XPERMS_AUDITALLOW,
  345. AVTAB_XPERMS_DONTAUDIT
  346. };
  347. int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
  348. int (*insertf)(struct avtab *a, const struct avtab_key *k,
  349. const struct avtab_datum *d, void *p),
  350. void *p)
  351. {
  352. __le16 buf16[4];
  353. u16 enabled;
  354. u32 items, items2, val, vers = pol->policyvers;
  355. struct avtab_key key;
  356. struct avtab_datum datum;
  357. struct avtab_extended_perms xperms;
  358. __le32 buf32[ARRAY_SIZE(xperms.perms.p)];
  359. int i, rc;
  360. unsigned set;
  361. memset(&key, 0, sizeof(struct avtab_key));
  362. memset(&datum, 0, sizeof(struct avtab_datum));
  363. if (vers < POLICYDB_VERSION_AVTAB) {
  364. rc = next_entry(buf32, fp, sizeof(u32));
  365. if (rc) {
  366. pr_err("SELinux: avtab: truncated entry\n");
  367. return rc;
  368. }
  369. items2 = le32_to_cpu(buf32[0]);
  370. if (items2 > ARRAY_SIZE(buf32)) {
  371. pr_err("SELinux: avtab: entry overflow\n");
  372. return -EINVAL;
  373. }
  374. rc = next_entry(buf32, fp, sizeof(u32)*items2);
  375. if (rc) {
  376. pr_err("SELinux: avtab: truncated entry\n");
  377. return rc;
  378. }
  379. items = 0;
  380. val = le32_to_cpu(buf32[items++]);
  381. key.source_type = (u16)val;
  382. if (key.source_type != val) {
  383. pr_err("SELinux: avtab: truncated source type\n");
  384. return -EINVAL;
  385. }
  386. val = le32_to_cpu(buf32[items++]);
  387. key.target_type = (u16)val;
  388. if (key.target_type != val) {
  389. pr_err("SELinux: avtab: truncated target type\n");
  390. return -EINVAL;
  391. }
  392. val = le32_to_cpu(buf32[items++]);
  393. key.target_class = (u16)val;
  394. if (key.target_class != val) {
  395. pr_err("SELinux: avtab: truncated target class\n");
  396. return -EINVAL;
  397. }
  398. val = le32_to_cpu(buf32[items++]);
  399. enabled = (val & AVTAB_ENABLED_OLD) ? AVTAB_ENABLED : 0;
  400. if (!(val & (AVTAB_AV | AVTAB_TYPE))) {
  401. pr_err("SELinux: avtab: null entry\n");
  402. return -EINVAL;
  403. }
  404. if ((val & AVTAB_AV) &&
  405. (val & AVTAB_TYPE)) {
  406. pr_err("SELinux: avtab: entry has both access vectors and types\n");
  407. return -EINVAL;
  408. }
  409. if (val & AVTAB_XPERMS) {
  410. pr_err("SELinux: avtab: entry has extended permissions\n");
  411. return -EINVAL;
  412. }
  413. for (i = 0; i < ARRAY_SIZE(spec_order); i++) {
  414. if (val & spec_order[i]) {
  415. key.specified = spec_order[i] | enabled;
  416. datum.u.data = le32_to_cpu(buf32[items++]);
  417. rc = insertf(a, &key, &datum, p);
  418. if (rc)
  419. return rc;
  420. }
  421. }
  422. if (items != items2) {
  423. pr_err("SELinux: avtab: entry only had %d items, expected %d\n",
  424. items2, items);
  425. return -EINVAL;
  426. }
  427. return 0;
  428. }
  429. rc = next_entry(buf16, fp, sizeof(u16)*4);
  430. if (rc) {
  431. pr_err("SELinux: avtab: truncated entry\n");
  432. return rc;
  433. }
  434. items = 0;
  435. key.source_type = le16_to_cpu(buf16[items++]);
  436. key.target_type = le16_to_cpu(buf16[items++]);
  437. key.target_class = le16_to_cpu(buf16[items++]);
  438. key.specified = le16_to_cpu(buf16[items++]);
  439. if (!policydb_type_isvalid(pol, key.source_type) ||
  440. !policydb_type_isvalid(pol, key.target_type) ||
  441. !policydb_class_isvalid(pol, key.target_class)) {
  442. pr_err("SELinux: avtab: invalid type or class\n");
  443. return -EINVAL;
  444. }
  445. set = 0;
  446. for (i = 0; i < ARRAY_SIZE(spec_order); i++) {
  447. if (key.specified & spec_order[i])
  448. set++;
  449. }
  450. if (!set || set > 1) {
  451. pr_err("SELinux: avtab: more than one specifier\n");
  452. return -EINVAL;
  453. }
  454. if ((vers < POLICYDB_VERSION_XPERMS_IOCTL) &&
  455. (key.specified & AVTAB_XPERMS)) {
  456. pr_err("SELinux: avtab: policy version %u does not "
  457. "support extended permissions rules and one "
  458. "was specified\n", vers);
  459. return -EINVAL;
  460. } else if (key.specified & AVTAB_XPERMS) {
  461. memset(&xperms, 0, sizeof(struct avtab_extended_perms));
  462. rc = next_entry(&xperms.specified, fp, sizeof(u8));
  463. if (rc) {
  464. pr_err("SELinux: avtab: truncated entry\n");
  465. return rc;
  466. }
  467. rc = next_entry(&xperms.driver, fp, sizeof(u8));
  468. if (rc) {
  469. pr_err("SELinux: avtab: truncated entry\n");
  470. return rc;
  471. }
  472. rc = next_entry(buf32, fp, sizeof(u32)*ARRAY_SIZE(xperms.perms.p));
  473. if (rc) {
  474. pr_err("SELinux: avtab: truncated entry\n");
  475. return rc;
  476. }
  477. for (i = 0; i < ARRAY_SIZE(xperms.perms.p); i++)
  478. xperms.perms.p[i] = le32_to_cpu(buf32[i]);
  479. datum.u.xperms = &xperms;
  480. } else {
  481. rc = next_entry(buf32, fp, sizeof(u32));
  482. if (rc) {
  483. pr_err("SELinux: avtab: truncated entry\n");
  484. return rc;
  485. }
  486. datum.u.data = le32_to_cpu(*buf32);
  487. }
  488. if ((key.specified & AVTAB_TYPE) &&
  489. !policydb_type_isvalid(pol, datum.u.data)) {
  490. pr_err("SELinux: avtab: invalid type\n");
  491. return -EINVAL;
  492. }
  493. return insertf(a, &key, &datum, p);
  494. }
  495. static int avtab_insertf(struct avtab *a, const struct avtab_key *k,
  496. const struct avtab_datum *d, void *p)
  497. {
  498. return avtab_insert(a, k, d);
  499. }
  500. int avtab_read(struct avtab *a, void *fp, struct policydb *pol)
  501. {
  502. int rc;
  503. __le32 buf[1];
  504. u32 nel, i;
  505. rc = next_entry(buf, fp, sizeof(u32));
  506. if (rc < 0) {
  507. pr_err("SELinux: avtab: truncated table\n");
  508. goto bad;
  509. }
  510. nel = le32_to_cpu(buf[0]);
  511. if (!nel) {
  512. pr_err("SELinux: avtab: table is empty\n");
  513. rc = -EINVAL;
  514. goto bad;
  515. }
  516. rc = avtab_alloc(a, nel);
  517. if (rc)
  518. goto bad;
  519. for (i = 0; i < nel; i++) {
  520. rc = avtab_read_item(a, fp, pol, avtab_insertf, NULL);
  521. if (rc) {
  522. if (rc == -ENOMEM)
  523. pr_err("SELinux: avtab: out of memory\n");
  524. else if (rc == -EEXIST)
  525. pr_err("SELinux: avtab: duplicate entry\n");
  526. goto bad;
  527. }
  528. }
  529. rc = 0;
  530. out:
  531. return rc;
  532. bad:
  533. avtab_destroy(a);
  534. goto out;
  535. }
  536. int avtab_write_item(struct policydb *p, const struct avtab_node *cur, void *fp)
  537. {
  538. __le16 buf16[4];
  539. __le32 buf32[ARRAY_SIZE(cur->datum.u.xperms->perms.p)];
  540. int rc;
  541. unsigned int i;
  542. buf16[0] = cpu_to_le16(cur->key.source_type);
  543. buf16[1] = cpu_to_le16(cur->key.target_type);
  544. buf16[2] = cpu_to_le16(cur->key.target_class);
  545. buf16[3] = cpu_to_le16(cur->key.specified);
  546. rc = put_entry(buf16, sizeof(u16), 4, fp);
  547. if (rc)
  548. return rc;
  549. if (cur->key.specified & AVTAB_XPERMS) {
  550. rc = put_entry(&cur->datum.u.xperms->specified, sizeof(u8), 1, fp);
  551. if (rc)
  552. return rc;
  553. rc = put_entry(&cur->datum.u.xperms->driver, sizeof(u8), 1, fp);
  554. if (rc)
  555. return rc;
  556. for (i = 0; i < ARRAY_SIZE(cur->datum.u.xperms->perms.p); i++)
  557. buf32[i] = cpu_to_le32(cur->datum.u.xperms->perms.p[i]);
  558. rc = put_entry(buf32, sizeof(u32),
  559. ARRAY_SIZE(cur->datum.u.xperms->perms.p), fp);
  560. } else {
  561. buf32[0] = cpu_to_le32(cur->datum.u.data);
  562. rc = put_entry(buf32, sizeof(u32), 1, fp);
  563. }
  564. if (rc)
  565. return rc;
  566. return 0;
  567. }
  568. int avtab_write(struct policydb *p, struct avtab *a, void *fp)
  569. {
  570. unsigned int i;
  571. int rc = 0;
  572. struct avtab_node *cur;
  573. __le32 buf[1];
  574. buf[0] = cpu_to_le32(a->nel);
  575. rc = put_entry(buf, sizeof(u32), 1, fp);
  576. if (rc)
  577. return rc;
  578. for (i = 0; i < a->nslot; i++) {
  579. for (cur = a->htable[i]; cur;
  580. cur = cur->next) {
  581. rc = avtab_write_item(p, cur, fp);
  582. if (rc)
  583. return rc;
  584. }
  585. }
  586. return rc;
  587. }
  588. void __init avtab_cache_init(void)
  589. {
  590. avtab_node_cachep = kmem_cache_create("avtab_node",
  591. sizeof(struct avtab_node),
  592. 0, SLAB_PANIC, NULL);
  593. avtab_xperms_cachep = kmem_cache_create("avtab_extended_perms",
  594. sizeof(struct avtab_extended_perms),
  595. 0, SLAB_PANIC, NULL);
  596. }